mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-19 18:26:34 +01:00
Fix cookies filtering with SiteSettings
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
parent
bbe03cf9c2
commit
8c846b889a
@ -29,7 +29,7 @@
|
|||||||
#include <QWebEngineSettings>
|
#include <QWebEngineSettings>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
|
||||||
//#define COOKIE_DEBUG
|
// #define COOKIE_DEBUG
|
||||||
|
|
||||||
CookieJar::CookieJar(QObject* parent)
|
CookieJar::CookieJar(QObject* parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
@ -182,7 +182,20 @@ bool CookieJar::rejectCookie(const QString &domain, const QNetworkCookie &cookie
|
|||||||
{
|
{
|
||||||
Q_UNUSED(domain)
|
Q_UNUSED(domain)
|
||||||
|
|
||||||
auto result = mApp->siteSettingsManager()->getPermission(SiteSettingsManager::poAllowCookies, cookieDomain);
|
SiteSettingsManager::Permission result = SiteSettingsManager::Default;
|
||||||
|
auto results = mApp->siteSettingsManager()->getPermissionsLike(SiteSettingsManager::poAllowCookies, cookieDomain);
|
||||||
|
for (auto it = results.begin(); it != results.end(); ++it) {
|
||||||
|
QString host = QUrl(it.key()).host();
|
||||||
|
|
||||||
|
if (matchDomain(cookieDomain, host)) {
|
||||||
|
result = it.value();
|
||||||
|
#ifdef COOKIE_DEBUG
|
||||||
|
qDebug() << "Cookie domain" << cookieDomain << "matched to" << it.key();
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (result == SiteSettingsManager::Default) {
|
if (result == SiteSettingsManager::Default) {
|
||||||
result = mApp->siteSettingsManager()->getDefaultPermission(SiteSettingsManager::poAllowCookies);
|
result = mApp->siteSettingsManager()->getDefaultPermission(SiteSettingsManager::poAllowCookies);
|
||||||
}
|
}
|
||||||
|
@ -226,6 +226,45 @@ SiteSettingsManager::Permission SiteSettingsManager::getPermission(const QWebEng
|
|||||||
return getPermission(webAttributeToSqlColumn(attribute), adjustUrl(url));
|
return getPermission(webAttributeToSqlColumn(attribute), adjustUrl(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMap<QString, SiteSettingsManager::Permission> SiteSettingsManager::getPermissionsLike(const QString& column, const QString& host)
|
||||||
|
{
|
||||||
|
QMap<QString, SiteSettingsManager::Permission> domainMatch;
|
||||||
|
|
||||||
|
if (column.isEmpty()) {
|
||||||
|
domainMatch.insert(host, Deny);
|
||||||
|
return domainMatch;
|
||||||
|
}
|
||||||
|
if (host.isEmpty()) {
|
||||||
|
domainMatch.insert(host, Default);
|
||||||
|
return domainMatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto searchHost = host;
|
||||||
|
|
||||||
|
if (searchHost.startsWith(QLatin1Char('.'))) {
|
||||||
|
searchHost.remove(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSqlQuery query(SqlDatabase::instance()->database());
|
||||||
|
query.prepare(QSL("SELECT server, %1 FROM %2 WHERE server LIKE ?").arg(column, sqlTable()));
|
||||||
|
query.addBindValue(QSL("%%%1").arg(searchHost));
|
||||||
|
query.exec();
|
||||||
|
|
||||||
|
while (query.next()) {
|
||||||
|
Permission allow_option = intToPermission(query.value(column).toInt());
|
||||||
|
QString server_option = query.value(QSL("server")).toString();
|
||||||
|
|
||||||
|
domainMatch.insert(server_option, allow_option);
|
||||||
|
}
|
||||||
|
|
||||||
|
return domainMatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, SiteSettingsManager::Permission> SiteSettingsManager::getPermissionsLike(const SiteSettingsManager::PageOptions option, const QString& host)
|
||||||
|
{
|
||||||
|
return getPermissionsLike(optionToSqlColumn(option), host);
|
||||||
|
}
|
||||||
|
|
||||||
SiteSettingsManager::Permission SiteSettingsManager::getDefaultPermission(const SiteSettingsManager::PageOptions option)
|
SiteSettingsManager::Permission SiteSettingsManager::getDefaultPermission(const SiteSettingsManager::PageOptions option)
|
||||||
{
|
{
|
||||||
switch (option) {
|
switch (option) {
|
||||||
|
@ -92,6 +92,9 @@ public:
|
|||||||
Permission getPermission(const QWebEnginePage::Feature feature, const QUrl &url);
|
Permission getPermission(const QWebEnginePage::Feature feature, const QUrl &url);
|
||||||
Permission getPermission(const QWebEngineSettings::WebAttribute attribute, const QUrl &url);
|
Permission getPermission(const QWebEngineSettings::WebAttribute attribute, const QUrl &url);
|
||||||
|
|
||||||
|
QMap<QString, SiteSettingsManager::Permission> getPermissionsLike(const QString &column, const QString &host);
|
||||||
|
QMap<QString, SiteSettingsManager::Permission> getPermissionsLike(const SiteSettingsManager::PageOptions option, const QString &host);
|
||||||
|
|
||||||
void setOption(const QString &column, const QUrl &url, const int value);
|
void setOption(const QString &column, const QUrl &url, const int value);
|
||||||
void setOption(const PageOptions option, const QUrl &url, const int value);
|
void setOption(const PageOptions option, const QUrl &url, const int value);
|
||||||
void setOption(const QWebEnginePage::Feature &feature, const QUrl &url, const Permission value);
|
void setOption(const QWebEnginePage::Feature &feature, const QUrl &url, const Permission value);
|
||||||
|
Loading…
Reference in New Issue
Block a user