From: Soren Stoutner Date: Fri, 24 Mar 2023 21:05:17 +0000 (-0700) Subject: Only display the HTTP Ping dialog if it originates from the current tab. https:... X-Git-Tag: v0.2~4 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=3108332092c1c2807f1e13c417c487fd07aed177;p=PrivacyBrowserPC.git Only display the HTTP Ping dialog if it originates from the current tab. https://redmine.stoutner.com/issues/979 --- diff --git a/po/privacybrowser.pot b/po/privacybrowser.pot index 2372941..396fd4b 100644 --- a/po/privacybrowser.pot +++ b/po/privacybrowser.pot @@ -1,4 +1,4 @@ -# Copyright © 2022-2023 Soren Stoutner . +# Copyright 2022-2023 Soren Stoutner . # # This file is part of Privacy Browser PC . # diff --git a/src/interceptors/UrlRequestInterceptor.cpp b/src/interceptors/UrlRequestInterceptor.cpp index 83f1045..5f9a8cc 100644 --- a/src/interceptors/UrlRequestInterceptor.cpp +++ b/src/interceptors/UrlRequestInterceptor.cpp @@ -1,5 +1,5 @@ /* - * Copyright © 2022 Soren Stoutner . + * Copyright 2022-2023 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -23,9 +23,6 @@ // KDE Framework headers. #include -// Qt framework headers. -#include - // 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; } diff --git a/src/interceptors/UrlRequestInterceptor.h b/src/interceptors/UrlRequestInterceptor.h index 721d523..5638768 100644 --- a/src/interceptors/UrlRequestInterceptor.h +++ b/src/interceptors/UrlRequestInterceptor.h @@ -1,5 +1,5 @@ /* - * Copyright © 2022 Soren Stoutner . + * Copyright 2022-2023 Soren Stoutner . * * This file is part of 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 diff --git a/src/widgets/PrivacyWebEngineView.cpp b/src/widgets/PrivacyWebEngineView.cpp index 20ae259..96a0da5 100644 --- a/src/widgets/PrivacyWebEngineView.cpp +++ b/src/widgets/PrivacyWebEngineView.cpp @@ -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(); diff --git a/src/widgets/PrivacyWebEngineView.h b/src/widgets/PrivacyWebEngineView.h index 152c56e..5548ec4 100644 --- a/src/widgets/PrivacyWebEngineView.h +++ b/src/widgets/PrivacyWebEngineView.h @@ -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. diff --git a/src/widgets/TabWidget.cpp b/src/widgets/TabWidget.cpp index 2e32cab..ec555fa 100644 --- a/src/widgets/TabWidget.cpp +++ b/src/widgets/TabWidget.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -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 is fixed. connect(webEnginePagePointer, &QWebEnginePage::contentsSizeChanged, [webEnginePagePointer, this] () {