X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=blobdiff_plain;f=src%2FUrlRequestInterceptor.cpp;h=12be0ed944dae1f6d60bf558bb5ed7d2371fdd69;hp=94a88aa11287691f33ae0f184cacd8b38bd8af41;hb=2c380f75b275780859774f3947db39cdf6f4f021;hpb=44cd064cb213ad693223ca117fe346d8b78456d6 diff --git a/src/UrlRequestInterceptor.cpp b/src/UrlRequestInterceptor.cpp index 94a88aa..12be0ed 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(); + } + } + + 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(); + } } }