aboutsummaryrefslogtreecommitdiff
path: root/src/webengine
diff options
context:
space:
mode:
Diffstat (limited to 'src/webengine')
-rw-r--r--src/webengine/webpage.cpp48
-rw-r--r--src/webengine/webpage.h11
2 files changed, 50 insertions, 9 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);
+}
diff --git a/src/webengine/webpage.h b/src/webengine/webpage.h
index 674f278..92c5925 100644
--- a/src/webengine/webpage.h
+++ b/src/webengine/webpage.h
@@ -6,8 +6,8 @@
* SPDX-License-Identifier: GPL-3.0
*/
-#ifndef WEBPAGE_H
-#define WEBPAGE_H
+#ifndef SMOLBOTE_WEBPAGE_H
+#define SMOLBOTE_WEBPAGE_H
#include <QWebEnginePage>
@@ -18,7 +18,10 @@ public:
explicit WebPage(QWebEngineProfile *profile, QObject *parent = nullptr);
protected:
- bool certificateError(const QWebEngineCertificateError &certificateError);
+ bool certificateError(const QWebEngineCertificateError &certificateError) override;
+
+private slots:
+ void featurePermissionDialog(const QUrl &securityOrigin, QWebEnginePage::Feature feature);
};
-#endif // WEBPAGE_H
+#endif // SMOLBOTE_WEBPAGE_H