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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 scoped_refptr<net::HttpResponseHeaders> headers( | 175 scoped_refptr<net::HttpResponseHeaders> headers( |
176 new net::HttpResponseHeaders(std::string())); | 176 new net::HttpResponseHeaders(std::string())); |
177 int result = net::URLRequestDataJob::BuildResponse( | 177 int result = net::URLRequestDataJob::BuildResponse( |
178 url, &mime_type, &charset, data, headers.get()); | 178 url, &mime_type, &charset, data, headers.get()); |
179 if (result != net::OK) | 179 if (result != net::OK) |
180 return result; | 180 return result; |
181 | 181 |
182 info->headers = headers; | 182 info->headers = headers; |
183 info->mime_type.swap(mime_type); | 183 info->mime_type.swap(mime_type); |
184 info->charset.swap(charset); | 184 info->charset.swap(charset); |
185 info->security_info.clear(); | |
186 info->content_length = data->length(); | 185 info->content_length = data->length(); |
187 info->encoded_data_length = 0; | 186 info->encoded_data_length = 0; |
188 info->encoded_body_length = 0; | 187 info->encoded_body_length = 0; |
189 | 188 |
190 return net::OK; | 189 return net::OK; |
191 } | 190 } |
192 | 191 |
193 // Convert a net::SignedCertificateTimestampAndStatus object to a | 192 // Convert a net::SignedCertificateTimestampAndStatus object to a |
194 // blink::WebURLResponse::SignedCertificateTimestamp object. | 193 // blink::WebURLResponse::SignedCertificateTimestamp object. |
195 blink::WebURLResponse::SignedCertificateTimestamp NetSCTToBlinkSCT( | 194 blink::WebURLResponse::SignedCertificateTimestamp NetSCTToBlinkSCT( |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 void OnUploadProgress(uint64_t position, uint64_t size); | 344 void OnUploadProgress(uint64_t position, uint64_t size); |
346 bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, | 345 bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, |
347 const ResourceResponseInfo& info); | 346 const ResourceResponseInfo& info); |
348 void OnReceivedResponse(const ResourceResponseInfo& info); | 347 void OnReceivedResponse(const ResourceResponseInfo& info); |
349 void OnDownloadedData(int len, int encoded_data_length); | 348 void OnDownloadedData(int len, int encoded_data_length); |
350 void OnReceivedData(std::unique_ptr<ReceivedData> data); | 349 void OnReceivedData(std::unique_ptr<ReceivedData> data); |
351 void OnReceivedCachedMetadata(const char* data, int len); | 350 void OnReceivedCachedMetadata(const char* data, int len); |
352 void OnCompletedRequest(int error_code, | 351 void OnCompletedRequest(int error_code, |
353 bool was_ignored_by_handler, | 352 bool was_ignored_by_handler, |
354 bool stale_copy_in_cache, | 353 bool stale_copy_in_cache, |
355 const std::string& security_info, | |
356 const base::TimeTicks& completion_time, | 354 const base::TimeTicks& completion_time, |
357 int64_t total_transfer_size); | 355 int64_t total_transfer_size); |
358 | 356 |
359 private: | 357 private: |
360 friend class base::RefCounted<Context>; | 358 friend class base::RefCounted<Context>; |
361 ~Context(); | 359 ~Context(); |
362 | 360 |
363 // Called when the body data stream is detached from the reader side. | 361 // Called when the body data stream is detached from the reader side. |
364 void CancelBodyStreaming(); | 362 void CancelBodyStreaming(); |
365 // We can optimize the handling of data URLs in most cases. | 363 // We can optimize the handling of data URLs in most cases. |
(...skipping 27 matching lines...) Expand all Loading... |
393 void OnUploadProgress(uint64_t position, uint64_t size) override; | 391 void OnUploadProgress(uint64_t position, uint64_t size) override; |
394 bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, | 392 bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, |
395 const ResourceResponseInfo& info) override; | 393 const ResourceResponseInfo& info) override; |
396 void OnReceivedResponse(const ResourceResponseInfo& info) override; | 394 void OnReceivedResponse(const ResourceResponseInfo& info) override; |
397 void OnDownloadedData(int len, int encoded_data_length) override; | 395 void OnDownloadedData(int len, int encoded_data_length) override; |
398 void OnReceivedData(std::unique_ptr<ReceivedData> data) override; | 396 void OnReceivedData(std::unique_ptr<ReceivedData> data) override; |
399 void OnReceivedCachedMetadata(const char* data, int len) override; | 397 void OnReceivedCachedMetadata(const char* data, int len) override; |
400 void OnCompletedRequest(int error_code, | 398 void OnCompletedRequest(int error_code, |
401 bool was_ignored_by_handler, | 399 bool was_ignored_by_handler, |
402 bool stale_copy_in_cache, | 400 bool stale_copy_in_cache, |
403 const std::string& security_info, | |
404 const base::TimeTicks& completion_time, | 401 const base::TimeTicks& completion_time, |
405 int64_t total_transfer_size) override; | 402 int64_t total_transfer_size) override; |
406 | 403 |
407 private: | 404 private: |
408 scoped_refptr<Context> context_; | 405 scoped_refptr<Context> context_; |
409 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); | 406 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); |
410 }; | 407 }; |
411 | 408 |
412 // WebURLLoaderImpl::Context -------------------------------------------------- | 409 // WebURLLoaderImpl::Context -------------------------------------------------- |
413 | 410 |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 TRACE_EVENT_WITH_FLOW0( | 768 TRACE_EVENT_WITH_FLOW0( |
772 "loading", "WebURLLoaderImpl::Context::OnReceivedCachedMetadata", | 769 "loading", "WebURLLoaderImpl::Context::OnReceivedCachedMetadata", |
773 this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | 770 this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); |
774 client_->didReceiveCachedMetadata(loader_, data, len); | 771 client_->didReceiveCachedMetadata(loader_, data, len); |
775 } | 772 } |
776 | 773 |
777 void WebURLLoaderImpl::Context::OnCompletedRequest( | 774 void WebURLLoaderImpl::Context::OnCompletedRequest( |
778 int error_code, | 775 int error_code, |
779 bool was_ignored_by_handler, | 776 bool was_ignored_by_handler, |
780 bool stale_copy_in_cache, | 777 bool stale_copy_in_cache, |
781 const std::string& security_info, | |
782 const base::TimeTicks& completion_time, | 778 const base::TimeTicks& completion_time, |
783 int64_t total_transfer_size) { | 779 int64_t total_transfer_size) { |
784 if (ftp_listing_delegate_) { | 780 if (ftp_listing_delegate_) { |
785 ftp_listing_delegate_->OnCompletedRequest(); | 781 ftp_listing_delegate_->OnCompletedRequest(); |
786 ftp_listing_delegate_.reset(NULL); | 782 ftp_listing_delegate_.reset(NULL); |
787 } | 783 } |
788 | 784 |
789 if (body_stream_writer_ && error_code != net::OK) | 785 if (body_stream_writer_ && error_code != net::OK) |
790 body_stream_writer_->Fail(); | 786 body_stream_writer_->Fail(); |
791 body_stream_writer_.reset(); | 787 body_stream_writer_.reset(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 int error_code = GetInfoFromDataURL(request_.url(), &info, &data); | 888 int error_code = GetInfoFromDataURL(request_.url(), &info, &data); |
893 | 889 |
894 if (error_code == net::OK) { | 890 if (error_code == net::OK) { |
895 OnReceivedResponse(info); | 891 OnReceivedResponse(info); |
896 auto size = data.size(); | 892 auto size = data.size(); |
897 if (size != 0) | 893 if (size != 0) |
898 OnReceivedData( | 894 OnReceivedData( |
899 base::MakeUnique<FixedReceivedData>(data.data(), size, 0, size)); | 895 base::MakeUnique<FixedReceivedData>(data.data(), size, 0, size)); |
900 } | 896 } |
901 | 897 |
902 OnCompletedRequest(error_code, false, false, info.security_info, | 898 OnCompletedRequest(error_code, false, false, base::TimeTicks::Now(), 0); |
903 base::TimeTicks::Now(), 0); | |
904 } | 899 } |
905 | 900 |
906 // WebURLLoaderImpl::RequestPeerImpl ------------------------------------------ | 901 // WebURLLoaderImpl::RequestPeerImpl ------------------------------------------ |
907 | 902 |
908 WebURLLoaderImpl::RequestPeerImpl::RequestPeerImpl(Context* context) | 903 WebURLLoaderImpl::RequestPeerImpl::RequestPeerImpl(Context* context) |
909 : context_(context) {} | 904 : context_(context) {} |
910 | 905 |
911 void WebURLLoaderImpl::RequestPeerImpl::OnUploadProgress(uint64_t position, | 906 void WebURLLoaderImpl::RequestPeerImpl::OnUploadProgress(uint64_t position, |
912 uint64_t size) { | 907 uint64_t size) { |
913 context_->OnUploadProgress(position, size); | 908 context_->OnUploadProgress(position, size); |
(...skipping 24 matching lines...) Expand all Loading... |
938 void WebURLLoaderImpl::RequestPeerImpl::OnReceivedCachedMetadata( | 933 void WebURLLoaderImpl::RequestPeerImpl::OnReceivedCachedMetadata( |
939 const char* data, | 934 const char* data, |
940 int len) { | 935 int len) { |
941 context_->OnReceivedCachedMetadata(data, len); | 936 context_->OnReceivedCachedMetadata(data, len); |
942 } | 937 } |
943 | 938 |
944 void WebURLLoaderImpl::RequestPeerImpl::OnCompletedRequest( | 939 void WebURLLoaderImpl::RequestPeerImpl::OnCompletedRequest( |
945 int error_code, | 940 int error_code, |
946 bool was_ignored_by_handler, | 941 bool was_ignored_by_handler, |
947 bool stale_copy_in_cache, | 942 bool stale_copy_in_cache, |
948 const std::string& security_info, | |
949 const base::TimeTicks& completion_time, | 943 const base::TimeTicks& completion_time, |
950 int64_t total_transfer_size) { | 944 int64_t total_transfer_size) { |
951 context_->OnCompletedRequest(error_code, was_ignored_by_handler, | 945 context_->OnCompletedRequest(error_code, was_ignored_by_handler, |
952 stale_copy_in_cache, security_info, | 946 stale_copy_in_cache, completion_time, |
953 completion_time, total_transfer_size); | 947 total_transfer_size); |
954 } | 948 } |
955 | 949 |
956 // WebURLLoaderImpl ----------------------------------------------------------- | 950 // WebURLLoaderImpl ----------------------------------------------------------- |
957 | 951 |
958 WebURLLoaderImpl::WebURLLoaderImpl(ResourceDispatcher* resource_dispatcher, | 952 WebURLLoaderImpl::WebURLLoaderImpl(ResourceDispatcher* resource_dispatcher, |
959 mojom::URLLoaderFactory* url_loader_factory) | 953 mojom::URLLoaderFactory* url_loader_factory) |
960 : context_(new Context(this, resource_dispatcher, url_loader_factory)) {} | 954 : context_(new Context(this, resource_dispatcher, url_loader_factory)) {} |
961 | 955 |
962 WebURLLoaderImpl::~WebURLLoaderImpl() { | 956 WebURLLoaderImpl::~WebURLLoaderImpl() { |
963 cancel(); | 957 cancel(); |
964 } | 958 } |
965 | 959 |
966 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, | 960 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, |
967 const ResourceResponseInfo& info, | 961 const ResourceResponseInfo& info, |
968 WebURLResponse* response, | 962 WebURLResponse* response, |
969 bool report_security_info) { | 963 bool report_security_info) { |
970 response->setURL(url); | 964 response->setURL(url); |
971 response->setResponseTime(info.response_time.ToInternalValue()); | 965 response->setResponseTime(info.response_time.ToInternalValue()); |
972 response->setMIMEType(WebString::fromUTF8(info.mime_type)); | 966 response->setMIMEType(WebString::fromUTF8(info.mime_type)); |
973 response->setTextEncodingName(WebString::fromUTF8(info.charset)); | 967 response->setTextEncodingName(WebString::fromUTF8(info.charset)); |
974 response->setExpectedContentLength(info.content_length); | 968 response->setExpectedContentLength(info.content_length); |
975 response->setSecurityInfo(info.security_info); | |
976 response->setHasMajorCertificateErrors(info.has_major_certificate_errors); | 969 response->setHasMajorCertificateErrors(info.has_major_certificate_errors); |
977 response->setAppCacheID(info.appcache_id); | 970 response->setAppCacheID(info.appcache_id); |
978 response->setAppCacheManifestURL(info.appcache_manifest_url); | 971 response->setAppCacheManifestURL(info.appcache_manifest_url); |
979 response->setWasCached(!info.load_timing.request_start_time.is_null() && | 972 response->setWasCached(!info.load_timing.request_start_time.is_null() && |
980 info.response_time < info.load_timing.request_start_time); | 973 info.response_time < info.load_timing.request_start_time); |
981 response->setRemoteIPAddress( | 974 response->setRemoteIPAddress( |
982 WebString::fromUTF8(info.socket_address.HostForURL())); | 975 WebString::fromUTF8(info.socket_address.HostForURL())); |
983 response->setRemotePort(info.socket_address.port()); | 976 response->setRemotePort(info.socket_address.port()); |
984 response->setConnectionID(info.load_timing.socket_log_id); | 977 response->setConnectionID(info.load_timing.socket_log_id); |
985 response->setConnectionReused(info.load_timing.socket_reused); | 978 response->setConnectionReused(info.load_timing.socket_reused); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 response->clearHTTPHeaderField(webStringName); | 1231 response->clearHTTPHeaderField(webStringName); |
1239 while (response_headers->EnumerateHeader(&iterator, name, &value)) { | 1232 while (response_headers->EnumerateHeader(&iterator, name, &value)) { |
1240 response->addHTTPHeaderField(webStringName, | 1233 response->addHTTPHeaderField(webStringName, |
1241 WebString::fromLatin1(value)); | 1234 WebString::fromLatin1(value)); |
1242 } | 1235 } |
1243 } | 1236 } |
1244 return true; | 1237 return true; |
1245 } | 1238 } |
1246 | 1239 |
1247 } // namespace content | 1240 } // namespace content |
OLD | NEW |