From ce90749b5fc2c4a3fcee6daee60c0d6e2aa0e1d6 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Fri, 22 Mar 2024 13:31:39 -0700 Subject: [PATCH] Fix HTTP authentication dialogs displaying indefinitely. https://redmine.stoutner.com/issues/1180 --- src/widgets/PrivacyWebEngineView.cpp | 17 +++++++++++++---- src/widgets/PrivacyWebEngineView.h | 1 + src/widgets/TabWidget.cpp | 3 +++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/widgets/PrivacyWebEngineView.cpp b/src/widgets/PrivacyWebEngineView.cpp index 6080288..42c331f 100644 --- a/src/widgets/PrivacyWebEngineView.cpp +++ b/src/widgets/PrivacyWebEngineView.cpp @@ -221,6 +221,9 @@ void PrivacyWebEngineView::applyDomainSettings(const QString &hostname, const bo if (reloadWebsite) reload(); + // Reset the HTTP authentication dialog counter. + httpAuthenticationDialogsDisplayed = 0; + // Update the UI. emit updateUi(this); } @@ -305,11 +308,17 @@ void PrivacyWebEngineView::displayHttpPingDialog(const QString &httpPingUrl) con void PrivacyWebEngineView::handleAuthenticationRequest(const QUrl &requestUrl, QAuthenticator *authenticatorPointer) { - // Instantiate an HTTP authentication dialog. - HttpAuthenticationDialog *httpAuthenticationDialogPointer = new HttpAuthenticationDialog(parentWidget(), requestUrl, authenticatorPointer); + // Only display the HTTP authentication dialog if it hasn't already been displayed three times for this URL. + if (httpAuthenticationDialogsDisplayed < 3) { + // Increment the HTTP authentication dialog display counter. + ++httpAuthenticationDialogsDisplayed; + + // Instantiate an HTTP authentication dialog. + HttpAuthenticationDialog *httpAuthenticationDialogPointer = new HttpAuthenticationDialog(parentWidget(), requestUrl, authenticatorPointer); - // Display the dialog. This must be `exec()` instead of `show()` so that the website doesn't proceed before populating the authentication pointer. - httpAuthenticationDialogPointer->exec(); + // Display the dialog. This must be `exec()` instead of `show()` so that the website doesn't proceed before populating the authentication pointer. + httpAuthenticationDialogPointer->exec(); + } } void PrivacyWebEngineView::removeCookieFromList(const QNetworkCookie &cookie) const diff --git a/src/widgets/PrivacyWebEngineView.h b/src/widgets/PrivacyWebEngineView.h index 4f621ce..95cc69f 100644 --- a/src/widgets/PrivacyWebEngineView.h +++ b/src/widgets/PrivacyWebEngineView.h @@ -46,6 +46,7 @@ public: bool findCaseSensitive = false; QString findString = QLatin1String(""); QWebEngineFindTextResult findTextResult = QWebEngineFindTextResult(); + int httpAuthenticationDialogsDisplayed = 0; bool isLoading = false; int loadProgressInt = -1; bool localStorageEnabled = false; diff --git a/src/widgets/TabWidget.cpp b/src/widgets/TabWidget.cpp index bdc541c..f65c79e 100644 --- a/src/widgets/TabWidget.cpp +++ b/src/widgets/TabWidget.cpp @@ -906,6 +906,9 @@ void TabWidget::printWebpage(QPrinter *printerPointer) const void TabWidget::refresh() const { + // Reset the HTTP authentication dialog counter. + currentPrivacyWebEngineViewPointer->httpAuthenticationDialogsDisplayed = 0; + // Reload the website. currentPrivacyWebEngineViewPointer->reload(); } -- 2.43.0