aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/adblockinterceptor.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-01-24 16:09:07 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-01-24 16:09:07 +0100
commit0250559bcf5764fb8cf3a8ccc4e330b8ed855f96 (patch)
tree2283350e44f78e83a8c0257b66c184939cd95a98 /src/webengine/adblockinterceptor.cpp
parentMade Profile menu a regular menu (diff)
downloadsmolbote-0250559bcf5764fb8cf3a8ccc4e330b8ed855f96.tar.xz
Blocker UI
Diffstat (limited to 'src/webengine/adblockinterceptor.cpp')
-rw-r--r--src/webengine/adblockinterceptor.cpp56
1 files changed, 0 insertions, 56 deletions
diff --git a/src/webengine/adblockinterceptor.cpp b/src/webengine/adblockinterceptor.cpp
deleted file mode 100644
index 02bf2f4..0000000
--- a/src/webengine/adblockinterceptor.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-#include "adblockinterceptor.h"
-
-#include <QFile>
-#include <QTextStream>
-
-AdBlockInterceptor::AdBlockInterceptor(QObject *parent) :
- QWebEngineUrlRequestInterceptor(parent)
-{
- loadSubscription("blocklist.txt");
-}
-
-void AdBlockInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
-{
- bool blocked = false;
- for(AdBlockRule *rule : m_urlBlacklist) {
- if(rule->match(info.requestUrl())) {
- info.block(true);
- blocked = true;
- }
- }
-
- qDebug("%i %i %i %s %s", blocked, info.navigationType(), info.resourceType(), qUtf8Printable(info.requestMethod()), qUtf8Printable(info.requestUrl().toString()));
-}
-
-int AdBlockInterceptor::loadSubscription(const QString &subpath)
-{
- QFile subfile(subpath);
- if(!subfile.open(QIODevice::ReadOnly | QIODevice::Text)) {
- qDebug("AdBlockInterceptor: cannot load subscription: %s", qUtf8Printable(subpath));
- return -1;
- }
-
- QTextStream subscription(&subfile);
-
- QString header = subscription.readLine();
- if(header != "[Adblock Plus 2.0]") {
- qDebug("AdBlockInterceptor: invalid format of subscription: %s", qUtf8Printable(subpath));
- return -1;
- }
-
- int rules = 0;
-
- while(!subscription.atEnd()) {
- QString line = subscription.readLine();
- if(!line.isEmpty() && !line.startsWith('!')) {
- // The line is not a comment
- AdBlockRule *rule = new AdBlockRule(line, this);
- m_urlBlacklist.append(rule);
- rules++;
- }
- }
-
- qDebug("Loaded %i rules from subscription %s", rules, qUtf8Printable(subpath));
-
- return rules;
-}