diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc index 9d73c0268..becaae355 100644 --- a/doc/changelog.asciidoc +++ b/doc/changelog.asciidoc @@ -34,6 +34,8 @@ Added * New `{audio}` field for `window.title_format` and `tabs.title.format` which displays `[M]`/`[A]` for muted/recently audible tabs. * New `:tab-mute` command (bound to ``) to mute/unmute a tab. +- QtWebEngine: Support for `content.cookies.accept` with third-party cookies + blocked by default (requires Qt 5.11). - QtWebEngine: New settings: * Support for requesting persistent storage via `navigator.webkitPersistentStorage.requestQuota` with a new diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index a9b2fc6bd..9143a4c41 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -1540,12 +1540,12 @@ Valid values: * +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. + * +no-unknown-3rdparty+: Accept cookies from the same origin only, unless a cookie is already set for the domain. On QtWebEngine, this is the same as no-3rdparty. * +never+: Don't accept cookies at all. Default: +pass:[no-3rdparty]+ -This setting is only available with the QtWebKit backend. +On QtWebEngine, this setting requires Qt 5.11 or newer. [[content.cookies.store]] === content.cookies.store diff --git a/qutebrowser/browser/webengine/cookies.py b/qutebrowser/browser/webengine/cookies.py new file mode 100644 index 000000000..d9d11cd98 --- /dev/null +++ b/qutebrowser/browser/webengine/cookies.py @@ -0,0 +1,48 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2018 Florian Bruhin (The Compiler) +# +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see . + +"""Filter for QtWebEngine cookies.""" + +from qutebrowser.config import config +from qutebrowser.utils import utils + + +def _accept_cookie(request): + """Check whether the given cookie should be accepted.""" + accept = config.val.content.cookies.accept + if accept == 'all': + return True + elif accept in ['no-3rdparty', 'no-unknown-3rdparty']: + return not request.thirdParty + elif accept == 'never': + return False + else: + raise utils.Unreachable + + +def install_filter(profile): + """Install the cookie filter on the given profile. + + On Qt < 5.11, the filter isn't installed. + """ + store = profile.cookieStore() + try: + store.setCookieFilter(_accept_cookie) + except AttributeError: + pass diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index e802df483..4c9d1f7d9 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -37,7 +37,7 @@ from qutebrowser.config import configdata, config from qutebrowser.browser import browsertab, mouse, shared from qutebrowser.browser.webengine import (webview, webengineelem, tabhistory, interceptor, webenginequtescheme, - webenginedownloads, + cookies, webenginedownloads, webenginesettings) from qutebrowser.misc import miscwidgets from qutebrowser.utils import (usertypes, qtutils, log, javascript, utils, @@ -74,6 +74,10 @@ def init(): download_manager.install(webenginesettings.private_profile) objreg.register('webengine-download-manager', download_manager) + log.init.debug("Initializing cookie filter...") + cookies.install_filter(webenginesettings.default_profile) + cookies.install_filter(webenginesettings.private_profile) + # Clear visited links on web history clear hist = objreg.get('web-history') for p in [webenginesettings.default_profile, diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index d32ffef25..49e037538 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -281,14 +281,17 @@ content.cache.appcache: content.cookies.accept: default: no-3rdparty - backend: QtWebKit + backend: + QtWebKit: true + QtWebEngine: Qt 5.11 type: name: String valid_values: - 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." + a cookie is already set for the domain. On QtWebEngine, this is the + same as no-3rdparty." - never: "Don't accept cookies at all." desc: Which cookies to accept.