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