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 16 matching lines...) Expand all Loading... |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 #include "config.h" | 30 #include "config.h" |
31 #include "modules/serviceworkers/ServiceWorkerContainer.h" | 31 #include "modules/serviceworkers/ServiceWorkerContainer.h" |
32 | 32 |
33 #include "RuntimeEnabledFeatures.h" | 33 #include "RuntimeEnabledFeatures.h" |
34 #include "bindings/v8/CallbackPromiseAdapter.h" | 34 #include "bindings/v8/CallbackPromiseAdapter.h" |
35 #include "bindings/v8/ScriptPromiseResolverWithContext.h" | 35 #include "bindings/v8/ScriptPromiseResolverWithContext.h" |
36 #include "bindings/v8/ScriptState.h" | 36 #include "bindings/v8/ScriptState.h" |
| 37 #include "bindings/v8/SerializedScriptValue.h" |
37 #include "core/dom/DOMException.h" | 38 #include "core/dom/DOMException.h" |
| 39 #include "core/dom/Document.h" |
38 #include "core/dom/ExceptionCode.h" | 40 #include "core/dom/ExceptionCode.h" |
39 #include "core/dom/ExecutionContext.h" | 41 #include "core/dom/ExecutionContext.h" |
| 42 #include "core/dom/MessagePort.h" |
| 43 #include "core/events/MessageEvent.h" |
40 #include "modules/serviceworkers/RegistrationOptionList.h" | 44 #include "modules/serviceworkers/RegistrationOptionList.h" |
41 #include "modules/serviceworkers/ServiceWorker.h" | 45 #include "modules/serviceworkers/ServiceWorker.h" |
42 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" | 46 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
43 #include "modules/serviceworkers/ServiceWorkerError.h" | 47 #include "modules/serviceworkers/ServiceWorkerError.h" |
44 #include "public/platform/WebServiceWorker.h" | 48 #include "public/platform/WebServiceWorker.h" |
45 #include "public/platform/WebServiceWorkerProvider.h" | 49 #include "public/platform/WebServiceWorkerProvider.h" |
46 #include "public/platform/WebString.h" | 50 #include "public/platform/WebString.h" |
47 #include "public/platform/WebURL.h" | 51 #include "public/platform/WebURL.h" |
48 #include "v8.h" | 52 #include "v8.h" |
49 | 53 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 return promise; | 137 return promise; |
134 } | 138 } |
135 | 139 |
136 void ServiceWorkerContainer::setCurrentServiceWorker(blink::WebServiceWorker* se
rviceWorker) | 140 void ServiceWorkerContainer::setCurrentServiceWorker(blink::WebServiceWorker* se
rviceWorker) |
137 { | 141 { |
138 if (!executionContext()) | 142 if (!executionContext()) |
139 return; | 143 return; |
140 m_current = ServiceWorker::create(executionContext(), adoptPtr(serviceWorker
)); | 144 m_current = ServiceWorker::create(executionContext(), adoptPtr(serviceWorker
)); |
141 } | 145 } |
142 | 146 |
| 147 void ServiceWorkerContainer::dispatchMessageEvent(const blink::WebString& messag
e, const blink::WebMessagePortChannelArray& webChannels) |
| 148 { |
| 149 if (!executionContext() || !window()) |
| 150 return; |
| 151 |
| 152 OwnPtr<MessagePortArray> ports = MessagePort::toMessagePortArray(executionCo
ntext(), webChannels); |
| 153 RefPtr<SerializedScriptValue> value = SerializedScriptValue::createFromWire(
message); |
| 154 window()->dispatchEvent(MessageEvent::create(ports.release(), value)); |
| 155 } |
| 156 |
143 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex
t) | 157 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex
t) |
144 : ContextLifecycleObserver(executionContext) | 158 : ContextLifecycleObserver(executionContext) |
| 159 , DOMWindowLifecycleObserver(executionContext->isDocument() ? toDocument(exe
cutionContext)->domWindow() : 0) |
145 , m_provider(0) | 160 , m_provider(0) |
146 { | 161 { |
147 ScriptWrappable::init(this); | 162 ScriptWrappable::init(this); |
148 | 163 |
149 if (!executionContext) | 164 if (!executionContext) |
150 return; | 165 return; |
151 | 166 |
152 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { | 167 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { |
153 m_provider = client->provider(); | 168 m_provider = client->provider(); |
154 if (m_provider) | 169 if (m_provider) |
155 m_provider->setClient(this); | 170 m_provider->setClient(this); |
156 } | 171 } |
157 } | 172 } |
158 | 173 |
159 } // namespace WebCore | 174 } // namespace WebCore |
OLD | NEW |