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

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 #38 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 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 { 127 {
128 ASSERT(!passedNewRequest.isNull()); 128 m_resource->willNotFollowRedirect();
129 ASSERT(!passedRedirectResponse.isNull());
130 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)
135 {
131 ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest()); 136 ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest());
132 const ResourceResponse& redirectResponse(passedRedirectResponse.toResourceRe sponse()); 137 const ResourceResponse& redirectResponse(passedRedirectResponse.toResourceRe sponse());
133 newRequest.setRedirectStatus(ResourceRequest::RedirectStatus::FollowedRedire ct); 138 newRequest.setRedirectStatus(ResourceRequest::RedirectStatus::FollowedRedire ct);
134 139
135 if (m_fetcher->willFollowRedirect(m_resource.get(), newRequest, redirectResp onse, encodedDataLength)) { 140 const KURL originalURL = newRequest.url();
136 m_resource->willFollowRedirect(newRequest, redirectResponse); 141
137 } else { 142 if (!m_fetcher->willFollowRedirect(m_resource.get(), newRequest, redirectRes ponse, encodedDataLength)) {
138 m_resource->willNotFollowRedirect(); 143 cancelForRedirectAccessCheckError(newRequest.url());
139 if (m_loader) 144 return false;
140 didFail(nullptr, ResourceError::cancelledDueToAccessCheckError(newRe quest.url()));
141 } 145 }
146
147 // ResourceFetcher::willFollowRedirect() may rewrite the URL to
148 // something else not for rejecting redirect but for other reasons.
149 // E.g. WebFrameTestClient::willSendRequest() and
150 // RenderFrameImpl::willSendRequest(). We should reflect the
151 // rewriting but currently we cannot. So, return false to make the
152 // redirect fail.
153 if (newRequest.url() != originalURL) {
154 cancelForRedirectAccessCheckError(newRequest.url());
155 return false;
156 }
157
158 if (!m_resource->willFollowRedirect(newRequest, redirectResponse)) {
159 cancelForRedirectAccessCheckError(newRequest.url());
160 return false;
161 }
162
163 return true;
142 } 164 }
143 165
144 void ResourceLoader::didReceiveCachedMetadata(WebURLLoader*, const char* data, i nt length) 166 void ResourceLoader::didReceiveCachedMetadata(WebURLLoader*, const char* data, i nt length)
145 { 167 {
146 m_resource->setSerializedCachedMetadata(data, length); 168 m_resource->setSerializedCachedMetadata(data, length);
147 } 169 }
148 170
149 void ResourceLoader::didSendData(WebURLLoader*, unsigned long long bytesSent, un signed long long totalBytesToBeSent) 171 void ResourceLoader::didSendData(WebURLLoader*, unsigned long long bytesSent, un signed long long totalBytesToBeSent)
150 { 172 {
151 m_resource->didSendData(bytesSent, totalBytesToBeSent); 173 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 242 // 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. 243 // a 304, where it will overwrite the cached data we should be reusing.
222 if (dataOut.size()) { 244 if (dataOut.size()) {
223 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size (), encodedDataLength); 245 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size (), encodedDataLength);
224 m_resource->setResourceBuffer(dataOut); 246 m_resource->setResourceBuffer(dataOut);
225 } 247 }
226 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); 248 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength);
227 } 249 }
228 250
229 } // namespace blink 251 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698