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

Side by Side 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: Rebase Created 4 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) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved.
3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) 3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com)
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 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 if (m_loader) 115 if (m_loader)
116 m_loader->didChangePriority( 116 m_loader->didChangePriority(
117 static_cast<WebURLRequest::Priority>(loadPriority), intraPriorityValue); 117 static_cast<WebURLRequest::Priority>(loadPriority), intraPriorityValue);
118 } 118 }
119 119
120 void ResourceLoader::cancel() { 120 void ResourceLoader::cancel() {
121 didFail(nullptr, ResourceError::cancelledError( 121 didFail(nullptr, ResourceError::cancelledError(
122 m_resource->lastResourceRequest().url())); 122 m_resource->lastResourceRequest().url()));
123 } 123 }
124 124
125 void ResourceLoader::willFollowRedirect( 125 void ResourceLoader::cancelForRedirectAccessCheckError(const KURL& newURL) {
126 m_resource->willNotFollowRedirect();
127
128 if (m_loader)
129 didFail(nullptr, ResourceError::cancelledDueToAccessCheckError(newURL));
130 }
131
132 bool ResourceLoader::willFollowRedirect(
126 WebURLLoader*, 133 WebURLLoader*,
127 WebURLRequest& passedNewRequest, 134 WebURLRequest& passedNewRequest,
128 const WebURLResponse& passedRedirectResponse) { 135 const WebURLResponse& passedRedirectResponse) {
129 DCHECK(!passedNewRequest.isNull()); 136 DCHECK(!passedNewRequest.isNull());
130 DCHECK(!passedRedirectResponse.isNull()); 137 DCHECK(!passedRedirectResponse.isNull());
131 138
132 ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest()); 139 ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest());
133 const ResourceResponse& redirectResponse( 140 const ResourceResponse& redirectResponse(
134 passedRedirectResponse.toResourceResponse()); 141 passedRedirectResponse.toResourceResponse());
135 newRequest.setRedirectStatus( 142 newRequest.setRedirectStatus(
136 ResourceRequest::RedirectStatus::FollowedRedirect); 143 ResourceRequest::RedirectStatus::FollowedRedirect);
137 144
138 if (m_fetcher->willFollowRedirect(m_resource.get(), newRequest, 145 const KURL originalURL = newRequest.url();
139 redirectResponse)) { 146
140 m_resource->willFollowRedirect(newRequest, redirectResponse); 147 if (!m_fetcher->willFollowRedirect(m_resource.get(), newRequest,
141 } else { 148 redirectResponse)) {
142 m_resource->willNotFollowRedirect(); 149 cancelForRedirectAccessCheckError(newRequest.url());
143 if (m_loader) 150 return false;
144 didFail(nullptr,
145 ResourceError::cancelledDueToAccessCheckError(newRequest.url()));
146 } 151 }
152
153 // ResourceFetcher::willFollowRedirect() may rewrite the URL to
154 // something else not for rejecting redirect but for other reasons.
155 // E.g. WebFrameTestClient::willSendRequest() and
156 // RenderFrameImpl::willSendRequest(). We should reflect the
157 // rewriting but currently we cannot. So, return false to make the
158 // redirect fail.
159 if (newRequest.url() != originalURL) {
160 cancelForRedirectAccessCheckError(newRequest.url());
161 return false;
162 }
163
164 if (!m_resource->willFollowRedirect(newRequest, redirectResponse)) {
165 cancelForRedirectAccessCheckError(newRequest.url());
166 return false;
167 }
168
169 return true;
147 } 170 }
148 171
149 void ResourceLoader::didReceiveCachedMetadata(WebURLLoader*, 172 void ResourceLoader::didReceiveCachedMetadata(WebURLLoader*,
150 const char* data, 173 const char* data,
151 int length) { 174 int length) {
152 m_resource->setSerializedCachedMetadata(data, length); 175 m_resource->setSerializedCachedMetadata(data, length);
153 } 176 }
154 177
155 void ResourceLoader::didSendData(WebURLLoader*, 178 void ResourceLoader::didSendData(WebURLLoader*,
156 unsigned long long bytesSent, 179 unsigned long long bytesSent,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 // a 304, where it will overwrite the cached data we should be reusing. 258 // a 304, where it will overwrite the cached data we should be reusing.
236 if (dataOut.size()) { 259 if (dataOut.size()) {
237 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size(), 260 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size(),
238 encodedDataLength); 261 encodedDataLength);
239 m_resource->setResourceBuffer(dataOut); 262 m_resource->setResourceBuffer(dataOut);
240 } 263 }
241 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); 264 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength);
242 } 265 }
243 266
244 } // namespace blink 267 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ResourceLoader.h ('k') | third_party/WebKit/Source/core/loader/DocumentLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698