1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

Bring back support for managing cookies

This commit is contained in:
David Rosca 2015-10-05 22:03:53 +02:00
parent 8ba58860db
commit 4d05c1105a
8 changed files with 178 additions and 399 deletions

View File

@ -243,6 +243,16 @@ MainApplication::MainApplication(int &argc, char** argv)
setQuitOnLastWindowClosed(true); setQuitOnLastWindowClosed(true);
#endif #endif
QSettings::setDefaultFormat(QSettings::IniFormat);
QDesktopServices::setUrlHandler("http", this, "addNewTab");
QDesktopServices::setUrlHandler("ftp", this, "addNewTab");
ProfileManager profileManager;
profileManager.initConfigDir();
profileManager.initCurrentProfile(startProfile);
Settings::createSettings(DataPaths::currentProfilePath() + QLatin1String("/settings.ini"));
m_webProfile = isPrivate() ? new QWebEngineProfile(this) : QWebEngineProfile::defaultProfile(); m_webProfile = isPrivate() ? new QWebEngineProfile(this) : QWebEngineProfile::defaultProfile();
connect(m_webProfile, &QWebEngineProfile::downloadRequested, this, &MainApplication::downloadRequested); connect(m_webProfile, &QWebEngineProfile::downloadRequested, this, &MainApplication::downloadRequested);
@ -257,16 +267,6 @@ MainApplication::MainApplication(int &argc, char** argv)
script.setSourceCode(Scripts::setupWebChannel()); script.setSourceCode(Scripts::setupWebChannel());
m_webProfile->scripts()->insert(script); m_webProfile->scripts()->insert(script);
QSettings::setDefaultFormat(QSettings::IniFormat);
QDesktopServices::setUrlHandler("http", this, "addNewTab");
QDesktopServices::setUrlHandler("ftp", this, "addNewTab");
ProfileManager profileManager;
profileManager.initConfigDir();
profileManager.initCurrentProfile(startProfile);
Settings::createSettings(DataPaths::currentProfilePath() + QLatin1String("/settings.ini"));
m_autoSaver = new AutoSaver(this); m_autoSaver = new AutoSaver(this);
connect(m_autoSaver, SIGNAL(save()), this, SLOT(saveSession())); connect(m_autoSaver, SIGNAL(save()), this, SLOT(saveSession()));

View File

