Skip to content
Browse files

Make qute://settings work with QtWebEngine and new config

Fixes #2332
  • Loading branch information
The-Compiler committed Jun 19, 2017
1 parent 6f11b27 commit 15e803c02af52d99f11db9b6233a1fdfd4312d0d
@@ -35,7 +35,7 @@
from PyQt5.QtCore import QUrlQuery, QUrl

import qutebrowser
from qutebrowser.config import config
from qutebrowser.config import config, configdata, configexc
from qutebrowser.utils import (version, utils, jinja, log, message, docutils,
objreg, usertypes, qtutils)
from qutebrowser.misc import objects
@@ -441,3 +441,37 @@ def qute_backend_warning(_url):
title="Legacy backend warning")
return 'text/html', html

def _qute_settings_set(url):
"""Handler for qute://settings/set."""
query = QUrlQuery(url)
option = query.queryItemValue('option', QUrl.FullyDecoded)
value = query.queryItemValue('value', QUrl.FullyDecoded)

if option == 'content.javascript.enabled' and value == 'false':
msg = ("Refusing to disable javascript via qute://settings "
"as it needs javascript support.")
return 'text/html', b'error: ' + msg.encode('utf-8')

config.instance.set(option, value)
return 'text/html', b'ok'
except configexc.Error as e:
return 'text/html', b'error: ' + str(e).encode('utf-8')

def qute_settings(url):
"""Handler for qute://settings. View/change qute configuration."""
# FIXME:conf add a test for this
if url.path() == '/set':
return _qute_settings_set(url)

config_getter = config.instance.get # FIXME to_str
html = jinja.render('settings.html', title='settings',
configdata=configdata, confget=config_getter)
return 'text/html', html
@@ -20,16 +20,13 @@
"""QtWebKit specific qute://* handlers and glue code."""

import mimetypes
import functools
import configparser

from PyQt5.QtCore import pyqtSlot, QObject
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtNetwork import QNetworkReply

from qutebrowser.browser import pdfjs, qutescheme
from import schemehandler, networkreply
from qutebrowser.utils import jinja, log, message, objreg, usertypes, qtutils
from qutebrowser.config import configexc, configdata, config
from qutebrowser.utils import jinja, log, message, usertypes, qtutils

class QuteSchemeHandler(schemehandler.SchemeHandler):
@@ -70,36 +67,6 @@ def createRequest(self, _op, request, _outgoing_data):

class JSBridge(QObject):

"""Javascript-bridge for special qute://... pages."""

@pyqtSlot(str, str, str)
def set(self, sectname, optname, value):
"""Slot to set a setting from qute://settings."""
if ((sectname, optname) == ('content', 'allow-javascript') and
value == 'false'):
message.error("Refusing to disable javascript via qute://settings "
"as it needs javascript support.")
# FIXME:conf
message.error("Setting doesn't work yet!")
# try:
# objreg.get('config').set('conf', sectname, optname, value)
# except (configexc.Error, configparser.Error) as e:
# message.error(str(e))

@qutescheme.add_handler('settings', backend=usertypes.Backend.QtWebKit)
def qute_settings(_url):
"""Handler for qute://settings. View/change qute configuration."""
config_getter = config.instance.get # FIXME to_str
html = jinja.render('settings.html', title='settings',
configdata=configdata, confget=config_getter)
return 'text/html', html

@qutescheme.add_handler('pdfjs', backend=usertypes.Backend.QtWebKit)
def qute_pdfjs(url):
"""Handler for qute://pdfjs. Return the pdf.js viewer."""
@@ -35,23 +35,16 @@
from qutebrowser.browser import browsertab
from import proxy
from qutebrowser.browser.webkit import webview, tabhistory, webkitelem
from import webkitqutescheme
from qutebrowser.utils import qtutils, objreg, usertypes, utils, log, debug

def init():
"""Initialize QtWebKit-specific modules."""
qapp = QApplication.instance()

if not qtutils.version_check('5.8'):
# Otherwise we initialize it globally in
log.init.debug("Initializing proxy...")

log.init.debug("Initializing js-bridge...")
js_bridge = webkitqutescheme.JSBridge(qapp)
objreg.register('js-bridge', js_bridge)

class WebKitAction(browsertab.AbstractAction):

@@ -135,22 +135,6 @@ def openurl(self, url):
url: The URL to load as QUrl
if url.scheme() == 'qute':
frame =

def add_js_bridge(self):
"""Add the javascript bridge for qute://... pages."""
frame = self.sender()
if not isinstance(frame, QWebFrame):
log.webview.error("Got non-QWebFrame {!r} in "

if frame.url().scheme() == 'qute':
bridge = objreg.get('js-bridge')
frame.addToJavaScriptWindowObject('qute', bridge)

def on_mode_entered(self, mode):
@@ -131,6 +131,9 @@ def get(self, option):
raise configexc.NoOptionError(option)
return value.typ.from_py(value.default)

def set(self, option, value):
raise configexc.Error("Setting doesn't work yet!")

class ConfigContainer:

@@ -1,9 +1,13 @@
{% extends "base.html" %}

{% block script %}
var cset = function(section, option, el) {
value = el.value;
window.qute.set(section, option, value);
var cset = function(option, value) {
// FIXME:conf we might want some error handling here?
var url = "qute://settings/set?option=" + encodeURIComponent(option);
url += "&value=" + encodeURIComponent(value);
var xhr = new XMLHttpRequest();"GET", url);
{% endblock %}

@@ -32,7 +36,7 @@
<input type="text"
onblur="cset('{{ }}', this)"
onblur="cset('{{ }}', this.value)"
value="{{ confget( }}">

0 comments on commit 15e803c

Please sign in to comment.
You can’t perform that action at this time.