Clear webengine's permissions.json on start

To avoid WebEngine remembering granted permissions across restarts,
remove their persistence file when we start up.

This is only technically required when Qt=>6.8 and PyQt<6.8. But we only
take action if the file exists anyway, so it's safe enough to run all
the time and that means less conditional code to test ;)

There are a few options for where we could do this cleanup, I'm choosing
to do it at the latest point possible, which is right before we set
`setPersistentStoragePath()`, since the permissions manager is
re-initialized after that, see https://bugreports.qt.io/browse/QTBUG-126595

TODO:
* call the new setPersistentPermissionsPolicy API when PyQt>=6.8
This commit is contained in:
toofar 2024-10-13 18:52:29 +13:00
parent dfd4fffaac
commit 0ab1e3b757
2 changed files with 21 additions and 1 deletions

View File

@ -392,6 +392,26 @@ def _init_profile(profile: QWebEngineProfile) -> None:
_global_settings.init_settings()
def _clear_webengine_permissions_json():
"""Remove QtWebEngine's persistent permissions file, if present.
We have our own permissions feature and don't integrate with their one.
This only needs to be called when you are on Qt6.8 but PyQt<6.8, since if
we have access to the `setPersistentPermissionsPolicy()` we will use that
to disable the Qt feature.
This needs to be called before we call `setPersistentStoragePath()`
because Qt will load the file during that.
"""
permissions_file = pathlib.Path(standarddir.data()) / "webengine" / "permissions.json"
if permissions_file.exists():
try:
permissions_file.unlink()
except OSError as err:
log.init.warning(
f"Error while cleaning up webengine permissions file: {err}"
)
def _init_default_profile():
"""Init the default QWebEngineProfile."""
global default_profile
@ -414,6 +434,7 @@ def _init_default_profile():
f" Early version: {non_ua_version}\n"
f" Real version: {ua_version}")
_clear_webengine_permissions_json()
default_profile.setCachePath(
os.path.join(standarddir.cache(), 'webengine'))
default_profile.setPersistentStoragePath(

View File

@ -636,7 +636,6 @@ def test_cookies_store(quteproc_new, request, short_tmpdir, store):
quteproc_new.wait_for_quit()
@pytest.mark.qt68_beta4_skip
def test_permission_prompt_across_restart(quteproc_new, request, short_tmpdir):
# Start test process
args = _base_args(request.config) + [