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

Side by Side Diff: third_party/WebKit/Source/core/fetch/ResourceLoader.cpp

Issue 1975373002: Clean up response handling in ResourceLoader/ResourceFetcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 5 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 m_loader->setDefersLoading(defersLoading); 86 m_loader->setDefersLoading(defersLoading);
87 ASSERT(m_loader); 87 ASSERT(m_loader);
88 m_loader->setLoadingTaskRunner(loadingTaskRunner); 88 m_loader->setLoadingTaskRunner(loadingTaskRunner);
89 89
90 if (m_resource->options().synchronousPolicy == RequestSynchronously) 90 if (m_resource->options().synchronousPolicy == RequestSynchronously)
91 requestSynchronously(request); 91 requestSynchronously(request);
92 else 92 else
93 m_loader->loadAsynchronously(WrappedResourceRequest(request), this); 93 m_loader->loadAsynchronously(WrappedResourceRequest(request), this);
94 } 94 }
95 95
96 void ResourceLoader::restart(const ResourceRequest& request)
hiroshige 2016/07/28 09:56:42 I think the name of |restart| is too general, beca
Nate Chapin 2016/07/28 22:29:35 Renamed to restartForServiceWorkerFallback.
97 {
98 m_loader.reset();
99 m_loader = wrapUnique(Platform::current()->createURLLoader());
100 DCHECK(m_loader);
101 m_loader->loadAsynchronously(WrappedResourceRequest(request), this);
102 }
103
96 void ResourceLoader::setDefersLoading(bool defers) 104 void ResourceLoader::setDefersLoading(bool defers)
97 { 105 {
98 ASSERT(m_loader); 106 ASSERT(m_loader);
99 m_loader->setDefersLoading(defers); 107 m_loader->setDefersLoading(defers);
100 } 108 }
101 109
102 void ResourceLoader::didDownloadData(WebURLLoader*, int length, int encodedDataL ength) 110 void ResourceLoader::didDownloadData(WebURLLoader*, int length, int encodedDataL ength)
103 { 111 {
104 m_fetcher->didDownloadData(m_resource.get(), length, encodedDataLength); 112 m_fetcher->didDownloadData(m_resource.get(), length, encodedDataLength);
105 m_resource->didDownloadData(length); 113 m_resource->didDownloadData(length);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 void ResourceLoader::didReceiveCachedMetadata(WebURLLoader*, const char* data, i nt length) 145 void ResourceLoader::didReceiveCachedMetadata(WebURLLoader*, const char* data, i nt length)
138 { 146 {
139 m_resource->setSerializedCachedMetadata(data, length); 147 m_resource->setSerializedCachedMetadata(data, length);
140 } 148 }
141 149
142 void ResourceLoader::didSendData(WebURLLoader*, unsigned long long bytesSent, un signed long long totalBytesToBeSent) 150 void ResourceLoader::didSendData(WebURLLoader*, unsigned long long bytesSent, un signed long long totalBytesToBeSent)
143 { 151 {
144 m_resource->didSendData(bytesSent, totalBytesToBeSent); 152 m_resource->didSendData(bytesSent, totalBytesToBeSent);
145 } 153 }
146 154
147 bool ResourceLoader::responseNeedsAccessControlCheck() const
148 {
149 // If the fetch was (potentially) CORS enabled, an access control check of t he response is required.
150 return m_resource->options().corsEnabled == IsCORSEnabled;
151 }
152
153 void ResourceLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& res ponse, WebDataConsumerHandle* rawHandle) 155 void ResourceLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& res ponse, WebDataConsumerHandle* rawHandle)
154 { 156 {
155 DCHECK(!response.isNull()); 157 DCHECK(!response.isNull());
156 // |rawHandle|'s ownership is transferred to the callee. 158 // |rawHandle|'s ownership is transferred to the callee.
157 std::unique_ptr<WebDataConsumerHandle> handle = wrapUnique(rawHandle); 159 std::unique_ptr<WebDataConsumerHandle> handle = wrapUnique(rawHandle);
158 const ResourceResponse& resourceResponse = response.toResourceResponse(); 160 const ResourceResponse& resourceResponse = response.toResourceResponse();
159 161 if (!m_fetcher->didReceiveResponse(m_resource.get(), resourceResponse))
160 if (responseNeedsAccessControlCheck()) { 162 return;
161 if (response.wasFetchedViaServiceWorker()) {
162 if (response.wasFallbackRequiredByServiceWorker()) {
163 m_loader.reset();
164 m_loader = wrapUnique(Platform::current()->createURLLoader());
165 DCHECK(m_loader);
166 ResourceRequest request = m_resource->lastResourceRequest();
167 DCHECK_EQ(request.skipServiceWorker(), WebURLRequest::SkipServic eWorker::None);
168 // This code handles the case when a regular controlling service worker
169 // doesn't handle a cross origin request. When this happens we s till
170 // want to give foreign fetch a chance to handle the request, so
171 // only skip the controlling service worker for the fallback req uest.
172 // This is currently safe because of http://crbug.com/604084 the
173 // wasFallbackRequiredByServiceWorker flag is never set when for eign fetch
174 // handled a request.
175 request.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::C ontrolling);
176 m_loader->loadAsynchronously(WrappedResourceRequest(request), th is);
177 return;
178 }
179 } else {
180 if (!m_resource->isCacheValidator() || resourceResponse.httpStatusCo de() != 304)
181 m_resource->setResponse(resourceResponse);
hiroshige 2016/07/28 09:56:42 This CL removes this setResponse(). It's probably
Nate Chapin 2016/07/28 22:29:35 Mostly correct. The only reason it needed to be he
182 if (!m_fetcher->canAccessResource(m_resource.get(), m_resource->opti ons().securityOrigin.get(), response.url(), ResourceFetcher::ShouldLogAccessCont rolErrors)) {
183 m_fetcher->didReceiveResponse(m_resource.get(), resourceResponse );
184 didFail(nullptr, ResourceError::cancelledDueToAccessCheckError(K URL(response.url())));
185 return;
186 }
187 }
188 }
189
190 m_resource->responseReceived(resourceResponse, std::move(handle)); 163 m_resource->responseReceived(resourceResponse, std::move(handle));
191 if (!m_loader) 164 if (response.httpStatusCode() >= 400 && !m_resource->shouldIgnoreHTTPStatusC odeErrors())
hiroshige 2016/07/28 09:56:42 Do we need |if (!m_loader) return;| before this?
Nate Chapin 2016/07/28 22:29:35 This moved to ResourceFetcher, but add a resource-
192 return; 165 didFail(nullptr, ResourceError::cancelledError(resourceResponse.url()));
193
194 m_fetcher->didReceiveResponse(m_resource.get(), resourceResponse);
195 if (!m_loader)
196 return;
197
198 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor eHTTPStatusCodeErrors())
199 return;
200 didFail(nullptr, ResourceError::cancelledError(resourceResponse.url()));
201 } 166 }
202 167
203 void ResourceLoader::didReceiveResponse(WebURLLoader* loader, const WebURLRespon se& response) 168 void ResourceLoader::didReceiveResponse(WebURLLoader* loader, const WebURLRespon se& response)
204 { 169 {
205 didReceiveResponse(loader, response, nullptr); 170 didReceiveResponse(loader, response, nullptr);
206 } 171 }
207 172
208 void ResourceLoader::didReceiveData(WebURLLoader*, const char* data, int length, int encodedDataLength, int encodedBodyLength) 173 void ResourceLoader::didReceiveData(WebURLLoader*, const char* data, int length, int encodedDataLength, int encodedBodyLength)
209 { 174 {
210 RELEASE_ASSERT(length >= 0); 175 RELEASE_ASSERT(length >= 0);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 // empty buffer is a noop in most cases, but is destructive in the case of 229 // empty buffer is a noop in most cases, but is destructive in the case of
265 // a 304, where it will overwrite the cached data we should be reusing. 230 // a 304, where it will overwrite the cached data we should be reusing.
266 if (dataOut.size()) { 231 if (dataOut.size()) {
267 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size (), encodedDataLength); 232 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size (), encodedDataLength);
268 m_resource->setResourceBuffer(dataOut); 233 m_resource->setResourceBuffer(dataOut);
269 } 234 }
270 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); 235 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength);
271 } 236 }
272 237
273 } // namespace blink 238 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698