From fc4c7bd2e449fe2fca2abbde9f49e96e458cdc24 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Fri, 5 Jun 2015 15:57:43 +0200 Subject: [PATCH] Merge the cookies-accept and third-party-cookie-policy settings --- doc/help/settings.asciidoc | 23 ++++++----------------- qutebrowser/config/configdata.py | 8 ++------ qutebrowser/config/configtypes.py | 19 +++++++------------ qutebrowser/config/websettings.py | 24 ++++++++++++------------ 4 files changed, 27 insertions(+), 47 deletions(-) diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index 717a46d13..da631e52f 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -149,9 +149,8 @@ |<>|Whether all javascript alerts should be ignored. |<>|Whether locally loaded documents are allowed to access remote urls. |<>|Whether locally loaded documents are allowed to access other local urls. -|<>|Whether to accept cookies. +|<>|Control which cookies to accept. |<>|Whether to store cookies. -|<>|Accept cookies from domains other than the main website |<>|List of URLs of lists which contain hosts to block. |<>|Whether host blocking is enabled. |============== @@ -1317,14 +1316,16 @@ Default: +pass:[true]+ [[content-cookies-accept]] === cookies-accept -Whether to accept cookies. +Control which cookies to accept. Valid values: - * +default+: Default QtWebKit behavior. + * +all+: Accept all cookies. + * +no-3rdparty+: Accept cookies from the same origin only. + * +no-unknown-3rdparty+: Accept cookies from the same origin only, unless a cookie is already set for the domain. * +never+: Don't accept cookies at all. -Default: +pass:[default]+ +Default: +pass:[no-3rdparty]+ [[content-cookies-store]] === cookies-store @@ -1337,18 +1338,6 @@ Valid values: Default: +pass:[true]+ -[[content-third-party-cookie-policy]] -=== third-party-cookie-policy -Accept cookies from domains other than the main website - -Valid values: - - * +always+: Always accept. - * +never+: Never accept. - * +existing+: Only accept if we already have acookie stored for the domain - -Default: +pass:[never]+ - [[content-host-block-lists]] === host-block-lists List of URLs of lists which contain hosts to block. diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 9028d2c78..7a8d3ea83 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -674,17 +674,13 @@ def data(readonly=False): "local urls."), ('cookies-accept', - SettingValue(typ.AcceptCookies(), 'default'), - "Whether to accept cookies."), + SettingValue(typ.AcceptCookies(), 'no-3rdparty'), + "Control which cookies to accept."), ('cookies-store', SettingValue(typ.Bool(), 'true'), "Whether to store cookies."), - ('third-party-cookie-policy', - SettingValue(typ.ThirdPartyCookiePolicy(), 'never'), - "Accept cookies from domains other than the main website"), - ('host-block-lists', SettingValue( typ.UrlList(none_ok=True), diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index b4d7319c6..6aaef90db 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -1323,22 +1323,17 @@ class LastClose(BaseType): class AcceptCookies(BaseType): - """Whether to accept a cookie.""" + """Control which cookies to accept.""" - valid_values = ValidValues(('default', "Default QtWebKit behavior."), + valid_values = ValidValues(('all', "Accept all cookies."), + ('no-3rdparty', "Accept cookies from the same" + " origin only."), + ('no-unknown-3rdparty', "Accept cookies from " + "the same origin only, unless a cookie is " + "already set for the domain."), ('never', "Don't accept cookies at all.")) -class ThirdPartyCookiePolicy(BaseType): - - """Accept cookies from domains other than the main website.""" - - valid_values = ValidValues(('always', "Always accept."), - ('never', "Never accept."), - ('existing', "Only accept if we already have a" - "cookie stored for the domain.")) - - class ConfirmQuit(List): """Whether to display a confirmation when the window is closed.""" diff --git a/qutebrowser/config/websettings.py b/qutebrowser/config/websettings.py index edea4edeb..c3216aae2 100644 --- a/qutebrowser/config/websettings.py +++ b/qutebrowser/config/websettings.py @@ -238,23 +238,23 @@ class GlobalSetter(Setter): self._setter(*args) -class ThirdPartyCookies(Base): +class CookiePolicy(Base): """The ThirdPartyCookiePolicy setting is different from other settings.""" - mapping = ( - ('always', QWebSettings.AlwaysAllowThirdPartyCookies), - ('never', QWebSettings.AlwaysBlockThirdPartyCookies), - ('existing', QWebSettings.AllowThirdPartyWithExistingCookies), - ) + MAPPING = { + 'all': QWebSettings.AlwaysAllowThirdPartyCookies, + 'no-3rdparty': QWebSettings.AlwaysBlockThirdPartyCookies, + 'never': QWebSettings.AlwaysBlockThirdPartyCookies, + 'no-unknown-3rdparty': QWebSettings.AllowThirdPartyWithExistingCookies, + } def get(self, qws=None): - policy = QWebSettings.globalSettings().thirdPartyCookiePolicy() - return tuple(filter(lambda i: i[1] == policy, self.mapping))[0][0] + return config.get('content', 'cookies-accept') def _set(self, value, qws=None): - x = filter(lambda i: i[0] == value, self.mapping) - QWebSettings.globalSettings().setThirdPartyCookiePolicy(tuple(x)[0][1]) + QWebSettings.globalSettings().setThirdPartyCookiePolicy( + self.MAPPING[value]) MAPPINGS = { @@ -283,8 +283,8 @@ MAPPINGS = { Attribute(QWebSettings.LocalContentCanAccessRemoteUrls), 'local-content-can-access-file-urls': Attribute(QWebSettings.LocalContentCanAccessFileUrls), - 'third-party-cookie-policy': - ThirdPartyCookies(), + 'cookies-accept': + CookiePolicy(), }, 'network': { 'dns-prefetch':