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

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

Issue 515083002: ServiceWorker: Change the return value of ServiceWorkerRegistration::unregister to boolean (1/4) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Incorporate the reviews in patch set 3, and rebase Created 6 years, 3 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
« no previous file with comments | « no previous file | Source/modules/serviceworkers/ServiceWorkerRegistration.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 if (!documentOrigin->canRequest(scriptURL)) { 117 if (!documentOrigin->canRequest(scriptURL)) {
118 resolver->reject(DOMException::create(SecurityError, "The origin of the script must match the current origin.")); 118 resolver->reject(DOMException::create(SecurityError, "The origin of the script must match the current origin."));
119 return promise; 119 return promise;
120 } 120 }
121 121
122 m_provider->registerServiceWorker(patternURL, scriptURL, new CallbackPromise Adapter<ServiceWorkerRegistration, ServiceWorkerError>(resolver)); 122 m_provider->registerServiceWorker(patternURL, scriptURL, new CallbackPromise Adapter<ServiceWorkerRegistration, ServiceWorkerError>(resolver));
123 123
124 return promise; 124 return promise;
125 } 125 }
126 126
127 #ifdef DISABLE_SERVICEWORKER_UNREGISTER_RESOLVE_TO_BOOLEAN
127 class UndefinedValue { 128 class UndefinedValue {
128 public: 129 public:
129 typedef WebServiceWorkerRegistration WebType; 130 typedef WebServiceWorkerRegistration WebType;
130 static V8UndefinedType take(ScriptPromiseResolver* resolver, WebType* regist ration) 131 static V8UndefinedType take(ScriptPromiseResolver* resolver, WebType* regist ration)
131 { 132 {
132 ASSERT(!registration); // Anything passed here will be leaked. 133 ASSERT(!registration); // Anything passed here will be leaked.
133 return V8UndefinedType(); 134 return V8UndefinedType();
134 } 135 }
135 static void dispose(WebType* registration) 136 static void dispose(WebType* registration)
136 { 137 {
137 ASSERT(!registration); // Anything passed here will be leaked. 138 ASSERT(!registration); // Anything passed here will be leaked.
138 } 139 }
139 140
140 private: 141 private:
141 UndefinedValue(); 142 UndefinedValue();
142 }; 143 };
144 #else
145 class BooleanValue {
146 public:
147 typedef bool WebType;
148 static bool take(ScriptPromiseResolver* resolver, WebType* boolean)
149 {
150 return *boolean;
151 }
152 static void dispose(WebType* boolean) { }
153
154 private:
155 BooleanValue();
156 };
157 #endif
143 158
144 ScriptPromise ServiceWorkerContainer::unregisterServiceWorker(ScriptState* scrip tState, const String& pattern) 159 ScriptPromise ServiceWorkerContainer::unregisterServiceWorker(ScriptState* scrip tState, const String& pattern)
145 { 160 {
146 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); 161 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled());
147 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); 162 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
148 ScriptPromise promise = resolver->promise(); 163 ScriptPromise promise = resolver->promise();
149 164
150 if (!m_provider) { 165 if (!m_provider) {
151 resolver->reject(DOMException::create(InvalidStateError, "No associated provider is available")); 166 resolver->reject(DOMException::create(InvalidStateError, "No associated provider is available"));
152 return promise; 167 return promise;
153 } 168 }
154 169
155 // FIXME: This should use the container's execution context, not 170 // FIXME: This should use the container's execution context, not
156 // the callers. 171 // the callers.
157 RefPtr<SecurityOrigin> documentOrigin = scriptState->executionContext()->sec urityOrigin(); 172 RefPtr<SecurityOrigin> documentOrigin = scriptState->executionContext()->sec urityOrigin();
158 String errorMessage; 173 String errorMessage;
159 if (!documentOrigin->canAccessFeatureRequiringSecureOrigin(errorMessage)) { 174 if (!documentOrigin->canAccessFeatureRequiringSecureOrigin(errorMessage)) {
160 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); 175 resolver->reject(DOMException::create(NotSupportedError, errorMessage));
161 return promise; 176 return promise;
162 } 177 }
163 178
164 KURL patternURL = scriptState->executionContext()->completeURL(pattern); 179 KURL patternURL = scriptState->executionContext()->completeURL(pattern);
165 patternURL.removeFragmentIdentifier(); 180 patternURL.removeFragmentIdentifier();
166 if (!pattern.isEmpty() && !documentOrigin->canRequest(patternURL)) { 181 if (!pattern.isEmpty() && !documentOrigin->canRequest(patternURL)) {
167 resolver->reject(DOMException::create(SecurityError, "The scope must mat ch the current origin.")); 182 resolver->reject(DOMException::create(SecurityError, "The scope must mat ch the current origin."));
168 return promise; 183 return promise;
169 } 184 }
170 185 #ifdef DISABLE_SERVICEWORKER_UNREGISTER_RESOLVE_TO_BOOLEAN
171 m_provider->unregisterServiceWorker(patternURL, new CallbackPromiseAdapter<U ndefinedValue, ServiceWorkerError>(resolver)); 186 m_provider->unregisterServiceWorker(patternURL, new CallbackPromiseAdapter<U ndefinedValue, ServiceWorkerError>(resolver));
187 #else
188 m_provider->unregisterServiceWorker(patternURL, new CallbackPromiseAdapter<B ooleanValue, ServiceWorkerError>(resolver));
189 #endif
172 return promise; 190 return promise;
173 } 191 }
174 192
175 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper ty() 193 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper ty()
176 { 194 {
177 return new ReadyProperty(executionContext(), this, ReadyProperty::Ready); 195 return new ReadyProperty(executionContext(), this, ReadyProperty::Ready);
178 } 196 }
179 197
180 ScriptPromise ServiceWorkerContainer::ready(ScriptState* callerState) 198 ScriptPromise ServiceWorkerContainer::ready(ScriptState* callerState)
181 { 199 {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 m_ready = createReadyProperty(); 295 m_ready = createReadyProperty();
278 296
279 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) { 297 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) {
280 m_provider = client->provider(); 298 m_provider = client->provider();
281 if (m_provider) 299 if (m_provider)
282 m_provider->setClient(this); 300 m_provider->setClient(this);
283 } 301 }
284 } 302 }
285 303
286 } // namespace blink 304 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/modules/serviceworkers/ServiceWorkerRegistration.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698