mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
Add preliminary Cookie support
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
parent
90ec7bcf99
commit
3b259711f4
@ -21,6 +21,7 @@
|
||||
#include "autosaver.h"
|
||||
#include "settings.h"
|
||||
#include "qztools.h"
|
||||
#include "sitesettingsmanager.h"
|
||||
|
||||
#include <QNetworkCookie>
|
||||
#include <QWebEngineProfile>
|
||||
@ -134,24 +135,20 @@ void CookieJar::slotCookieRemoved(const QNetworkCookie &cookie)
|
||||
|
||||
bool CookieJar::cookieFilter(const QWebEngineCookieStore::FilterRequest &request) const
|
||||
{
|
||||
if (!m_allowCookies) {
|
||||
bool result = listMatchesDomain(m_whitelist, request.origin.host());
|
||||
if (!result) {
|
||||
auto result = mApp->siteSettingsManager()->getPermission(SiteSettingsManager::poAllowCookies, request.origin);
|
||||
|
||||
if (!m_allowCookies && (result != SiteSettingsManager::Allow)) {
|
||||
#ifdef COOKIE_DEBUG
|
||||
qDebug() << "not in whitelist" << request.origin;
|
||||
qDebug() << "Cookies not allowed" << request.origin;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_allowCookies) {
|
||||
bool result = listMatchesDomain(m_blacklist, request.origin.host());
|
||||
if (result) {
|
||||
if (m_allowCookies && (result == SiteSettingsManager::Deny)) {
|
||||
#ifdef COOKIE_DEBUG
|
||||
qDebug() << "found in blacklist" << request.origin.host();
|
||||
qDebug() << "Cookies denied" << request.origin;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_filterThirdParty && request.thirdParty) {
|
||||
@ -168,24 +165,20 @@ bool CookieJar::rejectCookie(const QString &domain, const QNetworkCookie &cookie
|
||||
{
|
||||
Q_UNUSED(domain)
|
||||
|
||||
if (!m_allowCookies) {
|
||||
bool result = listMatchesDomain(m_whitelist, cookieDomain);
|
||||
if (!result) {
|
||||
auto result = mApp->siteSettingsManager()->getPermission(SiteSettingsManager::poAllowCookies, cookieDomain);
|
||||
|
||||
if (!m_allowCookies && (result != SiteSettingsManager::Allow)) {
|
||||
#ifdef COOKIE_DEBUG
|
||||
qDebug() << "not in whitelist" << cookie;
|
||||
qDebug() << "Cookies not allowed" << cookie;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_allowCookies) {
|
||||
bool result = listMatchesDomain(m_blacklist, cookieDomain);
|
||||
if (result) {
|
||||
if (m_allowCookies && (result == SiteSettingsManager::Deny)) {
|
||||
#ifdef COOKIE_DEBUG
|
||||
qDebug() << "found in blacklist" << cookie;
|
||||
qDebug() << "Cookies denied" << cookie;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef QTWEBENGINE_DISABLED
|
||||
|
@ -353,6 +353,8 @@ void SiteInfo::addSiteSettings()
|
||||
SiteInfoPermissionItem *item = addPermissionOption(siteSettings.features[feature]);
|
||||
item->setFeature(feature);
|
||||
}
|
||||
SiteInfoPermissionItem *item = addPermissionOption(siteSettings.AllowCookies);
|
||||
item->setOption(SiteSettingsManager::poAllowCookies);
|
||||
}
|
||||
|
||||
void SiteInfo::saveSiteSettings()
|
||||
@ -370,7 +372,8 @@ void SiteInfo::saveSiteSettings()
|
||||
auto* item = static_cast<SiteInfoPermissionItem*>(ui->listPermissions->itemWidget(ui->listPermissions->item(index)));
|
||||
siteSettings.features[supportedFeatures[i]] = item->permission();
|
||||
}
|
||||
siteSettings.AllowCookies = SiteSettingsManager::Default;
|
||||
auto* item = static_cast<SiteInfoPermissionItem*>(ui->listPermissions->itemWidget(ui->listPermissions->item(index++)));
|
||||
siteSettings.AllowCookies = item->permission();
|
||||
siteSettings.ZoomLevel = -1;
|
||||
|
||||
siteSettings.server = m_baseUrl.host();
|
||||
|
@ -273,7 +273,7 @@ void SiteSettingsManager::setOption(const QWebEngineSettings::WebAttribute& attr
|
||||
setOption(webAttributeToSqlColumn(attribute), url, value);
|
||||
}
|
||||
|
||||
SiteSettingsManager::Permission SiteSettingsManager::getPermission(const QString &column, const QUrl& url)
|
||||
SiteSettingsManager::Permission SiteSettingsManager::getPermission(const QString& column, const QString& host)
|
||||
{
|
||||
if (column.isEmpty()) {
|
||||
return Deny;
|
||||
@ -281,7 +281,7 @@ SiteSettingsManager::Permission SiteSettingsManager::getPermission(const QString
|
||||
|
||||
QSqlQuery query(SqlDatabase::instance()->database());
|
||||
query.prepare(QSL("SELECT %1 FROM %2 WHERE server=?").arg(column, sqlTable()));
|
||||
query.addBindValue(url.host());
|
||||
query.addBindValue(host);
|
||||
query.exec();
|
||||
|
||||
if (query.next()) {
|
||||
@ -293,19 +293,39 @@ SiteSettingsManager::Permission SiteSettingsManager::getPermission(const QString
|
||||
return Default;
|
||||
}
|
||||
|
||||
SiteSettingsManager::Permission SiteSettingsManager::getPermission(const SiteSettingsManager::PageOptions option, const QString& host)
|
||||
{
|
||||
return getPermission(optionToSqlColumn(option), host);
|
||||
}
|
||||
|
||||
SiteSettingsManager::Permission SiteSettingsManager::getPermission(const QWebEnginePage::Feature& feature, const QString& host)
|
||||
{
|
||||
return getPermission(featureToSqlColumn(feature), host);
|
||||
}
|
||||
|
||||
SiteSettingsManager::Permission SiteSettingsManager::getPermission(const QWebEngineSettings::WebAttribute& attribute, const QString& host)
|
||||
{
|
||||
return getPermission(webAttributeToSqlColumn(attribute), host);
|
||||
}
|
||||
|
||||
SiteSettingsManager::Permission SiteSettingsManager::getPermission(const QString &column, const QUrl& url)
|
||||
{
|
||||
return getPermission(column, url.host());
|
||||
}
|
||||
|
||||
SiteSettingsManager::Permission SiteSettingsManager::getPermission(const SiteSettingsManager::PageOptions option, const QUrl& url)
|
||||
{
|
||||
return getPermission(optionToSqlColumn(option), url);
|
||||
return getPermission(optionToSqlColumn(option), url.host());
|
||||
}
|
||||
|
||||
SiteSettingsManager::Permission SiteSettingsManager::getPermission(const QWebEnginePage::Feature& feature, const QUrl& url)
|
||||
{
|
||||
return getPermission(featureToSqlColumn(feature), url);
|
||||
return getPermission(featureToSqlColumn(feature), url.host());
|
||||
}
|
||||
|
||||
SiteSettingsManager::Permission SiteSettingsManager::getPermission(const QWebEngineSettings::WebAttribute& attribute, const QUrl& url)
|
||||
{
|
||||
return getPermission(webAttributeToSqlColumn(attribute), url);
|
||||
return getPermission(webAttributeToSqlColumn(attribute), url.host());
|
||||
}
|
||||
|
||||
QString SiteSettingsManager::optionToSqlColumn(const SiteSettingsManager::PageOptions &option)
|
||||
@ -324,9 +344,16 @@ QString SiteSettingsManager::optionToSqlColumn(const SiteSettingsManager::PageOp
|
||||
SiteSettingsManager::Permission SiteSettingsManager::getDefaultPermission(const SiteSettingsManager::PageOptions& option)
|
||||
{
|
||||
switch (option) {
|
||||
case poAllowCookies: {
|
||||
Settings settings;
|
||||
settings.beginGroup("Cookie-Settings");
|
||||
auto defaultCookies = settings.value("allowCookies", true).toBool() ? Allow : Deny;
|
||||
settings.endGroup();
|
||||
|
||||
return defaultCookies;
|
||||
}
|
||||
// so far not implemented
|
||||
case poZoomLevel:
|
||||
case poAllowCookies:
|
||||
default:
|
||||
qWarning() << "Unknown option:" << option;
|
||||
return Deny;
|
||||
|
@ -84,6 +84,11 @@ public:
|
||||
void setJavascript(const QUrl &url, const int value);
|
||||
void setImages(const QUrl &url, const int value);
|
||||
|
||||
Permission getPermission(const QString &column, const QString &host);
|
||||
Permission getPermission(const PageOptions option, const QString &host);
|
||||
Permission getPermission(const QWebEnginePage::Feature &feature, const QString &host);
|
||||
Permission getPermission(const QWebEngineSettings::WebAttribute &attribute, const QString &host);
|
||||
|
||||
Permission getPermission(const QString &column, const QUrl &url);
|
||||
Permission getPermission(const PageOptions option, const QUrl &url);
|
||||
Permission getPermission(const QWebEnginePage::Feature &feature, const QUrl &url);
|
||||
|
Loading…
Reference in New Issue
Block a user