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 "config.h" | 5 #include "config.h" |
6 #include "ServiceWorkerRegistration.h" | 6 #include "ServiceWorkerRegistration.h" |
7 | 7 |
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
11 #include "bindings/core/v8/ScriptState.h" | 11 #include "bindings/core/v8/ScriptState.h" |
12 #include "core/dom/DOMException.h" | 12 #include "core/dom/DOMException.h" |
13 #include "core/dom/ExceptionCode.h" | 13 #include "core/dom/ExceptionCode.h" |
14 #include "core/dom/ExecutionContext.h" | 14 #include "core/dom/ExecutionContext.h" |
15 #include "core/events/Event.h" | 15 #include "core/events/Event.h" |
16 #include "modules/EventTargetModules.h" | 16 #include "modules/EventTargetModules.h" |
17 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" | 17 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
18 #include "modules/serviceworkers/ServiceWorkerError.h" | 18 #include "modules/serviceworkers/ServiceWorkerError.h" |
| 19 #include "platform/serviceworkers/ServiceWorkerRegistrationProxy.h" |
19 #include "public/platform/WebServiceWorkerProvider.h" | 20 #include "public/platform/WebServiceWorkerProvider.h" |
20 | 21 |
21 namespace blink { | 22 namespace blink { |
22 | 23 |
23 #ifdef DISABLE_SERVICEWORKER_UNREGISTER_RESOLVE_TO_BOOLEAN | 24 #ifdef DISABLE_SERVICEWORKER_UNREGISTER_RESOLVE_TO_BOOLEAN |
24 class UndefinedValue { | 25 class UndefinedValue { |
25 public: | 26 public: |
26 typedef WebServiceWorkerRegistration WebType; | 27 typedef WebServiceWorkerRegistration WebType; |
27 static V8UndefinedType take(ScriptPromiseResolver* resolver, WebType* regist
ration) | 28 static V8UndefinedType take(ScriptPromiseResolver* resolver, WebType* regist
ration) |
28 { | 29 { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 89 |
89 void ServiceWorkerRegistration::setActive(WebServiceWorker* serviceWorker) | 90 void ServiceWorkerRegistration::setActive(WebServiceWorker* serviceWorker) |
90 { | 91 { |
91 if (!executionContext()) { | 92 if (!executionContext()) { |
92 deleteIfNoExistingOwner(serviceWorker); | 93 deleteIfNoExistingOwner(serviceWorker); |
93 return; | 94 return; |
94 } | 95 } |
95 m_active = ServiceWorker::from(executionContext(), serviceWorker); | 96 m_active = ServiceWorker::from(executionContext(), serviceWorker); |
96 } | 97 } |
97 | 98 |
98 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::tak
e(ScriptPromiseResolver* resolver, WebType* registration) | 99 ServiceWorkerRegistration* ServiceWorkerRegistration::take(ScriptPromiseResolver
* resolver, WebType* registration) |
99 { | 100 { |
100 if (!registration) | 101 if (!registration) |
101 return nullptr; | 102 return 0; |
102 return getOrCreate(resolver->scriptState()->executionContext(), registration
); | 103 return getOrCreate(resolver->scriptState()->executionContext(), registration
); |
103 } | 104 } |
104 | 105 |
105 void ServiceWorkerRegistration::dispose(WebType* registration) | 106 void ServiceWorkerRegistration::dispose(WebType* registration) |
106 { | 107 { |
107 delete registration; | 108 delete registration; |
108 } | 109 } |
109 | 110 |
110 String ServiceWorkerRegistration::scope() const | 111 String ServiceWorkerRegistration::scope() const |
111 { | 112 { |
(...skipping 19 matching lines...) Expand all Loading... |
131 } | 132 } |
132 | 133 |
133 #ifdef DISABLE_SERVICEWORKER_UNREGISTER_RESOLVE_TO_BOOLEAN | 134 #ifdef DISABLE_SERVICEWORKER_UNREGISTER_RESOLVE_TO_BOOLEAN |
134 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Und
efinedValue, ServiceWorkerError>(resolver)); | 135 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Und
efinedValue, ServiceWorkerError>(resolver)); |
135 #else | 136 #else |
136 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Boo
leanValue, ServiceWorkerError>(resolver)); | 137 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Boo
leanValue, ServiceWorkerError>(resolver)); |
137 #endif | 138 #endif |
138 return promise; | 139 return promise; |
139 } | 140 } |
140 | 141 |
141 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::get
OrCreate(ExecutionContext* executionContext, WebServiceWorkerRegistration* outer
Registration) | 142 ServiceWorkerRegistration* ServiceWorkerRegistration::getOrCreate(ExecutionConte
xt* executionContext, WebServiceWorkerRegistration* outerRegistration) |
142 { | 143 { |
143 if (!outerRegistration) | 144 if (!outerRegistration) |
144 return nullptr; | 145 return 0; |
145 | 146 |
146 WebServiceWorkerRegistrationProxy* proxy = outerRegistration->proxy(); | 147 WebServiceWorkerRegistrationProxy* proxy = outerRegistration->proxy(); |
147 if (proxy) { | 148 if (proxy) { |
148 ServiceWorkerRegistration* existingRegistration = *proxy; | 149 ServiceWorkerRegistrationProxy* existingRegistrationProxy = *proxy; |
149 if (existingRegistration) { | 150 if (existingRegistrationProxy) { |
150 ASSERT(existingRegistration->executionContext() == executionContext)
; | 151 ASSERT(existingRegistrationProxy->registration()->executionContext()
== executionContext); |
151 return existingRegistration; | 152 return existingRegistrationProxy->registration(); |
152 } | 153 } |
153 } | 154 } |
154 | 155 |
155 RefPtrWillBeRawPtr<ServiceWorkerRegistration> registration = adoptRefWillBeN
oop(new ServiceWorkerRegistration(executionContext, adoptPtr(outerRegistration))
); | 156 ServiceWorkerRegistration* registration = adoptRefCountedGarbageCollectedWil
lBeNoop(new ServiceWorkerRegistration(executionContext, adoptPtr(outerRegistrati
on))); |
156 registration->suspendIfNeeded(); | 157 registration->suspendIfNeeded(); |
157 return registration.release(); | 158 return registration; |
158 } | 159 } |
159 | 160 |
160 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution
Context, PassOwnPtr<WebServiceWorkerRegistration> outerRegistration) | 161 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution
Context, PassOwnPtr<WebServiceWorkerRegistration> outerRegistration) |
161 : ActiveDOMObject(executionContext) | 162 : ActiveDOMObject(executionContext) |
162 , WebServiceWorkerRegistrationProxy(this) | 163 , WebServiceWorkerRegistrationProxy(ServiceWorkerRegistrationProxy::create(t
his)) |
163 , m_outerRegistration(outerRegistration) | 164 , m_outerRegistration(outerRegistration) |
164 , m_provider(0) | 165 , m_provider(0) |
165 , m_stopped(false) | 166 , m_stopped(false) |
166 { | 167 { |
167 ASSERT(m_outerRegistration); | 168 ASSERT(m_outerRegistration); |
168 ScriptWrappable::init(this); | 169 ScriptWrappable::init(this); |
169 | 170 |
170 if (!executionContext) | 171 if (!executionContext) |
171 return; | 172 return; |
172 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) | 173 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) |
(...skipping 16 matching lines...) Expand all Loading... |
189 | 190 |
190 void ServiceWorkerRegistration::stop() | 191 void ServiceWorkerRegistration::stop() |
191 { | 192 { |
192 if (m_stopped) | 193 if (m_stopped) |
193 return; | 194 return; |
194 m_stopped = true; | 195 m_stopped = true; |
195 m_outerRegistration->proxyStopped(); | 196 m_outerRegistration->proxyStopped(); |
196 } | 197 } |
197 | 198 |
198 } // namespace blink | 199 } // namespace blink |
OLD | NEW |