X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=blobdiff_plain;f=src%2Fviews%2FBrowserView.cpp;h=07ce5f5d897039339513fa075e6ed401d3d67906;hp=933a300816208a1ad3528b29fb429f8cab742564;hb=8933c941521c591a962034ecf3486c9143bf1f80;hpb=455108aa18c90514c0dad3c12dfea98180dfb471 diff --git a/src/views/BrowserView.cpp b/src/views/BrowserView.cpp index 933a300..07ce5f5 100644 --- a/src/views/BrowserView.cpp +++ b/src/views/BrowserView.cpp @@ -19,9 +19,9 @@ // Application headers. #include "BrowserView.h" -#include "MouseEventFilter.h" #include "Settings.h" #include "ui_BrowserView.h" +#include "filters/MouseEventFilter.h" #include "helpers/DomainsDatabaseHelper.h" #include "helpers/SearchEngineHelper.h" #include "helpers/UserAgentHelper.h" @@ -30,7 +30,9 @@ // Qt framework headers. #include -#include + +// Initialize the public static variables. +QString BrowserView::webEngineDefaultUserAgent = QStringLiteral(""); BrowserView::BrowserView(QWidget *parent) : QWidget(parent) { @@ -43,11 +45,25 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent) // Get handles for the views. webEngineViewPointer = browserViewUi.webEngineView; + // Create an off-the-record profile (the default when no profile name is specified). + webEngineProfilePointer = new QWebEngineProfile(QStringLiteral("")); + + // Create a WebEngine page. + webEnginePagePointer = new QWebEnginePage(webEngineProfilePointer); + + // Set the WebEngine page. + webEngineViewPointer->setPage(webEnginePagePointer); + // Get handles for the aspects of the WebEngine. - QWebEnginePage *webEnginePagePointer = webEngineViewPointer->page(); webEngineHistoryPointer = webEnginePagePointer->history(); - webEngineProfilePointer = webEnginePagePointer->profile(); webEngineSettingsPointer = webEngineViewPointer->settings(); + webEngineCookieStorePointer = webEngineProfilePointer->cookieStore(); + + // Store a copy of each cookie when it is added. + connect(webEngineCookieStorePointer, SIGNAL(cookieAdded(QNetworkCookie)), this, SLOT(cookieAdded(QNetworkCookie))); + + // Store a copy of the WebEngine default user agent. + webEngineDefaultUserAgent = webEngineProfilePointer->httpUserAgent(); // Update the URL line edit when the URL changes. connect(webEngineViewPointer, SIGNAL(urlChanged(const QUrl)), this, SLOT(updateUrl(const QUrl))); @@ -58,11 +74,15 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent) connect(webEngineViewPointer, SIGNAL(loadFinished(const bool)), this, SLOT(loadFinished())); // Instantiate the mouse event filter pointer. - MouseEventFilter *mouseEventFilterPointer = new MouseEventFilter(webEngineViewPointer); + MouseEventFilter *mouseEventFilterPointer = new MouseEventFilter(); // Install the mouse event filter. qApp->installEventFilter(mouseEventFilterPointer); + // Process mouse forward and back commands. + connect(mouseEventFilterPointer, SIGNAL(mouseBack()), this, SLOT(mouseBack())); + connect(mouseEventFilterPointer, SIGNAL(mouseForward()), this, SLOT(mouseForward())); + // Listen for hovered link URLs. connect(webEnginePagePointer, SIGNAL(linkHovered(const QString)), this, SLOT(pageLinkHovered(const QString))); @@ -75,9 +95,6 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent) // Reapply the domain settings when the host changes. connect(urlRequestInterceptorPointer, SIGNAL(applyDomainSettings(QString)), this, SLOT(applyDomainSettingsWithoutReloading(QString))); - // Disable the cache. - webEngineProfilePointer->setHttpCacheType(QWebEngineProfile::NoCache); - // Don't allow JavaScript to open windows. webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, false); @@ -97,6 +114,12 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent) webEngineViewPointer->setFocus(); } +BrowserView::~BrowserView() +{ + // Delay the deletion of the WebEngine page to prevent the following error: `Release of profile requested but WebEnginePage still not deleted. Expect troubles !` + webEnginePagePointer->deleteLater(); +} + void BrowserView::applyApplicationSettings() { // Set the search engine URL. @@ -209,7 +232,7 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload webEngineViewPointer->setZoomFactor(currentZoomFactor); // Apply the domain settings palette to the URL line edit. - emit updateDomainSettingsIndicator(true); + emit updateDomainSettingsIndicator(true, domainRecord.field(DomainsDatabaseHelper::DOMAIN_NAME).value().toString()); } else // The hostname does not have domain settings. { @@ -229,7 +252,7 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload webEngineViewPointer->setZoomFactor(Settings::zoomFactor()); // Apply the no domain settings palette to the URL line edit. - emit updateDomainSettingsIndicator(false); + emit updateDomainSettingsIndicator(false, QStringLiteral("")); } // Emit the update actions signals. @@ -288,6 +311,18 @@ void BrowserView::back() const webEngineViewPointer->back(); } +void BrowserView::cookieAdded(const QNetworkCookie &cookie) const +{ + // Add the cookie to the cookie list. + emit addCookie(cookie); +} + +void BrowserView::deleteAllCookies() const +{ + // Delete all the cookies. + webEngineCookieStorePointer->deleteAllCookies(); +} + void BrowserView::forward() const { // Go forward. @@ -366,6 +401,32 @@ void BrowserView::loadUrlFromLineEdit(QString url) const } } +void BrowserView::mouseBack() const +{ + // Go back if possible. + if (webEngineHistoryPointer->canGoBack()) + { + // Clear the URL line edit focus. + emit clearUrlLineEditFocus(); + + // Go back. + webEngineViewPointer->back(); + } +} + +void BrowserView::mouseForward() const +{ + // Go forward if possible. + if (webEngineHistoryPointer->canGoForward()) + { + // Clear the URL line edit focus. + emit clearUrlLineEditFocus(); + + // Go forward. + webEngineViewPointer->forward(); + } +} + void BrowserView::pageLinkHovered(const QString &linkUrl) const { // Emit a signal so that the browser window can update the status bar. @@ -405,7 +466,7 @@ void BrowserView::toggleLocalStorage() const void BrowserView::updateUrl(const QUrl &url) const { // Update the URL line edit. - emit updateUrlLineEdit(url.toString()); + emit updateUrlLineEdit(url); // Update the status of the forward and back buttons. emit updateBackAction(webEngineHistoryPointer->canGoBack());