From 574d7c6a11030386ec3afec6ebd99e062a51fc47 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 17 Sep 2018 16:27:48 +0200 Subject: [PATCH] Add settings for process models See #4039, #2377 Fixes #4040 --- doc/changelog.asciidoc | 2 ++ doc/help/settings.asciidoc | 23 +++++++++++++++++++++++ qutebrowser/browser/commands.py | 5 +++++ qutebrowser/config/configdata.yml | 28 ++++++++++++++++++++++++++++ qutebrowser/config/configinit.py | 13 ++++++++++++- tests/unit/config/test_configinit.py | 22 ++++++++++++++++++++++ 6 files changed, 92 insertions(+), 1 deletion(-) diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc index 2e346b00d..926d40433 100644 --- a/doc/changelog.asciidoc +++ b/doc/changelog.asciidoc @@ -32,6 +32,8 @@ Added QtWebEngine. * Opening a PDF file now doesn't start a second request anymore. * Opening PDFs on https:// sites now works properly. +- New `qt.process_model` setting which can be used to change Chromium's process + model. Changed ~~~~~~~ diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index 333473dc7..45262dd09 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -229,6 +229,7 @@ |<>|Force a Qt platform to use. |<>|Force software rendering for QtWebEngine. |<>|Turn on Qt HighDPI scaling. +|<>|Which Chromium process model to use. |<>|Show a scrollbar. |<>|Enable smooth scrolling for web pages. |<>|When to find text on a page case-insensitively. @@ -2757,6 +2758,28 @@ Type: <> Default: +pass:[false]+ +[[qt.process_model]] +=== qt.process_model +Which Chromium process model to use. +Alternative process models use less resources, but decrease security and robustness. +See the following pages for more details: + + - https://www.chromium.org/developers/design-documents/process-models + - https://doc.qt.io/qt-5/qtwebengine-features.html#process-models +This setting requires a restart. + +Type: <> + +Valid values: + + * +process-per-site-instance+: Pages from separate sites are put into separate processes and separate visits to the same site are also isolated. + * +process-per-site+: Pages from separate sites are put into separate processes. Unlike Process per Site Instance, all visits to the same site will share an OS process. The benefit of this model is reduced memory consumption, because more web pages will share processes. The drawbacks include reduced security, robustness, and responsiveness. + * +single-process+: Run all tabs in a single process. This should be used for debugging purposes only, and it disables `:open --private`. + +Default: +pass:[process-per-site-instance]+ + +This setting is only available with the QtWebEngine backend. + [[scrolling.bar]] === scrolling.bar Show a scrollbar. diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 8dbb661e5..a66a8fdea 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -66,6 +66,11 @@ class CommandDispatcher: def _new_tabbed_browser(self, private): """Get a tabbed-browser from a new window.""" + args = QApplication.instance().arguments() + if private and '--single-process' in args: + raise cmdexc.CommandError("Private windows are unavailable with " + "the single-process process model.") + new_window = mainwindow.MainWindow(private=private) new_window.show() return new_window.tabbed_browser diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index b7648a4be..81be51cee 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -181,6 +181,34 @@ qt.force_platform: This sets the `QT_QPA_PLATFORM` environment variable and is useful to force using the XCB plugin when running QtWebEngine on Wayland. +qt.process_model: + type: + name: String + valid_values: + - process-per-site-instance: Pages from separate sites are put into + separate processes and separate visits to the same site are also + isolated. + - process-per-site: Pages from separate sites are put into separate + processes. Unlike Process per Site Instance, all visits to the same + site will share an OS process. The benefit of this model is reduced + memory consumption, because more web pages will share processes. + The drawbacks include reduced security, robustness, and + responsiveness. + - single-process: Run all tabs in a single process. This should be used + for debugging purposes only, and it disables `:open --private`. + default: process-per-site-instance + backend: QtWebEngine + restart: true + desc: >- + Which Chromium process model to use. + + Alternative process models use less resources, but decrease security and + robustness. + + See the following pages for more details: + + - https://www.chromium.org/developers/design-documents/process-models + - https://doc.qt.io/qt-5/qtwebengine-features.html#process-models qt.highdpi: type: Bool diff --git a/qutebrowser/config/configinit.py b/qutebrowser/config/configinit.py index b8c50500f..bd912e325 100644 --- a/qutebrowser/config/configinit.py +++ b/qutebrowser/config/configinit.py @@ -27,7 +27,7 @@ from PyQt5.QtWidgets import QMessageBox from qutebrowser.config import (config, configdata, configfiles, configtypes, configexc, configcommands) from qutebrowser.utils import (objreg, usertypes, log, standarddir, message, - qtutils) + qtutils, utils) from qutebrowser.config import configcache from qutebrowser.misc import msgbox, objects @@ -191,4 +191,15 @@ def qt_args(namespace): argv.append('--force-webrtc-ip-handling-policy=' 'default_public_interface_only') + process_model = config.val.qt.process_model + if process_model == 'process-per-site-instance': + pass + elif process_model == 'process-per-site': + argv.append('--process-per-site') + elif process_model == 'single-process': + argv.append('--single-process') + else: + raise utils.Unreachable("Unknown process model {}" + .format(process_model)) + return argv diff --git a/tests/unit/config/test_configinit.py b/tests/unit/config/test_configinit.py index 56f2a3c90..7c4f7b59e 100644 --- a/tests/unit/config/test_configinit.py +++ b/tests/unit/config/test_configinit.py @@ -470,6 +470,28 @@ class TestQtArgs: args = configinit.qt_args(parsed) assert ('--disable-reading-from-canvas' in args) == added + @pytest.mark.parametrize('process_model, added', [ + ('process-per-site-instance', False), + ('process-per-site', True), + ('single-process', True), + ]) + def test_process_model(self, config_stub, monkeypatch, parser, + process_model, added): + monkeypatch.setattr(configinit.objects, 'backend', + usertypes.Backend.QtWebEngine) + + config_stub.val.qt.process_model = process_model + parsed = parser.parse_args([]) + args = configinit.qt_args(parsed) + + if added: + assert '--' + process_model in args + else: + assert '--process-per-site' not in args + assert '--single-process' not in args + assert '--process-per-site-instance' not in args + assert '--process-per-tab' not in args + @pytest.mark.parametrize('arg, confval, used', [ # overridden by commandline arg