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" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 101 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
102 EnumerationHistogram, notificationCountHistogram, | 102 EnumerationHistogram, notificationCountHistogram, |
103 new EnumerationHistogram( | 103 new EnumerationHistogram( |
104 "Notifications.PersistentNotificationActionCount", 17)); | 104 "Notifications.PersistentNotificationActionCount", 17)); |
105 notificationCountHistogram.count(options.actions().size()); | 105 notificationCountHistogram.count(options.actions().size()); |
106 | 106 |
107 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 107 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
108 ScriptPromise promise = resolver->promise(); | 108 ScriptPromise promise = resolver->promise(); |
109 | 109 |
110 std::unique_ptr<WebNotificationShowCallbacks> callbacks = | 110 std::unique_ptr<WebNotificationShowCallbacks> callbacks = |
111 wrapUnique(new CallbackPromiseAdapter<void, void>(resolver)); | 111 WTF::wrapUnique(new CallbackPromiseAdapter<void, void>(resolver)); |
112 ServiceWorkerRegistrationNotifications::from(executionContext, registration) | 112 ServiceWorkerRegistrationNotifications::from(executionContext, registration) |
113 .prepareShow(data, std::move(callbacks)); | 113 .prepareShow(data, std::move(callbacks)); |
114 | 114 |
115 return promise; | 115 return promise; |
116 } | 116 } |
117 | 117 |
118 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications( | 118 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications( |
119 ScriptState* scriptState, | 119 ScriptState* scriptState, |
120 ServiceWorkerRegistration& registration, | 120 ServiceWorkerRegistration& registration, |
121 const GetNotificationOptions& options) { | 121 const GetNotificationOptions& options) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 return *supplement; | 167 return *supplement; |
168 } | 168 } |
169 | 169 |
170 void ServiceWorkerRegistrationNotifications::prepareShow( | 170 void ServiceWorkerRegistrationNotifications::prepareShow( |
171 const WebNotificationData& data, | 171 const WebNotificationData& data, |
172 std::unique_ptr<WebNotificationShowCallbacks> callbacks) { | 172 std::unique_ptr<WebNotificationShowCallbacks> callbacks) { |
173 RefPtr<SecurityOrigin> origin = getExecutionContext()->getSecurityOrigin(); | 173 RefPtr<SecurityOrigin> origin = getExecutionContext()->getSecurityOrigin(); |
174 NotificationResourcesLoader* loader = new NotificationResourcesLoader( | 174 NotificationResourcesLoader* loader = new NotificationResourcesLoader( |
175 WTF::bind(&ServiceWorkerRegistrationNotifications::didLoadResources, | 175 WTF::bind(&ServiceWorkerRegistrationNotifications::didLoadResources, |
176 wrapWeakPersistent(this), origin.release(), data, | 176 wrapWeakPersistent(this), origin.release(), data, |
177 passed(std::move(callbacks)))); | 177 WTF::passed(std::move(callbacks)))); |
178 m_loaders.add(loader); | 178 m_loaders.add(loader); |
179 loader->start(getExecutionContext(), data); | 179 loader->start(getExecutionContext(), data); |
180 } | 180 } |
181 | 181 |
182 void ServiceWorkerRegistrationNotifications::didLoadResources( | 182 void ServiceWorkerRegistrationNotifications::didLoadResources( |
183 PassRefPtr<SecurityOrigin> origin, | 183 PassRefPtr<SecurityOrigin> origin, |
184 const WebNotificationData& data, | 184 const WebNotificationData& data, |
185 std::unique_ptr<WebNotificationShowCallbacks> callbacks, | 185 std::unique_ptr<WebNotificationShowCallbacks> callbacks, |
186 NotificationResourcesLoader* loader) { | 186 NotificationResourcesLoader* loader) { |
187 DCHECK(m_loaders.contains(loader)); | 187 DCHECK(m_loaders.contains(loader)); |
188 | 188 |
189 WebNotificationManager* notificationManager = | 189 WebNotificationManager* notificationManager = |
190 Platform::current()->notificationManager(); | 190 Platform::current()->notificationManager(); |
191 DCHECK(notificationManager); | 191 DCHECK(notificationManager); |
192 | 192 |
193 notificationManager->showPersistent( | 193 notificationManager->showPersistent( |
194 WebSecurityOrigin(origin.get()), data, loader->getResources(), | 194 WebSecurityOrigin(origin.get()), data, loader->getResources(), |
195 m_registration->webRegistration(), std::move(callbacks)); | 195 m_registration->webRegistration(), std::move(callbacks)); |
196 m_loaders.remove(loader); | 196 m_loaders.remove(loader); |
197 } | 197 } |
198 | 198 |
199 } // namespace blink | 199 } // namespace blink |
OLD | NEW |