From 1c6fd6f7250063c5e2d1668afb661ab26430aa57 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 30 May 2017 08:42:37 +0200 Subject: [PATCH] Add a backend warning when using QtWebKit --- qutebrowser/app.py | 39 ++++++++---- qutebrowser/browser/qutescheme.py | 11 ++++ qutebrowser/html/backend-warning.html | 90 +++++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 11 deletions(-) create mode 100644 qutebrowser/html/backend-warning.html diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 225985e66..19a278ceb 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -53,7 +53,7 @@ from qutebrowser.browser.webkit.network import networkmanager from qutebrowser.keyinput import macros from qutebrowser.mainwindow import mainwindow, prompt from qutebrowser.misc import (readline, ipc, savemanager, sessions, - crashsignal, earlyinit) + crashsignal, earlyinit, objects) from qutebrowser.misc import utilcmds # pylint: disable=unused-import from qutebrowser.utils import (log, version, message, utils, qtutils, urlutils, objreg, usertypes, standarddir, error, debug) @@ -202,7 +202,7 @@ def _process_args(args): process_pos_args(args.command) _open_startpage() - _open_quickstart(args) + _open_special_pages(args) delta = datetime.datetime.now() - earlyinit.START_TIME log.init.debug("Init finished after {}s".format(delta.total_seconds())) @@ -319,23 +319,40 @@ def _open_startpage(win_id=None): tabbed_browser.tabopen(url) -def _open_quickstart(args): - """Open quickstart if it's the first start. +def _open_special_pages(args): + """Open special notification pages which are only shown once. + + Currently this is: + - Quickstart page if it's the first start. + - Legacy QtWebKit warning if needed. Args: args: The argparse namespace. """ if args.basedir is not None: - # With --basedir given, don't open quickstart. + # With --basedir given, don't open anything. return + state_config = objreg.get('state-config') - try: - quickstart_done = state_config['general']['quickstart-done'] == '1' - except KeyError: - quickstart_done = False + tabbed_browser = objreg.get('tabbed-browser', scope='window', + window='last-focused') + + # Legacy QtWebKit warning + + needs_warning = (objects.backend == usertypes.Backend.QtWebKit and + not qtutils.is_qtwebkit_ng()) + warning_shown = state_config['general'].get('backend-warning-shown') == '1' + + if not warning_shown and needs_warning: + tabbed_browser.tabopen(QUrl('qute://backend-warning'), + background=False) + state_config['general']['backend-warning-shown'] = '1' + + # Quickstart page + + quickstart_done = state_config['general'].get('quickstart-done') == '1' + if not quickstart_done: - tabbed_browser = objreg.get('tabbed-browser', scope='window', - window='last-focused') tabbed_browser.tabopen( QUrl('https://www.qutebrowser.org/quickstart.html')) state_config['general']['quickstart-done'] = '1' diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py index 919e6e186..1da0932d5 100644 --- a/qutebrowser/browser/qutescheme.py +++ b/qutebrowser/browser/qutescheme.py @@ -30,6 +30,7 @@ import sys import time import urllib.parse import datetime +import pkg_resources from PyQt5.QtCore import QUrlQuery, QUrl @@ -431,3 +432,13 @@ def qute_help(url): else: data = utils.read_file(path) return 'text/html', data + + +@add_handler('backend-warning') +def qute_backend_warning(url): + """Handler for qute://backend-warning.""" + html = jinja.render('backend-warning.html', + distribution=version.distribution(), + Distribution=version.Distribution, + version=pkg_resources.parse_version) + return 'text/html', html diff --git a/qutebrowser/html/backend-warning.html b/qutebrowser/html/backend-warning.html new file mode 100644 index 000000000..b6db4f001 --- /dev/null +++ b/qutebrowser/html/backend-warning.html @@ -0,0 +1,90 @@ +{% extends "styled.html" %} + +{% block style %} +{{super()}} +.note { + font-size: smaller; + color: grey; +} + +.mono { + font-family: monospace; +} +{% endblock %} + +{% block content %} +

Legacy QtWebKit backend

+ +Note this warning will only appear once. Use :open +qute://backend-warning to show it again at a later time. + +

+ You're using qutebrowser with the legacy QtWebKit backend. It's still the + default until a few remaining issues are sorted out. If you can, it's + strongly suggested to switch earlier, as legacy QtWebKit has known security + issues and also breaks things on various websites. +

+ +

Using QtWebEngine instead

+ +This is usually the better choice if you aren't using Nouveau graphics, and +don't need any features which are currently unavailable with QtWebEngine (like +the qute://settings page or caret browsing). + +{% macro install_webengine(package) -%} + You should be able to install {{ package }} and start qutebrowser with --backend webengine to use the new backend. +{%- endmacro %} + +{% macro please_open_issue() -%} + If you know more, please open an issue! +{%- endmacro %} + +

+{% if distribution.parsed == Distribution.ubuntu %} + {% if distribution.version >= version('17.04') %} + {{ install_webengine('python3-pyqt5.qtwebengine') }} + {% elif distribution.version >= version('16.04') %} + QtWebEngine is only available in Ubuntu's repositories since 17.04, but you can install qutebrowser via tox with tox -e mkvenv-pypi to use the new backend. + {% else %} + Unfortunately, no easy way is known to install QtWebEngine on Ubuntu < 16.04. {{ please_open_issue() }} + {% endif %} +{% elif distribution.parsed == Distribution.debian %} + {% if distribution.version >= version('9') %} + {{ install_webengine('python3-pyqt5.qtwebengine') }} + {% else %} + Unfortunately, no easy way is known to install QtWebEngine on Debian < 9. {{ please_open_issue() }} + {% endif %} +{% elif distribution.parsed in [Distribution.arch, Distribution.manjaro] %} + {{ install_webengine('qt5-webengine') }} +{% elif distribution.parsed == Distribution.void %} + {{ install_webengine('python-PyQt5-webengine') }} +{% elif distribution.parsed == Distribution.fedora %} + {{ install_webengine('qt5-qtwebengine') }} +{% elif distribution.parsed == Distribution.opensuse %} + {{ install_webengine('libqt5-qtwebengine') }} +{% else %} + There's no information available for your system. {{ please_open_issue() }} +{% endif %} +

+ +

Using QtWebKit-NG instead

+ +This is a drop-in replacement for legacy QtWebKit. Note private browsing won't work with it properly until its next release. + +

+{% if distribution.parsed == Distribution.debian and distribution.version >= version('9') %} + There are unofficial QtWebKit-NG packages available. +{% elif distribution.parsed in [Distribution.ubuntu, Distribution.debian] %} + No easy way is known to install QtWebKit-NG on your system. + There are unofficial QtWebKit-NG packages available, but they are intended for Debian Unstable. + {{ please_open_issue() }} +{% elif distribution.parsed in [Distribution.arch, Distribution.manjaro] %} + You should be able to install qt5-webkit-ng via pacman. +{% elif distribution.parsed == Distribution.gentoo %} + There's an unofficial ebuild available. +{% else %} + There's no information available for your system. {{ please_open_issue() }} +{% endif %} +

+ +{% endblock %}