Disable QtWebEngine's permissions persistence feature

QtWebEngine has a new feature where it will remember what permissions
you have granted or denied. It has three options regarding permissions
storage:

    AskEveryTime -- don't store
    StoreInMemory -- store in memory only
    StoreOnDisk -- store in memory and on disk

By default it does the StoreOnDisk behavior. Having webengine remember
whether you granted or denied a permission would make the qutebrowser UX
around that area inconsistent. For example the default y/n actions for a
permission prompt in qutebrowser will only accept that single
permission request, and you'll be re-prompted if you reload the page.
Users may be used to this and if webengine started remembering
permission grants the users may be surprised to find that the page was
accessing features without prompting them for permission anymore.
Additionally we already have our own permission storage machinery in
autoconfig.yml.

This commit will set the webengine feature to AskEveryTime, which disables
any storing of permission grants.

Also adjusts the skip marker of the affected tests so they'll be enabled
again on Qt versions with the appropriate permissions API.
This commit is contained in:
toofar 2024-10-13 20:55:28 +13:00
parent 0ab1e3b757
commit 8064e3ea6f
4 changed files with 16 additions and 7 deletions

View File

@ -41,7 +41,7 @@ markers =
qt6_only: Tests which should only run with Qt 6
qt5_xfail: Tests which fail with Qt 5
qt6_xfail: Tests which fail with Qt 6
qt68_beta4_skip: Fails on Qt 6.8 beta 4
qt68_no_permission_api: Fails on Qt 6.8 with PyQt<6.8
qt_log_level_fail = WARNING
qt_log_ignore =
# GitHub Actions

View File

@ -26,7 +26,7 @@ from qutebrowser.config import config, websettings
from qutebrowser.config.websettings import AttributeInfo as Attr
from qutebrowser.misc import pakjoy
from qutebrowser.utils import (standarddir, qtutils, message, log,
urlmatch, usertypes, objreg, version)
urlmatch, usertypes, objreg, version, utils)
if TYPE_CHECKING:
from qutebrowser.browser.webengine import interceptor
@ -281,6 +281,7 @@ class ProfileSetter:
self._set_hardcoded_settings()
self.set_persistent_cookie_policy()
self.set_dictionary_language()
self.disable_persistent_permissions_policy()
def _set_hardcoded_settings(self):
"""Set up settings with a fixed value."""
@ -345,6 +346,14 @@ class ProfileSetter:
self._profile.setSpellCheckLanguages(filenames)
self._profile.setSpellCheckEnabled(bool(filenames))
def disable_persistent_permissions_policy(self):
"""Disable webengine's permission persistence."""
pyqt_version = utils.VersionNumber.parse(version.PYQT_WEBENGINE_VERSION_STR)
if pyqt_version >= utils.VersionNumber(6, 8):
self._profile.setPersistentPermissionsPolicy(
QWebEngineProfile.PersistentPermissionsPolicy.AskEveryTime
)
def _update_settings(option):
"""Update global settings when qwebsettings changed."""

View File

@ -192,8 +192,8 @@ def pytest_collection_modifyitems(config, items):
'Skipped on Windows',
pytest.mark.skipif,
utils.is_windows),
('qt68_beta4_skip', # WORKAROUND: https://github.com/qutebrowser/qutebrowser/issues/8242#issuecomment-2184542226
"Fails on Qt 6.8 beta 4",
('qt68_no_permission_api', # WORKAROUND: https://github.com/qutebrowser/qutebrowser/issues/8242#issuecomment-2184542226
"Fails on Qt 6.8 with PyQt<6.8",
pytest.mark.xfail,
machinery.IS_QT6 and version.qtwebengine_versions(
avoid_init=True

View File

@ -251,7 +251,7 @@ Feature: Prompts
And I run :click-element id button
Then the javascript message "geolocation permission denied" should be logged
@qt68_beta4_skip
@qt68_no_permission_api
Scenario: geolocation with ask -> false
When I set content.geolocation to ask
And I open data/prompt/geolocation.html in a new tab
@ -260,7 +260,7 @@ Feature: Prompts
And I run :prompt-accept no
Then the javascript message "geolocation permission denied" should be logged
@qt68_beta4_skip
@qt68_no_permission_api
Scenario: geolocation with ask -> false and save
When I set content.geolocation to ask
And I open data/prompt/geolocation.html in a new tab
@ -270,7 +270,7 @@ Feature: Prompts
Then the javascript message "geolocation permission denied" should be logged
And the per-domain option content.geolocation should be set to false for http://localhost:(port)
@qt68_beta4_skip
@qt68_no_permission_api
Scenario: geolocation with ask -> abort
When I set content.geolocation to ask
And I open data/prompt/geolocation.html in a new tab