From e87693c54ca97ed3a6ed25f9eaae8ab223fc18b1 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 29 Apr 2020 18:49:07 +0300 Subject: libwebengine Make src/webengine into a static library - Add some tests - Updated manpage - Remove WebProfileManager::id and WebProfileManager::instance - Add consumable semantics checks to WebProfileManager - Add WebProfileManager::walk Add ApplicationMenu class --- src/webengine/urlinterceptor.cpp | 45 +++++----------------------------------- 1 file changed, 5 insertions(+), 40 deletions(-) (limited to 'src/webengine/urlinterceptor.cpp') 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()); } } -- cgit v1.2.1