X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=src%2Fwidgets%2FPrivacyWebEngineView.cpp;h=6080288e4f5b4238404e8e13795e305f2fd9c65e;hb=3ea5ede1fd0721bea6813f36388ba6387bdbfcfe;hp=38b03c31fa37c7fa3d8476dc6741897baafc3a4d;hpb=425fed98271cd951cddef9904e5e271f0fb76fc1;p=PrivacyBrowserPC.git diff --git a/src/widgets/PrivacyWebEngineView.cpp b/src/widgets/PrivacyWebEngineView.cpp index 38b03c3..6080288 100644 --- a/src/widgets/PrivacyWebEngineView.cpp +++ b/src/widgets/PrivacyWebEngineView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Soren Stoutner . + * Copyright 2022-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -20,8 +20,10 @@ // Application headers. #include "PrivacyWebEngineView.h" #include "Settings.h" +#include "ui_HttpAuthenticationDialog.h" #include "databases/CookiesDatabase.h" #include "databases/DomainsDatabase.h" +#include "dialogs/HttpAuthenticationDialog.h" #include "interceptors/UrlRequestInterceptor.h" #include "windows/BrowserWindow.h" @@ -30,7 +32,7 @@ #include // Construct the class. -PrivacyWebEngineView::PrivacyWebEngineView() : QWebEngineView(nullptr) +PrivacyWebEngineView::PrivacyWebEngineView(QWidget *parentWidgetPointer) : QWebEngineView(parentWidgetPointer) { // Create an off-the-record profile (the default when no profile name is specified). webEngineProfilePointer = new QWebEngineProfile(QLatin1String("")); @@ -45,7 +47,7 @@ PrivacyWebEngineView::PrivacyWebEngineView() : QWebEngineView(nullptr) webEngineSettingsPointer = webEnginePagePointer->settings(); // Instantiate the URL request interceptor. - UrlRequestInterceptor *urlRequestInterceptorPointer = new UrlRequestInterceptor(); + UrlRequestInterceptor *urlRequestInterceptorPointer = new UrlRequestInterceptor(this); // Set the URL request interceptor. webEngineProfilePointer->setUrlRequestInterceptor(urlRequestInterceptorPointer); @@ -55,6 +57,9 @@ PrivacyWebEngineView::PrivacyWebEngineView() : QWebEngineView(nullptr) // Display HTTP Ping blocked dialogs. connect(urlRequestInterceptorPointer, SIGNAL(displayHttpPingDialog(const QString&)), this, SLOT(displayHttpPingDialog(const QString&))); + + // Handle HTTP authentication requests. + connect(webEnginePagePointer, SIGNAL(authenticationRequired(const QUrl&, QAuthenticator*)), this, SLOT(handleAuthenticationRequest(const QUrl&, QAuthenticator*))); } void PrivacyWebEngineView::addCookieToList(const QNetworkCookie &cookie) const @@ -259,9 +264,9 @@ QWebEngineView* PrivacyWebEngineView::createWindow(QWebEnginePage::WebWindowType { case QWebEnginePage::WebBrowserTab: { - // Create the new tab and return the privacy WebEngine view pointer. `true` removes the focus from the blank URL line edit. + // Create the new tab and return the privacy WebEngine view pointer. `true` removes the focus from the blank URL line edit. `true` adds the new tab adjacent to the current tab. // The new privacy WebEngine view pointer is returned so it can be populated with the link from the context menu. - return browserWindowPointer->tabWidgetPointer->addTab(true); + return browserWindowPointer->tabWidgetPointer->addTab(true, true); } case QWebEnginePage::WebBrowserWindow: @@ -278,9 +283,10 @@ QWebEngineView* PrivacyWebEngineView::createWindow(QWebEnginePage::WebWindowType case QWebEnginePage::WebBrowserBackgroundTab: { - // Create the new tab and return the privacy WebEngine view pointer. `false` does not clear the URL line edit. `true` creates a background tab. + // Create the new tab and return the privacy WebEngine view pointer. `false` does not clear the URL line edit. `true` adds the new tab adjacent to the current tab. + // `true` creates a background tab. // The new privacy WebEngine view pointer is returned so it can be populated with the link from the context menu. - return browserWindowPointer->tabWidgetPointer->addTab(false, true); + return browserWindowPointer->tabWidgetPointer->addTab(false, true, true); } default: @@ -297,6 +303,15 @@ void PrivacyWebEngineView::displayHttpPingDialog(const QString &httpPingUrl) con emit displayHttpPingBlockedDialog(httpPingUrl); } +void PrivacyWebEngineView::handleAuthenticationRequest(const QUrl &requestUrl, QAuthenticator *authenticatorPointer) +{ + // 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(); +} + void PrivacyWebEngineView::removeCookieFromList(const QNetworkCookie &cookie) const { //qDebug() << "Remove cookie: " << cookie.toRawForm();