]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/UrlRequestInterceptor.cpp
Add on-the-fly settings.
[PrivacyBrowserPC.git] / src / UrlRequestInterceptor.cpp
index 94a88aa11287691f33ae0f184cacd8b38bd8af41..12be0ed944dae1f6d60bf558bb5ed7d2371fdd69 100644 (file)
@@ -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();
+        }
     }
 }