diff options
| author | Kaloyan Chehlarski <kaloyan.chehlarski@qt.io> | 2024-03-07 16:20:01 +0100 |
|---|---|---|
| committer | Kaloyan Chehlarski <kaloyan.chehlarski@qt.io> | 2024-06-01 13:28:22 +0200 |
| commit | 02b8b5afb45c2f926a4c0026cdb05e2fbb47dc46 (patch) | |
| tree | b71d95563b1fc99ff7c2963ffec86564cb54bcce /src/core/profile_adapter.cpp | |
| parent | ebf9ad043daa53c310ea2d5ee9987afbc615e4cd (diff) | |
Implement optional website permission persistence
This change introduces a new API allowing application developers
to choose whether they want to retain the granted/denied status of
permissions between different pages or browsing sessions. The
previous behavior of asking for permission every time is still
optionally available, but the default behavior is to persist
permissions inbetween sessions (except for off-the-record profiles,
where the permissions get destroyed alongside the profile).
Storage is handled via a PrefService, which writes to a
permissions.json file stored inside the profile folder. This is
different to Chromium's implementation, which is massively
overengineered and would require enabling a ton of code we will
never need to use.
[ChangeLog][QtWebEngineCore][QWebEngineProfile] Added new API
to control permission persistence.
[ChangeLog][QtWebEngineQuick] Added new API
to control permission persistence.
Fixes: QTBUG-55108
Change-Id: Ib3057feda3bfbbf2a17a86356feca35a67180806
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core/profile_adapter.cpp')
| -rw-r--r-- | src/core/profile_adapter.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/core/profile_adapter.cpp b/src/core/profile_adapter.cpp index b26f9b1de..6fec8aa28 100644 --- a/src/core/profile_adapter.cpp +++ b/src/core/profile_adapter.cpp @@ -64,6 +64,7 @@ ProfileAdapter::ProfileAdapter(const QString &storageName): , m_downloadPath(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)) , m_httpCacheType(DiskHttpCache) , m_persistentCookiesPolicy(AllowPersistentCookies) + , m_persistentPermissionsPolicy(PersistentPermissionsOnDisk) , m_visitedLinksPolicy(TrackVisitedLinksOnDisk) , m_clientHintsEnabled(true) , m_pushServiceEnabled(false) @@ -72,6 +73,8 @@ ProfileAdapter::ProfileAdapter(const QString &storageName): WebEngineContext::current()->addProfileAdapter(this); // creation of profile requires webengine context m_profile.reset(new ProfileQt(this)); + // initialize permissions store + profile()->GetPermissionControllerDelegate(); // fixme: this should not be here m_profile->m_profileIOData->initializeOnUIThread(); m_customUrlSchemeHandlers.insert(QByteArrayLiteral("qrc"), &m_qrcHandler); @@ -109,6 +112,7 @@ void ProfileAdapter::setStorageName(const QString &storageName) m_name = storageName; if (!m_offTheRecord) { m_profile->setupPrefService(); + m_profile->setupPermissionsManager(); if (!m_profile->m_profileIOData->isClearHttpCacheInProgress()) m_profile->m_profileIOData->resetNetworkContext(); if (m_visitedLinksManager) @@ -124,6 +128,7 @@ void ProfileAdapter::setOffTheRecord(bool offTheRecord) return; m_offTheRecord = offTheRecord; m_profile->setupPrefService(); + m_profile->setupPermissionsManager(); if (!m_profile->m_profileIOData->isClearHttpCacheInProgress()) m_profile->m_profileIOData->resetNetworkContext(); if (m_visitedLinksManager) @@ -371,6 +376,24 @@ void ProfileAdapter::setPersistentCookiesPolicy(ProfileAdapter::PersistentCookie m_profile->m_profileIOData->resetNetworkContext(); } +ProfileAdapter::PersistentPermissionsPolicy ProfileAdapter::persistentPermissionsPolicy() const +{ + if (m_persistentPermissionsPolicy == NoPersistentPermissions) + return NoPersistentPermissions; + if (isOffTheRecord() || m_name.isEmpty()) + return PersistentPermissionsInMemory; + return m_persistentPermissionsPolicy; +} + +void ProfileAdapter::setPersistentPermissionsPolicy(ProfileAdapter::PersistentPermissionsPolicy newPersistentPermissionsPolicy) +{ + ProfileAdapter::PersistentPermissionsPolicy oldPolicy = persistentPermissionsPolicy(); + m_persistentPermissionsPolicy = newPersistentPermissionsPolicy; + if (oldPolicy == persistentPermissionsPolicy()) + return; + m_profile->setupPermissionsManager(); +} + ProfileAdapter::VisitedLinksPolicy ProfileAdapter::visitedLinksPolicy() const { if (isOffTheRecord() || m_visitedLinksPolicy == DoNotTrackVisitedLinks) |
