From f4ca67aa7f70f58d39ef8689ddd5910e215ed6cd Mon Sep 17 00:00:00 2001 From: Kirill Burtsev Date: Thu, 31 Jan 2019 13:08:21 +0100 Subject: Web Notifications API Implements API for end-user notifications. Co-authored by Allan Sandfeld Jensen [ChangeLog][Profile] Support for Web Notifications API for end-user notifications through QWebEngineNotification Task-number: QTBUG-50995 Fixes: QTBUG-51191 Change-Id: Icebaaa05275a713e801f1f8ecdaaec725fa264c8 Reviewed-by: Allan Sandfeld Jensen --- src/webengine/api/qquickwebengineprofile.cpp | 23 +++++++++++++++++++++++ src/webengine/api/qquickwebengineprofile.h | 3 +++ src/webengine/api/qquickwebengineprofile_p.h | 2 ++ src/webengine/api/qquickwebengineview.cpp | 9 +++++++++ src/webengine/api/qquickwebengineview_p.h | 3 ++- src/webengine/api/qquickwebengineview_p_p.h | 1 + src/webengine/doc/src/qtwebengine-features.qdoc | 10 ++++++++++ src/webengine/doc/src/webengineview_lgpl.qdoc | 2 ++ src/webengine/plugin/plugin.cpp | 3 ++- 9 files changed, 54 insertions(+), 2 deletions(-) (limited to 'src/webengine') diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp index 8a6c20f67..cf9dae90a 100644 --- a/src/webengine/api/qquickwebengineprofile.cpp +++ b/src/webengine/api/qquickwebengineprofile.cpp @@ -46,6 +46,7 @@ #include "qquickwebenginesettings_p.h" #include "qquickwebengineview_p_p.h" #include "qwebenginecookiestore.h" +#include "qwebenginenotification.h" #include @@ -150,6 +151,13 @@ ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::MimeHtmlSaveFormat, QtWebEngineC The \a download argument holds the state of the finished download instance. */ +/*! + \fn QQuickWebEngineProfile::userNotification(QWebEngineNotification *notification) + + This signal is emitted whenever there is a newly created user notification. + The \a notification argument holds the notification instance to query data and interact with. +*/ + QQuickWebEngineProfilePrivate::QQuickWebEngineProfilePrivate(ProfileAdapter *profileAdapter) : m_settings(new QQuickWebEngineSettings()) , m_profileAdapter(profileAdapter) @@ -285,6 +293,14 @@ void QQuickWebEngineProfilePrivate::useForGlobalCertificateVerificationChanged() Q_EMIT q->useForGlobalCertificateVerificationChanged(); } +void QQuickWebEngineProfilePrivate::showNotification(QSharedPointer &controller) +{ + Q_Q(QQuickWebEngineProfile); + auto notification = new QWebEngineNotification(controller); + QQmlEngine::setObjectOwnership(notification, QQmlEngine::JavaScriptOwnership); + Q_EMIT q->userNotification(notification); +} + void QQuickWebEngineProfilePrivate::userScripts_append(QQmlListProperty *p, QQuickWebEngineScript *script) { Q_ASSERT(p && p->data); @@ -364,6 +380,13 @@ void QQuickWebEngineProfilePrivate::userScripts_clear(QQmlListProperty &controller) override; + // QQmlListPropertyHelpers static void userScripts_append(QQmlListProperty *p, QQuickWebEngineScript *script); static int userScripts_count(QQmlListProperty *p); diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index 5e6a45924..e7b2d8c9c 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -320,6 +320,12 @@ void QQuickWebEngineViewPrivate::runGeolocationPermissionRequest(const QUrl &url Q_EMIT q->featurePermissionRequested(url, QQuickWebEngineView::Geolocation); } +void QQuickWebEngineViewPrivate::runUserNotificationPermissionRequest(const QUrl &url) +{ + Q_Q(QQuickWebEngineView); + Q_EMIT q->featurePermissionRequested(url, QQuickWebEngineView::Notifications); +} + void QQuickWebEngineViewPrivate::showColorDialog(QSharedPointer controller) { Q_Q(QQuickWebEngineView); @@ -1550,6 +1556,9 @@ void QQuickWebEngineView::grantFeaturePermission(const QUrl &securityOrigin, QQu WebContentsAdapterClient::MediaDesktopAudioCapture | WebContentsAdapterClient::MediaDesktopVideoCapture)); break; + case Notifications: + d_ptr->adapter->runUserNotificationRequestCallback(securityOrigin, granted); + break; default: Q_UNREACHABLE(); } diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h index 3a40abf0a..c851dcb8d 100644 --- a/src/webengine/api/qquickwebengineview_p.h +++ b/src/webengine/api/qquickwebengineview_p.h @@ -209,7 +209,8 @@ public: MediaAudioVideoCapture, Geolocation, DesktopVideoCapture, - DesktopAudioVideoCapture + DesktopAudioVideoCapture, + Notifications, }; Q_ENUM(Feature) diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h index 4e8657651..543d7b119 100644 --- a/src/webengine/api/qquickwebengineview_p_p.h +++ b/src/webengine/api/qquickwebengineview_p_p.h @@ -145,6 +145,7 @@ public: void allowCertificateError(const QSharedPointer &errorController) override; void selectClientCert(const QSharedPointer &selectController) override; void runGeolocationPermissionRequest(QUrl const&) override; + void runUserNotificationPermissionRequest(QUrl const&) override; void renderProcessTerminated(RenderProcessTerminationStatus terminationStatus, int exitCode) override; void requestGeometryChange(const QRect &geometry, const QRect &frameGeometry) override; void updateScrollPosition(const QPointF &position) override; diff --git a/src/webengine/doc/src/qtwebengine-features.qdoc b/src/webengine/doc/src/qtwebengine-features.qdoc index 1dce17e08..64e9badb1 100644 --- a/src/webengine/doc/src/qtwebengine-features.qdoc +++ b/src/webengine/doc/src/qtwebengine-features.qdoc @@ -50,6 +50,7 @@ \li \l{Touch} \li \l{View Source} \li \l{WebRTC} + \li \l{Notifications} \endlist \section1 Audio and Video Codecs @@ -511,4 +512,13 @@ This feature can be tested by setting up a webcam or microphone and then opening \c https://test.webrtc.org/ in \l{WebEngine Widgets Simple Browser Example}{Simple Browser} or \l{WebEngine Quick Nano Browser}{Nano Browser}. + + \section1 Notifications + + Qt WebEngine supports JavaScript Web Notification API. + The application has to explicitly allow the feature by using + QWebEnginePage::Notifications or \l{WebEngineView::Feature} + {WebEngineView.Notifications}. + + Support for this feature was added in Qt 5.13.0. */ diff --git a/src/webengine/doc/src/webengineview_lgpl.qdoc b/src/webengine/doc/src/webengineview_lgpl.qdoc index d96aabc97..a6f2af39e 100644 --- a/src/webengine/doc/src/webengineview_lgpl.qdoc +++ b/src/webengine/doc/src/webengineview_lgpl.qdoc @@ -858,6 +858,8 @@ (Added in Qt 5.10) \value DesktopAudioVideoCapture Both audio and video output capture. (Added in Qt 5.10) + \value WebEnginView.Notifications + Web notifications for the end-user. \sa featurePermissionRequested(), grantFeaturePermission() */ diff --git a/src/webengine/plugin/plugin.cpp b/src/webengine/plugin/plugin.cpp index 0e63989ee..82a76760d 100644 --- a/src/webengine/plugin/plugin.cpp +++ b/src/webengine/plugin/plugin.cpp @@ -55,6 +55,7 @@ #include #include #include +#include #include #include @@ -161,7 +162,7 @@ public: tr("Cannot create a separate instance of WebEngineClientCertificateSelection")); qmlRegisterUncreatableType(uri, 1, 9, "WebEngineClientCertificateOption", tr("Cannot create a separate instance of WebEngineClientCertificateOption")); - + qmlRegisterUncreatableType(uri, 1, 9, "WebEngineNotification", msgUncreatableType("WebEngineNotification")); } private: -- cgit v1.2.3