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

Unified Diff: third_party/WebKit/Source/core/fetch/ResourceLoader.cpp

Issue 2230173002: Change WebURLLoaderClient::willFollowRedirect() API to return bool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed jochen's point Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
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)

Powered by Google App Engine
This is Rietveld 408576698