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/webengine/urlinterceptor.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/webengine/urlinterceptor.cpp') 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; } -- cgit v1.2.1