| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/child/web_url_loader_impl.h" | 5 #include "content/child/web_url_loader_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 bool was_ignored_by_handler, | 316 bool was_ignored_by_handler, |
| 317 bool stale_copy_in_cache, | 317 bool stale_copy_in_cache, |
| 318 const std::string& security_info, | 318 const std::string& security_info, |
| 319 const base::TimeTicks& completion_time, | 319 const base::TimeTicks& completion_time, |
| 320 int64 total_transfer_size) override; | 320 int64 total_transfer_size) override; |
| 321 | 321 |
| 322 private: | 322 private: |
| 323 friend class base::RefCounted<Context>; | 323 friend class base::RefCounted<Context>; |
| 324 ~Context() override; | 324 ~Context() override; |
| 325 | 325 |
| 326 // Called when the body data stream is detached from the reader side. |
| 327 void CancelBodyStreaming(); |
| 326 // We can optimize the handling of data URLs in most cases. | 328 // We can optimize the handling of data URLs in most cases. |
| 327 bool CanHandleDataURLRequestLocally() const; | 329 bool CanHandleDataURLRequestLocally() const; |
| 328 void HandleDataURL(); | 330 void HandleDataURL(); |
| 329 | 331 |
| 330 WebURLLoaderImpl* loader_; | 332 WebURLLoaderImpl* loader_; |
| 331 WebURLRequest request_; | 333 WebURLRequest request_; |
| 332 WebURLLoaderClient* client_; | 334 WebURLLoaderClient* client_; |
| 333 ResourceDispatcher* resource_dispatcher_; | 335 ResourceDispatcher* resource_dispatcher_; |
| 334 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 336 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 335 WebReferrerPolicy referrer_policy_; | 337 WebReferrerPolicy referrer_policy_; |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 scoped_refptr<Context> protect(this); | 613 scoped_refptr<Context> protect(this); |
| 612 | 614 |
| 613 if (request_.useStreamOnResponse()) { | 615 if (request_.useStreamOnResponse()) { |
| 614 SharedMemoryDataConsumerHandle::BackpressureMode mode = | 616 SharedMemoryDataConsumerHandle::BackpressureMode mode = |
| 615 SharedMemoryDataConsumerHandle::kDoNotApplyBackpressure; | 617 SharedMemoryDataConsumerHandle::kDoNotApplyBackpressure; |
| 616 if (info.headers && | 618 if (info.headers && |
| 617 info.headers->HasHeaderValue("Cache-Control", "no-store")) { | 619 info.headers->HasHeaderValue("Cache-Control", "no-store")) { |
| 618 mode = SharedMemoryDataConsumerHandle::kApplyBackpressure; | 620 mode = SharedMemoryDataConsumerHandle::kApplyBackpressure; |
| 619 } | 621 } |
| 620 | 622 |
| 621 auto reader = make_scoped_ptr( | 623 auto read_handle = make_scoped_ptr(new SharedMemoryDataConsumerHandle( |
| 622 new SharedMemoryDataConsumerHandle(mode, &body_stream_writer_)); | 624 mode, base::Bind(&Context::CancelBodyStreaming, this), |
| 625 &body_stream_writer_)); |
| 623 | 626 |
| 624 // The client takes |reader|'s ownership. | 627 // Here |body_stream_writer_| has an indirect reference to |this| and that |
| 625 client_->didReceiveResponse(loader_, response, reader.release()); | 628 // creates a reference cycle, but it is not a problem because the cycle |
| 629 // will break if one of the following happens: |
| 630 // 1) The body data transfer is done (with or without an error). |
| 631 // 2) |read_handle| (and its reader) is detached. |
| 632 |
| 633 // The client takes |read_handle|'s ownership. |
| 634 client_->didReceiveResponse(loader_, response, read_handle.release()); |
| 626 // TODO(yhirano): Support ftp listening and multipart | 635 // TODO(yhirano): Support ftp listening and multipart |
| 627 return; | 636 return; |
| 628 } else { | 637 } else { |
| 629 client_->didReceiveResponse(loader_, response); | 638 client_->didReceiveResponse(loader_, response); |
| 630 } | 639 } |
| 631 | 640 |
| 632 // We may have been cancelled after didReceiveResponse, which would leave us | 641 // We may have been cancelled after didReceiveResponse, which would leave us |
| 633 // without a client and therefore without much need to do further handling. | 642 // without a client and therefore without much need to do further handling. |
| 634 if (!client_) | 643 if (!client_) |
| 635 return; | 644 return; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 } | 756 } |
| 748 } | 757 } |
| 749 } | 758 } |
| 750 | 759 |
| 751 WebURLLoaderImpl::Context::~Context() { | 760 WebURLLoaderImpl::Context::~Context() { |
| 752 if (request_id_ >= 0) { | 761 if (request_id_ >= 0) { |
| 753 resource_dispatcher_->RemovePendingRequest(request_id_); | 762 resource_dispatcher_->RemovePendingRequest(request_id_); |
| 754 } | 763 } |
| 755 } | 764 } |
| 756 | 765 |
| 766 void WebURLLoaderImpl::Context::CancelBodyStreaming() { |
| 767 scoped_refptr<Context> protect(this); |
| 768 |
| 769 // Notify renderer clients that the request is canceled. |
| 770 if (ftp_listing_delegate_) { |
| 771 ftp_listing_delegate_->OnCompletedRequest(); |
| 772 ftp_listing_delegate_.reset(NULL); |
| 773 } else if (multipart_delegate_) { |
| 774 multipart_delegate_->OnCompletedRequest(); |
| 775 multipart_delegate_.reset(NULL); |
| 776 } |
| 777 |
| 778 if (body_stream_writer_) { |
| 779 body_stream_writer_->Fail(); |
| 780 body_stream_writer_.reset(); |
| 781 } |
| 782 if (client_) { |
| 783 // TODO(yhirano): Set |stale_copy_in_cache| appropriately if possible. |
| 784 client_->didFail( |
| 785 loader_, CreateWebURLError(request_.url(), false, net::ERR_ABORTED)); |
| 786 } |
| 787 |
| 788 // Notify the browser process that the request is canceled. |
| 789 Cancel(); |
| 790 } |
| 791 |
| 757 bool WebURLLoaderImpl::Context::CanHandleDataURLRequestLocally() const { | 792 bool WebURLLoaderImpl::Context::CanHandleDataURLRequestLocally() const { |
| 758 GURL url = request_.url(); | 793 GURL url = request_.url(); |
| 759 if (!url.SchemeIs(url::kDataScheme)) | 794 if (!url.SchemeIs(url::kDataScheme)) |
| 760 return false; | 795 return false; |
| 761 | 796 |
| 762 // The fast paths for data URL, Start() and HandleDataURL(), don't support | 797 // The fast paths for data URL, Start() and HandleDataURL(), don't support |
| 763 // the downloadToFile option. | 798 // the downloadToFile option. |
| 764 if (request_.downloadToFile()) | 799 if (request_.downloadToFile()) |
| 765 return false; | 800 return false; |
| 766 | 801 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 int intra_priority_value) { | 1035 int intra_priority_value) { |
| 1001 context_->DidChangePriority(new_priority, intra_priority_value); | 1036 context_->DidChangePriority(new_priority, intra_priority_value); |
| 1002 } | 1037 } |
| 1003 | 1038 |
| 1004 bool WebURLLoaderImpl::attachThreadedDataReceiver( | 1039 bool WebURLLoaderImpl::attachThreadedDataReceiver( |
| 1005 blink::WebThreadedDataReceiver* threaded_data_receiver) { | 1040 blink::WebThreadedDataReceiver* threaded_data_receiver) { |
| 1006 return context_->AttachThreadedDataReceiver(threaded_data_receiver); | 1041 return context_->AttachThreadedDataReceiver(threaded_data_receiver); |
| 1007 } | 1042 } |
| 1008 | 1043 |
| 1009 } // namespace content | 1044 } // namespace content |
| OLD | NEW |