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

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: split the CL 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 24 matching lines...) Expand all
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 "bindings/core/v8/SerializedScriptValueFactory.h" 38 #include "bindings/core/v8/SerializedScriptValueFactory.h"
39 #include "core/dom/DOMException.h" 39 #include "core/dom/DOMException.h"
40 #include "core/dom/ExceptionCode.h" 40 #include "core/dom/ExceptionCode.h"
41 #include "core/dom/ExecutionContext.h" 41 #include "core/dom/ExecutionContext.h"
42 #include "core/dom/MessagePort.h" 42 #include "core/dom/MessagePort.h"
43 #include "core/events/MessageEvent.h" 43 #include "core/events/MessageEvent.h"
44 #include "core/frame/LocalDOMWindow.h" 44 #include "core/frame/LocalDOMWindow.h"
45 #include "modules/EventTargetModules.h"
45 #include "modules/serviceworkers/ServiceWorker.h" 46 #include "modules/serviceworkers/ServiceWorker.h"
46 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" 47 #include "modules/serviceworkers/ServiceWorkerContainerClient.h"
47 #include "modules/serviceworkers/ServiceWorkerError.h" 48 #include "modules/serviceworkers/ServiceWorkerError.h"
48 #include "modules/serviceworkers/ServiceWorkerRegistration.h" 49 #include "modules/serviceworkers/ServiceWorkerRegistration.h"
49 #include "platform/RuntimeEnabledFeatures.h" 50 #include "platform/RuntimeEnabledFeatures.h"
50 #include "public/platform/WebServiceWorker.h" 51 #include "public/platform/WebServiceWorker.h"
51 #include "public/platform/WebServiceWorkerProvider.h" 52 #include "public/platform/WebServiceWorkerProvider.h"
52 #include "public/platform/WebServiceWorkerRegistration.h" 53 #include "public/platform/WebServiceWorkerRegistration.h"
53 #include "public/platform/WebString.h" 54 #include "public/platform/WebString.h"
54 #include "public/platform/WebURL.h" 55 #include "public/platform/WebURL.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 m_provider->setClient(0); 94 m_provider->setClient(0);
94 m_provider = nullptr; 95 m_provider = nullptr;
95 } 96 }
96 } 97 }
97 98
98 void ServiceWorkerContainer::trace(Visitor* visitor) 99 void ServiceWorkerContainer::trace(Visitor* visitor)
99 { 100 {
100 visitor->trace(m_controller); 101 visitor->trace(m_controller);
101 visitor->trace(m_readyRegistration); 102 visitor->trace(m_readyRegistration);
102 visitor->trace(m_ready); 103 visitor->trace(m_ready);
104 EventTargetWithInlineData::trace(visitor);
105 HeapSupplementable<ServiceWorkerContainer>::trace(visitor);
103 } 106 }
104 107
105 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptS tate, const String& url, const RegistrationOptions& options) 108 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptS tate, const String& url, const RegistrationOptions& options)
106 { 109 {
107 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); 110 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled());
108 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); 111 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
109 ScriptPromise promise = resolver->promise(); 112 ScriptPromise promise = resolver->promise();
110 113
111 if (!m_provider) { 114 if (!m_provider) {
112 resolver->reject(DOMException::create(InvalidStateError, "The document i s in an invalid state.")); 115 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
225 228
226 // If the WebServiceWorker is up for adoption (does not have a 229 // If the WebServiceWorker is up for adoption (does not have a
227 // WebServiceWorkerProxy owner), rejects the adoption by deleting the 230 // WebServiceWorkerProxy owner), rejects the adoption by deleting the
228 // WebServiceWorker. 231 // WebServiceWorker.
229 static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker) 232 static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker)
230 { 233 {
231 if (serviceWorker && !serviceWorker->proxy()) 234 if (serviceWorker && !serviceWorker->proxy())
232 delete serviceWorker; 235 delete serviceWorker;
233 } 236 }
234 237
235 void ServiceWorkerContainer::setController(WebServiceWorker* serviceWorker) 238 void ServiceWorkerContainer::setController(WebServiceWorker* serviceWorker, bool shouldNotifyControllerChange)
236 { 239 {
237 if (!executionContext()) { 240 if (!executionContext()) {
238 deleteIfNoExistingOwner(serviceWorker); 241 deleteIfNoExistingOwner(serviceWorker);
239 return; 242 return;
240 } 243 }
241 m_controller = ServiceWorker::from(executionContext(), serviceWorker); 244 m_controller = ServiceWorker::from(executionContext(), serviceWorker);
245 if (shouldNotifyControllerChange)
246 dispatchEvent(Event::create(EventTypeNames::controllerchange));
tkent 2014/12/01 07:57:13 Is it possible to cause use-after-free by JavaScri
xiang 2014/12/02 02:31:48 I don't know in which case the event object will b
tkent 2014/12/02 02:37:07 A web page can run any JavaScript code as a |contr
242 } 247 }
243 248
244 void ServiceWorkerContainer::setReadyRegistration(WebServiceWorkerRegistration* registration) 249 void ServiceWorkerContainer::setReadyRegistration(WebServiceWorkerRegistration* registration)
245 { 250 {
246 if (!executionContext()) { 251 if (!executionContext()) {
247 ServiceWorkerRegistration::dispose(registration); 252 ServiceWorkerRegistration::dispose(registration);
248 return; 253 return;
249 } 254 }
250 255
251 ServiceWorkerRegistration* readyRegistration = ServiceWorkerRegistration::fr om(executionContext(), registration); 256 ServiceWorkerRegistration* readyRegistration = ServiceWorkerRegistration::fr om(executionContext(), registration);
(...skipping 12 matching lines...) Expand all
264 void ServiceWorkerContainer::dispatchMessageEvent(const WebString& message, cons t WebMessagePortChannelArray& webChannels) 269 void ServiceWorkerContainer::dispatchMessageEvent(const WebString& message, cons t WebMessagePortChannelArray& webChannels)
265 { 270 {
266 if (!executionContext() || !executionContext()->executingWindow()) 271 if (!executionContext() || !executionContext()->executingWindow())
267 return; 272 return;
268 273
269 OwnPtrWillBeRawPtr<MessagePortArray> ports = MessagePort::toMessagePortArray (executionContext(), webChannels); 274 OwnPtrWillBeRawPtr<MessagePortArray> ports = MessagePort::toMessagePortArray (executionContext(), webChannels);
270 RefPtr<SerializedScriptValue> value = SerializedScriptValueFactory::instance ().createFromWire(message); 275 RefPtr<SerializedScriptValue> value = SerializedScriptValueFactory::instance ().createFromWire(message);
271 executionContext()->executingWindow()->dispatchEvent(MessageEvent::create(po rts.release(), value)); 276 executionContext()->executingWindow()->dispatchEvent(MessageEvent::create(po rts.release(), value));
272 } 277 }
273 278
279 const AtomicString& ServiceWorkerContainer::interfaceName() const
280 {
281 return EventTargetNames::ServiceWorkerContainer;
282 }
283
274 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex t) 284 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex t)
275 : ContextLifecycleObserver(executionContext) 285 : ContextLifecycleObserver(executionContext)
276 , m_provider(0) 286 , m_provider(0)
277 { 287 {
278 288
279 if (!executionContext) 289 if (!executionContext)
280 return; 290 return;
281 291
282 m_ready = createReadyProperty(); 292 m_ready = createReadyProperty();
283 293
284 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) { 294 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) {
285 m_provider = client->provider(); 295 m_provider = client->provider();
286 if (m_provider) 296 if (m_provider)
287 m_provider->setClient(this); 297 m_provider->setClient(this);
288 } 298 }
289 } 299 }
290 300
291 } // namespace blink 301 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698