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 "modules/notifications/ServiceWorkerRegistrationNotifications.h" | 5 #include "modules/notifications/ServiceWorkerRegistrationNotifications.h" |
6 | 6 |
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
10 #include "core/dom/ExecutionContext.h" | 10 #include "core/dom/ExecutionContext.h" |
11 #include "modules/notifications/GetNotificationOptions.h" | 11 #include "modules/notifications/GetNotificationOptions.h" |
12 #include "modules/notifications/Notification.h" | 12 #include "modules/notifications/Notification.h" |
13 #include "modules/notifications/NotificationData.h" | 13 #include "modules/notifications/NotificationData.h" |
14 #include "modules/notifications/NotificationManager.h" | 14 #include "modules/notifications/NotificationManager.h" |
15 #include "modules/notifications/NotificationOptions.h" | 15 #include "modules/notifications/NotificationOptions.h" |
16 #include "modules/notifications/NotificationResourcesLoader.h" | 16 #include "modules/notifications/NotificationResourcesLoader.h" |
17 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | 17 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
18 #include "platform/Histogram.h" | 18 #include "platform/Histogram.h" |
19 #include "platform/heap/Handle.h" | 19 #include "platform/heap/Handle.h" |
20 #include "public/platform/Platform.h" | 20 #include "public/platform/Platform.h" |
21 #include "public/platform/WebSecurityOrigin.h" | 21 #include "public/platform/WebSecurityOrigin.h" |
22 #include "public/platform/modules/notifications/WebNotificationData.h" | 22 #include "public/platform/modules/notifications/WebNotificationData.h" |
23 #include "wtf/Assertions.h" | 23 #include "wtf/Assertions.h" |
24 #include "wtf/PtrUtil.h" | 24 #include "wtf/PtrUtil.h" |
25 #include "wtf/RefPtr.h" | 25 #include "wtf/RefPtr.h" |
26 #include <memory> | 26 #include <memory> |
| 27 #include <utility> |
27 | 28 |
28 namespace blink { | 29 namespace blink { |
29 namespace { | 30 namespace { |
30 | 31 |
31 // Allows using a CallbackPromiseAdapter with a WebVector to resolve the | 32 // Allows using a CallbackPromiseAdapter with a WebVector to resolve the |
32 // getNotifications() promise with a HeapVector owning Notifications. | 33 // getNotifications() promise with a HeapVector owning Notifications. |
33 class NotificationArray { | 34 class NotificationArray { |
34 public: | 35 public: |
35 using WebType = const WebVector<WebPersistentNotificationInfo>&; | 36 using WebType = const WebVector<WebPersistentNotificationInfo>&; |
36 | 37 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 return promise; | 114 return promise; |
114 } | 115 } |
115 | 116 |
116 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications( | 117 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications( |
117 ScriptState* scriptState, | 118 ScriptState* scriptState, |
118 ServiceWorkerRegistration& registration, | 119 ServiceWorkerRegistration& registration, |
119 const GetNotificationOptions& options) { | 120 const GetNotificationOptions& options) { |
120 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 121 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
121 ScriptPromise promise = resolver->promise(); | 122 ScriptPromise promise = resolver->promise(); |
122 | 123 |
123 WebNotificationGetCallbacks* callbacks = | 124 auto callbacks = |
124 new CallbackPromiseAdapter<NotificationArray, void>(resolver); | 125 WTF::makeUnique<CallbackPromiseAdapter<NotificationArray, void>>( |
| 126 resolver); |
125 | 127 |
126 WebNotificationManager* notificationManager = | 128 WebNotificationManager* notificationManager = |
127 Platform::current()->notificationManager(); | 129 Platform::current()->notificationManager(); |
128 DCHECK(notificationManager); | 130 DCHECK(notificationManager); |
129 | 131 |
130 notificationManager->getNotifications( | 132 notificationManager->getNotifications( |
131 options.tag(), registration.webRegistration(), callbacks); | 133 options.tag(), registration.webRegistration(), std::move(callbacks)); |
132 return promise; | 134 return promise; |
133 } | 135 } |
134 | 136 |
135 void ServiceWorkerRegistrationNotifications::contextDestroyed() { | 137 void ServiceWorkerRegistrationNotifications::contextDestroyed() { |
136 for (auto loader : m_loaders) | 138 for (auto loader : m_loaders) |
137 loader->stop(); | 139 loader->stop(); |
138 } | 140 } |
139 | 141 |
140 DEFINE_TRACE(ServiceWorkerRegistrationNotifications) { | 142 DEFINE_TRACE(ServiceWorkerRegistrationNotifications) { |
141 visitor->trace(m_registration); | 143 visitor->trace(m_registration); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 std::unique_ptr<WebNotificationShowCallbacks> callbacks, | 184 std::unique_ptr<WebNotificationShowCallbacks> callbacks, |
183 NotificationResourcesLoader* loader) { | 185 NotificationResourcesLoader* loader) { |
184 DCHECK(m_loaders.contains(loader)); | 186 DCHECK(m_loaders.contains(loader)); |
185 | 187 |
186 WebNotificationManager* notificationManager = | 188 WebNotificationManager* notificationManager = |
187 Platform::current()->notificationManager(); | 189 Platform::current()->notificationManager(); |
188 DCHECK(notificationManager); | 190 DCHECK(notificationManager); |
189 | 191 |
190 notificationManager->showPersistent( | 192 notificationManager->showPersistent( |
191 WebSecurityOrigin(origin.get()), data, loader->getResources(), | 193 WebSecurityOrigin(origin.get()), data, loader->getResources(), |
192 m_registration->webRegistration(), callbacks.release()); | 194 m_registration->webRegistration(), std::move(callbacks)); |
193 m_loaders.remove(loader); | 195 m_loaders.remove(loader); |
194 } | 196 } |
195 | 197 |
196 } // namespace blink | 198 } // namespace blink |
OLD | NEW |