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

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

Issue 1191793003: [Service Worker Registration] removed protocolIsInHTTPFamily and replaced with SchemeRegistry check (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Comments Created 5 years, 5 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/platform/weborigin/SchemeRegistry.h » ('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 30 matching lines...) Expand all
41 #include "core/dom/ExecutionContext.h" 41 #include "core/dom/ExecutionContext.h"
42 #include "core/dom/MessagePort.h" 42 #include "core/dom/MessagePort.h"
43 #include "core/events/MessageEvent.h" 43 #include "core/events/MessageEvent.h"
44 #include "core/frame/LocalDOMWindow.h" 44 #include "core/frame/LocalDOMWindow.h"
45 #include "modules/EventTargetModules.h" 45 #include "modules/EventTargetModules.h"
46 #include "modules/serviceworkers/ServiceWorker.h" 46 #include "modules/serviceworkers/ServiceWorker.h"
47 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" 47 #include "modules/serviceworkers/ServiceWorkerContainerClient.h"
48 #include "modules/serviceworkers/ServiceWorkerError.h" 48 #include "modules/serviceworkers/ServiceWorkerError.h"
49 #include "modules/serviceworkers/ServiceWorkerRegistration.h" 49 #include "modules/serviceworkers/ServiceWorkerRegistration.h"
50 #include "platform/RuntimeEnabledFeatures.h" 50 #include "platform/RuntimeEnabledFeatures.h"
51 #include "platform/weborigin/SchemeRegistry.h"
51 #include "public/platform/WebServiceWorker.h" 52 #include "public/platform/WebServiceWorker.h"
52 #include "public/platform/WebServiceWorkerProvider.h" 53 #include "public/platform/WebServiceWorkerProvider.h"
53 #include "public/platform/WebServiceWorkerRegistration.h" 54 #include "public/platform/WebServiceWorkerRegistration.h"
54 #include "public/platform/WebString.h" 55 #include "public/platform/WebString.h"
55 #include "public/platform/WebURL.h" 56 #include "public/platform/WebURL.h"
56 57
57 namespace blink { 58 namespace blink {
58 59
59 class RegistrationCallback : public WebServiceWorkerProvider::WebServiceWorkerRe gistrationCallbacks { 60 class RegistrationCallback : public WebServiceWorkerProvider::WebServiceWorkerRe gistrationCallbacks {
60 public: 61 public:
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 return promise; 207 return promise;
207 } 208 }
208 209
209 ExecutionContext* executionContext = scriptState->executionContext(); 210 ExecutionContext* executionContext = scriptState->executionContext();
210 // FIXME: May be null due to worker termination: http://crbug.com/413518. 211 // FIXME: May be null due to worker termination: http://crbug.com/413518.
211 if (!executionContext) 212 if (!executionContext)
212 return ScriptPromise(); 213 return ScriptPromise();
213 214
214 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); 215 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
215 String errorMessage; 216 String errorMessage;
217 // Restrict to secure origins: https://w3c.github.io/webappsec/specs/powerfu lfeatures/#settings-privileged
216 if (!executionContext->isPrivilegedContext(errorMessage)) { 218 if (!executionContext->isPrivilegedContext(errorMessage)) {
217 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); 219 resolver->reject(DOMException::create(NotSupportedError, errorMessage));
218 return promise; 220 return promise;
219 } 221 }
220 222
221 KURL pageURL = KURL(KURL(), documentOrigin->toString()); 223 KURL pageURL = KURL(KURL(), documentOrigin->toString());
222 if (!pageURL.protocolIsInHTTPFamily()) { 224 if (!SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers(pageURL.pr otocol())) {
223 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The URL protocol of the current origin ('" + documentOrigin->t oString() + "') is not supported.")); 225 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The URL protocol of the current origin ('" + documentOrigin->t oString() + "') is not supported."));
224 return promise; 226 return promise;
225 } 227 }
226 228
227 KURL scriptURL = callingExecutionContext(scriptState->isolate())->completeUR L(url); 229 KURL scriptURL = callingExecutionContext(scriptState->isolate())->completeUR L(url);
228 scriptURL.removeFragmentIdentifier(); 230 scriptURL.removeFragmentIdentifier();
229 if (!documentOrigin->canRequest(scriptURL)) { 231 if (!documentOrigin->canRequest(scriptURL)) {
230 RefPtr<SecurityOrigin> scriptOrigin = SecurityOrigin::create(scriptURL); 232 RefPtr<SecurityOrigin> scriptOrigin = SecurityOrigin::create(scriptURL);
231 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The origin of the provided scriptURL ('" + scriptOrigin->toStr ing() + "') does not match the current origin ('" + documentOrigin->toString() + "').")); 233 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The origin of the provided scriptURL ('" + scriptOrigin->toStr ing() + "') does not match the current origin ('" + documentOrigin->toString() + "')."));
232 return promise; 234 return promise;
233 } 235 }
234 if (!scriptURL.protocolIsInHTTPFamily()) { 236 if (!SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers(scriptURL. protocol())) {
235 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The URL protocol of the script ('" + scriptURL.string() + "') is not supported.")); 237 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The URL protocol of the script ('" + scriptURL.string() + "') is not supported."));
236 return promise; 238 return promise;
237 } 239 }
238 240
239 KURL patternURL; 241 KURL patternURL;
240 if (options.scope().isNull()) 242 if (options.scope().isNull())
241 patternURL = KURL(scriptURL, "./"); 243 patternURL = KURL(scriptURL, "./");
242 else 244 else
243 patternURL = callingExecutionContext(scriptState->isolate())->completeUR L(options.scope()); 245 patternURL = callingExecutionContext(scriptState->isolate())->completeUR L(options.scope());
244 patternURL.removeFragmentIdentifier(); 246 patternURL.removeFragmentIdentifier();
245 247
246 if (!documentOrigin->canRequest(patternURL)) { 248 if (!documentOrigin->canRequest(patternURL)) {
247 RefPtr<SecurityOrigin> patternOrigin = SecurityOrigin::create(patternURL ); 249 RefPtr<SecurityOrigin> patternOrigin = SecurityOrigin::create(patternURL );
248 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The origin of the provided scope ('" + patternOrigin->toString () + "') does not match the current origin ('" + documentOrigin->toString() + "' ).")); 250 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The origin of the provided scope ('" + patternOrigin->toString () + "') does not match the current origin ('" + documentOrigin->toString() + "' )."));
249 return promise; 251 return promise;
250 } 252 }
251 if (!patternURL.protocolIsInHTTPFamily()) { 253 if (!SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers(patternURL .protocol())) {
252 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The URL protocol of the scope ('" + patternURL.string() + "') is not supported.")); 254 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The URL protocol of the scope ('" + patternURL.string() + "') is not supported."));
253 return promise; 255 return promise;
254 } 256 }
255 257
256 m_provider->registerServiceWorker(patternURL, scriptURL, new RegistrationCal lback(resolver)); 258 m_provider->registerServiceWorker(patternURL, scriptURL, new RegistrationCal lback(resolver));
257 259
258 return promise; 260 return promise;
259 } 261 }
260 262
261 ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState, const String& documentURL) 263 ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState, const String& documentURL)
(...skipping 12 matching lines...) Expand all
274 return ScriptPromise(); 276 return ScriptPromise();
275 277
276 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); 278 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
277 String errorMessage; 279 String errorMessage;
278 if (!executionContext->isPrivilegedContext(errorMessage)) { 280 if (!executionContext->isPrivilegedContext(errorMessage)) {
279 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); 281 resolver->reject(DOMException::create(NotSupportedError, errorMessage));
280 return promise; 282 return promise;
281 } 283 }
282 284
283 KURL pageURL = KURL(KURL(), documentOrigin->toString()); 285 KURL pageURL = KURL(KURL(), documentOrigin->toString());
284 if (!pageURL.protocolIsInHTTPFamily()) { 286 if (!SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers(pageURL.pr otocol())) {
285 resolver->reject(DOMException::create(SecurityError, "Failed to get a Se rviceWorkerRegistration: The URL protocol of the current origin ('" + documentOr igin->toString() + "') is not supported.")); 287 resolver->reject(DOMException::create(SecurityError, "Failed to get a Se rviceWorkerRegistration: The URL protocol of the current origin ('" + documentOr igin->toString() + "') is not supported."));
286 return promise; 288 return promise;
287 } 289 }
288 290
289 KURL completedURL = callingExecutionContext(scriptState->isolate())->complet eURL(documentURL); 291 KURL completedURL = callingExecutionContext(scriptState->isolate())->complet eURL(documentURL);
290 completedURL.removeFragmentIdentifier(); 292 completedURL.removeFragmentIdentifier();
291 if (!documentOrigin->canRequest(completedURL)) { 293 if (!documentOrigin->canRequest(completedURL)) {
292 RefPtr<SecurityOrigin> documentURLOrigin = SecurityOrigin::create(comple tedURL); 294 RefPtr<SecurityOrigin> documentURLOrigin = SecurityOrigin::create(comple tedURL);
293 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() + "').")); 295 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() + "')."));
294 return promise; 296 return promise;
(...skipping 15 matching lines...) Expand all
310 312
311 ExecutionContext* executionContext = scriptState->executionContext(); 313 ExecutionContext* executionContext = scriptState->executionContext();
312 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); 314 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
313 String errorMessage; 315 String errorMessage;
314 if (!executionContext->isPrivilegedContext(errorMessage)) { 316 if (!executionContext->isPrivilegedContext(errorMessage)) {
315 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); 317 resolver->reject(DOMException::create(NotSupportedError, errorMessage));
316 return promise; 318 return promise;
317 } 319 }
318 320
319 KURL pageURL = KURL(KURL(), documentOrigin->toString()); 321 KURL pageURL = KURL(KURL(), documentOrigin->toString());
320 if (!pageURL.protocolIsInHTTPFamily()) { 322 if (!SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers(pageURL.pr otocol())) {
321 resolver->reject(DOMException::create(SecurityError, "Failed to get Serv iceWorkerRegistration objects: The URL protocol of the current origin ('" + docu mentOrigin->toString() + "') is not supported.")); 323 resolver->reject(DOMException::create(SecurityError, "Failed to get Serv iceWorkerRegistration objects: The URL protocol of the current origin ('" + docu mentOrigin->toString() + "') is not supported."));
322 return promise; 324 return promise;
323 } 325 }
324 326
325 m_provider->getRegistrations(new GetRegistrationsCallback(resolver)); 327 m_provider->getRegistrations(new GetRegistrationsCallback(resolver));
326 328
327 return promise; 329 return promise;
328 } 330 }
329 331
330 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper ty() 332 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper ty()
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 return; 398 return;
397 399
398 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) { 400 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) {
399 m_provider = client->provider(); 401 m_provider = client->provider();
400 if (m_provider) 402 if (m_provider)
401 m_provider->setClient(this); 403 m_provider->setClient(this);
402 } 404 }
403 } 405 }
404 406
405 } // namespace blink 407 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/platform/weborigin/SchemeRegistry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698