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 22 matching lines...) Expand all Loading... | |
33 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 33 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
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 "modules/EventTargetModules.h" | |
43 #include "modules/serviceworkers/ServiceWorker.h" | 44 #include "modules/serviceworkers/ServiceWorker.h" |
44 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" | 45 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
45 #include "modules/serviceworkers/ServiceWorkerError.h" | 46 #include "modules/serviceworkers/ServiceWorkerError.h" |
46 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | 47 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
47 #include "platform/RuntimeEnabledFeatures.h" | 48 #include "platform/RuntimeEnabledFeatures.h" |
48 #include "public/platform/WebServiceWorker.h" | 49 #include "public/platform/WebServiceWorker.h" |
49 #include "public/platform/WebServiceWorkerProvider.h" | 50 #include "public/platform/WebServiceWorkerProvider.h" |
50 #include "public/platform/WebServiceWorkerRegistration.h" | 51 #include "public/platform/WebServiceWorkerRegistration.h" |
51 #include "public/platform/WebString.h" | 52 #include "public/platform/WebString.h" |
52 #include "public/platform/WebURL.h" | 53 #include "public/platform/WebURL.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 m_provider->setClient(0); | 92 m_provider->setClient(0); |
92 m_provider = nullptr; | 93 m_provider = nullptr; |
93 } | 94 } |
94 } | 95 } |
95 | 96 |
96 void ServiceWorkerContainer::trace(Visitor* visitor) | 97 void ServiceWorkerContainer::trace(Visitor* visitor) |
97 { | 98 { |
98 visitor->trace(m_controller); | 99 visitor->trace(m_controller); |
99 visitor->trace(m_readyRegistration); | 100 visitor->trace(m_readyRegistration); |
100 visitor->trace(m_ready); | 101 visitor->trace(m_ready); |
102 EventTargetWithInlineData::trace(visitor); | |
103 HeapSupplementable<ServiceWorkerContainer>::trace(visitor); | |
101 } | 104 } |
102 | 105 |
103 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptS tate, const String& url, const RegistrationOptions& options) | 106 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptS tate, const String& url, const RegistrationOptions& options) |
104 { | 107 { |
105 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 108 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
106 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | 109 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); |
107 ScriptPromise promise = resolver->promise(); | 110 ScriptPromise promise = resolver->promise(); |
108 | 111 |
109 if (!m_provider) { | 112 if (!m_provider) { |
110 resolver->reject(DOMException::create(InvalidStateError, "No associated provider is available")); | 113 resolver->reject(DOMException::create(InvalidStateError, "No associated provider is available")); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 delete serviceWorker; | 216 delete serviceWorker; |
214 } | 217 } |
215 | 218 |
216 void ServiceWorkerContainer::setController(WebServiceWorker* serviceWorker) | 219 void ServiceWorkerContainer::setController(WebServiceWorker* serviceWorker) |
217 { | 220 { |
218 if (!executionContext()) { | 221 if (!executionContext()) { |
219 deleteIfNoExistingOwner(serviceWorker); | 222 deleteIfNoExistingOwner(serviceWorker); |
220 return; | 223 return; |
221 } | 224 } |
222 m_controller = ServiceWorker::from(executionContext(), serviceWorker); | 225 m_controller = ServiceWorker::from(executionContext(), serviceWorker); |
226 if (m_controller.get()) | |
227 dispatchEvent(Event::create(EventTypeNames::controllerchange)); | |
michaeln
2014/11/14 22:53:55
This event should only be raised in the skipWaitin
xiang
2014/11/28 08:00:48
Done.
| |
223 } | 228 } |
224 | 229 |
225 void ServiceWorkerContainer::setReadyRegistration(WebServiceWorkerRegistration* registration) | 230 void ServiceWorkerContainer::setReadyRegistration(WebServiceWorkerRegistration* registration) |
226 { | 231 { |
227 if (!executionContext()) { | 232 if (!executionContext()) { |
228 ServiceWorkerRegistration::dispose(registration); | 233 ServiceWorkerRegistration::dispose(registration); |
229 return; | 234 return; |
230 } | 235 } |
231 | 236 |
232 ServiceWorkerRegistration* readyRegistration = ServiceWorkerRegistration::fr om(executionContext(), registration); | 237 ServiceWorkerRegistration* readyRegistration = ServiceWorkerRegistration::fr om(executionContext(), registration); |
(...skipping 12 matching lines...) Expand all Loading... | |
245 void ServiceWorkerContainer::dispatchMessageEvent(const WebString& message, cons t WebMessagePortChannelArray& webChannels) | 250 void ServiceWorkerContainer::dispatchMessageEvent(const WebString& message, cons t WebMessagePortChannelArray& webChannels) |
246 { | 251 { |
247 if (!executionContext() || !executionContext()->executingWindow()) | 252 if (!executionContext() || !executionContext()->executingWindow()) |
248 return; | 253 return; |
249 | 254 |
250 OwnPtrWillBeRawPtr<MessagePortArray> ports = MessagePort::toMessagePortArray (executionContext(), webChannels); | 255 OwnPtrWillBeRawPtr<MessagePortArray> ports = MessagePort::toMessagePortArray (executionContext(), webChannels); |
251 RefPtr<SerializedScriptValue> value = SerializedScriptValue::createFromWire( message); | 256 RefPtr<SerializedScriptValue> value = SerializedScriptValue::createFromWire( message); |
252 executionContext()->executingWindow()->dispatchEvent(MessageEvent::create(po rts.release(), value)); | 257 executionContext()->executingWindow()->dispatchEvent(MessageEvent::create(po rts.release(), value)); |
253 } | 258 } |
254 | 259 |
260 const AtomicString& ServiceWorkerContainer::interfaceName() const | |
261 { | |
262 return EventTargetNames::ServiceWorkerContainer; | |
263 } | |
264 | |
255 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex t) | 265 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex t) |
256 : ContextLifecycleObserver(executionContext) | 266 : ContextLifecycleObserver(executionContext) |
257 , m_provider(0) | 267 , m_provider(0) |
258 { | 268 { |
259 | 269 |
260 if (!executionContext) | 270 if (!executionContext) |
261 return; | 271 return; |
262 | 272 |
263 m_ready = createReadyProperty(); | 273 m_ready = createReadyProperty(); |
264 | 274 |
265 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) { | 275 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) { |
266 m_provider = client->provider(); | 276 m_provider = client->provider(); |
267 if (m_provider) | 277 if (m_provider) |
268 m_provider->setClient(this); | 278 m_provider->setClient(this); |
269 } | 279 } |
270 } | 280 } |
271 | 281 |
272 } // namespace blink | 282 } // namespace blink |
OLD | NEW |