| 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> | |
| 20 | 18 |
| 21 namespace blink { | 19 namespace blink { |
| 22 | 20 |
| 23 const AtomicString& ServiceWorkerRegistration::interfaceName() const | 21 const AtomicString& ServiceWorkerRegistration::interfaceName() const |
| 24 { | 22 { |
| 25 return EventTargetNames::ServiceWorkerRegistration; | 23 return EventTargetNames::ServiceWorkerRegistration; |
| 26 } | 24 } |
| 27 | 25 |
| 28 void ServiceWorkerRegistration::dispatchUpdateFoundEvent() | 26 void ServiceWorkerRegistration::dispatchUpdateFoundEvent() |
| 29 { | 27 { |
| 30 dispatchEvent(Event::create(EventTypeNames::updatefound)); | 28 dispatchEvent(Event::create(EventTypeNames::updatefound)); |
| 31 } | 29 } |
| 32 | 30 |
| 33 void ServiceWorkerRegistration::setInstalling(std::unique_ptr<WebServiceWorker::
Handle> handle) | 31 void ServiceWorkerRegistration::setInstalling(std::unique_ptr<WebServiceWorker::
Handle> handle) |
| 34 { | 32 { |
| 35 if (!getExecutionContext()) | 33 if (!getExecutionContext()) |
| 36 return; | 34 return; |
| 37 m_installing = ServiceWorker::from(getExecutionContext(), wrapUnique(handle.
release())); | 35 m_installing = ServiceWorker::from(getExecutionContext(), adoptPtr(handle.re
lease())); |
| 38 } | 36 } |
| 39 | 37 |
| 40 void ServiceWorkerRegistration::setWaiting(std::unique_ptr<WebServiceWorker::Han
dle> handle) | 38 void ServiceWorkerRegistration::setWaiting(std::unique_ptr<WebServiceWorker::Han
dle> handle) |
| 41 { | 39 { |
| 42 if (!getExecutionContext()) | 40 if (!getExecutionContext()) |
| 43 return; | 41 return; |
| 44 m_waiting = ServiceWorker::from(getExecutionContext(), wrapUnique(handle.rel
ease())); | 42 m_waiting = ServiceWorker::from(getExecutionContext(), adoptPtr(handle.relea
se())); |
| 45 } | 43 } |
| 46 | 44 |
| 47 void ServiceWorkerRegistration::setActive(std::unique_ptr<WebServiceWorker::Hand
le> handle) | 45 void ServiceWorkerRegistration::setActive(std::unique_ptr<WebServiceWorker::Hand
le> handle) |
| 48 { | 46 { |
| 49 if (!getExecutionContext()) | 47 if (!getExecutionContext()) |
| 50 return; | 48 return; |
| 51 m_active = ServiceWorker::from(getExecutionContext(), wrapUnique(handle.rele
ase())); | 49 m_active = ServiceWorker::from(getExecutionContext(), adoptPtr(handle.releas
e())); |
| 52 } | 50 } |
| 53 | 51 |
| 54 ServiceWorkerRegistration* ServiceWorkerRegistration::getOrCreate(ExecutionConte
xt* executionContext, std::unique_ptr<WebServiceWorkerRegistration::Handle> hand
le) | 52 ServiceWorkerRegistration* ServiceWorkerRegistration::getOrCreate(ExecutionConte
xt* executionContext, PassOwnPtr<WebServiceWorkerRegistration::Handle> handle) |
| 55 { | 53 { |
| 56 ASSERT(handle); | 54 ASSERT(handle); |
| 57 | 55 |
| 58 ServiceWorkerRegistration* existingRegistration = static_cast<ServiceWorkerR
egistration*>(handle->registration()->proxy()); | 56 ServiceWorkerRegistration* existingRegistration = static_cast<ServiceWorkerR
egistration*>(handle->registration()->proxy()); |
| 59 if (existingRegistration) { | 57 if (existingRegistration) { |
| 60 ASSERT(existingRegistration->getExecutionContext() == executionContext); | 58 ASSERT(existingRegistration->getExecutionContext() == executionContext); |
| 61 return existingRegistration; | 59 return existingRegistration; |
| 62 } | 60 } |
| 63 | 61 |
| 64 ServiceWorkerRegistration* newRegistration = new ServiceWorkerRegistration(e
xecutionContext, std::move(handle)); | 62 ServiceWorkerRegistration* newRegistration = new ServiceWorkerRegistration(e
xecutionContext, std::move(handle)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 88 ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::from(ge
tExecutionContext()); | 86 ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::from(ge
tExecutionContext()); |
| 89 if (!client || !client->provider()) | 87 if (!client || !client->provider()) |
| 90 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "Failed to unregister a ServiceWorkerRegistration: No
associated provider is available.")); | 88 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "Failed to unregister a ServiceWorkerRegistration: No
associated provider is available.")); |
| 91 | 89 |
| 92 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 90 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 93 ScriptPromise promise = resolver->promise(); | 91 ScriptPromise promise = resolver->promise(); |
| 94 m_handle->registration()->unregister(client->provider(), new CallbackPromise
Adapter<bool, ServiceWorkerError>(resolver)); | 92 m_handle->registration()->unregister(client->provider(), new CallbackPromise
Adapter<bool, ServiceWorkerError>(resolver)); |
| 95 return promise; | 93 return promise; |
| 96 } | 94 } |
| 97 | 95 |
| 98 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution
Context, std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) | 96 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution
Context, PassOwnPtr<WebServiceWorkerRegistration::Handle> handle) |
| 99 : ActiveScriptWrappable(this) | 97 : ActiveScriptWrappable(this) |
| 100 , ActiveDOMObject(executionContext) | 98 , ActiveDOMObject(executionContext) |
| 101 , m_handle(std::move(handle)) | 99 , m_handle(std::move(handle)) |
| 102 , m_stopped(false) | 100 , m_stopped(false) |
| 103 { | 101 { |
| 104 ASSERT(m_handle); | 102 ASSERT(m_handle); |
| 105 ASSERT(!m_handle->registration()->proxy()); | 103 ASSERT(!m_handle->registration()->proxy()); |
| 106 ThreadState::current()->registerPreFinalizer(this); | 104 ThreadState::current()->registerPreFinalizer(this); |
| 107 | 105 |
| 108 if (!executionContext) | 106 if (!executionContext) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 138 | 136 |
| 139 void ServiceWorkerRegistration::stop() | 137 void ServiceWorkerRegistration::stop() |
| 140 { | 138 { |
| 141 if (m_stopped) | 139 if (m_stopped) |
| 142 return; | 140 return; |
| 143 m_stopped = true; | 141 m_stopped = true; |
| 144 m_handle->registration()->proxyStopped(); | 142 m_handle->registration()->proxyStopped(); |
| 145 } | 143 } |
| 146 | 144 |
| 147 } // namespace blink | 145 } // namespace blink |
| OLD | NEW |