Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(695)

Side by Side Diff: Source/modules/serviceworkers/ServiceWorkerRegistration.cpp

Issue 1166283006: ServiceWorker: Implement ServiceWorkerRegistration.update() (1) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
89 ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState) 108 ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState)
90 { 109 {
91 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); 110 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
92 ScriptPromise promise = resolver->promise(); 111 ScriptPromise promise = resolver->promise();
93 112
94 if (!m_provider) { 113 if (!m_provider) {
95 resolver->reject(DOMException::create(InvalidStateError, "Failed to unre gister a ServiceWorkerRegistration: No associated provider is available.")); 114 resolver->reject(DOMException::create(InvalidStateError, "Failed to unre gister a ServiceWorkerRegistration: No associated provider is available."));
96 return promise; 115 return promise;
97 } 116 }
98 117
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 180
162 void ServiceWorkerRegistration::stop() 181 void ServiceWorkerRegistration::stop()
163 { 182 {
164 if (m_stopped) 183 if (m_stopped)
165 return; 184 return;
166 m_stopped = true; 185 m_stopped = true;
167 m_outerRegistration->proxyStopped(); 186 m_outerRegistration->proxyStopped();
168 } 187 }
169 188
170 } // namespace blink 189 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerRegistration.h ('k') | Source/modules/serviceworkers/ServiceWorkerRegistration.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698