]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Only display the HTTP Ping dialog if it originates from the current tab. https:...
authorSoren Stoutner <soren@stoutner.com>
Fri, 24 Mar 2023 21:05:17 +0000 (14:05 -0700)
committerSoren Stoutner <soren@stoutner.com>
Fri, 24 Mar 2023 21:05:17 +0000 (14:05 -0700)
po/privacybrowser.pot
src/interceptors/UrlRequestInterceptor.cpp
src/interceptors/UrlRequestInterceptor.h
src/widgets/PrivacyWebEngineView.cpp
src/widgets/PrivacyWebEngineView.h
src/widgets/TabWidget.cpp

index 2372941ff0776adf47f919e8620d1c775b91158d..396fd4be4bfdee006dc88fbf1626e217e7c3e9c6 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright © 2022-2023 Soren Stoutner <soren@stoutner.com>.
+# Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
 #
 # This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
 #
index 83f104595ac8ab67e904d04b48b769b3c05556f8..5f9a8cc3a312bbc0759c5d57797edb84984acecb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
  *
@@ -23,9 +23,6 @@
 // KDE Framework headers.
 #include <KLocalizedString>
 
-// Qt framework headers.
-#include <QMessageBox>
-
 // Construct the class.
 UrlRequestInterceptor::UrlRequestInterceptor(QObject *parentObjectPointer) : QWebEngineUrlRequestInterceptor(parentObjectPointer) {}
 
@@ -37,27 +34,11 @@ void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &urlReques
         // A naughty HTTP ping request.
         case QWebEngineUrlRequestInfo::ResourceTypePing:
         {
-            // Block HTTP ping requests.
+            // Block the HTTP ping request.
             urlRequestInfo.block(true);
 
-            // Instantiate an HTTP ping blocked message box.
-            QMessageBox httpPingBlockedMessageBox;
-
-            // Set the icon.
-            httpPingBlockedMessageBox.setIcon(QMessageBox::Information);
-
-            // Set the window title.
-            httpPingBlockedMessageBox.setWindowTitle(i18nc("HTTP Ping blocked dialog title", "HTTP Ping Blocked"));
-
-            // Set the text.
-            httpPingBlockedMessageBox.setText(i18nc("HTTP Ping blocked dialog text", "This request has been blocked because it sends a naughty HTTP ping to %1.",
-                                                    urlRequestInfo.requestUrl().toString()));
-
-            // Set the standard button.
-            httpPingBlockedMessageBox.setStandardButtons(QMessageBox::Ok);
-
-            // Display the message box.
-            httpPingBlockedMessageBox.exec();
+            // Display the HTTP Ping blocked dialog.
+            emit displayHttpPingDialog(urlRequestInfo.requestUrl().toString());
 
             break;
         }
index 721d5231b3508deaea545650b29e94c77cbf5e2c..5638768529dbf5713460d88278c4aa15c4aaf0b5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
  *
@@ -37,6 +37,7 @@ public:
 
 signals:
     // The signals.
-    void applyDomainSettings(const QString hostname) const;
+    void applyDomainSettings(const QString &hostname) const;
+    void displayHttpPingDialog(const QString &httpPingUrl) const;
 };
 #endif
index 20ae259c96ebd1f4a3310093a4d18f535ad7cba0..96a0da5d67735743225293e0ca6a8db1990e5922 100644 (file)
@@ -51,7 +51,10 @@ PrivacyWebEngineView::PrivacyWebEngineView() : QWebEngineView(nullptr)
     webEngineProfilePointer->setUrlRequestInterceptor(urlRequestInterceptorPointer);
 
     // Reapply the domain settings when the host changes.
-    connect(urlRequestInterceptorPointer, SIGNAL(applyDomainSettings(QString)), this, SLOT(applyDomainSettingsWithoutReloading(QString)));
+    connect(urlRequestInterceptorPointer, SIGNAL(applyDomainSettings(const QString&)), this, SLOT(applyDomainSettingsWithoutReloading(const QString&)));
+
+    // Display HTTP Ping blocked dialogs.
+    connect(urlRequestInterceptorPointer, SIGNAL(displayHttpPingDialog(const QString&)), this, SLOT(displayHttpPingDialog(const QString&)));
 }
 
 void PrivacyWebEngineView::addCookieToList(const QNetworkCookie &cookie) const
@@ -288,6 +291,12 @@ QWebEngineView* PrivacyWebEngineView::createWindow(QWebEnginePage::WebWindowType
     }
 }
 
+void PrivacyWebEngineView::displayHttpPingDialog(const QString &httpPingUrl) const
+{
+    // Display the HTTP Ping blocked dialog.
+    emit displayHttpPingBlockedDialog(httpPingUrl);
+}
+
 void PrivacyWebEngineView::removeCookieFromList(const QNetworkCookie &cookie) const
 {
     //qDebug() << "Remove cookie:  " << cookie.toRawForm();
index 152c56e84f515c5979df2e26fb8b5b6f316dc40f..5548ec422dc56a567443c881f591621dedf255ea 100644 (file)
@@ -48,6 +48,7 @@ public:
 
 signals:
     // The signals.
+    void displayHttpPingBlockedDialog(const QString &httpPingUrl) const;
     void updateCookiesAction(const int numberOfCookies) const;
     void updateUi(const PrivacyWebEngineView *privacyWebEngineViewPointer) const;
 
@@ -59,6 +60,7 @@ public Q_SLOTS:
 private Q_SLOTS:
     // The private slots.
     void applyDomainSettingsWithoutReloading(const QString &hostname);
+    void displayHttpPingDialog(const QString &httpPingUrl) const;
 
 private:
     // The private variables.
index 2e32cab37320efa2364d1921a54bcf6b3c4fb965..ec555faa50c3bcf88884ece0143083cbe85ea431 100644 (file)
@@ -38,6 +38,7 @@
 #include <QFileDialog>
 #include <QGraphicsScene>
 #include <QGraphicsView>
+#include <QMessageBox>
 #include <QPrintDialog>
 #include <QPrintPreviewDialog>
 #include <QPrinter>
@@ -209,6 +210,32 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const
             emit hideProgressBar();
     });
 
+    // Display HTTP Ping blocked dialogs.
+    connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::displayHttpPingBlockedDialog, [privacyWebEngineViewPointer, this] (const QString &httpPingUrl)
+    {
+        // Only display the HTTP Ping blocked dialog if this is the current tab.
+        if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer)
+        {
+            // Instantiate an HTTP ping blocked message box.
+            QMessageBox httpPingBlockedMessageBox;
+
+            // Set the icon.
+            httpPingBlockedMessageBox.setIcon(QMessageBox::Information);
+
+            // Set the window title.
+            httpPingBlockedMessageBox.setWindowTitle(i18nc("HTTP Ping blocked dialog title", "HTTP Ping Blocked"));
+
+            // Set the text.
+            httpPingBlockedMessageBox.setText(i18nc("HTTP Ping blocked dialog text", "This request has been blocked because it sends a naughty HTTP ping to %1.", httpPingUrl));
+
+            // Set the standard button.
+            httpPingBlockedMessageBox.setStandardButtons(QMessageBox::Ok);
+
+            // Display the message box.
+            httpPingBlockedMessageBox.exec();
+        }
+    });
+
     // Update the zoom factor when changed by CTRL-Scrolling.  This can be modified when <https://redmine.stoutner.com/issues/845> is fixed.
     connect(webEnginePagePointer, &QWebEnginePage::contentsSizeChanged, [webEnginePagePointer, this] ()
     {