| 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 14 matching lines...) Expand all Loading... |
| 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 | 29 |
| 30 #include "core/fetch/ResourceLoader.h" | 30 #include "core/fetch/ResourceLoader.h" |
| 31 | 31 |
| 32 #include "core/fetch/CSSStyleSheetResource.h" | 32 #include "core/fetch/CSSStyleSheetResource.h" |
| 33 #include "core/fetch/Resource.h" | 33 #include "core/fetch/Resource.h" |
| 34 #include "core/fetch/ResourceFetcher.h" | 34 #include "core/fetch/ResourceFetcher.h" |
| 35 #include "core/fetch/ResourcePtr.h" | |
| 36 #include "platform/Logging.h" | 35 #include "platform/Logging.h" |
| 37 #include "platform/SharedBuffer.h" | 36 #include "platform/SharedBuffer.h" |
| 38 #include "platform/ThreadedDataReceiver.h" | 37 #include "platform/ThreadedDataReceiver.h" |
| 39 #include "platform/exported/WrappedResourceRequest.h" | 38 #include "platform/exported/WrappedResourceRequest.h" |
| 40 #include "platform/exported/WrappedResourceResponse.h" | 39 #include "platform/exported/WrappedResourceResponse.h" |
| 41 #include "platform/network/ResourceError.h" | 40 #include "platform/network/ResourceError.h" |
| 42 #include "public/platform/Platform.h" | 41 #include "public/platform/Platform.h" |
| 43 #include "public/platform/WebData.h" | 42 #include "public/platform/WebData.h" |
| 44 #include "public/platform/WebThreadedDataReceiver.h" | 43 #include "public/platform/WebThreadedDataReceiver.h" |
| 45 #include "public/platform/WebURLError.h" | 44 #include "public/platform/WebURLError.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 91 } |
| 93 | 92 |
| 94 void ResourceLoader::releaseResources() | 93 void ResourceLoader::releaseResources() |
| 95 { | 94 { |
| 96 ASSERT(m_state != Terminated); | 95 ASSERT(m_state != Terminated); |
| 97 ASSERT(m_notifiedLoadComplete); | 96 ASSERT(m_notifiedLoadComplete); |
| 98 m_fetcher->didLoadResource(m_resource.get()); | 97 m_fetcher->didLoadResource(m_resource.get()); |
| 99 if (m_state == Terminated) | 98 if (m_state == Terminated) |
| 100 return; | 99 return; |
| 101 m_resource->clearLoader(); | 100 m_resource->clearLoader(); |
| 102 m_resource->deleteIfPossible(); | |
| 103 m_resource = nullptr; | 101 m_resource = nullptr; |
| 104 | 102 |
| 105 ASSERT(m_state != Terminated); | 103 ASSERT(m_state != Terminated); |
| 106 | 104 |
| 107 m_state = Terminated; | 105 m_state = Terminated; |
| 108 if (m_loader) { | 106 if (m_loader) { |
| 109 m_loader->cancel(); | 107 m_loader->cancel(); |
| 110 m_loader.clear(); | 108 m_loader.clear(); |
| 111 } | 109 } |
| 112 m_deferredRequest = ResourceRequest(); | 110 m_deferredRequest = ResourceRequest(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 125 ASSERT(m_state != Terminated); | 123 ASSERT(m_state != Terminated); |
| 126 m_fetcher->didInitializeResourceLoader(this); | 124 m_fetcher->didInitializeResourceLoader(this); |
| 127 } | 125 } |
| 128 | 126 |
| 129 void ResourceLoader::start() | 127 void ResourceLoader::start() |
| 130 { | 128 { |
| 131 ASSERT(!m_loader); | 129 ASSERT(!m_loader); |
| 132 ASSERT(!m_request.isNull()); | 130 ASSERT(!m_request.isNull()); |
| 133 ASSERT(m_deferredRequest.isNull()); | 131 ASSERT(m_deferredRequest.isNull()); |
| 134 | 132 |
| 135 m_fetcher->willStartLoadingResource(m_resource, m_request); | 133 m_fetcher->willStartLoadingResource(m_resource.get(), m_request); |
| 136 | 134 |
| 137 if (m_options.synchronousPolicy == RequestSynchronously) { | 135 if (m_options.synchronousPolicy == RequestSynchronously) { |
| 138 requestSynchronously(); | 136 requestSynchronously(); |
| 139 return; | 137 return; |
| 140 } | 138 } |
| 141 | 139 |
| 142 if (m_defersLoading) { | 140 if (m_defersLoading) { |
| 143 m_deferredRequest = m_request; | 141 m_deferredRequest = m_request; |
| 144 return; | 142 return; |
| 145 } | 143 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 WebThreadedDataReceiver* webDataReceiver = new WebThreadedDataReceiver(t
hreadedDataReceiver); | 187 WebThreadedDataReceiver* webDataReceiver = new WebThreadedDataReceiver(t
hreadedDataReceiver); |
| 190 if (!m_loader->attachThreadedDataReceiver(webDataReceiver)) | 188 if (!m_loader->attachThreadedDataReceiver(webDataReceiver)) |
| 191 delete webDataReceiver; | 189 delete webDataReceiver; |
| 192 } | 190 } |
| 193 } | 191 } |
| 194 | 192 |
| 195 void ResourceLoader::didDownloadData(WebURLLoader*, int length, int encodedDataL
ength) | 193 void ResourceLoader::didDownloadData(WebURLLoader*, int length, int encodedDataL
ength) |
| 196 { | 194 { |
| 197 ASSERT(m_state != Terminated); | 195 ASSERT(m_state != Terminated); |
| 198 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse); | 196 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse); |
| 199 m_fetcher->didDownloadData(m_resource, length, encodedDataLength); | 197 m_fetcher->didDownloadData(m_resource.get(), length, encodedDataLength); |
| 200 if (m_state == Terminated) | 198 if (m_state == Terminated) |
| 201 return; | 199 return; |
| 202 m_resource->didDownloadData(length); | 200 m_resource->didDownloadData(length); |
| 203 } | 201 } |
| 204 | 202 |
| 205 void ResourceLoader::didFinishLoadingOnePart(double finishTime, int64_t encodedD
ataLength) | 203 void ResourceLoader::didFinishLoadingOnePart(double finishTime, int64_t encodedD
ataLength) |
| 206 { | 204 { |
| 207 // If load has been cancelled after finishing (which could happen with a | 205 // If load has been cancelled after finishing (which could happen with a |
| 208 // JavaScript that changes the window location), do nothing. | 206 // JavaScript that changes the window location), do nothing. |
| 209 if (m_state == Terminated) | 207 if (m_state == Terminated) |
| 210 return; | 208 return; |
| 211 | 209 |
| 212 if (m_notifiedLoadComplete) | 210 if (m_notifiedLoadComplete) |
| 213 return; | 211 return; |
| 214 m_notifiedLoadComplete = true; | 212 m_notifiedLoadComplete = true; |
| 215 m_fetcher->didFinishLoading(m_resource, finishTime, encodedDataLength); | 213 m_fetcher->didFinishLoading(m_resource.get(), finishTime, encodedDataLength)
; |
| 216 } | 214 } |
| 217 | 215 |
| 218 void ResourceLoader::didChangePriority(ResourceLoadPriority loadPriority, int in
traPriorityValue) | 216 void ResourceLoader::didChangePriority(ResourceLoadPriority loadPriority, int in
traPriorityValue) |
| 219 { | 217 { |
| 220 ASSERT(m_state != Terminated); | 218 ASSERT(m_state != Terminated); |
| 221 if (m_loader) | 219 if (m_loader) |
| 222 m_loader->didChangePriority(static_cast<WebURLRequest::Priority>(loadPri
ority), intraPriorityValue); | 220 m_loader->didChangePriority(static_cast<WebURLRequest::Priority>(loadPri
ority), intraPriorityValue); |
| 223 } | 221 } |
| 224 | 222 |
| 225 void ResourceLoader::cancelIfNotFinishing() | 223 void ResourceLoader::cancelIfNotFinishing() |
| (...skipping 26 matching lines...) Expand all Loading... |
| 252 m_resource->setResourceError(nonNullError); | 250 m_resource->setResourceError(nonNullError); |
| 253 | 251 |
| 254 if (m_loader) { | 252 if (m_loader) { |
| 255 m_connectionState = ConnectionStateCanceled; | 253 m_connectionState = ConnectionStateCanceled; |
| 256 m_loader->cancel(); | 254 m_loader->cancel(); |
| 257 m_loader.clear(); | 255 m_loader.clear(); |
| 258 } | 256 } |
| 259 | 257 |
| 260 if (!m_notifiedLoadComplete) { | 258 if (!m_notifiedLoadComplete) { |
| 261 m_notifiedLoadComplete = true; | 259 m_notifiedLoadComplete = true; |
| 262 m_fetcher->didFailLoading(m_resource, nonNullError); | 260 m_fetcher->didFailLoading(m_resource.get(), nonNullError); |
| 263 } | 261 } |
| 264 | 262 |
| 265 if (m_state == Finishing) | 263 if (m_state == Finishing) |
| 266 m_resource->error(Resource::LoadError); | 264 m_resource->error(Resource::LoadError); |
| 267 if (m_state != Terminated) | 265 if (m_state != Terminated) |
| 268 releaseResources(); | 266 releaseResources(); |
| 269 } | 267 } |
| 270 | 268 |
| 271 void ResourceLoader::willFollowRedirect(WebURLLoader*, WebURLRequest& passedNewR
equest, const WebURLResponse& passedRedirectResponse) | 269 void ResourceLoader::willFollowRedirect(WebURLLoader*, WebURLRequest& passedNewR
equest, const WebURLResponse& passedRedirectResponse) |
| 272 { | 270 { |
| 273 ASSERT(m_state != Terminated); | 271 ASSERT(m_state != Terminated); |
| 274 | 272 |
| 275 ResourceRequest& newRequest(applyOptions(passedNewRequest.toMutableResourceR
equest())); | 273 ResourceRequest& newRequest(applyOptions(passedNewRequest.toMutableResourceR
equest())); |
| 276 | 274 |
| 277 ASSERT(!newRequest.isNull()); | 275 ASSERT(!newRequest.isNull()); |
| 278 const ResourceResponse& redirectResponse(passedRedirectResponse.toResourceRe
sponse()); | 276 const ResourceResponse& redirectResponse(passedRedirectResponse.toResourceRe
sponse()); |
| 279 ASSERT(!redirectResponse.isNull()); | 277 ASSERT(!redirectResponse.isNull()); |
| 280 newRequest.setFollowedRedirect(true); | 278 newRequest.setFollowedRedirect(true); |
| 281 if (!isManualRedirectFetchRequest(m_resource->resourceRequest()) && !m_fetch
er->canAccessRedirect(m_resource, newRequest, redirectResponse, m_options)) { | 279 if (!isManualRedirectFetchRequest(m_resource->resourceRequest()) && !m_fetch
er->canAccessRedirect(m_resource.get(), newRequest, redirectResponse, m_options)
) { |
| 282 cancel(ResourceError::cancelledDueToAccessCheckError(newRequest.url())); | 280 cancel(ResourceError::cancelledDueToAccessCheckError(newRequest.url())); |
| 283 return; | 281 return; |
| 284 } | 282 } |
| 285 ASSERT(m_state != Terminated); | 283 ASSERT(m_state != Terminated); |
| 286 | 284 |
| 287 applyOptions(newRequest); // canAccessRedirect() can modify m_options so we
should re-apply it. | 285 applyOptions(newRequest); // canAccessRedirect() can modify m_options so we
should re-apply it. |
| 288 m_fetcher->redirectReceived(m_resource, redirectResponse); | 286 m_fetcher->redirectReceived(m_resource.get(), redirectResponse); |
| 289 ASSERT(m_state != Terminated); | 287 ASSERT(m_state != Terminated); |
| 290 m_resource->willFollowRedirect(newRequest, redirectResponse); | 288 m_resource->willFollowRedirect(newRequest, redirectResponse); |
| 291 if (newRequest.isNull() || m_state == Terminated) | 289 if (newRequest.isNull() || m_state == Terminated) |
| 292 return; | 290 return; |
| 293 | 291 |
| 294 m_fetcher->willSendRequest(m_resource->identifier(), newRequest, redirectRes
ponse, m_options.initiatorInfo); | 292 m_fetcher->willSendRequest(m_resource->identifier(), newRequest, redirectRes
ponse, m_options.initiatorInfo); |
| 295 ASSERT(m_state != Terminated); | 293 ASSERT(m_state != Terminated); |
| 296 ASSERT(!newRequest.isNull()); | 294 ASSERT(!newRequest.isNull()); |
| 297 m_resource->updateRequest(newRequest); | 295 m_resource->updateRequest(newRequest); |
| 298 m_request = newRequest; | 296 m_request = newRequest; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 m_connectionState = ConnectionStateStarted; | 338 m_connectionState = ConnectionStateStarted; |
| 341 m_loader = adoptPtr(Platform::current()->createURLLoader()); | 339 m_loader = adoptPtr(Platform::current()->createURLLoader()); |
| 342 ASSERT(m_loader); | 340 ASSERT(m_loader); |
| 343 ASSERT(!m_request.skipServiceWorker()); | 341 ASSERT(!m_request.skipServiceWorker()); |
| 344 m_request.setSkipServiceWorker(true); | 342 m_request.setSkipServiceWorker(true); |
| 345 WrappedResourceRequest wrappedRequest(m_request); | 343 WrappedResourceRequest wrappedRequest(m_request); |
| 346 m_loader->loadAsynchronously(wrappedRequest, this); | 344 m_loader->loadAsynchronously(wrappedRequest, this); |
| 347 return; | 345 return; |
| 348 } | 346 } |
| 349 } else { | 347 } else { |
| 350 // If the response successfully validated a cached resource, perform | 348 if (!m_resource->isCacheValidator() || resourceResponse.httpStatusCo
de() != 304) |
| 351 // the access control with respect to it. Need to do this right here | |
| 352 // before the resource switches clients over to that validated resou
rce. | |
| 353 Resource* resource = m_resource; | |
| 354 if (!resource->isCacheValidator() || resourceResponse.httpStatusCode
() != 304) | |
| 355 m_resource->setResponse(resourceResponse); | 349 m_resource->setResponse(resourceResponse); |
| 356 if (!m_fetcher->canAccessResource(resource, m_options.securityOrigin
.get(), response.url(), ResourceFetcher::ShouldLogAccessControlErrors)) { | 350 if (!m_fetcher->canAccessResource(m_resource.get(), m_options.securi
tyOrigin.get(), response.url(), ResourceFetcher::ShouldLogAccessControlErrors))
{ |
| 357 m_fetcher->didReceiveResponse(m_resource, resourceResponse); | 351 m_fetcher->didReceiveResponse(m_resource.get(), resourceResponse
); |
| 358 cancel(ResourceError::cancelledDueToAccessCheckError(KURL(respon
se.url()))); | 352 cancel(ResourceError::cancelledDueToAccessCheckError(KURL(respon
se.url()))); |
| 359 return; | 353 return; |
| 360 } | 354 } |
| 361 } | 355 } |
| 362 } | 356 } |
| 363 | 357 |
| 364 m_resource->responseReceived(resourceResponse, handle.release()); | 358 m_resource->responseReceived(resourceResponse, handle.release()); |
| 365 if (m_state == Terminated) | 359 if (m_state == Terminated) |
| 366 return; | 360 return; |
| 367 | 361 |
| 368 m_fetcher->didReceiveResponse(m_resource, resourceResponse); | 362 m_fetcher->didReceiveResponse(m_resource.get(), resourceResponse); |
| 369 if (m_state == Terminated) | 363 if (m_state == Terminated) |
| 370 return; | 364 return; |
| 371 | 365 |
| 372 if (response.toResourceResponse().isMultipart()) { | 366 if (response.toResourceResponse().isMultipart()) { |
| 373 // We only support multipart for images, though the image may be loaded | 367 // We only support multipart for images, though the image may be loaded |
| 374 // as a main resource that we end up displaying through an ImageDocument
. | 368 // as a main resource that we end up displaying through an ImageDocument
. |
| 375 if (!m_resource->isImage() && m_resource->type() != Resource::MainResour
ce) { | 369 if (!m_resource->isImage() && m_resource->type() != Resource::MainResour
ce) { |
| 376 cancel(); | 370 cancel(); |
| 377 return; | 371 return; |
| 378 } | 372 } |
| 379 m_loadingMultipartContent = true; | 373 m_loadingMultipartContent = true; |
| 380 } else if (isMultipartPayload) { | 374 } else if (isMultipartPayload) { |
| 381 // Since a subresource loader does not load multipart sections progressi
vely, data was delivered to the loader all at once. | 375 // Since a subresource loader does not load multipart sections progressi
vely, data was delivered to the loader all at once. |
| 382 // After the first multipart section is complete, signal to delegates th
at this load is "finished" | 376 // After the first multipart section is complete, signal to delegates th
at this load is "finished" |
| 383 m_fetcher->subresourceLoaderFinishedLoadingOnePart(this); | 377 m_fetcher->subresourceLoaderFinishedLoadingOnePart(this); |
| 384 didFinishLoadingOnePart(0, WebURLLoaderClient::kUnknownEncodedDataLength
); | 378 didFinishLoadingOnePart(0, WebURLLoaderClient::kUnknownEncodedDataLength
); |
| 385 } | 379 } |
| 386 if (m_state == Terminated) | 380 if (m_state == Terminated) |
| 387 return; | 381 return; |
| 388 | 382 |
| 389 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor
eHTTPStatusCodeErrors()) | 383 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor
eHTTPStatusCodeErrors()) |
| 390 return; | 384 return; |
| 391 m_state = Finishing; | 385 m_state = Finishing; |
| 392 | 386 |
| 393 if (!m_notifiedLoadComplete) { | 387 if (!m_notifiedLoadComplete) { |
| 394 m_notifiedLoadComplete = true; | 388 m_notifiedLoadComplete = true; |
| 395 m_fetcher->didFailLoading(m_resource, ResourceError::cancelledError(m_re
quest.url())); | 389 m_fetcher->didFailLoading(m_resource.get(), ResourceError::cancelledErro
r(m_request.url())); |
| 396 } | 390 } |
| 397 | 391 |
| 398 ASSERT(m_state != Terminated); | 392 ASSERT(m_state != Terminated); |
| 399 m_resource->error(Resource::LoadError); | 393 m_resource->error(Resource::LoadError); |
| 400 cancel(); | 394 cancel(); |
| 401 } | 395 } |
| 402 | 396 |
| 403 void ResourceLoader::didReceiveResponse(WebURLLoader* loader, const WebURLRespon
se& response) | 397 void ResourceLoader::didReceiveResponse(WebURLLoader* loader, const WebURLRespon
se& response) |
| 404 { | 398 { |
| 405 didReceiveResponse(loader, response, nullptr); | 399 didReceiveResponse(loader, response, nullptr); |
| 406 } | 400 } |
| 407 | 401 |
| 408 void ResourceLoader::didReceiveData(WebURLLoader*, const char* data, int length,
int encodedDataLength) | 402 void ResourceLoader::didReceiveData(WebURLLoader*, const char* data, int length,
int encodedDataLength) |
| 409 { | 403 { |
| 410 ASSERT(m_state != Terminated); | 404 ASSERT(m_state != Terminated); |
| 411 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con
nectionState == ConnectionStateReceivingData); | 405 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con
nectionState == ConnectionStateReceivingData); |
| 412 m_connectionState = ConnectionStateReceivingData; | 406 m_connectionState = ConnectionStateReceivingData; |
| 413 | 407 |
| 414 // It is possible to receive data on uninitialized resources if it had an er
ror status code, and we are running a nested message | 408 // It is possible to receive data on uninitialized resources if it had an er
ror status code, and we are running a nested message |
| 415 // loop. When this occurs, ignoring the data is the correct action. | 409 // loop. When this occurs, ignoring the data is the correct action. |
| 416 if (m_resource->response().httpStatusCode() >= 400 && !m_resource->shouldIgn
oreHTTPStatusCodeErrors()) | 410 if (m_resource->response().httpStatusCode() >= 400 && !m_resource->shouldIgn
oreHTTPStatusCodeErrors()) |
| 417 return; | 411 return; |
| 418 ASSERT(m_state == Initialized); | 412 ASSERT(m_state == Initialized); |
| 419 | 413 |
| 420 // FIXME: If we get a resource with more than 2B bytes, this code won't do t
he right thing. | 414 // FIXME: If we get a resource with more than 2B bytes, this code won't do t
he right thing. |
| 421 // However, with today's computers and networking speeds, this won't happen
in practice. | 415 // However, with today's computers and networking speeds, this won't happen
in practice. |
| 422 // Could be an issue with a giant local file. | 416 // Could be an issue with a giant local file. |
| 423 m_fetcher->didReceiveData(m_resource, data, length, encodedDataLength); | 417 m_fetcher->didReceiveData(m_resource.get(), data, length, encodedDataLength)
; |
| 424 if (m_state == Terminated) | 418 if (m_state == Terminated) |
| 425 return; | 419 return; |
| 426 RELEASE_ASSERT(length >= 0); | 420 RELEASE_ASSERT(length >= 0); |
| 427 m_resource->appendData(data, length); | 421 m_resource->appendData(data, length); |
| 428 } | 422 } |
| 429 | 423 |
| 430 void ResourceLoader::didFinishLoading(WebURLLoader*, double finishTime, int64_t
encodedDataLength) | 424 void ResourceLoader::didFinishLoading(WebURLLoader*, double finishTime, int64_t
encodedDataLength) |
| 431 { | 425 { |
| 432 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con
nectionState == ConnectionStateReceivingData); | 426 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con
nectionState == ConnectionStateReceivingData); |
| 433 m_connectionState = ConnectionStateFinishedLoading; | 427 m_connectionState = ConnectionStateFinishedLoading; |
| 434 if (m_state != Initialized) | 428 if (m_state != Initialized) |
| 435 return; | 429 return; |
| 436 ASSERT(m_state != Terminated); | 430 ASSERT(m_state != Terminated); |
| 437 WTF_LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1
().data()); | 431 WTF_LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1
().data()); |
| 438 | 432 |
| 439 ResourcePtr<Resource> protectResource(m_resource); | 433 RefPtrWillBeRawPtr<Resource> protectResource(m_resource.get()); |
| 440 m_state = Finishing; | 434 m_state = Finishing; |
| 441 m_resource->setLoadFinishTime(finishTime); | 435 m_resource->setLoadFinishTime(finishTime); |
| 442 didFinishLoadingOnePart(finishTime, encodedDataLength); | 436 didFinishLoadingOnePart(finishTime, encodedDataLength); |
| 443 if (m_state == Terminated) | 437 if (m_state == Terminated) |
| 444 return; | 438 return; |
| 445 m_resource->finish(); | 439 m_resource->finish(); |
| 446 | 440 |
| 447 // If the load has been cancelled by a delegate in response to didFinishLoad
(), do not release | 441 // If the load has been cancelled by a delegate in response to didFinishLoad
(), do not release |
| 448 // the resources a second time, they have been released by cancel. | 442 // the resources a second time, they have been released by cancel. |
| 449 if (m_state == Terminated) | 443 if (m_state == Terminated) |
| 450 return; | 444 return; |
| 451 releaseResources(); | 445 releaseResources(); |
| 452 } | 446 } |
| 453 | 447 |
| 454 void ResourceLoader::didFail(WebURLLoader*, const WebURLError& error) | 448 void ResourceLoader::didFail(WebURLLoader*, const WebURLError& error) |
| 455 { | 449 { |
| 456 m_connectionState = ConnectionStateFailed; | 450 m_connectionState = ConnectionStateFailed; |
| 457 ASSERT(m_state != Terminated); | 451 ASSERT(m_state != Terminated); |
| 458 WTF_LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().string(
).latin1().data()); | 452 WTF_LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().string(
).latin1().data()); |
| 459 | 453 |
| 460 ResourcePtr<Resource> protectResource(m_resource); | 454 RefPtrWillBeRawPtr<Resource> protectResource(m_resource.get()); |
| 461 m_state = Finishing; | 455 m_state = Finishing; |
| 462 m_resource->setResourceError(error); | 456 m_resource->setResourceError(error); |
| 463 | 457 |
| 464 if (!m_notifiedLoadComplete) { | 458 if (!m_notifiedLoadComplete) { |
| 465 m_notifiedLoadComplete = true; | 459 m_notifiedLoadComplete = true; |
| 466 m_fetcher->didFailLoading(m_resource, error); | 460 m_fetcher->didFailLoading(m_resource.get(), error); |
| 467 } | 461 } |
| 468 if (m_state == Terminated) | 462 if (m_state == Terminated) |
| 469 return; | 463 return; |
| 470 | 464 |
| 471 m_resource->error(Resource::LoadError); | 465 m_resource->error(Resource::LoadError); |
| 472 | 466 |
| 473 if (m_state == Terminated) | 467 if (m_state == Terminated) |
| 474 return; | 468 return; |
| 475 | 469 |
| 476 releaseResources(); | 470 releaseResources(); |
| 477 } | 471 } |
| 478 | 472 |
| 479 bool ResourceLoader::isLoadedBy(ResourceFetcher* loader) const | 473 bool ResourceLoader::isLoadedBy(ResourceFetcher* loader) const |
| 480 { | 474 { |
| 481 return m_fetcher->isLoadedBy(loader); | 475 return m_fetcher->isLoadedBy(loader); |
| 482 } | 476 } |
| 483 | 477 |
| 484 void ResourceLoader::requestSynchronously() | 478 void ResourceLoader::requestSynchronously() |
| 485 { | 479 { |
| 486 OwnPtr<WebURLLoader> loader = adoptPtr(Platform::current()->createURLLoader(
)); | 480 OwnPtr<WebURLLoader> loader = adoptPtr(Platform::current()->createURLLoader(
)); |
| 487 ASSERT(loader); | 481 ASSERT(loader); |
| 488 | 482 |
| 489 // downloadToFile is not supported for synchronous requests. | 483 // downloadToFile is not supported for synchronous requests. |
| 490 ASSERT(!m_request.downloadToFile()); | 484 ASSERT(!m_request.downloadToFile()); |
| 491 | 485 |
| 492 ResourcePtr<Resource> protectResource(m_resource); | 486 RefPtrWillBeRawPtr<Resource> protectResource(m_resource.get()); |
| 493 | 487 |
| 494 RELEASE_ASSERT(m_connectionState == ConnectionStateNew); | 488 RELEASE_ASSERT(m_connectionState == ConnectionStateNew); |
| 495 m_connectionState = ConnectionStateStarted; | 489 m_connectionState = ConnectionStateStarted; |
| 496 | 490 |
| 497 WrappedResourceRequest requestIn(m_request); | 491 WrappedResourceRequest requestIn(m_request); |
| 498 WebURLResponse responseOut; | 492 WebURLResponse responseOut; |
| 499 responseOut.initialize(); | 493 responseOut.initialize(); |
| 500 WebURLError errorOut; | 494 WebURLError errorOut; |
| 501 WebData dataOut; | 495 WebData dataOut; |
| 502 loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut); | 496 loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 514 if (m_state == Terminated) | 508 if (m_state == Terminated) |
| 515 return; | 509 return; |
| 516 RefPtr<ResourceLoadInfo> resourceLoadInfo = responseOut.toResourceResponse()
.resourceLoadInfo(); | 510 RefPtr<ResourceLoadInfo> resourceLoadInfo = responseOut.toResourceResponse()
.resourceLoadInfo(); |
| 517 int64_t encodedDataLength = resourceLoadInfo ? resourceLoadInfo->encodedData
Length : WebURLLoaderClient::kUnknownEncodedDataLength; | 511 int64_t encodedDataLength = resourceLoadInfo ? resourceLoadInfo->encodedData
Length : WebURLLoaderClient::kUnknownEncodedDataLength; |
| 518 | 512 |
| 519 // Follow the async case convention of not calling didReceiveData or | 513 // Follow the async case convention of not calling didReceiveData or |
| 520 // appending data to m_resource if the response body is empty. Copying the | 514 // appending data to m_resource if the response body is empty. Copying the |
| 521 // empty buffer is a noop in most cases, but is destructive in the case of | 515 // empty buffer is a noop in most cases, but is destructive in the case of |
| 522 // a 304, where it will overwrite the cached data we should be reusing. | 516 // a 304, where it will overwrite the cached data we should be reusing. |
| 523 if (dataOut.size()) { | 517 if (dataOut.size()) { |
| 524 m_fetcher->didReceiveData(m_resource, dataOut.data(), dataOut.size(), en
codedDataLength); | 518 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size
(), encodedDataLength); |
| 525 m_resource->setResourceBuffer(dataOut); | 519 m_resource->setResourceBuffer(dataOut); |
| 526 } | 520 } |
| 527 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); | 521 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); |
| 528 } | 522 } |
| 529 | 523 |
| 530 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const | 524 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const |
| 531 { | 525 { |
| 532 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC
redentials); | 526 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC
redentials); |
| 533 return request; | 527 return request; |
| 534 } | 528 } |
| 535 | 529 |
| 536 } // namespace blink | 530 } // namespace blink |
| OLD | NEW |