]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Fix the application of Domain Settings when navigating history. https://redmine.stout...
authorSoren Stoutner <soren@stoutner.com>
Wed, 30 Mar 2022 21:33:29 +0000 (14:33 -0700)
committerSoren Stoutner <soren@stoutner.com>
Wed, 30 Mar 2022 21:33:29 +0000 (14:33 -0700)
src/CMakeLists.txt
src/UrlRequestInterceptor.cpp [deleted file]
src/UrlRequestInterceptor.h [deleted file]
src/interceptors/CMakeLists.txt [new file with mode: 0644]
src/interceptors/UrlRequestInterceptor.cpp [new file with mode: 0644]
src/interceptors/UrlRequestInterceptor.h [new file with mode: 0644]
src/views/BrowserView.cpp
src/views/BrowserView.h
src/windows/BrowserWindow.cpp

index 55b3e3f75911dd82616e6361a452f080098d5ba0..709b74ca16e6f9d88746142cce3062097e4bde32 100644 (file)
@@ -22,7 +22,6 @@ add_executable(privacy-browser resources.qrc)
 target_sources(privacy-browser PRIVATE
     main.cpp
     MouseEventFilter.cpp
-    UrlRequestInterceptor.cpp
 )
 
 # Add the Qt logging category.  This will create the `debug.h` header file.
@@ -64,6 +63,7 @@ target_link_libraries(privacy-browser
 # Add the subdirectories.
 add_subdirectory(dialogs)
 add_subdirectory(helpers)
+add_subdirectory(interceptors)
 add_subdirectory(ui.rc)
 add_subdirectory(views)
 add_subdirectory(windows)
diff --git a/src/UrlRequestInterceptor.cpp b/src/UrlRequestInterceptor.cpp
deleted file mode 100644 (file)
index 10f9862..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
- *
- * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
- *
- * Privacy Browser PC is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Privacy Browser PC is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Privacy Browser PC.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-// Application headers.
-#include "UrlRequestInterceptor.h"
-
-// The default constructor.
-UrlRequestInterceptor::UrlRequestInterceptor(QObject *parentObjectPointer) : QWebEngineUrlRequestInterceptor(parentObjectPointer) {}
-
-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;
-        }
-    }
-}
diff --git a/src/UrlRequestInterceptor.h b/src/UrlRequestInterceptor.h
deleted file mode 100644 (file)
index 721d523..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
- *
- * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
- *
- * Privacy Browser PC is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Privacy Browser PC is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Privacy Browser PC.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef URLREQUESTINTERCEPTOR_H
-#define URLREQUESTINTERCEPTOR_H
-
-// Qt framework headers.
-#include <QtWebEngineCore>
-
-class UrlRequestInterceptor : public QWebEngineUrlRequestInterceptor
-{
-    // Include the Q_OBJECT macro.
-    Q_OBJECT
-
-public:
-    // The default constructor.
-    UrlRequestInterceptor(QObject *parentObjectPointer = 0);
-
-    // The public functions.
-    void interceptRequest(QWebEngineUrlRequestInfo &urlRequestInfo) override;
-
-signals:
-    // The signals.
-    void applyDomainSettings(const QString hostname) const;
-};
-#endif
diff --git a/src/interceptors/CMakeLists.txt b/src/interceptors/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6e92b32
--- /dev/null
@@ -0,0 +1,22 @@
+# Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+#
+# This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+#
+# Privacy Browser PC is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Privacy Browser PC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Privacy Browser PC.  If not, see <http://www.gnu.org/licenses/>.
+
+
+# List the sources to include in the executable.
+target_sources(privacy-browser PRIVATE
+    UrlRequestInterceptor.cpp
+)
diff --git a/src/interceptors/UrlRequestInterceptor.cpp b/src/interceptors/UrlRequestInterceptor.cpp
new file mode 100644 (file)
index 0000000..2b9bd05
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+ *
+ * Privacy Browser PC is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Browser PC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Privacy Browser PC.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Application headers.
+#include "UrlRequestInterceptor.h"
+
+// The default constructor.
+UrlRequestInterceptor::UrlRequestInterceptor(QObject *parentObjectPointer) : QWebEngineUrlRequestInterceptor(parentObjectPointer) {}
+
+void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &urlRequestInfo)
+{
+    // Handle the request according to the navigation type.
+    switch (urlRequestInfo.navigationType())
+    {
+        case QWebEngineUrlRequestInfo::NavigationTypeLink:
+        case QWebEngineUrlRequestInfo::NavigationTypeTyped:
+        case QWebEngineUrlRequestInfo::NavigationTypeBackForward:
+        case QWebEngineUrlRequestInfo::NavigationTypeRedirect:
+        {
+            // 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;
+        }
+    }
+}
diff --git a/src/interceptors/UrlRequestInterceptor.h b/src/interceptors/UrlRequestInterceptor.h
new file mode 100644 (file)
index 0000000..721d523
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+ *
+ * Privacy Browser PC is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Browser PC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Privacy Browser PC.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef URLREQUESTINTERCEPTOR_H
+#define URLREQUESTINTERCEPTOR_H
+
+// Qt framework headers.
+#include <QtWebEngineCore>
+
+class UrlRequestInterceptor : public QWebEngineUrlRequestInterceptor
+{
+    // Include the Q_OBJECT macro.
+    Q_OBJECT
+
+public:
+    // The default constructor.
+    UrlRequestInterceptor(QObject *parentObjectPointer = 0);
+
+    // The public functions.
+    void interceptRequest(QWebEngineUrlRequestInfo &urlRequestInfo) override;
+
+signals:
+    // The signals.
+    void applyDomainSettings(const QString hostname) const;
+};
+#endif
index 90539a3dfee1e89bfe7f45a992ca872547ce8a07..d190dbec3bcdc4ab4525bf48b19e9a93d32a20c7 100644 (file)
 #include "MouseEventFilter.h"
 #include "Settings.h"
 #include "ui_BrowserView.h"
