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

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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 { 62 {
63 ResourceLoader* loader = new ResourceLoader(fetcher, resource, options); 63 ResourceLoader* loader = new ResourceLoader(fetcher, resource, options);
64 loader->init(request); 64 loader->init(request);
65 return loader; 65 return loader;
66 } 66 }
67 67
68 ResourceLoader::ResourceLoader(ResourceFetcher* fetcher, Resource* resource, con st ResourceLoaderOptions& options) 68 ResourceLoader::ResourceLoader(ResourceFetcher* fetcher, Resource* resource, con st ResourceLoaderOptions& options)
69 : m_fetcher(fetcher) 69 : m_fetcher(fetcher)
70 , m_notifiedLoadComplete(false) 70 , m_notifiedLoadComplete(false)
71 , m_defersLoading(fetcher->defersLoading()) 71 , m_defersLoading(fetcher->defersLoading())
72 , m_loadingMultipartContent(false)
73 , m_options(options) 72 , m_options(options)
74 , m_resource(resource) 73 , m_resource(resource)
75 , m_state(Initialized) 74 , m_state(Initialized)
76 , m_connectionState(ConnectionStateNew) 75 , m_connectionState(ConnectionStateNew)
77 { 76 {
78 ASSERT(m_resource); 77 ASSERT(m_resource);
79 ASSERT(m_fetcher); 78 ASSERT(m_fetcher);
80 } 79 }
81 80
82 ResourceLoader::~ResourceLoader() 81 ResourceLoader::~ResourceLoader()
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 ASSERT(m_state != Terminated); 194 ASSERT(m_state != Terminated);
196 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse); 195 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse);
197 m_fetcher->didDownloadData(m_resource.get(), length, encodedDataLength); 196 m_fetcher->didDownloadData(m_resource.get(), length, encodedDataLength);
198 if (m_state == Terminated) 197 if (m_state == Terminated)
199 return; 198 return;
200 m_resource->didDownloadData(length); 199 m_resource->didDownloadData(length);
201 } 200 }
202 201
203 void ResourceLoader::didFinishLoadingOnePart(double finishTime, int64_t encodedD ataLength) 202 void ResourceLoader::didFinishLoadingOnePart(double finishTime, int64_t encodedD ataLength)
204 { 203 {
205 // If load has been cancelled after finishing (which could happen with a 204 ASSERT(m_state != Terminated);
Nate Chapin 2016/03/01 19:02:15 This means we both ASSERT and early-exit for this
yhirano 2016/03/01 19:43:23 Calling subresourceLoaderFinishedLoadingOnePar may
Nate Chapin 2016/03/01 19:56:45 ...of course. Never mind :)
206 // JavaScript that changes the window location), do nothing. 205 if (m_state != Finishing) {
206 // When loading a multipart resource, make the loader non-block when
207 // finishing loading the first part.
208 m_fetcher->subresourceLoaderFinishedLoadingOnePart(this);
209 }
210
207 if (m_state == Terminated) 211 if (m_state == Terminated)
208 return; 212 return;
209 213
210 if (m_notifiedLoadComplete) 214 if (m_notifiedLoadComplete)
211 return; 215 return;
212 m_notifiedLoadComplete = true; 216 m_notifiedLoadComplete = true;
213 m_fetcher->didFinishLoading(m_resource.get(), finishTime, encodedDataLength) ; 217 m_fetcher->didFinishLoading(m_resource.get(), finishTime, encodedDataLength) ;
214 } 218 }
215 219
216 void ResourceLoader::didChangePriority(ResourceLoadPriority loadPriority, int in traPriorityValue) 220 void ResourceLoader::didChangePriority(ResourceLoadPriority loadPriority, int in traPriorityValue)
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 return m_options.corsEnabled == IsCORSEnabled; 319 return m_options.corsEnabled == IsCORSEnabled;
316 } 320 }
317 321
318 void ResourceLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& res ponse, WebDataConsumerHandle* rawHandle) 322 void ResourceLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& res ponse, WebDataConsumerHandle* rawHandle)
319 { 323 {
320 ASSERT(!response.isNull()); 324 ASSERT(!response.isNull());
321 ASSERT(m_state == Initialized); 325 ASSERT(m_state == Initialized);
322 // |rawHandle|'s ownership is transferred to the callee. 326 // |rawHandle|'s ownership is transferred to the callee.
323 OwnPtr<WebDataConsumerHandle> handle = adoptPtr(rawHandle); 327 OwnPtr<WebDataConsumerHandle> handle = adoptPtr(rawHandle);
324 328
325 bool isMultipartPayload = response.isMultipartPayload();
326 bool isValidStateTransition = (m_connectionState == ConnectionStateStarted | | m_connectionState == ConnectionStateReceivedResponse); 329 bool isValidStateTransition = (m_connectionState == ConnectionStateStarted | | m_connectionState == ConnectionStateReceivedResponse);
327 // In the case of multipart loads, calls to didReceiveData & didReceiveRespo nse can be interleaved. 330 RELEASE_ASSERT(isValidStateTransition);
328 RELEASE_ASSERT(isMultipartPayload || isValidStateTransition);
329 m_connectionState = ConnectionStateReceivedResponse; 331 m_connectionState = ConnectionStateReceivedResponse;
330 332
331 const ResourceResponse& resourceResponse = response.toResourceResponse(); 333 const ResourceResponse& resourceResponse = response.toResourceResponse();
332 334
333 if (responseNeedsAccessControlCheck()) { 335 if (responseNeedsAccessControlCheck()) {
334 if (response.wasFetchedViaServiceWorker()) { 336 if (response.wasFetchedViaServiceWorker()) {
335 if (response.wasFallbackRequiredByServiceWorker()) { 337 if (response.wasFallbackRequiredByServiceWorker()) {
336 m_loader->cancel(); 338 m_loader->cancel();
337 m_loader.clear(); 339 m_loader.clear();
338 m_connectionState = ConnectionStateStarted; 340 m_connectionState = ConnectionStateStarted;
(...skipping 17 matching lines...) Expand all
356 } 358 }
357 359
358 m_resource->responseReceived(resourceResponse, handle.release()); 360 m_resource->responseReceived(resourceResponse, handle.release());
359 if (m_state == Terminated) 361 if (m_state == Terminated)
360 return; 362 return;
361 363
362 m_fetcher->didReceiveResponse(m_resource.get(), resourceResponse); 364 m_fetcher->didReceiveResponse(m_resource.get(), resourceResponse);
363 if (m_state == Terminated) 365 if (m_state == Terminated)
364 return; 366 return;
365 367
366 if (response.toResourceResponse().isMultipart()) {
367 // We only support multipart for images, though the image may be loaded
368 // as a main resource that we end up displaying through an ImageDocument .
369 if (!m_resource->isImage() && m_resource->getType() != Resource::MainRes ource) {
370 cancel();
371 return;
372 }
373 m_loadingMultipartContent = true;
374 } else if (isMultipartPayload) {
375 // Since a subresource loader does not load multipart sections progressi vely, data was delivered to the loader all at once.
376 // After the first multipart section is complete, signal to delegates th at this load is "finished"
377 m_fetcher->subresourceLoaderFinishedLoadingOnePart(this);
378 didFinishLoadingOnePart(0, WebURLLoaderClient::kUnknownEncodedDataLength );
379 }
380 if (m_state == Terminated)
381 return;
382
383 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor eHTTPStatusCodeErrors()) 368 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor eHTTPStatusCodeErrors())
384 return; 369 return;
385 m_state = Finishing; 370 m_state = Finishing;
386 371
387 if (!m_notifiedLoadComplete) { 372 if (!m_notifiedLoadComplete) {
388 m_notifiedLoadComplete = true; 373 m_notifiedLoadComplete = true;
389 m_fetcher->didFailLoading(m_resource.get(), ResourceError::cancelledErro r(m_request.url())); 374 m_fetcher->didFailLoading(m_resource.get(), ResourceError::cancelledErro r(m_request.url()));
390 } 375 }
391 376
392 ASSERT(m_state != Terminated); 377 ASSERT(m_state != Terminated);
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); 506 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength);
522 } 507 }
523 508
524 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const 509 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const
525 { 510 {
526 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC redentials); 511 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC redentials);
527 return request; 512 return request;
528 } 513 }
529 514
530 } // namespace blink 515 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698