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" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState) | 98 ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState) |
99 { | 99 { |
100 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 100 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
101 ScriptPromise promise = resolver->promise(); | 101 ScriptPromise promise = resolver->promise(); |
102 | 102 |
103 if (!m_provider) { | 103 if (!m_provider) { |
104 resolver->reject(DOMException::create(InvalidStateError, "Failed to unre
gister a ServiceWorkerRegistration: No associated provider is available.")); | 104 resolver->reject(DOMException::create(InvalidStateError, "Failed to unre
gister a ServiceWorkerRegistration: No associated provider is available.")); |
105 return promise; | 105 return promise; |
106 } | 106 } |
107 | 107 |
108 RefPtr<SecurityOrigin> documentOrigin = scriptState->executionContext()->sec
urityOrigin(); | 108 m_outerRegistration->unregister(m_provider, new CallbackPromiseAdapter<bool,
ServiceWorkerError>(resolver)); |
109 KURL scopeURL = scriptState->executionContext()->completeURL(scope()); | |
110 scopeURL.removeFragmentIdentifier(); | |
111 if (!scope().isEmpty() && !documentOrigin->canRequest(scopeURL)) { | |
112 RefPtr<SecurityOrigin> scopeOrigin = SecurityOrigin::create(scopeURL); | |
113 resolver->reject(DOMException::create(SecurityError, "Failed to unregist
er a ServiceWorkerRegistration: The origin of the registration's scope ('" + sco
peOrigin->toString() + "') does not match the current origin ('" + documentOrigi
n->toString() + "').")); | |
114 return promise; | |
115 } | |
116 | |
117 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<boo
l, ServiceWorkerError>(resolver)); | |
118 return promise; | 109 return promise; |
119 } | 110 } |
120 | 111 |
121 ServiceWorkerRegistration* ServiceWorkerRegistration::getOrCreate(ExecutionConte
xt* executionContext, WebServiceWorkerRegistration* outerRegistration) | 112 ServiceWorkerRegistration* ServiceWorkerRegistration::getOrCreate(ExecutionConte
xt* executionContext, WebServiceWorkerRegistration* outerRegistration) |
122 { | 113 { |
123 if (!outerRegistration) | 114 if (!outerRegistration) |
124 return 0; | 115 return 0; |
125 | 116 |
126 ServiceWorkerRegistration* existingRegistration = static_cast<ServiceWorkerR
egistration*>(outerRegistration->proxy()); | 117 ServiceWorkerRegistration* existingRegistration = static_cast<ServiceWorkerR
egistration*>(outerRegistration->proxy()); |
127 if (existingRegistration) { | 118 if (existingRegistration) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 161 |
171 void ServiceWorkerRegistration::stop() | 162 void ServiceWorkerRegistration::stop() |
172 { | 163 { |
173 if (m_stopped) | 164 if (m_stopped) |
174 return; | 165 return; |
175 m_stopped = true; | 166 m_stopped = true; |
176 m_outerRegistration->proxyStopped(); | 167 m_outerRegistration->proxyStopped(); |
177 } | 168 } |
178 | 169 |
179 } // namespace blink | 170 } // namespace blink |
OLD | NEW |