Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: third_party/WebKit/Source/modules/notifications/ServiceWorkerRegistrationNotifications.cpp

Issue 2686613004: Revert of Use a new Supplement constructor for ServiceWorkerRegistration supplements (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 ServiceWorkerRegistration& registration, 58 ExecutionContext* executionContext,
59 ExecutionContext* executionContext) 59 ServiceWorkerRegistration* registration)
60 : Supplement<ServiceWorkerRegistration>(registration), 60 : ContextLifecycleObserver(executionContext),
61 ContextLifecycleObserver(executionContext) {} 61 m_registration(registration) {}
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
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);
145 visitor->trace(m_loaders); 146 visitor->trace(m_loaders);
146 Supplement<ServiceWorkerRegistration>::trace(visitor); 147 Supplement<ServiceWorkerRegistration>::trace(visitor);
147 ContextLifecycleObserver::trace(visitor); 148 ContextLifecycleObserver::trace(visitor);
148 } 149 }
149 150
150 const char* ServiceWorkerRegistrationNotifications::supplementName() { 151 const char* ServiceWorkerRegistrationNotifications::supplementName() {
151 return "ServiceWorkerRegistrationNotifications"; 152 return "ServiceWorkerRegistrationNotifications";
152 } 153 }
153 154
154 ServiceWorkerRegistrationNotifications& 155 ServiceWorkerRegistrationNotifications&
155 ServiceWorkerRegistrationNotifications::from( 156 ServiceWorkerRegistrationNotifications::from(
156 ExecutionContext* executionContext, 157 ExecutionContext* executionContext,
157 ServiceWorkerRegistration& registration) { 158 ServiceWorkerRegistration& registration) {
158 ServiceWorkerRegistrationNotifications* supplement = 159 ServiceWorkerRegistrationNotifications* supplement =
159 static_cast<ServiceWorkerRegistrationNotifications*>( 160 static_cast<ServiceWorkerRegistrationNotifications*>(
160 Supplement<ServiceWorkerRegistration>::from(registration, 161 Supplement<ServiceWorkerRegistration>::from(registration,
161 supplementName())); 162 supplementName()));
162 if (!supplement) { 163 if (!supplement) {
163 supplement = new ServiceWorkerRegistrationNotifications(registration, 164 supplement = new ServiceWorkerRegistrationNotifications(executionContext,
164 executionContext); 165 &registration);
165 provideTo(registration, supplementName(), supplement); 166 provideTo(registration, supplementName(), supplement);
166 } 167 }
167 return *supplement; 168 return *supplement;
168 } 169 }
169 170
170 void ServiceWorkerRegistrationNotifications::prepareShow( 171 void ServiceWorkerRegistrationNotifications::prepareShow(
171 const WebNotificationData& data, 172 const WebNotificationData& data,
172 std::unique_ptr<WebNotificationShowCallbacks> callbacks) { 173 std::unique_ptr<WebNotificationShowCallbacks> callbacks) {
173 RefPtr<SecurityOrigin> origin = getExecutionContext()->getSecurityOrigin(); 174 RefPtr<SecurityOrigin> origin = getExecutionContext()->getSecurityOrigin();
174 NotificationResourcesLoader* loader = new NotificationResourcesLoader( 175 NotificationResourcesLoader* loader = new NotificationResourcesLoader(
(...skipping 10 matching lines...) Expand all
185 std::unique_ptr<WebNotificationShowCallbacks> callbacks, 186 std::unique_ptr<WebNotificationShowCallbacks> callbacks,
186 NotificationResourcesLoader* loader) { 187 NotificationResourcesLoader* loader) {
187 DCHECK(m_loaders.contains(loader)); 188 DCHECK(m_loaders.contains(loader));
188 189
189 WebNotificationManager* notificationManager = 190 WebNotificationManager* notificationManager =
190 Platform::current()->notificationManager(); 191 Platform::current()->notificationManager();
191 DCHECK(notificationManager); 192 DCHECK(notificationManager);
192 193
193 notificationManager->showPersistent( 194 notificationManager->showPersistent(
194 WebSecurityOrigin(origin.get()), data, loader->getResources(), 195 WebSecurityOrigin(origin.get()), data, loader->getResources(),
195 supplementable()->webRegistration(), std::move(callbacks)); 196 m_registration->webRegistration(), std::move(callbacks));
196 m_loaders.remove(loader); 197 m_loaders.remove(loader);
197 } 198 }
198 199
199 } // namespace blink 200 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698