| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 namespace blink { | 59 namespace blink { |
| 60 | 60 |
| 61 class RegistrationCallback : public WebServiceWorkerProvider::WebServiceWorkerRe
gistrationCallbacks { | 61 class RegistrationCallback : public WebServiceWorkerProvider::WebServiceWorkerRe
gistrationCallbacks { |
| 62 public: | 62 public: |
| 63 explicit RegistrationCallback(ScriptPromiseResolver* resolver) | 63 explicit RegistrationCallback(ScriptPromiseResolver* resolver) |
| 64 : m_resolver(resolver) { } | 64 : m_resolver(resolver) { } |
| 65 ~RegistrationCallback() override { } | 65 ~RegistrationCallback() override { } |
| 66 | 66 |
| 67 void onSuccess(WebPassOwnPtr<WebServiceWorkerRegistration::Handle> handle) o
verride | 67 void onSuccess(WebPassOwnPtr<WebServiceWorkerRegistration::Handle> handle) o
verride |
| 68 { | 68 { |
| 69 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 69 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) |
| 70 return; | 70 return; |
| 71 m_resolver->resolve(ServiceWorkerRegistration::getOrCreate(m_resolver->e
xecutionContext(), handle.release())); | 71 m_resolver->resolve(ServiceWorkerRegistration::getOrCreate(m_resolver->g
etExecutionContext(), handle.release())); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void onError(const WebServiceWorkerError& error) override | 74 void onError(const WebServiceWorkerError& error) override |
| 75 { | 75 { |
| 76 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 76 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) |
| 77 return; | 77 return; |
| 78 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)); | 78 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 private: | 81 private: |
| 82 Persistent<ScriptPromiseResolver> m_resolver; | 82 Persistent<ScriptPromiseResolver> m_resolver; |
| 83 WTF_MAKE_NONCOPYABLE(RegistrationCallback); | 83 WTF_MAKE_NONCOPYABLE(RegistrationCallback); |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 class GetRegistrationCallback : public WebServiceWorkerProvider::WebServiceWorke
rGetRegistrationCallbacks { | 86 class GetRegistrationCallback : public WebServiceWorkerProvider::WebServiceWorke
rGetRegistrationCallbacks { |
| 87 public: | 87 public: |
| 88 explicit GetRegistrationCallback(ScriptPromiseResolver* resolver) | 88 explicit GetRegistrationCallback(ScriptPromiseResolver* resolver) |
| 89 : m_resolver(resolver) { } | 89 : m_resolver(resolver) { } |
| 90 ~GetRegistrationCallback() override { } | 90 ~GetRegistrationCallback() override { } |
| 91 | 91 |
| 92 void onSuccess(WebPassOwnPtr<WebServiceWorkerRegistration::Handle> webPassHa
ndle) override | 92 void onSuccess(WebPassOwnPtr<WebServiceWorkerRegistration::Handle> webPassHa
ndle) override |
| 93 { | 93 { |
| 94 OwnPtr<WebServiceWorkerRegistration::Handle> handle = webPassHandle.rele
ase(); | 94 OwnPtr<WebServiceWorkerRegistration::Handle> handle = webPassHandle.rele
ase(); |
| 95 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 95 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) |
| 96 return; | 96 return; |
| 97 if (!handle) { | 97 if (!handle) { |
| 98 // Resolve the promise with undefined. | 98 // Resolve the promise with undefined. |
| 99 m_resolver->resolve(); | 99 m_resolver->resolve(); |
| 100 return; | 100 return; |
| 101 } | 101 } |
| 102 m_resolver->resolve(ServiceWorkerRegistration::getOrCreate(m_resolver->e
xecutionContext(), handle.release())); | 102 m_resolver->resolve(ServiceWorkerRegistration::getOrCreate(m_resolver->g
etExecutionContext(), handle.release())); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void onError(const WebServiceWorkerError& error) override | 105 void onError(const WebServiceWorkerError& error) override |
| 106 { | 106 { |
| 107 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 107 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) |
| 108 return; | 108 return; |
| 109 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)); | 109 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)); |
| 110 } | 110 } |
| 111 | 111 |
| 112 private: | 112 private: |
| 113 Persistent<ScriptPromiseResolver> m_resolver; | 113 Persistent<ScriptPromiseResolver> m_resolver; |
| 114 WTF_MAKE_NONCOPYABLE(GetRegistrationCallback); | 114 WTF_MAKE_NONCOPYABLE(GetRegistrationCallback); |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 class GetRegistrationsCallback : public WebServiceWorkerProvider::WebServiceWork
erGetRegistrationsCallbacks { | 117 class GetRegistrationsCallback : public WebServiceWorkerProvider::WebServiceWork
erGetRegistrationsCallbacks { |
| 118 public: | 118 public: |
| 119 explicit GetRegistrationsCallback(ScriptPromiseResolver* resolver) | 119 explicit GetRegistrationsCallback(ScriptPromiseResolver* resolver) |
| 120 : m_resolver(resolver) { } | 120 : m_resolver(resolver) { } |
| 121 ~GetRegistrationsCallback() override { } | 121 ~GetRegistrationsCallback() override { } |
| 122 | 122 |
| 123 void onSuccess(WebPassOwnPtr<WebVector<WebServiceWorkerRegistration::Handle*
>> webPassRegistrations) override | 123 void onSuccess(WebPassOwnPtr<WebVector<WebServiceWorkerRegistration::Handle*
>> webPassRegistrations) override |
| 124 { | 124 { |
| 125 Vector<OwnPtr<WebServiceWorkerRegistration::Handle>> handles; | 125 Vector<OwnPtr<WebServiceWorkerRegistration::Handle>> handles; |
| 126 OwnPtr<WebVector<WebServiceWorkerRegistration::Handle*>> webRegistration
s = webPassRegistrations.release(); | 126 OwnPtr<WebVector<WebServiceWorkerRegistration::Handle*>> webRegistration
s = webPassRegistrations.release(); |
| 127 for (auto& handle : *webRegistrations) { | 127 for (auto& handle : *webRegistrations) { |
| 128 handles.append(adoptPtr(handle)); | 128 handles.append(adoptPtr(handle)); |
| 129 } | 129 } |
| 130 | 130 |
| 131 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 131 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) |
| 132 return; | 132 return; |
| 133 m_resolver->resolve(ServiceWorkerRegistrationArray::take(m_resolver.get(
), &handles)); | 133 m_resolver->resolve(ServiceWorkerRegistrationArray::take(m_resolver.get(
), &handles)); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void onError(const WebServiceWorkerError& error) override | 136 void onError(const WebServiceWorkerError& error) override |
| 137 { | 137 { |
| 138 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 138 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) |
| 139 return; | 139 return; |
| 140 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)); | 140 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)); |
| 141 } | 141 } |
| 142 | 142 |
| 143 private: | 143 private: |
| 144 Persistent<ScriptPromiseResolver> m_resolver; | 144 Persistent<ScriptPromiseResolver> m_resolver; |
| 145 WTF_MAKE_NONCOPYABLE(GetRegistrationsCallback); | 145 WTF_MAKE_NONCOPYABLE(GetRegistrationsCallback); |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 class ServiceWorkerContainer::GetRegistrationForReadyCallback : public WebServic
eWorkerProvider::WebServiceWorkerGetRegistrationForReadyCallbacks { | 148 class ServiceWorkerContainer::GetRegistrationForReadyCallback : public WebServic
eWorkerProvider::WebServiceWorkerGetRegistrationForReadyCallbacks { |
| 149 public: | 149 public: |
| 150 explicit GetRegistrationForReadyCallback(ReadyProperty* ready) | 150 explicit GetRegistrationForReadyCallback(ReadyProperty* ready) |
| 151 : m_ready(ready) { } | 151 : m_ready(ready) { } |
| 152 ~GetRegistrationForReadyCallback() override { } | 152 ~GetRegistrationForReadyCallback() override { } |
| 153 | 153 |
| 154 void onSuccess(WebPassOwnPtr<WebServiceWorkerRegistration::Handle> handle) o
verride | 154 void onSuccess(WebPassOwnPtr<WebServiceWorkerRegistration::Handle> handle) o
verride |
| 155 { | 155 { |
| 156 ASSERT(m_ready->getState() == ReadyProperty::Pending); | 156 ASSERT(m_ready->getState() == ReadyProperty::Pending); |
| 157 | 157 |
| 158 if (m_ready->executionContext() && !m_ready->executionContext()->activeD
OMObjectsAreStopped()) | 158 if (m_ready->getExecutionContext() && !m_ready->getExecutionContext()->a
ctiveDOMObjectsAreStopped()) |
| 159 m_ready->resolve(ServiceWorkerRegistration::getOrCreate(m_ready->exe
cutionContext(), handle.release())); | 159 m_ready->resolve(ServiceWorkerRegistration::getOrCreate(m_ready->get
ExecutionContext(), handle.release())); |
| 160 } | 160 } |
| 161 | 161 |
| 162 private: | 162 private: |
| 163 Persistent<ReadyProperty> m_ready; | 163 Persistent<ReadyProperty> m_ready; |
| 164 WTF_MAKE_NONCOPYABLE(GetRegistrationForReadyCallback); | 164 WTF_MAKE_NONCOPYABLE(GetRegistrationForReadyCallback); |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 ServiceWorkerContainer* ServiceWorkerContainer::create(ExecutionContext* executi
onContext) | 167 ServiceWorkerContainer* ServiceWorkerContainer::create(ExecutionContext* executi
onContext) |
| 168 { | 168 { |
| 169 return new ServiceWorkerContainer(executionContext); | 169 return new ServiceWorkerContainer(executionContext); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 193 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptS
tate, const String& url, const RegistrationOptions& options) | 193 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptS
tate, const String& url, const RegistrationOptions& options) |
| 194 { | 194 { |
| 195 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 195 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 196 ScriptPromise promise = resolver->promise(); | 196 ScriptPromise promise = resolver->promise(); |
| 197 | 197 |
| 198 if (!m_provider) { | 198 if (!m_provider) { |
| 199 resolver->reject(DOMException::create(InvalidStateError, "Failed to regi
ster a ServiceWorker: The document is in an invalid state.")); | 199 resolver->reject(DOMException::create(InvalidStateError, "Failed to regi
ster a ServiceWorker: The document is in an invalid state.")); |
| 200 return promise; | 200 return promise; |
| 201 } | 201 } |
| 202 | 202 |
| 203 ExecutionContext* executionContext = scriptState->executionContext(); | 203 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 204 // FIXME: May be null due to worker termination: http://crbug.com/413518. | 204 // FIXME: May be null due to worker termination: http://crbug.com/413518. |
| 205 if (!executionContext) | 205 if (!executionContext) |
| 206 return ScriptPromise(); | 206 return ScriptPromise(); |
| 207 | 207 |
| 208 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); | 208 RefPtr<SecurityOrigin> documentOrigin = executionContext->getSecurityOrigin(
); |
| 209 String errorMessage; | 209 String errorMessage; |
| 210 // Restrict to secure origins: https://w3c.github.io/webappsec/specs/powerfu
lfeatures/#settings-privileged | 210 // Restrict to secure origins: https://w3c.github.io/webappsec/specs/powerfu
lfeatures/#settings-privileged |
| 211 if (!executionContext->isSecureContext(errorMessage)) { | 211 if (!executionContext->isSecureContext(errorMessage)) { |
| 212 resolver->reject(DOMException::create(SecurityError, errorMessage)); | 212 resolver->reject(DOMException::create(SecurityError, errorMessage)); |
| 213 return promise; | 213 return promise; |
| 214 } | 214 } |
| 215 | 215 |
| 216 KURL pageURL = KURL(KURL(), documentOrigin->toString()); | 216 KURL pageURL = KURL(KURL(), documentOrigin->toString()); |
| 217 if (!SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers(pageURL.pr
otocol())) { | 217 if (!SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers(pageURL.pr
otocol())) { |
| 218 resolver->reject(DOMException::create(SecurityError, "Failed to register
a ServiceWorker: The URL protocol of the current origin ('" + documentOrigin->t
oString() + "') is not supported.")); | 218 resolver->reject(DOMException::create(SecurityError, "Failed to register
a ServiceWorker: The URL protocol of the current origin ('" + documentOrigin->t
oString() + "') is not supported.")); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState,
const String& documentURL) | 262 ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState,
const String& documentURL) |
| 263 { | 263 { |
| 264 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 264 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 265 ScriptPromise promise = resolver->promise(); | 265 ScriptPromise promise = resolver->promise(); |
| 266 | 266 |
| 267 if (!m_provider) { | 267 if (!m_provider) { |
| 268 resolver->reject(DOMException::create(InvalidStateError, "Failed to get
a ServiceWorkerRegistration: The document is in an invalid state.")); | 268 resolver->reject(DOMException::create(InvalidStateError, "Failed to get
a ServiceWorkerRegistration: The document is in an invalid state.")); |
| 269 return promise; | 269 return promise; |
| 270 } | 270 } |
| 271 | 271 |
| 272 ExecutionContext* executionContext = scriptState->executionContext(); | 272 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 273 // FIXME: May be null due to worker termination: http://crbug.com/413518. | 273 // FIXME: May be null due to worker termination: http://crbug.com/413518. |
| 274 if (!executionContext) | 274 if (!executionContext) |
| 275 return ScriptPromise(); | 275 return ScriptPromise(); |
| 276 | 276 |
| 277 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); | 277 RefPtr<SecurityOrigin> documentOrigin = executionContext->getSecurityOrigin(
); |
| 278 String errorMessage; | 278 String errorMessage; |
| 279 if (!executionContext->isSecureContext(errorMessage)) { | 279 if (!executionContext->isSecureContext(errorMessage)) { |
| 280 resolver->reject(DOMException::create(SecurityError, errorMessage)); | 280 resolver->reject(DOMException::create(SecurityError, errorMessage)); |
| 281 return promise; | 281 return promise; |
| 282 } | 282 } |
| 283 | 283 |
| 284 KURL pageURL = KURL(KURL(), documentOrigin->toString()); | 284 KURL pageURL = KURL(KURL(), documentOrigin->toString()); |
| 285 if (!SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers(pageURL.pr
otocol())) { | 285 if (!SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers(pageURL.pr
otocol())) { |
| 286 resolver->reject(DOMException::create(SecurityError, "Failed to get a Se
rviceWorkerRegistration: The URL protocol of the current origin ('" + documentOr
igin->toString() + "') is not supported.")); | 286 resolver->reject(DOMException::create(SecurityError, "Failed to get a Se
rviceWorkerRegistration: The URL protocol of the current origin ('" + documentOr
igin->toString() + "') is not supported.")); |
| 287 return promise; | 287 return promise; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 302 ScriptPromise ServiceWorkerContainer::getRegistrations(ScriptState* scriptState) | 302 ScriptPromise ServiceWorkerContainer::getRegistrations(ScriptState* scriptState) |
| 303 { | 303 { |
| 304 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 304 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 305 ScriptPromise promise = resolver->promise(); | 305 ScriptPromise promise = resolver->promise(); |
| 306 | 306 |
| 307 if (!m_provider) { | 307 if (!m_provider) { |
| 308 resolver->reject(DOMException::create(InvalidStateError, "Failed to get
ServiceWorkerRegistration objects: The document is in an invalid state.")); | 308 resolver->reject(DOMException::create(InvalidStateError, "Failed to get
ServiceWorkerRegistration objects: The document is in an invalid state.")); |
| 309 return promise; | 309 return promise; |
| 310 } | 310 } |
| 311 | 311 |
| 312 ExecutionContext* executionContext = scriptState->executionContext(); | 312 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 313 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); | 313 RefPtr<SecurityOrigin> documentOrigin = executionContext->getSecurityOrigin(
); |
| 314 String errorMessage; | 314 String errorMessage; |
| 315 if (!executionContext->isSecureContext(errorMessage)) { | 315 if (!executionContext->isSecureContext(errorMessage)) { |
| 316 resolver->reject(DOMException::create(SecurityError, errorMessage)); | 316 resolver->reject(DOMException::create(SecurityError, errorMessage)); |
| 317 return promise; | 317 return promise; |
| 318 } | 318 } |
| 319 | 319 |
| 320 KURL pageURL = KURL(KURL(), documentOrigin->toString()); | 320 KURL pageURL = KURL(KURL(), documentOrigin->toString()); |
| 321 if (!SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers(pageURL.pr
otocol())) { | 321 if (!SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers(pageURL.pr
otocol())) { |
| 322 resolver->reject(DOMException::create(SecurityError, "Failed to get Serv
iceWorkerRegistration objects: The URL protocol of the current origin ('" + docu
mentOrigin->toString() + "') is not supported.")); | 322 resolver->reject(DOMException::create(SecurityError, "Failed to get Serv
iceWorkerRegistration objects: The URL protocol of the current origin ('" + docu
mentOrigin->toString() + "') is not supported.")); |
| 323 return promise; | 323 return promise; |
| 324 } | 324 } |
| 325 | 325 |
| 326 m_provider->getRegistrations(new GetRegistrationsCallback(resolver)); | 326 m_provider->getRegistrations(new GetRegistrationsCallback(resolver)); |
| 327 | 327 |
| 328 return promise; | 328 return promise; |
| 329 } | 329 } |
| 330 | 330 |
| 331 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper
ty() | 331 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper
ty() |
| 332 { | 332 { |
| 333 return new ReadyProperty(executionContext(), this, ReadyProperty::Ready); | 333 return new ReadyProperty(getExecutionContext(), this, ReadyProperty::Ready); |
| 334 } | 334 } |
| 335 | 335 |
| 336 ScriptPromise ServiceWorkerContainer::ready(ScriptState* callerState) | 336 ScriptPromise ServiceWorkerContainer::ready(ScriptState* callerState) |
| 337 { | 337 { |
| 338 if (!executionContext()) | 338 if (!getExecutionContext()) |
| 339 return ScriptPromise(); | 339 return ScriptPromise(); |
| 340 | 340 |
| 341 if (!callerState->world().isMainWorld()) { | 341 if (!callerState->world().isMainWorld()) { |
| 342 // FIXME: Support .ready from isolated worlds when | 342 // FIXME: Support .ready from isolated worlds when |
| 343 // ScriptPromiseProperty can vend Promises in isolated worlds. | 343 // ScriptPromiseProperty can vend Promises in isolated worlds. |
| 344 return ScriptPromise::rejectWithDOMException(callerState, DOMException::
create(NotSupportedError, "'ready' is only supported in pages.")); | 344 return ScriptPromise::rejectWithDOMException(callerState, DOMException::
create(NotSupportedError, "'ready' is only supported in pages.")); |
| 345 } | 345 } |
| 346 | 346 |
| 347 if (!m_ready) { | 347 if (!m_ready) { |
| 348 m_ready = createReadyProperty(); | 348 m_ready = createReadyProperty(); |
| 349 if (m_provider) | 349 if (m_provider) |
| 350 m_provider->getRegistrationForReady(new GetRegistrationForReadyCallb
ack(m_ready.get())); | 350 m_provider->getRegistrationForReady(new GetRegistrationForReadyCallb
ack(m_ready.get())); |
| 351 } | 351 } |
| 352 | 352 |
| 353 return m_ready->promise(callerState->world()); | 353 return m_ready->promise(callerState->world()); |
| 354 } | 354 } |
| 355 | 355 |
| 356 void ServiceWorkerContainer::setController(WebPassOwnPtr<WebServiceWorker::Handl
e> handle, bool shouldNotifyControllerChange) | 356 void ServiceWorkerContainer::setController(WebPassOwnPtr<WebServiceWorker::Handl
e> handle, bool shouldNotifyControllerChange) |
| 357 { | 357 { |
| 358 if (!executionContext()) | 358 if (!getExecutionContext()) |
| 359 return; | 359 return; |
| 360 m_controller = ServiceWorker::from(executionContext(), handle.release()); | 360 m_controller = ServiceWorker::from(getExecutionContext(), handle.release()); |
| 361 if (m_controller) | 361 if (m_controller) |
| 362 UseCounter::count(executionContext(), UseCounter::ServiceWorkerControlle
dPage); | 362 UseCounter::count(getExecutionContext(), UseCounter::ServiceWorkerContro
lledPage); |
| 363 if (shouldNotifyControllerChange) | 363 if (shouldNotifyControllerChange) |
| 364 dispatchEvent(Event::create(EventTypeNames::controllerchange)); | 364 dispatchEvent(Event::create(EventTypeNames::controllerchange)); |
| 365 } | 365 } |
| 366 | 366 |
| 367 void ServiceWorkerContainer::dispatchMessageEvent(WebPassOwnPtr<WebServiceWorker
::Handle> handle, const WebString& message, const WebMessagePortChannelArray& we
bChannels) | 367 void ServiceWorkerContainer::dispatchMessageEvent(WebPassOwnPtr<WebServiceWorker
::Handle> handle, const WebString& message, const WebMessagePortChannelArray& we
bChannels) |
| 368 { | 368 { |
| 369 if (!executionContext() || !executionContext()->executingWindow()) | 369 if (!getExecutionContext() || !getExecutionContext()->executingWindow()) |
| 370 return; | 370 return; |
| 371 | 371 |
| 372 MessagePortArray* ports = MessagePort::toMessagePortArray(executionContext()
, webChannels); | 372 MessagePortArray* ports = MessagePort::toMessagePortArray(getExecutionContex
t(), webChannels); |
| 373 RefPtr<SerializedScriptValue> value = SerializedScriptValueFactory::instance
().createFromWire(message); | 373 RefPtr<SerializedScriptValue> value = SerializedScriptValueFactory::instance
().createFromWire(message); |
| 374 ServiceWorker* source = ServiceWorker::from(executionContext(), handle.relea
se()); | 374 ServiceWorker* source = ServiceWorker::from(getExecutionContext(), handle.re
lease()); |
| 375 dispatchEvent(ServiceWorkerMessageEvent::create(ports, value, source, execut
ionContext()->securityOrigin()->toString())); | 375 dispatchEvent(ServiceWorkerMessageEvent::create(ports, value, source, getExe
cutionContext()->getSecurityOrigin()->toString())); |
| 376 } | 376 } |
| 377 | 377 |
| 378 const AtomicString& ServiceWorkerContainer::interfaceName() const | 378 const AtomicString& ServiceWorkerContainer::interfaceName() const |
| 379 { | 379 { |
| 380 return EventTargetNames::ServiceWorkerContainer; | 380 return EventTargetNames::ServiceWorkerContainer; |
| 381 } | 381 } |
| 382 | 382 |
| 383 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex
t) | 383 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex
t) |
| 384 : ContextLifecycleObserver(executionContext) | 384 : ContextLifecycleObserver(executionContext) |
| 385 , m_provider(0) | 385 , m_provider(0) |
| 386 { | 386 { |
| 387 | 387 |
| 388 if (!executionContext) | 388 if (!executionContext) |
| 389 return; | 389 return; |
| 390 | 390 |
| 391 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { | 391 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { |
| 392 m_provider = client->provider(); | 392 m_provider = client->provider(); |
| 393 if (m_provider) | 393 if (m_provider) |
| 394 m_provider->setClient(this); | 394 m_provider->setClient(this); |
| 395 } | 395 } |
| 396 } | 396 } |
| 397 | 397 |
| 398 } // namespace blink | 398 } // namespace blink |
| OLD | NEW |