From 17c7663ad0bbc76b651e1025951048ad93359335 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 17 Sep 2018 19:22:44 +0200 Subject: [PATCH] Make content.headers.referer work on QtWebEngine --- doc/changelog.asciidoc | 1 + doc/help/settings.asciidoc | 6 +++--- qutebrowser/config/configdata.yml | 8 ++++++-- qutebrowser/config/configinit.py | 11 +++++++++++ tests/unit/config/test_configinit.py | 24 ++++++++++++++++++++++-- 5 files changed, 43 insertions(+), 7 deletions(-) diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc index 7a2e53660..f7ccc605c 100644 --- a/doc/changelog.asciidoc +++ b/doc/changelog.asciidoc @@ -42,6 +42,7 @@ Added Changed ~~~~~~~ +- The `content.headers.referer` setting now works on QtWebEngine. - The `:repeat` command now takes a count which is multiplied with the given "times" argument. - The default keybinding to leave passthrough mode was changed from `` diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index 006545c83..bfa5d3438 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -1677,6 +1677,8 @@ Default: +pass:[true]+ === content.headers.referer When to send the Referer header. The Referer header tells websites from which website you were coming from when visiting them. +No restart is needed with QtWebKit. +This setting requires a restart. Type: <> @@ -1684,12 +1686,10 @@ Valid values: * +always+: Always send the Referer. * +never+: Never send the Referer. This is not recommended, as some sites may break. - * +same-domain+: Only send the Referer for the same domain. This will still protect your privacy, but shouldn't break any sites. + * +same-domain+: Only send the Referer for the same domain. This will still protect your privacy, but shouldn't break any sites. With QtWebEngine, the referer will still be sent for other domains, but with stripped path information. Default: +pass:[same-domain]+ -This setting is only available with the QtWebKit backend. - [[content.headers.user_agent]] === content.headers.user_agent User agent to send. Unset to send the default. diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index 578f9fb90..9910d7289 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -456,14 +456,18 @@ content.headers.referer: - never: "Never send the Referer. This is not recommended, as some sites may break." - same-domain: "Only send the Referer for the same domain. This will - still protect your privacy, but shouldn't break any sites." - backend: QtWebKit + still protect your privacy, but shouldn't break any sites. With + QtWebEngine, the referer will still be sent for other domains, but + with stripped path information." + restart: true desc: >- When to send the Referer header. The Referer header tells websites from which website you were coming from when visiting them. + No restart is needed with QtWebKit. + content.headers.user_agent: default: null type: diff --git a/qutebrowser/config/configinit.py b/qutebrowser/config/configinit.py index d7ec1d5cb..56df71eb4 100644 --- a/qutebrowser/config/configinit.py +++ b/qutebrowser/config/configinit.py @@ -215,4 +215,15 @@ def qt_args(namespace): raise utils.Unreachable("Unknown low-end device mode {}" .format(low_end_device_mode)) + referrer = config.val.content.headers.referer + if referrer == 'always': + pass + elif referrer == 'never': + argv.append('--no-referrers') + elif referrer == 'same-domain': + argv.append('--reduced-referrer-granularity') + else: + raise utils.Unreachable("Unknown referrer {}" + .format(referrer)) + return argv diff --git a/tests/unit/config/test_configinit.py b/tests/unit/config/test_configinit.py index 3c7752055..8910ac42e 100644 --- a/tests/unit/config/test_configinit.py +++ b/tests/unit/config/test_configinit.py @@ -359,10 +359,11 @@ class TestQtArgs: return parser @pytest.fixture(autouse=True) - def patch_version_check(self, monkeypatch): - """Make sure no --disable-shared-workers argument gets added.""" + def reduce_args(self, monkeypatch, config_stub): + """Make sure no --disable-shared-workers/referer argument get added.""" monkeypatch.setattr(configinit.qtutils, 'version_check', lambda version, compiled=False: True) + config_stub.val.content.headers.referer = 'always' @pytest.mark.parametrize('args, expected', [ # No Qt arguments @@ -524,6 +525,25 @@ class TestQtArgs: else: assert arg in args + @pytest.mark.parametrize('referer, arg', [ + ('always', None), + ('never', '--no-referrers'), + ('same-domain', '--reduced-referrer-granularity'), + ]) + def test_referer(self, config_stub, monkeypatch, parser, referer, arg): + monkeypatch.setattr(configinit.objects, 'backend', + usertypes.Backend.QtWebEngine) + + config_stub.val.content.headers.referer = referer + parsed = parser.parse_args([]) + args = configinit.qt_args(parsed) + + if arg is None: + assert '--no-referrers' not in args + assert '--reduced-referrer-granularity' not in args + else: + assert arg in args + @pytest.mark.parametrize('arg, confval, used', [ # overridden by commandline arg