OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "modules/notifications/ServiceWorkerRegistrationNotifications.h" | 6 #include "modules/notifications/ServiceWorkerRegistrationNotifications.h" |
7 | 7 |
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
11 #include "core/dom/ExecutionContext.h" | 11 #include "core/dom/ExecutionContext.h" |
12 #include "modules/notifications/GetNotificationOptions.h" | 12 #include "modules/notifications/GetNotificationOptions.h" |
13 #include "modules/notifications/Notification.h" | 13 #include "modules/notifications/Notification.h" |
14 #include "modules/notifications/NotificationData.h" | 14 #include "modules/notifications/NotificationData.h" |
15 #include "modules/notifications/NotificationOptions.h" | 15 #include "modules/notifications/NotificationOptions.h" |
| 16 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
16 #include "public/platform/Platform.h" | 17 #include "public/platform/Platform.h" |
17 #include "public/platform/WebSecurityOrigin.h" | 18 #include "public/platform/WebSecurityOrigin.h" |
18 #include "public/platform/modules/notifications/WebNotificationData.h" | 19 #include "public/platform/modules/notifications/WebNotificationData.h" |
19 #include "public/platform/modules/notifications/WebNotificationManager.h" | 20 #include "public/platform/modules/notifications/WebNotificationManager.h" |
20 #include "wtf/OwnPtr.h" | |
21 #include "wtf/PassOwnPtr.h" | |
22 | 21 |
23 namespace blink { | 22 namespace blink { |
24 namespace { | 23 namespace { |
25 | 24 |
26 // Allows using a CallbackPromiseAdapter with a WebVector to resolve the | 25 // Allows using a CallbackPromiseAdapter with a WebVector to resolve the |
27 // getNotifications() promise with a HeapVector owning Notifications. | 26 // getNotifications() promise with a HeapVector owning Notifications. |
28 class NotificationArray { | 27 class NotificationArray { |
29 public: | 28 public: |
30 using WebType = const WebVector<WebPersistentNotificationInfo>&; | 29 using WebType = const WebVector<WebPersistentNotificationInfo>&; |
31 | 30 |
32 static HeapVector<Member<Notification>> take(ScriptPromiseResolver* resolver
, const WebVector<WebPersistentNotificationInfo>& notificationInfos) | 31 static HeapVector<Member<Notification>> take(ScriptPromiseResolver* resolver
, const WebVector<WebPersistentNotificationInfo>& notificationInfos) |
33 { | 32 { |
34 HeapVector<Member<Notification>> notifications; | 33 HeapVector<Member<Notification>> notifications; |
35 for (const WebPersistentNotificationInfo& notificationInfo : notificatio
nInfos) | 34 for (const WebPersistentNotificationInfo& notificationInfo : notificatio
nInfos) |
36 notifications.append(Notification::create(resolver->executionContext
(), notificationInfo.persistentId, notificationInfo.data)); | 35 notifications.append(Notification::create(resolver->executionContext
(), notificationInfo.persistentId, notificationInfo.data)); |
| 36 |
37 return notifications; | 37 return notifications; |
38 } | 38 } |
39 | 39 |
40 private: | 40 private: |
41 NotificationArray() = delete; | 41 NotificationArray() = delete; |
42 }; | 42 }; |
43 | 43 |
44 } // namespace | 44 } // namespace |
45 | 45 |
46 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptSta
te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Str
ing& title, const NotificationOptions& options, ExceptionState& exceptionState) | 46 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptSta
te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Str
ing& title, const NotificationOptions& options, ExceptionState& exceptionState) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<Notifica
tionArray, void>(resolver); | 81 WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<Notifica
tionArray, void>(resolver); |
82 | 82 |
83 WebNotificationManager* notificationManager = Platform::current()->notificat
ionManager(); | 83 WebNotificationManager* notificationManager = Platform::current()->notificat
ionManager(); |
84 ASSERT(notificationManager); | 84 ASSERT(notificationManager); |
85 | 85 |
86 notificationManager->getNotifications(options.tag(), serviceWorkerRegistrati
on.webRegistration(), callbacks); | 86 notificationManager->getNotifications(options.tag(), serviceWorkerRegistrati
on.webRegistration(), callbacks); |
87 return promise; | 87 return promise; |
88 } | 88 } |
89 | 89 |
90 } // namespace blink | 90 } // namespace blink |
OLD | NEW |