| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | 5 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| 11 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
| 12 #include "core/dom/ExecutionContext.h" | 12 #include "core/dom/ExecutionContext.h" |
| 13 #include "core/events/Event.h" | 13 #include "core/events/Event.h" |
| 14 #include "modules/EventTargetModules.h" | 14 #include "modules/EventTargetModules.h" |
| 15 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" | 15 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
| 16 #include "modules/serviceworkers/ServiceWorkerError.h" | 16 #include "modules/serviceworkers/ServiceWorkerError.h" |
| 17 #include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h" | 17 #include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h" |
| 18 #include "wtf/PtrUtil.h" |
| 19 #include <memory> |
| 18 | 20 |
| 19 namespace blink { | 21 namespace blink { |
| 20 | 22 |
| 21 const AtomicString& ServiceWorkerRegistration::interfaceName() const | 23 const AtomicString& ServiceWorkerRegistration::interfaceName() const |
| 22 { | 24 { |
| 23 return EventTargetNames::ServiceWorkerRegistration; | 25 return EventTargetNames::ServiceWorkerRegistration; |
| 24 } | 26 } |
| 25 | 27 |
| 26 void ServiceWorkerRegistration::dispatchUpdateFoundEvent() | 28 void ServiceWorkerRegistration::dispatchUpdateFoundEvent() |
| 27 { | 29 { |
| 28 dispatchEvent(Event::create(EventTypeNames::updatefound)); | 30 dispatchEvent(Event::create(EventTypeNames::updatefound)); |
| 29 } | 31 } |
| 30 | 32 |
| 31 void ServiceWorkerRegistration::setInstalling(std::unique_ptr<WebServiceWorker::
Handle> handle) | 33 void ServiceWorkerRegistration::setInstalling(std::unique_ptr<WebServiceWorker::
Handle> handle) |
| 32 { | 34 { |
| 33 if (!getExecutionContext()) | 35 if (!getExecutionContext()) |
| 34 return; | 36 return; |
| 35 m_installing = ServiceWorker::from(getExecutionContext(), adoptPtr(handle.re
lease())); | 37 m_installing = ServiceWorker::from(getExecutionContext(), wrapUnique(handle.
release())); |
| 36 } | 38 } |
| 37 | 39 |
| 38 void ServiceWorkerRegistration::setWaiting(std::unique_ptr<WebServiceWorker::Han
dle> handle) | 40 void ServiceWorkerRegistration::setWaiting(std::unique_ptr<WebServiceWorker::Han
dle> handle) |
| 39 { | 41 { |
| 40 if (!getExecutionContext()) | 42 if (!getExecutionContext()) |
| 41 return; | 43 return; |
| 42 m_waiting = ServiceWorker::from(getExecutionContext(), adoptPtr(handle.relea
se())); | 44 m_waiting = ServiceWorker::from(getExecutionContext(), wrapUnique(handle.rel
ease())); |
| 43 } | 45 } |
| 44 | 46 |
| 45 void ServiceWorkerRegistration::setActive(std::unique_ptr<WebServiceWorker::Hand
le> handle) | 47 void ServiceWorkerRegistration::setActive(std::unique_ptr<WebServiceWorker::Hand
le> handle) |
| 46 { | 48 { |
| 47 if (!getExecutionContext()) | 49 if (!getExecutionContext()) |
| 48 return; | 50 return; |
| 49 m_active = ServiceWorker::from(getExecutionContext(), adoptPtr(handle.releas
e())); | 51 m_active = ServiceWorker::from(getExecutionContext(), wrapUnique(handle.rele
ase())); |
| 50 } | 52 } |
| 51 | 53 |
| 52 ServiceWorkerRegistration* ServiceWorkerRegistration::getOrCreate(ExecutionConte
xt* executionContext, PassOwnPtr<WebServiceWorkerRegistration::Handle> handle) | 54 ServiceWorkerRegistration* ServiceWorkerRegistration::getOrCreate(ExecutionConte
xt* executionContext, std::unique_ptr<WebServiceWorkerRegistration::Handle> hand
le) |
| 53 { | 55 { |
| 54 ASSERT(handle); | 56 ASSERT(handle); |
| 55 | 57 |
| 56 ServiceWorkerRegistration* existingRegistration = static_cast<ServiceWorkerR
egistration*>(handle->registration()->proxy()); | 58 ServiceWorkerRegistration* existingRegistration = static_cast<ServiceWorkerR
egistration*>(handle->registration()->proxy()); |
| 57 if (existingRegistration) { | 59 if (existingRegistration) { |
| 58 ASSERT(existingRegistration->getExecutionContext() == executionContext); | 60 ASSERT(existingRegistration->getExecutionContext() == executionContext); |
| 59 return existingRegistration; | 61 return existingRegistration; |
| 60 } | 62 } |
| 61 | 63 |
| 62 ServiceWorkerRegistration* newRegistration = new ServiceWorkerRegistration(e
xecutionContext, std::move(handle)); | 64 ServiceWorkerRegistration* newRegistration = new ServiceWorkerRegistration(e
xecutionContext, std::move(handle)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 86 ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::from(ge
tExecutionContext()); | 88 ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::from(ge
tExecutionContext()); |
| 87 if (!client || !client->provider()) | 89 if (!client || !client->provider()) |
| 88 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "Failed to unregister a ServiceWorkerRegistration: No
associated provider is available.")); | 90 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "Failed to unregister a ServiceWorkerRegistration: No
associated provider is available.")); |
| 89 | 91 |
| 90 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 92 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 91 ScriptPromise promise = resolver->promise(); | 93 ScriptPromise promise = resolver->promise(); |
| 92 m_handle->registration()->unregister(client->provider(), new CallbackPromise
Adapter<bool, ServiceWorkerError>(resolver)); | 94 m_handle->registration()->unregister(client->provider(), new CallbackPromise
Adapter<bool, ServiceWorkerError>(resolver)); |
| 93 return promise; | 95 return promise; |
| 94 } | 96 } |
| 95 | 97 |
| 96 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution
Context, PassOwnPtr<WebServiceWorkerRegistration::Handle> handle) | 98 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution
Context, std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) |
| 97 : ActiveScriptWrappable(this) | 99 : ActiveScriptWrappable(this) |
| 98 , ActiveDOMObject(executionContext) | 100 , ActiveDOMObject(executionContext) |
| 99 , m_handle(std::move(handle)) | 101 , m_handle(std::move(handle)) |
| 100 , m_stopped(false) | 102 , m_stopped(false) |
| 101 { | 103 { |
| 102 ASSERT(m_handle); | 104 ASSERT(m_handle); |
| 103 ASSERT(!m_handle->registration()->proxy()); | 105 ASSERT(!m_handle->registration()->proxy()); |
| 104 ThreadState::current()->registerPreFinalizer(this); | 106 ThreadState::current()->registerPreFinalizer(this); |
| 105 | 107 |
| 106 if (!executionContext) | 108 if (!executionContext) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 136 | 138 |
| 137 void ServiceWorkerRegistration::stop() | 139 void ServiceWorkerRegistration::stop() |
| 138 { | 140 { |
| 139 if (m_stopped) | 141 if (m_stopped) |
| 140 return; | 142 return; |
| 141 m_stopped = true; | 143 m_stopped = true; |
| 142 m_handle->registration()->proxyStopped(); | 144 m_handle->registration()->proxyStopped(); |
| 143 } | 145 } |
| 144 | 146 |
| 145 } // namespace blink | 147 } // namespace blink |
| OLD | NEW |