diff options
| author | Kaloyan Chehlarski <kaloyan.chehlarski@qt.io> | 2024-04-02 16:08:15 +0200 |
|---|---|---|
| committer | Kaloyan Chehlarski <kaloyan.chehlarski@qt.io> | 2024-06-03 14:42:44 +0200 |
| commit | 00d7de830a43a84a431511a55525f04c21b8ba49 (patch) | |
| tree | 9411fe4666661afa85a11d5a8070968b69747dc4 /examples/webenginewidgets/simplebrowser/webview.cpp | |
| parent | ece3b065828bc6ca09dd2ad8654b48cdaddf1178 (diff) | |
Add QWebEnginePermission and rewrite permissions API
With the addition of permission persistence, it's now important for us
to have an API for querying previously granted/denied permissions, so
that they can be revoked at a later point. This change does the bulk
of the work to get us there, by introducing a new type representing
a single permission for a given URL/Feature pair.
This type holds no information about the permission's state; it is
simply an accessor object which allows its user to query the current
status of the permission, grant/deny it, or reset it back to its
initial state (so, delete it from storage). This provides application
developers an easy way to store/modify lists of permissions without
having to define their own custom types. A subsequent change will expand
the API to provide a list of all permissions for a given profile.
The current API (in QWebEnginePage and QQuickWebEngineView) has been
marked as deprecated, but has not been disabled to ensure a smooth
transition for developers.
[ChangeLog][QtWebEngineCore][QWebEnginePage] Deprecated old
permissions API
[ChangeLog][QtWebEngineQuick][WebEngineView] Deprecated old
permissions API
[ChangeLog][QtWebEngineCore] Added new API for querying and modifying
website permissions.
[ChangeLog][QtWebEngineQuick] Added new API for querying and modifying
website permissions.
Pick-to: 6.8
Change-Id: I8661cdc26bbd6dcde6403d29cc083bcea1a49ccc
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'examples/webenginewidgets/simplebrowser/webview.cpp')
| -rw-r--r-- | examples/webenginewidgets/simplebrowser/webview.cpp | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/examples/webenginewidgets/simplebrowser/webview.cpp b/examples/webenginewidgets/simplebrowser/webview.cpp index 08e044f70..3dcfc0c47 100644 --- a/examples/webenginewidgets/simplebrowser/webview.cpp +++ b/examples/webenginewidgets/simplebrowser/webview.cpp @@ -71,26 +71,26 @@ WebView::~WebView() m_imageAnimationGroup = nullptr; } -inline QString questionForFeature(QWebEnginePage::Feature feature) +inline QString questionForFeature(QWebEnginePermission::Feature feature) { switch (feature) { - case QWebEnginePage::Geolocation: + case QWebEnginePermission::Geolocation: return QObject::tr("Allow %1 to access your location information?"); - case QWebEnginePage::MediaAudioCapture: + case QWebEnginePermission::MediaAudioCapture: return QObject::tr("Allow %1 to access your microphone?"); - case QWebEnginePage::MediaVideoCapture: + case QWebEnginePermission::MediaVideoCapture: return QObject::tr("Allow %1 to access your webcam?"); - case QWebEnginePage::MediaAudioVideoCapture: + case QWebEnginePermission::MediaAudioVideoCapture: return QObject::tr("Allow %1 to access your microphone and webcam?"); - case QWebEnginePage::MouseLock: + case QWebEnginePermission::MouseLock: return QObject::tr("Allow %1 to lock your mouse cursor?"); - case QWebEnginePage::DesktopVideoCapture: + case QWebEnginePermission::DesktopVideoCapture: return QObject::tr("Allow %1 to capture video of your desktop?"); - case QWebEnginePage::DesktopAudioVideoCapture: + case QWebEnginePermission::DesktopAudioVideoCapture: return QObject::tr("Allow %1 to capture audio and video of your desktop?"); - case QWebEnginePage::Notifications: + case QWebEnginePermission::Notifications: return QObject::tr("Allow %1 to show notification on your desktop?"); - case QWebEnginePage::ClipboardReadWrite: + case QWebEnginePermission::ClipboardReadWrite: return QObject::tr("Allow %1 to read from and write to the clipboard?"); } return QString(); @@ -103,8 +103,8 @@ void WebView::setPage(WebPage *page) &WebView::handleCertificateError); disconnect(oldPage, &QWebEnginePage::authenticationRequired, this, &WebView::handleAuthenticationRequired); - disconnect(oldPage, &QWebEnginePage::featurePermissionRequested, this, - &WebView::handleFeaturePermissionRequested); + disconnect(oldPage, &QWebEnginePage::permissionRequested, this, + &WebView::handlePermissionRequested); disconnect(oldPage, &QWebEnginePage::proxyAuthenticationRequired, this, &WebView::handleProxyAuthenticationRequired); disconnect(oldPage, &QWebEnginePage::registerProtocolHandlerRequested, this, @@ -124,8 +124,8 @@ void WebView::setPage(WebPage *page) connect(page, &WebPage::createCertificateErrorDialog, this, &WebView::handleCertificateError); connect(page, &QWebEnginePage::authenticationRequired, this, &WebView::handleAuthenticationRequired); - connect(page, &QWebEnginePage::featurePermissionRequested, this, - &WebView::handleFeaturePermissionRequested); + connect(page, &QWebEnginePage::permissionRequested, this, + &WebView::handlePermissionRequested); connect(page, &QWebEnginePage::proxyAuthenticationRequired, this, &WebView::handleProxyAuthenticationRequired); connect(page, &QWebEnginePage::registerProtocolHandlerRequested, this, @@ -309,17 +309,14 @@ void WebView::handleAuthenticationRequired(const QUrl &requestUrl, QAuthenticato } } -void WebView::handleFeaturePermissionRequested(const QUrl &securityOrigin, - QWebEnginePage::Feature feature) +void WebView::handlePermissionRequested(QWebEnginePermission permission) { QString title = tr("Permission Request"); - QString question = questionForFeature(feature).arg(securityOrigin.host()); + QString question = questionForFeature(permission.feature()).arg(permission.origin().host()); if (!question.isEmpty() && QMessageBox::question(window(), title, question) == QMessageBox::Yes) - page()->setFeaturePermission(securityOrigin, feature, - QWebEnginePage::PermissionGrantedByUser); + permission.grant(); else - page()->setFeaturePermission(securityOrigin, feature, - QWebEnginePage::PermissionDeniedByUser); + permission.deny(); } void WebView::handleProxyAuthenticationRequired(const QUrl &, QAuthenticator *auth, |
