| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 { | 79 { |
| 80 if (registration && !registration->proxy()) | 80 if (registration && !registration->proxy()) |
| 81 delete registration; | 81 delete registration; |
| 82 } | 82 } |
| 83 | 83 |
| 84 String ServiceWorkerRegistration::scope() const | 84 String ServiceWorkerRegistration::scope() const |
| 85 { | 85 { |
| 86 return m_outerRegistration->scope().string(); | 86 return m_outerRegistration->scope().string(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void ServiceWorkerRegistration::update(ScriptState* scriptState, ExceptionState&
exceptionState) | |
| 90 { | |
| 91 if (!m_provider) { | |
| 92 exceptionState.throwDOMException(InvalidStateError, "Failed to update a
ServiceWorkerRegistration: No associated provider is available."); | |
| 93 return; | |
| 94 } | |
| 95 | |
| 96 RefPtr<SecurityOrigin> documentOrigin = scriptState->executionContext()->sec
urityOrigin(); | |
| 97 KURL scopeURL = scriptState->executionContext()->completeURL(scope()); | |
| 98 scopeURL.removeFragmentIdentifier(); | |
| 99 if (!scope().isEmpty() && !documentOrigin->canRequest(scopeURL)) { | |
| 100 RefPtr<SecurityOrigin> scopeOrigin = SecurityOrigin::create(scopeURL); | |
| 101 exceptionState.throwSecurityError("Failed to update a ServiceWorkerRegis
tration: The origin of the registration's scope ('" + scopeOrigin->toString() +
"') does not match the current origin ('" + documentOrigin->toString() + "')."); | |
| 102 return; | |
| 103 } | |
| 104 | |
| 105 m_provider->updateServiceWorker(scopeURL); | |
| 106 } | |
| 107 | |
| 108 ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState) | 89 ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState) |
| 109 { | 90 { |
| 110 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 91 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
| 111 ScriptPromise promise = resolver->promise(); | 92 ScriptPromise promise = resolver->promise(); |
| 112 | 93 |
| 113 if (!m_provider) { | 94 if (!m_provider) { |
| 114 resolver->reject(DOMException::create(InvalidStateError, "Failed to unre
gister a ServiceWorkerRegistration: No associated provider is available.")); | 95 resolver->reject(DOMException::create(InvalidStateError, "Failed to unre
gister a ServiceWorkerRegistration: No associated provider is available.")); |
| 115 return promise; | 96 return promise; |
| 116 } | 97 } |
| 117 | 98 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 161 |
| 181 void ServiceWorkerRegistration::stop() | 162 void ServiceWorkerRegistration::stop() |
| 182 { | 163 { |
| 183 if (m_stopped) | 164 if (m_stopped) |
| 184 return; | 165 return; |
| 185 m_stopped = true; | 166 m_stopped = true; |
| 186 m_outerRegistration->proxyStopped(); | 167 m_outerRegistration->proxyStopped(); |
| 187 } | 168 } |
| 188 | 169 |
| 189 } // namespace blink | 170 } // namespace blink |
| OLD | NEW |