Index: third_party/WebKit/Source/core/fetch/ResourceLoader.cpp |
diff --git a/third_party/WebKit/Source/core/fetch/ResourceLoader.cpp b/third_party/WebKit/Source/core/fetch/ResourceLoader.cpp |
index 90eecfeb99a3ca1dee0579a103d874dbe70e0420..3b41ec025e82c7be3f79f392e8b0fe623e793a69 100644 |
--- a/third_party/WebKit/Source/core/fetch/ResourceLoader.cpp |
+++ b/third_party/WebKit/Source/core/fetch/ResourceLoader.cpp |
@@ -123,7 +123,15 @@ void ResourceLoader::cancel() |
didFail(nullptr, ResourceError::cancelledError(m_resource->lastResourceRequest().url())); |
} |
-void ResourceLoader::willFollowRedirect(WebURLLoader*, WebURLRequest& passedNewRequest, const WebURLResponse& passedRedirectResponse, int64_t encodedDataLength) |
+void ResourceLoader::cancelForRedirectAccessCheckError(const KURL& newURL) |
+{ |
+ m_resource->willNotFollowRedirect(); |
+ |
+ if (m_loader) |
+ didFail(nullptr, ResourceError::cancelledDueToAccessCheckError(newURL)); |
+} |
+ |
+bool ResourceLoader::willFollowRedirect(WebURLLoader*, WebURLRequest& passedNewRequest, const WebURLResponse& passedRedirectResponse, int64_t encodedDataLength) |
{ |
DCHECK(!passedNewRequest.isNull()); |
DCHECK(!passedRedirectResponse.isNull()); |
@@ -132,13 +140,30 @@ void ResourceLoader::willFollowRedirect(WebURLLoader*, WebURLRequest& passedNewR |
const ResourceResponse& redirectResponse(passedRedirectResponse.toResourceResponse()); |
newRequest.setRedirectStatus(ResourceRequest::RedirectStatus::FollowedRedirect); |
- if (m_fetcher->willFollowRedirect(m_resource.get(), newRequest, redirectResponse, encodedDataLength)) { |
- m_resource->willFollowRedirect(newRequest, redirectResponse); |
- } else { |
- m_resource->willNotFollowRedirect(); |
- if (m_loader) |
- didFail(nullptr, ResourceError::cancelledDueToAccessCheckError(newRequest.url())); |
+ const KURL originalURL = newRequest.url(); |
+ |
+ if (!m_fetcher->willFollowRedirect(m_resource.get(), newRequest, redirectResponse, encodedDataLength)) { |
+ cancelForRedirectAccessCheckError(newRequest.url()); |
+ return false; |
} |
+ |
+ // ResourceFetcher::willFollowRedirect() may rewrite the URL to |
+ // something else not for rejecting redirect but for other reasons. |
+ // E.g. WebFrameTestClient::willSendRequest() and |
+ // RenderFrameImpl::willSendRequest(). We should reflect the |
+ // rewriting but currently we cannot. So, return false to make the |
+ // redirect fail. |
+ if (newRequest.url() != originalURL) { |
+ cancelForRedirectAccessCheckError(newRequest.url()); |
+ return false; |
+ } |
+ |
+ if (!m_resource->willFollowRedirect(newRequest, redirectResponse)) { |
+ cancelForRedirectAccessCheckError(newRequest.url()); |
+ return false; |
+ } |
+ |
+ return true; |
} |
void ResourceLoader::didReceiveCachedMetadata(WebURLLoader*, const char* data, int length) |