From 94cf3fa4ff1f040329f177dbee30cd8204908fd9 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 4 Aug 2016 21:33:53 +0200 Subject: [PATCH] QtWebEngine: Restore Qt 5.6 compatibility --- doc/help/settings.asciidoc | 4 ++-- .../browser/webengine/webenginesettings.py | 8 ++++++-- qutebrowser/browser/webengine/webenginetab.py | 15 +++++++++++---- qutebrowser/config/configdata.py | 3 ++- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index 7bace1c88..c0b4ad878 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -149,7 +149,7 @@ |<>|Whether images are automatically loaded in web pages. |<>|Enables or disables the running of JavaScript programs. |<>|Enables or disables plugins in Web pages. -|<>|Enables or disables WebGL. +|<>|Enables or disables WebGL. For QtWebEngine, Qt/PyQt >= 5.7 is required for this setting. |<>|Enable or disable support for CSS regions. |<>|Enable or disable hyperlink auditing (). |<>|Allow websites to request geolocations. @@ -1377,7 +1377,7 @@ Default: +pass:[false]+ [[content-webgl]] === webgl -Enables or disables WebGL. +Enables or disables WebGL. For QtWebEngine, Qt/PyQt >= 5.7 is required for this setting. Valid values: diff --git a/qutebrowser/browser/webengine/webenginesettings.py b/qutebrowser/browser/webengine/webenginesettings.py index 58cd85520..2cde8fb1f 100644 --- a/qutebrowser/browser/webengine/webenginesettings.py +++ b/qutebrowser/browser/webengine/webenginesettings.py @@ -110,8 +110,6 @@ MAPPINGS = { Attribute(QWebEngineSettings.JavascriptCanAccessClipboard), 'allow-plugins': Attribute(QWebEngineSettings.PluginsEnabled), - 'webgl': - Attribute(QWebEngineSettings.WebGLEnabled), 'hyperlink-auditing': Attribute(QWebEngineSettings.HyperlinkAuditingEnabled), 'local-content-can-access-remote-urls': @@ -183,3 +181,9 @@ MAPPINGS = { setter=QWebEngineSettings.setDefaultTextEncoding), } } + +try: + MAPPINGS['content']['webgl'] = Attribute(QWebEngineSettings.WebGLEnabled) +except AttributeError: + # Added in Qt 5.7 + pass diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index 457473e32..ec98e3baa 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -348,10 +348,17 @@ class WebEngineTab(browsertab.AbstractTab): def run_js_async(self, code, callback=None): world = QWebEngineScript.ApplicationWorld - if callback is None: - self._widget.page().runJavaScript(code, world) - else: - self._widget.page().runJavaScript(code, world, callback) + try: + if callback is None: + self._widget.page().runJavaScript(code, world) + else: + self._widget.page().runJavaScript(code, world, callback) + except TypeError: + # Qt < 5.7 + if callback is None: + self._widget.page().runJavaScript(code) + else: + self._widget.page().runJavaScript(code, callback) def run_js_blocking(self, code): unset = object() diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 9eb932f21..8cbfe3938 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -775,7 +775,8 @@ def data(readonly=False): ('webgl', SettingValue(typ.Bool(), 'false'), - "Enables or disables WebGL."), + "Enables or disables WebGL. For QtWebEngine, Qt/PyQt >= 5.7 is " + "required for this setting."), ('css-regions', SettingValue(typ.Bool(), 'true',