X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=src%2Fwidgets%2FPrivacyWebEngineView.cpp;h=8f61f9156acd62994e26da68eab4dbb845a8cc8d;hb=e5ec85accb02116b08c33b574805c132475d90bc;hp=bc207cb21c94d5823b832642bb59ac193739a68a;hpb=8756d450d1d44dd8e840f7e3de7b1d72ca5b7d8e;p=PrivacyBrowserPC.git diff --git a/src/widgets/PrivacyWebEngineView.cpp b/src/widgets/PrivacyWebEngineView.cpp index bc207cb..8f61f91 100644 --- a/src/widgets/PrivacyWebEngineView.cpp +++ b/src/widgets/PrivacyWebEngineView.cpp @@ -30,7 +30,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,13 +45,16 @@ 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); // 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 @@ -83,14 +86,11 @@ void PrivacyWebEngineView::applyDomainSettings(const QString &hostname, const bo // Check if the hostname has domain settings. if (domainQuery.isValid()) // The hostname has domain settings. { - // Get the domain record. - QSqlRecord domainRecord = domainQuery.record(); - // Store the domain settings name. - domainSettingsName = domainRecord.field(DomainsDatabase::DOMAIN_NAME).value().toString(); + domainSettingsName = domainQuery.value(DomainsDatabase::DOMAIN_NAME).toString(); // Set the JavaScript status. - switch (domainRecord.field(DomainsDatabase::JAVASCRIPT).value().toInt()) + switch (domainQuery.value(DomainsDatabase::JAVASCRIPT).toInt()) { // Set the default JavaScript status. case (DomainsDatabase::SYSTEM_DEFAULT): @@ -100,25 +100,25 @@ void PrivacyWebEngineView::applyDomainSettings(const QString &hostname, const bo break; } - // Disable JavaScript. - case (DomainsDatabase::DISABLED): + // Enable JavaScript. + case (DomainsDatabase::ENABLED): { - webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, false); + webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, true); break; } - // Enable JavaScript. - case (DomainsDatabase::ENABLED): + // Disable JavaScript. + case (DomainsDatabase::DISABLED): { - webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, true); + webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, false); break; } } // Set the local storage status. - switch (domainRecord.field(DomainsDatabase::LOCAL_STORAGE).value().toInt()) + switch (domainQuery.value(DomainsDatabase::LOCAL_STORAGE).toInt()) { // Set the default local storage status. case (DomainsDatabase::SYSTEM_DEFAULT): @@ -128,25 +128,25 @@ void PrivacyWebEngineView::applyDomainSettings(const QString &hostname, const bo break; } - // Disable local storage. - case (DomainsDatabase::DISABLED): + // Enable local storage. + case (DomainsDatabase::ENABLED): { - localStorageEnabled = false; + localStorageEnabled = true; break; } - // Enable local storage. - case (DomainsDatabase::ENABLED): + // Disable local storage. + case (DomainsDatabase::DISABLED): { - localStorageEnabled = true; + localStorageEnabled = false; break; } } // Set the DOM storage status. - switch (domainRecord.field(DomainsDatabase::DOM_STORAGE).value().toInt()) + switch (domainQuery.value(DomainsDatabase::DOM_STORAGE).toInt()) { // Set the default DOM storage status. QWebEngineSettings confusingly calls this local storage. case (DomainsDatabase::SYSTEM_DEFAULT): @@ -156,36 +156,36 @@ void PrivacyWebEngineView::applyDomainSettings(const QString &hostname, const bo break; } - // Disable DOM storage. QWebEngineSettings confusingly calls this local storage. - case (DomainsDatabase::DISABLED): + // Enable DOM storage. QWebEngineSettings confusingly calls this local storage. + case (DomainsDatabase::ENABLED): { - webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, false); + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, true); break; } - // Enable DOM storage. QWebEngineSettings confusingly calls this local storage. - case (DomainsDatabase::ENABLED): + // Disable DOM storage. QWebEngineSettings confusingly calls this local storage. + case (DomainsDatabase::DISABLED): { - webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, true); + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, false); break; } } // Set the user agent. - webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getResultingDomainSettingsUserAgent(domainRecord.field(DomainsDatabase::USER_AGENT).value().toString())); + webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getResultingDomainSettingsUserAgent(domainQuery.value(DomainsDatabase::USER_AGENT).toString())); // Check if a custom zoom factor is set. - if (domainRecord.field(DomainsDatabase::ZOOM_FACTOR).value().toInt()) + if (domainQuery.value(DomainsDatabase::ZOOM_FACTOR).toInt()) { // Store the current zoom factor. - setZoomFactor(domainRecord.field(DomainsDatabase::CUSTOM_ZOOM_FACTOR).value().toDouble()); + defaultZoomFactor = domainQuery.value(DomainsDatabase::CUSTOM_ZOOM_FACTOR).toDouble(); } else { - // Reset the current zoom factor. - setZoomFactor(Settings::zoomFactor()); + // Store the current zoom factor. + defaultZoomFactor = Settings::zoomFactor(); } } else // The hostname does not have domain settings. @@ -205,10 +205,13 @@ void PrivacyWebEngineView::applyDomainSettings(const QString &hostname, const bo // Set the user agent. webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgentFromDatabaseName(Settings::userAgent())); - // Set the zoom factor. - setZoomFactor(Settings::zoomFactor()); + // Store the zoom factor. + defaultZoomFactor = Settings::zoomFactor(); } + // Set the current zoom factor. + setZoomFactor(defaultZoomFactor); + // Reload the website if requested. if (reloadWebsite) reload(); @@ -229,7 +232,19 @@ void PrivacyWebEngineView::contextMenuEvent(QContextMenuEvent *contextMenuEvent) // Add the open link in new background tab action if the context menu already contains the open link in new window action. if (contextMenuActionsList.contains(webEnginePagePointer->action(QWebEnginePage::OpenLinkInNewWindow))) - contextMenu->insertAction(webEnginePagePointer->action(QWebEnginePage::OpenLinkInNewWindow), webEnginePagePointer->action(QWebEnginePage::OpenLinkInNewBackgroundTab)); + { + // Move the open in new tab action to the top of the list. + contextMenu->insertAction(webEnginePagePointer->action(QWebEnginePage::Back), webEnginePagePointer->action(QWebEnginePage::OpenLinkInNewTab)); + + // Add the open link in background tab action below the open in new tab action. + contextMenu->insertAction(webEnginePagePointer->action(QWebEnginePage::Back), webEnginePagePointer->action(QWebEnginePage::OpenLinkInNewBackgroundTab)); + + // Move the open in new window action below the open in background tab action. + contextMenu->insertAction(webEnginePagePointer->action(QWebEnginePage::Back), webEnginePagePointer->action(QWebEnginePage::OpenLinkInNewWindow)); + + // Add a separator below the open in new window action. + contextMenu->insertSeparator(webEnginePagePointer->action(QWebEnginePage::Back)); + } // Display the menu using the location in the context menu event. contextMenu->popup(contextMenuEvent->globalPos()); @@ -276,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();