Chromium Code Reviews| Index: Source/core/loader/DocumentThreadableLoader.cpp |
| diff --git a/Source/core/loader/DocumentThreadableLoader.cpp b/Source/core/loader/DocumentThreadableLoader.cpp |
| index 15e351a0bce9f3b6f676d73c3ae81d5163130cbb..050e32cc4cb0a801af26aa2168822a2bd086e7cd 100644 |
| --- a/Source/core/loader/DocumentThreadableLoader.cpp |
| +++ b/Source/core/loader/DocumentThreadableLoader.cpp |
| @@ -46,6 +46,7 @@ |
| #include "core/loader/CrossOriginPreflightResultCache.h" |
| #include "core/loader/DocumentThreadableLoaderClient.h" |
| #include "core/loader/FrameLoader.h" |
| +#include "core/loader/FrameLoaderClient.h" |
| #include "core/loader/ThreadableLoaderClient.h" |
| #include "platform/SharedBuffer.h" |
| #include "platform/network/ResourceRequest.h" |
| @@ -99,6 +100,35 @@ DocumentThreadableLoader::DocumentThreadableLoader(Document& document, Threadabl |
| m_simpleRequestHeaders.add(it->key, it->value); |
| } |
| + // When the request is asynchronous mode and skipServiceWorker flag is not |
| + // set and the document is controlled by the ServiceWorker the fetch request |
| + // 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.
|
| + // the request must be FetchRequestModeCORS or |
| + // FetchRequestModeCORSWithForcedPreflight. Otherwise the ServiceWorker can |
| + // 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.
|
| + // script in the page can read the content. |
| + if (m_async && !request.skipServiceWorker() && m_document.fetcher()->isControlledByServiceWorker()) { |
| + if (!m_sameOriginRequest && m_options.crossOriginRequestPolicy == DenyCrossOriginRequests) { |
| + m_client->didFail(ResourceError(errorDomainBlinkInternal, 0, request.url().string(), "Cross origin requests are not supported.")); |
| + return; |
| + } |
| + ResourceRequest newRequest(request); |
| + // FetchRequestMode should be set by the caller. But the expected value |
| + // of FetchRequestMode is not speced yet except for XHR. So we set here. |
| + // FIXME: When we support fetch API in document, this value should not |
| + // be overridden here. |
| + if (options.preflightPolicy == ForcePreflight) |
| + newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeCORSWithForcedPreflight); |
| + else |
| + newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeCORS); |
| + |
| + m_fallbackRequest = adoptPtr(new ResourceRequest(request)); |
| + m_fallbackRequest->setSkipServiceWorker(true); |
| + |
| + loadRequest(newRequest, m_resourceLoaderOptions); |
| + return; |
| + } |
| + |
| if (m_sameOriginRequest || m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) { |
| loadRequest(request, m_resourceLoaderOptions); |
| return; |
| @@ -365,22 +395,14 @@ void DocumentThreadableLoader::handleResponse(unsigned long identifier, const Re |
| // If the response is fetched via ServiceWorker, the original URL of the response could be different from the URL of the request. |
| 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.
|
| if (response.wasFetchedViaServiceWorker()) { |
| - if (!isAllowedByPolicy(response.url())) { |
| - notifyResponseReceived(identifier, response); |
| - m_client->didFailRedirectCheck(); |
| - return; |
| - } |
| - isCrossOriginResponse = !securityOrigin()->canRequest(response.url()); |
| - if (m_options.crossOriginRequestPolicy == DenyCrossOriginRequests && isCrossOriginResponse) { |
| - notifyResponseReceived(identifier, response); |
| - m_client->didFail(ResourceError(errorDomainBlinkInternal, 0, response.url().string(), "Cross origin requests are not supported.")); |
| + if (response.wasFallbackRequiredByServiceWorker()) { |
| + ASSERT(m_fallbackRequest); |
| + loadFallbackRequest(); |
| return; |
| } |
| - if (isCrossOriginResponse && m_resourceLoaderOptions.credentialsRequested == ClientDidNotRequestCredentials) { |
| - // Since the request is no longer same-origin, if the user didn't request credentials in |
| - // the first place, update our state so we neither request them nor expect they must be allowed. |
| - m_forceDoNotAllowStoredCredentials = true; |
| - } |
| + m_fallbackRequest = nullptr; |
| + m_client->didReceiveResponse(identifier, response); |
| + return; |
| } else { |
| isCrossOriginResponse = !m_sameOriginRequest; |
| } |
| @@ -406,7 +428,7 @@ void DocumentThreadableLoader::handleReceivedData(const char* data, unsigned dat |
| { |
| ASSERT(m_client); |
| // Preflight data should be invisible to clients. |
| - if (!m_actualRequest) |
| + if (!m_actualRequest && !m_fallbackRequest) |
| m_client->didReceiveData(data, dataLength); |
| } |
| @@ -448,6 +470,18 @@ void DocumentThreadableLoader::didTimeout(Timer<DocumentThreadableLoader>* timer |
| cancelWithError(error); |
| } |
| +void DocumentThreadableLoader::loadFallbackRequest() |
| +{ |
| + clearResource(); |
| + OwnPtr<ResourceRequest> fallbackRequest(m_fallbackRequest.release()); |
| + if (m_sameOriginRequest || m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) { |
| + loadRequest(*fallbackRequest, m_resourceLoaderOptions); |
| + return; |
| + } |
| + ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl); |
| + makeCrossOriginAccessRequest(*fallbackRequest); |
| +} |
| + |
| void DocumentThreadableLoader::loadActualRequest() |
| { |
| OwnPtr<ResourceRequest> actualRequest; |