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

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

Issue 1710733002: Move multipart resource handling to core/fetch (2/2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@multipart-cleanup
Patch Set: Created 4 years, 9 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 namespace blink { 48 namespace blink {
49 49
50 ResourceLoader* ResourceLoader::create(ResourceFetcher* fetcher, Resource* resou rce) 50 ResourceLoader* ResourceLoader::create(ResourceFetcher* fetcher, Resource* resou rce)
51 { 51 {
52 return new ResourceLoader(fetcher, resource); 52 return new ResourceLoader(fetcher, resource);
53 } 53 }
54 54
55 ResourceLoader::ResourceLoader(ResourceFetcher* fetcher, Resource* resource) 55 ResourceLoader::ResourceLoader(ResourceFetcher* fetcher, Resource* resource)
56 : m_fetcher(fetcher) 56 : m_fetcher(fetcher)
57 , m_notifiedLoadComplete(false) 57 , m_notifiedLoadComplete(false)
58 , m_loadingMultipartContent(false)
59 , m_resource(resource) 58 , m_resource(resource)
60 , m_state(ConnectionStateNew) 59 , m_state(ConnectionStateNew)
61 { 60 {
62 ASSERT(m_resource); 61 ASSERT(m_resource);
63 ASSERT(m_fetcher); 62 ASSERT(m_fetcher);
64 } 63 }
65 64
66 ResourceLoader::~ResourceLoader() 65 ResourceLoader::~ResourceLoader()
67 { 66 {
68 ASSERT(m_state == ConnectionStateReleased); 67 ASSERT(m_state == ConnectionStateReleased);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 { 121 {
123 RELEASE_ASSERT(m_state == ConnectionStateReceivedResponse); 122 RELEASE_ASSERT(m_state == ConnectionStateReceivedResponse);
124 m_fetcher->didDownloadData(m_resource.get(), length, encodedDataLength); 123 m_fetcher->didDownloadData(m_resource.get(), length, encodedDataLength);
125 if (m_state == ConnectionStateReleased) 124 if (m_state == ConnectionStateReleased)
126 return; 125 return;
127 m_resource->didDownloadData(length); 126 m_resource->didDownloadData(length);
128 } 127 }
129 128
130 void ResourceLoader::didFinishLoadingOnePart(double finishTime, int64_t encodedD ataLength) 129 void ResourceLoader::didFinishLoadingOnePart(double finishTime, int64_t encodedD ataLength)
131 { 130 {
132 // If load has been cancelled after finishing (which could happen with a 131 ASSERT(m_state != ConnectionStateReleased);
133 // JavaScript that changes the window location), do nothing. 132 if (!isFinishing()) {
133 // When loading a multipart resource, make the loader non-block when
134 // finishing loading the first part.
135 m_fetcher->subresourceLoaderFinishedLoadingOnePart(this);
136 }
137
134 if (m_state == ConnectionStateReleased) 138 if (m_state == ConnectionStateReleased)
135 return; 139 return;
136 140
137 if (m_notifiedLoadComplete) 141 if (m_notifiedLoadComplete)
138 return; 142 return;
139 m_notifiedLoadComplete = true; 143 m_notifiedLoadComplete = true;
140 m_fetcher->didFinishLoading(m_resource.get(), finishTime, encodedDataLength) ; 144 m_fetcher->didFinishLoading(m_resource.get(), finishTime, encodedDataLength) ;
141 } 145 }
142 146
143 void ResourceLoader::didChangePriority(ResourceLoadPriority loadPriority, int in traPriorityValue) 147 void ResourceLoader::didChangePriority(ResourceLoadPriority loadPriority, int in traPriorityValue)
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 // If the fetch was (potentially) CORS enabled, an access control check of t he response is required. 222 // If the fetch was (potentially) CORS enabled, an access control check of t he response is required.
219 return m_resource->options().corsEnabled == IsCORSEnabled; 223 return m_resource->options().corsEnabled == IsCORSEnabled;
220 } 224 }
221 225
222 void ResourceLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& res ponse, WebDataConsumerHandle* rawHandle) 226 void ResourceLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& res ponse, WebDataConsumerHandle* rawHandle)
223 { 227 {
224 ASSERT(!response.isNull()); 228 ASSERT(!response.isNull());
225 // |rawHandle|'s ownership is transferred to the callee. 229 // |rawHandle|'s ownership is transferred to the callee.
226 OwnPtr<WebDataConsumerHandle> handle = adoptPtr(rawHandle); 230 OwnPtr<WebDataConsumerHandle> handle = adoptPtr(rawHandle);
227 231
228 bool isMultipartPayload = response.isMultipartPayload();
229 bool isValidStateTransition = (m_state == ConnectionStateStarted || m_state == ConnectionStateReceivedResponse); 232 bool isValidStateTransition = (m_state == ConnectionStateStarted || m_state == ConnectionStateReceivedResponse);
230 // In the case of multipart loads, calls to didReceiveData & didReceiveRespo nse can be interleaved. 233 RELEASE_ASSERT(isValidStateTransition);
231 RELEASE_ASSERT(isMultipartPayload || isValidStateTransition);
232 m_state = ConnectionStateReceivedResponse; 234 m_state = ConnectionStateReceivedResponse;
233 235
234 const ResourceResponse& resourceResponse = response.toResourceResponse(); 236 const ResourceResponse& resourceResponse = response.toResourceResponse();
235 237
236 if (responseNeedsAccessControlCheck()) { 238 if (responseNeedsAccessControlCheck()) {
237 if (response.wasFetchedViaServiceWorker()) { 239 if (response.wasFetchedViaServiceWorker()) {
238 if (response.wasFallbackRequiredByServiceWorker()) { 240 if (response.wasFallbackRequiredByServiceWorker()) {
239 m_loader->cancel(); 241 m_loader->cancel();
240 m_loader.clear(); 242 m_loader.clear();
241 m_state = ConnectionStateStarted; 243 m_state = ConnectionStateStarted;
(...skipping 17 matching lines...) Expand all
259 } 261 }
260 262
261 m_resource->responseReceived(resourceResponse, handle.release()); 263 m_resource->responseReceived(resourceResponse, handle.release());
262 if (m_state == ConnectionStateReleased) 264 if (m_state == ConnectionStateReleased)
263 return; 265 return;
264 266
265 m_fetcher->didReceiveResponse(m_resource.get(), resourceResponse); 267 m_fetcher->didReceiveResponse(m_resource.get(), resourceResponse);
266 if (m_state == ConnectionStateReleased) 268 if (m_state == ConnectionStateReleased)
267 return; 269 return;
268 270
269 if (response.toResourceResponse().isMultipart()) {
270 // We only support multipart for images, though the image may be loaded
271 // as a main resource that we end up displaying through an ImageDocument .
272 if (!m_resource->isImage() && m_resource->getType() != Resource::MainRes ource) {
273 cancel(ResourceError::cancelledError(resourceResponse.url()));
274 return;
275 }
276 m_loadingMultipartContent = true;
277 } else if (isMultipartPayload) {
278 // Since a subresource loader does not load multipart sections progressi vely, data was delivered to the loader all at once.
279 // After the first multipart section is complete, signal to delegates th at this load is "finished"
280 m_fetcher->subresourceLoaderFinishedLoadingOnePart(this);
281 didFinishLoadingOnePart(0, WebURLLoaderClient::kUnknownEncodedDataLength );
282 }
283 if (m_state == ConnectionStateReleased)
284 return;
285
286 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor eHTTPStatusCodeErrors()) 271 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor eHTTPStatusCodeErrors())
287 return; 272 return;
288 273
289 if (!m_notifiedLoadComplete) { 274 if (!m_notifiedLoadComplete) {
290 m_notifiedLoadComplete = true; 275 m_notifiedLoadComplete = true;
291 m_fetcher->didFailLoading(m_resource.get(), ResourceError::cancelledErro r(resourceResponse.url())); 276 m_fetcher->didFailLoading(m_resource.get(), ResourceError::cancelledErro r(resourceResponse.url()));
292 } 277 }
293 278
294 ASSERT(m_state != ConnectionStateReleased); 279 ASSERT(m_state != ConnectionStateReleased);
295 m_resource->error(Resource::LoadError); 280 m_resource->error(Resource::LoadError);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 // empty buffer is a noop in most cases, but is destructive in the case of 394 // empty buffer is a noop in most cases, but is destructive in the case of
410 // a 304, where it will overwrite the cached data we should be reusing. 395 // a 304, where it will overwrite the cached data we should be reusing.
411 if (dataOut.size()) { 396 if (dataOut.size()) {
412 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size (), encodedDataLength); 397 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size (), encodedDataLength);
413 m_resource->setResourceBuffer(dataOut); 398 m_resource->setResourceBuffer(dataOut);
414 } 399 }
415 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); 400 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength);
416 } 401 }
417 402
418 } // namespace blink 403 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ResourceLoader.h ('k') | third_party/WebKit/Source/core/html/ImageDocument.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698