| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 #include "public/platform/modules/serviceworker/WebServiceWorkerRegistration.h" | 57 #include "public/platform/modules/serviceworker/WebServiceWorkerRegistration.h" |
| 58 | 58 |
| 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(std::unique_ptr<WebServiceWorkerRegistration::Handle> handle)
override |
| 68 { | 68 { |
| 69 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) | 69 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) |
| 70 return; | 70 return; |
| 71 m_resolver->resolve(ServiceWorkerRegistration::getOrCreate(m_resolver->g
etExecutionContext(), handle.release())); | 71 m_resolver->resolve(ServiceWorkerRegistration::getOrCreate(m_resolver->g
etExecutionContext(), adoptPtr(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->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) | 76 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) |
| 77 return; | 77 return; |
| 78 if (error.errorType == WebServiceWorkerError::ErrorTypeType) { | 78 if (error.errorType == WebServiceWorkerError::ErrorTypeType) { |
| 79 m_resolver->reject(V8ThrowException::createTypeError(m_resolver->get
ScriptState()->isolate(), error.message)); | 79 m_resolver->reject(V8ThrowException::createTypeError(m_resolver->get
ScriptState()->isolate(), error.message)); |
| 80 } else { | 80 } else { |
| 81 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)
); | 81 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)
); |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 Persistent<ScriptPromiseResolver> m_resolver; | 86 Persistent<ScriptPromiseResolver> m_resolver; |
| 87 WTF_MAKE_NONCOPYABLE(RegistrationCallback); | 87 WTF_MAKE_NONCOPYABLE(RegistrationCallback); |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 class GetRegistrationCallback : public WebServiceWorkerProvider::WebServiceWorke
rGetRegistrationCallbacks { | 90 class GetRegistrationCallback : public WebServiceWorkerProvider::WebServiceWorke
rGetRegistrationCallbacks { |
| 91 public: | 91 public: |
| 92 explicit GetRegistrationCallback(ScriptPromiseResolver* resolver) | 92 explicit GetRegistrationCallback(ScriptPromiseResolver* resolver) |
| 93 : m_resolver(resolver) { } | 93 : m_resolver(resolver) { } |
| 94 ~GetRegistrationCallback() override { } | 94 ~GetRegistrationCallback() override { } |
| 95 | 95 |
| 96 void onSuccess(WebPassOwnPtr<WebServiceWorkerRegistration::Handle> webPassHa
ndle) override | 96 void onSuccess(std::unique_ptr<WebServiceWorkerRegistration::Handle> webPass
Handle) override |
| 97 { | 97 { |
| 98 OwnPtr<WebServiceWorkerRegistration::Handle> handle = webPassHandle.rele
ase(); | 98 OwnPtr<WebServiceWorkerRegistration::Handle> handle = adoptPtr(webPassHa
ndle.release()); |
| 99 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) | 99 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) |
| 100 return; | 100 return; |
| 101 if (!handle) { | 101 if (!handle) { |
| 102 // Resolve the promise with undefined. | 102 // Resolve the promise with undefined. |
| 103 m_resolver->resolve(); | 103 m_resolver->resolve(); |
| 104 return; | 104 return; |
| 105 } | 105 } |
| 106 m_resolver->resolve(ServiceWorkerRegistration::getOrCreate(m_resolver->g
etExecutionContext(), handle.release())); | 106 m_resolver->resolve(ServiceWorkerRegistration::getOrCreate(m_resolver->g
etExecutionContext(), handle.release())); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void onError(const WebServiceWorkerError& error) override | 109 void onError(const WebServiceWorkerError& error) override |
| 110 { | 110 { |
| 111 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) | 111 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) |
| 112 return; | 112 return; |
| 113 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)); | 113 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)); |
| 114 } | 114 } |
| 115 | 115 |
| 116 private: | 116 private: |
| 117 Persistent<ScriptPromiseResolver> m_resolver; | 117 Persistent<ScriptPromiseResolver> m_resolver; |
| 118 WTF_MAKE_NONCOPYABLE(GetRegistrationCallback); | 118 WTF_MAKE_NONCOPYABLE(GetRegistrationCallback); |
| 119 }; | 119 }; |
| 120 | 120 |
| 121 class GetRegistrationsCallback : public WebServiceWorkerProvider::WebServiceWork
erGetRegistrationsCallbacks { | 121 class GetRegistrationsCallback : public WebServiceWorkerProvider::WebServiceWork
erGetRegistrationsCallbacks { |
| 122 public: | 122 public: |
| 123 explicit GetRegistrationsCallback(ScriptPromiseResolver* resolver) | 123 explicit GetRegistrationsCallback(ScriptPromiseResolver* resolver) |
| 124 : m_resolver(resolver) { } | 124 : m_resolver(resolver) { } |
| 125 ~GetRegistrationsCallback() override { } | 125 ~GetRegistrationsCallback() override { } |
| 126 | 126 |
| 127 void onSuccess(WebPassOwnPtr<WebVector<WebServiceWorkerRegistration::Handle*
>> webPassRegistrations) override | 127 void onSuccess(std::unique_ptr<WebVector<WebServiceWorkerRegistration::Handl
e*>> webPassRegistrations) override |
| 128 { | 128 { |
| 129 Vector<OwnPtr<WebServiceWorkerRegistration::Handle>> handles; | 129 Vector<OwnPtr<WebServiceWorkerRegistration::Handle>> handles; |
| 130 OwnPtr<WebVector<WebServiceWorkerRegistration::Handle*>> webRegistration
s = webPassRegistrations.release(); | 130 OwnPtr<WebVector<WebServiceWorkerRegistration::Handle*>> webRegistration
s = adoptPtr(webPassRegistrations.release()); |
| 131 for (auto& handle : *webRegistrations) { | 131 for (auto& handle : *webRegistrations) { |
| 132 handles.append(adoptPtr(handle)); | 132 handles.append(adoptPtr(handle)); |
| 133 } | 133 } |
| 134 | 134 |
| 135 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) | 135 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) |
| 136 return; | 136 return; |
| 137 m_resolver->resolve(ServiceWorkerRegistrationArray::take(m_resolver.get(
), &handles)); | 137 m_resolver->resolve(ServiceWorkerRegistrationArray::take(m_resolver.get(
), &handles)); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void onError(const WebServiceWorkerError& error) override | 140 void onError(const WebServiceWorkerError& error) override |
| 141 { | 141 { |
| 142 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) | 142 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) |
| 143 return; | 143 return; |
| 144 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)); | 144 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)); |
| 145 } | 145 } |
| 146 | 146 |
| 147 private: | 147 private: |
| 148 Persistent<ScriptPromiseResolver> m_resolver; | 148 Persistent<ScriptPromiseResolver> m_resolver; |
| 149 WTF_MAKE_NONCOPYABLE(GetRegistrationsCallback); | 149 WTF_MAKE_NONCOPYABLE(GetRegistrationsCallback); |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 class ServiceWorkerContainer::GetRegistrationForReadyCallback : public WebServic
eWorkerProvider::WebServiceWorkerGetRegistrationForReadyCallbacks { | 152 class ServiceWorkerContainer::GetRegistrationForReadyCallback : public WebServic
eWorkerProvider::WebServiceWorkerGetRegistrationForReadyCallbacks { |
| 153 public: | 153 public: |
| 154 explicit GetRegistrationForReadyCallback(ReadyProperty* ready) | 154 explicit GetRegistrationForReadyCallback(ReadyProperty* ready) |
| 155 : m_ready(ready) { } | 155 : m_ready(ready) { } |
| 156 ~GetRegistrationForReadyCallback() override { } | 156 ~GetRegistrationForReadyCallback() override { } |
| 157 | 157 |
| 158 void onSuccess(WebPassOwnPtr<WebServiceWorkerRegistration::Handle> handle) o
verride | 158 void onSuccess(std::unique_ptr<WebServiceWorkerRegistration::Handle> handle)
override |
| 159 { | 159 { |
| 160 ASSERT(m_ready->getState() == ReadyProperty::Pending); | 160 ASSERT(m_ready->getState() == ReadyProperty::Pending); |
| 161 | 161 |
| 162 if (m_ready->getExecutionContext() && !m_ready->getExecutionContext()->a
ctiveDOMObjectsAreStopped()) | 162 if (m_ready->getExecutionContext() && !m_ready->getExecutionContext()->a
ctiveDOMObjectsAreStopped()) |
| 163 m_ready->resolve(ServiceWorkerRegistration::getOrCreate(m_ready->get
ExecutionContext(), handle.release())); | 163 m_ready->resolve(ServiceWorkerRegistration::getOrCreate(m_ready->get
ExecutionContext(), adoptPtr(handle.release()))); |
| 164 } | 164 } |
| 165 | 165 |
| 166 private: | 166 private: |
| 167 Persistent<ReadyProperty> m_ready; | 167 Persistent<ReadyProperty> m_ready; |
| 168 WTF_MAKE_NONCOPYABLE(GetRegistrationForReadyCallback); | 168 WTF_MAKE_NONCOPYABLE(GetRegistrationForReadyCallback); |
| 169 }; | 169 }; |
| 170 | 170 |
| 171 ServiceWorkerContainer* ServiceWorkerContainer::create(ExecutionContext* executi
onContext) | 171 ServiceWorkerContainer* ServiceWorkerContainer::create(ExecutionContext* executi
onContext) |
| 172 { | 172 { |
| 173 return new ServiceWorkerContainer(executionContext); | 173 return new ServiceWorkerContainer(executionContext); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 | 365 |
| 366 if (!m_ready) { | 366 if (!m_ready) { |
| 367 m_ready = createReadyProperty(); | 367 m_ready = createReadyProperty(); |
| 368 if (m_provider) | 368 if (m_provider) |
| 369 m_provider->getRegistrationForReady(new GetRegistrationForReadyCallb
ack(m_ready.get())); | 369 m_provider->getRegistrationForReady(new GetRegistrationForReadyCallb
ack(m_ready.get())); |
| 370 } | 370 } |
| 371 | 371 |
| 372 return m_ready->promise(callerState->world()); | 372 return m_ready->promise(callerState->world()); |
| 373 } | 373 } |
| 374 | 374 |
| 375 void ServiceWorkerContainer::setController(WebPassOwnPtr<WebServiceWorker::Handl
e> handle, bool shouldNotifyControllerChange) | 375 void ServiceWorkerContainer::setController(std::unique_ptr<WebServiceWorker::Han
dle> handle, bool shouldNotifyControllerChange) |
| 376 { | 376 { |
| 377 if (!getExecutionContext()) | 377 if (!getExecutionContext()) |
| 378 return; | 378 return; |
| 379 m_controller = ServiceWorker::from(getExecutionContext(), handle.release()); | 379 m_controller = ServiceWorker::from(getExecutionContext(), adoptPtr(handle.re
lease())); |
| 380 if (m_controller) | 380 if (m_controller) |
| 381 UseCounter::count(getExecutionContext(), UseCounter::ServiceWorkerContro
lledPage); | 381 UseCounter::count(getExecutionContext(), UseCounter::ServiceWorkerContro
lledPage); |
| 382 if (shouldNotifyControllerChange) | 382 if (shouldNotifyControllerChange) |
| 383 dispatchEvent(Event::create(EventTypeNames::controllerchange)); | 383 dispatchEvent(Event::create(EventTypeNames::controllerchange)); |
| 384 } | 384 } |
| 385 | 385 |
| 386 void ServiceWorkerContainer::dispatchMessageEvent(WebPassOwnPtr<WebServiceWorker
::Handle> handle, const WebString& message, const WebMessagePortChannelArray& we
bChannels) | 386 void ServiceWorkerContainer::dispatchMessageEvent(std::unique_ptr<WebServiceWork
er::Handle> handle, const WebString& message, const WebMessagePortChannelArray&
webChannels) |
| 387 { | 387 { |
| 388 if (!getExecutionContext() || !getExecutionContext()->executingWindow()) | 388 if (!getExecutionContext() || !getExecutionContext()->executingWindow()) |
| 389 return; | 389 return; |
| 390 | 390 |
| 391 MessagePortArray* ports = MessagePort::toMessagePortArray(getExecutionContex
t(), webChannels); | 391 MessagePortArray* ports = MessagePort::toMessagePortArray(getExecutionContex
t(), webChannels); |
| 392 RefPtr<SerializedScriptValue> value = SerializedScriptValueFactory::instance
().createFromWire(message); | 392 RefPtr<SerializedScriptValue> value = SerializedScriptValueFactory::instance
().createFromWire(message); |
| 393 ServiceWorker* source = ServiceWorker::from(getExecutionContext(), handle.re
lease()); | 393 ServiceWorker* source = ServiceWorker::from(getExecutionContext(), adoptPtr(
handle.release())); |
| 394 dispatchEvent(ServiceWorkerMessageEvent::create(ports, value, source, getExe
cutionContext()->getSecurityOrigin()->toString())); | 394 dispatchEvent(ServiceWorkerMessageEvent::create(ports, value, source, getExe
cutionContext()->getSecurityOrigin()->toString())); |
| 395 } | 395 } |
| 396 | 396 |
| 397 const AtomicString& ServiceWorkerContainer::interfaceName() const | 397 const AtomicString& ServiceWorkerContainer::interfaceName() const |
| 398 { | 398 { |
| 399 return EventTargetNames::ServiceWorkerContainer; | 399 return EventTargetNames::ServiceWorkerContainer; |
| 400 } | 400 } |
| 401 | 401 |
| 402 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex
t) | 402 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex
t) |
| 403 : ContextLifecycleObserver(executionContext) | 403 : ContextLifecycleObserver(executionContext) |
| 404 , m_provider(0) | 404 , m_provider(0) |
| 405 { | 405 { |
| 406 | 406 |
| 407 if (!executionContext) | 407 if (!executionContext) |
| 408 return; | 408 return; |
| 409 | 409 |
| 410 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { | 410 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { |
| 411 m_provider = client->provider(); | 411 m_provider = client->provider(); |
| 412 if (m_provider) | 412 if (m_provider) |
| 413 m_provider->setClient(this); | 413 m_provider->setClient(this); |
| 414 } | 414 } |
| 415 } | 415 } |
| 416 | 416 |
| 417 } // namespace blink | 417 } // namespace blink |
| OLD | NEW |