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

Side by Side Diff: Source/modules/serviceworkers/ServiceWorkerContainer.cpp

Issue 723923002: ServiceWorker: Add support for .skipWaiting and controllerchange event(1/3) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: webcallback->skipwaitingcallbacks, test re-write Created 6 years 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 23 matching lines...) Expand all
34 #include "bindings/core/v8/ScriptPromise.h" 34 #include "bindings/core/v8/ScriptPromise.h"
35 #include "bindings/core/v8/ScriptPromiseResolver.h" 35 #include "bindings/core/v8/ScriptPromiseResolver.h"
36 #include "bindings/core/v8/ScriptState.h" 36 #include "bindings/core/v8/ScriptState.h"
37 #include "bindings/core/v8/SerializedScriptValue.h" 37 #include "bindings/core/v8/SerializedScriptValue.h"
38 #include "core/dom/DOMException.h" 38 #include "core/dom/DOMException.h"
39 #include "core/dom/ExceptionCode.h" 39 #include "core/dom/ExceptionCode.h"
40 #include "core/dom/ExecutionContext.h" 40 #include "core/dom/ExecutionContext.h"
41 #include "core/dom/MessagePort.h" 41 #include "core/dom/MessagePort.h"
42 #include "core/events/MessageEvent.h" 42 #include "core/events/MessageEvent.h"
43 #include "core/frame/LocalDOMWindow.h" 43 #include "core/frame/LocalDOMWindow.h"
44 #include "modules/EventTargetModules.h"
44 #include "modules/serviceworkers/ServiceWorker.h" 45 #include "modules/serviceworkers/ServiceWorker.h"
45 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" 46 #include "modules/serviceworkers/ServiceWorkerContainerClient.h"
46 #include "modules/serviceworkers/ServiceWorkerError.h" 47 #include "modules/serviceworkers/ServiceWorkerError.h"
47 #include "modules/serviceworkers/ServiceWorkerRegistration.h" 48 #include "modules/serviceworkers/ServiceWorkerRegistration.h"
48 #include "platform/RuntimeEnabledFeatures.h" 49 #include "platform/RuntimeEnabledFeatures.h"
49 #include "public/platform/WebServiceWorker.h" 50 #include "public/platform/WebServiceWorker.h"
50 #include "public/platform/WebServiceWorkerProvider.h" 51 #include "public/platform/WebServiceWorkerProvider.h"
51 #include "public/platform/WebServiceWorkerRegistration.h" 52 #include "public/platform/WebServiceWorkerRegistration.h"
52 #include "public/platform/WebString.h" 53 #include "public/platform/WebString.h"
53 #include "public/platform/WebURL.h" 54 #include "public/platform/WebURL.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 m_provider->setClient(0); 93 m_provider->setClient(0);
93 m_provider = nullptr; 94 m_provider = nullptr;
94 } 95 }
95 } 96 }
96 97
97 void ServiceWorkerContainer::trace(Visitor* visitor) 98 void ServiceWorkerContainer::trace(Visitor* visitor)
98 { 99 {
99 visitor->trace(m_controller); 100 visitor->trace(m_controller);
100 visitor->trace(m_readyRegistration); 101 visitor->trace(m_readyRegistration);
101 visitor->trace(m_ready); 102 visitor->trace(m_ready);
103 EventTargetWithInlineData::trace(visitor);
104 HeapSupplementable<ServiceWorkerContainer>::trace(visitor);
102 } 105 }
103 106
104 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptS tate, const String& url, const RegistrationOptions& options) 107 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptS tate, const String& url, const RegistrationOptions& options)
105 { 108 {
106 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); 109 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled());
107 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); 110 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
108 ScriptPromise promise = resolver->promise(); 111 ScriptPromise promise = resolver->promise();
109 112
110 if (!m_provider) { 113 if (!m_provider) {
111 resolver->reject(DOMException::create(InvalidStateError, "The document i s in an invalid state.")); 114 resolver->reject(DOMException::create(InvalidStateError, "The document i s in an invalid state."));
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 227
225 // If the WebServiceWorker is up for adoption (does not have a 228 // If the WebServiceWorker is up for adoption (does not have a
226 // WebServiceWorkerProxy owner), rejects the adoption by deleting the 229 // WebServiceWorkerProxy owner), rejects the adoption by deleting the
227 // WebServiceWorker. 230 // WebServiceWorker.
228 static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker) 231 static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker)
229 { 232 {
230 if (serviceWorker && !serviceWorker->proxy()) 233 if (serviceWorker && !serviceWorker->proxy())
231 delete serviceWorker; 234 delete serviceWorker;
232 } 235 }
233 236
234 void ServiceWorkerContainer::setController(WebServiceWorker* serviceWorker) 237 void ServiceWorkerContainer::setController(WebServiceWorker* serviceWorker, bool shouldNotifyControllerChange)
235 { 238 {
236 if (!executionContext()) { 239 if (!executionContext()) {
237 deleteIfNoExistingOwner(serviceWorker); 240 deleteIfNoExistingOwner(serviceWorker);
238 return; 241 return;
239 } 242 }
240 m_controller = ServiceWorker::from(executionContext(), serviceWorker); 243 m_controller = ServiceWorker::from(executionContext(), serviceWorker);
244 if (shouldNotifyControllerChange)
245 dispatchEvent(Event::create(EventTypeNames::controllerchange));
241 } 246 }
242 247
243 void ServiceWorkerContainer::setReadyRegistration(WebServiceWorkerRegistration* registration) 248 void ServiceWorkerContainer::setReadyRegistration(WebServiceWorkerRegistration* registration)
244 { 249 {
245 if (!executionContext()) { 250 if (!executionContext()) {
246 ServiceWorkerRegistration::dispose(registration); 251 ServiceWorkerRegistration::dispose(registration);
247 return; 252 return;
248 } 253 }
249 254
250 ServiceWorkerRegistration* readyRegistration = ServiceWorkerRegistration::fr om(executionContext(), registration); 255 ServiceWorkerRegistration* readyRegistration = ServiceWorkerRegistration::fr om(executionContext(), registration);
(...skipping 12 matching lines...) Expand all
263 void ServiceWorkerContainer::dispatchMessageEvent(const WebString& message, cons t WebMessagePortChannelArray& webChannels) 268 void ServiceWorkerContainer::dispatchMessageEvent(const WebString& message, cons t WebMessagePortChannelArray& webChannels)
264 { 269 {
265 if (!executionContext() || !executionContext()->executingWindow()) 270 if (!executionContext() || !executionContext()->executingWindow())
266 return; 271 return;
267 272
268 OwnPtrWillBeRawPtr<MessagePortArray> ports = MessagePort::toMessagePortArray (executionContext(), webChannels); 273 OwnPtrWillBeRawPtr<MessagePortArray> ports = MessagePort::toMessagePortArray (executionContext(), webChannels);
269 RefPtr<SerializedScriptValue> value = SerializedScriptValue::createFromWire( message); 274 RefPtr<SerializedScriptValue> value = SerializedScriptValue::createFromWire( message);
270 executionContext()->executingWindow()->dispatchEvent(MessageEvent::create(po rts.release(), value)); 275 executionContext()->executingWindow()->dispatchEvent(MessageEvent::create(po rts.release(), value));
271 } 276 }
272 277
278 const AtomicString& ServiceWorkerContainer::interfaceName() const
279 {
280 return EventTargetNames::ServiceWorkerContainer;
281 }
282
273 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex t) 283 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex t)
274 : ContextLifecycleObserver(executionContext) 284 : ContextLifecycleObserver(executionContext)
275 , m_provider(0) 285 , m_provider(0)
276 { 286 {
277 287
278 if (!executionContext) 288 if (!executionContext)
279 return; 289 return;
280 290
281 m_ready = createReadyProperty(); 291 m_ready = createReadyProperty();
282 292
283 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) { 293 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) {
284 m_provider = client->provider(); 294 m_provider = client->provider();
285 if (m_provider) 295 if (m_provider)
286 m_provider->setClient(this); 296 m_provider->setClient(this);
287 } 297 }
288 } 298 }
289 299
290 } // namespace blink 300 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698