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

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: add setFetchCredentialsMode in PingLoader::PingLoader() 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 if (m_async && !request.skipServiceWorker() && m_document.fetcher()->isContr olledByServiceWorker()) {
yhirano 2014/10/07 08:03:14 why m_async is needed, is it a workaround?
yhirano 2014/10/07 08:03:15 Can you write a brief comment about this block?
horo 2014/10/08 02:34:56 Done.
horo 2014/10/08 02:34:56 ServiceWorker's onFetch event doesn't support sync
104 if (!m_sameOriginRequest && m_options.crossOriginRequestPolicy == DenyCr ossOriginRequests) {
105 m_client->didFail(ResourceError(errorDomainBlinkInternal, 0, request .url().string(), "Cross origin requests are not supported."));
106 return;
107 }
108 ResourceRequest newRequest = ResourceRequest(request);
yhirano 2014/10/07 08:03:15 ResourceRequest newRequest(request) is enough.
horo 2014/10/08 02:34:56 Done.
109 if (options.preflightPolicy == ForcePreflight)
yhirano 2014/10/07 08:03:14 Sorry I don't understand this flag manipulation. W
horo 2014/10/08 02:34:56 Added the comment.
110 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeCORSWi thForcedPreflight);
111 else
112 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeCORS);
113
114 if (resourceLoaderOptions.credentialsRequested == ClientRequestedCredent ials)
yhirano 2014/10/07 08:03:14 Ditto
horo 2014/10/08 02:34:56 removed
115 newRequest.setFetchCredentialsMode(WebURLRequest::FetchCredentialsMo deInclude);
116 else
117 newRequest.setFetchCredentialsMode(WebURLRequest::FetchCredentialsMo deSameOrigin);
118
yhirano 2014/10/07 08:03:14 Shouldn't we check the credentials flag correctnes
horo 2014/10/08 02:34:56 removed setFetchCredentialsMode
119 m_fallbackRequest = adoptPtr(new ResourceRequest(request));
120 m_fallbackRequest->setSkipServiceWorker(true);
121
122 loadRequest(newRequest, m_resourceLoaderOptions);
123 return;
124 }
125
102 if (m_sameOriginRequest || m_options.crossOriginRequestPolicy == AllowCrossO riginRequests) { 126 if (m_sameOriginRequest || m_options.crossOriginRequestPolicy == AllowCrossO riginRequests) {
103 loadRequest(request, m_resourceLoaderOptions); 127 loadRequest(request, m_resourceLoaderOptions);
104 return; 128 return;
105 } 129 }
106 130
107 if (m_options.crossOriginRequestPolicy == DenyCrossOriginRequests) { 131 if (m_options.crossOriginRequestPolicy == DenyCrossOriginRequests) {
108 m_client->didFail(ResourceError(errorDomainBlinkInternal, 0, request.url ().string(), "Cross origin requests are not supported.")); 132 m_client->didFail(ResourceError(errorDomainBlinkInternal, 0, request.url ().string(), "Cross origin requests are not supported."));
109 return; 133 return;
110 } 134 }
111 135
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 382
359 if (m_actualRequest) { 383 if (m_actualRequest) {
360 notifyResponseReceived(identifier, response); 384 notifyResponseReceived(identifier, response);
361 handlePreflightResponse(response); 385 handlePreflightResponse(response);
362 return; 386 return;
363 } 387 }
364 388
365 // If the response is fetched via ServiceWorker, the original URL of the res ponse could be different from the URL of the request. 389 // 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; 390 bool isCrossOriginResponse = false;
367 if (response.wasFetchedViaServiceWorker()) { 391 if (response.wasFetchedViaServiceWorker()) {
368 if (!isAllowedByPolicy(response.url())) { 392 if (response.wasFallbackRequiredByServiceWorker() && m_fallbackRequest) {
yhirano 2014/10/07 08:03:14 What happens if wasFallbackRequiredByServiceWorker
horo 2014/10/08 02:34:56 m_fallbackRequest must not be null when wasFallbac
369 notifyResponseReceived(identifier, response); 393 loadFallbackRequest();
370 m_client->didFailRedirectCheck();
371 return; 394 return;
372 } 395 }
373 isCrossOriginResponse = !securityOrigin()->canRequest(response.url()); 396 m_fallbackRequest = nullptr;
374 if (m_options.crossOriginRequestPolicy == DenyCrossOriginRequests && isC rossOriginResponse) { 397 m_client->didReceiveResponse(identifier, response);
375 notifyResponseReceived(identifier, response); 398 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 { 399 } else {
385 isCrossOriginResponse = !m_sameOriginRequest; 400 isCrossOriginResponse = !m_sameOriginRequest;
386 } 401 }
387 if (isCrossOriginResponse && m_options.crossOriginRequestPolicy == UseAccess Control) { 402 if (isCrossOriginResponse && m_options.crossOriginRequestPolicy == UseAccess Control) {
388 String accessControlErrorDescription; 403 String accessControlErrorDescription;
389 if (!passesAccessControlCheck(response, effectiveAllowCredentials(), sec urityOrigin(), accessControlErrorDescription)) { 404 if (!passesAccessControlCheck(response, effectiveAllowCredentials(), sec urityOrigin(), accessControlErrorDescription)) {
390 notifyResponseReceived(identifier, response); 405 notifyResponseReceived(identifier, response);
391 m_client->didFailAccessControlCheck(ResourceError(errorDomainBlinkIn ternal, 0, response.url().string(), accessControlErrorDescription)); 406 m_client->didFailAccessControlCheck(ResourceError(errorDomainBlinkIn ternal, 0, response.url().string(), accessControlErrorDescription));
392 return; 407 return;
393 } 408 }
394 } 409 }
395 410
396 m_client->didReceiveResponse(identifier, response); 411 m_client->didReceiveResponse(identifier, response);
397 } 412 }
398 413
399 void DocumentThreadableLoader::dataReceived(Resource* resource, const char* data , unsigned dataLength) 414 void DocumentThreadableLoader::dataReceived(Resource* resource, const char* data , unsigned dataLength)
400 { 415 {
401 ASSERT_UNUSED(resource, resource == this->resource()); 416 ASSERT_UNUSED(resource, resource == this->resource());
402 handleReceivedData(data, dataLength); 417 handleReceivedData(data, dataLength);
403 } 418 }
404 419
405 void DocumentThreadableLoader::handleReceivedData(const char* data, unsigned dat aLength) 420 void DocumentThreadableLoader::handleReceivedData(const char* data, unsigned dat aLength)
406 { 421 {
407 ASSERT(m_client); 422 ASSERT(m_client);
408 // Preflight data should be invisible to clients. 423 // Preflight data should be invisible to clients.
409 if (!m_actualRequest) 424 if (!m_actualRequest && !m_fallbackRequest)
410 m_client->didReceiveData(data, dataLength); 425 m_client->didReceiveData(data, dataLength);
411 } 426 }
412 427
413 void DocumentThreadableLoader::notifyFinished(Resource* resource) 428 void DocumentThreadableLoader::notifyFinished(Resource* resource)
414 { 429 {
415 ASSERT(m_client); 430 ASSERT(m_client);
416 ASSERT(resource == this->resource()); 431 ASSERT(resource == this->resource());
417 432
418 m_timeoutTimer.stop(); 433 m_timeoutTimer.stop();
419 434
(...skipping 21 matching lines...) Expand all
441 ASSERT_UNUSED(timer, timer == &m_timeoutTimer); 456 ASSERT_UNUSED(timer, timer == &m_timeoutTimer);
442 457
443 // Using values from net/base/net_error_list.h ERR_TIMED_OUT, 458 // 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. 459 // Same as existing FIXME above - this error should be coming from FrameLoad erClient to be identifiable.
445 static const int timeoutError = -7; 460 static const int timeoutError = -7;
446 ResourceError error("net", timeoutError, resource()->url(), String()); 461 ResourceError error("net", timeoutError, resource()->url(), String());
447 error.setIsTimeout(true); 462 error.setIsTimeout(true);
448 cancelWithError(error); 463 cancelWithError(error);
449 } 464 }
450 465
466 void DocumentThreadableLoader::loadFallbackRequest()
467 {
468 clearResource();
469 OwnPtr<ResourceRequest> fallbackRequest;
yhirano 2014/10/07 08:03:15 fallbackRequest(m_fallbackRequest.release());
horo 2014/10/08 02:34:56 Done.
470 fallbackRequest.swap(m_fallbackRequest);
471 if (m_sameOriginRequest || m_options.crossOriginRequestPolicy == AllowCrossO riginRequests) {
472 loadRequest(*fallbackRequest, m_resourceLoaderOptions);
473 return;
474 }
yhirano 2014/10/07 08:03:15 makeCrossOriginAccessRequest expects that the poli
horo 2014/10/08 02:34:56 Done.
475 makeCrossOriginAccessRequest(*fallbackRequest);
476 }
477
451 void DocumentThreadableLoader::loadActualRequest() 478 void DocumentThreadableLoader::loadActualRequest()
452 { 479 {
453 OwnPtr<ResourceRequest> actualRequest; 480 OwnPtr<ResourceRequest> actualRequest;
454 actualRequest.swap(m_actualRequest); 481 actualRequest.swap(m_actualRequest);
455 OwnPtr<ResourceLoaderOptions> actualOptions; 482 OwnPtr<ResourceLoaderOptions> actualOptions;
456 actualOptions.swap(m_actualOptions); 483 actualOptions.swap(m_actualOptions);
457 484
458 actualRequest->setHTTPOrigin(securityOrigin()->toAtomicString()); 485 actualRequest->setHTTPOrigin(securityOrigin()->toAtomicString());
459 486
460 clearResource(); 487 clearResource();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 return DoNotAllowStoredCredentials; 594 return DoNotAllowStoredCredentials;
568 return m_resourceLoaderOptions.allowCredentials; 595 return m_resourceLoaderOptions.allowCredentials;
569 } 596 }
570 597
571 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const 598 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const
572 { 599 {
573 return m_securityOrigin ? m_securityOrigin.get() : m_document.securityOrigin (); 600 return m_securityOrigin ? m_securityOrigin.get() : m_document.securityOrigin ();
574 } 601 }
575 602
576 } // namespace blink 603 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698