OLD | NEW |
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 Loading... |
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 Loading... |
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); |
103 } | 105 } |
104 | 106 |
105 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) |
106 { | 108 { |
107 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 109 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
108 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 110 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
109 ScriptPromise promise = resolver->promise(); | 111 ScriptPromise promise = resolver->promise(); |
110 | 112 |
111 if (!m_provider) { | 113 if (!m_provider) { |
112 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 Loading... |
225 | 227 |
226 // If the WebServiceWorker is up for adoption (does not have a | 228 // If the WebServiceWorker is up for adoption (does not have a |
227 // WebServiceWorkerProxy owner), rejects the adoption by deleting the | 229 // WebServiceWorkerProxy owner), rejects the adoption by deleting the |
228 // WebServiceWorker. | 230 // WebServiceWorker. |
229 static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker) | 231 static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker) |
230 { | 232 { |
231 if (serviceWorker && !serviceWorker->proxy()) | 233 if (serviceWorker && !serviceWorker->proxy()) |
232 delete serviceWorker; | 234 delete serviceWorker; |
233 } | 235 } |
234 | 236 |
235 void ServiceWorkerContainer::setController(WebServiceWorker* serviceWorker) | 237 void ServiceWorkerContainer::setController(WebServiceWorker* serviceWorker, bool
shouldNotifyControllerChange) |
236 { | 238 { |
237 if (!executionContext()) { | 239 if (!executionContext()) { |
238 deleteIfNoExistingOwner(serviceWorker); | 240 deleteIfNoExistingOwner(serviceWorker); |
239 return; | 241 return; |
240 } | 242 } |
241 m_controller = ServiceWorker::from(executionContext(), serviceWorker); | 243 m_controller = ServiceWorker::from(executionContext(), serviceWorker); |
| 244 if (shouldNotifyControllerChange) |
| 245 dispatchEvent(Event::create(EventTypeNames::controllerchange)); |
242 } | 246 } |
243 | 247 |
244 void ServiceWorkerContainer::setReadyRegistration(WebServiceWorkerRegistration*
registration) | 248 void ServiceWorkerContainer::setReadyRegistration(WebServiceWorkerRegistration*
registration) |
245 { | 249 { |
246 if (!executionContext()) { | 250 if (!executionContext()) { |
247 ServiceWorkerRegistration::dispose(registration); | 251 ServiceWorkerRegistration::dispose(registration); |
248 return; | 252 return; |
249 } | 253 } |
250 | 254 |
251 ServiceWorkerRegistration* readyRegistration = ServiceWorkerRegistration::fr
om(executionContext(), registration); | 255 ServiceWorkerRegistration* readyRegistration = ServiceWorkerRegistration::fr
om(executionContext(), registration); |
(...skipping 12 matching lines...) Expand all Loading... |
264 void ServiceWorkerContainer::dispatchMessageEvent(const WebString& message, cons
t WebMessagePortChannelArray& webChannels) | 268 void ServiceWorkerContainer::dispatchMessageEvent(const WebString& message, cons
t WebMessagePortChannelArray& webChannels) |
265 { | 269 { |
266 if (!executionContext() || !executionContext()->executingWindow()) | 270 if (!executionContext() || !executionContext()->executingWindow()) |
267 return; | 271 return; |
268 | 272 |
269 OwnPtrWillBeRawPtr<MessagePortArray> ports = MessagePort::toMessagePortArray
(executionContext(), webChannels); | 273 OwnPtrWillBeRawPtr<MessagePortArray> ports = MessagePort::toMessagePortArray
(executionContext(), webChannels); |
270 RefPtr<SerializedScriptValue> value = SerializedScriptValueFactory::instance
().createFromWire(message); | 274 RefPtr<SerializedScriptValue> value = SerializedScriptValueFactory::instance
().createFromWire(message); |
271 executionContext()->executingWindow()->dispatchEvent(MessageEvent::create(po
rts.release(), value)); | 275 executionContext()->executingWindow()->dispatchEvent(MessageEvent::create(po
rts.release(), value)); |
272 } | 276 } |
273 | 277 |
| 278 const AtomicString& ServiceWorkerContainer::interfaceName() const |
| 279 { |
| 280 return EventTargetNames::ServiceWorkerContainer; |
| 281 } |
| 282 |
274 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex
t) | 283 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex
t) |
275 : ContextLifecycleObserver(executionContext) | 284 : ContextLifecycleObserver(executionContext) |
276 , m_provider(0) | 285 , m_provider(0) |
277 { | 286 { |
278 | 287 |
279 if (!executionContext) | 288 if (!executionContext) |
280 return; | 289 return; |
281 | 290 |
282 m_ready = createReadyProperty(); | 291 m_ready = createReadyProperty(); |
283 | 292 |
284 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { | 293 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { |
285 m_provider = client->provider(); | 294 m_provider = client->provider(); |
286 if (m_provider) | 295 if (m_provider) |
287 m_provider->setClient(this); | 296 m_provider->setClient(this); |
288 } | 297 } |
289 } | 298 } |
290 | 299 |
291 } // namespace blink | 300 } // namespace blink |
OLD | NEW |