From ed7430d2352b3f87991f68fbc0acfe4dbae39b56 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 27 Jan 2017 17:14:49 +0100 Subject: URL blocking whitelist --- src/webengine/urlinterceptor.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'src/webengine/urlinterceptor.cpp') diff --git a/src/webengine/urlinterceptor.cpp b/src/webengine/urlinterceptor.cpp index 87879a5..2bd50b8 100644 --- a/src/webengine/urlinterceptor.cpp +++ b/src/webengine/urlinterceptor.cpp @@ -1,19 +1,32 @@ #include "urlinterceptor.h" -AdBlockInterceptor::AdBlockInterceptor(QObject *parent) : +UrlRequestInterceptor::UrlRequestInterceptor(QObject *parent) : QWebEngineUrlRequestInterceptor(parent) { } -void AdBlockInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info) +void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info) { -// bool blocked = false; -// for(AdBlockRule *rule : m_urlBlacklist) { -// if(rule->match(info.requestUrl())) { -// info.block(true); -// blocked = true; -// } -// } + for(BlockerRule *rule : m_sub->urlWhitelist()) { + if(rule->match(info.requestUrl())) { + qDebug("OK %s", qUtf8Printable(info.requestUrl().toString())); + return; + } + } - qDebug("%i %i %s %s", info.navigationType(), info.resourceType(), qUtf8Printable(info.requestMethod()), qUtf8Printable(info.requestUrl().toString())); + for(BlockerRule *rule : m_sub->urlBlacklist()) { + if(rule->match(info.requestUrl())) { + info.block(true); + qDebug(" %s", qUtf8Printable(info.requestUrl().toString())); + return; + } + } + + qDebug("OK %s", qUtf8Printable(info.requestUrl().toString())); + +} + +void UrlRequestInterceptor::setSubscription(BlockerSubscription *subscription) +{ + m_sub = subscription; } -- cgit v1.2.1