Fix problem with qutesettings scope in pages
Fix to make sure the js bridge code is only enabled when qute: pages are shown. Previously it would only be available to the first page (and before that it was available to all pages).
This commit is contained in:
parent
4fd4376c6a
commit
9cfb4b3431
@ -154,6 +154,9 @@ class Application(QApplication):
|
||||
config.init(self._args)
|
||||
log.init.debug("Initializing crashlog...")
|
||||
self._handle_segfault()
|
||||
log.init.debug("Initializing js-bridge...")
|
||||
js_bridge = qutescheme.JSBridge(self)
|
||||
objreg.register('js-bridge', js_bridge)
|
||||
log.init.debug("Initializing websettings...")
|
||||
websettings.init()
|
||||
log.init.debug("Initializing adblock...")
|
||||
|
@ -520,13 +520,6 @@ class ConfigManager(QObject):
|
||||
if self._initialized:
|
||||
self._after_set(sectname, optname)
|
||||
|
||||
@pyqtSlot(int, str, str, str)
|
||||
def set_javascript(self, win_id, sectname, optname, value):
|
||||
try:
|
||||
self.set('conf', sectname, optname, value)
|
||||
except configtypes.ValidationError as e:
|
||||
message.error(win_id, e)
|
||||
|
||||
@cmdutils.register(instance='config')
|
||||
def save(self):
|
||||
"""Save the config file."""
|
||||
|
@ -4,7 +4,7 @@
|
||||
var win_id = {{ win_id }};
|
||||
var cset = function(section, option, el) {
|
||||
value = el.value;
|
||||
window.qutesettings.set_javascript(win_id, section, option, value);
|
||||
window.qute.set(win_id, section, option, value);
|
||||
}
|
||||
{% endblock %}
|
||||
|
||||
@ -17,6 +17,7 @@ th pre { color: grey; text-align: left; }
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<noscript><h1>View Only</h1><p>Changing settings requires javascript to be enabled</p></noscript>
|
||||
<header><h1>{{ title }}</h1></header>
|
||||
<table>
|
||||
{% for section in config.DATA %}
|
||||
@ -35,4 +36,4 @@ th pre { color: grey; text-align: left; }
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
@ -27,12 +27,14 @@ Module attributes:
|
||||
pyeval_output: The output of the last :pyeval command.
|
||||
"""
|
||||
|
||||
from PyQt5.QtCore import pyqtSlot, QObject
|
||||
from PyQt5.QtNetwork import QNetworkReply
|
||||
|
||||
import qutebrowser
|
||||
from qutebrowser.network import schemehandler, networkreply
|
||||
from qutebrowser.utils import (version, utils, jinja, log, message, docutils,
|
||||
objreg)
|
||||
from qutebrowser.config import configtypes
|
||||
|
||||
|
||||
pyeval_output = ":pyeval was never called"
|
||||
@ -79,6 +81,22 @@ class QuteSchemeHandler(schemehandler.SchemeHandler):
|
||||
request, data, 'text/html', self.parent())
|
||||
|
||||
|
||||
class JSBridge(QObject):
|
||||
|
||||
"""Javascript-bridge for special qute:... pages."""
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
@pyqtSlot(int, str, str, str)
|
||||
def set(self, win_id, sectname, optname, value):
|
||||
"""Slot to set a setting from qute:settings."""
|
||||
try:
|
||||
objreg.get('config').set('conf', sectname, optname, value)
|
||||
except configtypes.ValidationError as e:
|
||||
message.error(win_id, e)
|
||||
|
||||
|
||||
def qute_pyeval(_win_id, _request):
|
||||
"""Handler for qute:pyeval. Return HTML content as bytes."""
|
||||
html = jinja.env.get_template('pre.html').render(
|
||||
@ -151,12 +169,8 @@ def qute_settings(win_id, request):
|
||||
"""Handler for qute:settings. View/change qute configuration"""
|
||||
from qutebrowser.config import configdata
|
||||
|
||||
cfg = objreg.get('config')
|
||||
frame = objreg.get('webview', scope='tab').page().mainFrame()
|
||||
frame.addToJavaScriptWindowObject("qutesettings", cfg)
|
||||
|
||||
html = jinja.env.get_template('settings.html').render(
|
||||
win_id=win_id, title='settings', config=configdata, cfg=cfg)
|
||||
win_id=win_id, title='settings', config=configdata)
|
||||
return html.encode('UTF-8', errors='xmlcharrefreplace')
|
||||
|
||||
|
||||
|
@ -289,9 +289,6 @@ class WebView(QWebView):
|
||||
|
||||
Args:
|
||||
url: The URL to load as QUrl
|
||||
|
||||
Return:
|
||||
Return status of self.load
|
||||
"""
|
||||
qtutils.ensure_valid(url)
|
||||
urlstr = url.toDisplayString()
|
||||
@ -299,7 +296,20 @@ class WebView(QWebView):
|
||||
self.titleChanged.emit(urlstr)
|
||||
self.cur_url = url
|
||||
self.url_text_changed.emit(url.toDisplayString())
|
||||
return self.load(url)
|
||||
self.load(url)
|
||||
if url.scheme() == 'qute':
|
||||
frame = self.page().mainFrame()
|
||||
frame.javaScriptWindowObjectCleared.connect(self.add_js_bridge)
|
||||
|
||||
def add_js_bridge(self):
|
||||
"""Add the javascript bridge for qute:... pages."""
|
||||
frame = self.sender()
|
||||
assert frame.url().scheme() == 'qute'
|
||||
bridge = objreg.get('js-bridge')
|
||||
frame.addToJavaScriptWindowObject('qute', bridge)
|
||||
# We need to make sure the bridge doesn't get added on non-qute:...
|
||||
# pages.
|
||||
frame.javaScriptWindowObjectCleared.disconnect(self.add_js_bridge)
|
||||
|
||||
def zoom_perc(self, perc, fuzzyval=True):
|
||||
"""Zoom to a given zoom percentage.
|
||||
|
Loading…
Reference in New Issue
Block a user