OLD | NEW |
---|---|
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 } | 80 } |
81 | 81 |
82 ResourceLoader::~ResourceLoader() | 82 ResourceLoader::~ResourceLoader() |
83 { | 83 { |
84 ASSERT(m_state == Terminated); | 84 ASSERT(m_state == Terminated); |
85 } | 85 } |
86 | 86 |
87 void ResourceLoader::releaseResources() | 87 void ResourceLoader::releaseResources() |
88 { | 88 { |
89 ASSERT(m_state != Terminated); | 89 ASSERT(m_state != Terminated); |
90 if (!m_notifiedLoadComplete) { | |
Nate Chapin
2014/02/03 18:01:50
I *think* it's impossible to get here without m_no
| |
91 m_notifiedLoadComplete = true; | |
92 m_host->didFailLoading(m_resource, ResourceError::cancelledError(m_reque st.url())); | |
93 } | |
90 m_requestCountTracker.clear(); | 94 m_requestCountTracker.clear(); |
91 m_host->didLoadResource(m_resource); | 95 m_host->didLoadResource(m_resource); |
92 if (m_state == Terminated) | 96 if (m_state == Terminated) |
93 return; | 97 return; |
94 m_resource->clearLoader(); | 98 m_resource->clearLoader(); |
95 m_host->willTerminateResourceLoader(this); | 99 m_host->willTerminateResourceLoader(this); |
96 | 100 |
97 ASSERT(m_state != Terminated); | 101 ASSERT(m_state != Terminated); |
98 | 102 |
99 // It's possible that when we release the loader, it will be | 103 // It's possible that when we release the loader, it will be |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 if (m_state == Initialized) | 244 if (m_state == Initialized) |
241 m_state = Finishing; | 245 m_state = Finishing; |
242 m_resource->setResourceError(nonNullError); | 246 m_resource->setResourceError(nonNullError); |
243 | 247 |
244 if (m_loader) { | 248 if (m_loader) { |
245 m_connectionState = ConnectionStateCanceled; | 249 m_connectionState = ConnectionStateCanceled; |
246 m_loader->cancel(); | 250 m_loader->cancel(); |
247 m_loader.clear(); | 251 m_loader.clear(); |
248 } | 252 } |
249 | 253 |
250 m_host->didFailLoading(m_resource, nonNullError); | 254 if (!m_notifiedLoadComplete) { |
255 m_notifiedLoadComplete = true; | |
256 m_host->didFailLoading(m_resource, nonNullError); | |
257 } | |
251 | 258 |
252 if (m_state == Finishing) | 259 if (m_state == Finishing) |
253 m_resource->error(Resource::LoadError); | 260 m_resource->error(Resource::LoadError); |
254 if (m_state != Terminated) | 261 if (m_state != Terminated) |
255 releaseResources(); | 262 releaseResources(); |
256 } | 263 } |
257 | 264 |
258 void ResourceLoader::willSendRequest(blink::WebURLLoader*, blink::WebURLRequest& passedRequest, const blink::WebURLResponse& passedRedirectResponse) | 265 void ResourceLoader::willSendRequest(blink::WebURLLoader*, blink::WebURLRequest& passedRequest, const blink::WebURLResponse& passedRedirectResponse) |
259 { | 266 { |
260 RefPtr<ResourceLoader> protect(this); | 267 RefPtr<ResourceLoader> protect(this); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 } else if (isMultipartPayload) { | 353 } else if (isMultipartPayload) { |
347 // Since a subresource loader does not load multipart sections progressi vely, data was delivered to the loader all at once. | 354 // Since a subresource loader does not load multipart sections progressi vely, data was delivered to the loader all at once. |
348 // After the first multipart section is complete, signal to delegates th at this load is "finished" | 355 // After the first multipart section is complete, signal to delegates th at this load is "finished" |
349 m_host->subresourceLoaderFinishedLoadingOnePart(this); | 356 m_host->subresourceLoaderFinishedLoadingOnePart(this); |
350 didFinishLoadingOnePart(0); | 357 didFinishLoadingOnePart(0); |
351 } | 358 } |
352 | 359 |
353 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor eHTTPStatusCodeErrors()) | 360 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor eHTTPStatusCodeErrors()) |
354 return; | 361 return; |
355 m_state = Finishing; | 362 m_state = Finishing; |
363 | |
364 if (!m_notifiedLoadComplete) { | |
365 m_notifiedLoadComplete = true; | |
366 m_host->didFailLoading(m_resource, ResourceError::cancelledError(m_reque st.url())); | |
367 } | |
368 | |
356 m_resource->error(Resource::LoadError); | 369 m_resource->error(Resource::LoadError); |
Nate Chapin
2014/02/03 18:01:50
Hmm...I wonder if cancel() could just take care of
| |
357 cancel(); | 370 cancel(); |
358 } | 371 } |
359 | 372 |
360 void ResourceLoader::didReceiveData(blink::WebURLLoader*, const char* data, int length, int encodedDataLength) | 373 void ResourceLoader::didReceiveData(blink::WebURLLoader*, const char* data, int length, int encodedDataLength) |
361 { | 374 { |
362 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con nectionState == ConnectionStateReceivingData); | 375 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con nectionState == ConnectionStateReceivingData); |
363 m_connectionState = ConnectionStateReceivingData; | 376 m_connectionState = ConnectionStateReceivingData; |
364 | 377 |
365 // It is possible to receive data on uninitialized resources if it had an er ror status code, and we are running a nested message | 378 // It is possible to receive data on uninitialized resources if it had an er ror status code, and we are running a nested message |
366 // loop. When this occurs, ignoring the data is the correct action. | 379 // loop. When this occurs, ignoring the data is the correct action. |
(...skipping 17 matching lines...) Expand all Loading... | |
384 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con nectionState == ConnectionStateReceivingData); | 397 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con nectionState == ConnectionStateReceivingData); |
385 m_connectionState = ConnectionStateFinishedLoading; | 398 m_connectionState = ConnectionStateFinishedLoading; |
386 if (m_state != Initialized) | 399 if (m_state != Initialized) |
387 return; | 400 return; |
388 ASSERT(m_state != Terminated); | 401 ASSERT(m_state != Terminated); |
389 WTF_LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1 ().data()); | 402 WTF_LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1 ().data()); |
390 | 403 |
391 RefPtr<ResourceLoader> protect(this); | 404 RefPtr<ResourceLoader> protect(this); |
392 ResourcePtr<Resource> protectResource(m_resource); | 405 ResourcePtr<Resource> protectResource(m_resource); |
393 m_state = Finishing; | 406 m_state = Finishing; |
407 didFinishLoadingOnePart(finishTime); | |
394 m_resource->finish(finishTime); | 408 m_resource->finish(finishTime); |
395 didFinishLoadingOnePart(finishTime); | |
396 | 409 |
397 // If the load has been cancelled by a delegate in response to didFinishLoad (), do not release | 410 // If the load has been cancelled by a delegate in response to didFinishLoad (), do not release |
398 // the resources a second time, they have been released by cancel. | 411 // the resources a second time, they have been released by cancel. |
399 if (m_state == Terminated) | 412 if (m_state == Terminated) |
400 return; | 413 return; |
401 releaseResources(); | 414 releaseResources(); |
402 } | 415 } |
403 | 416 |
404 void ResourceLoader::didFail(blink::WebURLLoader*, const blink::WebURLError& err or) | 417 void ResourceLoader::didFail(blink::WebURLLoader*, const blink::WebURLError& err or) |
405 { | 418 { |
406 m_connectionState = ConnectionStateFailed; | 419 m_connectionState = ConnectionStateFailed; |
407 ASSERT(m_state != Terminated); | 420 ASSERT(m_state != Terminated); |
408 WTF_LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().string( ).latin1().data()); | 421 WTF_LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().string( ).latin1().data()); |
409 | 422 |
410 RefPtr<ResourceLoader> protect(this); | 423 RefPtr<ResourceLoader> protect(this); |
411 RefPtr<ResourceLoaderHost> protectHost(m_host); | 424 RefPtr<ResourceLoaderHost> protectHost(m_host); |
412 ResourcePtr<Resource> protectResource(m_resource); | 425 ResourcePtr<Resource> protectResource(m_resource); |
413 m_state = Finishing; | 426 m_state = Finishing; |
414 m_resource->setResourceError(error); | 427 m_resource->setResourceError(error); |
415 m_resource->error(Resource::LoadError); | |
416 | |
417 if (m_state == Terminated) | |
418 return; | |
419 | 428 |
420 if (!m_notifiedLoadComplete) { | 429 if (!m_notifiedLoadComplete) { |
421 m_notifiedLoadComplete = true; | 430 m_notifiedLoadComplete = true; |
422 m_host->didFailLoading(m_resource, error); | 431 m_host->didFailLoading(m_resource, error); |
423 } | 432 } |
424 | 433 |
434 m_resource->error(Resource::LoadError); | |
435 | |
436 if (m_state == Terminated) | |
437 return; | |
438 | |
425 releaseResources(); | 439 releaseResources(); |
426 } | 440 } |
427 | 441 |
428 bool ResourceLoader::isLoadedBy(ResourceLoaderHost* loader) const | 442 bool ResourceLoader::isLoadedBy(ResourceLoaderHost* loader) const |
429 { | 443 { |
430 return m_host->isLoadedBy(loader); | 444 return m_host->isLoadedBy(loader); |
431 } | 445 } |
432 | 446 |
433 void ResourceLoader::requestSynchronously() | 447 void ResourceLoader::requestSynchronously() |
434 { | 448 { |
(...skipping 21 matching lines...) Expand all Loading... | |
456 didReceiveResponse(0, responseOut); | 470 didReceiveResponse(0, responseOut); |
457 if (m_state == Terminated) | 471 if (m_state == Terminated) |
458 return; | 472 return; |
459 RefPtr<ResourceLoadInfo> resourceLoadInfo = responseOut.toResourceResponse() .resourceLoadInfo(); | 473 RefPtr<ResourceLoadInfo> resourceLoadInfo = responseOut.toResourceResponse() .resourceLoadInfo(); |
460 m_host->didReceiveData(m_resource, dataOut.data(), dataOut.size(), resourceL oadInfo ? resourceLoadInfo->encodedDataLength : -1); | 474 m_host->didReceiveData(m_resource, dataOut.data(), dataOut.size(), resourceL oadInfo ? resourceLoadInfo->encodedDataLength : -1); |
461 m_resource->setResourceBuffer(dataOut); | 475 m_resource->setResourceBuffer(dataOut); |
462 didFinishLoading(0, monotonicallyIncreasingTime()); | 476 didFinishLoading(0, monotonicallyIncreasingTime()); |
463 } | 477 } |
464 | 478 |
465 } | 479 } |
OLD | NEW |