Add an initial cookie filter for Qt 5.11

See #3010
This commit is contained in:
Florian Bruhin 2018-06-11 10:16:22 +02:00
parent 093f07f552
commit 3b0c8e46a3
5 changed files with 62 additions and 5 deletions

View File

@ -34,6 +34,8 @@ Added
* New `{audio}` field for `window.title_format` and `tabs.title.format` which * New `{audio}` field for `window.title_format` and `tabs.title.format` which
displays `[M]`/`[A]` for muted/recently audible tabs. displays `[M]`/`[A]` for muted/recently audible tabs.
* New `:tab-mute` command (bound to `<Alt-m>`) to mute/unmute a tab. * New `:tab-mute` command (bound to `<Alt-m>`) 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: - QtWebEngine: New settings:
* Support for requesting persistent storage via * Support for requesting persistent storage via
`navigator.webkitPersistentStorage.requestQuota` with a new `navigator.webkitPersistentStorage.requestQuota` with a new

View File

@ -1540,12 +1540,12 @@ Valid values:
* +all+: Accept all cookies. * +all+: Accept all cookies.
* +no-3rdparty+: Accept cookies from the same origin only. * +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. * +never+: Don't accept cookies at all.
Default: +pass:[no-3rdparty]+ 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]]
=== content.cookies.store === content.cookies.store

View File

@ -0,0 +1,48 @@
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2018 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# 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 <http://www.gnu.org/licenses/>.
"""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

View File

@ -37,7 +37,7 @@ from qutebrowser.config import configdata, config
from qutebrowser.browser import browsertab, mouse, shared from qutebrowser.browser import browsertab, mouse, shared
from qutebrowser.browser.webengine import (webview, webengineelem, tabhistory, from qutebrowser.browser.webengine import (webview, webengineelem, tabhistory,
interceptor, webenginequtescheme, interceptor, webenginequtescheme,
webenginedownloads, cookies, webenginedownloads,
webenginesettings) webenginesettings)
from qutebrowser.misc import miscwidgets from qutebrowser.misc import miscwidgets
from qutebrowser.utils import (usertypes, qtutils, log, javascript, utils, from qutebrowser.utils import (usertypes, qtutils, log, javascript, utils,
@ -74,6 +74,10 @@ def init():
download_manager.install(webenginesettings.private_profile) download_manager.install(webenginesettings.private_profile)
objreg.register('webengine-download-manager', download_manager) 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 # Clear visited links on web history clear
hist = objreg.get('web-history') hist = objreg.get('web-history')
for p in [webenginesettings.default_profile, for p in [webenginesettings.default_profile,

View File

@ -281,14 +281,17 @@ content.cache.appcache:
content.cookies.accept: content.cookies.accept:
default: no-3rdparty default: no-3rdparty
backend: QtWebKit backend:
QtWebKit: true
QtWebEngine: Qt 5.11
type: type:
name: String name: String
valid_values: valid_values:
- all: "Accept all cookies." - all: "Accept all cookies."
- no-3rdparty: "Accept cookies from the same origin only." - no-3rdparty: "Accept cookies from the same origin only."
- no-unknown-3rdparty: "Accept cookies from the same origin only, unless - 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." - never: "Don't accept cookies at all."
desc: Which cookies to accept. desc: Which cookies to accept.