| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 return notifications; | 48 return notifications; |
| 49 } | 49 } |
| 50 | 50 |
| 51 private: | 51 private: |
| 52 NotificationArray() = delete; | 52 NotificationArray() = delete; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 ServiceWorkerRegistrationNotifications::ServiceWorkerRegistrationNotifications( | 57 ServiceWorkerRegistrationNotifications::ServiceWorkerRegistrationNotifications( |
| 58 ExecutionContext* executionContext, | 58 ServiceWorkerRegistration& registration, |
| 59 ServiceWorkerRegistration* registration) | 59 ExecutionContext* executionContext) |
| 60 : ContextLifecycleObserver(executionContext), | 60 : Supplement<ServiceWorkerRegistration>(registration), |
| 61 m_registration(registration) {} | 61 ContextLifecycleObserver(executionContext) {} |
| 62 | 62 |
| 63 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification( | 63 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification( |
| 64 ScriptState* scriptState, | 64 ScriptState* scriptState, |
| 65 ServiceWorkerRegistration& registration, | 65 ServiceWorkerRegistration& registration, |
| 66 const String& title, | 66 const String& title, |
| 67 const NotificationOptions& options, | 67 const NotificationOptions& options, |
| 68 ExceptionState& exceptionState) { | 68 ExceptionState& exceptionState) { |
| 69 ExecutionContext* executionContext = scriptState->getExecutionContext(); | 69 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 70 | 70 |
| 71 // If context object's active worker is null, reject the promise with a | 71 // If context object's active worker is null, reject the promise with a |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 return promise; | 135 return promise; |
| 136 } | 136 } |
| 137 | 137 |
| 138 void ServiceWorkerRegistrationNotifications::contextDestroyed( | 138 void ServiceWorkerRegistrationNotifications::contextDestroyed( |
| 139 ExecutionContext*) { | 139 ExecutionContext*) { |
| 140 for (auto loader : m_loaders) | 140 for (auto loader : m_loaders) |
| 141 loader->stop(); | 141 loader->stop(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 DEFINE_TRACE(ServiceWorkerRegistrationNotifications) { | 144 DEFINE_TRACE(ServiceWorkerRegistrationNotifications) { |
| 145 visitor->trace(m_registration); | |
| 146 visitor->trace(m_loaders); | 145 visitor->trace(m_loaders); |
| 147 Supplement<ServiceWorkerRegistration>::trace(visitor); | 146 Supplement<ServiceWorkerRegistration>::trace(visitor); |
| 148 ContextLifecycleObserver::trace(visitor); | 147 ContextLifecycleObserver::trace(visitor); |
| 149 } | 148 } |
| 150 | 149 |
| 151 const char* ServiceWorkerRegistrationNotifications::supplementName() { | 150 const char* ServiceWorkerRegistrationNotifications::supplementName() { |
| 152 return "ServiceWorkerRegistrationNotifications"; | 151 return "ServiceWorkerRegistrationNotifications"; |
| 153 } | 152 } |
| 154 | 153 |
| 155 ServiceWorkerRegistrationNotifications& | 154 ServiceWorkerRegistrationNotifications& |
| 156 ServiceWorkerRegistrationNotifications::from( | 155 ServiceWorkerRegistrationNotifications::from( |
| 157 ExecutionContext* executionContext, | 156 ExecutionContext* executionContext, |
| 158 ServiceWorkerRegistration& registration) { | 157 ServiceWorkerRegistration& registration) { |
| 159 ServiceWorkerRegistrationNotifications* supplement = | 158 ServiceWorkerRegistrationNotifications* supplement = |
| 160 static_cast<ServiceWorkerRegistrationNotifications*>( | 159 static_cast<ServiceWorkerRegistrationNotifications*>( |
| 161 Supplement<ServiceWorkerRegistration>::from(registration, | 160 Supplement<ServiceWorkerRegistration>::from(registration, |
| 162 supplementName())); | 161 supplementName())); |
| 163 if (!supplement) { | 162 if (!supplement) { |
| 164 supplement = new ServiceWorkerRegistrationNotifications(executionContext, | 163 supplement = new ServiceWorkerRegistrationNotifications(registration, |
| 165 ®istration); | 164 executionContext); |
| 166 provideTo(registration, supplementName(), supplement); | 165 provideTo(registration, supplementName(), supplement); |
| 167 } | 166 } |
| 168 return *supplement; | 167 return *supplement; |
| 169 } | 168 } |
| 170 | 169 |
| 171 void ServiceWorkerRegistrationNotifications::prepareShow( | 170 void ServiceWorkerRegistrationNotifications::prepareShow( |
| 172 const WebNotificationData& data, | 171 const WebNotificationData& data, |
| 173 std::unique_ptr<WebNotificationShowCallbacks> callbacks) { | 172 std::unique_ptr<WebNotificationShowCallbacks> callbacks) { |
| 174 RefPtr<SecurityOrigin> origin = getExecutionContext()->getSecurityOrigin(); | 173 RefPtr<SecurityOrigin> origin = getExecutionContext()->getSecurityOrigin(); |
| 175 NotificationResourcesLoader* loader = new NotificationResourcesLoader( | 174 NotificationResourcesLoader* loader = new NotificationResourcesLoader( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 186 std::unique_ptr<WebNotificationShowCallbacks> callbacks, | 185 std::unique_ptr<WebNotificationShowCallbacks> callbacks, |
| 187 NotificationResourcesLoader* loader) { | 186 NotificationResourcesLoader* loader) { |
| 188 DCHECK(m_loaders.contains(loader)); | 187 DCHECK(m_loaders.contains(loader)); |
| 189 | 188 |
| 190 WebNotificationManager* notificationManager = | 189 WebNotificationManager* notificationManager = |
| 191 Platform::current()->notificationManager(); | 190 Platform::current()->notificationManager(); |
| 192 DCHECK(notificationManager); | 191 DCHECK(notificationManager); |
| 193 | 192 |
| 194 notificationManager->showPersistent( | 193 notificationManager->showPersistent( |
| 195 WebSecurityOrigin(origin.get()), data, loader->getResources(), | 194 WebSecurityOrigin(origin.get()), data, loader->getResources(), |
| 196 m_registration->webRegistration(), std::move(callbacks)); | 195 supplementable()->webRegistration(), std::move(callbacks)); |
| 197 m_loaders.remove(loader); | 196 m_loaders.remove(loader); |
| 198 } | 197 } |
| 199 | 198 |
| 200 } // namespace blink | 199 } // namespace blink |
| OLD | NEW |