-#include "UrlRequestInterceptor.h"
 #include "helpers/DomainsDatabaseHelper.h"
 #include "helpers/SearchEngineHelper.h"
 #include "helpers/UserAgentHelper.h"
+#include "interceptors/UrlRequestInterceptor.h"
 #include "windows/BrowserWindow.h"
 
 // Qt framework headers.
@@ -162,7 +162,7 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload
         // Set the user agent.
         webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getResultingDomainSettingsUserAgent(domainRecord.field(DomainsDatabaseHelper::USER_AGENT).value().toString()));
 
-        // Check if a custom zoom factor is set.  This can be removed once <https://redmine.stoutner.com/issues/799> has been resolved.
+        // Check if a custom zoom factor is set.
         if (domainRecord.field(DomainsDatabaseHelper::ZOOM_FACTOR).value().toInt())
         {
             // Store the current zoom factor.
@@ -174,7 +174,7 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload
             currentZoomFactor = Settings::zoomFactor();
         }
 
-        // Set the zoom factor.
+        // Set the zoom factor.    The use of `currentZoomFactor` can be removed once <https://redmine.stoutner.com/issues/799> has been resolved.
         webEngineViewPointer->setZoomFactor(currentZoomFactor);
 
         // Apply the domain settings palette to the URL line edit.
@@ -188,11 +188,11 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload
         // Set the user agent.
         webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgentFromDatabaseName(Settings::userAgent()));
 
-        // Store the current zoom factor.
+        // Store the current zoom factor.  This can be removed once <https://redmine.stoutner.com/issues/799> has been resolved.
         currentZoomFactor = Settings::zoomFactor();
 
         // Set the zoom factor.
-        webEngineViewPointer->setZoomFactor(currentZoomFactor);
+        webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
 
         // Apply the no domain settings palette to the URL line edit.
         emit updateDomainSettingsIndicator(false);
@@ -237,8 +237,12 @@ void BrowserView::applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const
     webEngineViewPointer->reload();
 }
 
-void BrowserView::applyOnTheFlyZoomFactor(const double &zoomFactor) const
+// This can be const once <https://redmine.stoutner.com/issues/799> has been resolved.
+void BrowserView::applyOnTheFlyZoomFactor(const double &zoomFactor)
 {
+    // Update the current zoom factor.  This can be removed once <https://redmine.stoutner.com/issues/799> has been resolved.
+    currentZoomFactor = zoomFactor;
+
     // Set the zoom factor.
     webEngineViewPointer->setZoomFactor(zoomFactor);
 }
index 12f0274b9908513e868074c1dfaaebf67deeb949..6088a6384cf85e79f497045c2fdd0a87bf463e73 100644 (file)
@@ -39,7 +39,7 @@ public:
     explicit BrowserView(QWidget *parent);
 
     // The public functions.
-    void applyOnTheFlyZoomFactor(const double &zoomFactor) const;
+    void applyOnTheFlyZoomFactor(const double &zoomFactor);
     void loadInitialWebsite();
 
 signals:
index e2dd30109863fe8b8a4a7414aacd3a757ff5afc9..2d647948f21f8663a2b23d4aa3e5aa67860c479f 100644 (file)
@@ -511,7 +511,7 @@ void BrowserWindow::updateOnTheFlyUserAgent(const QString &userAgent) const
 void BrowserWindow::updateOnTheFlyZoomFactor(const double &zoomFactor)
 {
     // Set the current zoom factor.
-    currentZoomFactor = Settings::zoomFactor();
+    currentZoomFactor = zoomFactor;
 
     // Update the zoom factor action text, formatting the double with 2 decimal places.
     zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());