Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1374)

Side by Side Diff: content/child/web_url_loader_impl.cc

Issue 958083002: PlzNavigate: Show error pages when the navigation failed before commit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@support-data-urls
Patch Set: Updated test Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/child/web_url_loader_impl.h ('k') | content/child/web_url_request_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 int data_length, 682 int data_length,
686 int encoded_data_length) { 683 int encoded_data_length) {
687 if (!client_) 684 if (!client_)
688 return; 685 return;
689 686
690 if (request_.useStreamOnResponse()) { 687 if (request_.useStreamOnResponse()) {
691 // We don't support ftp_listening_delegate_ and multipart_delegate_ for now. 688 // We don't support ftp_listening_delegate_ and multipart_delegate_ for now.
692 // TODO(yhirano): Support ftp listening and multipart. 689 // TODO(yhirano): Support ftp listening and multipart.
693 MojoResult rv = WriteDataOnBodyStream(data, data_length); 690 MojoResult rv = WriteDataOnBodyStream(data, data_length);
694 if (rv != MOJO_RESULT_OK && client_) { 691 if (rv != MOJO_RESULT_OK && client_) {
695 client_->didFail(loader_, 692 client_->didFail(
696 loader_->CreateError(request_.url(), 693 loader_, CreateWebURLError(request_.url(), false, net::ERR_FAILED));
697 false,
698 net::ERR_FAILED));
699 } 694 }
700 } else if (ftp_listing_delegate_) { 695 } else if (ftp_listing_delegate_) {
701 // The FTP listing delegate will make the appropriate calls to 696 // The FTP listing delegate will make the appropriate calls to
702 // client_->didReceiveData and client_->didReceiveResponse. Since the 697 // client_->didReceiveData and client_->didReceiveResponse. Since the
703 // delegate may want to do work after sending data to the delegate, keep 698 // delegate may want to do work after sending data to the delegate, keep
704 // |this| and the delegate alive until it's finished handling the data. 699 // |this| and the delegate alive until it's finished handling the data.
705 scoped_refptr<Context> protect(this); 700 scoped_refptr<Context> protect(this);
706 ftp_listing_delegate_->OnReceivedData(data, data_length); 701 ftp_listing_delegate_->OnReceivedData(data, data_length);
707 } else if (multipart_delegate_) { 702 } else if (multipart_delegate_) {
708 // The multipart delegate will make the appropriate calls to 703 // The multipart delegate will make the appropriate calls to
(...skipping 29 matching lines...) Expand all
738 if (ftp_listing_delegate_) { 733 if (ftp_listing_delegate_) {
739 ftp_listing_delegate_->OnCompletedRequest(); 734 ftp_listing_delegate_->OnCompletedRequest();
740 ftp_listing_delegate_.reset(NULL); 735 ftp_listing_delegate_.reset(NULL);
741 } else if (multipart_delegate_) { 736 } else if (multipart_delegate_) {
742 multipart_delegate_->OnCompletedRequest(); 737 multipart_delegate_->OnCompletedRequest();
743 multipart_delegate_.reset(NULL); 738 multipart_delegate_.reset(NULL);
744 } 739 }
745 740
746 if (client_) { 741 if (client_) {
747 if (error_code != net::OK) { 742 if (error_code != net::OK) {
748 client_->didFail(loader_, CreateError(request_.url(), 743 client_->didFail(
749 stale_copy_in_cache, 744 loader_,
750 error_code)); 745 CreateWebURLError(request_.url(), stale_copy_in_cache, error_code));
751 } else { 746 } else {
752 if (request_.useStreamOnResponse()) { 747 if (request_.useStreamOnResponse()) {
753 got_all_stream_body_data_ = true; 748 got_all_stream_body_data_ = true;
754 if (body_stream_buffer_.empty()) { 749 if (body_stream_buffer_.empty()) {
755 // Close the handle to notify the end of data. 750 // Close the handle to notify the end of data.
756 body_stream_writer_.reset(); 751 body_stream_writer_.reset();
757 client_->didFinishLoading( 752 client_->didFinishLoading(
758 loader_, (completion_time - TimeTicks()).InSecondsF(), 753 loader_, (completion_time - TimeTicks()).InSecondsF(),
759 total_transfer_size); 754 total_transfer_size);
760 } 755 }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 MOJO_DEADLINE_INDEFINITE, 891 MOJO_DEADLINE_INDEFINITE,
897 base::Bind(&WebURLLoaderImpl::Context::OnHandleGotWritable, 892 base::Bind(&WebURLLoaderImpl::Context::OnHandleGotWritable,
898 base::Unretained(this))); 893 base::Unretained(this)));
899 } 894 }
900 return rv; 895 return rv;
901 } 896 }
902 897
903 void WebURLLoaderImpl::Context::OnHandleGotWritable(MojoResult result) { 898 void WebURLLoaderImpl::Context::OnHandleGotWritable(MojoResult result) {
904 if (result != MOJO_RESULT_OK) { 899 if (result != MOJO_RESULT_OK) {
905 if (client_) { 900 if (client_) {
906 client_->didFail(loader_, 901 client_->didFail(
907 loader_->CreateError(request_.url(), 902 loader_, CreateWebURLError(request_.url(), false, net::ERR_FAILED));
908 false,
909 net::ERR_FAILED));
910 // |this| can be deleted here. 903 // |this| can be deleted here.
911 } 904 }
912 return; 905 return;
913 } 906 }
914 907
915 if (body_stream_buffer_.empty()) 908 if (body_stream_buffer_.empty())
916 return; 909 return;
917 910
918 MojoResult rv = WriteDataOnBodyStream(nullptr, 0); 911 MojoResult rv = WriteDataOnBodyStream(nullptr, 0);
919 if (rv == MOJO_RESULT_OK) { 912 if (rv == MOJO_RESULT_OK) {
920 if (got_all_stream_body_data_ && body_stream_buffer_.empty()) { 913 if (got_all_stream_body_data_ && body_stream_buffer_.empty()) {
921 // Close the handle to notify the end of data. 914 // Close the handle to notify the end of data.
922 body_stream_writer_.reset(); 915 body_stream_writer_.reset();
923 if (client_) { 916 if (client_) {
924 // TODO(yhirano): Pass appropriate arguments. 917 // TODO(yhirano): Pass appropriate arguments.
925 client_->didFinishLoading(loader_, 0, 0); 918 client_->didFinishLoading(loader_, 0, 0);
926 // |this| can be deleted here. 919 // |this| can be deleted here.
927 } 920 }
928 } 921 }
929 } else { 922 } else {
930 if (client_) { 923 if (client_) {
931 client_->didFail(loader_, loader_->CreateError(request_.url(), 924 client_->didFail(
932 false, 925 loader_, CreateWebURLError(request_.url(), false, net::ERR_FAILED));
933 net::ERR_FAILED));
934 // |this| can be deleted here. 926 // |this| can be deleted here.
935 } 927 }
936 } 928 }
937 } 929 }
938 930
939 // WebURLLoaderImpl ----------------------------------------------------------- 931 // WebURLLoaderImpl -----------------------------------------------------------
940 932
941 WebURLLoaderImpl::WebURLLoaderImpl( 933 WebURLLoaderImpl::WebURLLoaderImpl(
942 ResourceDispatcher* resource_dispatcher, 934 ResourceDispatcher* resource_dispatcher,
943 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 935 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
944 : context_(new Context(this, resource_dispatcher, task_runner)) { 936 : context_(new Context(this, resource_dispatcher, task_runner)) {
945 } 937 }
946 938
947 WebURLLoaderImpl::~WebURLLoaderImpl() { 939 WebURLLoaderImpl::~WebURLLoaderImpl() {
948 cancel(); 940 cancel();
949 } 941 }
950 942
951 WebURLError WebURLLoaderImpl::CreateError(const WebURL& unreachable_url,
952 bool stale_copy_in_cache,
953 int reason) {
954 WebURLError error;
955 error.domain = WebString::fromUTF8(net::kErrorDomain);
956 error.reason = reason;
957 error.unreachableURL = unreachable_url;
958 error.staleCopyInCache = stale_copy_in_cache;
959 if (reason == net::ERR_ABORTED) {
960 error.isCancellation = true;
961 } else if (reason == net::ERR_TEMPORARILY_THROTTLED) {
962 error.localizedDescription = WebString::fromUTF8(
963 kThrottledErrorDescription);
964 } else {
965 error.localizedDescription = WebString::fromUTF8(
966 net::ErrorToString(reason));
967 }
968 return error;
969 }
970
971 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, 943 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url,
972 const ResourceResponseInfo& info, 944 const ResourceResponseInfo& info,
973 WebURLResponse* response) { 945 WebURLResponse* response) {
974 response->setURL(url); 946 response->setURL(url);
975 response->setResponseTime(info.response_time.ToInternalValue()); 947 response->setResponseTime(info.response_time.ToInternalValue());
976 response->setMIMEType(WebString::fromUTF8(info.mime_type)); 948 response->setMIMEType(WebString::fromUTF8(info.mime_type));
977 response->setTextEncodingName(WebString::fromUTF8(info.charset)); 949 response->setTextEncodingName(WebString::fromUTF8(info.charset));
978 response->setExpectedContentLength(info.content_length); 950 response->setExpectedContentLength(info.content_length);
979 response->setSecurityInfo(info.security_info); 951 response->setSecurityInfo(info.security_info);
980 response->setAppCacheID(info.appcache_id); 952 response->setAppCacheID(info.appcache_id);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 int intra_priority_value) { 1112 int intra_priority_value) {
1141 context_->DidChangePriority(new_priority, intra_priority_value); 1113 context_->DidChangePriority(new_priority, intra_priority_value);
1142 } 1114 }
1143 1115
1144 bool WebURLLoaderImpl::attachThreadedDataReceiver( 1116 bool WebURLLoaderImpl::attachThreadedDataReceiver(
1145 blink::WebThreadedDataReceiver* threaded_data_receiver) { 1117 blink::WebThreadedDataReceiver* threaded_data_receiver) {
1146 return context_->AttachThreadedDataReceiver(threaded_data_receiver); 1118 return context_->AttachThreadedDataReceiver(threaded_data_receiver);
1147 } 1119 }
1148 1120
1149 } // namespace content 1121 } // namespace content
OLDNEW
« no previous file with comments | « content/child/web_url_loader_impl.h ('k') | content/child/web_url_request_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698