| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 void ResourceLoader::trace(Visitor* visitor) | 95 void ResourceLoader::trace(Visitor* visitor) |
| 96 { | 96 { |
| 97 visitor->trace(m_host); | 97 visitor->trace(m_host); |
| 98 visitor->trace(m_resource); | 98 visitor->trace(m_resource); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void ResourceLoader::releaseResources() | 101 void ResourceLoader::releaseResources() |
| 102 { | 102 { |
| 103 ASSERT(m_state != Terminated); | 103 ASSERT(m_state != Terminated); |
| 104 ASSERT(m_notifiedLoadComplete); | 104 ASSERT(m_notifiedLoadComplete); |
| 105 m_requestCountTracker.clear(); | 105 ASSERT(!m_requestCountTracker); |
| 106 m_host->didLoadResource(m_resource); | 106 m_host->didLoadResource(); |
| 107 if (m_state == Terminated) | 107 if (m_state == Terminated) |
| 108 return; | 108 return; |
| 109 m_resource->clearLoader(); | 109 m_resource->clearLoader(); |
| 110 m_resource->deleteIfPossible(); | 110 m_resource->deleteIfPossible(); |
| 111 m_resource = nullptr; | 111 m_resource = nullptr; |
| 112 m_host->willTerminateResourceLoader(this); | 112 m_host->willTerminateResourceLoader(this); |
| 113 | 113 |
| 114 ASSERT(m_state != Terminated); | 114 ASSERT(m_state != Terminated); |
| 115 | 115 |
| 116 // It's possible that when we release the loader, it will be | 116 // It's possible that when we release the loader, it will be |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 226 |
| 227 void ResourceLoader::didFinishLoadingOnePart(double finishTime, int64 encodedDat
aLength) | 227 void ResourceLoader::didFinishLoadingOnePart(double finishTime, int64 encodedDat
aLength) |
| 228 { | 228 { |
| 229 // If load has been cancelled after finishing (which could happen with a | 229 // If load has been cancelled after finishing (which could happen with a |
| 230 // JavaScript that changes the window location), do nothing. | 230 // JavaScript that changes the window location), do nothing. |
| 231 if (m_state == Terminated) | 231 if (m_state == Terminated) |
| 232 return; | 232 return; |
| 233 | 233 |
| 234 if (m_notifiedLoadComplete) | 234 if (m_notifiedLoadComplete) |
| 235 return; | 235 return; |
| 236 m_notifiedLoadComplete = true; | 236 didComplete(); |
| 237 m_host->didFinishLoading(m_resource, finishTime, encodedDataLength); | 237 m_host->didFinishLoading(m_resource, finishTime, encodedDataLength); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void ResourceLoader::didChangePriority(ResourceLoadPriority loadPriority, int in
traPriorityValue) | 240 void ResourceLoader::didChangePriority(ResourceLoadPriority loadPriority, int in
traPriorityValue) |
| 241 { | 241 { |
| 242 if (m_loader) { | 242 if (m_loader) { |
| 243 m_host->didChangeLoadingPriority(m_resource, loadPriority, intraPriority
Value); | 243 m_host->didChangeLoadingPriority(m_resource, loadPriority, intraPriority
Value); |
| 244 ASSERT(m_state != Terminated); | 244 ASSERT(m_state != Terminated); |
| 245 m_loader->didChangePriority(static_cast<blink::WebURLRequest::Priority>(
loadPriority), intraPriorityValue); | 245 m_loader->didChangePriority(static_cast<blink::WebURLRequest::Priority>(
loadPriority), intraPriorityValue); |
| 246 } | 246 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 m_state = Finishing; | 279 m_state = Finishing; |
| 280 m_resource->setResourceError(nonNullError); | 280 m_resource->setResourceError(nonNullError); |
| 281 | 281 |
| 282 if (m_loader) { | 282 if (m_loader) { |
| 283 m_connectionState = ConnectionStateCanceled; | 283 m_connectionState = ConnectionStateCanceled; |
| 284 m_loader->cancel(); | 284 m_loader->cancel(); |
| 285 m_loader.clear(); | 285 m_loader.clear(); |
| 286 } | 286 } |
| 287 | 287 |
| 288 if (!m_notifiedLoadComplete) { | 288 if (!m_notifiedLoadComplete) { |
| 289 m_notifiedLoadComplete = true; | 289 didComplete(); |
| 290 m_host->didFailLoading(m_resource, nonNullError); | 290 m_host->didFailLoading(m_resource, nonNullError); |
| 291 } | 291 } |
| 292 | 292 |
| 293 if (m_state == Finishing) | 293 if (m_state == Finishing) |
| 294 m_resource->error(Resource::LoadError); | 294 m_resource->error(Resource::LoadError); |
| 295 if (m_state != Terminated) | 295 if (m_state != Terminated) |
| 296 releaseResources(); | 296 releaseResources(); |
| 297 } | 297 } |
| 298 | 298 |
| 299 void ResourceLoader::willSendRequest(blink::WebURLLoader*, blink::WebURLRequest&
passedNewRequest, const blink::WebURLResponse& passedRedirectResponse) | 299 void ResourceLoader::willSendRequest(blink::WebURLLoader*, blink::WebURLRequest&
passedNewRequest, const blink::WebURLResponse& passedRedirectResponse) |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 didFinishLoadingOnePart(0, blink::WebURLLoaderClient::kUnknownEncodedDat
aLength); | 415 didFinishLoadingOnePart(0, blink::WebURLLoaderClient::kUnknownEncodedDat
aLength); |
| 416 } | 416 } |
| 417 if (m_state == Terminated) | 417 if (m_state == Terminated) |
| 418 return; | 418 return; |
| 419 | 419 |
| 420 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor
eHTTPStatusCodeErrors()) | 420 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor
eHTTPStatusCodeErrors()) |
| 421 return; | 421 return; |
| 422 m_state = Finishing; | 422 m_state = Finishing; |
| 423 | 423 |
| 424 if (!m_notifiedLoadComplete) { | 424 if (!m_notifiedLoadComplete) { |
| 425 m_notifiedLoadComplete = true; | 425 didComplete(); |
| 426 m_host->didFailLoading(m_resource, ResourceError::cancelledError(m_reque
st.url())); | 426 m_host->didFailLoading(m_resource, ResourceError::cancelledError(m_reque
st.url())); |
| 427 } | 427 } |
| 428 | 428 |
| 429 ASSERT(m_state != Terminated); | 429 ASSERT(m_state != Terminated); |
| 430 m_resource->error(Resource::LoadError); | 430 m_resource->error(Resource::LoadError); |
| 431 cancel(); | 431 cancel(); |
| 432 } | 432 } |
| 433 | 433 |
| 434 void ResourceLoader::didReceiveData(blink::WebURLLoader*, const char* data, int
length, int encodedDataLength) | 434 void ResourceLoader::didReceiveData(blink::WebURLLoader*, const char* data, int
length, int encodedDataLength) |
| 435 { | 435 { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 462 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con
nectionState == ConnectionStateReceivingData); | 462 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con
nectionState == ConnectionStateReceivingData); |
| 463 m_connectionState = ConnectionStateFinishedLoading; | 463 m_connectionState = ConnectionStateFinishedLoading; |
| 464 if (m_state != Initialized) | 464 if (m_state != Initialized) |
| 465 return; | 465 return; |
| 466 ASSERT(m_state != Terminated); | 466 ASSERT(m_state != Terminated); |
| 467 WTF_LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1
().data()); | 467 WTF_LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1
().data()); |
| 468 | 468 |
| 469 RefPtrWillBeRawPtr<ResourceLoader> protect(this); | 469 RefPtrWillBeRawPtr<ResourceLoader> protect(this); |
| 470 ResourcePtr<Resource> protectResource(m_resource); | 470 ResourcePtr<Resource> protectResource(m_resource); |
| 471 m_state = Finishing; | 471 m_state = Finishing; |
| 472 m_resource->setLoadFinishTime(finishTime); |
| 472 didFinishLoadingOnePart(finishTime, encodedDataLength); | 473 didFinishLoadingOnePart(finishTime, encodedDataLength); |
| 473 if (m_state == Terminated) | 474 if (m_state == Terminated) |
| 474 return; | 475 return; |
| 475 m_resource->finish(finishTime); | 476 m_resource->finish(); |
| 476 | 477 |
| 477 // If the load has been cancelled by a delegate in response to didFinishLoad
(), do not release | 478 // If the load has been cancelled by a delegate in response to didFinishLoad
(), do not release |
| 478 // the resources a second time, they have been released by cancel. | 479 // the resources a second time, they have been released by cancel. |
| 479 if (m_state == Terminated) | 480 if (m_state == Terminated) |
| 480 return; | 481 return; |
| 481 releaseResources(); | 482 releaseResources(); |
| 482 } | 483 } |
| 483 | 484 |
| 484 void ResourceLoader::didFail(blink::WebURLLoader*, const blink::WebURLError& err
or) | 485 void ResourceLoader::didFail(blink::WebURLLoader*, const blink::WebURLError& err
or) |
| 485 { | 486 { |
| 486 m_connectionState = ConnectionStateFailed; | 487 m_connectionState = ConnectionStateFailed; |
| 487 ASSERT(m_state != Terminated); | 488 ASSERT(m_state != Terminated); |
| 488 WTF_LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().string(
).latin1().data()); | 489 WTF_LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().string(
).latin1().data()); |
| 489 | 490 |
| 490 RefPtrWillBeRawPtr<ResourceLoader> protect(this); | 491 RefPtrWillBeRawPtr<ResourceLoader> protect(this); |
| 491 RefPtrWillBeRawPtr<ResourceLoaderHost> protectHost(m_host.get()); | 492 RefPtrWillBeRawPtr<ResourceLoaderHost> protectHost(m_host.get()); |
| 492 ResourcePtr<Resource> protectResource(m_resource); | 493 ResourcePtr<Resource> protectResource(m_resource); |
| 493 m_state = Finishing; | 494 m_state = Finishing; |
| 494 m_resource->setResourceError(error); | 495 m_resource->setResourceError(error); |
| 495 | 496 |
| 496 if (!m_notifiedLoadComplete) { | 497 if (!m_notifiedLoadComplete) { |
| 497 m_notifiedLoadComplete = true; | 498 didComplete(); |
| 498 m_host->didFailLoading(m_resource, error); | 499 m_host->didFailLoading(m_resource, error); |
| 499 } | 500 } |
| 500 if (m_state == Terminated) | 501 if (m_state == Terminated) |
| 501 return; | 502 return; |
| 502 | 503 |
| 503 m_resource->error(Resource::LoadError); | 504 m_resource->error(Resource::LoadError); |
| 504 | 505 |
| 505 if (m_state == Terminated) | 506 if (m_state == Terminated) |
| 506 return; | 507 return; |
| 507 | 508 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 didReceiveResponse(0, responseOut); | 542 didReceiveResponse(0, responseOut); |
| 542 if (m_state == Terminated) | 543 if (m_state == Terminated) |
| 543 return; | 544 return; |
| 544 RefPtr<ResourceLoadInfo> resourceLoadInfo = responseOut.toResourceResponse()
.resourceLoadInfo(); | 545 RefPtr<ResourceLoadInfo> resourceLoadInfo = responseOut.toResourceResponse()
.resourceLoadInfo(); |
| 545 int64 encodedDataLength = resourceLoadInfo ? resourceLoadInfo->encodedDataLe
ngth : blink::WebURLLoaderClient::kUnknownEncodedDataLength; | 546 int64 encodedDataLength = resourceLoadInfo ? resourceLoadInfo->encodedDataLe
ngth : blink::WebURLLoaderClient::kUnknownEncodedDataLength; |
| 546 m_host->didReceiveData(m_resource, dataOut.data(), dataOut.size(), encodedDa
taLength); | 547 m_host->didReceiveData(m_resource, dataOut.data(), dataOut.size(), encodedDa
taLength); |
| 547 m_resource->setResourceBuffer(dataOut); | 548 m_resource->setResourceBuffer(dataOut); |
| 548 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); | 549 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); |
| 549 } | 550 } |
| 550 | 551 |
| 552 void ResourceLoader::didComplete() |
| 553 { |
| 554 m_notifiedLoadComplete = true; |
| 555 m_requestCountTracker.clear(); |
| 556 } |
| 557 |
| 551 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const | 558 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const |
| 552 { | 559 { |
| 553 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC
redentials); | 560 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC
redentials); |
| 554 return request; | 561 return request; |
| 555 } | 562 } |
| 556 | 563 |
| 557 } | 564 } |
| OLD | NEW |