@ -29,19 +29,9 @@
//#define COOKIE_DEBUG //#define COOKIE_DEBUG
CookieJar::CookieJar(QObject* parent) CookieJar::CookieJar(QObject* parent)
: QNetworkCookieJar(parent) : QWebEngineCookieStoreClient(parent)
, m_autoSaver(0)
{ {
m_autoSaver = new AutoSaver(this);
connect(m_autoSaver, SIGNAL(save()), this, SLOT(saveCookies()));
loadSettings(); loadSettings();
restoreCookies();
}
CookieJar::~CookieJar()
{
m_autoSaver->saveIfNecessary();
} }
void CookieJar::loadSettings() void CookieJar::loadSettings()
@ -49,28 +39,11 @@ 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_allowThirdParty = settings.value("allowThirdPartyCookies", 0).toInt(); m_filterThirdParty = settings.value("filterThirdPartyCookies", false).toBool();
m_filterTrackingCookie = settings.value("filterTrackingCookie", false).toBool(); m_filterTrackingCookie = settings.value("filterTrackingCookie", false).toBool();
m_deleteOnClose = settings.value("deleteCookiesOnClose", false).toBool();
m_whitelist = settings.value("whitelist", QStringList()).toStringList(); m_whitelist = settings.value("whitelist", QStringList()).toStringList();
m_blacklist = settings.value("blacklist", QStringList()).toStringList(); m_blacklist = settings.value("blacklist", QStringList()).toStringList();
settings.endGroup(); settings.endGroup();
#if QTWEBENGINE_DISABLED
switch (m_allowThirdParty) {
case 0:
QWebSettings::defaultSettings()->setThirdPartyCookiePolicy(QWebSettings::AlwaysAllowThirdPartyCookies);
break;
case 1:
QWebSettings::defaultSettings()->setThirdPartyCookiePolicy(QWebSettings::AlwaysBlockThirdPartyCookies);
break;
case 2:
QWebSettings::defaultSettings()->setThirdPartyCookiePolicy(QWebSettings::AllowThirdPartyWithExistingCookies);
break;
}
#endif
} }
void CookieJar::setAllowCookies(bool allow) void CookieJar::setAllowCookies(bool allow)
@ -78,126 +51,17 @@ void CookieJar::setAllowCookies(bool allow)
m_allowCookies = allow; m_allowCookies = allow;
} }
bool CookieJar::setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url) bool CookieJar::acceptCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &cookieSource)
{ {
QList<QNetworkCookie> newList; const QList<QNetworkCookie> cookies = QNetworkCookie::parseCookies(cookieLine);
Q_ASSERT(cookies.size() == 1);
foreach (QNetworkCookie cookie, cookieList) { QNetworkCookie cookie = cookies.first();
// If cookie domain is empty, set it to url.host() return !rejectCookie(firstPartyUrl.host(), cookie, cookieSource.host());
if (cookie.domain().isEmpty()) {
cookie.setDomain(url.host());
}
if (!rejectCookie(url.host(), cookie)) {
newList.append(cookie);
}
}
bool added = QNetworkCookieJar::setCookiesFromUrl(newList, url);
if (added) {
m_autoSaver->changeOcurred();
}
return added;
} }
QList<QNetworkCookie> CookieJar::allCookies() const bool CookieJar::rejectCookie(const QString &domain, const QNetworkCookie &cookie, const QString &cookieDomain) const
{ {
return QNetworkCookieJar::allCookies();
}
void CookieJar::setAllCookies(const QList<QNetworkCookie> &cookieList)
{
m_autoSaver->changeOcurred();
QNetworkCookieJar::setAllCookies(cookieList);
}
void CookieJar::clearCookies()
{
setAllCookies(QList<QNetworkCookie>());
}
void CookieJar::restoreCookies()
{
if (mApp->isPrivate()) {
return;
}
const QString cookiesFile = DataPaths::currentProfilePath() + QLatin1String("/cookies.dat");
QDateTime now = QDateTime::currentDateTime();
QList<QNetworkCookie> restoredCookies;
QFile file(cookiesFile);
file.open(QIODevice::ReadOnly);
QDataStream stream(&file);
int count;
stream >> count;
for (int i = 0; i < count; i++) {
QByteArray rawForm;
stream >> rawForm;
const QList<QNetworkCookie> &cookieList = QNetworkCookie::parseCookies(rawForm);
if (cookieList.isEmpty()) {
continue;
}
const QNetworkCookie cookie = cookieList.at(0);
if (cookie.expirationDate() < now) {
continue;
}
restoredCookies.append(cookie);
}
file.close();
QNetworkCookieJar::setAllCookies(restoredCookies);
}
void CookieJar::saveCookies()
{
if (mApp->isPrivate()) {
return;
}
QList<QNetworkCookie> cookies = allCookies();
if (m_deleteOnClose) {
// If we are deleting cookies on close, save only whitelisted cookies
cookies.clear();
QList<QNetworkCookie> aCookies = allCookies();
foreach (const QNetworkCookie &cookie, aCookies) {
if (listMatchesDomain(m_whitelist, cookie.domain())) {
cookies.append(cookie);
}
}
}
QFile file(DataPaths::currentProfilePath() + QLatin1String("/cookies.dat"));
file.open(QIODevice::WriteOnly);
QDataStream stream(&file);
int count = cookies.count();
stream << count;
for (int i = 0; i < count; i++) {
const QNetworkCookie cookie = cookies.at(i);
if (cookie.isSessionCookie()) {
continue;
}
stream << cookie.toRawForm();
}
file.close();
}
bool CookieJar::rejectCookie(const QString &domain, const QNetworkCookie &cookie) const
{
Q_UNUSED(domain)
const QString cookieDomain = cookie.domain();
if (!m_allowCookies) { if (!m_allowCookies) {
bool result = listMatchesDomain(m_whitelist, cookieDomain); bool result = listMatchesDomain(m_whitelist, cookieDomain);
if (!result) { if (!result) {
@ -218,6 +82,16 @@ bool CookieJar::rejectCookie(const QString &domain, const QNetworkCookie &cookie
} }
} }
if (m_filterThirdParty) {
bool result = matchDomain(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")) { if (m_filterTrackingCookie && cookie.name().startsWith("__utm")) {
#ifdef COOKIE_DEBUG #ifdef COOKIE_DEBUG
qDebug() << "purged as tracking " << cookie; qDebug() << "purged as tracking " << cookie;

View File

@ -20,50 +20,37 @@
#include <QFile> #include <QFile>
#include <QStringList> #include <QStringList>
#include <QNetworkCookieJar> #include <QWebEngineCookieStoreClient>
#include "qzcommon.h" #include "qzcommon.h"
class AutoSaver; class AutoSaver;
class QUPZILLA_EXPORT CookieJar : public QNetworkCookieJar class QUPZILLA_EXPORT CookieJar : public QWebEngineCookieStoreClient
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit CookieJar(QObject* parent = 0); explicit CookieJar(QObject* parent = 0);
~CookieJar();
void loadSettings(); void loadSettings();
void setAllowCookies(bool allow); void setAllowCookies(bool allow);
bool setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url); bool acceptCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &cookieSource) Q_DECL_OVERRIDE;
QList<QNetworkCookie> allCookies() const;
void setAllCookies(const QList<QNetworkCookie> &cookieList);
void clearCookies();
void restoreCookies();
private slots:
void saveCookies();
protected: protected:
bool matchDomain(QString cookieDomain, QString siteDomain) const; bool matchDomain(QString cookieDomain, QString siteDomain) const;
bool listMatchesDomain(const QStringList &list, const QString &cookieDomain) const; bool listMatchesDomain(const QStringList &list, const QString &cookieDomain) const;
private: private:
bool rejectCookie(const QString &domain, const QNetworkCookie &cookie) const; bool rejectCookie(const QString &domain, const QNetworkCookie &cookie, const QString &cookieDomain) const;
bool m_allowCookies; bool m_allowCookies;
bool m_filterTrackingCookie; bool m_filterTrackingCookie;
int m_allowThirdParty; bool m_filterThirdParty;
bool m_deleteOnClose;
QStringList m_whitelist; QStringList m_whitelist;
QStringList m_blacklist; QStringList m_blacklist;
AutoSaver* m_autoSaver;
}; };
#endif // COOKIEJAR_H #endif // COOKIEJAR_H

View File

@ -35,7 +35,6 @@
CookieManager::CookieManager() CookieManager::CookieManager()
: QWidget() : QWidget()
, ui(new Ui::CookieManager) , ui(new Ui::CookieManager)
, m_refreshCookieJar(true)
{ {
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
@ -53,8 +52,7 @@ CookieManager::CookieManager()
// Stored Cookies // Stored Cookies
connect(ui->cookieTree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*))); connect(ui->cookieTree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
connect(ui->removeAll, SIGNAL(clicked()), this, SLOT(removeAll())); connect(ui->removeAll, SIGNAL(clicked()), this, SLOT(removeAll()));
connect(ui->removeOne, SIGNAL(clicked()), this, SLOT(removeCookie())); connect(ui->removeOne, SIGNAL(clicked()), this, SLOT(remove()));
connect(ui->blockDomain, SIGNAL(clicked()), this, SLOT(blockCurrentHostAndRemoveCookie()));
connect(ui->close, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close())); connect(ui->close, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close()));
connect(ui->close2, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close())); connect(ui->close2, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close()));
connect(ui->close3, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close())); connect(ui->close3, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close()));
@ -70,16 +68,12 @@ CookieManager::CookieManager()
Settings settings; Settings settings;
settings.beginGroup("Cookie-Settings"); settings.beginGroup("Cookie-Settings");
ui->saveCookies->setChecked(settings.value("allowCookies", true).toBool()); ui->saveCookies->setChecked(settings.value("allowCookies", true).toBool());
if (!ui->saveCookies->isChecked()) { ui->filter3rdParty->setChecked(settings.value("filterThirdPartyCookies", false).toBool());
ui->deleteCookiesOnClose->setEnabled(false);
}
ui->deleteCookiesOnClose->setChecked(settings.value("deleteCookiesOnClose", false).toBool());
ui->allowThirdPartyCookies->setCurrentIndex(settings.value("allowThirdPartyCookies", 0).toInt());
ui->filterTracking->setChecked(settings.value("filterTrackingCookie", false).toBool()); ui->filterTracking->setChecked(settings.value("filterTrackingCookie", false).toBool());
ui->whiteList->addItems(settings.value("whitelist", QStringList()).toStringList());
ui->blackList->addItems(settings.value("blacklist", QStringList()).toStringList());
settings.endGroup(); settings.endGroup();
connect(ui->saveCookies, SIGNAL(toggled(bool)), this, SLOT(saveCookiesChanged(bool)));
ui->search->setPlaceholderText(tr("Search")); ui->search->setPlaceholderText(tr("Search"));
ui->cookieTree->setDefaultItemShowMode(TreeWidget::ItemsCollapsed); ui->cookieTree->setDefaultItemShowMode(TreeWidget::ItemsCollapsed);
ui->cookieTree->sortItems(0, Qt::AscendingOrder); ui->cookieTree->sortItems(0, Qt::AscendingOrder);
@ -89,9 +83,19 @@ CookieManager::CookieManager()
QShortcut* removeShortcut = new QShortcut(QKeySequence("Del"), this); QShortcut* removeShortcut = new QShortcut(QKeySequence("Del"), this);
connect(removeShortcut, SIGNAL(activated()), this, SLOT(deletePressed())); connect(removeShortcut, SIGNAL(activated()), this, SLOT(deletePressed()));
QzTools::setWmClass("Cookies", this); connect(ui->search, SIGNAL(textChanged(QString)), this, SLOT(filterString(QString)));
connect (mApp->cookieJar(), &CookieJar::cookieAdded, this, &CookieManager::addCookie);
connect (mApp->cookieJar(), &CookieJar::cookieRemoved, this, &CookieManager::removeCookie);
refreshTable(); // Load cookies
mApp->cookieJar()->getAllCookies([this](const QByteArray &res) {
const QList<QNetworkCookie> &allCookies = QNetworkCookie::parseCookies(res);
foreach (const QNetworkCookie &cookie, allCookies) {
addCookie(cookie);
}
});
QzTools::setWmClass("Cookies", this);
} }
void CookieManager::removeAll() void CookieManager::removeAll()
@ -102,56 +106,31 @@ void CookieManager::removeAll()
return; return;
} }
QList<QNetworkCookie> emptyList; mApp->cookieJar()->deleteAllCookies();
mApp->cookieJar()->setAllCookies(emptyList);
m_itemHash.clear();
m_domainHash.clear();
ui->cookieTree->clear(); ui->cookieTree->clear();
} }
void CookieManager::removeCookie() void CookieManager::remove()
{ {
QTreeWidgetItem* current = ui->cookieTree->currentItem(); QTreeWidgetItem* current = ui->cookieTree->currentItem();
if (!current) { if (!current) {
return; return;
} }
QList<QNetworkCookie> allCookies = mApp->cookieJar()->allCookies(); if (current->childCount()) {
for (int i = 0; i < current->childCount(); ++i) {
if (current->text(1).isEmpty()) { //Remove whole cookie group QTreeWidgetItem *item = current->child(i);
const QString domain = current->data(0, Qt::UserRole + 10).toString(); if (item && m_itemHash.contains(item))
foreach (const QNetworkCookie &cookie, allCookies) { removeCookie(m_itemHash.value(item));
if (cookie.domain() == domain || cookie.domain() == domain.mid(1)) {
allCookies.removeOne(cookie);
}
} }
ui->cookieTree->deleteItem(current);
} }
else { else {
const QNetworkCookie cookie = qvariant_cast<QNetworkCookie>(current->data(0, Qt::UserRole + 10)); if (m_itemHash.contains(current))
allCookies.removeOne(cookie); removeCookie(m_itemHash.value(current));
QTreeWidgetItem* parentItem = current->parent();
ui->cookieTree->deleteItem(current);
if (parentItem->childCount() == 0) {
ui->cookieTree->deleteItem(parentItem);
}
} }
mApp->cookieJar()->setAllCookies(allCookies);
}
void CookieManager::blockCurrentHostAndRemoveCookie()
{
QTreeWidgetItem* current = ui->cookieTree->currentItem();
if (!current) {
return;
}
const QString domain = (current->text(1).isEmpty()) ? current->data(0, Qt::UserRole + 10).toString() :
qvariant_cast<QNetworkCookie>(current->data(0, Qt::UserRole + 10)).domain();
removeCookie();
addBlacklist(domain);
} }
void CookieManager::currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* parent) void CookieManager::currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* parent)
@ -185,84 +164,6 @@ void CookieManager::currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem
ui->removeOne->setText(tr("Remove cookie")); ui->removeOne->setText(tr("Remove cookie"));
} }
void CookieManager::refreshTable()
{
disconnect(ui->search, SIGNAL(textChanged(QString)), this, SLOT(filterString(QString)));
ui->search->clear();
connect(ui->search, SIGNAL(textChanged(QString)), this, SLOT(filterString(QString)));
QTimer::singleShot(0, this, SLOT(slotRefreshTable()));
QTimer::singleShot(0, this, SLOT(slotRefreshFilters()));
}
void CookieManager::slotRefreshTable()
{
const QList<QNetworkCookie> &allCookies = mApp->cookieJar()->allCookies();
QApplication::setOverrideCursor(Qt::WaitCursor);
ui->cookieTree->clear();
int counter = 0;
QPointer<CookieManager> guard = this;
QHash<QString, QTreeWidgetItem*> hash;
for (int i = 0; i < allCookies.count(); ++i) {
const QNetworkCookie cookie = allCookies.at(i);
QTreeWidgetItem* item;
QString cookieDomain = cookie.domain();
if (cookieDomain.startsWith(QLatin1Char('.'))) {
cookieDomain = cookieDomain.mid(1);
}
QTreeWidgetItem* findParent = hash[cookieDomain];
if (findParent) {
item = new QTreeWidgetItem(findParent);
}
else {
QTreeWidgetItem* newParent = new QTreeWidgetItem(ui->cookieTree);
newParent->setText(0, cookieDomain);
newParent->setIcon(0, IconProvider::standardIcon(QStyle::SP_DirIcon));
newParent->setData(0, Qt::UserRole + 10, cookie.domain());
ui->cookieTree->addTopLevelItem(newParent);
hash[cookieDomain] = newParent;
item = new QTreeWidgetItem(newParent);
}
item->setText(0, "." + cookieDomain);
item->setText(1, cookie.name());
item->setData(0, Qt::UserRole + 10, QVariant::fromValue(cookie));
ui->cookieTree->addTopLevelItem(item);
++counter;
if (counter > 200) {
QApplication::processEvents();
counter = 0;
}
if (!guard) {
break;
}
}
QApplication::restoreOverrideCursor();
}
void CookieManager::slotRefreshFilters()
{
ui->whiteList->clear();
ui->blackList->clear();
Settings settings;
settings.beginGroup("Cookie-Settings");
QStringList whiteList = settings.value("whitelist", QStringList()).toStringList();
QStringList blackList = settings.value("blacklist", QStringList()).toStringList();
settings.endGroup();
ui->whiteList->addItems(whiteList);
ui->blackList->addItems(blackList);
}
void CookieManager::addWhitelist() void CookieManager::addWhitelist()
{ {
const QString server = QInputDialog::getText(this, tr("Add to whitelist"), tr("Server:")); const QString server = QInputDialog::getText(this, tr("Add to whitelist"), tr("Server:"));
@ -308,6 +209,26 @@ void CookieManager::addBlacklist(const QString &server)
} }
} }
QString CookieManager::cookieDomain(const QNetworkCookie &cookie) const
{
QString domain = cookie.domain();
if (domain.startsWith(QLatin1Char('.'))) {
domain = domain.mid(1);
}
return domain;
}
QTreeWidgetItem *CookieManager::cookieItem(const QNetworkCookie &cookie) const
{
QHashIterator<QTreeWidgetItem*, QNetworkCookie> it(m_itemHash);
while (it.hasNext()) {
it.next();
if (it.value() == cookie)
return it.key();
}
return Q_NULLPTR;
}
void CookieManager::removeBlacklist() void CookieManager::removeBlacklist()
{ {
delete ui->blackList->currentItem(); delete ui->blackList->currentItem();
@ -316,7 +237,7 @@ void CookieManager::removeBlacklist()
void CookieManager::deletePressed() void CookieManager::deletePressed()
{ {
if (ui->cookieTree->hasFocus()) { if (ui->cookieTree->hasFocus()) {
removeCookie(); remove();
} }
else if (ui->whiteList->hasFocus()) { else if (ui->whiteList->hasFocus()) {
removeWhitelist(); removeWhitelist();
@ -326,11 +247,6 @@ void CookieManager::deletePressed()
} }
} }
void CookieManager::saveCookiesChanged(bool state)
{
ui->deleteCookiesOnClose->setEnabled(state);
}
void CookieManager::filterString(const QString &string) void CookieManager::filterString(const QString &string)
{ {
if (string.isEmpty()) { if (string.isEmpty()) {
@ -348,6 +264,51 @@ void CookieManager::filterString(const QString &string)
} }
} }
void CookieManager::addCookie(const QNetworkCookie &cookie)
{
QTreeWidgetItem* item;
const QString domain = cookieDomain(cookie);
QTreeWidgetItem* findParent = m_domainHash.value(domain);
if (findParent) {
item = new QTreeWidgetItem(findParent);
}
else {
QTreeWidgetItem* newParent = new QTreeWidgetItem(ui->cookieTree);
newParent->setText(0, domain);
newParent->setIcon(0, IconProvider::standardIcon(QStyle::SP_DirIcon));
newParent->setData(0, Qt::UserRole + 10, cookie.domain());
ui->cookieTree->addTopLevelItem(newParent);
m_domainHash[domain] = newParent;
item = new QTreeWidgetItem(newParent);
}
item->setText(0, "." + domain);
item->setText(1, cookie.name());
item->setData(0, Qt::UserRole + 10, QVariant::fromValue(cookie));
ui->cookieTree->addTopLevelItem(item);
m_itemHash[item] = cookie;
}
void CookieManager::removeCookie(const QNetworkCookie &cookie)
{
QTreeWidgetItem *item = cookieItem(cookie);
if (!item)
return;
m_itemHash.remove(item);
if (item->parent() && item->parent()->childCount() == 1) {
m_domainHash.remove(cookieDomain(cookie));
delete item->parent();
item = Q_NULLPTR;
}
delete item;
}
void CookieManager::closeEvent(QCloseEvent* e) void CookieManager::closeEvent(QCloseEvent* e)
{ {
QStringList whitelist; QStringList whitelist;
@ -364,8 +325,7 @@ void CookieManager::closeEvent(QCloseEvent* e)
Settings settings; Settings settings;
settings.beginGroup("Cookie-Settings"); settings.beginGroup("Cookie-Settings");
settings.setValue("allowCookies", ui->saveCookies->isChecked()); settings.setValue("allowCookies", ui->saveCookies->isChecked());
settings.setValue("deleteCookiesOnClose", ui->deleteCookiesOnClose->isChecked()); settings.setValue("filterThirdPartyCookies", ui->filter3rdParty->isChecked());
settings.setValue("allowThirdPartyCookies", ui->allowThirdPartyCookies->currentIndex());
settings.setValue("filterTrackingCookie", ui->filterTracking->isChecked()); settings.setValue("filterTrackingCookie", ui->filterTracking->isChecked());
settings.setValue("whitelist", whitelist); settings.setValue("whitelist", whitelist);
settings.setValue("blacklist", blacklist); settings.setValue("blacklist", blacklist);

View File

@ -28,6 +28,7 @@ class CookieManager;
} }
class QTreeWidgetItem; class QTreeWidgetItem;
class QNetworkCookie;
class BrowserWindow; class BrowserWindow;
@ -43,12 +44,8 @@ public:
private slots: private slots:
void currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* parent); void currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* parent);
void removeCookie(); void remove();
void removeAll(); void removeAll();
void blockCurrentHostAndRemoveCookie();
void slotRefreshTable();
void slotRefreshFilters();
void addWhitelist(); void addWhitelist();
void removeWhitelist(); void removeWhitelist();
@ -56,18 +53,24 @@ private slots:
void removeBlacklist(); void removeBlacklist();
void deletePressed(); void deletePressed();
void saveCookiesChanged(bool state);
void filterString(const QString &string); void filterString(const QString &string);
void addCookie(const QNetworkCookie &cookie);
void removeCookie(const QNetworkCookie &cookie);
private: private:
void closeEvent(QCloseEvent* e); void closeEvent(QCloseEvent* e);
void keyPressEvent(QKeyEvent* e); void keyPressEvent(QKeyEvent* e);
void addBlacklist(const QString &server); void addBlacklist(const QString &server);
QString cookieDomain(const QNetworkCookie &cookie) const;
QTreeWidgetItem *cookieItem(const QNetworkCookie &cookie) const;
Ui::CookieManager* ui; Ui::CookieManager* ui;
bool m_refreshCookieJar; QHash<QString, QTreeWidgetItem*> m_domainHash;
QHash<QTreeWidgetItem*, QNetworkCookie> m_itemHash;
}; };
#endif // COOKIEMANAGER_H #endif // COOKIEMANAGER_H

