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

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: Addressed jochen's point 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 { 116 {
117 if (m_loader) 117 if (m_loader)
118 m_loader->didChangePriority(static_cast<WebURLRequest::Priority>(loadPri ority), intraPriorityValue); 118 m_loader->didChangePriority(static_cast<WebURLRequest::Priority>(loadPri ority), intraPriorityValue);
119 } 119 }
120 120
121 void ResourceLoader::cancel() 121 void ResourceLoader::cancel()
122 { 122 {
123 didFail(nullptr, ResourceError::cancelledError(m_resource->lastResourceReque st().url())); 123 didFail(nullptr, ResourceError::cancelledError(m_resource->lastResourceReque st().url()));
124 } 124 }
125 125
126 void ResourceLoader::willFollowRedirect(WebURLLoader*, WebURLRequest& passedNewR equest, const WebURLResponse& passedRedirectResponse, int64_t encodedDataLength) 126 void ResourceLoader::cancelForRedirectAccessCheckError(const KURL& newURL)
127 {
128 m_resource->willNotFollowRedirect();
129
130 if (m_loader)
131 didFail(nullptr, ResourceError::cancelledDueToAccessCheckError(newURL));
132 }
133
134 bool ResourceLoader::willFollowRedirect(WebURLLoader*, WebURLRequest& passedNewR equest, const WebURLResponse& passedRedirectResponse, int64_t encodedDataLength)
127 { 135 {
128 DCHECK(!passedNewRequest.isNull()); 136 DCHECK(!passedNewRequest.isNull());
129 DCHECK(!passedRedirectResponse.isNull()); 137 DCHECK(!passedRedirectResponse.isNull());
130 138
131 ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest()); 139 ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest());
132 const ResourceResponse& redirectResponse(passedRedirectResponse.toResourceRe sponse()); 140 const ResourceResponse& redirectResponse(passedRedirectResponse.toResourceRe sponse());
133 newRequest.setRedirectStatus(ResourceRequest::RedirectStatus::FollowedRedire ct); 141 newRequest.setRedirectStatus(ResourceRequest::RedirectStatus::FollowedRedire ct);
134 142
135 if (m_fetcher->willFollowRedirect(m_resource.get(), newRequest, redirectResp onse, encodedDataLength)) { 143 const KURL originalURL = newRequest.url();
136 m_resource->willFollowRedirect(newRequest, redirectResponse); 144
137 } else { 145 if (!m_fetcher->willFollowRedirect(m_resource.get(), newRequest, redirectRes ponse, encodedDataLength)) {
138 m_resource->willNotFollowRedirect(); 146 cancelForRedirectAccessCheckError(newRequest.url());
139 if (m_loader) 147 return false;
140 didFail(nullptr, ResourceError::cancelledDueToAccessCheckError(newRe quest.url()));
141 } 148 }
149
150 // ResourceFetcher::willFollowRedirect() may rewrite the URL to
151 // something else not for rejecting redirect but for other reasons.
152 // E.g. WebFrameTestClient::willSendRequest() and
153 // RenderFrameImpl::willSendRequest(). We should reflect the
154 // rewriting but currently we cannot. So, return false to make the
155 // redirect fail.
156 if (newRequest.url() != originalURL) {
157 cancelForRedirectAccessCheckError(newRequest.url());
158 return false;
159 }
160
161 if (!m_resource->willFollowRedirect(newRequest, redirectResponse)) {
162 cancelForRedirectAccessCheckError(newRequest.url());
163 return false;
164 }
165
166 return true;
142 } 167 }
143 168
144 void ResourceLoader::didReceiveCachedMetadata(WebURLLoader*, const char* data, i nt length) 169 void ResourceLoader::didReceiveCachedMetadata(WebURLLoader*, const char* data, i nt length)
145 { 170 {
146 m_resource->setSerializedCachedMetadata(data, length); 171 m_resource->setSerializedCachedMetadata(data, length);
147 } 172 }
148 173
149 void ResourceLoader::didSendData(WebURLLoader*, unsigned long long bytesSent, un signed long long totalBytesToBeSent) 174 void ResourceLoader::didSendData(WebURLLoader*, unsigned long long bytesSent, un signed long long totalBytesToBeSent)
150 { 175 {
151 m_resource->didSendData(bytesSent, totalBytesToBeSent); 176 m_resource->didSendData(bytesSent, totalBytesToBeSent);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 // empty buffer is a noop in most cases, but is destructive in the case of 245 // empty buffer is a noop in most cases, but is destructive in the case of
221 // a 304, where it will overwrite the cached data we should be reusing. 246 // a 304, where it will overwrite the cached data we should be reusing.
222 if (dataOut.size()) { 247 if (dataOut.size()) {
223 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size (), encodedDataLength); 248 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size (), encodedDataLength);
224 m_resource->setResourceBuffer(dataOut); 249 m_resource->setResourceBuffer(dataOut);
225 } 250 }
226 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); 251 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength);
227 } 252 }
228 253
229 } // namespace blink 254 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698