summaryrefslogtreecommitdiffstats
path: root/examples/webenginewidgets
diff options
context:
space:
mode:
Diffstat (limited to 'examples/webenginewidgets')
-rw-r--r--examples/webenginewidgets/simplebrowser/webpage.cpp34
-rw-r--r--examples/webenginewidgets/simplebrowser/webpage.h1
2 files changed, 35 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();
diff --git a/examples/webenginewidgets/simplebrowser/webpage.h b/examples/webenginewidgets/simplebrowser/webpage.h
index c8b884077..0b9ef2abe 100644
--- a/examples/webenginewidgets/simplebrowser/webpage.h
+++ b/examples/webenginewidgets/simplebrowser/webpage.h
@@ -66,6 +66,7 @@ protected:
private slots:
void handleAuthenticationRequired(const QUrl &requestUrl, QAuthenticator *auth);
+ void handleFeaturePermissionRequested(const QUrl &securityOrigin, Feature feature);
void handleProxyAuthenticationRequired(const QUrl &requestUrl, QAuthenticator *auth, const QString &proxyHost);
void handleRegisterProtocolHandlerRequested(QWebEngineRegisterProtocolHandlerRequest request);
};