Fix issues with per-domain proof-of-concept

This commit is contained in:
Florian Bruhin 2018-02-18 20:06:43 +01:00
parent d09afdf0ee
commit 74a7676111
8 changed files with 47 additions and 40 deletions

View File

@ -299,7 +299,7 @@ def init(args):
def update_for_tab(tab, url): def update_for_tab(tab, url):
websettings.update_mappings(MAPPINGS, option, url, tab.settings()) websettings.update_for_tab(MAPPINGS, tab, url)
def shutdown(): def shutdown():

View File

@ -906,7 +906,7 @@ class WebEngineTab(browsertab.AbstractTab):
page.loadFinished.connect(self._restore_zoom) page.loadFinished.connect(self._restore_zoom)
page.loadFinished.connect(self._on_load_finished) page.loadFinished.connect(self._on_load_finished)
self.on_url_changed.connect( self.url_changed.connect(
functools.partial(webenginesettings.update_for_tab, self)) functools.partial(webenginesettings.update_for_tab, self))
def event_target(self): def event_target(self):

View File

@ -118,8 +118,8 @@ def _update_settings(option):
websettings.update_mappings(MAPPINGS, option) websettings.update_mappings(MAPPINGS, option)
def update_for_tab(tab, url, option): def update_for_tab(tab, url):
websettings.update_mappings(MAPPINGS, option, url, tab.settings()) websettings.update_for_tab(MAPPINGS, tab, url)
def init(_args): def init(_args):

View File

@ -36,7 +36,8 @@ from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtPrintSupport import QPrinter from PyQt5.QtPrintSupport import QPrinter
from qutebrowser.browser import browsertab from qutebrowser.browser import browsertab
from qutebrowser.browser.webkit import webview, tabhistory, webkitelem from qutebrowser.browser.webkit import (webview, tabhistory, webkitelem,
webkitsettings)
from qutebrowser.utils import qtutils, objreg, usertypes, utils, log, debug from qutebrowser.utils import qtutils, objreg, usertypes, utils, log, debug
@ -780,7 +781,7 @@ class WebKitTab(browsertab.AbstractTab):
frame.contentsSizeChanged.connect(self._on_contents_size_changed) frame.contentsSizeChanged.connect(self._on_contents_size_changed)
frame.initialLayoutCompleted.connect(self._on_history_trigger) frame.initialLayoutCompleted.connect(self._on_history_trigger)
self.on_url_changed.connect( self.url_changed.connect(
functools.partial(webkitsettings.update_for_tab, self)) functools.partial(webkitsettings.update_for_tab, self))
def event_target(self): def event_target(self):

View File

