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 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 response.initialize(); | 577 response.initialize(); |
578 PopulateURLResponse(request_.url(), info, &response, | 578 PopulateURLResponse(request_.url(), info, &response, |
579 request_.reportRawHeaders()); | 579 request_.reportRawHeaders()); |
580 | 580 |
581 WebURLRequest new_request; | 581 WebURLRequest new_request; |
582 new_request.initialize(); | 582 new_request.initialize(); |
583 PopulateURLRequestForRedirect(request_, redirect_info, referrer_policy_, | 583 PopulateURLRequestForRedirect(request_, redirect_info, referrer_policy_, |
584 !info.was_fetched_via_service_worker, | 584 !info.was_fetched_via_service_worker, |
585 &new_request); | 585 &new_request); |
586 | 586 |
587 client_->willFollowRedirect(loader_, new_request, response); | 587 client_->willFollowRedirect(loader_, new_request, response, |
| 588 info.encoded_data_length); |
588 request_ = new_request; | 589 request_ = new_request; |
589 | 590 |
590 // Only follow the redirect if WebKit left the URL unmodified. | 591 // Only follow the redirect if WebKit left the URL unmodified. |
591 if (redirect_info.new_url == GURL(new_request.url())) { | 592 if (redirect_info.new_url == GURL(new_request.url())) { |
592 // First-party cookie logic moved from DocumentLoader in Blink to | 593 // First-party cookie logic moved from DocumentLoader in Blink to |
593 // net::URLRequest in the browser. Assert that Blink didn't try to change it | 594 // net::URLRequest in the browser. Assert that Blink didn't try to change it |
594 // to something else. | 595 // to something else. |
595 DCHECK_EQ(redirect_info.new_first_party_for_cookies.spec(), | 596 DCHECK_EQ(redirect_info.new_first_party_for_cookies.spec(), |
596 request_.firstPartyForCookies().string().utf8()); | 597 request_.firstPartyForCookies().string().utf8()); |
597 return true; | 598 return true; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 void WebURLLoaderImpl::Context::OnDownloadedData(int len, | 693 void WebURLLoaderImpl::Context::OnDownloadedData(int len, |
693 int encoded_data_length) { | 694 int encoded_data_length) { |
694 if (client_) | 695 if (client_) |
695 client_->didDownloadData(loader_, len, encoded_data_length); | 696 client_->didDownloadData(loader_, len, encoded_data_length); |
696 } | 697 } |
697 | 698 |
698 void WebURLLoaderImpl::Context::OnReceivedData( | 699 void WebURLLoaderImpl::Context::OnReceivedData( |
699 std::unique_ptr<ReceivedData> data) { | 700 std::unique_ptr<ReceivedData> data) { |
700 const char* payload = data->payload(); | 701 const char* payload = data->payload(); |
701 int data_length = data->length(); | 702 int data_length = data->length(); |
702 int encoded_data_length = data->encoded_length(); | 703 int encoded_data_length = data->encoded_data_length(); |
703 if (!client_) | 704 if (!client_) |
704 return; | 705 return; |
705 | 706 |
706 TRACE_EVENT_WITH_FLOW0( | 707 TRACE_EVENT_WITH_FLOW0( |
707 "loading", "WebURLLoaderImpl::Context::OnReceivedData", | 708 "loading", "WebURLLoaderImpl::Context::OnReceivedData", |
708 this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); | 709 this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); |
709 | 710 |
710 if (ftp_listing_delegate_) { | 711 if (ftp_listing_delegate_) { |
711 // The FTP listing delegate will make the appropriate calls to | 712 // The FTP listing delegate will make the appropriate calls to |
712 // client_->didReceiveData and client_->didReceiveResponse. | 713 // client_->didReceiveData and client_->didReceiveResponse. |
713 ftp_listing_delegate_->OnReceivedData(payload, data_length); | 714 ftp_listing_delegate_->OnReceivedData(payload, data_length); |
714 } else { | 715 } else { |
715 // We dispatch the data even when |useStreamOnResponse()| is set, in order | 716 // We dispatch the data even when |useStreamOnResponse()| is set, in order |
716 // to make Devtools work. | 717 // to make Devtools work. |
717 client_->didReceiveData(loader_, payload, data_length, encoded_data_length); | 718 client_->didReceiveData(loader_, payload, data_length, encoded_data_length, |
| 719 data->encoded_body_length()); |
718 | 720 |
719 if (request_.useStreamOnResponse()) { | 721 if (request_.useStreamOnResponse()) { |
720 // We don't support ftp_listening_delegate_ for now. | 722 // We don't support ftp_listening_delegate_ for now. |
721 // TODO(yhirano): Support ftp listening. | 723 // TODO(yhirano): Support ftp listening. |
722 body_stream_writer_->AddData(std::move(data)); | 724 body_stream_writer_->AddData(std::move(data)); |
723 } | 725 } |
724 } | 726 } |
725 } | 727 } |
726 | 728 |
727 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata( | 729 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata( |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 return; | 848 return; |
847 } | 849 } |
848 | 850 |
849 ResourceResponseInfo info; | 851 ResourceResponseInfo info; |
850 std::string data; | 852 std::string data; |
851 | 853 |
852 int error_code = GetInfoFromDataURL(request_.url(), &info, &data); | 854 int error_code = GetInfoFromDataURL(request_.url(), &info, &data); |
853 | 855 |
854 if (error_code == net::OK) { | 856 if (error_code == net::OK) { |
855 OnReceivedResponse(info); | 857 OnReceivedResponse(info); |
856 if (!data.empty()) | 858 auto size = data.size(); |
| 859 if (size != 0) |
857 OnReceivedData( | 860 OnReceivedData( |
858 base::WrapUnique(new FixedReceivedData(data.data(), data.size(), 0))); | 861 base::WrapUnique(new FixedReceivedData(data.data(), size, 0, size))); |
859 } | 862 } |
860 | 863 |
861 OnCompletedRequest(error_code, false, false, info.security_info, | 864 OnCompletedRequest(error_code, false, false, info.security_info, |
862 base::TimeTicks::Now(), 0); | 865 base::TimeTicks::Now(), 0); |
863 } | 866 } |
864 | 867 |
865 // WebURLLoaderImpl::RequestPeerImpl ------------------------------------------ | 868 // WebURLLoaderImpl::RequestPeerImpl ------------------------------------------ |
866 | 869 |
867 WebURLLoaderImpl::RequestPeerImpl::RequestPeerImpl(Context* context) | 870 WebURLLoaderImpl::RequestPeerImpl::RequestPeerImpl(Context* context) |
868 : context_(context) {} | 871 : context_(context) {} |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 if (error_code != net::OK) { | 1117 if (error_code != net::OK) { |
1115 response.setURL(final_url); | 1118 response.setURL(final_url); |
1116 error.domain = WebString::fromUTF8(net::kErrorDomain); | 1119 error.domain = WebString::fromUTF8(net::kErrorDomain); |
1117 error.reason = error_code; | 1120 error.reason = error_code; |
1118 error.unreachableURL = final_url; | 1121 error.unreachableURL = final_url; |
1119 return; | 1122 return; |
1120 } | 1123 } |
1121 | 1124 |
1122 PopulateURLResponse(final_url, sync_load_response, &response, | 1125 PopulateURLResponse(final_url, sync_load_response, &response, |
1123 request.reportRawHeaders()); | 1126 request.reportRawHeaders()); |
| 1127 response.addToEncodedBodyLength(sync_load_response.encoded_body_length); |
| 1128 response.addToDecodedBodyLength(sync_load_response.data.size()); |
1124 | 1129 |
1125 data.assign(sync_load_response.data.data(), | 1130 data.assign(sync_load_response.data.data(), sync_load_response.data.size()); |
1126 sync_load_response.data.size()); | |
1127 } | 1131 } |
1128 | 1132 |
1129 void WebURLLoaderImpl::loadAsynchronously(const WebURLRequest& request, | 1133 void WebURLLoaderImpl::loadAsynchronously(const WebURLRequest& request, |
1130 WebURLLoaderClient* client) { | 1134 WebURLLoaderClient* client) { |
1131 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::loadAsynchronously", | 1135 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::loadAsynchronously", |
1132 this, TRACE_EVENT_FLAG_FLOW_OUT); | 1136 this, TRACE_EVENT_FLAG_FLOW_OUT); |
1133 DCHECK(!context_->client()); | 1137 DCHECK(!context_->client()); |
1134 | 1138 |
1135 context_->set_client(client); | 1139 context_->set_client(client); |
1136 context_->Start(request, NULL); | 1140 context_->Start(request, NULL); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 response->clearHTTPHeaderField(webStringName); | 1202 response->clearHTTPHeaderField(webStringName); |
1199 while (response_headers->EnumerateHeader(&iterator, name, &value)) { | 1203 while (response_headers->EnumerateHeader(&iterator, name, &value)) { |
1200 response->addHTTPHeaderField(webStringName, | 1204 response->addHTTPHeaderField(webStringName, |
1201 WebString::fromLatin1(value)); | 1205 WebString::fromLatin1(value)); |
1202 } | 1206 } |
1203 } | 1207 } |
1204 return true; | 1208 return true; |
1205 } | 1209 } |
1206 | 1210 |
1207 } // namespace content | 1211 } // namespace content |
OLD | NEW |