summaryrefslogtreecommitdiffstats
path: root/src/webenginequick/api/qquickwebengineprofile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/webenginequick/api/qquickwebengineprofile.cpp')
-rw-r--r--src/webenginequick/api/qquickwebengineprofile.cpp229
1 files changed, 224 insertions, 5 deletions
diff --git a/src/webenginequick/api/qquickwebengineprofile.cpp b/src/webenginequick/api/qquickwebengineprofile.cpp
index 7c3d11fcf..d3373d0b9 100644
--- a/src/webenginequick/api/qquickwebengineprofile.cpp
+++ b/src/webenginequick/api/qquickwebengineprofile.cpp
@@ -19,6 +19,7 @@
#include <QtWebEngineCore/qwebenginenotification.h>
#include <QtWebEngineCore/private/qwebenginedownloadrequest_p.h>
#include <QtWebEngineCore/qwebengineurlscheme.h>
+#include <QtWebEngineCore/private/qwebenginepermission_p.h>
#include <QtCore/qdir.h>
#include <QtCore/qfileinfo.h>
@@ -95,6 +96,28 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \enum QQuickWebEngineProfile::PersistentPermissionsPolicy
+
+ \since 6.8
+
+ This enum describes the policy for permission persistence:
+
+ \value NoPersistentPermissions
+ The application will ask for permissions every time they're needed, regardless of
+ whether they've been granted before or not. This is intended for backwards compatibility
+ with existing applications, and otherwise not recommended.
+ \value PersistentPermissionsInMemory
+ A request will be made only the first time a permission is needed. Any subsequent
+ requests will be automatically granted or denied, depending on the initial user choice.
+ This carries over to all pages that use the same QQuickWebEngineProfile instance, until the
+ application is shut down. This is the setting applied if \c off-the-record is set
+ or no persistent data path is available.
+ \value PersistentPermissionsOnDisk
+ Works the same way as \c PersistentPermissionsInMemory, but the permissions are saved to
+ and restored from disk. This is the default setting.
+*/
+
+/*!
\fn QQuickWebEngineProfile::downloadRequested(QQuickWebEngineDownloadRequest *download)
This signal is emitted whenever a download has been triggered.
@@ -105,6 +128,8 @@ QT_BEGIN_NAMESPACE
The download item is parented by the profile. If it is not accepted, it
will be deleted immediately after the signal emission.
This signal cannot be used with a queued connection.
+
+ \note To use from C++ static_cast \a download to QWebEngineDownloadRequest
*/
/*!
@@ -113,6 +138,8 @@ QT_BEGIN_NAMESPACE
This signal is emitted whenever downloading stops, because it finished successfully, was
cancelled, or was interrupted (for example, because connectivity was lost).
The \a download argument holds the state of the finished download instance.
+
+ \note To use from C++ static_cast \a download to QWebEngineDownloadRequest
*/
/*!
@@ -431,15 +458,18 @@ void QQuickWebEngineProfile::setStorageName(const QString &name)
if (d->profileAdapter()->storageName() == name)
return;
ProfileAdapter::HttpCacheType oldCacheType = d->profileAdapter()->httpCacheType();
- ProfileAdapter::PersistentCookiesPolicy oldPolicy = d->profileAdapter()->persistentCookiesPolicy();
+ ProfileAdapter::PersistentCookiesPolicy oldCookiePolicy = d->profileAdapter()->persistentCookiesPolicy();
+ ProfileAdapter::PersistentPermissionsPolicy oldPermissionsPolicy = d->profileAdapter()->persistentPermissionsPolicy();
d->profileAdapter()->setStorageName(name);
emit storageNameChanged();
emit persistentStoragePathChanged();
emit cachePathChanged();
if (d->profileAdapter()->httpCacheType() != oldCacheType)
emit httpCacheTypeChanged();
- if (d->profileAdapter()->persistentCookiesPolicy() != oldPolicy)
+ if (d->profileAdapter()->persistentCookiesPolicy() != oldCookiePolicy)
emit persistentCookiesPolicyChanged();
+ if (d->profileAdapter()->persistentPermissionsPolicy() != oldPermissionsPolicy)
+ emit persistentPermissionsPolicyChanged();
}
/*!
@@ -471,13 +501,16 @@ void QQuickWebEngineProfile::setOffTheRecord(bool offTheRecord)
if (d->profileAdapter()->isOffTheRecord() == offTheRecord)
return;
ProfileAdapter::HttpCacheType oldCacheType = d->profileAdapter()->httpCacheType();
- ProfileAdapter::PersistentCookiesPolicy oldPolicy = d->profileAdapter()->persistentCookiesPolicy();
+ ProfileAdapter::PersistentCookiesPolicy oldCookiePolicy = d->profileAdapter()->persistentCookiesPolicy();
+ ProfileAdapter::PersistentPermissionsPolicy oldPermissionsPolicy = d->profileAdapter()->persistentPermissionsPolicy();
d->profileAdapter()->setOffTheRecord(offTheRecord);
emit offTheRecordChanged();
if (d->profileAdapter()->httpCacheType() != oldCacheType)
emit httpCacheTypeChanged();
- if (d->profileAdapter()->persistentCookiesPolicy() != oldPolicy)
+ if (d->profileAdapter()->persistentCookiesPolicy() != oldCookiePolicy)
emit persistentCookiesPolicyChanged();
+ if (d->profileAdapter()->persistentPermissionsPolicy() != oldPermissionsPolicy)
+ emit persistentPermissionsPolicyChanged();
}
/*!
@@ -624,7 +657,7 @@ void QQuickWebEngineProfile::setHttpCacheType(QQuickWebEngineProfile::HttpCacheT
/*!
\qmlproperty enumeration WebEngineProfile::persistentCookiesPolicy
- This enumeration describes the policy of cookie persistency:
+ This enumeration describes the policy of cookie persistence:
\value WebEngineProfile.NoPersistentCookies
Both session and persistent cookies are stored in memory. This is the only setting
@@ -660,6 +693,51 @@ void QQuickWebEngineProfile::setPersistentCookiesPolicy(QQuickWebEngineProfile::
}
/*!
+ \qmlproperty enumeration WebEngineProfile::persistentPermissionsPolicy
+
+ \since 6.8
+
+ This enumeration describes the policy for permission persistence:
+
+ \value WebEngineProfile.NoPersistentPermissions
+ The application will ask for permissions every time they're needed, regardless of
+ whether they've been granted before or not. This is intended for backwards compatibility
+ with existing applications, and otherwise not recommended.
+ \value WebEngineProfile.PersistentPermissionsInMemory
+ A request will be made only the first time a permission is needed. Any subsequent
+ requests will be automatically granted or denied, depending on the initial user choice.
+ This carries over to all pages using the same QWebEngineProfile instance, until the
+ application is shut down. This is the setting applied if \c off-the-record is set
+ or no persistent data path is available.
+ \value WebEngineProfile.PersistentPermissionsOnDisk
+ Works the same way as \c PersistentPermissionsInMemory, but the permissions are saved to
+ and restored from disk. This is the default setting.
+*/
+
+/*!
+ \property QQuickWebEngineProfile::persistentPermissionsPolicy
+ \since 6.8
+
+ Describes the policy of permission persistence.
+ If the profile is off-the-record, NoPersistentCookies is returned.
+*/
+
+QQuickWebEngineProfile::PersistentPermissionsPolicy QQuickWebEngineProfile::persistentPermissionsPolicy() const
+{
+ Q_D(const QQuickWebEngineProfile);
+ return QQuickWebEngineProfile::PersistentPermissionsPolicy(d->profileAdapter()->persistentPermissionsPolicy());
+}
+
+void QQuickWebEngineProfile::setPersistentPermissionsPolicy(QQuickWebEngineProfile::PersistentPermissionsPolicy newPersistentPermissionsPolicy)
+{
+ Q_D(QQuickWebEngineProfile);
+ ProfileAdapter::PersistentPermissionsPolicy oldPolicy = d->profileAdapter()->persistentPermissionsPolicy();
+ d->profileAdapter()->setPersistentPermissionsPolicy(ProfileAdapter::PersistentPermissionsPolicy(newPersistentPermissionsPolicy));
+ if (d->profileAdapter()->persistentPermissionsPolicy() != oldPolicy)
+ emit persistentPermissionsPolicyChanged();
+}
+
+/*!
\qmlproperty int WebEngineProfile::httpCacheMaximumSize
The maximum size of the HTTP cache. If \c 0, the size will be controlled automatically by
@@ -1036,6 +1114,147 @@ QWebEngineClientHints *QQuickWebEngineProfile::clientHints() const
return d->m_clientHints.data();
}
+/*!
+ \fn QQuickWebEngineProfile::getPermission(const QUrl &securityOrigin, QWebEnginePermission::Feature feature) const
+
+ Returns a QWebEnginePermission object corresponding to a single permission for the provided \a securityOrigin and
+ \a feature. The object may be used to query for the current state of the permission, or to change it. It is not required
+ for a permission to already exist; the returned object may also be used to pre-grant a permission if a website is
+ known to use it.
+
+ \note This may only be used for permanent feature types. Calling it with a transient \a feature will return an invalid object.
+ \since 6.8
+ \sa listPermissions(), QWebEnginePermission::Feature
+ */
+
+/*!
+ \qmlmethod void WebEngineProfile::getPermission(url securityOrigin, WebEnginePermission.Feature feature) const
+
+ Returns a webEnginePermission object corresponding to a single permission for the provided \a securityOrigin and
+ \a feature. The object may be used to query for the current state of the permission, or to change it. It is not required
+ for a permission to already exist; the returned object may also be used to pre-grant a permission if a website is
+ known to use it.
+
+ \note This may only be used for permanent feature types. Calling it with a transient \a feature will return an invalid object.
+ \since 6.8
+ \sa listPermissions()
+ */
+QWebEnginePermission QQuickWebEngineProfile::getPermission(const QUrl &securityOrigin, QWebEnginePermission::Feature feature) const
+{
+ Q_D(const QQuickWebEngineProfile);
+
+ if (feature == QWebEnginePermission::Unsupported) {
+ qWarning("Attempting to get unsupported permission. Returned object will be in an invalid state.");
+ return QWebEnginePermission(new QWebEnginePermissionPrivate());
+ }
+
+ if (QWebEnginePermission::isTransient(feature)) {
+ qWarning() << "Attempting to get permission for feature" << feature << ". Returned object will be in an invalid state.";
+ return QWebEnginePermission(new QWebEnginePermissionPrivate());
+ }
+
+ auto *pvt = new QWebEnginePermissionPrivate(securityOrigin, feature, nullptr, d->profileAdapter());
+ return QWebEnginePermission(pvt);
+}
+
+/*!
+ \qmlmethod list<webEnginePermission> WebEngineProfile::listPermissions() const
+
+ Returns a \l list of webEnginePermission objects, each one representing a single permission currently
+ present in the permissions store. The returned list contains all previously granted/denied permissions for this profile,
+ except for those of a transient feature type.
+
+ \since 6.8
+ \sa getPermission()
+ */
+
+/*!
+ Returns a QList of QWebEnginePermission objects, each one representing a single permission currently
+ present in the permissions store. The returned list contains all previously granted/denied permissions for this profile,
+ except for those of a transient feature type.
+
+ \since 6.8
+ \sa getPermission()
+ */
+QList<QWebEnginePermission> QQuickWebEngineProfile::listPermissions() const
+{
+ Q_D(const QQuickWebEngineProfile);
+ if (persistentPermissionsPolicy() == NoPersistentPermissions)
+ return QList<QWebEnginePermission>();
+ return d->profileAdapter()->listPermissions();
+}
+
+/*!
+ \qmlmethod list<webEnginePermission> WebEngineProfile::listPermissions(url securityOrigin) const
+
+ Returns a \l list of webEnginePermission objects, each one representing a single permission currently
+ present in the permissions store. The returned list contains all previously granted/denied permissions associated with a
+ specific \a securityOrigin for this profile, except for those of a transient feature type.
+
+ \note Since permissions are granted on a per-origin basis, the provided \a securityOrigin will be stripped to its
+ origin form, and the returned list will contain all permissions for the origin. Thus, passing https://www.example.com/some/page.html
+ is the same as passing just https://www.example.com/.
+ \since 6.8
+ \sa getPermission()
+ */
+
+/*!
+ Returns a QList of QWebEnginePermission objects, each one representing a single permission currently
+ present in the permissions store. The returned list contains all previously granted/denied permissions associated with a
+ specific \a securityOrigin for this profile, except for those of a transient feature type.
+
+ \note Since permissions are granted on a per-origin basis, the provided \a securityOrigin will be stripped to its
+ origin form, and the returned list will contain all permissions for the origin. Thus, passing https://www.example.com/some/page.html
+ is the same as passing just https://www.example.com/.
+ \since 6.8
+ \sa getPermission()
+ */
+QList<QWebEnginePermission> QQuickWebEngineProfile::listPermissions(const QUrl &securityOrigin) const
+{
+ Q_D(const QQuickWebEngineProfile);
+ if (persistentPermissionsPolicy() == NoPersistentPermissions)
+ return QList<QWebEnginePermission>();
+ return d->profileAdapter()->listPermissions(securityOrigin);
+}
+
+/*!
+ \qmlmethod list<webEnginePermission> WebEngineProfile::listPermissions(WebEnginePermission.Feature feature) const
+
+ Returns a \l list of webEnginePermission objects, each one representing a single permission currently
+ present in the permissions store. The returned list contains all previously granted/denied permissions of the \a feature
+ type for this profile. If the feature is of a transient or unsupported type, the list will be empty.
+
+ \since 6.8
+ \sa getPermission()
+ */
+
+/*!
+ Returns a QList of QWebEnginePermission objects, each one representing a single permission currently
+ present in the permissions store. The returned list contains all previously granted/denied permissions of the \a feature
+ type for this profile. If the feature is of a transient or unsupported type, the list will be empty.
+
+ \since 6.8
+ \sa getPermission(), QWebEnginePermission::Feature
+ */
+QList<QWebEnginePermission> QQuickWebEngineProfile::listPermissions(QWebEnginePermission::Feature feature) const
+{
+ Q_D(const QQuickWebEngineProfile);
+ if (persistentPermissionsPolicy() == NoPersistentPermissions)
+ return QList<QWebEnginePermission>();
+
+ if (feature == QWebEnginePermission::Unsupported) {
+ qWarning("Attempting to get permission list for an unsupported type. Returned list will be empty.");
+ return QList<QWebEnginePermission>();
+ }
+
+ if (QWebEnginePermission::isTransient(feature)) {
+ qWarning() << "Attempting to get permission list for feature" << feature << ". Returned list will be empty.";
+ return QList<QWebEnginePermission>();
+ }
+
+ return d->profileAdapter()->listPermissions(QUrl(), feature);
+}
+
void QQuickWebEngineProfile::ensureQmlContext(const QObject *object)
{
if (!qmlContext(this)) {