View File

@ -14,7 +14,16 @@
<string>Cookies</string> <string>Cookies</string>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="margin"> <property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number> <number>4</number>
</property> </property>
<item> <item>
@ -208,7 +217,16 @@
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="margin"> <property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
@ -225,13 +243,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="blockDomain">
<property name="text">
<string>Remove and block domain</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QDialogButtonBox" name="close"> <widget class="QDialogButtonBox" name="close">
<property name="sizePolicy"> <property name="sizePolicy">
@ -371,21 +382,7 @@
<string>Settings</string> <string>Settings</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_4"> <layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0" colspan="3"> <item row="1" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>&lt;b&gt;Cookie Settings&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QCheckBox" name="saveCookies">
<property name="text">
<string>Allow storing of cookies</string>
</property>
</widget>
</item>
<item row="2" column="0">
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
@ -401,46 +398,24 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="2" column="1"> <item row="4" column="1">
<spacer name="horizontalSpacer"> <widget class="QCheckBox" name="filter3rdParty">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="2">
<widget class="QCheckBox" name="deleteCookiesOnClose">
<property name="text"> <property name="text">
<string>Delete cookies on close</string> <string>Filter 3rd party cookies</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="3"> <item row="0" column="0" colspan="3">
<spacer name="horizontalSpacer_22"> <widget class="QLabel" name="label_13">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>344</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="1" colspan="2">
<widget class="QLabel" name="label_14">
<property name="text"> <property name="text">
<string>Allow 3rd party cookies:</string> <string>&lt;b&gt;Cookie Settings&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QCheckBox" name="saveCookies">
<property name="text">
<string>Allow storing of cookies</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -467,7 +442,7 @@
<item row="5" column="1" colspan="3"> <item row="5" column="1" colspan="3">
<widget class="QLabel" name="label_19"> <widget class="QLabel" name="label_19">
<property name="text"> <property name="text">
<string>&lt;b&gt;Warning:&lt;/b&gt; Allow 3rd party and tracking cookies options can lead to deny some cookies from sites. If you have problems with cookies, try to disable these options first!</string> <string>&lt;b&gt;Warning:&lt;/b&gt; Filter 3rd party and tracking cookies options can lead to deny some cookies from sites. If you have problems with cookies, try to disable these options first!</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
@ -481,30 +456,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="3">
<widget class="QComboBox" name="allowThirdPartyCookies">
<property name="toolTip">
<string>&lt;p&gt;&lt;b&gt;Always:&lt;/b&gt; Allow third-party resources to set and retrieve cookies.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Never:&lt;/b&gt; Never allow third-party resources to set and retrieve cookies.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Keep existing:&lt;/b&gt; If the cookie jar already contains cookies from a third-party, allow it to set and retrieve new and existing cookies.&lt;/p&gt;</string>
</property>
<item>
<property name="text">
<string>Always</string>
</property>
</item>
<item>
<property name="text">
<string>Never</string>
</property>
</item>
<item>
<property name="text">
<string>Keep existing</string>
</property>
</item>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>

