old qt: Remove old inspector logic

This commit is contained in:
Florian Bruhin 2020-11-03 12:13:04 +01:00
parent c4a72120d2
commit c95b9637e1
14 changed files with 20 additions and 111 deletions

View File

@ -62,9 +62,6 @@ show it.
*--backend* '{webkit,webengine}'::
Which backend to use.
*--enable-webengine-inspector*::
Enable the web inspector / devtools 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
*-l* '{critical,error,warning,info,debug,vdebug}', *--loglevel* '{critical,error,warning,info,debug,vdebug}'::
Override the configured console loglevel

View File

@ -49,12 +49,7 @@ def create(*, splitter: 'miscwidgets.InspectorSplitter',
# argument and to avoid circular imports.
if objects.backend == usertypes.Backend.QtWebEngine:
from qutebrowser.browser.webengine import webengineinspector
if webengineinspector.supports_new():
return webengineinspector.WebEngineInspector(
splitter, win_id, parent)
else:
return webengineinspector.LegacyWebEngineInspector(
splitter, win_id, parent)
return webengineinspector.WebEngineInspector(splitter, win_id, parent)
elif objects.backend == usertypes.Backend.QtWebKit:
from qutebrowser.browser.webkit import webkitinspector
return webkitinspector.WebKitInspector(splitter, win_id, parent)

View File

@ -52,47 +52,9 @@ class WebEngineInspectorView(QWebEngineView):
return self.page().inspectedPage().view().createWindow(wintype)
def supports_new() -> bool:
"""Check whether a new-style inspector is supported."""
return hasattr(QWebEnginePage, 'setInspectedPage')
class LegacyWebEngineInspector(inspector.AbstractWebInspector):
"""A web inspector for QtWebEngine without Qt API support.
Only needed with Qt <= 5.10.
"""
def __init__(self, splitter: miscwidgets.InspectorSplitter,
win_id: int,
parent: QWidget = None) -> None:
super().__init__(splitter, win_id, parent)
self._ensure_enabled()
view = WebEngineInspectorView()
self._settings = webenginesettings.WebEngineSettings(view.settings())
self._set_widget(view)
def _ensure_enabled(self) -> None:
if 'QTWEBENGINE_REMOTE_DEBUGGING' not in os.environ:
raise inspector.Error(
"QtWebEngine inspector is not enabled. See "
"'qutebrowser --help' for details.")
def inspect(self, page: QWebEnginePage) -> None: # type: ignore[override]
# We're lying about the URL here a bit, but this way, URL patterns for
# Qt 5.11/5.12/5.13 also work in this case.
self._settings.update_for_url(QUrl('chrome-devtools://devtools'))
port = int(os.environ['QTWEBENGINE_REMOTE_DEBUGGING'])
self._widget.load(QUrl('http://localhost:{}/'.format(port)))
class WebEngineInspector(inspector.AbstractWebInspector):
"""A web inspector for QtWebEngine with Qt API support.
Available since Qt 5.11.
"""
"""A web inspector for QtWebEngine with Qt API support."""
def __init__(self, splitter: miscwidgets.InspectorSplitter,
win_id: int,
@ -130,4 +92,4 @@ class WebEngineInspector(inspector.AbstractWebInspector):
WORKAROUND for what's likely an unknown Qt bug.
"""
return qtutils.version_check('5.12')
return True

View File

@ -462,12 +462,8 @@ def _init_devtools_settings():
hide_userconfig=True)
def init(args):
def init():
"""Initialize the global QWebSettings."""
if (args.enable_webengine_inspector and
not hasattr(QWebEnginePage, 'setInspectedPage')): # only Qt < 5.11
os.environ['QTWEBENGINE_REMOTE_DEBUGGING'] = str(utils.random_port())
webenginequtescheme.init()
spell.init()

View File

@ -172,7 +172,7 @@ def _init_user_agent():
parsed_user_agent = websettings.UserAgent.parse(ua)
def init(_args):
def init():
"""Initialize the global QWebSettings."""
cache_path = standarddir.cache()
data_path = standarddir.data()

View File

@ -267,10 +267,10 @@ def init(args: argparse.Namespace) -> None:
"""Initialize all QWeb(Engine)Settings."""
if objects.backend == usertypes.Backend.QtWebEngine:
from qutebrowser.browser.webengine import webenginesettings
webenginesettings.init(args)
webenginesettings.init()
elif objects.backend == usertypes.Backend.QtWebKit:
from qutebrowser.browser.webkit import webkitsettings
webkitsettings.init(args)
webkitsettings.init()
else:
raise utils.Unreachable(objects.backend)

View File

@ -82,14 +82,6 @@ def get_argparser():
"qutebrowser instance running.")
parser.add_argument('--backend', choices=['webkit', 'webengine'],
help="Which backend to use.")
parser.add_argument('--enable-webengine-inspector', action='store_true',
help="Enable the web inspector / devtools 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.")
parser.add_argument('--json-args', help=argparse.SUPPRESS)
parser.add_argument('--temp-basedir-restarted', help=argparse.SUPPRESS)

View File

@ -634,15 +634,6 @@ def supports_selection() -> bool:
return QApplication.clipboard().supportsSelection()
def random_port() -> int:
"""Get a random free port."""
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('localhost', 0))
port = sock.getsockname()[1]
sock.close()
return port
def open_file(filename: str, cmdline: str = None) -> None:
"""Open the given file.

View File

@ -171,11 +171,6 @@ Feature: Various utility commands.
# :inspect
@qtwebkit_skip @qt<5.11
Scenario: Inspector without --enable-webengine-inspector
When I run :devtools
Then the error "QtWebEngine inspector is not enabled. See 'qutebrowser --help' for details." should be shown
@no_xvfb @posix @qtwebengine_skip
Scenario: Inspector smoke test
When I run :inspector

View File

@ -23,6 +23,7 @@ import re
import sys
import json
import os.path
import socket
from http import HTTPStatus
import attr
@ -31,8 +32,6 @@ from PyQt5.QtCore import pyqtSignal, QUrl
from end2end.fixtures import testprocess
from qutebrowser.utils import utils
class Request(testprocess.Line):
@ -140,9 +139,17 @@ class WebserverProcess(testprocess.Process):
def __init__(self, request, script, parent=None):
super().__init__(request, parent)
self._script = script
self.port = utils.random_port()
self.port = self._random_port()
self.new_data.connect(self.new_request)
def _random_port(self) -> int:
"""Get a random free port."""
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('localhost', 0))
port = sock.getsockname()[1]
sock.close()
return port
def get_requests(self):
"""Get the requests to the server during this test."""
requests = self._get_data()

View File

@ -275,23 +275,6 @@ def test_qt_arg(request, quteproc_new, tmpdir):
quteproc_new.wait_for_quit()
@utils.skip_qt511
def test_webengine_inspector(request, quteproc_new):
if not request.config.webengine:
pytest.skip()
args = (['--temp-basedir', '--enable-webengine-inspector'] +
_base_args(request.config))
quteproc_new.start(args)
line = quteproc_new.wait_for(
message='Remote debugging server started successfully. Try pointing a '
'Chromium-based browser to http://127.0.0.1:*')
port = int(line.message.split(':')[-1])
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', port))
s.close()
@pytest.mark.linux
def test_webengine_download_suffix(request, quteproc_new, tmpdir):
"""Make sure QtWebEngine does not add a suffix to downloads."""

View File

@ -17,7 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
import types
import logging
import pytest
@ -34,8 +33,7 @@ def init(qapp, config_stub, cache_tmpdir, data_tmpdir, monkeypatch):
monkeypatch.setattr(webenginesettings.webenginequtescheme, 'init',
lambda: None)
monkeypatch.setattr(objects, 'backend', usertypes.Backend.QtWebEngine)
init_args = types.SimpleNamespace(enable_webengine_inspector=False)
webenginesettings.init(init_args)
webenginesettings.init()
config_stub.changed.disconnect(webenginesettings._update_settings)

View File

@ -95,10 +95,10 @@ def test_user_agent(monkeypatch, config_stub, qapp):
def test_config_init(request, monkeypatch, config_stub):
if request.config.webengine:
from qutebrowser.browser.webengine import webenginesettings
monkeypatch.setattr(webenginesettings, 'init', lambda _args: None)
monkeypatch.setattr(webenginesettings, 'init', lambda: None)
else:
from qutebrowser.browser.webkit import webkitsettings
monkeypatch.setattr(webkitsettings, 'init', lambda _args: None)
monkeypatch.setattr(webkitsettings, 'init', lambda: None)
websettings.init(args=None)
assert config_stub.dump_userconfig() == '<Default configuration>'

View File

@ -750,13 +750,6 @@ class TestGetSetClipboard:
utils.get_clipboard(fallback=True)
def test_random_port():
port = utils.random_port()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('localhost', port))
sock.close()
class TestOpenFile:
@pytest.mark.not_frozen