diff options
Diffstat (limited to 'src/webengine/urlinterceptor.cpp')
-rw-r--r-- | src/webengine/urlinterceptor.cpp | 45 |
1 files changed, 5 insertions, 40 deletions
diff --git a/src/webengine/urlinterceptor.cpp b/src/webengine/urlinterceptor.cpp index 29cd869..047cad4 100644 --- a/src/webengine/urlinterceptor.cpp +++ b/src/webengine/urlinterceptor.cpp @@ -8,59 +8,24 @@ #include "urlinterceptor.h" #include "webprofile.h" -#include "urlfilter.h" // test DNT on https://browserleaks.com/donottrack -UrlRequestInterceptor::UrlRequestInterceptor(WebProfile* profile, QObject* parent) - : QWebEngineUrlRequestInterceptor(parent) +UrlRequestInterceptor::UrlRequestInterceptor(WebProfile* profile) + : QWebEngineUrlRequestInterceptor(profile) { Q_CHECK_PTR(profile); m_profile = profile; } -void UrlRequestInterceptor::addHttpHeader(const QByteArray &key, const QByteArray &value) -{ - headers.append(qMakePair(key, value)); -} - -void UrlRequestInterceptor::addFilter(UrlFilter *filter) -{ - if(filter != nullptr) - filters.append(filter); -} -void UrlRequestInterceptor::removeFilter(UrlFilter *filter) -{ - if(filter != nullptr) - filters.removeOne(filter); -} - void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info) { - for(const auto *filter : qAsConst(filters)) { - const auto match = filter->match(info.firstPartyUrl(), info.requestUrl(), info.resourceType()); - - // skip if no match - if(match.first == UrlFilter::NotMatched) - continue; - - else { - if(match.first == UrlFilter::Allow) - info.block(false); - else if(match.first == UrlFilter::Block) - info.block(true); - else if(match.first == UrlFilter::Redirect) - info.redirect(QUrl::fromUserInput(match.second)); - // we found a match, skip the rest - break; - } + for(auto *filter : qAsConst(m_profile->m_filters)) { + filter->interceptRequest(info); } // set headers - for(const auto &header : qAsConst(headers)) { - info.setHttpHeader(header.first, header.second); - } - for(auto i = m_profile->headers().constBegin(); i != m_profile->headers().constEnd(); ++i) { + for(auto i = m_profile->m_headers.constBegin(); i != m_profile->m_headers.constEnd(); ++i) { info.setHttpHeader(i.key(), i.value()); } } |