View File

@ -18,6 +18,7 @@
#include "networkmanager.h" #include "networkmanager.h"
#include "autofill.h" #include "autofill.h"
#include "qztools.h" #include "qztools.h"
#include "cookiejar.h"
#include "mainapplication.h" #include "mainapplication.h"
#include "passwordmanager.h" #include "passwordmanager.h"
#include "sslerrordialog.h" #include "sslerrordialog.h"
@ -48,6 +49,9 @@ NetworkManager::NetworkManager(QObject *parent)
m_urlInterceptor = new NetworkUrlInterceptor(this); m_urlInterceptor = new NetworkUrlInterceptor(this);
mApp->webProfile()->setRequestInterceptor(m_urlInterceptor); mApp->webProfile()->setRequestInterceptor(m_urlInterceptor);
// Create cookie jar
mApp->webProfile()->setCookieStoreClient(mApp->cookieJar());
connect(this, &QNetworkAccessManager::authenticationRequired, this, [this](QNetworkReply *reply, QAuthenticator *auth) { connect(this, &QNetworkAccessManager::authenticationRequired, this, [this](QNetworkReply *reply, QAuthenticator *auth) {
authentication(reply->url(), auth); authentication(reply->url(), auth);
}); });

View File

@ -136,7 +136,7 @@ void ClearPrivateData::dialogAccepted()
} }
if (ui->cookies->isChecked()) { if (ui->cookies->isChecked()) {
mApp->cookieJar()->setAllCookies(QList<QNetworkCookie>()); mApp->cookieJar()->deleteAllCookies();
} }
if (ui->cache->isChecked()) { if (ui->cache->isChecked()) {