From 7d8cbdb9941532cd5bf560b21395f6ed371d1ab5 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 1 Oct 2018 16:43:18 +0200 Subject: Split off UrlFilter into library - add more adblock filter options --- src/CMakeLists.txt | 2 +- src/webengine/urlinterceptor.cpp | 11 ++++++----- src/webengine/urlinterceptor.h | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src') 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 #include #include @@ -27,7 +27,6 @@ inline std::vector 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_ptrvalue("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 #include #include @@ -27,7 +27,7 @@ public: }; explicit UrlRequestInterceptor(const std::unique_ptr &config, QObject *parent = nullptr); - ~UrlRequestInterceptor() = default; + ~UrlRequestInterceptor() override = default; void interceptRequest(QWebEngineUrlRequestInfo &info) override; -- cgit v1.2.1