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" | 18 #include "wtf/PtrUtil.h" |
19 #include <memory> | 19 #include <memory> |
| 20 #include <utility> |
20 | 21 |
21 namespace blink { | 22 namespace blink { |
22 | 23 |
23 bool ServiceWorkerRegistration::hasPendingActivity() const { | 24 bool ServiceWorkerRegistration::hasPendingActivity() const { |
24 return !m_stopped; | 25 return !m_stopped; |
25 } | 26 } |
26 | 27 |
27 const AtomicString& ServiceWorkerRegistration::interfaceName() const { | 28 const AtomicString& ServiceWorkerRegistration::interfaceName() const { |
28 return EventTargetNames::ServiceWorkerRegistration; | 29 return EventTargetNames::ServiceWorkerRegistration; |
29 } | 30 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 return ScriptPromise::rejectWithDOMException( | 92 return ScriptPromise::rejectWithDOMException( |
92 scriptState, | 93 scriptState, |
93 DOMException::create(InvalidStateError, | 94 DOMException::create(InvalidStateError, |
94 "Failed to update a ServiceWorkerRegistration: No " | 95 "Failed to update a ServiceWorkerRegistration: No " |
95 "associated provider is available.")); | 96 "associated provider is available.")); |
96 | 97 |
97 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 98 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
98 ScriptPromise promise = resolver->promise(); | 99 ScriptPromise promise = resolver->promise(); |
99 m_handle->registration()->update( | 100 m_handle->registration()->update( |
100 client->provider(), | 101 client->provider(), |
101 new CallbackPromiseAdapter<void, ServiceWorkerErrorForUpdate>(resolver)); | 102 WTF::makeUnique< |
| 103 CallbackPromiseAdapter<void, ServiceWorkerErrorForUpdate>>(resolver)); |
102 return promise; | 104 return promise; |
103 } | 105 } |
104 | 106 |
105 ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState) { | 107 ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState) { |
106 ServiceWorkerContainerClient* client = | 108 ServiceWorkerContainerClient* client = |
107 ServiceWorkerContainerClient::from(getExecutionContext()); | 109 ServiceWorkerContainerClient::from(getExecutionContext()); |
108 if (!client || !client->provider()) | 110 if (!client || !client->provider()) |
109 return ScriptPromise::rejectWithDOMException( | 111 return ScriptPromise::rejectWithDOMException( |
110 scriptState, DOMException::create(InvalidStateError, | 112 scriptState, DOMException::create(InvalidStateError, |
111 "Failed to unregister a " | 113 "Failed to unregister a " |
112 "ServiceWorkerRegistration: No " | 114 "ServiceWorkerRegistration: No " |
113 "associated provider is available.")); | 115 "associated provider is available.")); |
114 | 116 |
115 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 117 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
116 ScriptPromise promise = resolver->promise(); | 118 ScriptPromise promise = resolver->promise(); |
117 m_handle->registration()->unregister( | 119 m_handle->registration()->unregister( |
118 client->provider(), | 120 client->provider(), |
119 new CallbackPromiseAdapter<bool, ServiceWorkerError>(resolver)); | 121 WTF::makeUnique<CallbackPromiseAdapter<bool, ServiceWorkerError>>( |
| 122 resolver)); |
120 return promise; | 123 return promise; |
121 } | 124 } |
122 | 125 |
123 ServiceWorkerRegistration::ServiceWorkerRegistration( | 126 ServiceWorkerRegistration::ServiceWorkerRegistration( |
124 ExecutionContext* executionContext, | 127 ExecutionContext* executionContext, |
125 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) | 128 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) |
126 : ActiveScriptWrappable(this), | 129 : ActiveScriptWrappable(this), |
127 ActiveDOMObject(executionContext), | 130 ActiveDOMObject(executionContext), |
128 m_handle(std::move(handle)), | 131 m_handle(std::move(handle)), |
129 m_stopped(false) { | 132 m_stopped(false) { |
(...skipping 25 matching lines...) Expand all Loading... |
155 } | 158 } |
156 | 159 |
157 void ServiceWorkerRegistration::contextDestroyed() { | 160 void ServiceWorkerRegistration::contextDestroyed() { |
158 if (m_stopped) | 161 if (m_stopped) |
159 return; | 162 return; |
160 m_stopped = true; | 163 m_stopped = true; |
161 m_handle->registration()->proxyStopped(); | 164 m_handle->registration()->proxyStopped(); |
162 } | 165 } |
163 | 166 |
164 } // namespace blink | 167 } // namespace blink |
OLD | NEW |