mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
Bring back support for managing cookies
This commit is contained in:
parent
8ba58860db
commit
4d05c1105a
@ -243,6 +243,16 @@ MainApplication::MainApplication(int &argc, char** argv)
|
||||
setQuitOnLastWindowClosed(true);
|
||||
#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();
|
||||
connect(m_webProfile, &QWebEngineProfile::downloadRequested, this, &MainApplication::downloadRequested);
|
||||
|
||||
@ -257,16 +267,6 @@ MainApplication::MainApplication(int &argc, char** argv)
|
||||
script.setSourceCode(Scripts::setupWebChannel());
|
||||
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);
|
||||
connect(m_autoSaver, SIGNAL(save()), this, SLOT(saveSession()));
|
||||
|
||||
|
@ -29,19 +29,9 @@
|
||||
//#define COOKIE_DEBUG
|
||||
|
||||
CookieJar::CookieJar(QObject* parent)
|
||||
: QNetworkCookieJar(parent)
|
||||
, m_autoSaver(0)
|
||||
: QWebEngineCookieStoreClient(parent)
|
||||
{
|
||||
m_autoSaver = new AutoSaver(this);
|
||||
connect(m_autoSaver, SIGNAL(save()), this, SLOT(saveCookies()));
|
||||
|
||||
loadSettings();
|
||||
restoreCookies();
|
||||
}
|
||||
|
||||
CookieJar::~CookieJar()
|
||||
{
|
||||
m_autoSaver->saveIfNecessary();
|
||||
}
|
||||
|
||||
void CookieJar::loadSettings()
|
||||
@ -49,28 +39,11 @@ void CookieJar::loadSettings()
|
||||
Settings settings;
|
||||
settings.beginGroup("Cookie-Settings");
|
||||
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_deleteOnClose = settings.value("deleteCookiesOnClose", false).toBool();
|
||||
m_whitelist = settings.value("whitelist", QStringList()).toStringList();
|
||||
m_blacklist = settings.value("blacklist", QStringList()).toStringList();
|
||||
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)
|
||||
@ -78,126 +51,17 @@ void CookieJar::setAllowCookies(bool 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) {
|
||||
// If cookie domain is empty, set it to url.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;
|
||||
QNetworkCookie cookie = cookies.first();
|
||||
return !rejectCookie(firstPartyUrl.host(), cookie, cookieSource.host());
|
||||
}
|
||||
|
||||
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) {
|
||||
bool result = listMatchesDomain(m_whitelist, cookieDomain);
|
||||
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")) {
|
||||
#ifdef COOKIE_DEBUG
|
||||
qDebug() << "purged as tracking " << cookie;
|
||||
|
@ -20,50 +20,37 @@
|
||||
|
||||
#include <QFile>
|
||||
#include <QStringList>
|
||||
#include <QNetworkCookieJar>
|
||||
#include <QWebEngineCookieStoreClient>
|
||||
|
||||
#include "qzcommon.h"
|
||||
|
||||
class AutoSaver;
|
||||
|
||||
class QUPZILLA_EXPORT CookieJar : public QNetworkCookieJar
|
||||
class QUPZILLA_EXPORT CookieJar : public QWebEngineCookieStoreClient
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CookieJar(QObject* parent = 0);
|
||||
~CookieJar();
|
||||
|
||||
void loadSettings();
|
||||
|
||||
void setAllowCookies(bool allow);
|
||||
bool setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url);
|
||||
|
||||
QList<QNetworkCookie> allCookies() const;
|
||||
void setAllCookies(const QList<QNetworkCookie> &cookieList);
|
||||
|
||||
void clearCookies();
|
||||
void restoreCookies();
|
||||
|
||||
private slots:
|
||||
void saveCookies();
|
||||
bool acceptCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &cookieSource) Q_DECL_OVERRIDE;
|
||||
|
||||
protected:
|
||||
bool matchDomain(QString cookieDomain, QString siteDomain) const;
|
||||
bool listMatchesDomain(const QStringList &list, const QString &cookieDomain) const;
|
||||
|
||||
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_filterTrackingCookie;
|
||||
int m_allowThirdParty;
|
||||
bool m_deleteOnClose;
|
||||
bool m_filterThirdParty;
|
||||
|
||||
QStringList m_whitelist;
|
||||
QStringList m_blacklist;
|
||||
|
||||
AutoSaver* m_autoSaver;
|
||||
};
|
||||
|
||||
#endif // COOKIEJAR_H
|
||||
|
@ -35,7 +35,6 @@
|
||||
CookieManager::CookieManager()
|
||||
: QWidget()
|
||||
, ui(new Ui::CookieManager)
|
||||
, m_refreshCookieJar(true)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
@ -53,8 +52,7 @@ CookieManager::CookieManager()
|
||||
// Stored Cookies
|
||||
connect(ui->cookieTree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
|
||||
connect(ui->removeAll, SIGNAL(clicked()), this, SLOT(removeAll()));
|
||||
connect(ui->removeOne, SIGNAL(clicked()), this, SLOT(removeCookie()));
|
||||
connect(ui->blockDomain, SIGNAL(clicked()), this, SLOT(blockCurrentHostAndRemoveCookie()));
|
||||
connect(ui->removeOne, SIGNAL(clicked()), this, SLOT(remove()));
|
||||
connect(ui->close, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close()));
|
||||
connect(ui->close2, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close()));
|
||||
connect(ui->close3, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close()));
|
||||
@ -70,16 +68,12 @@ CookieManager::CookieManager()
|
||||
Settings settings;
|
||||
settings.beginGroup("Cookie-Settings");
|
||||
ui->saveCookies->setChecked(settings.value("allowCookies", true).toBool());
|
||||
if (!ui->saveCookies->isChecked()) {
|
||||
ui->deleteCookiesOnClose->setEnabled(false);
|
||||
}
|
||||
ui->deleteCookiesOnClose->setChecked(settings.value("deleteCookiesOnClose", false).toBool());
|
||||
ui->allowThirdPartyCookies->setCurrentIndex(settings.value("allowThirdPartyCookies", 0).toInt());
|
||||
ui->filter3rdParty->setChecked(settings.value("filterThirdPartyCookies", 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();
|
||||
|
||||
connect(ui->saveCookies, SIGNAL(toggled(bool)), this, SLOT(saveCookiesChanged(bool)));
|
||||
|
||||
ui->search->setPlaceholderText(tr("Search"));
|
||||
ui->cookieTree->setDefaultItemShowMode(TreeWidget::ItemsCollapsed);
|
||||
ui->cookieTree->sortItems(0, Qt::AscendingOrder);
|
||||
@ -89,9 +83,19 @@ CookieManager::CookieManager()
|
||||
QShortcut* removeShortcut = new QShortcut(QKeySequence("Del"), this);
|
||||
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()
|
||||
@ -102,56 +106,31 @@ void CookieManager::removeAll()
|
||||
return;
|
||||
}
|
||||
|
||||
QList<QNetworkCookie> emptyList;
|
||||
mApp->cookieJar()->setAllCookies(emptyList);
|
||||
mApp->cookieJar()->deleteAllCookies();
|
||||
|
||||
m_itemHash.clear();
|
||||
m_domainHash.clear();
|
||||
ui->cookieTree->clear();
|
||||
}
|
||||
|
||||
void CookieManager::removeCookie()
|
||||
void CookieManager::remove()
|
||||
{
|
||||
QTreeWidgetItem* current = ui->cookieTree->currentItem();
|
||||
if (!current) {
|
||||
return;
|
||||
}
|
||||
|
||||
QList<QNetworkCookie> allCookies = mApp->cookieJar()->allCookies();
|
||||
|
||||
if (current->text(1).isEmpty()) { //Remove whole cookie group
|
||||
const QString domain = current->data(0, Qt::UserRole + 10).toString();
|
||||
foreach (const QNetworkCookie &cookie, allCookies) {
|
||||
if (cookie.domain() == domain || cookie.domain() == domain.mid(1)) {
|
||||
allCookies.removeOne(cookie);
|
||||
}
|
||||
if (current->childCount()) {
|
||||
for (int i = 0; i < current->childCount(); ++i) {
|
||||
QTreeWidgetItem *item = current->child(i);
|
||||
if (item && m_itemHash.contains(item))
|
||||
removeCookie(m_itemHash.value(item));
|
||||
}
|
||||
|
||||
ui->cookieTree->deleteItem(current);
|
||||
}
|
||||
else {
|
||||
const QNetworkCookie cookie = qvariant_cast<QNetworkCookie>(current->data(0, Qt::UserRole + 10));
|
||||
allCookies.removeOne(cookie);
|
||||
|
||||
QTreeWidgetItem* parentItem = current->parent();
|
||||
ui->cookieTree->deleteItem(current);
|
||||
|
||||
if (parentItem->childCount() == 0) {
|
||||
ui->cookieTree->deleteItem(parentItem);
|
||||
}
|
||||
if (m_itemHash.contains(current))
|
||||
removeCookie(m_itemHash.value(current));
|
||||
}
|
||||
|
||||
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)
|
||||
@ -185,84 +164,6 @@ void CookieManager::currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem
|
||||
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()
|
||||
{
|
||||
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()
|
||||
{
|
||||
delete ui->blackList->currentItem();
|
||||
@ -316,7 +237,7 @@ void CookieManager::removeBlacklist()
|
||||
void CookieManager::deletePressed()
|
||||
{
|
||||
if (ui->cookieTree->hasFocus()) {
|
||||
removeCookie();
|
||||
remove();
|
||||
}
|
||||
else if (ui->whiteList->hasFocus()) {
|
||||
removeWhitelist();
|
||||
@ -326,11 +247,6 @@ void CookieManager::deletePressed()
|
||||
}
|
||||
}
|
||||
|
||||
void CookieManager::saveCookiesChanged(bool state)
|
||||
{
|
||||
ui->deleteCookiesOnClose->setEnabled(state);
|
||||
}
|
||||
|
||||
void CookieManager::filterString(const QString &string)
|
||||
{
|
||||
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)
|
||||
{
|
||||
QStringList whitelist;
|
||||
@ -364,8 +325,7 @@ void CookieManager::closeEvent(QCloseEvent* e)
|
||||
Settings settings;
|
||||
settings.beginGroup("Cookie-Settings");
|
||||
settings.setValue("allowCookies", ui->saveCookies->isChecked());
|
||||
settings.setValue("deleteCookiesOnClose", ui->deleteCookiesOnClose->isChecked());
|
||||
settings.setValue("allowThirdPartyCookies", ui->allowThirdPartyCookies->currentIndex());
|
||||
settings.setValue("filterThirdPartyCookies", ui->filter3rdParty->isChecked());
|
||||
settings.setValue("filterTrackingCookie", ui->filterTracking->isChecked());
|
||||
settings.setValue("whitelist", whitelist);
|
||||
settings.setValue("blacklist", blacklist);
|
||||
|
@ -28,6 +28,7 @@ class CookieManager;
|
||||
}
|
||||
|
||||
class QTreeWidgetItem;
|
||||
class QNetworkCookie;
|
||||
|
||||
class BrowserWindow;
|
||||
|
||||
@ -43,12 +44,8 @@ public:
|
||||
|
||||
private slots:
|
||||
void currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* parent);
|
||||
void removeCookie();
|
||||
void remove();
|
||||
void removeAll();
|
||||
void blockCurrentHostAndRemoveCookie();
|
||||
|
||||
void slotRefreshTable();
|
||||
void slotRefreshFilters();
|
||||
|
||||
void addWhitelist();
|
||||
void removeWhitelist();
|
||||
@ -56,18 +53,24 @@ private slots:
|
||||
void removeBlacklist();
|
||||
|
||||
void deletePressed();
|
||||
void saveCookiesChanged(bool state);
|
||||
|
||||
void filterString(const QString &string);
|
||||
|
||||
void addCookie(const QNetworkCookie &cookie);
|
||||
void removeCookie(const QNetworkCookie &cookie);
|
||||
|
||||
private:
|
||||
void closeEvent(QCloseEvent* e);
|
||||
void keyPressEvent(QKeyEvent* e);
|
||||
|
||||
void addBlacklist(const QString &server);
|
||||
QString cookieDomain(const QNetworkCookie &cookie) const;
|
||||
QTreeWidgetItem *cookieItem(const QNetworkCookie &cookie) const;
|
||||
|
||||
Ui::CookieManager* ui;
|
||||
|
||||
bool m_refreshCookieJar;
|
||||
QHash<QString, QTreeWidgetItem*> m_domainHash;
|
||||
QHash<QTreeWidgetItem*, QNetworkCookie> m_itemHash;
|
||||
};
|
||||
|
||||
#endif // COOKIEMANAGER_H
|
||||
|
@ -14,7 +14,16 @@
|
||||
<string>Cookies</string>
|
||||
</property>
|
||||
<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>
|
||||
</property>
|
||||
<item>
|
||||
@ -208,7 +217,16 @@
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<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>
|
||||
</property>
|
||||
<item>
|
||||
@ -225,13 +243,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="blockDomain">
|
||||
<property name="text">
|
||||
<string>Remove and block domain</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="close">
|
||||
<property name="sizePolicy">
|
||||
@ -371,21 +382,7 @@
|
||||
<string>Settings</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0" colspan="3">
|
||||
<widget class="QLabel" name="label_13">
|
||||
<property name="text">
|
||||
<string><b>Cookie Settings</b></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">
|
||||
<item row="1" column="0">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@ -401,46 +398,24 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<spacer name="horizontalSpacer">
|
||||
<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">
|
||||
<item row="4" column="1">
|
||||
<widget class="QCheckBox" name="filter3rdParty">
|
||||
<property name="text">
|
||||
<string>Delete cookies on close</string>
|
||||
<string>Filter 3rd party cookies</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<spacer name="horizontalSpacer_22">
|
||||
<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">
|
||||
<item row="0" column="0" colspan="3">
|
||||
<widget class="QLabel" name="label_13">
|
||||
<property name="text">
|
||||
<string>Allow 3rd party cookies:</string>
|
||||
<string><b>Cookie Settings</b></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>
|
||||
@ -467,7 +442,7 @@
|
||||
<item row="5" column="1" colspan="3">
|
||||
<widget class="QLabel" name="label_19">
|
||||
<property name="text">
|
||||
<string><b>Warning:</b> 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><b>Warning:</b> 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 name="wordWrap">
|
||||
<bool>true</bool>
|
||||
@ -481,30 +456,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="3">
|
||||
<widget class="QComboBox" name="allowThirdPartyCookies">
|
||||
<property name="toolTip">
|
||||
<string><p><b>Always:</b> Allow third-party resources to set and retrieve cookies.</p>
|
||||
<p><b>Never:</b> Never allow third-party resources to set and retrieve cookies.</p>
|
||||
<p><b>Keep existing:</b> If the cookie jar already contains cookies from a third-party, allow it to set and retrieve new and existing cookies.</p></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>
|
||||
</widget>
|
||||
</widget>
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "networkmanager.h"
|
||||
#include "autofill.h"
|
||||
#include "qztools.h"
|
||||
#include "cookiejar.h"
|
||||
#include "mainapplication.h"
|
||||
#include "passwordmanager.h"
|
||||
#include "sslerrordialog.h"
|
||||
@ -48,6 +49,9 @@ NetworkManager::NetworkManager(QObject *parent)
|
||||
m_urlInterceptor = new NetworkUrlInterceptor(this);
|
||||
mApp->webProfile()->setRequestInterceptor(m_urlInterceptor);
|
||||
|
||||
// Create cookie jar
|
||||
mApp->webProfile()->setCookieStoreClient(mApp->cookieJar());
|
||||
|
||||
connect(this, &QNetworkAccessManager::authenticationRequired, this, [this](QNetworkReply *reply, QAuthenticator *auth) {
|
||||
authentication(reply->url(), auth);
|
||||
});
|
||||
|
@ -136,7 +136,7 @@ void ClearPrivateData::dialogAccepted()
|
||||
}
|
||||
|
||||
if (ui->cookies->isChecked()) {
|
||||
mApp->cookieJar()->setAllCookies(QList<QNetworkCookie>());
|
||||
mApp->cookieJar()->deleteAllCookies();
|
||||
}
|
||||
|
||||
if (ui->cache->isChecked()) {
|
||||
|
Loading…
Reference in New Issue
Block a user