#include <QMenu>
// 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(""));
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
// 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):
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):
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):
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.
// 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();
// 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());
}
}
+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();