summaryrefslogtreecommitdiffstats
path: root/examples/webenginewidgets
diff options
context:
space:
mode:
authorJüri Valdmann <juri.valdmann@qt.io>2018-05-25 13:02:33 +0200
committerJüri Valdmann <juri.valdmann@qt.io>2018-06-01 04:51:21 +0000
commit914d4346da5b69bfeab4c94eb380050853120c1c (patch)
tree5fc7feeaa0985602e78fcb7d963673c4430ea41d /examples/webenginewidgets
parentd282d2b1999f3b2b8ad68fbd8e243071f02bab2a (diff)
simplebrowser: Handle featurePermissionRequested signal
Change-Id: I012461722c006cbd6a4871279e94a442681d4fe5 Reviewed-by: Kai Koehne <kai.koehne@qt.io>
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);
};