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

Side by Side Diff: Source/core/loader/DocumentThreadableLoader.cpp

Issue 600393004: [ServiceWorker] Set FetchRequestMode and handle wasFetchedViaServiceWorker. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: remove console.log from fetch-request-image.html Created 6 years, 2 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) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013, Intel Corporation 3 * Copyright (C) 2013, Intel Corporation
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 28 matching lines...) Expand all
39 #include "core/fetch/Resource.h" 39 #include "core/fetch/Resource.h"
40 #include "core/fetch/ResourceFetcher.h" 40 #include "core/fetch/ResourceFetcher.h"
41 #include "core/frame/FrameConsole.h" 41 #include "core/frame/FrameConsole.h"
42 #include "core/frame/LocalFrame.h" 42 #include "core/frame/LocalFrame.h"
43 #include "core/frame/csp/ContentSecurityPolicy.h" 43 #include "core/frame/csp/ContentSecurityPolicy.h"
44 #include "core/inspector/InspectorInstrumentation.h" 44 #include "core/inspector/InspectorInstrumentation.h"
45 #include "core/inspector/InspectorTraceEvents.h" 45 #include "core/inspector/InspectorTraceEvents.h"
46 #include "core/loader/CrossOriginPreflightResultCache.h" 46 #include "core/loader/CrossOriginPreflightResultCache.h"
47 #include "core/loader/DocumentThreadableLoaderClient.h" 47 #include "core/loader/DocumentThreadableLoaderClient.h"
48 #include "core/loader/FrameLoader.h" 48 #include "core/loader/FrameLoader.h"
49 #include "core/loader/FrameLoaderClient.h"
49 #include "core/loader/ThreadableLoaderClient.h" 50 #include "core/loader/ThreadableLoaderClient.h"
50 #include "platform/SharedBuffer.h" 51 #include "platform/SharedBuffer.h"
51 #include "platform/network/ResourceRequest.h" 52 #include "platform/network/ResourceRequest.h"
52 #include "platform/weborigin/SchemeRegistry.h" 53 #include "platform/weborigin/SchemeRegistry.h"
53 #include "platform/weborigin/SecurityOrigin.h" 54 #include "platform/weborigin/SecurityOrigin.h"
54 #include "public/platform/WebURLRequest.h" 55 #include "public/platform/WebURLRequest.h"
55 #include "wtf/Assertions.h" 56 #include "wtf/Assertions.h"
56 57
57 namespace blink { 58 namespace blink {
58 59
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 93
93 // Save any CORS simple headers on the request here. If this request redirec ts cross-origin, we cancel the old request 94 // Save any CORS simple headers on the request here. If this request redirec ts cross-origin, we cancel the old request
94 // create a new one, and copy these headers. 95 // create a new one, and copy these headers.
95 const HTTPHeaderMap& headerMap = request.httpHeaderFields(); 96 const HTTPHeaderMap& headerMap = request.httpHeaderFields();
96 HTTPHeaderMap::const_iterator end = headerMap.end(); 97 HTTPHeaderMap::const_iterator end = headerMap.end();
97 for (HTTPHeaderMap::const_iterator it = headerMap.begin(); it != end; ++it) { 98 for (HTTPHeaderMap::const_iterator it = headerMap.begin(); it != end; ++it) {
98 if (FetchUtils::isSimpleHeader(it->key, it->value)) 99 if (FetchUtils::isSimpleHeader(it->key, it->value))
99 m_simpleRequestHeaders.add(it->key, it->value); 100 m_simpleRequestHeaders.add(it->key, it->value);
100 } 101 }
101 102
103 // When the request is asynchronous mode and skipServiceWorker flag is not
104 // set and the document is controlled by the ServiceWorker the fetch request
105 // will be handled by the ServiceWorker. In such a case FetchRequestMode of
falken 2014/10/09 05:38:34 nit: Much of the first sentence just repeats the c
horo 2014/10/09 07:27:53 Done.
106 // the request must be FetchRequestModeCORS or
107 // FetchRequestModeCORSWithForcedPreflight. Otherwise the ServiceWorker can
108 // return the opaque responce which is from the other origin site and the
falken 2014/10/09 05:38:34 nit: "return the" -> "return an", "responce" -> "r
horo 2014/10/09 07:27:53 Done.
109 // script in the page can read the content.
110 if (m_async && !request.skipServiceWorker() && m_document.fetcher()->isContr olledByServiceWorker()) {
111 if (!m_sameOriginRequest && m_options.crossOriginRequestPolicy == DenyCr ossOriginRequests) {
112 m_client->didFail(ResourceError(errorDomainBlinkInternal, 0, request .url().string(), "Cross origin requests are not supported."));
113 return;
114 }
115 ResourceRequest newRequest(request);
116 // FetchRequestMode should be set by the caller. But the expected value
117 // of FetchRequestMode is not speced yet except for XHR. So we set here.
118 // FIXME: When we support fetch API in document, this value should not
119 // be overridden here.
120 if (options.preflightPolicy == ForcePreflight)
121 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeCORSWi thForcedPreflight);
122 else
123 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeCORS);
124
125 m_fallbackRequest = adoptPtr(new ResourceRequest(request));
126 m_fallbackRequest->setSkipServiceWorker(true);
127
128 loadRequest(newRequest, m_resourceLoaderOptions);
129 return;
130 }
131
102 if (m_sameOriginRequest || m_options.crossOriginRequestPolicy == AllowCrossO riginRequests) { 132 if (m_sameOriginRequest || m_options.crossOriginRequestPolicy == AllowCrossO riginRequests) {
103 loadRequest(request, m_resourceLoaderOptions); 133 loadRequest(request, m_resourceLoaderOptions);
104 return; 134 return;
105 } 135 }
106 136
107 if (m_options.crossOriginRequestPolicy == DenyCrossOriginRequests) { 137 if (m_options.crossOriginRequestPolicy == DenyCrossOriginRequests) {
108 m_client->didFail(ResourceError(errorDomainBlinkInternal, 0, request.url ().string(), "Cross origin requests are not supported.")); 138 m_client->didFail(ResourceError(errorDomainBlinkInternal, 0, request.url ().string(), "Cross origin requests are not supported."));
109 return; 139 return;
110 } 140 }
111 141
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 { 386 {
357 ASSERT(m_client); 387 ASSERT(m_client);
358 388
359 if (m_actualRequest) { 389 if (m_actualRequest) {
360 notifyResponseReceived(identifier, response); 390 notifyResponseReceived(identifier, response);
361 handlePreflightResponse(response); 391 handlePreflightResponse(response);
362 return; 392 return;
363 } 393 }
364 394
365 // If the response is fetched via ServiceWorker, the original URL of the res ponse could be different from the URL of the request. 395 // If the response is fetched via ServiceWorker, the original URL of the res ponse could be different from the URL of the request.
366 bool isCrossOriginResponse = false; 396 bool isCrossOriginResponse = false;
falken 2014/10/09 05:38:34 It looks like isCrossOriginResponse is no longer u
horo 2014/10/09 07:27:53 Done.
367 if (response.wasFetchedViaServiceWorker()) { 397 if (response.wasFetchedViaServiceWorker()) {
368 if (!isAllowedByPolicy(response.url())) { 398 if (response.wasFallbackRequiredByServiceWorker()) {
369 notifyResponseReceived(identifier, response); 399 ASSERT(m_fallbackRequest);
370 m_client->didFailRedirectCheck(); 400 loadFallbackRequest();
371 return; 401 return;
372 } 402 }
373 isCrossOriginResponse = !securityOrigin()->canRequest(response.url()); 403 m_fallbackRequest = nullptr;
374 if (m_options.crossOriginRequestPolicy == DenyCrossOriginRequests && isC rossOriginResponse) { 404 m_client->didReceiveResponse(identifier, response);
375 notifyResponseReceived(identifier, response); 405 return;
376 m_client->didFail(ResourceError(errorDomainBlinkInternal, 0, respons e.url().string(), "Cross origin requests are not supported."));
377 return;
378 }
379 if (isCrossOriginResponse && m_resourceLoaderOptions.credentialsRequeste d == ClientDidNotRequestCredentials) {
380 // Since the request is no longer same-origin, if the user didn't re quest credentials in
381 // the first place, update our state so we neither request them nor expect they must be allowed.
382 m_forceDoNotAllowStoredCredentials = true;
383 }
384 } else { 406 } else {
385 isCrossOriginResponse = !m_sameOriginRequest; 407 isCrossOriginResponse = !m_sameOriginRequest;
386 } 408 }
387 if (isCrossOriginResponse && m_options.crossOriginRequestPolicy == UseAccess Control) { 409 if (isCrossOriginResponse && m_options.crossOriginRequestPolicy == UseAccess Control) {
388 String accessControlErrorDescription; 410 String accessControlErrorDescription;
389 if (!passesAccessControlCheck(response, effectiveAllowCredentials(), sec urityOrigin(), accessControlErrorDescription)) { 411 if (!passesAccessControlCheck(response, effectiveAllowCredentials(), sec urityOrigin(), accessControlErrorDescription)) {
390 notifyResponseReceived(identifier, response); 412 notifyResponseReceived(identifier, response);
391 m_client->didFailAccessControlCheck(ResourceError(errorDomainBlinkIn ternal, 0, response.url().string(), accessControlErrorDescription)); 413 m_client->didFailAccessControlCheck(ResourceError(errorDomainBlinkIn ternal, 0, response.url().string(), accessControlErrorDescription));
392 return; 414 return;
393 } 415 }
394 } 416 }
395 417
396 m_client->didReceiveResponse(identifier, response); 418 m_client->didReceiveResponse(identifier, response);
397 } 419 }
398 420
399 void DocumentThreadableLoader::dataReceived(Resource* resource, const char* data , unsigned dataLength) 421 void DocumentThreadableLoader::dataReceived(Resource* resource, const char* data , unsigned dataLength)
400 { 422 {
401 ASSERT_UNUSED(resource, resource == this->resource()); 423 ASSERT_UNUSED(resource, resource == this->resource());
402 handleReceivedData(data, dataLength); 424 handleReceivedData(data, dataLength);
403 } 425 }
404 426
405 void DocumentThreadableLoader::handleReceivedData(const char* data, unsigned dat aLength) 427 void DocumentThreadableLoader::handleReceivedData(const char* data, unsigned dat aLength)
406 { 428 {
407 ASSERT(m_client); 429 ASSERT(m_client);
408 // Preflight data should be invisible to clients. 430 // Preflight data should be invisible to clients.
409 if (!m_actualRequest) 431 if (!m_actualRequest && !m_fallbackRequest)
410 m_client->didReceiveData(data, dataLength); 432 m_client->didReceiveData(data, dataLength);
411 } 433 }
412 434
413 void DocumentThreadableLoader::notifyFinished(Resource* resource) 435 void DocumentThreadableLoader::notifyFinished(Resource* resource)
414 { 436 {
415 ASSERT(m_client); 437 ASSERT(m_client);
416 ASSERT(resource == this->resource()); 438 ASSERT(resource == this->resource());
417 439
418 m_timeoutTimer.stop(); 440 m_timeoutTimer.stop();
419 441
(...skipping 21 matching lines...) Expand all
441 ASSERT_UNUSED(timer, timer == &m_timeoutTimer); 463 ASSERT_UNUSED(timer, timer == &m_timeoutTimer);
442 464
443 // Using values from net/base/net_error_list.h ERR_TIMED_OUT, 465 // Using values from net/base/net_error_list.h ERR_TIMED_OUT,
444 // Same as existing FIXME above - this error should be coming from FrameLoad erClient to be identifiable. 466 // Same as existing FIXME above - this error should be coming from FrameLoad erClient to be identifiable.
445 static const int timeoutError = -7; 467 static const int timeoutError = -7;
446 ResourceError error("net", timeoutError, resource()->url(), String()); 468 ResourceError error("net", timeoutError, resource()->url(), String());
447 error.setIsTimeout(true); 469 error.setIsTimeout(true);
448 cancelWithError(error); 470 cancelWithError(error);
449 } 471 }
450 472
473 void DocumentThreadableLoader::loadFallbackRequest()
474 {
475 clearResource();
476 OwnPtr<ResourceRequest> fallbackRequest(m_fallbackRequest.release());
477 if (m_sameOriginRequest || m_options.crossOriginRequestPolicy == AllowCrossO riginRequests) {
478 loadRequest(*fallbackRequest, m_resourceLoaderOptions);
479 return;
480 }
481 ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl);
482 makeCrossOriginAccessRequest(*fallbackRequest);
483 }
484
451 void DocumentThreadableLoader::loadActualRequest() 485 void DocumentThreadableLoader::loadActualRequest()
452 { 486 {
453 OwnPtr<ResourceRequest> actualRequest; 487 OwnPtr<ResourceRequest> actualRequest;
454 actualRequest.swap(m_actualRequest); 488 actualRequest.swap(m_actualRequest);
455 OwnPtr<ResourceLoaderOptions> actualOptions; 489 OwnPtr<ResourceLoaderOptions> actualOptions;
456 actualOptions.swap(m_actualOptions); 490 actualOptions.swap(m_actualOptions);
457 491
458 actualRequest->setHTTPOrigin(securityOrigin()->toAtomicString()); 492 actualRequest->setHTTPOrigin(securityOrigin()->toAtomicString());
459 493
460 clearResource(); 494 clearResource();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 return DoNotAllowStoredCredentials; 601 return DoNotAllowStoredCredentials;
568 return m_resourceLoaderOptions.allowCredentials; 602 return m_resourceLoaderOptions.allowCredentials;
569 } 603 }
570 604
571 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const 605 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const
572 { 606 {
573 return m_securityOrigin ? m_securityOrigin.get() : m_document.securityOrigin (); 607 return m_securityOrigin ? m_securityOrigin.get() : m_document.securityOrigin ();
574 } 608 }
575 609
576 } // namespace blink 610 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698