Implement Qt 5.11 devtools support

See #3010
This commit is contained in:
Florian Bruhin 2018-06-11 08:52:31 +02:00
parent 20763a87c0
commit 1ba2e3e24b
8 changed files with 28 additions and 8 deletions

View File

@ -51,6 +51,8 @@ Changed
one), which allows scripts like OneeChan to work. one), which allows scripts like OneeChan to work.
- Rapid hinting is now supported with the `yank` and `yank-primary` targets, - Rapid hinting is now supported with the `yank` and `yank-primary` targets,
copying newline-separated links. copying newline-separated links.
- QtWebEngine: On Qt 5.11, the developer tools (inspector) can now be used
securely and without requiring the `--enable-webengine-inspector` option.
Removed Removed
~~~~~~~ ~~~~~~~

View File

@ -60,7 +60,7 @@ show it.
Which backend to use. Which backend to use.
*--enable-webengine-inspector*:: *--enable-webengine-inspector*::
Enable the web inspector for QtWebEngine. Note that this is a SECURITY RISK and you should not visit untrusted websites with the inspector turned on. See https://bugreports.qt.io/browse/QTBUG-50725 for more details. Enable the web inspector for QtWebEngine. Note that this is a SECURITY RISK and you should not visit untrusted websites with the inspector turned on. See https://bugreports.qt.io/browse/QTBUG-50725 for more details. This is not needed anymore since Qt 5.11 where the inspector is always enabled and secure.
=== debug arguments === debug arguments
*-l* '{critical,error,warning,info,debug,vdebug}', *--loglevel* '{critical,error,warning,info,debug,vdebug}':: *-l* '{critical,error,warning,info,debug,vdebug}', *--loglevel* '{critical,error,warning,info,debug,vdebug}'::

View File

@ -39,8 +39,8 @@ class WebEngineInspector(inspector.AbstractWebInspector):
settings.setAttribute(QWebEngineSettings.JavascriptEnabled, True) settings.setAttribute(QWebEngineSettings.JavascriptEnabled, True)
self._set_widget(view) self._set_widget(view)
def inspect(self, _page): def _inspect_old(self):
"""Set up the inspector.""" """Set up the inspector for Qt < 5.11."""
try: try:
port = int(os.environ['QTWEBENGINE_REMOTE_DEBUGGING']) port = int(os.environ['QTWEBENGINE_REMOTE_DEBUGGING'])
except KeyError: except KeyError:
@ -49,4 +49,14 @@ class WebEngineInspector(inspector.AbstractWebInspector):
"'qutebrowser --help' for details.") "'qutebrowser --help' for details.")
url = QUrl('http://localhost:{}/'.format(port)) url = QUrl('http://localhost:{}/'.format(port))
self._widget.load(url) self._widget.load(url)
def _inspect_new(self, page):
"""Set up the inspector for Qt >= 5.11."""
self._widget.page().setInspectedPage(page)
def inspect(self, page):
try:
self._inspect_new(page)
except AttributeError:
self._inspect_old()
self.show() self.show()

View File

@ -27,7 +27,8 @@ Module attributes:
import os import os
from PyQt5.QtGui import QFont from PyQt5.QtGui import QFont
from PyQt5.QtWebEngineWidgets import QWebEngineSettings, QWebEngineProfile from PyQt5.QtWebEngineWidgets import (QWebEngineSettings, QWebEngineProfile,
QWebEnginePage)
from qutebrowser.browser.webengine import spell from qutebrowser.browser.webengine import spell
from qutebrowser.config import config, websettings from qutebrowser.config import config, websettings
@ -274,7 +275,8 @@ def _init_profiles():
def init(args): def init(args):
"""Initialize the global QWebSettings.""" """Initialize the global QWebSettings."""
if args.enable_webengine_inspector: if (args.enable_webengine_inspector and
not hasattr(QWebEnginePage, 'setInspectedPage')): # only Qt < 5.11
os.environ['QTWEBENGINE_REMOTE_DEBUGGING'] = str(utils.random_port()) os.environ['QTWEBENGINE_REMOTE_DEBUGGING'] = str(utils.random_port())
_init_profiles() _init_profiles()

View File

@ -86,7 +86,9 @@ def get_argparser():
"that this is a SECURITY RISK and you should not " "that this is a SECURITY RISK and you should not "
"visit untrusted websites with the inspector turned " "visit untrusted websites with the inspector turned "
"on. See https://bugreports.qt.io/browse/QTBUG-50725 " "on. See https://bugreports.qt.io/browse/QTBUG-50725 "
"for more details.") "for more details. This is not needed anymore since "
"Qt 5.11 where the inspector is always enabled and "
"secure.")
parser.add_argument('--json-args', help=argparse.SUPPRESS) parser.add_argument('--json-args', help=argparse.SUPPRESS)
parser.add_argument('--temp-basedir-restarted', help=argparse.SUPPRESS) parser.add_argument('--temp-basedir-restarted', help=argparse.SUPPRESS)

View File

@ -163,7 +163,7 @@ Feature: Various utility commands.
And I run :inspector And I run :inspector
Then the error "Please enable content.developer_extras before using the webinspector!" should be shown Then the error "Please enable content.developer_extras before using the webinspector!" should be shown
@qtwebkit_skip @qtwebkit_skip @qt<5.11
Scenario: Inspector without --enable-webengine-inspector Scenario: Inspector without --enable-webengine-inspector
When I run :inspector When I run :inspector
Then the error "QtWebEngine inspector is not enabled. See 'qutebrowser --help' for details." should be shown Then the error "QtWebEngine inspector is not enabled. See 'qutebrowser --help' for details." should be shown

View File

@ -26,9 +26,10 @@ import logging
import re import re
import pytest import pytest
from PyQt5.QtCore import QProcess, qVersion from PyQt5.QtCore import QProcess, qVersion
from tests import utils
ascii_locale = pytest.mark.skipif(sys.hexversion >= 0x03070000, ascii_locale = pytest.mark.skipif(sys.hexversion >= 0x03070000,
reason="Python >= 3.7 doesn't force ASCII " reason="Python >= 3.7 doesn't force ASCII "
@ -257,6 +258,7 @@ def test_qt_arg(request, quteproc_new, tmpdir):
quteproc_new.wait_for_quit() quteproc_new.wait_for_quit()
@utils.skip_qt511
def test_webengine_inspector(request, quteproc_new): def test_webengine_inspector(request, quteproc_new):
if not request.config.webengine: if not request.config.webengine:
pytest.skip() pytest.skip()

View File

@ -36,6 +36,8 @@ qt58 = pytest.mark.skipif(
qtutils.version_check('5.9'), reason="Needs Qt 5.8 or earlier") qtutils.version_check('5.9'), reason="Needs Qt 5.8 or earlier")
qt59 = pytest.mark.skipif( qt59 = pytest.mark.skipif(
not qtutils.version_check('5.9'), reason="Needs Qt 5.9 or newer") not qtutils.version_check('5.9'), reason="Needs Qt 5.9 or newer")
skip_qt511 = pytest.mark.skipif(
qtutils.version_check('5.11'), reason="Needs Qt 5.10 or earlier")
class PartialCompareOutcome: class PartialCompareOutcome: