Add support for content -> cookies-store with QtWebEngine

This commit is contained in:
Florian Bruhin 2017-02-06 10:47:03 +01:00
parent 4104056950
commit bd0b62ab80
4 changed files with 28 additions and 8 deletions

View File

@ -25,6 +25,7 @@ Added
- link:https://github.com/annulen/webkit/wiki[QtWebKit Reloaded] (also called QtWebKit-NG) is now supported. - link:https://github.com/annulen/webkit/wiki[QtWebKit Reloaded] (also called QtWebKit-NG) is now supported.
- Printing support for QtWebEngine with Qt >= 5.8 - Printing support for QtWebEngine with Qt >= 5.8
- Proxy support for QtWebEngine with Qt >= 5.8 - Proxy support for QtWebEngine with Qt >= 5.8
- Support for the `content -> cookies-store` option with QtWebEngine
Changed Changed
~~~~~~~ ~~~~~~~

View File

@ -172,7 +172,7 @@
|<<content-local-content-can-access-remote-urls,local-content-can-access-remote-urls>>|Whether locally loaded documents are allowed to access remote urls. |<<content-local-content-can-access-remote-urls,local-content-can-access-remote-urls>>|Whether locally loaded documents are allowed to access remote urls.
|<<content-local-content-can-access-file-urls,local-content-can-access-file-urls>>|Whether locally loaded documents are allowed to access other local urls. |<<content-local-content-can-access-file-urls,local-content-can-access-file-urls>>|Whether locally loaded documents are allowed to access other local urls.
|<<content-cookies-accept,cookies-accept>>|Control which cookies to accept. |<<content-cookies-accept,cookies-accept>>|Control which cookies to accept.
|<<content-cookies-store,cookies-store>>|Whether to store cookies. |<<content-cookies-store,cookies-store>>|Whether to store cookies. Note this option needs a restart with QtWebEngine.
|<<content-host-block-lists,host-block-lists>>|List of URLs of lists which contain hosts to block. |<<content-host-block-lists,host-block-lists>>|List of URLs of lists which contain hosts to block.
|<<content-host-blocking-enabled,host-blocking-enabled>>|Whether host blocking is enabled. |<<content-host-blocking-enabled,host-blocking-enabled>>|Whether host blocking is enabled.
|<<content-host-blocking-whitelist,host-blocking-whitelist>>|List of domains that should always be loaded, despite being ad-blocked. |<<content-host-blocking-whitelist,host-blocking-whitelist>>|List of domains that should always be loaded, despite being ad-blocked.
@ -1594,7 +1594,7 @@ This setting is only available with the QtWebKit backend.
[[content-cookies-store]] [[content-cookies-store]]
=== cookies-store === cookies-store
Whether to store cookies. Whether to store cookies. Note this option needs a restart with QtWebEngine.
Valid values: Valid values:
@ -1603,8 +1603,6 @@ Valid values:
Default: +pass:[true]+ Default: +pass:[true]+
This setting is only available with the QtWebKit backend.
[[content-host-block-lists]] [[content-host-block-lists]]
=== host-block-lists === host-block-lists
List of URLs of lists which contain hosts to block. List of URLs of lists which contain hosts to block.

View File

@ -32,7 +32,7 @@ from PyQt5.QtWebEngineWidgets import (QWebEngineSettings, QWebEngineProfile,
# pylint: enable=no-name-in-module,import-error,useless-suppression # pylint: enable=no-name-in-module,import-error,useless-suppression
from qutebrowser.browser import shared from qutebrowser.browser import shared
from qutebrowser.config import websettings from qutebrowser.config import config, websettings
from qutebrowser.utils import objreg, utils, standarddir, javascript from qutebrowser.utils import objreg, utils, standarddir, javascript
@ -65,6 +65,21 @@ class StaticSetter(websettings.StaticSetter):
GLOBAL_SETTINGS = QWebEngineSettings.globalSettings GLOBAL_SETTINGS = QWebEngineSettings.globalSettings
class PersistentCookiePolicy(websettings.Base):
"""The cookies -> store setting is different from other settings."""
def get(self, settings=None):
return config.get('content', 'cookies-store')
def _set(self, value, settings=None):
utils.unused(settings)
QWebEngineProfile.defaultProfile().setPersistentCookiesPolicy(
QWebEngineProfile.AllowPersistentCookies if value else
QWebEngineProfile.NoPersistentCookies
)
def _init_stylesheet(profile): def _init_stylesheet(profile):
"""Initialize custom stylesheets. """Initialize custom stylesheets.
@ -121,6 +136,9 @@ def init(args):
profile = QWebEngineProfile.defaultProfile() profile = QWebEngineProfile.defaultProfile()
_init_profile(profile) _init_profile(profile)
_init_stylesheet(profile) _init_stylesheet(profile)
# We need to do this here as a WORKAROUND for
# https://bugreports.qt.io/browse/QTBUG-58650
PersistentCookiePolicy().set(config.get('content', 'cookies-store'))
websettings.init_mappings(MAPPINGS) websettings.init_mappings(MAPPINGS)
objreg.get('config').changed.connect(update_settings) objreg.get('config').changed.connect(update_settings)
@ -169,6 +187,9 @@ MAPPINGS = {
Attribute(QWebEngineSettings.LocalContentCanAccessRemoteUrls), Attribute(QWebEngineSettings.LocalContentCanAccessRemoteUrls),
'local-content-can-access-file-urls': 'local-content-can-access-file-urls':
Attribute(QWebEngineSettings.LocalContentCanAccessFileUrls), Attribute(QWebEngineSettings.LocalContentCanAccessFileUrls),
# https://bugreports.qt.io/browse/QTBUG-58650
# 'cookies-store':
# PersistentCookiePolicy(),
}, },
'input': { 'input': {
'spatial-navigation': 'spatial-navigation':

View File

@ -891,9 +891,9 @@ def data(readonly=False):
"Control which cookies to accept."), "Control which cookies to accept."),
('cookies-store', ('cookies-store',
SettingValue(typ.Bool(), 'true', SettingValue(typ.Bool(), 'true'),
backends=[usertypes.Backend.QtWebKit]), "Whether to store cookies. Note this option needs a restart with "
"Whether to store cookies."), "QtWebEngine."),
('host-block-lists', ('host-block-lists',
SettingValue( SettingValue(