@ -190,7 +190,7 @@ class KeyConfig:
log.keyboard.vdebug("Adding binding {} -> {} in mode {}.".format( log.keyboard.vdebug("Adding binding {} -> {} in mode {}.".format(
key, command, mode)) key, command, mode))
bindings = self._config.get_obj('bindings.commands') bindings = self._config.get_mutable_obj('bindings.commands')
if mode not in bindings: if mode not in bindings:
bindings[mode] = {} bindings[mode] = {}
bindings[mode][key] = command bindings[mode][key] = command
@ -200,7 +200,7 @@ class KeyConfig:
"""Restore a default keybinding.""" """Restore a default keybinding."""
key = self._prepare(key, mode) key = self._prepare(key, mode)
bindings_commands = self._config.get_obj('bindings.commands') bindings_commands = self._config.get_mutable_obj('bindings.commands')
try: try:
del bindings_commands[mode][key] del bindings_commands[mode][key]
except KeyError: except KeyError:
@ -212,7 +212,7 @@ class KeyConfig:
"""Unbind the given key in the given mode.""" """Unbind the given key in the given mode."""
key = self._prepare(key, mode) key = self._prepare(key, mode)
bindings_commands = self._config.get_obj('bindings.commands') bindings_commands = self._config.get_mutable_obj('bindings.commands')
if val.bindings.commands[mode].get(key, None) is not None: if val.bindings.commands[mode].get(key, None) is not None:
# In custom bindings -> remove it # In custom bindings -> remove it
@ -252,15 +252,17 @@ class Config(QObject):
def __init__(self, yaml_config, parent=None): def __init__(self, yaml_config, parent=None):
super().__init__(parent) super().__init__(parent)
self.changed.connect(_render_stylesheet.cache_clear) self.changed.connect(_render_stylesheet.cache_clear)
self._values = {}
self._mutables = {} self._mutables = {}
self._yaml = yaml_config self._yaml = yaml_config
self._values = {}
for name, opt in configdata.DATA.items():
self._values[name] = configutils.Values(opt)
def __iter__(self): def __iter__(self):
"""Iterate over Option, ScopedValue tuples.""" """Iterate over Option, configutils.Values tuples."""
for name, values in sorted(self._values.items()): for name, values in sorted(self._values.items()):
for scoped in values: yield self.get_opt(name), values
yield self.get_opt(name), scoped
def init_save_manager(self, save_manager): def init_save_manager(self, save_manager):
"""Make sure the config gets saved properly. """Make sure the config gets saved properly.
@ -277,8 +279,7 @@ class Config(QObject):
raise configexc.BackendError(opt.name, objects.backend) raise configexc.BackendError(opt.name, objects.backend)
opt.typ.to_py(value) # for validation opt.typ.to_py(value) # for validation
scoped = configutils.ScopedValue(opt.typ.from_obj(value), pattern) self._values[opt.name].add(opt.typ.from_obj(value), pattern)
self._values[opt.name].add(scoped)
self.changed.emit(opt.name) self.changed.emit(opt.name)
log.config.debug("Config option changed: {} = {}".format( log.config.debug("Config option changed: {} = {}".format(
@ -305,7 +306,7 @@ class Config(QObject):
def get(self, name, url=None): def get(self, name, url=None):
"""Get the given setting converted for Python code.""" """Get the given setting converted for Python code."""
opt = self.get_opt(name) opt = self.get_opt(name)
obj = self.get_obj(name, mutable=False, url=url) obj = self.get_obj(name, url=url)
return opt.typ.to_py(obj) return opt.typ.to_py(obj)
def _maybe_copy(self, value): def _maybe_copy(self, value):
@ -511,7 +512,7 @@ class ConfigContainer:
return self._config.get(name) return self._config.get(name)
else: else:
# access from config.py # access from config.py
return self._config.get_obj(name) return self._config.get_mutable_obj(name)
def __setattr__(self, attr, value): def __setattr__(self, attr, value):
"""Set the given option in the config.""" """Set the given option in the config."""

View File

@ -191,8 +191,8 @@ class ConfigCommands:
with self._handle_config_error(): with self._handle_config_error():
opt = self._config.get_opt(option) opt = self._config.get_opt(option)
old_value = self._config.get_obj(option, mutable=False, old_value = self._config.get_obj_for_pattern(option,
pattern=pattern) pattern=pattern)
if not values and isinstance(opt.typ, configtypes.Bool): if not values and isinstance(opt.typ, configtypes.Bool):
values = ['true', 'false'] values = ['true', 'false']
@ -318,7 +318,7 @@ class ConfigCommands:
commented = True commented = True
else: else:
options = list(self._config) options = list(self._config)
bindings = dict(self._config.get_obj('bindings.commands')) bindings = dict(self._config.get_mutable_obj('bindings.commands'))
commented = False commented = False
writer = configfiles.ConfigPyWriter(options, bindings, writer = configfiles.ConfigPyWriter(options, bindings,

View File

@ -87,9 +87,12 @@ class YamlConfig(QObject):
super().__init__(parent) super().__init__(parent)
self._filename = os.path.join(standarddir.config(auto=True), self._filename = os.path.join(standarddir.config(auto=True),
'autoconfig.yml') 'autoconfig.yml')
self._values = {}
self._dirty = None self._dirty = None
self._values = {}
for name, opt in configdata.DATA.items():
self._values[name] = configutils.Values(opt)
def init_save_manager(self, save_manager): def init_save_manager(self, save_manager):
"""Make sure the config gets saved properly. """Make sure the config gets saved properly.
@ -163,7 +166,7 @@ class YamlConfig(QObject):
self._handle_migrations() self._handle_migrations()
self._validate() self._validate()
def _load_settings_obj(self, settings_obj): def _load_settings_object(self, settings_obj):
"""Load the settings from the settings: key.""" """Load the settings from the settings: key."""
if not isinstance(settings_obj, dict): if not isinstance(settings_obj, dict):
desc = configexc.ConfigErrorDesc( desc = configexc.ConfigErrorDesc(
@ -172,16 +175,13 @@ class YamlConfig(QObject):
raise configexc.ConfigFileErrors('autoconfig.yml', [desc]) raise configexc.ConfigFileErrors('autoconfig.yml', [desc])
# FIXME:conf test this # FIXME:conf test this
self._values = {}
for name, yaml_values in settings_obj.items(): for name, yaml_values in settings_obj.items():
values = configutils.Values(self._config.get_opt(name)) values = configutils.Values(self._config.get_opt(name))
if 'global' in yaml_values: if 'global' in yaml_values:
scoped = configutils.ScopedValue(yaml_values.pop('global')) values.add(yaml_values.pop('global'))
values.add(scoped)
for pattern, value in yaml_values.items(): for pattern, value in yaml_values.items():
scoped = configutils.ScopedValue(value, pattern) values.add(value, pattern)
values.add(scoped)
self._values[name] = values self._values[name] = values
@ -230,16 +230,11 @@ class YamlConfig(QObject):
def set_obj(self, name, value, *, pattern=None): def set_obj(self, name, value, *, pattern=None):
"""Set the given setting to the given value.""" """Set the given setting to the given value."""
values = self._get_values(pattern) self._values[name].add(value, pattern)
values[name] = value
def unset(self, name, *, pattern=None): def unset(self, name, *, pattern=None):
"""Remove the given option name if it's configured.""" """Remove the given option name if it's configured."""
values = self._get_values(pattern) self._values[name].remove(pattern)
try:
del values[name]
except KeyError:
return
self._mark_changed() self._mark_changed()
def clear(self): def clear(self):
@ -294,7 +289,7 @@ class ConfigAPI:
def get(self, name): def get(self, name):
with self._handle_error('getting', name): with self._handle_error('getting', name):
return self._config.get_obj(name) return self._config.get_mutable_obj(name)
def set(self, name, value): def set(self, name, value):
with self._handle_error('setting', name): with self._handle_error('setting', name):

View File

@ -24,7 +24,7 @@
from PyQt5.QtGui import QFont from PyQt5.QtGui import QFont
from qutebrowser.config import config from qutebrowser.config import config, configutils
from qutebrowser.utils import log, utils, debug, usertypes from qutebrowser.utils import log, utils, debug, usertypes
from qutebrowser.misc import objects from qutebrowser.misc import objects
@ -198,15 +198,25 @@ def init_mappings(mappings):
mapping.set(value) mapping.set(value)
def update_mappings(mappings, option, url=None, settings=None): def update_mappings(mappings, option):
"""Update global settings when QWeb(Engine)Settings changed.""" """Update global settings when QWeb(Engine)Settings changed."""
try: try:
mapping = mappings[option] mapping = mappings[option]
except KeyError: except KeyError:
return return
value = config.instance.get(option, url=url) value = config.instance.get(option)
# FIXME:conf handle settings != None with global/static setters mapping.set(value)
mapping.set(value, settings=settings)
def update_for_tab(mappings, tab, url):
"""Update settings customized for the given tab."""
for opt, values in config.instance:
value = values.get_for_url(url, fallback=False)
if value is not configutils.UNSET and opt.name in mappings:
# FIXME:conf handle settings != None with global/static setters
mapping = mappings[opt.name]
# FIXME:conf have a proper API for this.
mapping.set(value, settings=tab._widget.settings())
def init(args): def init(args):