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 <deque> | 8 #include <deque> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 using blink::WebURLLoaderClient; | 64 using blink::WebURLLoaderClient; |
65 using blink::WebURLRequest; | 65 using blink::WebURLRequest; |
66 using blink::WebURLResponse; | 66 using blink::WebURLResponse; |
67 | 67 |
68 namespace content { | 68 namespace content { |
69 | 69 |
70 // Utilities ------------------------------------------------------------------ | 70 // Utilities ------------------------------------------------------------------ |
71 | 71 |
72 namespace { | 72 namespace { |
73 | 73 |
74 const char kThrottledErrorDescription[] = | |
75 "Request throttled. Visit http://dev.chromium.org/throttling for more " | |
76 "information."; | |
77 const size_t kBodyStreamPipeCapacity = 4 * 1024; | 74 const size_t kBodyStreamPipeCapacity = 4 * 1024; |
78 | 75 |
79 typedef ResourceDevToolsInfo::HeadersVector HeadersVector; | 76 typedef ResourceDevToolsInfo::HeadersVector HeadersVector; |
80 | 77 |
81 // Converts timing data from |load_timing| to the format used by WebKit. | 78 // Converts timing data from |load_timing| to the format used by WebKit. |
82 void PopulateURLLoadTiming(const net::LoadTimingInfo& load_timing, | 79 void PopulateURLLoadTiming(const net::LoadTimingInfo& load_timing, |
83 WebURLLoadTiming* url_timing) { | 80 WebURLLoadTiming* url_timing) { |
84 DCHECK(!load_timing.request_start.is_null()); | 81 DCHECK(!load_timing.request_start.is_null()); |
85 | 82 |
86 const TimeTicks kNullTicks; | 83 const TimeTicks kNullTicks; |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 int data_length, | 680 int data_length, |
684 int encoded_data_length) { | 681 int encoded_data_length) { |
685 if (!client_) | 682 if (!client_) |
686 return; | 683 return; |
687 | 684 |
688 if (request_.useStreamOnResponse()) { | 685 if (request_.useStreamOnResponse()) { |
689 // We don't support ftp_listening_delegate_ and multipart_delegate_ for now. | 686 // We don't support ftp_listening_delegate_ and multipart_delegate_ for now. |
690 // TODO(yhirano): Support ftp listening and multipart. | 687 // TODO(yhirano): Support ftp listening and multipart. |
691 MojoResult rv = WriteDataOnBodyStream(data, data_length); | 688 MojoResult rv = WriteDataOnBodyStream(data, data_length); |
692 if (rv != MOJO_RESULT_OK && client_) { | 689 if (rv != MOJO_RESULT_OK && client_) { |
693 client_->didFail(loader_, | 690 client_->didFail( |
694 loader_->CreateError(request_.url(), | 691 loader_, CreateWebURLError(request_.url(), false, net::ERR_FAILED)); |
695 false, | |
696 net::ERR_FAILED)); | |
697 } | 692 } |
698 } else if (ftp_listing_delegate_) { | 693 } else if (ftp_listing_delegate_) { |
699 // The FTP listing delegate will make the appropriate calls to | 694 // The FTP listing delegate will make the appropriate calls to |
700 // client_->didReceiveData and client_->didReceiveResponse. Since the | 695 // client_->didReceiveData and client_->didReceiveResponse. Since the |
701 // delegate may want to do work after sending data to the delegate, keep | 696 // delegate may want to do work after sending data to the delegate, keep |
702 // |this| and the delegate alive until it's finished handling the data. | 697 // |this| and the delegate alive until it's finished handling the data. |
703 scoped_refptr<Context> protect(this); | 698 scoped_refptr<Context> protect(this); |
704 ftp_listing_delegate_->OnReceivedData(data, data_length); | 699 ftp_listing_delegate_->OnReceivedData(data, data_length); |
705 } else if (multipart_delegate_) { | 700 } else if (multipart_delegate_) { |
706 // The multipart delegate will make the appropriate calls to | 701 // The multipart delegate will make the appropriate calls to |
(...skipping 29 matching lines...) Expand all Loading... |
736 if (ftp_listing_delegate_) { | 731 if (ftp_listing_delegate_) { |
737 ftp_listing_delegate_->OnCompletedRequest(); | 732 ftp_listing_delegate_->OnCompletedRequest(); |
738 ftp_listing_delegate_.reset(NULL); | 733 ftp_listing_delegate_.reset(NULL); |
739 } else if (multipart_delegate_) { | 734 } else if (multipart_delegate_) { |
740 multipart_delegate_->OnCompletedRequest(); | 735 multipart_delegate_->OnCompletedRequest(); |
741 multipart_delegate_.reset(NULL); | 736 multipart_delegate_.reset(NULL); |
742 } | 737 } |
743 | 738 |
744 if (client_) { | 739 if (client_) { |
745 if (error_code != net::OK) { | 740 if (error_code != net::OK) { |
746 client_->didFail(loader_, CreateError(request_.url(), | 741 client_->didFail( |
747 stale_copy_in_cache, | 742 loader_, |
748 error_code)); | 743 CreateWebURLError(request_.url(), stale_copy_in_cache, error_code)); |
749 } else { | 744 } else { |
750 if (request_.useStreamOnResponse()) { | 745 if (request_.useStreamOnResponse()) { |
751 got_all_stream_body_data_ = true; | 746 got_all_stream_body_data_ = true; |
752 if (body_stream_buffer_.empty()) { | 747 if (body_stream_buffer_.empty()) { |
753 // Close the handle to notify the end of data. | 748 // Close the handle to notify the end of data. |
754 body_stream_writer_.reset(); | 749 body_stream_writer_.reset(); |
755 client_->didFinishLoading( | 750 client_->didFinishLoading( |
756 loader_, (completion_time - TimeTicks()).InSecondsF(), | 751 loader_, (completion_time - TimeTicks()).InSecondsF(), |
757 total_transfer_size); | 752 total_transfer_size); |
758 } | 753 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 MOJO_DEADLINE_INDEFINITE, | 889 MOJO_DEADLINE_INDEFINITE, |
895 base::Bind(&WebURLLoaderImpl::Context::OnHandleGotWritable, | 890 base::Bind(&WebURLLoaderImpl::Context::OnHandleGotWritable, |
896 base::Unretained(this))); | 891 base::Unretained(this))); |
897 } | 892 } |
898 return rv; | 893 return rv; |
899 } | 894 } |
900 | 895 |
901 void WebURLLoaderImpl::Context::OnHandleGotWritable(MojoResult result) { | 896 void WebURLLoaderImpl::Context::OnHandleGotWritable(MojoResult result) { |
902 if (result != MOJO_RESULT_OK) { | 897 if (result != MOJO_RESULT_OK) { |
903 if (client_) { | 898 if (client_) { |
904 client_->didFail(loader_, | 899 client_->didFail( |
905 loader_->CreateError(request_.url(), | 900 loader_, CreateWebURLError(request_.url(), false, net::ERR_FAILED)); |
906 false, | |
907 net::ERR_FAILED)); | |
908 // |this| can be deleted here. | 901 // |this| can be deleted here. |
909 } | 902 } |
910 return; | 903 return; |
911 } | 904 } |
912 | 905 |
913 if (body_stream_buffer_.empty()) | 906 if (body_stream_buffer_.empty()) |
914 return; | 907 return; |
915 | 908 |
916 MojoResult rv = WriteDataOnBodyStream(nullptr, 0); | 909 MojoResult rv = WriteDataOnBodyStream(nullptr, 0); |
917 if (rv == MOJO_RESULT_OK) { | 910 if (rv == MOJO_RESULT_OK) { |
918 if (got_all_stream_body_data_ && body_stream_buffer_.empty()) { | 911 if (got_all_stream_body_data_ && body_stream_buffer_.empty()) { |
919 // Close the handle to notify the end of data. | 912 // Close the handle to notify the end of data. |
920 body_stream_writer_.reset(); | 913 body_stream_writer_.reset(); |
921 if (client_) { | 914 if (client_) { |
922 // TODO(yhirano): Pass appropriate arguments. | 915 // TODO(yhirano): Pass appropriate arguments. |
923 client_->didFinishLoading(loader_, 0, 0); | 916 client_->didFinishLoading(loader_, 0, 0); |
924 // |this| can be deleted here. | 917 // |this| can be deleted here. |
925 } | 918 } |
926 } | 919 } |
927 } else { | 920 } else { |
928 if (client_) { | 921 if (client_) { |
929 client_->didFail(loader_, loader_->CreateError(request_.url(), | 922 client_->didFail( |
930 false, | 923 loader_, CreateWebURLError(request_.url(), false, net::ERR_FAILED)); |
931 net::ERR_FAILED)); | |
932 // |this| can be deleted here. | 924 // |this| can be deleted here. |
933 } | 925 } |
934 } | 926 } |
935 } | 927 } |
936 | 928 |
937 // WebURLLoaderImpl ----------------------------------------------------------- | 929 // WebURLLoaderImpl ----------------------------------------------------------- |
938 | 930 |
939 WebURLLoaderImpl::WebURLLoaderImpl( | 931 WebURLLoaderImpl::WebURLLoaderImpl( |
940 ResourceDispatcher* resource_dispatcher, | 932 ResourceDispatcher* resource_dispatcher, |
941 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 933 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
942 : context_(new Context(this, resource_dispatcher, task_runner)) { | 934 : context_(new Context(this, resource_dispatcher, task_runner)) { |
943 } | 935 } |
944 | 936 |
945 WebURLLoaderImpl::~WebURLLoaderImpl() { | 937 WebURLLoaderImpl::~WebURLLoaderImpl() { |
946 cancel(); | 938 cancel(); |
947 } | 939 } |
948 | 940 |
949 WebURLError WebURLLoaderImpl::CreateError(const WebURL& unreachable_url, | |
950 bool stale_copy_in_cache, | |
951 int reason) { | |
952 WebURLError error; | |
953 error.domain = WebString::fromUTF8(net::kErrorDomain); | |
954 error.reason = reason; | |
955 error.unreachableURL = unreachable_url; | |
956 error.staleCopyInCache = stale_copy_in_cache; | |
957 if (reason == net::ERR_ABORTED) { | |
958 error.isCancellation = true; | |
959 } else if (reason == net::ERR_TEMPORARILY_THROTTLED) { | |
960 error.localizedDescription = WebString::fromUTF8( | |
961 kThrottledErrorDescription); | |
962 } else { | |
963 error.localizedDescription = WebString::fromUTF8( | |
964 net::ErrorToString(reason)); | |
965 } | |
966 return error; | |
967 } | |
968 | |
969 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, | 941 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, |
970 const ResourceResponseInfo& info, | 942 const ResourceResponseInfo& info, |
971 WebURLResponse* response) { | 943 WebURLResponse* response) { |
972 response->setURL(url); | 944 response->setURL(url); |
973 response->setResponseTime(info.response_time.ToInternalValue()); | 945 response->setResponseTime(info.response_time.ToInternalValue()); |
974 response->setMIMEType(WebString::fromUTF8(info.mime_type)); | 946 response->setMIMEType(WebString::fromUTF8(info.mime_type)); |
975 response->setTextEncodingName(WebString::fromUTF8(info.charset)); | 947 response->setTextEncodingName(WebString::fromUTF8(info.charset)); |
976 response->setExpectedContentLength(info.content_length); | 948 response->setExpectedContentLength(info.content_length); |
977 response->setSecurityInfo(info.security_info); | 949 response->setSecurityInfo(info.security_info); |
978 response->setAppCacheID(info.appcache_id); | 950 response->setAppCacheID(info.appcache_id); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 int intra_priority_value) { | 1110 int intra_priority_value) { |
1139 context_->DidChangePriority(new_priority, intra_priority_value); | 1111 context_->DidChangePriority(new_priority, intra_priority_value); |
1140 } | 1112 } |
1141 | 1113 |
1142 bool WebURLLoaderImpl::attachThreadedDataReceiver( | 1114 bool WebURLLoaderImpl::attachThreadedDataReceiver( |
1143 blink::WebThreadedDataReceiver* threaded_data_receiver) { | 1115 blink::WebThreadedDataReceiver* threaded_data_receiver) { |
1144 return context_->AttachThreadedDataReceiver(threaded_data_receiver); | 1116 return context_->AttachThreadedDataReceiver(threaded_data_receiver); |
1145 } | 1117 } |
1146 | 1118 |
1147 } // namespace content | 1119 } // namespace content |
OLD | NEW |