diff options
author | Kirill Burtsev <kirill.burtsev@qt.io> | 2019-01-31 13:08:21 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-02-06 15:18:18 +0000 |
commit | f4ca67aa7f70f58d39ef8689ddd5910e215ed6cd (patch) | |
tree | ebb9937672b14c725de14fd7da6e3eeac269e861 /src/webenginewidgets/api/qwebengineprofile.cpp | |
parent | 7aa06a1614b7ca6508d96ee2e8ef0f4c49038a6f (diff) |
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 <allan.jensen@qt.io>
Diffstat (limited to 'src/webenginewidgets/api/qwebengineprofile.cpp')
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp index e9703ffe8..74dc14da0 100644 --- a/src/webenginewidgets/api/qwebengineprofile.cpp +++ b/src/webenginewidgets/api/qwebengineprofile.cpp @@ -43,6 +43,7 @@ #include "qwebenginecookiestore.h" #include "qwebenginedownloaditem.h" #include "qwebenginedownloaditem_p.h" +#include "qwebenginenotificationpresenter_p.h" #include "qwebenginepage.h" #include "qwebenginepage_p.h" #include "qwebenginesettings.h" @@ -140,6 +141,12 @@ using QtWebEngineCore::ProfileAdapter; Both session and persistent cookies are saved to and restored from disk. */ +void QWebEngineProfilePrivate::showNotification(QSharedPointer<QtWebEngineCore::UserNotificationController> ¬ification) +{ + if (m_notificationPresenter) + m_notificationPresenter(QWebEngineNotification(notification)); +} + /*! \fn QWebEngineProfile::downloadRequested(QWebEngineDownloadItem *download) @@ -634,6 +641,27 @@ QWebEngineScriptCollection *QWebEngineProfile::scripts() const } /*! + Sets the function \a notificationPresenter as responsible for presenting sent notifications. + + \since 5.13 + \sa QWebEngineNotification +*/ +void QWebEngineProfile::setNotificationPresenter(const std::function<void(const QWebEngineNotification &)> ¬ificationPresenter) +{ + Q_D(QWebEngineProfile); + d->m_notificationPresenter = notificationPresenter; +} + +/*! + \overload +*/ +void QWebEngineProfile::setNotificationPresenter(std::function<void(const QWebEngineNotification &)> &¬ificationPresenter) +{ + Q_D(QWebEngineProfile); + d->m_notificationPresenter = std::move(notificationPresenter); +} + +/*! Returns the default profile. The default profile uses the storage name "Default". @@ -645,6 +673,8 @@ QWebEngineProfile *QWebEngineProfile::defaultProfile() static QWebEngineProfile* profile = new QWebEngineProfile( new QWebEngineProfilePrivate(ProfileAdapter::createDefaultProfileAdapter()), ProfileAdapter::globalQObjectRoot()); + if (!profile->d_ptr->m_notificationPresenter) + profile->setNotificationPresenter(&defaultNotificationPresenter); return profile; } |