X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=blobdiff_plain;f=src%2Fviews%2FBrowserView.cpp;h=2e29ea0caf9fd515690e9205f498cdd621659c20;hp=21e1493aaa63c7482314936ac664e85f889d8825;hb=2e5db0d355267f5823610100947970af12ca6342;hpb=9514cabb5648123b68264e595e9ffef6261bd215 diff --git a/src/views/BrowserView.cpp b/src/views/BrowserView.cpp index 21e1493..2e29ea0 100644 --- a/src/views/BrowserView.cpp +++ b/src/views/BrowserView.cpp @@ -32,6 +32,9 @@ #include #include +// Initialize the public static variables. +QString BrowserView::webEngineDefaultUserAgent = QStringLiteral(""); + BrowserView::BrowserView(QWidget *parent) : QWidget(parent) { // Instantiate the browser view UI. @@ -43,12 +46,22 @@ 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. + QWebEnginePage *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(); + // 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))); @@ -75,9 +88,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); @@ -162,6 +172,34 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload } } + // Set local storage. + switch (domainRecord.field(DomainsDatabaseHelper::LOCAL_STORAGE).value().toInt()) + { + case (DomainsDatabaseHelper::SYSTEM_DEFAULT): + { + // Set the default local storage status. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, Settings::localStorage()); + + break; + } + + case (DomainsDatabaseHelper::DISABLED): + { + // Disable local storage. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, false); + + break; + } + + case (DomainsDatabaseHelper::ENABLED): + { + // Enable local storage. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, true); + + break; + } + } + // Set the user agent. webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getResultingDomainSettingsUserAgent(domainRecord.field(DomainsDatabaseHelper::USER_AGENT).value().toString())); @@ -181,13 +219,16 @@ 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. { // Set the JavaScript status. webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScript()); + // Set local storage. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, Settings::localStorage()); + // Set the user agent. webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgentFromDatabaseName(Settings::userAgent())); @@ -198,11 +239,12 @@ 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. emit updateJavaScriptAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled)); + emit updateLocalStorageAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); emit updateUserAgentActions(webEngineProfilePointer->httpUserAgent()); emit updateZoomFactorAction(webEngineViewPointer->zoomFactor()); @@ -358,10 +400,22 @@ void BrowserView::toggleJavaScript() const webEngineViewPointer->reload(); } +void BrowserView::toggleLocalStorage() const +{ + // Toggle local storage. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, !webEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); + + // Update the local storage icon. + emit updateLocalStorageAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); + + // Reload the website. + webEngineViewPointer->reload(); +} + 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());