mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
parent
435ab60e79
commit
5e3e9393b1
@ -21,6 +21,8 @@
|
|||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
//#define COOKIE_DEBUG
|
//#define COOKIE_DEBUG
|
||||||
|
|
||||||
bool containsDomain(QString string, QString domain)
|
bool containsDomain(QString string, QString domain)
|
||||||
@ -30,23 +32,26 @@ bool containsDomain(QString string, QString domain)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
string.prepend(".");
|
if (string.startsWith('.')) {
|
||||||
if (domain.startsWith("www.")) {
|
string = string.mid(1);
|
||||||
domain = domain.mid(4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return string.endsWith(domain);
|
return domain.endsWith(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool listContainsDomain(const QStringList &list, const QString &domain)
|
int listContainsDomain(const QStringList &list, const QString &domain)
|
||||||
{
|
{
|
||||||
|
if (domain.isEmpty()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
foreach(const QString & d, list) {
|
foreach(const QString & d, list) {
|
||||||
if (containsDomain(d, domain)) {
|
if (domain.endsWith(d)) {
|
||||||
return true;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CookieJar::CookieJar(QupZilla* mainClass, QObject* parent)
|
CookieJar::CookieJar(QupZilla* mainClass, QObject* parent)
|
||||||
@ -62,7 +67,7 @@ void CookieJar::loadSettings()
|
|||||||
Settings settings;
|
Settings settings;
|
||||||
settings.beginGroup("Cookie-Settings");
|
settings.beginGroup("Cookie-Settings");
|
||||||
m_allowCookies = settings.value("allowCookies", true).toBool();
|
m_allowCookies = settings.value("allowCookies", true).toBool();
|
||||||
m_allowCookiesFromDomain = settings.value("allowCookiesFromVisitedDomainOnly", false).toBool();
|
m_blockThirdParty = settings.value("allowCookiesFromVisitedDomainOnly", false).toBool();
|
||||||
m_filterTrackingCookie = settings.value("filterTrackingCookie", false).toBool();
|
m_filterTrackingCookie = settings.value("filterTrackingCookie", false).toBool();
|
||||||
m_deleteOnClose = settings.value("deleteCookiesOnClose", false).toBool();
|
m_deleteOnClose = settings.value("deleteCookiesOnClose", false).toBool();
|
||||||
m_whitelist = settings.value("whitelist", QStringList()).toStringList();
|
m_whitelist = settings.value("whitelist", QStringList()).toStringList();
|
||||||
@ -75,39 +80,56 @@ void CookieJar::setAllowCookies(bool allow)
|
|||||||
m_allowCookies = allow;
|
m_allowCookies = allow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CookieJar::rejectCookie(const QString &domain, const QNetworkCookie &cookie) const
|
||||||
|
{
|
||||||
|
const QString &cookieDomain = cookie.domain();
|
||||||
|
|
||||||
|
if (!m_allowCookies) {
|
||||||
|
int result = listContainsDomain(m_whitelist, cookieDomain);
|
||||||
|
if (result != 1) {
|
||||||
|
#ifdef COOKIE_DEBUG
|
||||||
|
qDebug() << "not in whitelist" << cookie;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_allowCookies) {
|
||||||
|
int result = listContainsDomain(m_blacklist, cookieDomain);
|
||||||
|
if (result == 1) {
|
||||||
|
#ifdef COOKIE_DEBUG
|
||||||
|
qDebug() << "found in blacklist" << cookie;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_blockThirdParty) {
|
||||||
|
bool result = !containsDomain(cookieDomain, domain);
|
||||||
|
if (result) {
|
||||||
|
#ifdef COOKIE_DEBUG
|
||||||
|
qDebug() << "purged for domain mismatch" << cookie << cookieDomain << domain;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_filterTrackingCookie && cookie.name().startsWith("__utm")) {
|
||||||
|
#ifdef COOKIE_DEBUG
|
||||||
|
qDebug() << "purged as tracking " << cookie;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool CookieJar::setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url)
|
bool CookieJar::setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url)
|
||||||
{
|
{
|
||||||
QList<QNetworkCookie> newList = cookieList;
|
QList<QNetworkCookie> newList = cookieList;
|
||||||
|
|
||||||
foreach(const QNetworkCookie & cookie, newList) {
|
foreach(const QNetworkCookie & cookie, newList) {
|
||||||
if (!m_allowCookies && !listContainsDomain(m_whitelist, cookie.domain())) {
|
if (rejectCookie(url.host(), cookie)) {
|
||||||
#ifdef COOKIE_DEBUG
|
|
||||||
qDebug() << "not in whitelist" << cookie;
|
|
||||||
#endif
|
|
||||||
newList.removeOne(cookie);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_allowCookies && listContainsDomain(m_blacklist, cookie.domain())) {
|
|
||||||
#ifdef COOKIE_DEBUG
|
|
||||||
qDebug() << "found in blacklist" << cookie;
|
|
||||||
#endif
|
|
||||||
newList.removeOne(cookie);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_allowCookiesFromDomain && !containsDomain(url.host(), cookie.domain())) {
|
|
||||||
#ifdef COOKIE_DEBUG
|
|
||||||
qDebug() << "purged for domain mismatch" << cookie << cookie.domain() << url.host();
|
|
||||||
#endif
|
|
||||||
newList.removeOne(cookie);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_filterTrackingCookie && cookie.name().startsWith("__utm")) {
|
|
||||||
#ifdef COOKIE_DEBUG
|
|
||||||
qDebug() << "purged as tracking " << cookie;
|
|
||||||
#endif
|
|
||||||
newList.removeOne(cookie);
|
newList.removeOne(cookie);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -43,11 +43,13 @@ public:
|
|||||||
void setAllowCookies(bool allow);
|
void setAllowCookies(bool allow);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool rejectCookie(const QString &domain, const QNetworkCookie &cookie) const;
|
||||||
|
|
||||||
QupZilla* p_QupZilla;
|
QupZilla* p_QupZilla;
|
||||||
|
|
||||||
bool m_allowCookies;
|
bool m_allowCookies;
|
||||||
bool m_filterTrackingCookie;
|
bool m_filterTrackingCookie;
|
||||||
bool m_allowCookiesFromDomain;
|
bool m_blockThirdParty;
|
||||||
bool m_deleteOnClose;
|
bool m_deleteOnClose;
|
||||||
|
|
||||||
QStringList m_whitelist;
|
QStringList m_whitelist;
|
||||||
|
@ -200,6 +200,9 @@ void CookieManager::slotRefreshTable()
|
|||||||
|
|
||||||
void CookieManager::slotRefreshFilters()
|
void CookieManager::slotRefreshFilters()
|
||||||
{
|
{
|
||||||
|
ui->whiteList->clear();
|
||||||
|
ui->blackList->clear();
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.beginGroup("Cookie-Settings");
|
settings.beginGroup("Cookie-Settings");
|
||||||
QStringList whiteList = settings.value("whitelist", QStringList()).toStringList();
|
QStringList whiteList = settings.value("whitelist", QStringList()).toStringList();
|
||||||
|
Loading…
Reference in New Issue
Block a user