| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 } | 641 } |
| 642 | 642 |
| 643 void WebURLLoaderImpl::Context::SetTaskRunner( | 643 void WebURLLoaderImpl::Context::SetTaskRunner( |
| 644 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 644 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
| 645 task_runner_ = task_runner; | 645 task_runner_ = task_runner; |
| 646 } | 646 } |
| 647 | 647 |
| 648 void WebURLLoaderImpl::Context::OnUploadProgress(uint64_t position, | 648 void WebURLLoaderImpl::Context::OnUploadProgress(uint64_t position, |
| 649 uint64_t size) { | 649 uint64_t size) { |
| 650 if (client_) | 650 if (client_) |
| 651 client_->didSendData(loader_, position, size); | 651 client_->didSendData(position, size); |
| 652 } | 652 } |
| 653 | 653 |
| 654 bool WebURLLoaderImpl::Context::OnReceivedRedirect( | 654 bool WebURLLoaderImpl::Context::OnReceivedRedirect( |
| 655 const net::RedirectInfo& redirect_info, | 655 const net::RedirectInfo& redirect_info, |
| 656 const ResourceResponseInfo& info) { | 656 const ResourceResponseInfo& info) { |
| 657 if (!client_) | 657 if (!client_) |
| 658 return false; | 658 return false; |
| 659 | 659 |
| 660 TRACE_EVENT_WITH_FLOW0( | 660 TRACE_EVENT_WITH_FLOW0( |
| 661 "loading", "WebURLLoaderImpl::Context::OnReceivedRedirect", | 661 "loading", "WebURLLoaderImpl::Context::OnReceivedRedirect", |
| 662 this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | 662 this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); |
| 663 | 663 |
| 664 WebURLResponse response; | 664 WebURLResponse response; |
| 665 PopulateURLResponse(request_.url(), info, &response, | 665 PopulateURLResponse(request_.url(), info, &response, |
| 666 request_.reportRawHeaders()); | 666 request_.reportRawHeaders()); |
| 667 | 667 |
| 668 WebURLRequest new_request = PopulateURLRequestForRedirect( | 668 WebURLRequest new_request = PopulateURLRequestForRedirect( |
| 669 request_, redirect_info, | 669 request_, redirect_info, |
| 670 info.was_fetched_via_service_worker | 670 info.was_fetched_via_service_worker |
| 671 ? blink::WebURLRequest::SkipServiceWorker::None | 671 ? blink::WebURLRequest::SkipServiceWorker::None |
| 672 : blink::WebURLRequest::SkipServiceWorker::All); | 672 : blink::WebURLRequest::SkipServiceWorker::All); |
| 673 | 673 |
| 674 bool follow = client_->willFollowRedirect(loader_, new_request, response); | 674 bool follow = client_->willFollowRedirect(new_request, response); |
| 675 if (!follow) { | 675 if (!follow) { |
| 676 request_ = WebURLRequest(); | 676 request_ = WebURLRequest(); |
| 677 | 677 |
| 678 return false; | 678 return false; |
| 679 } | 679 } |
| 680 | 680 |
| 681 DCHECK(WebURL(redirect_info.new_url) == new_request.url()); | 681 DCHECK(WebURL(redirect_info.new_url) == new_request.url()); |
| 682 | 682 |
| 683 request_ = new_request; | 683 request_ = new_request; |
| 684 | 684 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 | 764 |
| 765 auto read_handle = base::MakeUnique<SharedMemoryDataConsumerHandle>( | 765 auto read_handle = base::MakeUnique<SharedMemoryDataConsumerHandle>( |
| 766 mode, base::Bind(&Context::CancelBodyStreaming, this), | 766 mode, base::Bind(&Context::CancelBodyStreaming, this), |
| 767 &body_stream_writer_); | 767 &body_stream_writer_); |
| 768 | 768 |
| 769 // Here |body_stream_writer_| has an indirect reference to |this| and that | 769 // Here |body_stream_writer_| has an indirect reference to |this| and that |
| 770 // creates a reference cycle, but it is not a problem because the cycle | 770 // creates a reference cycle, but it is not a problem because the cycle |
| 771 // will break if one of the following happens: | 771 // will break if one of the following happens: |
| 772 // 1) The body data transfer is done (with or without an error). | 772 // 1) The body data transfer is done (with or without an error). |
| 773 // 2) |read_handle| (and its reader) is detached. | 773 // 2) |read_handle| (and its reader) is detached. |
| 774 client_->didReceiveResponse(loader_, response, std::move(read_handle)); | 774 client_->didReceiveResponse(response, std::move(read_handle)); |
| 775 // TODO(yhirano): Support ftp listening and multipart | 775 // TODO(yhirano): Support ftp listening and multipart |
| 776 return; | 776 return; |
| 777 } else { | 777 } else { |
| 778 client_->didReceiveResponse(loader_, response); | 778 client_->didReceiveResponse(response); |
| 779 } | 779 } |
| 780 | 780 |
| 781 // We may have been cancelled after didReceiveResponse, which would leave us | 781 // We may have been cancelled after didReceiveResponse, which would leave us |
| 782 // without a client and therefore without much need to do further handling. | 782 // without a client and therefore without much need to do further handling. |
| 783 if (!client_) | 783 if (!client_) |
| 784 return; | 784 return; |
| 785 | 785 |
| 786 DCHECK(!ftp_listing_delegate_.get()); | 786 DCHECK(!ftp_listing_delegate_.get()); |
| 787 if (info.mime_type == "text/vnd.chromium.ftp-dir" && !show_raw_listing) { | 787 if (info.mime_type == "text/vnd.chromium.ftp-dir" && !show_raw_listing) { |
| 788 ftp_listing_delegate_.reset( | 788 ftp_listing_delegate_.reset( |
| 789 new FtpDirectoryListingResponseDelegate(client_, loader_, response)); | 789 new FtpDirectoryListingResponseDelegate(client_, loader_, response)); |
| 790 } | 790 } |
| 791 } | 791 } |
| 792 | 792 |
| 793 void WebURLLoaderImpl::Context::OnDownloadedData(int len, | 793 void WebURLLoaderImpl::Context::OnDownloadedData(int len, |
| 794 int encoded_data_length) { | 794 int encoded_data_length) { |
| 795 if (client_) | 795 if (client_) |
| 796 client_->didDownloadData(loader_, len, encoded_data_length); | 796 client_->didDownloadData(len, encoded_data_length); |
| 797 } | 797 } |
| 798 | 798 |
| 799 void WebURLLoaderImpl::Context::OnReceivedData( | 799 void WebURLLoaderImpl::Context::OnReceivedData( |
| 800 std::unique_ptr<ReceivedData> data) { | 800 std::unique_ptr<ReceivedData> data) { |
| 801 const char* payload = data->payload(); | 801 const char* payload = data->payload(); |
| 802 int data_length = data->length(); | 802 int data_length = data->length(); |
| 803 int encoded_data_length = data->encoded_data_length(); | 803 int encoded_data_length = data->encoded_data_length(); |
| 804 if (!client_) | 804 if (!client_) |
| 805 return; | 805 return; |
| 806 | 806 |
| 807 TRACE_EVENT_WITH_FLOW0( | 807 TRACE_EVENT_WITH_FLOW0( |
| 808 "loading", "WebURLLoaderImpl::Context::OnReceivedData", | 808 "loading", "WebURLLoaderImpl::Context::OnReceivedData", |
| 809 this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | 809 this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); |
| 810 | 810 |
| 811 if (ftp_listing_delegate_) { | 811 if (ftp_listing_delegate_) { |
| 812 // The FTP listing delegate will make the appropriate calls to | 812 // The FTP listing delegate will make the appropriate calls to |
| 813 // client_->didReceiveData and client_->didReceiveResponse. | 813 // client_->didReceiveData and client_->didReceiveResponse. |
| 814 ftp_listing_delegate_->OnReceivedData(payload, data_length); | 814 ftp_listing_delegate_->OnReceivedData(payload, data_length); |
| 815 } else { | 815 } else { |
| 816 // We dispatch the data even when |useStreamOnResponse()| is set, in order | 816 // We dispatch the data even when |useStreamOnResponse()| is set, in order |
| 817 // to make Devtools work. | 817 // to make Devtools work. |
| 818 client_->didReceiveData(loader_, payload, data_length, encoded_data_length); | 818 client_->didReceiveData(payload, data_length, encoded_data_length); |
| 819 | 819 |
| 820 if (request_.useStreamOnResponse()) { | 820 if (request_.useStreamOnResponse()) { |
| 821 // We don't support ftp_listening_delegate_ for now. | 821 // We don't support ftp_listening_delegate_ for now. |
| 822 // TODO(yhirano): Support ftp listening. | 822 // TODO(yhirano): Support ftp listening. |
| 823 body_stream_writer_->AddData(std::move(data)); | 823 body_stream_writer_->AddData(std::move(data)); |
| 824 } | 824 } |
| 825 } | 825 } |
| 826 } | 826 } |
| 827 | 827 |
| 828 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata( | 828 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata( |
| 829 const char* data, int len) { | 829 const char* data, int len) { |
| 830 if (!client_) | 830 if (!client_) |
| 831 return; | 831 return; |
| 832 TRACE_EVENT_WITH_FLOW0( | 832 TRACE_EVENT_WITH_FLOW0( |
| 833 "loading", "WebURLLoaderImpl::Context::OnReceivedCachedMetadata", | 833 "loading", "WebURLLoaderImpl::Context::OnReceivedCachedMetadata", |
| 834 this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | 834 this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); |
| 835 client_->didReceiveCachedMetadata(loader_, data, len); | 835 client_->didReceiveCachedMetadata(data, len); |
| 836 } | 836 } |
| 837 | 837 |
| 838 void WebURLLoaderImpl::Context::OnCompletedRequest( | 838 void WebURLLoaderImpl::Context::OnCompletedRequest( |
| 839 int error_code, | 839 int error_code, |
| 840 bool was_ignored_by_handler, | 840 bool was_ignored_by_handler, |
| 841 bool stale_copy_in_cache, | 841 bool stale_copy_in_cache, |
| 842 const base::TimeTicks& completion_time, | 842 const base::TimeTicks& completion_time, |
| 843 int64_t total_transfer_size, | 843 int64_t total_transfer_size, |
| 844 int64_t encoded_body_size) { | 844 int64_t encoded_body_size) { |
| 845 if (ftp_listing_delegate_) { | 845 if (ftp_listing_delegate_) { |
| 846 ftp_listing_delegate_->OnCompletedRequest(); | 846 ftp_listing_delegate_->OnCompletedRequest(); |
| 847 ftp_listing_delegate_.reset(NULL); | 847 ftp_listing_delegate_.reset(NULL); |
| 848 } | 848 } |
| 849 | 849 |
| 850 if (body_stream_writer_ && error_code != net::OK) | 850 if (body_stream_writer_ && error_code != net::OK) |
| 851 body_stream_writer_->Fail(); | 851 body_stream_writer_->Fail(); |
| 852 body_stream_writer_.reset(); | 852 body_stream_writer_.reset(); |
| 853 | 853 |
| 854 if (client_) { | 854 if (client_) { |
| 855 TRACE_EVENT_WITH_FLOW0( | 855 TRACE_EVENT_WITH_FLOW0( |
| 856 "loading", "WebURLLoaderImpl::Context::OnCompletedRequest", | 856 "loading", "WebURLLoaderImpl::Context::OnCompletedRequest", |
| 857 this, TRACE_EVENT_FLAG_FLOW_IN); | 857 this, TRACE_EVENT_FLAG_FLOW_IN); |
| 858 | 858 |
| 859 if (error_code != net::OK) { | 859 if (error_code != net::OK) { |
| 860 client_->didFail(loader_, | 860 client_->didFail(CreateWebURLError(request_.url(), stale_copy_in_cache, |
| 861 CreateWebURLError(request_.url(), stale_copy_in_cache, | |
| 862 error_code, was_ignored_by_handler), | 861 error_code, was_ignored_by_handler), |
| 863 total_transfer_size, encoded_body_size); | 862 total_transfer_size, encoded_body_size); |
| 864 } else { | 863 } else { |
| 865 client_->didFinishLoading(loader_, | 864 client_->didFinishLoading((completion_time - TimeTicks()).InSecondsF(), |
| 866 (completion_time - TimeTicks()).InSecondsF(), | |
| 867 total_transfer_size, encoded_body_size); | 865 total_transfer_size, encoded_body_size); |
| 868 } | 866 } |
| 869 } | 867 } |
| 870 } | 868 } |
| 871 | 869 |
| 872 WebURLLoaderImpl::Context::~Context() { | 870 WebURLLoaderImpl::Context::~Context() { |
| 873 // We must be already cancelled at this point. | 871 // We must be already cancelled at this point. |
| 874 DCHECK_LT(request_id_, 0); | 872 DCHECK_LT(request_id_, 0); |
| 875 } | 873 } |
| 876 | 874 |
| 877 void WebURLLoaderImpl::Context::CancelBodyStreaming() { | 875 void WebURLLoaderImpl::Context::CancelBodyStreaming() { |
| 878 scoped_refptr<Context> protect(this); | 876 scoped_refptr<Context> protect(this); |
| 879 | 877 |
| 880 // Notify renderer clients that the request is canceled. | 878 // Notify renderer clients that the request is canceled. |
| 881 if (ftp_listing_delegate_) { | 879 if (ftp_listing_delegate_) { |
| 882 ftp_listing_delegate_->OnCompletedRequest(); | 880 ftp_listing_delegate_->OnCompletedRequest(); |
| 883 ftp_listing_delegate_.reset(NULL); | 881 ftp_listing_delegate_.reset(NULL); |
| 884 } | 882 } |
| 885 | 883 |
| 886 if (body_stream_writer_) { | 884 if (body_stream_writer_) { |
| 887 body_stream_writer_->Fail(); | 885 body_stream_writer_->Fail(); |
| 888 body_stream_writer_.reset(); | 886 body_stream_writer_.reset(); |
| 889 } | 887 } |
| 890 if (client_) { | 888 if (client_) { |
| 891 // TODO(yhirano): Set |stale_copy_in_cache| appropriately if possible. | 889 // TODO(yhirano): Set |stale_copy_in_cache| appropriately if possible. |
| 892 client_->didFail(loader_, | 890 client_->didFail(CreateWebURLError(request_.url(), false, net::ERR_ABORTED), |
| 893 CreateWebURLError(request_.url(), false, net::ERR_ABORTED), | |
| 894 WebURLLoaderClient::kUnknownEncodedDataLength, 0); | 891 WebURLLoaderClient::kUnknownEncodedDataLength, 0); |
| 895 } | 892 } |
| 896 | 893 |
| 897 // Notify the browser process that the request is canceled. | 894 // Notify the browser process that the request is canceled. |
| 898 Cancel(); | 895 Cancel(); |
| 899 } | 896 } |
| 900 | 897 |
| 901 bool WebURLLoaderImpl::Context::CanHandleDataURLRequestLocally() const { | 898 bool WebURLLoaderImpl::Context::CanHandleDataURLRequestLocally() const { |
| 902 GURL url = request_.url(); | 899 GURL url = request_.url(); |
| 903 if (!url.SchemeIs(url::kDataScheme)) | 900 if (!url.SchemeIs(url::kDataScheme)) |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1254 int intra_priority_value) { | 1251 int intra_priority_value) { |
| 1255 context_->DidChangePriority(new_priority, intra_priority_value); | 1252 context_->DidChangePriority(new_priority, intra_priority_value); |
| 1256 } | 1253 } |
| 1257 | 1254 |
| 1258 void WebURLLoaderImpl::setLoadingTaskRunner( | 1255 void WebURLLoaderImpl::setLoadingTaskRunner( |
| 1259 base::SingleThreadTaskRunner* loading_task_runner) { | 1256 base::SingleThreadTaskRunner* loading_task_runner) { |
| 1260 context_->SetTaskRunner(loading_task_runner); | 1257 context_->SetTaskRunner(loading_task_runner); |
| 1261 } | 1258 } |
| 1262 | 1259 |
| 1263 } // namespace content | 1260 } // namespace content |
| OLD | NEW |