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

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: Added comments for scheme checks 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;
216 if (!executionContext->isPrivilegedContext(errorMessage)) { 217 if (!executionContext->isPrivilegedContext(errorMessage)) {
Devlin 2015/06/29 19:54:44 so let's say (courtesy of falken@) // Restrict to
217 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); 218 resolver->reject(DOMException::create(NotSupportedError, errorMessage));
218 return promise; 219 return promise;
219 } 220 }
220 221
221 KURL pageURL = KURL(KURL(), documentOrigin->toString()); 222 KURL pageURL = KURL(KURL(), documentOrigin->toString());
222 if (!pageURL.protocolIsInHTTPFamily()) { 223 // There is a check that a context is privileged before checking the scheme.
Devlin 2015/06/29 19:54:43 nit: It's better to comment exactly where the rele
224 // URL scheme occurs after to filter out things like blobs and files.
225 // HTTP is required because http://localhost is considered secure.
226 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.")); 227 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; 228 return promise;
225 } 229 }
226 230
227 KURL scriptURL = callingExecutionContext(scriptState->isolate())->completeUR L(url); 231 KURL scriptURL = callingExecutionContext(scriptState->isolate())->completeUR L(url);
228 scriptURL.removeFragmentIdentifier(); 232 scriptURL.removeFragmentIdentifier();
229 if (!documentOrigin->canRequest(scriptURL)) { 233 if (!documentOrigin->canRequest(scriptURL)) {
230 RefPtr<SecurityOrigin> scriptOrigin = SecurityOrigin::create(scriptURL); 234 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() + "').")); 235 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; 236 return promise;
233 } 237 }
234 if (!scriptURL.protocolIsInHTTPFamily()) { 238 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.")); 239 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The URL protocol of the script ('" + scriptURL.string() + "') is not supported."));
236 return promise; 240 return promise;
237 } 241 }
238 242
239 KURL patternURL; 243 KURL patternURL;
240 if (options.scope().isNull()) 244 if (options.scope().isNull())
241 patternURL = KURL(scriptURL, "./"); 245 patternURL = KURL(scriptURL, "./");
242 else 246 else
243 patternURL = callingExecutionContext(scriptState->isolate())->completeUR L(options.scope()); 247 patternURL = callingExecutionContext(scriptState->isolate())->completeUR L(options.scope());
244 patternURL.removeFragmentIdentifier(); 248 patternURL.removeFragmentIdentifier();
245 249
246 if (!documentOrigin->canRequest(patternURL)) { 250 if (!documentOrigin->canRequest(patternURL)) {
247 RefPtr<SecurityOrigin> patternOrigin = SecurityOrigin::create(patternURL ); 251 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() + "' ).")); 252 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; 253 return promise;
250 } 254 }
251 if (!patternURL.protocolIsInHTTPFamily()) { 255 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.")); 256 resolver->reject(DOMException::create(SecurityError, "Failed to register a ServiceWorker: The URL protocol of the scope ('" + patternURL.string() + "') is not supported."));
253 return promise; 257 return promise;
254 } 258 }
255 259
256 m_provider->registerServiceWorker(patternURL, scriptURL, new RegistrationCal lback(resolver)); 260 m_provider->registerServiceWorker(patternURL, scriptURL, new RegistrationCal lback(resolver));
257 261
258 return promise; 262 return promise;
259 } 263 }
260 264
261 ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState, const String& documentURL) 265 ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState, const String& documentURL)
(...skipping 12 matching lines...) Expand all
274 return ScriptPromise(); 278 return ScriptPromise();
275 279
276 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); 280 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
277 String errorMessage; 281 String errorMessage;
278 if (!executionContext->isPrivilegedContext(errorMessage)) { 282 if (!executionContext->isPrivilegedContext(errorMessage)) {
279 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); 283 resolver->reject(DOMException::create(NotSupportedError, errorMessage));
280 return promise; 284 return promise;
281 } 285 }
282 286
283 KURL pageURL = KURL(KURL(), documentOrigin->toString()); 287 KURL pageURL = KURL(KURL(), documentOrigin->toString());
284 if (!pageURL.protocolIsInHTTPFamily()) { 288 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.")); 289 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; 290 return promise;
287 } 291 }
288 292
289 KURL completedURL = callingExecutionContext(scriptState->isolate())->complet eURL(documentURL); 293 KURL completedURL = callingExecutionContext(scriptState->isolate())->complet eURL(documentURL);
290 completedURL.removeFragmentIdentifier(); 294 completedURL.removeFragmentIdentifier();
291 if (!documentOrigin->canRequest(completedURL)) { 295 if (!documentOrigin->canRequest(completedURL)) {
292 RefPtr<SecurityOrigin> documentURLOrigin = SecurityOrigin::create(comple tedURL); 296 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() + "').")); 297 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; 298 return promise;
(...skipping 15 matching lines...) Expand all
310 314
311 ExecutionContext* executionContext = scriptState->executionContext(); 315 ExecutionContext* executionContext = scriptState->executionContext();
312 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); 316 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
313 String errorMessage; 317 String errorMessage;
314 if (!executionContext->isPrivilegedContext(errorMessage)) { 318 if (!executionContext->isPrivilegedContext(errorMessage)) {
315 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); 319 resolver->reject(DOMException::create(NotSupportedError, errorMessage));
316 return promise; 320 return promise;
317 } 321 }
318 322
319 KURL pageURL = KURL(KURL(), documentOrigin->toString()); 323 KURL pageURL = KURL(KURL(), documentOrigin->toString());
320 if (!pageURL.protocolIsInHTTPFamily()) { 324 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.")); 325 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; 326 return promise;
323 } 327 }
324 328
325 m_provider->getRegistrations(new GetRegistrationsCallback(resolver)); 329 m_provider->getRegistrations(new GetRegistrationsCallback(resolver));
326 330
327 return promise; 331 return promise;
328 } 332 }
329 333
330 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper ty() 334 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper ty()
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 return; 400 return;
397 401
398 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) { 402 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) {
399 m_provider = client->provider(); 403 m_provider = client->provider();
400 if (m_provider) 404 if (m_provider)
401 m_provider->setClient(this); 405 m_provider->setClient(this);
402 } 406 }
403 } 407 }
404 408
405 } // namespace blink 409 } // 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