X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=blobdiff_plain;f=src%2FUrlRequestInterceptor.cpp;h=10f986200b9e60cd546c6fd63dc8310947edd432;hp=94a88aa11287691f33ae0f184cacd8b38bd8af41;hb=16118809a11aa423f453a03c47f5263e9dd8b662;hpb=44cd064cb213ad693223ca117fe346d8b78456d6 diff --git a/src/UrlRequestInterceptor.cpp b/src/UrlRequestInterceptor.cpp index 94a88aa..10f9862 100644 --- a/src/UrlRequestInterceptor.cpp +++ b/src/UrlRequestInterceptor.cpp @@ -25,26 +25,50 @@ UrlRequestInterceptor::UrlRequestInterceptor(QObject *parentObjectPointer) : QWe void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &urlRequestInfo) { + // Handle the request according to the navigation type. + switch (urlRequestInfo.navigationType()) + { + case QWebEngineUrlRequestInfo::NavigationTypeLink: + case QWebEngineUrlRequestInfo::NavigationTypeTyped: + { + // Only check the hosts if the main URL is changing. + if (urlRequestInfo.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame) + { + // Get the hosts. + QString requestingHost = urlRequestInfo.initiator().host(); + QString requestedHost = urlRequestInfo.requestUrl().host(); + + // Reapply the domain settings if the host is changing. + if (requestingHost != requestedHost) + { + emit applyDomainSettings(requestedHost); + } + } + + break; + } + + default: + // Do nothing. + break; + } + // Handle the request according to the resource type. switch (urlRequestInfo.resourceType()) { + // A naughty HTTP ping request. case QWebEngineUrlRequestInfo::ResourceTypePing: + { // Block HTTP ping requests. urlRequestInfo.block(true); + break; + } default: + { // Do nothing. break; - } - - // Get the hosts. - QString requestingHost = urlRequestInfo.firstPartyUrl().host(); - QString requestedHost = urlRequestInfo.requestUrl().host(); - - // Reapply the domain settings if the host is changing. - if (requestingHost != requestedHost) - { - emit applyDomainSettings(); + } } }