aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/webpage.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-03-30 09:52:43 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-03-30 09:52:43 +0200
commit3e21d6afa724b48ba39d9edbc6a40ff8b2f95a0f (patch)
tree5a64b946ce1913d8e6a949b400531b9daac4f1e3 /src/webengine/webpage.cpp
parentMore informative SSL error message (diff)
downloadsmolbote-3e21d6afa724b48ba39d9edbc6a40ff8b2f95a0f.tar.xz
Page feature permission request dialog
Diffstat (limited to 'src/webengine/webpage.cpp')
-rw-r--r--src/webengine/webpage.cpp48
1 files changed, 43 insertions, 5 deletions
diff --git a/src/webengine/webpage.cpp b/src/webengine/webpage.cpp
index 79bf328..fe011b4 100644
--- a/src/webengine/webpage.cpp
+++ b/src/webengine/webpage.cpp
@@ -10,17 +10,36 @@
#include <QMessageBox>
#include <QWebEngineFullScreenRequest>
+QString feature_toString(QWebEnginePage::Feature feature)
+{
+ switch(feature) {
+ case QWebEnginePage::Notifications:
+ return QObject::tr("Notifications");
+ case QWebEnginePage::Geolocation:
+ return QObject::tr("Geolocation");
+ case QWebEnginePage::MediaAudioCapture:
+ return QObject::tr("Audio Capture");
+ case QWebEnginePage::MediaVideoCapture:
+ return QObject::tr("Video Capture");
+ case QWebEnginePage::MediaAudioVideoCapture:
+ return QObject::tr("Audio and Video Capture");
+ case QWebEnginePage::MouseLock:
+ return QObject::tr("Mouse Lock");
+ case QWebEnginePage::DesktopVideoCapture:
+ return QObject::tr("Desktop Video Capture");
+ case QWebEnginePage::DesktopAudioVideoCapture:
+ return QObject::tr("Desktop Audio and Video Capture");
+ }
+}
+
WebPage::WebPage(QWebEngineProfile *profile, QObject *parent)
: QWebEnginePage(profile, parent)
{
connect(this, &WebPage::fullScreenRequested, this, [](QWebEngineFullScreenRequest request) {
request.accept();
});
-#ifdef QT_DEBUG
- connect(this, &WebPage::featurePermissionRequested, this, [](const QUrl &securityOrigin, QWebEnginePage::Feature feature) {
- qDebug("Feature requested: %i", feature);
- });
-#endif
+
+ connect(this, &QWebEnginePage::featurePermissionRequested, this, &WebPage::featurePermissionDialog);
}
bool WebPage::certificateError(const QWebEngineCertificateError &certificateError)
@@ -50,3 +69,22 @@ bool WebPage::certificateError(const QWebEngineCertificateError &certificateErro
return resp == QMessageBox::Ignore;
}
+
+void WebPage::featurePermissionDialog(const QUrl &securityOrigin, QWebEnginePage::Feature feature)
+{
+ QMessageBox messageBox;
+
+ messageBox.setWindowTitle(tr("Feature permission request"));
+ messageBox.setIcon(QMessageBox::Question);
+ messageBox.setText(tr("<p>The webpage <strong>%1</strong> has requested permission to access: %2</p>"
+ "<p>Allow this feature?</p>")
+ .arg(securityOrigin.toString(), feature_toString(feature)));
+
+ messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+ messageBox.setDefaultButton(QMessageBox::No);
+
+ if(messageBox.exec() == QMessageBox::Yes)
+ setFeaturePermission(securityOrigin, feature, QWebEnginePage::PermissionGrantedByUser);
+ else
+ setFeaturePermission(securityOrigin, feature, QWebEnginePage::PermissionDeniedByUser);
+}