#include "BrowserView.h"
#include "Settings.h"
#include "ui_BrowserView.h"
+#include "databases/CookiesDatabase.h"
+#include "databases/DomainsDatabase.h"
#include "filters/MouseEventFilter.h"
-#include "helpers/DomainsDatabaseHelper.h"
#include "helpers/SearchEngineHelper.h"
#include "helpers/UserAgentHelper.h"
#include "interceptors/UrlRequestInterceptor.h"
// Set the local storage filter.
webEngineCookieStorePointer->setCookieFilter([this](const QWebEngineCookieStore::FilterRequest &filterRequest)
{
- // qDebug() << "Page URL: " << filterRequest.firstPartyUrl << ", Local storage URL: " << filterRequest.origin << ", Is third-party: " << filterRequest.thirdParty;
+ //qDebug().noquote().nospace() << "Page URL: " << filterRequest.firstPartyUrl << ", Local storage URL: " << filterRequest.origin << ", Is third-party: " << filterRequest.thirdParty;
// Block all third party local storage requests, including the sneaky ones that don't register a first party URL.
if (filterRequest.thirdParty || (filterRequest.firstPartyUrl == QStringLiteral("")))
+ {
+ //qDebug() << "Request blocked.";
+
+ // Return false.
return false;
+ }
+ /* TODO. Waiting for a solution to <https://redmine.stoutner.com/issues/857>.
// Check each tab to see if this local storage request should be allowed.
for (PrivacyWebEngine *privacyWebEnginePointer : *privacyWebEngineListPointer)
{
+ //qDebug().noquote().nospace() << "Local storage: " << privacyWebEnginePointer->localStorageEnabled << ". WebEngine URL: " << webEngineViewPointer->url().host() << ". Request Host: " << filterRequest.firstPartyUrl.host();
+
// Allow this local storage request if it comes from a tab with local storage enabled.
if (privacyWebEnginePointer->localStorageEnabled && (webEngineViewPointer->url().host() == filterRequest.firstPartyUrl.host()))
+ {
+ //qDebug() << "Request allowed.";
+
+ // Return true.
return true;
+ }
}
+ */
+
+ // Allow the request if it is first party and local storage is enabled.
+ if (!filterRequest.thirdParty && currentPrivacyWebEnginePointer->localStorageEnabled)
+ {
+ // Return true.
+ return true;
+ }
+
+ //qDebug() << "Request blocked.";
// Block any remaining local storage requests.
return false;
connect(webEngineCookieStorePointer, SIGNAL(cookieAdded(QNetworkCookie)), this, SLOT(cookieAdded(QNetworkCookie)));
connect(webEngineCookieStorePointer, SIGNAL(cookieRemoved(QNetworkCookie)), this, SLOT(cookieRemoved(QNetworkCookie)));
+ // Get a list of durable cookies.
+ QList<QNetworkCookie*> *durableCookiesListPointer = CookiesDatabase::getCookies();
+
+ // Add the durable cookies to the store.
+ for (QNetworkCookie *cookiePointer : *durableCookiesListPointer)
+ addCookieToStore(*cookiePointer);
+
// Store a copy of the WebEngine default user agent.
webEngineDefaultUserAgent = webEngineProfilePointer->httpUserAgent();
webEnginePagePointer->deleteLater();
}
-void BrowserView::addCookieToStore(QNetworkCookie &cookie) const
+// The cookie is copied instead of referenced so that changes made to the cookie do not create a race condition with the display of the cookie in the dialog.
+void BrowserView::addCookieToStore(QNetworkCookie cookie) const
{
// Create a url.
QUrl url;
void BrowserView::applyDomainSettings(const QString &hostname, const bool reloadWebsite)
{
// Get the record for the hostname.
- QSqlQuery domainQuery = DomainsDatabaseHelper::getDomainQuery(hostname);
+ QSqlQuery domainQuery = DomainsDatabase::getDomainQuery(hostname);
// Check if the hostname has domain settings.
if (domainQuery.isValid()) // The hostname has domain settings.
QSqlRecord domainRecord = domainQuery.record();
// Set the JavaScript status.
- switch (domainRecord.field(DomainsDatabaseHelper::JAVASCRIPT).value().toInt())
+ switch (domainRecord.field(DomainsDatabase::JAVASCRIPT).value().toInt())
{
// Set the default JavaScript status.
- case (DomainsDatabaseHelper::SYSTEM_DEFAULT):
+ case (DomainsDatabase::SYSTEM_DEFAULT):
{
webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScriptEnabled());
}
// Disable JavaScript.
- case (DomainsDatabaseHelper::DISABLED):
+ case (DomainsDatabase::DISABLED):
{
webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
}
// Enable JavaScript.
- case (DomainsDatabaseHelper::ENABLED):
+ case (DomainsDatabase::ENABLED):
{
webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
}
// Set the local storage status.
- switch (domainRecord.field(DomainsDatabaseHelper::LOCAL_STORAGE).value().toInt())
+ switch (domainRecord.field(DomainsDatabase::LOCAL_STORAGE).value().toInt())
{
// Set the default local storage status.
- case (DomainsDatabaseHelper::SYSTEM_DEFAULT):
+ case (DomainsDatabase::SYSTEM_DEFAULT):
{
currentPrivacyWebEnginePointer->localStorageEnabled = Settings::localStorageEnabled();
}
// Disable local storage.
- case (DomainsDatabaseHelper::DISABLED):
+ case (DomainsDatabase::DISABLED):
{
currentPrivacyWebEnginePointer->localStorageEnabled = false;
}
// Enable local storage.
- case (DomainsDatabaseHelper::ENABLED):
+ case (DomainsDatabase::ENABLED):
{
currentPrivacyWebEnginePointer->localStorageEnabled = true;
}
// Set the DOM storage status.
- switch (domainRecord.field(DomainsDatabaseHelper::DOM_STORAGE).value().toInt())
+ switch (domainRecord.field(DomainsDatabase::DOM_STORAGE).value().toInt())
{
// Set the default DOM storage status.
- case (DomainsDatabaseHelper::SYSTEM_DEFAULT):
+ case (DomainsDatabase::SYSTEM_DEFAULT):
{
webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, Settings::domStorageEnabled());
}
// Disable DOM storage.
- case (DomainsDatabaseHelper::DISABLED):
+ case (DomainsDatabase::DISABLED):
{
webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, false);
}
// Enable DOM storage.
- case (DomainsDatabaseHelper::ENABLED):
+ case (DomainsDatabase::ENABLED):
{
webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, true);
}
// Set the user agent.
- webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getResultingDomainSettingsUserAgent(domainRecord.field(DomainsDatabaseHelper::USER_AGENT).value().toString()));
+ webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getResultingDomainSettingsUserAgent(domainRecord.field(DomainsDatabase::USER_AGENT).value().toString()));
// Check if a custom zoom factor is set.
- if (domainRecord.field(DomainsDatabaseHelper::ZOOM_FACTOR).value().toInt())
+ if (domainRecord.field(DomainsDatabase::ZOOM_FACTOR).value().toInt())
{
// Store the current zoom factor.
- currentZoomFactor = domainRecord.field(DomainsDatabaseHelper::CUSTOM_ZOOM_FACTOR).value().toDouble();
+ currentZoomFactor = domainRecord.field(DomainsDatabase::CUSTOM_ZOOM_FACTOR).value().toDouble();
}
else
{
webEngineViewPointer->setZoomFactor(currentZoomFactor);
// Apply the domain settings palette to the URL line edit.
- emit updateDomainSettingsIndicator(true, domainRecord.field(DomainsDatabaseHelper::DOMAIN_NAME).value().toString());
+ emit updateDomainSettingsIndicator(true, domainRecord.field(DomainsDatabase::DOMAIN_NAME).value().toString());
}
else // The hostname does not have domain settings.
{
void BrowserView::mouseBack() const
{
// Go back if possible.
- if (webEngineHistoryPointer->canGoBack())
+ if (webEngineViewPointer->isActiveWindow() && webEngineHistoryPointer->canGoBack())
{
// Clear the URL line edit focus.
emit clearUrlLineEditFocus();
void BrowserView::mouseForward() const
{
// Go forward if possible.
- if (webEngineHistoryPointer->canGoForward())
+ if (webEngineViewPointer->isActiveWindow() && webEngineHistoryPointer->canGoForward())
{
// Clear the URL line edit focus.
emit clearUrlLineEditFocus();