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

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

Issue 1143293003: Service Worker: Add ServiceWorkerContainer.getRegistrations() method. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Use provider's origin in browser instead of passing client's url from renderer. Created 5 years, 7 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 /* 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 if (!documentOrigin->canRequest(completedURL)) { 211 if (!documentOrigin->canRequest(completedURL)) {
212 RefPtr<SecurityOrigin> documentURLOrigin = SecurityOrigin::create(comple tedURL); 212 RefPtr<SecurityOrigin> documentURLOrigin = SecurityOrigin::create(comple tedURL);
213 resolver->reject(DOMException::create(SecurityError, "Failed to get a Se rviceWorkerRegistration: The origin of the provided documentURL ('" + documentUR LOrigin->toString() + "') does not match the current origin ('" + documentOrigin ->toString() + "').")); 213 resolver->reject(DOMException::create(SecurityError, "Failed to get a Se rviceWorkerRegistration: The origin of the provided documentURL ('" + documentUR LOrigin->toString() + "') does not match the current origin ('" + documentOrigin ->toString() + "')."));
214 return promise; 214 return promise;
215 } 215 }
216 m_provider->getRegistration(completedURL, new GetRegistrationCallback(resolv er)); 216 m_provider->getRegistration(completedURL, new GetRegistrationCallback(resolv er));
217 217
218 return promise; 218 return promise;
219 } 219 }
220 220
221 ScriptPromise ServiceWorkerContainer::getRegistrations(ScriptState* scriptState)
222 {
223 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled());
falken 2015/05/25 00:43:02 We should not add this, since we'd like to remove
224 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
225 ScriptPromise promise = resolver->promise();
226
227 if (!m_provider) {
228 resolver->reject(DOMException::create(InvalidStateError, "Failed to get ServiceWorkerRegistration objects: The document is in an invalid state."));
229 return promise;
230 }
231
232 ExecutionContext* executionContext = scriptState->executionContext();
233 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
234 String errorMessage;
235 if (!executionContext->isPrivilegedContext(errorMessage)) {
236 resolver->reject(DOMException::create(NotSupportedError, errorMessage));
237 return promise;
238 }
239
240 KURL pageURL = KURL(KURL(), documentOrigin->toString());
241 if (!pageURL.protocolIsInHTTPFamily()) {
242 resolver->reject(DOMException::create(SecurityError, "Failed to get Serv iceWorkerRegistration objects: The URL protocol of the current origin ('" + docu mentOrigin->toString() + "') is not supported."));
243 return promise;
244 }
245
246 m_provider->getRegistrations(new CallbackPromiseAdapter<ServiceWorkerRegistr ationArray, ServiceWorkerError>(resolver));
247
248 return promise;
249 }
250
221 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper ty() 251 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper ty()
222 { 252 {
223 return new ReadyProperty(executionContext(), this, ReadyProperty::Ready); 253 return new ReadyProperty(executionContext(), this, ReadyProperty::Ready);
224 } 254 }
225 255
226 ScriptPromise ServiceWorkerContainer::ready(ScriptState* callerState) 256 ScriptPromise ServiceWorkerContainer::ready(ScriptState* callerState)
227 { 257 {
228 if (!executionContext()) 258 if (!executionContext())
229 return ScriptPromise(); 259 return ScriptPromise();
230 260
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 return; 317 return;
288 318
289 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) { 319 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) {
290 m_provider = client->provider(); 320 m_provider = client->provider();
291 if (m_provider) 321 if (m_provider)
292 m_provider->setClient(this); 322 m_provider->setClient(this);
293 } 323 }
294 } 324 }
295 325
296 } // namespace blink 326 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698