diff options
Diffstat (limited to 'examples/webenginewidgets/simplebrowser/webpage.cpp')
-rw-r--r-- | examples/webenginewidgets/simplebrowser/webpage.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/examples/webenginewidgets/simplebrowser/webpage.cpp b/examples/webenginewidgets/simplebrowser/webpage.cpp index 512778b82..fcbb38b8f 100644 --- a/examples/webenginewidgets/simplebrowser/webpage.cpp +++ b/examples/webenginewidgets/simplebrowser/webpage.cpp @@ -62,6 +62,7 @@ WebPage::WebPage(QWebEngineProfile *profile, QObject *parent) : QWebEnginePage(profile, parent) { connect(this, &QWebEnginePage::authenticationRequired, this, &WebPage::handleAuthenticationRequired); + connect(this, &QWebEnginePage::featurePermissionRequested, this, &WebPage::handleFeaturePermissionRequested); connect(this, &QWebEnginePage::proxyAuthenticationRequired, this, &WebPage::handleProxyAuthenticationRequired); connect(this, &QWebEnginePage::registerProtocolHandlerRequested, this, &WebPage::handleRegisterProtocolHandlerRequested); } @@ -115,6 +116,39 @@ void WebPage::handleAuthenticationRequired(const QUrl &requestUrl, QAuthenticato } } +inline QString questionForFeature(QWebEnginePage::Feature feature) +{ + switch (feature) { + case QWebEnginePage::Geolocation: + return WebPage::tr("Allow %1 to access your location information?"); + case QWebEnginePage::MediaAudioCapture: + return WebPage::tr("Allow %1 to access your microphone?"); + case QWebEnginePage::MediaVideoCapture: + return WebPage::tr("Allow %1 to access your webcam?"); + case QWebEnginePage::MediaAudioVideoCapture: + return WebPage::tr("Allow %1 to access your microphone and webcam?"); + case QWebEnginePage::MouseLock: + return WebPage::tr("Allow %1 to lock your mouse cursor?"); + case QWebEnginePage::DesktopVideoCapture: + return WebPage::tr("Allow %1 to capture video of your desktop?"); + case QWebEnginePage::DesktopAudioVideoCapture: + return WebPage::tr("Allow %1 to capture audio and video of your desktop?"); + case QWebEnginePage::Notifications: + return QString(); + } + return QString(); +} + +void WebPage::handleFeaturePermissionRequested(const QUrl &securityOrigin, Feature feature) +{ + QString title = tr("Permission Request"); + QString question = questionForFeature(feature).arg(securityOrigin.host()); + if (!question.isEmpty() && QMessageBox::question(view()->window(), title, question) == QMessageBox::Yes) + setFeaturePermission(securityOrigin, feature, PermissionGrantedByUser); + else + setFeaturePermission(securityOrigin, feature, PermissionDeniedByUser); +} + void WebPage::handleProxyAuthenticationRequired(const QUrl &, QAuthenticator *auth, const QString &proxyHost) { QWidget *mainWindow = view()->window(); |