Set websettings on each profile's setting object

Turns out QWebEngineSettings.globalSettings() only sets things on the default
profile. We now get everything from the default profile settings, but set it on
both the default and the private profile.

Fixes #2638

(cherry picked from commit b11a4388cd10b6ff2fd917fca689ebdc50d581ae)
This commit is contained in:
Florian Bruhin 2017-05-17 06:28:27 +02:00
parent 00083ad825
commit a48ea597d0
4 changed files with 56 additions and 44 deletions

View File

@ -44,33 +44,26 @@ default_profile = None
private_profile = None private_profile = None
class Attribute(websettings.Attribute): class Base(websettings.Base):
"""Base settings class with appropriate _get_global_settings."""
def _get_global_settings(self):
return [default_profile.settings(), private_profile.settings()]
class Attribute(Base, websettings.Attribute):
"""A setting set via QWebEngineSettings::setAttribute.""" """A setting set via QWebEngineSettings::setAttribute."""
GLOBAL_SETTINGS = QWebEngineSettings.globalSettings
ENUM_BASE = QWebEngineSettings ENUM_BASE = QWebEngineSettings
class Setter(websettings.Setter): class Setter(Base, websettings.Setter):
"""A setting set via QWebEngineSettings getter/setter methods.""" """A setting set via QWebEngineSettings getter/setter methods."""
GLOBAL_SETTINGS = QWebEngineSettings.globalSettings pass
class NullStringSetter(websettings.NullStringSetter):
"""A setter for settings requiring a null QString as default."""
GLOBAL_SETTINGS = QWebEngineSettings.globalSettings
class StaticSetter(websettings.StaticSetter):
"""A setting set via static QWebEngineSettings getter/setter methods."""
GLOBAL_SETTINGS = QWebEngineSettings.globalSettings
class DefaultProfileSetter(websettings.Base): class DefaultProfileSetter(websettings.Base):
@ -204,11 +197,11 @@ def init(args):
log.misc.debug("Imported PyOpenGL as workaround") log.misc.debug("Imported PyOpenGL as workaround")
_init_profiles() _init_profiles()
# We need to do this here as a WORKAROUND for # We need to do this here as a WORKAROUND for
# https://bugreports.qt.io/browse/QTBUG-58650 # https://bugreports.qt.io/browse/QTBUG-58650
if not qtutils.version_check('5.9'): if not qtutils.version_check('5.9'):
PersistentCookiePolicy().set(config.get('content', 'cookies-store')) PersistentCookiePolicy().set(config.get('content', 'cookies-store'))
Attribute(QWebEngineSettings.FullScreenSupportEnabled).set(True) Attribute(QWebEngineSettings.FullScreenSupportEnabled).set(True)
websettings.init_mappings(MAPPINGS) websettings.init_mappings(MAPPINGS)

View File

@ -33,33 +33,40 @@ from qutebrowser.utils import standarddir, objreg, urlutils, qtutils
from qutebrowser.browser import shared from qutebrowser.browser import shared
class Attribute(websettings.Attribute): class Base(websettings.Base):
"""Base settings class with appropriate _get_global_settings."""
def _get_global_settings(self):
return [QWebSettings.globalSettings()]
class Attribute(Base, websettings.Attribute):
"""A setting set via QWebSettings::setAttribute.""" """A setting set via QWebSettings::setAttribute."""
GLOBAL_SETTINGS = QWebSettings.globalSettings
ENUM_BASE = QWebSettings ENUM_BASE = QWebSettings
class Setter(websettings.Setter): class Setter(Base, websettings.Setter):
"""A setting set via QWebSettings getter/setter methods.""" """A setting set via QWebSettings getter/setter methods."""
GLOBAL_SETTINGS = QWebSettings.globalSettings pass
class NullStringSetter(websettings.NullStringSetter): class NullStringSetter(Base, websettings.NullStringSetter):
"""A setter for settings requiring a null QString as default.""" """A setter for settings requiring a null QString as default."""
GLOBAL_SETTINGS = QWebSettings.globalSettings pass
class StaticSetter(websettings.StaticSetter): class StaticSetter(Base, websettings.StaticSetter):
"""A setting set via static QWebSettings getter/setter methods.""" """A setting set via static QWebSettings getter/setter methods."""
GLOBAL_SETTINGS = QWebSettings.globalSettings pass
class CookiePolicy(websettings.Base): class CookiePolicy(websettings.Base):

View File

@ -34,24 +34,28 @@ class Base:
_default: The default value of this setting. _default: The default value of this setting.
""" """
# Needs to be overridden by subclasses in
# webkitsettings.py/webenginesettings.py
GLOBAL_SETTINGS = None
def __init__(self): def __init__(self):
self._default = UNSET self._default = UNSET
def _get_global_settings(self):
"""Get a list of global QWeb(Engine)Settings to use."""
raise NotImplementedError
def _get_settings(self, settings): def _get_settings(self, settings):
"""Get the QWeb(Engine)Settings object to use. """Get a list of QWeb(Engine)Settings objects to use.
Args: Args:
settings: The QWeb(Engine)Settings instance to use, or None to use settings: The QWeb(Engine)Settings instance to use, or None to use
the global instance. the global instance.
Return:
A list of QWeb(Engine)Settings objects. The first one should be used
for reading.
""" """
if settings is None: if settings is None:
return self.GLOBAL_SETTINGS() # pylint: disable=not-callable return self._get_global_settings()
else: else:
return settings return [settings]
def save_default(self, settings=None): def save_default(self, settings=None):
"""Save the default value based on the currently set one. """Save the default value based on the currently set one.
@ -141,10 +145,11 @@ class Attribute(Base):
constructor=True) constructor=True)
def get(self, settings=None): def get(self, settings=None):
return self._get_settings(settings).attribute(self._attribute) return self._get_settings(settings)[0].attribute(self._attribute)
def _set(self, value, settings=None): def _set(self, value, settings=None):
self._get_settings(settings).setAttribute(self._attribute, value) for obj in self._get_settings(settings):
obj.setAttribute(self._attribute, value)
class Setter(Base): class Setter(Base):
@ -178,16 +183,17 @@ class Setter(Base):
def get(self, settings=None): def get(self, settings=None):
if self._getter is None: if self._getter is None:
raise AttributeError("No getter set!") raise AttributeError("No getter set!")
return self._getter(self._get_settings(settings), *self._args) return self._getter(self._get_settings(settings)[0], *self._args)
def _set(self, value, settings=None): def _set(self, value, settings=None):
args = [self._get_settings(settings)] for obj in self._get_settings(settings):
args.extend(self._args) args = [obj]
if self._unpack: args.extend(self._args)
args.extend(value) if self._unpack:
else: args.extend(value)
args.append(value) else:
self._setter(*args) args.append(value)
self._setter(*args)
class NullStringSetter(Setter): class NullStringSetter(Setter):

View File

@ -117,3 +117,9 @@ Feature: Using private browsing
And I run :session-save (tmpdir)/session.yml And I run :session-save (tmpdir)/session.yml
And I wait for "Saved session */session.yml." in the log And I wait for "Saved session */session.yml." in the log
Then the file session.yml should not contain "hello.txt" Then the file session.yml should not contain "hello.txt"
# https://github.com/qutebrowser/qutebrowser/issues/2638
Scenario: Turning off javascript with private browsing
When I set content -> allow-javascript to false
And I open data/javascript/consolelog.html in a private window
Then the javascript message "console.log works!" should not be logged