allow user to disable all incoming cookies for greate privacy
This commit is contained in:
parent
9b033ad717
commit
d9a651490a
@ -8,6 +8,7 @@
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/externaltool.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
#include "network-web/cookiejar.h"
|
||||
#include "network-web/silentnetworkaccessmanager.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->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_proxyDetails, &NetworkProxyDetails::changed, this, &SettingsBrowserMail::dirtifySettings);
|
||||
connect(m_ui->m_grpCustomExternalBrowser, &QGroupBox::toggled, this, &SettingsBrowserMail::dirtifySettings);
|
||||
@ -153,6 +155,8 @@ void SettingsBrowserMail::selectEmailExecutable() {
|
||||
void SettingsBrowserMail::loadSettings() {
|
||||
onBeginLoadSettings();
|
||||
|
||||
m_ui->m_cbIgnoreAllCookies
|
||||
->setChecked(settings()->value(GROUP(Network), SETTING(Network::IgnoreAllCookies)).toBool());
|
||||
m_ui->m_checkOpenLinksInExternal
|
||||
->setChecked(settings()->value(GROUP(Browser), SETTING(Browser::OpenLinksInExternalBrowserRightAway)).toBool());
|
||||
|
||||
@ -191,6 +195,8 @@ void SettingsBrowserMail::loadSettings() {
|
||||
void SettingsBrowserMail::saveSettings() {
|
||||
onBeginSaveSettings();
|
||||
|
||||
settings()->setValue(GROUP(Network), Network::IgnoreAllCookies, m_ui->m_cbIgnoreAllCookies->isChecked());
|
||||
|
||||
settings()->setValue(GROUP(Browser),
|
||||
Browser::OpenLinksInExternalBrowserRightAway,
|
||||
m_ui->m_checkOpenLinksInExternal->isChecked());
|
||||
@ -229,6 +235,7 @@ void SettingsBrowserMail::saveSettings() {
|
||||
|
||||
ExternalTool::setToolsToSettings(tools);
|
||||
|
||||
qApp->web()->cookieJar()->updateSettings();
|
||||
qApp->web()->updateProxy();
|
||||
|
||||
// Reload settings for all network access managers.
|
||||
|
@ -12,7 +12,7 @@
|
||||
class NetworkProxyDetails;
|
||||
|
||||
class SettingsBrowserMail : public SettingsPanel {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SettingsBrowserMail(Settings* settings, QWidget* parent = nullptr);
|
||||
@ -43,7 +43,7 @@ class SettingsBrowserMail : public SettingsPanel {
|
||||
};
|
||||
|
||||
inline QString SettingsBrowserMail::title() const {
|
||||
return tr("Web browser & e-mail & proxy");
|
||||
return tr("Network & web & tools");
|
||||
}
|
||||
|
||||
#endif // SETTINGSBROWSERMAIL_H
|
||||
|
@ -16,6 +16,20 @@
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</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">
|
||||
<attribute name="title">
|
||||
<string>External web browser</string>
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include <QPointer>
|
||||
|
||||
#if defined(USE_WEBENGINE)
|
||||
|
||||
// WebEngine.
|
||||
DKEY WebEngineAttributes::ID = "web_engine_attributes";
|
||||
#endif
|
||||
@ -42,6 +41,11 @@ DVALUE(QString) Node::PackageFolderDef = QSL(USER_DATA_PLACEHOLDER) + "/node-pac
|
||||
// Cookies.
|
||||
DKEY Cookies::ID = "cookies";
|
||||
|
||||
DKEY Network::ID = "network";
|
||||
|
||||
DKEY Network::IgnoreAllCookies = "ignore_all_cookies";
|
||||
DVALUE(bool) Network::IgnoreAllCookiesDef = false;
|
||||
|
||||
// AdBlock.
|
||||
DKEY AdBlock::ID = "adblock";
|
||||
|
||||
|
@ -316,6 +316,14 @@ namespace GUI {
|
||||
VALUE(char*) StyleDef;
|
||||
} // namespace GUI
|
||||
|
||||
// Network.
|
||||
namespace Network {
|
||||
KEY ID;
|
||||
|
||||
KEY IgnoreAllCookies;
|
||||
VALUE(bool) IgnoreAllCookiesDef;
|
||||
} // namespace Network
|
||||
|
||||
// General.
|
||||
namespace General {
|
||||
KEY ID;
|
||||
|
@ -21,12 +21,14 @@
|
||||
CookieJar::CookieJar(QObject* parent) : QNetworkCookieJar(parent) {
|
||||
#if defined(USE_WEBENGINE)
|
||||
// WebEngine does not store cookies, CookieJar does.
|
||||
QWebEngineProfile::defaultProfile()->setPersistentCookiesPolicy(QWebEngineProfile::PersistentCookiesPolicy::NoPersistentCookies);
|
||||
QWebEngineProfile::defaultProfile()
|
||||
->setPersistentCookiesPolicy(QWebEngineProfile::PersistentCookiesPolicy::NoPersistentCookies);
|
||||
|
||||
m_webEngineCookies = QWebEngineProfile::defaultProfile()->cookieStore();
|
||||
#endif
|
||||
|
||||
// Load all cookies and also set them into WebEngine store.
|
||||
updateSettings();
|
||||
loadCookies();
|
||||
|
||||
#if defined(USE_WEBENGINE)
|
||||
@ -75,7 +77,7 @@ QList<QNetworkCookie> CookieJar::extractCookiesFromUrl(const QString& url) {
|
||||
|
||||
void CookieJar::loadCookies() {
|
||||
Settings* sett = qApp->settings();
|
||||
auto keys = sett->allKeys(Cookies::ID);
|
||||
auto keys = sett->allKeys(GROUP(Cookies));
|
||||
|
||||
for (const QString& cookie_key : qAsConst(keys)) {
|
||||
QByteArray encoded = sett->password(GROUP(Cookies), cookie_key, {}).toByteArray();
|
||||
@ -85,10 +87,7 @@ void CookieJar::loadCookies() {
|
||||
|
||||
if (!cookie.isEmpty()) {
|
||||
if (!insertCookieInternal(cookie.at(0), true, false)) {
|
||||
qCriticalNN << LOGSEC_NETWORK
|
||||
<< "Failed to load cookie"
|
||||
<< QUOTE_W_SPACE(cookie_key)
|
||||
<< "from settings.";
|
||||
qCriticalNN << LOGSEC_NETWORK << "Failed to load cookie" << QUOTE_W_SPACE(cookie_key) << "from settings.";
|
||||
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) {
|
||||
return insertCookieInternal(cookie, false, true);
|
||||
if (m_ignoreAllCookies) {
|
||||
return {};
|
||||
}
|
||||
else {
|
||||
return insertCookieInternal(cookie, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
bool CookieJar::deleteCookie(const QNetworkCookie& cookie) {
|
||||
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) {
|
||||
return updateCookieInternal(cookie, false);
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ class CookieJar : public QNetworkCookieJar {
|
||||
virtual bool updateCookie(const QNetworkCookie& cookie);
|
||||
virtual bool deleteCookie(const QNetworkCookie& cookie);
|
||||
|
||||
void updateSettings();
|
||||
|
||||
public:
|
||||
static QList<QNetworkCookie> extractCookiesFromUrl(const QString& url);
|
||||
|
||||
@ -32,8 +34,10 @@ class CookieJar : public QNetworkCookieJar {
|
||||
|
||||
private:
|
||||
#if defined(USE_WEBENGINE)
|
||||
QWebEngineCookieStore * m_webEngineCookies;
|
||||
QWebEngineCookieStore* m_webEngineCookies;
|
||||
#endif
|
||||
|
||||
bool m_ignoreAllCookies;
|
||||
};
|
||||
|
||||
#endif // COOKIEJAR_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user