Chromium Code Reviews| Index: Source/modules/notifications/ServiceWorkerRegistrationNotifications.cpp |
| diff --git a/Source/modules/notifications/ServiceWorkerRegistrationNotifications.cpp b/Source/modules/notifications/ServiceWorkerRegistrationNotifications.cpp |
| index 5249eb6fd59f2ed731d42c434739475fe740b76f..bd11847f1595088fe071113d36aff3428622acf6 100644 |
| --- a/Source/modules/notifications/ServiceWorkerRegistrationNotifications.cpp |
| +++ b/Source/modules/notifications/ServiceWorkerRegistrationNotifications.cpp |
| @@ -14,6 +14,7 @@ |
| #include "core/dom/DOMException.h" |
| #include "core/dom/ExceptionCode.h" |
| #include "core/dom/ExecutionContext.h" |
| +#include "modules/notifications/GetNotificationOptions.h" |
| #include "modules/notifications/Notification.h" |
| #include "modules/notifications/NotificationOptions.h" |
| #include "platform/weborigin/KURL.h" |
| @@ -23,6 +24,37 @@ |
| #include "public/platform/modules/notifications/WebNotificationManager.h" |
| namespace blink { |
| +namespace { |
| + |
| +// Allows using a CallbackPromiseAdapter with a WebVector to resolve the |
| +// getNotifications() promise with a HeapVector owning Notifications. |
| +class NotificationArray { |
| +public: |
| + using WebType = WebVector<WebPersistentNotificationInfo>; |
| + |
| + static HeapVector<Member<Notification>> take(ScriptPromiseResolver* resolver, WebType* notificationInfosRaw) |
| + { |
| + OwnPtr<WebType> notificationInfos = adoptPtr(notificationInfosRaw); |
| + HeapVector<Member<Notification>> notifications; |
| + |
| + for (size_t i = 0; i < notificationInfos->size(); ++i) { |
| + const WebPersistentNotificationInfo& notificationInfo = (*notificationInfos)[i]; |
|
johnme
2015/03/17 19:39:35
Nit - how about:
for (const WebPersistentNotifica
Peter Beverloo
2015/03/19 15:43:07
I waited and applied it :-). Thanks!
|
| + notifications.append(Notification::create(resolver->executionContext(), notificationInfo.persistentNotificationId, notificationInfo.data)); |
| + } |
| + |
| + return notifications; |
| + } |
| + |
| + static void dispose(WebType* notificationInfosRaw) |
| + { |
| + delete notificationInfosRaw; |
|
haraken
2015/03/18 01:32:54
I don't fully understand why we need to take a raw
Peter Beverloo
2015/03/19 15:43:07
In some cases the CallbackPromiseAdapter is used t
|
| + } |
| + |
| +private: |
| + NotificationArray() = delete; |
| +}; |
| + |
| +} // namespace |
| ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptState* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const String& title, const NotificationOptions& options, ExceptionState& exceptionState) |
| { |
| @@ -71,4 +103,21 @@ ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptSta |
| return promise; |
| } |
| +ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptState* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const GetNotificationOptions& options) |
| +{ |
| + RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); |
| + ScriptPromise promise = resolver->promise(); |
| + |
| + SecurityOrigin* origin = scriptState->executionContext()->securityOrigin(); |
| + ASSERT(origin); |
| + |
| + WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<NotificationArray, void>(resolver); |
| + |
| + WebNotificationManager* notificationManager = Platform::current()->notificationManager(); |
| + ASSERT(notificationManager); |
| + |
| + notificationManager->getNotifications(options.tag(), serviceWorkerRegistration.webRegistration(), callbacks); |
| + return promise; |
| +} |
| + |
| } // namespace blink |