| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 // ScriptPromiseProperty can vend Promises in isolated worlds. | 195 // ScriptPromiseProperty can vend Promises in isolated worlds. |
| 196 return ScriptPromise::rejectWithDOMException(callerState, DOMException::
create(NotSupportedError, "'ready' is only supported in pages.")); | 196 return ScriptPromise::rejectWithDOMException(callerState, DOMException::
create(NotSupportedError, "'ready' is only supported in pages.")); |
| 197 } | 197 } |
| 198 | 198 |
| 199 return m_ready->promise(callerState->world()); | 199 return m_ready->promise(callerState->world()); |
| 200 } | 200 } |
| 201 | 201 |
| 202 // If the WebServiceWorker is up for adoption (does not have a | 202 // If the WebServiceWorker is up for adoption (does not have a |
| 203 // WebServiceWorkerProxy owner), rejects the adoption by deleting the | 203 // WebServiceWorkerProxy owner), rejects the adoption by deleting the |
| 204 // WebServiceWorker. | 204 // WebServiceWorker. |
| 205 static void deleteIfNoExistingOwner(blink::WebServiceWorker* serviceWorker) | 205 static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker) |
| 206 { | 206 { |
| 207 if (serviceWorker && !serviceWorker->proxy()) | 207 if (serviceWorker && !serviceWorker->proxy()) |
| 208 delete serviceWorker; | 208 delete serviceWorker; |
| 209 } | 209 } |
| 210 | 210 |
| 211 void ServiceWorkerContainer::setActive(blink::WebServiceWorker* serviceWorker) | 211 void ServiceWorkerContainer::setActive(WebServiceWorker* serviceWorker) |
| 212 { | 212 { |
| 213 if (!executionContext()) { | 213 if (!executionContext()) { |
| 214 deleteIfNoExistingOwner(serviceWorker); | 214 deleteIfNoExistingOwner(serviceWorker); |
| 215 return; | 215 return; |
| 216 } | 216 } |
| 217 RefPtrWillBeRawPtr<ServiceWorker> previousReadyWorker = m_active; | 217 RefPtrWillBeRawPtr<ServiceWorker> previousReadyWorker = m_active; |
| 218 m_active = ServiceWorker::from(executionContext(), serviceWorker); | 218 m_active = ServiceWorker::from(executionContext(), serviceWorker); |
| 219 checkReadyChanged(previousReadyWorker.release()); | 219 checkReadyChanged(previousReadyWorker.release()); |
| 220 } | 220 } |
| 221 | 221 |
| 222 void ServiceWorkerContainer::checkReadyChanged(PassRefPtrWillBeRawPtr<ServiceWor
ker> previousReadyWorker) | 222 void ServiceWorkerContainer::checkReadyChanged(PassRefPtrWillBeRawPtr<ServiceWor
ker> previousReadyWorker) |
| 223 { | 223 { |
| 224 ServiceWorker* currentReadyWorker = m_active.get(); | 224 ServiceWorker* currentReadyWorker = m_active.get(); |
| 225 | 225 |
| 226 if (previousReadyWorker == currentReadyWorker) | 226 if (previousReadyWorker == currentReadyWorker) |
| 227 return; | 227 return; |
| 228 | 228 |
| 229 if (m_ready->state() != ReadyProperty::Pending) { | 229 if (m_ready->state() != ReadyProperty::Pending) { |
| 230 // Already resolved Promises are now stale because the | 230 // Already resolved Promises are now stale because the |
| 231 // ready worker changed | 231 // ready worker changed |
| 232 m_ready = createReadyProperty(); | 232 m_ready = createReadyProperty(); |
| 233 } | 233 } |
| 234 | 234 |
| 235 if (currentReadyWorker) | 235 if (currentReadyWorker) |
| 236 m_ready->resolve(currentReadyWorker); | 236 m_ready->resolve(currentReadyWorker); |
| 237 } | 237 } |
| 238 | 238 |
| 239 void ServiceWorkerContainer::setController(blink::WebServiceWorker* serviceWorke
r) | 239 void ServiceWorkerContainer::setController(WebServiceWorker* serviceWorker) |
| 240 { | 240 { |
| 241 if (!executionContext()) { | 241 if (!executionContext()) { |
| 242 deleteIfNoExistingOwner(serviceWorker); | 242 deleteIfNoExistingOwner(serviceWorker); |
| 243 return; | 243 return; |
| 244 } | 244 } |
| 245 m_controller = ServiceWorker::from(executionContext(), serviceWorker); | 245 m_controller = ServiceWorker::from(executionContext(), serviceWorker); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void ServiceWorkerContainer::setInstalling(blink::WebServiceWorker* serviceWorke
r) | 248 void ServiceWorkerContainer::setInstalling(WebServiceWorker* serviceWorker) |
| 249 { | 249 { |
| 250 if (!executionContext()) { | 250 if (!executionContext()) { |
| 251 deleteIfNoExistingOwner(serviceWorker); | 251 deleteIfNoExistingOwner(serviceWorker); |
| 252 return; | 252 return; |
| 253 } | 253 } |
| 254 m_installing = ServiceWorker::from(executionContext(), serviceWorker); | 254 m_installing = ServiceWorker::from(executionContext(), serviceWorker); |
| 255 } | 255 } |
| 256 | 256 |
| 257 void ServiceWorkerContainer::setWaiting(blink::WebServiceWorker* serviceWorker) | 257 void ServiceWorkerContainer::setWaiting(WebServiceWorker* serviceWorker) |
| 258 { | 258 { |
| 259 if (!executionContext()) { | 259 if (!executionContext()) { |
| 260 deleteIfNoExistingOwner(serviceWorker); | 260 deleteIfNoExistingOwner(serviceWorker); |
| 261 return; | 261 return; |
| 262 } | 262 } |
| 263 m_waiting = ServiceWorker::from(executionContext(), serviceWorker); | 263 m_waiting = ServiceWorker::from(executionContext(), serviceWorker); |
| 264 } | 264 } |
| 265 | 265 |
| 266 void ServiceWorkerContainer::dispatchMessageEvent(const blink::WebString& messag
e, const blink::WebMessagePortChannelArray& webChannels) | 266 void ServiceWorkerContainer::dispatchMessageEvent(const WebString& message, cons
t WebMessagePortChannelArray& webChannels) |
| 267 { | 267 { |
| 268 if (!executionContext() || !executionContext()->executingWindow()) | 268 if (!executionContext() || !executionContext()->executingWindow()) |
| 269 return; | 269 return; |
| 270 | 270 |
| 271 OwnPtrWillBeRawPtr<MessagePortArray> ports = MessagePort::toMessagePortArray
(executionContext(), webChannels); | 271 OwnPtrWillBeRawPtr<MessagePortArray> ports = MessagePort::toMessagePortArray
(executionContext(), webChannels); |
| 272 RefPtr<SerializedScriptValue> value = SerializedScriptValue::createFromWire(
message); | 272 RefPtr<SerializedScriptValue> value = SerializedScriptValue::createFromWire(
message); |
| 273 executionContext()->executingWindow()->dispatchEvent(MessageEvent::create(po
rts.release(), value)); | 273 executionContext()->executingWindow()->dispatchEvent(MessageEvent::create(po
rts.release(), value)); |
| 274 } | 274 } |
| 275 | 275 |
| 276 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex
t) | 276 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex
t) |
| 277 : ContextLifecycleObserver(executionContext) | 277 : ContextLifecycleObserver(executionContext) |
| 278 , m_provider(0) | 278 , m_provider(0) |
| 279 { | 279 { |
| 280 ScriptWrappable::init(this); | 280 ScriptWrappable::init(this); |
| 281 | 281 |
| 282 if (!executionContext) | 282 if (!executionContext) |
| 283 return; | 283 return; |
| 284 | 284 |
| 285 m_ready = createReadyProperty(); | 285 m_ready = createReadyProperty(); |
| 286 | 286 |
| 287 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { | 287 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { |
| 288 m_provider = client->provider(); | 288 m_provider = client->provider(); |
| 289 if (m_provider) | 289 if (m_provider) |
| 290 m_provider->setClient(this); | 290 m_provider->setClient(this); |
| 291 } | 291 } |
| 292 } | 292 } |
| 293 | 293 |
| 294 } // namespace blink | 294 } // namespace blink |
| OLD | NEW |