diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-10-01 16:43:18 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-10-02 11:47:49 +0200 |
commit | 7d8cbdb9941532cd5bf560b21395f6ed371d1ab5 (patch) | |
tree | 9c5a2d72a3882050f2c3c95ec2d15ad21ff98a93 /src | |
parent | updater: windows fixes (diff) | |
download | smolbote-7d8cbdb9941532cd5bf560b21395f6ed371d1ab5.tar.xz |
Split off UrlFilter into library
- add more adblock filter options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/webengine/urlinterceptor.cpp | 11 | ||||
-rw-r--r-- | src/webengine/urlinterceptor.h | 4 |
3 files changed, 9 insertions, 8 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3263bbb..6162cd4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -72,7 +72,7 @@ target_link_libraries(${poi_exe} about addressbar configuration - bookmarks downloads web + bookmarks downloads web urlfilter ) if(Breakpad) diff --git a/src/webengine/urlinterceptor.cpp b/src/webengine/urlinterceptor.cpp index 06464ae..db4aea9 100644 --- a/src/webengine/urlinterceptor.cpp +++ b/src/webengine/urlinterceptor.cpp @@ -7,7 +7,7 @@ */ #include "urlinterceptor.h" -#include "web/urlfilter/adblockrule.h" +#include "urlfilter/formats/adblockrule.h" #include <QDir> #include <QJsonArray> #include <QJsonDocument> @@ -27,7 +27,6 @@ inline std::vector<FilterRule> parseAdBlockList(const QString &filename) AdBlockRule rule(line); if(rule.isEnabled()) { rules.emplace_back(std::move(rule)); - //qDebug("added rule: %s", qUtf8Printable(line)); } } list.close(); @@ -63,7 +62,7 @@ UrlRequestInterceptor::UrlRequestInterceptor(const std::unique_ptr<Configuration auto filtersPath = config->value<QString>("filter.adblock"); if(filtersPath) - filters = std::move(parseAdBlockList(filtersPath.value())); + filters = parseAdBlockList(filtersPath.value()); } // test DNT on https://browserleaks.com/donottrack @@ -78,12 +77,14 @@ void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info) return; } + const uint domainHash = qHash(info.firstPartyUrl().host()); + const QWebEngineUrlRequestInfo::ResourceType type = info.resourceType(); + const QUrl requestUrl = info.requestUrl(); for(const FilterRule &rule : filters) { - if(rule.matchesDomain(info.firstPartyUrl().host()) && rule.matchesType(info.resourceType()) && rule.matchesUrl(info.requestUrl())) { + if(rule.matchesDomain(domainHash) && rule.matchesType(type) && rule.matchesUrl(requestUrl)) { info.block(rule.isBlocking()); #ifdef QT_DEBUG qDebug("--> blocked %s", qUtf8Printable(info.requestUrl().toString())); - qDebug("- %s", qUtf8Printable(rule.toString())); #endif break; } diff --git a/src/webengine/urlinterceptor.h b/src/webengine/urlinterceptor.h index 5c78b62..575e0c9 100644 --- a/src/webengine/urlinterceptor.h +++ b/src/webengine/urlinterceptor.h @@ -9,7 +9,7 @@ #ifndef SMOLBOTE_URLREQUESTINTERCEPTOR_H #define SMOLBOTE_URLREQUESTINTERCEPTOR_H -#include "web/urlfilter/filterrule.h" +#include "urlfilter/filterrule.h" #include <QByteArray> #include <QVector> #include <QWebEngineUrlRequestInterceptor> @@ -27,7 +27,7 @@ public: }; explicit UrlRequestInterceptor(const std::unique_ptr<Configuration> &config, QObject *parent = nullptr); - ~UrlRequestInterceptor() = default; + ~UrlRequestInterceptor() override = default; void interceptRequest(QWebEngineUrlRequestInfo &info) override; |