| 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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 RefPtrWillBeRawPtr<ResourceLoader> protect(this); | 339 RefPtrWillBeRawPtr<ResourceLoader> protect(this); |
| 340 m_resource->didSendData(bytesSent, totalBytesToBeSent); | 340 m_resource->didSendData(bytesSent, totalBytesToBeSent); |
| 341 } | 341 } |
| 342 | 342 |
| 343 bool ResourceLoader::responseNeedsAccessControlCheck() const | 343 bool ResourceLoader::responseNeedsAccessControlCheck() const |
| 344 { | 344 { |
| 345 // If the fetch was (potentially) CORS enabled, an access control check of t
he response is required. | 345 // If the fetch was (potentially) CORS enabled, an access control check of t
he response is required. |
| 346 return m_options.corsEnabled == IsCORSEnabled; | 346 return m_options.corsEnabled == IsCORSEnabled; |
| 347 } | 347 } |
| 348 | 348 |
| 349 void ResourceLoader::didReceiveResponse(blink::WebURLLoader*, const blink::WebUR
LResponse& response) | 349 void ResourceLoader::didReceiveResponse(blink::WebURLLoader*, const blink::WebUR
LResponse& response, WebDataConsumerHandle* rawHandle) |
| 350 { | 350 { |
| 351 ASSERT(!response.isNull()); | 351 ASSERT(!response.isNull()); |
| 352 ASSERT(m_state == Initialized); | 352 ASSERT(m_state == Initialized); |
| 353 // |rawHandle|'s ownership is transferred to the callee. |
| 354 OwnPtr<WebDataConsumerHandle> handle = adoptPtr(rawHandle); |
| 353 | 355 |
| 354 bool isMultipartPayload = response.isMultipartPayload(); | 356 bool isMultipartPayload = response.isMultipartPayload(); |
| 355 bool isValidStateTransition = (m_connectionState == ConnectionStateStarted |
| m_connectionState == ConnectionStateReceivedResponse); | 357 bool isValidStateTransition = (m_connectionState == ConnectionStateStarted |
| m_connectionState == ConnectionStateReceivedResponse); |
| 356 // In the case of multipart loads, calls to didReceiveData & didReceiveRespo
nse can be interleaved. | 358 // In the case of multipart loads, calls to didReceiveData & didReceiveRespo
nse can be interleaved. |
| 357 RELEASE_ASSERT(isMultipartPayload || isValidStateTransition); | 359 RELEASE_ASSERT(isMultipartPayload || isValidStateTransition); |
| 358 m_connectionState = ConnectionStateReceivedResponse; | 360 m_connectionState = ConnectionStateReceivedResponse; |
| 359 | 361 |
| 360 const ResourceResponse& resourceResponse = response.toResourceResponse(); | 362 const ResourceResponse& resourceResponse = response.toResourceResponse(); |
| 361 | 363 |
| 362 if (responseNeedsAccessControlCheck()) { | 364 if (responseNeedsAccessControlCheck()) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 386 m_host->didReceiveResponse(m_resource, resourceResponse); | 388 m_host->didReceiveResponse(m_resource, resourceResponse); |
| 387 cancel(); | 389 cancel(); |
| 388 return; | 390 return; |
| 389 } | 391 } |
| 390 } | 392 } |
| 391 } | 393 } |
| 392 | 394 |
| 393 // Reference the object in this method since the additional processing can d
o | 395 // Reference the object in this method since the additional processing can d
o |
| 394 // anything including removing the last reference to this object. | 396 // anything including removing the last reference to this object. |
| 395 RefPtrWillBeRawPtr<ResourceLoader> protect(this); | 397 RefPtrWillBeRawPtr<ResourceLoader> protect(this); |
| 396 m_resource->responseReceived(resourceResponse); | 398 m_resource->responseReceived(resourceResponse, handle.release()); |
| 397 if (m_state == Terminated) | 399 if (m_state == Terminated) |
| 398 return; | 400 return; |
| 399 | 401 |
| 400 m_host->didReceiveResponse(m_resource, resourceResponse); | 402 m_host->didReceiveResponse(m_resource, resourceResponse); |
| 401 if (m_state == Terminated) | 403 if (m_state == Terminated) |
| 402 return; | 404 return; |
| 403 | 405 |
| 404 if (response.toResourceResponse().isMultipart()) { | 406 if (response.toResourceResponse().isMultipart()) { |
| 405 // We don't count multiParts in a ResourceFetcher's request count | 407 // We don't count multiParts in a ResourceFetcher's request count |
| 406 m_requestCountTracker.clear(); | 408 m_requestCountTracker.clear(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 425 if (!m_notifiedLoadComplete) { | 427 if (!m_notifiedLoadComplete) { |
| 426 m_notifiedLoadComplete = true; | 428 m_notifiedLoadComplete = true; |
| 427 m_host->didFailLoading(m_resource, ResourceError::cancelledError(m_reque
st.url())); | 429 m_host->didFailLoading(m_resource, ResourceError::cancelledError(m_reque
st.url())); |
| 428 } | 430 } |
| 429 | 431 |
| 430 ASSERT(m_state != Terminated); | 432 ASSERT(m_state != Terminated); |
| 431 m_resource->error(Resource::LoadError); | 433 m_resource->error(Resource::LoadError); |
| 432 cancel(); | 434 cancel(); |
| 433 } | 435 } |
| 434 | 436 |
| 437 void ResourceLoader::didReceiveResponse(blink::WebURLLoader* loader, const blink
::WebURLResponse& response) |
| 438 { |
| 439 didReceiveResponse(loader, response, nullptr); |
| 440 } |
| 441 |
| 435 void ResourceLoader::didReceiveData(blink::WebURLLoader*, const char* data, int
length, int encodedDataLength) | 442 void ResourceLoader::didReceiveData(blink::WebURLLoader*, const char* data, int
length, int encodedDataLength) |
| 436 { | 443 { |
| 437 ASSERT(m_state != Terminated); | 444 ASSERT(m_state != Terminated); |
| 438 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con
nectionState == ConnectionStateReceivingData); | 445 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con
nectionState == ConnectionStateReceivingData); |
| 439 m_connectionState = ConnectionStateReceivingData; | 446 m_connectionState = ConnectionStateReceivingData; |
| 440 | 447 |
| 441 // It is possible to receive data on uninitialized resources if it had an er
ror status code, and we are running a nested message | 448 // It is possible to receive data on uninitialized resources if it had an er
ror status code, and we are running a nested message |
| 442 // loop. When this occurs, ignoring the data is the correct action. | 449 // loop. When this occurs, ignoring the data is the correct action. |
| 443 if (m_resource->response().httpStatusCode() >= 400 && !m_resource->shouldIgn
oreHTTPStatusCodeErrors()) | 450 if (m_resource->response().httpStatusCode() >= 400 && !m_resource->shouldIgn
oreHTTPStatusCodeErrors()) |
| 444 return; | 451 return; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); | 556 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); |
| 550 } | 557 } |
| 551 | 558 |
| 552 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const | 559 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const |
| 553 { | 560 { |
| 554 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC
redentials); | 561 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC
redentials); |
| 555 return request; | 562 return request; |
| 556 } | 563 } |
| 557 | 564 |
| 558 } | 565 } |
| OLD | NEW |