allow user to disable all incoming cookies for greate privacy

This commit is contained in:
Martin Rotter 2022-05-02 13:09:20 +02:00
parent 9b033ad717
commit d9a651490a
7 changed files with 61 additions and 11 deletions

View File

@ -8,6 +8,7 @@
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "miscellaneous/externaltool.h" #include "miscellaneous/externaltool.h"
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
#include "network-web/cookiejar.h"
#include "network-web/silentnetworkaccessmanager.h" #include "network-web/silentnetworkaccessmanager.h"
#include "network-web/webfactory.h" #include "network-web/webfactory.h"
@ -39,6 +40,7 @@ SettingsBrowserMail::SettingsBrowserMail(Settings* settings, QWidget* parent)
m_ui->m_listTools->setHeaderLabels(QStringList() << tr("Executable") << tr("Parameters")); m_ui->m_listTools->setHeaderLabels(QStringList() << tr("Executable") << tr("Parameters"));
m_ui->m_listTools->header()->setSectionResizeMode(0, QHeaderView::ResizeMode::ResizeToContents); m_ui->m_listTools->header()->setSectionResizeMode(0, QHeaderView::ResizeMode::ResizeToContents);
connect(m_ui->m_cbIgnoreAllCookies, &QCheckBox::stateChanged, this, &SettingsBrowserMail::dirtifySettings);
connect(m_ui->m_checkOpenLinksInExternal, &QCheckBox::stateChanged, this, &SettingsBrowserMail::dirtifySettings); connect(m_ui->m_checkOpenLinksInExternal, &QCheckBox::stateChanged, this, &SettingsBrowserMail::dirtifySettings);
connect(m_proxyDetails, &NetworkProxyDetails::changed, this, &SettingsBrowserMail::dirtifySettings); connect(m_proxyDetails, &NetworkProxyDetails::changed, this, &SettingsBrowserMail::dirtifySettings);
connect(m_ui->m_grpCustomExternalBrowser, &QGroupBox::toggled, this, &SettingsBrowserMail::dirtifySettings); connect(m_ui->m_grpCustomExternalBrowser, &QGroupBox::toggled, this, &SettingsBrowserMail::dirtifySettings);
@ -153,6 +155,8 @@ void SettingsBrowserMail::selectEmailExecutable() {
void SettingsBrowserMail::loadSettings() { void SettingsBrowserMail::loadSettings() {
onBeginLoadSettings(); onBeginLoadSettings();
m_ui->m_cbIgnoreAllCookies
->setChecked(settings()->value(GROUP(Network), SETTING(Network::IgnoreAllCookies)).toBool());
m_ui->m_checkOpenLinksInExternal m_ui->m_checkOpenLinksInExternal
->setChecked(settings()->value(GROUP(Browser), SETTING(Browser::OpenLinksInExternalBrowserRightAway)).toBool()); ->setChecked(settings()->value(GROUP(Browser), SETTING(Browser::OpenLinksInExternalBrowserRightAway)).toBool());
@ -191,6 +195,8 @@ void SettingsBrowserMail::loadSettings() {
void SettingsBrowserMail::saveSettings() { void SettingsBrowserMail::saveSettings() {
onBeginSaveSettings(); onBeginSaveSettings();
settings()->setValue(GROUP(Network), Network::IgnoreAllCookies, m_ui->m_cbIgnoreAllCookies->isChecked());
settings()->setValue(GROUP(Browser), settings()->setValue(GROUP(Browser),
Browser::OpenLinksInExternalBrowserRightAway, Browser::OpenLinksInExternalBrowserRightAway,
m_ui->m_checkOpenLinksInExternal->isChecked()); m_ui->m_checkOpenLinksInExternal->isChecked());
@ -229,6 +235,7 @@ void SettingsBrowserMail::saveSettings() {
ExternalTool::setToolsToSettings(tools); ExternalTool::setToolsToSettings(tools);
qApp->web()->cookieJar()->updateSettings();
qApp->web()->updateProxy(); qApp->web()->updateProxy();
// Reload settings for all network access managers. // Reload settings for all network access managers.

View File

@ -43,7 +43,7 @@ class SettingsBrowserMail : public SettingsPanel {
}; };
inline QString SettingsBrowserMail::title() const { inline QString SettingsBrowserMail::title() const {
return tr("Web browser & e-mail & proxy"); return tr("Network & web & tools");
} }
#endif // SETTINGSBROWSERMAIL_H #endif // SETTINGSBROWSERMAIL_H

View File

@ -16,6 +16,20 @@
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="m_tabNetwork">
<attribute name="title">
<string>Network</string>
</attribute>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="m_cbIgnoreAllCookies">
<property name="text">
<string>Do not accept any incoming cookies</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="m_tabExternalBrowser"> <widget class="QWidget" name="m_tabExternalBrowser">
<attribute name="title"> <attribute name="title">
<string>External web browser</string> <string>External web browser</string>

View File

@ -10,7 +10,6 @@
#include <QPointer> #include <QPointer>
#if defined(USE_WEBENGINE) #if defined(USE_WEBENGINE)
// WebEngine. // WebEngine.
DKEY WebEngineAttributes::ID = "web_engine_attributes"; DKEY WebEngineAttributes::ID = "web_engine_attributes";
#endif #endif
@ -42,6 +41,11 @@ DVALUE(QString) Node::PackageFolderDef = QSL(USER_DATA_PLACEHOLDER) + "/node-pac
// Cookies. // Cookies.
DKEY Cookies::ID = "cookies"; DKEY Cookies::ID = "cookies";
DKEY Network::ID = "network";
DKEY Network::IgnoreAllCookies = "ignore_all_cookies";
DVALUE(bool) Network::IgnoreAllCookiesDef = false;
// AdBlock. // AdBlock.
DKEY AdBlock::ID = "adblock"; DKEY AdBlock::ID = "adblock";

View File

@ -316,6 +316,14 @@ namespace GUI {
VALUE(char*) StyleDef; VALUE(char*) StyleDef;
} // namespace GUI } // namespace GUI
// Network.
namespace Network {
KEY ID;
KEY IgnoreAllCookies;
VALUE(bool) IgnoreAllCookiesDef;
} // namespace Network
// General. // General.
namespace General { namespace General {
KEY ID; KEY ID;

View File

@ -21,12 +21,14 @@
CookieJar::CookieJar(QObject* parent) : QNetworkCookieJar(parent) { CookieJar::CookieJar(QObject* parent) : QNetworkCookieJar(parent) {
#if defined(USE_WEBENGINE) #if defined(USE_WEBENGINE)
// WebEngine does not store cookies, CookieJar does. // WebEngine does not store cookies, CookieJar does.
QWebEngineProfile::defaultProfile()->setPersistentCookiesPolicy(QWebEngineProfile::PersistentCookiesPolicy::NoPersistentCookies); QWebEngineProfile::defaultProfile()
->setPersistentCookiesPolicy(QWebEngineProfile::PersistentCookiesPolicy::NoPersistentCookies);
m_webEngineCookies = QWebEngineProfile::defaultProfile()->cookieStore(); m_webEngineCookies = QWebEngineProfile::defaultProfile()->cookieStore();
#endif #endif
// Load all cookies and also set them into WebEngine store. // Load all cookies and also set them into WebEngine store.
updateSettings();
loadCookies(); loadCookies();
#if defined(USE_WEBENGINE) #if defined(USE_WEBENGINE)
@ -75,7 +77,7 @@ QList<QNetworkCookie> CookieJar::extractCookiesFromUrl(const QString& url) {
void CookieJar::loadCookies() { void CookieJar::loadCookies() {
Settings* sett = qApp->settings(); Settings* sett = qApp->settings();
auto keys = sett->allKeys(Cookies::ID); auto keys = sett->allKeys(GROUP(Cookies));
for (const QString& cookie_key : qAsConst(keys)) { for (const QString& cookie_key : qAsConst(keys)) {
QByteArray encoded = sett->password(GROUP(Cookies), cookie_key, {}).toByteArray(); QByteArray encoded = sett->password(GROUP(Cookies), cookie_key, {}).toByteArray();
@ -85,10 +87,7 @@ void CookieJar::loadCookies() {
if (!cookie.isEmpty()) { if (!cookie.isEmpty()) {
if (!insertCookieInternal(cookie.at(0), true, false)) { if (!insertCookieInternal(cookie.at(0), true, false)) {
qCriticalNN << LOGSEC_NETWORK qCriticalNN << LOGSEC_NETWORK << "Failed to load cookie" << QUOTE_W_SPACE(cookie_key) << "from settings.";
<< "Failed to load cookie"
<< QUOTE_W_SPACE(cookie_key)
<< "from settings.";
sett->remove(Cookies::ID, cookie_key); sett->remove(Cookies::ID, cookie_key);
} }
} }
@ -181,13 +180,27 @@ bool CookieJar::deleteCookieInternal(const QNetworkCookie& cookie, bool notify_o
} }
bool CookieJar::insertCookie(const QNetworkCookie& cookie) { bool CookieJar::insertCookie(const QNetworkCookie& cookie) {
if (m_ignoreAllCookies) {
return {};
}
else {
return insertCookieInternal(cookie, false, true); return insertCookieInternal(cookie, false, true);
} }
}
bool CookieJar::deleteCookie(const QNetworkCookie& cookie) { bool CookieJar::deleteCookie(const QNetworkCookie& cookie) {
return deleteCookieInternal(cookie, false); return deleteCookieInternal(cookie, false);
} }
void CookieJar::updateSettings() {
m_ignoreAllCookies = qApp->settings()->value(GROUP(Network), SETTING(Network::IgnoreAllCookies)).toBool();
if (m_ignoreAllCookies) {
setAllCookies({});
qApp->settings()->remove(GROUP(Cookies));
}
}
bool CookieJar::updateCookie(const QNetworkCookie& cookie) { bool CookieJar::updateCookie(const QNetworkCookie& cookie) {
return updateCookieInternal(cookie, false); return updateCookieInternal(cookie, false);
} }

View File

@ -19,6 +19,8 @@ class CookieJar : public QNetworkCookieJar {
virtual bool updateCookie(const QNetworkCookie& cookie); virtual bool updateCookie(const QNetworkCookie& cookie);
virtual bool deleteCookie(const QNetworkCookie& cookie); virtual bool deleteCookie(const QNetworkCookie& cookie);
void updateSettings();
public: public:
static QList<QNetworkCookie> extractCookiesFromUrl(const QString& url); static QList<QNetworkCookie> extractCookiesFromUrl(const QString& url);
@ -34,6 +36,8 @@ class CookieJar : public QNetworkCookieJar {
#if defined(USE_WEBENGINE) #if defined(USE_WEBENGINE)
QWebEngineCookieStore* m_webEngineCookies; QWebEngineCookieStore* m_webEngineCookies;
#endif #endif
bool m_ignoreAllCookies;
}; };
#endif // COOKIEJAR_H #endif // COOKIEJAR_H