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:
parent
00083ad825
commit
a48ea597d0
@ -44,33 +44,26 @@ default_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."""
|
||||
|
||||
GLOBAL_SETTINGS = QWebEngineSettings.globalSettings
|
||||
ENUM_BASE = QWebEngineSettings
|
||||
|
||||
|
||||
class Setter(websettings.Setter):
|
||||
class Setter(Base, websettings.Setter):
|
||||
|
||||
"""A setting set via QWebEngineSettings getter/setter methods."""
|
||||
|
||||
GLOBAL_SETTINGS = QWebEngineSettings.globalSettings
|
||||
|
||||
|
||||
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
|
||||
pass
|
||||
|
||||
|
||||
class DefaultProfileSetter(websettings.Base):
|
||||
@ -204,11 +197,11 @@ def init(args):
|
||||
log.misc.debug("Imported PyOpenGL as workaround")
|
||||
|
||||
_init_profiles()
|
||||
|
||||
# We need to do this here as a WORKAROUND for
|
||||
# https://bugreports.qt.io/browse/QTBUG-58650
|
||||
if not qtutils.version_check('5.9'):
|
||||
PersistentCookiePolicy().set(config.get('content', 'cookies-store'))
|
||||
|
||||
Attribute(QWebEngineSettings.FullScreenSupportEnabled).set(True)
|
||||
|
||||
websettings.init_mappings(MAPPINGS)
|
||||
|
@ -33,33 +33,40 @@ from qutebrowser.utils import standarddir, objreg, urlutils, qtutils
|
||||
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."""
|
||||
|
||||
GLOBAL_SETTINGS = QWebSettings.globalSettings
|
||||
ENUM_BASE = QWebSettings
|
||||
|
||||
|
||||
class Setter(websettings.Setter):
|
||||
class Setter(Base, websettings.Setter):
|
||||
|
||||
"""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."""
|
||||
|
||||
GLOBAL_SETTINGS = QWebSettings.globalSettings
|
||||
pass
|
||||
|
||||
|
||||
class StaticSetter(websettings.StaticSetter):
|
||||
class StaticSetter(Base, websettings.StaticSetter):
|
||||
|
||||
"""A setting set via static QWebSettings getter/setter methods."""
|
||||
|
||||
GLOBAL_SETTINGS = QWebSettings.globalSettings
|
||||
pass
|
||||
|
||||
|
||||
class CookiePolicy(websettings.Base):
|
||||
|
@ -34,24 +34,28 @@ class Base:
|
||||
_default: The default value of this setting.
|
||||
"""
|
||||
|
||||
# Needs to be overridden by subclasses in
|
||||
# webkitsettings.py/webenginesettings.py
|
||||
GLOBAL_SETTINGS = None
|
||||
|
||||
def __init__(self):
|
||||
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):
|
||||
"""Get the QWeb(Engine)Settings object to use.
|
||||
"""Get a list of QWeb(Engine)Settings objects to use.
|
||||
|
||||
Args:
|
||||
settings: The QWeb(Engine)Settings instance to use, or None to use
|
||||
the global instance.
|
||||
|
||||
Return:
|
||||
A list of QWeb(Engine)Settings objects. The first one should be used
|
||||
for reading.
|
||||
"""
|
||||
if settings is None:
|
||||
return self.GLOBAL_SETTINGS() # pylint: disable=not-callable
|
||||
return self._get_global_settings()
|
||||
else:
|
||||
return settings
|
||||
return [settings]
|
||||
|
||||
def save_default(self, settings=None):
|
||||
"""Save the default value based on the currently set one.
|
||||
@ -141,10 +145,11 @@ class Attribute(Base):
|
||||
constructor=True)
|
||||
|
||||
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):
|
||||
self._get_settings(settings).setAttribute(self._attribute, value)
|
||||
for obj in self._get_settings(settings):
|
||||
obj.setAttribute(self._attribute, value)
|
||||
|
||||
|
||||
class Setter(Base):
|
||||
@ -178,16 +183,17 @@ class Setter(Base):
|
||||
def get(self, settings=None):
|
||||
if self._getter is None:
|
||||
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):
|
||||
args = [self._get_settings(settings)]
|
||||
args.extend(self._args)
|
||||
if self._unpack:
|
||||
args.extend(value)
|
||||
else:
|
||||
args.append(value)
|
||||
self._setter(*args)
|
||||
for obj in self._get_settings(settings):
|
||||
args = [obj]
|
||||
args.extend(self._args)
|
||||
if self._unpack:
|
||||
args.extend(value)
|
||||
else:
|
||||
args.append(value)
|
||||
self._setter(*args)
|
||||
|
||||
|
||||
class NullStringSetter(Setter):
|
||||
|
@ -117,3 +117,9 @@ Feature: Using private browsing
|
||||
And I run :session-save (tmpdir)/session.yml
|
||||
And I wait for "Saved session */session.yml." in the log
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user