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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(s
criptState); | 149 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(s
criptState); |
150 ScriptPromise promise = resolver->promise(); | 150 ScriptPromise promise = resolver->promise(); |
151 resolver->resolve(m_controller.get()); | 151 resolver->resolve(m_controller.get()); |
152 return promise; | 152 return promise; |
153 } | 153 } |
154 // FIXME: Elaborate the implementation when the "waiting" property | 154 // FIXME: Elaborate the implementation when the "waiting" property |
155 // or replace() is implemented. | 155 // or replace() is implemented. |
156 return ScriptPromise(); | 156 return ScriptPromise(); |
157 } | 157 } |
158 | 158 |
159 void ServiceWorkerContainer::setCurrentServiceWorker(blink::WebServiceWorker* se
rviceWorker) | |
160 { | |
161 setController(serviceWorker); | |
162 } | |
163 | |
164 // If the WebServiceWorker is up for adoption (does not have a | 159 // If the WebServiceWorker is up for adoption (does not have a |
165 // WebServiceWorkerProxy owner), rejects the adoption by deleting the | 160 // WebServiceWorkerProxy owner), rejects the adoption by deleting the |
166 // WebServiceWorker. | 161 // WebServiceWorker. |
167 static void deleteIfNoExistingOwner(blink::WebServiceWorker* serviceWorker) | 162 static void deleteIfNoExistingOwner(blink::WebServiceWorker* serviceWorker) |
168 { | 163 { |
169 if (serviceWorker && !serviceWorker->proxy()) | 164 if (serviceWorker && !serviceWorker->proxy()) |
170 delete serviceWorker; | 165 delete serviceWorker; |
171 } | 166 } |
172 | 167 |
173 void ServiceWorkerContainer::setWaiting(blink::WebServiceWorker* serviceWorker) | 168 void ServiceWorkerContainer::setActive(blink::WebServiceWorker* serviceWorker) |
174 { | 169 { |
175 if (!executionContext()) { | 170 if (!executionContext()) { |
176 deleteIfNoExistingOwner(serviceWorker); | 171 deleteIfNoExistingOwner(serviceWorker); |
177 return; | 172 return; |
178 } | 173 } |
179 m_waiting = ServiceWorker::from(executionContext(), serviceWorker); | 174 m_active = ServiceWorker::from(executionContext(), serviceWorker); |
180 } | 175 } |
181 | 176 |
182 void ServiceWorkerContainer::setController(blink::WebServiceWorker* serviceWorke
r) | 177 void ServiceWorkerContainer::setController(blink::WebServiceWorker* serviceWorke
r) |
183 { | 178 { |
184 if (!executionContext()) { | 179 if (!executionContext()) { |
185 deleteIfNoExistingOwner(serviceWorker); | 180 deleteIfNoExistingOwner(serviceWorker); |
186 return; | 181 return; |
187 } | 182 } |
188 m_controller = ServiceWorker::from(executionContext(), serviceWorker); | 183 m_controller = ServiceWorker::from(executionContext(), serviceWorker); |
189 } | 184 } |
190 | 185 |
| 186 void ServiceWorkerContainer::setInstalling(blink::WebServiceWorker* serviceWorke
r) |
| 187 { |
| 188 if (!executionContext()) { |
| 189 deleteIfNoExistingOwner(serviceWorker); |
| 190 return; |
| 191 } |
| 192 m_installing = ServiceWorker::from(executionContext(), serviceWorker); |
| 193 } |
| 194 |
| 195 void ServiceWorkerContainer::setWaiting(blink::WebServiceWorker* serviceWorker) |
| 196 { |
| 197 if (!executionContext()) { |
| 198 deleteIfNoExistingOwner(serviceWorker); |
| 199 return; |
| 200 } |
| 201 m_waiting = ServiceWorker::from(executionContext(), serviceWorker); |
| 202 } |
| 203 |
191 void ServiceWorkerContainer::dispatchMessageEvent(const blink::WebString& messag
e, const blink::WebMessagePortChannelArray& webChannels) | 204 void ServiceWorkerContainer::dispatchMessageEvent(const blink::WebString& messag
e, const blink::WebMessagePortChannelArray& webChannels) |
192 { | 205 { |
193 if (!executionContext() || !executionContext()->executingWindow()) | 206 if (!executionContext() || !executionContext()->executingWindow()) |
194 return; | 207 return; |
195 | 208 |
196 OwnPtr<MessagePortArray> ports = MessagePort::toMessagePortArray(executionCo
ntext(), webChannels); | 209 OwnPtr<MessagePortArray> ports = MessagePort::toMessagePortArray(executionCo
ntext(), webChannels); |
197 RefPtr<SerializedScriptValue> value = SerializedScriptValue::createFromWire(
message); | 210 RefPtr<SerializedScriptValue> value = SerializedScriptValue::createFromWire(
message); |
198 executionContext()->executingWindow()->dispatchEvent(MessageEvent::create(po
rts.release(), value)); | 211 executionContext()->executingWindow()->dispatchEvent(MessageEvent::create(po
rts.release(), value)); |
199 } | 212 } |
200 | 213 |
201 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex
t) | 214 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex
t) |
202 : ContextLifecycleObserver(executionContext) | 215 : ContextLifecycleObserver(executionContext) |
203 , m_provider(0) | 216 , m_provider(0) |
204 { | 217 { |
205 ScriptWrappable::init(this); | 218 ScriptWrappable::init(this); |
206 | 219 |
207 if (!executionContext) | 220 if (!executionContext) |
208 return; | 221 return; |
209 | 222 |
210 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { | 223 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { |
211 m_provider = client->provider(); | 224 m_provider = client->provider(); |
212 if (m_provider) | 225 if (m_provider) |
213 m_provider->setClient(this); | 226 m_provider->setClient(this); |
214 } | 227 } |
215 } | 228 } |
216 | 229 |
217 } // namespace WebCore | 230 } // namespace WebCore |
OLD | NEW |