aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/urlinterceptor.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-10-01 16:43:18 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-10-02 11:47:49 +0200
commit7d8cbdb9941532cd5bf560b21395f6ed371d1ab5 (patch)
tree9c5a2d72a3882050f2c3c95ec2d15ad21ff98a93 /src/webengine/urlinterceptor.cpp
parentupdater: windows fixes (diff)
downloadsmolbote-7d8cbdb9941532cd5bf560b21395f6ed371d1ab5.tar.xz
Split off UrlFilter into library
- add more adblock filter options
Diffstat (limited to 'src/webengine/urlinterceptor.cpp')
-rw-r--r--src/webengine/urlinterceptor.cpp11
1 files changed, 6 insertions, 5 deletions
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;
}