Falkon Develop
Cross-platform Qt-based web browser
adblockmanager.h
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#ifndef ADBLOCKMANAGER_H
19#define ADBLOCKMANAGER_H
20
21#include <QObject>
22#include <QStringList>
23#include <QPointer>
24#include <QMutex>
25#include <QUrl>
26#include <QWebEngineUrlRequestInfo>
27
28#include "qzcommon.h"
29
30#define ADBLOCK_EASYLIST_URL QSL("https://easylist-downloads.adblockplus.org/easylist.txt")
31#define ADBLOCK_NOCOINLIST_URL QSL("https://raw.githubusercontent.com/hoshsadiq/adblock-nocoin-list/master/nocoin.txt")
32
33class AdBlockRule;
34class AdBlockDialog;
35class AdBlockMatcher;
39
41{
44 QByteArray requestMethod;
45 QWebEngineUrlRequestInfo::ResourceType resourceType;
46 QWebEngineUrlRequestInfo::NavigationType navigationType;
47 QString rule;
48};
50
51class FALKON_EXPORT AdBlockManager : public QObject
52{
53 Q_OBJECT
54
55public:
56 AdBlockManager(QObject* parent = nullptr);
58
59 void load();
60 void save();
61
62 bool isEnabled() const;
63 bool canRunOnScheme(const QString &scheme) const;
64 bool canBeBlocked(const QUrl &url) const;
65
66 QString elementHidingRules(const QUrl &url) const;
67 QString elementHidingRulesForDomain(const QUrl &url) const;
68
69 AdBlockSubscription* subscriptionByName(const QString &name) const;
70 QList<AdBlockSubscription*> subscriptions() const;
71
72 bool block(QWebEngineUrlRequestInfo &request, QString &ruleFilter, QString &ruleSubscription);
73
74 QVector<AdBlockedRequest> blockedRequestsForUrl(const QUrl &url) const;
75 void clearBlockedRequestsForUrl(const QUrl &url);
76
77 QStringList disabledRules() const;
78 void addDisabledRule(const QString &filter);
79 void removeDisabledRule(const QString &filter);
80
81 bool addSubscriptionFromUrl(const QUrl &url);
82
83 AdBlockSubscription* addSubscription(const QString &title, const QString &url);
84 bool removeSubscription(AdBlockSubscription* subscription);
85
86 AdBlockCustomList* customList() const;
87
88 static AdBlockManager* instance();
89
90Q_SIGNALS:
91 void enabledChanged(bool enabled);
92 void blockedRequestsChanged(const QUrl &url);
93
94public Q_SLOTS:
95 void setEnabled(bool enabled);
96 void showRule();
97
98 void updateMatcher();
99 void updateAllSubscriptions();
100
101 AdBlockDialog *showDialog(QWidget *parent = nullptr);
102
103private:
104 bool m_loaded;
105 bool m_enabled;
106
107 QList<AdBlockSubscription*> m_subscriptions;
108 AdBlockMatcher* m_matcher;
109 QStringList m_disabledRules;
110
111 AdBlockUrlInterceptor *m_interceptor;
112 QPointer<AdBlockDialog> m_adBlockDialog;
113 QMutex m_mutex;
114 QHash<QUrl, QVector<AdBlockedRequest>> m_blockedRequests;
115};
116
117#endif // ADBLOCKMANAGER_H
118
void enabledChanged(bool enabled)
void blockedRequestsChanged(const QUrl &url)
Q_DECLARE_METATYPE(FlashCookie)
#define FALKON_EXPORT
Definition: qzcommon.h:28
QByteArray requestMethod
QWebEngineUrlRequestInfo::ResourceType resourceType
QWebEngineUrlRequestInfo::NavigationType navigationType