OLD | NEW |
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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 // request to the SW. https://crbug.com/604583 | 383 // request to the SW. https://crbug.com/604583 |
384 // Similarly we don't want any requests that could involve a CORS preflight | 384 // Similarly we don't want any requests that could involve a CORS preflight |
385 // to get intercepted by a foreign fetch service worker, even if we have the | 385 // to get intercepted by a foreign fetch service worker, even if we have the |
386 // result of the preflight cached already. https://crbug.com/674370 | 386 // result of the preflight cached already. https://crbug.com/674370 |
387 crossOriginRequest.setServiceWorkerMode( | 387 crossOriginRequest.setServiceWorkerMode( |
388 WebURLRequest::ServiceWorkerMode::None); | 388 WebURLRequest::ServiceWorkerMode::None); |
389 | 389 |
390 bool shouldForcePreflight = request.isExternalRequest(); | 390 bool shouldForcePreflight = request.isExternalRequest(); |
391 if (!shouldForcePreflight) | 391 if (!shouldForcePreflight) |
392 probe::shouldForceCORSPreflight(document(), &shouldForcePreflight); | 392 probe::shouldForceCORSPreflight(document(), &shouldForcePreflight); |
| 393 // TODO(horo): Move CrossOriginPreflightResultCache to |
| 394 // ThreadableLoadingContext |
393 bool canSkipPreflight = | 395 bool canSkipPreflight = |
| 396 isMainThread() && |
394 CrossOriginPreflightResultCache::shared().canSkipPreflight( | 397 CrossOriginPreflightResultCache::shared().canSkipPreflight( |
395 getSecurityOrigin()->toString(), crossOriginRequest.url(), | 398 getSecurityOrigin()->toString(), crossOriginRequest.url(), |
396 effectiveAllowCredentials(), crossOriginRequest.httpMethod(), | 399 effectiveAllowCredentials(), crossOriginRequest.httpMethod(), |
397 crossOriginRequest.httpHeaderFields()); | 400 crossOriginRequest.httpHeaderFields()); |
398 if (canSkipPreflight && !shouldForcePreflight) { | 401 if (canSkipPreflight && !shouldForcePreflight) { |
399 prepareCrossOriginRequest(crossOriginRequest); | 402 prepareCrossOriginRequest(crossOriginRequest); |
400 loadRequest(crossOriginRequest, crossOriginOptions); | 403 loadRequest(crossOriginRequest, crossOriginOptions); |
401 } else { | 404 } else { |
402 ResourceRequest preflightRequest = | 405 ResourceRequest preflightRequest = |
403 createAccessControlPreflightRequest(crossOriginRequest); | 406 createAccessControlPreflightRequest(crossOriginRequest); |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 new CrossOriginPreflightResultCacheItem(effectiveAllowCredentials())); | 758 new CrossOriginPreflightResultCacheItem(effectiveAllowCredentials())); |
756 if (!preflightResult->parse(response, accessControlErrorDescription) || | 759 if (!preflightResult->parse(response, accessControlErrorDescription) || |
757 !preflightResult->allowsCrossOriginMethod( | 760 !preflightResult->allowsCrossOriginMethod( |
758 m_actualRequest.httpMethod(), accessControlErrorDescription) || | 761 m_actualRequest.httpMethod(), accessControlErrorDescription) || |
759 !preflightResult->allowsCrossOriginHeaders( | 762 !preflightResult->allowsCrossOriginHeaders( |
760 m_actualRequest.httpHeaderFields(), accessControlErrorDescription)) { | 763 m_actualRequest.httpHeaderFields(), accessControlErrorDescription)) { |
761 handlePreflightFailure(response.url().getString(), | 764 handlePreflightFailure(response.url().getString(), |
762 accessControlErrorDescription); | 765 accessControlErrorDescription); |
763 return; | 766 return; |
764 } | 767 } |
765 | 768 if (isMainThread()) { |
766 CrossOriginPreflightResultCache::shared().appendEntry( | 769 // TODO(horo): Move CrossOriginPreflightResultCache to |
767 getSecurityOrigin()->toString(), m_actualRequest.url(), | 770 // ThreadableLoadingContext |
768 std::move(preflightResult)); | 771 CrossOriginPreflightResultCache::shared().appendEntry( |
| 772 getSecurityOrigin()->toString(), m_actualRequest.url(), |
| 773 std::move(preflightResult)); |
| 774 } |
769 } | 775 } |
770 | 776 |
771 void DocumentThreadableLoader::reportResponseReceived( | 777 void DocumentThreadableLoader::reportResponseReceived( |
772 unsigned long identifier, | 778 unsigned long identifier, |
773 const ResourceResponse& response) { | 779 const ResourceResponse& response) { |
774 LocalFrame* frame = document() ? document()->frame() : nullptr; | 780 LocalFrame* frame = document() ? document()->frame() : nullptr; |
775 if (!frame) | 781 if (!frame) |
776 return; | 782 return; |
777 DocumentLoader* loader = frame->loader().documentLoader(); | 783 DocumentLoader* loader = frame->loader().documentLoader(); |
778 probe::didReceiveResourceResponse(frame, identifier, loader, response, | 784 probe::didReceiveResourceResponse(document(), identifier, loader, response, |
779 resource()); | 785 resource()); |
780 frame->console().reportResourceResponseReceived(loader, identifier, response); | 786 frame->console().reportResourceResponseReceived(loader, identifier, response); |
781 } | 787 } |
782 | 788 |
783 void DocumentThreadableLoader::handleResponse( | 789 void DocumentThreadableLoader::handleResponse( |
784 unsigned long identifier, | 790 unsigned long identifier, |
785 const ResourceResponse& response, | 791 const ResourceResponse& response, |
786 std::unique_ptr<WebDataConsumerHandle> handle) { | 792 std::unique_ptr<WebDataConsumerHandle> handle) { |
787 DCHECK(m_client); | 793 DCHECK(m_client); |
788 | 794 |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 } | 1152 } |
1147 | 1153 |
1148 DEFINE_TRACE(DocumentThreadableLoader) { | 1154 DEFINE_TRACE(DocumentThreadableLoader) { |
1149 visitor->trace(m_resource); | 1155 visitor->trace(m_resource); |
1150 visitor->trace(m_loadingContext); | 1156 visitor->trace(m_loadingContext); |
1151 ThreadableLoader::trace(visitor); | 1157 ThreadableLoader::trace(visitor); |
1152 RawResourceClient::trace(visitor); | 1158 RawResourceClient::trace(visitor); |
1153 } | 1159 } |
1154 | 1160 |
1155 } // namespace blink | 1161 } // namespace blink |
OLD | NEW |