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

Side by Side Diff: webkit/child/weburlloader_impl.cc

Issue 23830007: Support byte range requests when routing resource requests directly through the browser process. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // An implementation of WebURLLoader in terms of ResourceLoaderBridge. 5 // An implementation of WebURLLoader in terms of ResourceLoaderBridge.
6 6
7 #include "webkit/child/weburlloader_impl.h" 7 #include "webkit/child/weburlloader_impl.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 url_timing->setSSLEnd( 173 url_timing->setSSLEnd(
174 (load_timing.connect_timing.ssl_end - kNullTicks).InSecondsF()); 174 (load_timing.connect_timing.ssl_end - kNullTicks).InSecondsF());
175 url_timing->setSendStart( 175 url_timing->setSendStart(
176 (load_timing.send_start - kNullTicks).InSecondsF()); 176 (load_timing.send_start - kNullTicks).InSecondsF());
177 url_timing->setSendEnd( 177 url_timing->setSendEnd(
178 (load_timing.send_end - kNullTicks).InSecondsF()); 178 (load_timing.send_end - kNullTicks).InSecondsF());
179 url_timing->setReceiveHeadersEnd( 179 url_timing->setReceiveHeadersEnd(
180 (load_timing.receive_headers_end - kNullTicks).InSecondsF()); 180 (load_timing.receive_headers_end - kNullTicks).InSecondsF());
181 } 181 }
182 182
183 void PopulateURLResponse(
184 const GURL& url,
185 const ResourceResponseInfo& info,
186 WebURLResponse* response) {
187 response->setURL(url);
188 response->setResponseTime(info.response_time.ToDoubleT());
189 response->setMIMEType(WebString::fromUTF8(info.mime_type));
190 response->setTextEncodingName(WebString::fromUTF8(info.charset));
191 response->setExpectedContentLength(info.content_length);
192 response->setSecurityInfo(info.security_info);
193 response->setAppCacheID(info.appcache_id);
194 response->setAppCacheManifestURL(info.appcache_manifest_url);
195 response->setWasCached(!info.load_timing.request_start_time.is_null() &&
196 info.response_time < info.load_timing.request_start_time);
197 response->setRemoteIPAddress(
198 WebString::fromUTF8(info.socket_address.host()));
199 response->setRemotePort(info.socket_address.port());
200 response->setConnectionID(info.load_timing.socket_log_id);
201 response->setConnectionReused(info.load_timing.socket_reused);
202 response->setDownloadFilePath(info.download_file_path.AsUTF16Unsafe());
203 WebURLResponseExtraDataImpl* extra_data =
204 new WebURLResponseExtraDataImpl(info.npn_negotiated_protocol);
205 response->setExtraData(extra_data);
206 extra_data->set_was_fetched_via_spdy(info.was_fetched_via_spdy);
207 extra_data->set_was_npn_negotiated(info.was_npn_negotiated);
208 extra_data->set_was_alternate_protocol_available(
209 info.was_alternate_protocol_available);
210 extra_data->set_connection_info(info.connection_info);
211 extra_data->set_was_fetched_via_proxy(info.was_fetched_via_proxy);
212
213 // If there's no received headers end time, don't set load timing. This is
214 // the case for non-HTTP requests, requests that don't go over the wire, and
215 // certain error cases.
216 if (!info.load_timing.receive_headers_end.is_null()) {
217 WebURLLoadTiming timing;
218 PopulateURLLoadTiming(info.load_timing, &timing);
219 response->setLoadTiming(timing);
220 }
221
222 if (info.devtools_info.get()) {
223 WebHTTPLoadInfo load_info;
224
225 load_info.setHTTPStatusCode(info.devtools_info->http_status_code);
226 load_info.setHTTPStatusText(WebString::fromLatin1(
227 info.devtools_info->http_status_text));
228 load_info.setEncodedDataLength(info.encoded_data_length);
229
230 load_info.setRequestHeadersText(WebString::fromLatin1(
231 info.devtools_info->request_headers_text));
232 load_info.setResponseHeadersText(WebString::fromLatin1(
233 info.devtools_info->response_headers_text));
234 const HeadersVector& request_headers = info.devtools_info->request_headers;
235 for (HeadersVector::const_iterator it = request_headers.begin();
236 it != request_headers.end(); ++it) {
237 load_info.addRequestHeader(WebString::fromLatin1(it->first),
238 WebString::fromLatin1(it->second));
239 }
240 const HeadersVector& response_headers =
241 info.devtools_info->response_headers;
242 for (HeadersVector::const_iterator it = response_headers.begin();
243 it != response_headers.end(); ++it) {
244 load_info.addResponseHeader(WebString::fromLatin1(it->first),
245 WebString::fromLatin1(it->second));
246 }
247 response->setHTTPLoadInfo(load_info);
248 }
249
250 const net::HttpResponseHeaders* headers = info.headers.get();
251 if (!headers)
252 return;
253
254 WebURLResponse::HTTPVersion version = WebURLResponse::Unknown;
255 if (headers->GetHttpVersion() == net::HttpVersion(0, 9))
256 version = WebURLResponse::HTTP_0_9;
257 else if (headers->GetHttpVersion() == net::HttpVersion(1, 0))
258 version = WebURLResponse::HTTP_1_0;
259 else if (headers->GetHttpVersion() == net::HttpVersion(1, 1))
260 version = WebURLResponse::HTTP_1_1;
261 response->setHTTPVersion(version);
262 response->setHTTPStatusCode(headers->response_code());
263 response->setHTTPStatusText(WebString::fromLatin1(headers->GetStatusText()));
264
265 // TODO(darin): We should leverage HttpResponseHeaders for this, and this
266 // should be using the same code as ResourceDispatcherHost.
267 // TODO(jungshik): Figure out the actual value of the referrer charset and
268 // pass it to GetSuggestedFilename.
269 std::string value;
270 headers->EnumerateHeader(NULL, "content-disposition", &value);
271 response->setSuggestedFileName(
272 net::GetSuggestedFilename(url,
273 value,
274 std::string(), // referrer_charset
275 std::string(), // suggested_name
276 std::string(), // mime_type
277 std::string())); // default_name
278
279 Time time_val;
280 if (headers->GetLastModifiedValue(&time_val))
281 response->setLastModifiedDate(time_val.ToDoubleT());
282
283 // Build up the header map.
284 void* iter = NULL;
285 std::string name;
286 while (headers->EnumerateHeaderLines(&iter, &name, &value)) {
287 response->addHTTPHeaderField(WebString::fromLatin1(name),
288 WebString::fromLatin1(value));
289 }
290 }
291
292 net::RequestPriority ConvertWebKitPriorityToNetPriority( 183 net::RequestPriority ConvertWebKitPriorityToNetPriority(
293 const WebURLRequest::Priority& priority) { 184 const WebURLRequest::Priority& priority) {
294 switch (priority) { 185 switch (priority) {
295 case WebURLRequest::PriorityVeryHigh: 186 case WebURLRequest::PriorityVeryHigh:
296 return net::HIGHEST; 187 return net::HIGHEST;
297 188
298 case WebURLRequest::PriorityHigh: 189 case WebURLRequest::PriorityHigh:
299 return net::MEDIUM; 190 return net::MEDIUM;
300 191
301 case WebURLRequest::PriorityMedium: 192 case WebURLRequest::PriorityMedium:
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 error.unreachableURL = unreachable_url; 688 error.unreachableURL = unreachable_url;
798 if (reason == net::ERR_ABORTED) { 689 if (reason == net::ERR_ABORTED) {
799 error.isCancellation = true; 690 error.isCancellation = true;
800 } else if (reason == net::ERR_TEMPORARILY_THROTTLED) { 691 } else if (reason == net::ERR_TEMPORARILY_THROTTLED) {
801 error.localizedDescription = WebString::fromUTF8( 692 error.localizedDescription = WebString::fromUTF8(
802 kThrottledErrorDescription); 693 kThrottledErrorDescription);
803 } 694 }
804 return error; 695 return error;
805 } 696 }
806 697
698 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url,
699 const ResourceResponseInfo& info,
700 WebURLResponse* response) {
701 response->setURL(url);
702 response->setResponseTime(info.response_time.ToDoubleT());
703 response->setMIMEType(WebString::fromUTF8(info.mime_type));
704 response->setTextEncodingName(WebString::fromUTF8(info.charset));
705 response->setExpectedContentLength(info.content_length);
706 response->setSecurityInfo(info.security_info);
707 response->setAppCacheID(info.appcache_id);
708 response->setAppCacheManifestURL(info.appcache_manifest_url);
709 response->setWasCached(!info.load_timing.request_start_time.is_null() &&
710 info.response_time < info.load_timing.request_start_time);
711 response->setRemoteIPAddress(
712 WebString::fromUTF8(info.socket_address.host()));
713 response->setRemotePort(info.socket_address.port());
714 response->setConnectionID(info.load_timing.socket_log_id);
715 response->setConnectionReused(info.load_timing.socket_reused);
716 response->setDownloadFilePath(info.download_file_path.AsUTF16Unsafe());
717 WebURLResponseExtraDataImpl* extra_data =
718 new WebURLResponseExtraDataImpl(info.npn_negotiated_protocol);
719 response->setExtraData(extra_data);
720 extra_data->set_was_fetched_via_spdy(info.was_fetched_via_spdy);
721 extra_data->set_was_npn_negotiated(info.was_npn_negotiated);
722 extra_data->set_was_alternate_protocol_available(
723 info.was_alternate_protocol_available);
724 extra_data->set_connection_info(info.connection_info);
725 extra_data->set_was_fetched_via_proxy(info.was_fetched_via_proxy);
726
727 // If there's no received headers end time, don't set load timing. This is
728 // the case for non-HTTP requests, requests that don't go over the wire, and
729 // certain error cases.
730 if (!info.load_timing.receive_headers_end.is_null()) {
731 WebURLLoadTiming timing;
732 PopulateURLLoadTiming(info.load_timing, &timing);
733 response->setLoadTiming(timing);
734 }
735
736 if (info.devtools_info.get()) {
737 WebHTTPLoadInfo load_info;
738
739 load_info.setHTTPStatusCode(info.devtools_info->http_status_code);
740 load_info.setHTTPStatusText(WebString::fromLatin1(
741 info.devtools_info->http_status_text));
742 load_info.setEncodedDataLength(info.encoded_data_length);
743
744 load_info.setRequestHeadersText(WebString::fromLatin1(
745 info.devtools_info->request_headers_text));
746 load_info.setResponseHeadersText(WebString::fromLatin1(
747 info.devtools_info->response_headers_text));
748 const HeadersVector& request_headers = info.devtools_info->request_headers;
749 for (HeadersVector::const_iterator it = request_headers.begin();
750 it != request_headers.end(); ++it) {
751 load_info.addRequestHeader(WebString::fromLatin1(it->first),
752 WebString::fromLatin1(it->second));
753 }
754 const HeadersVector& response_headers =
755 info.devtools_info->response_headers;
756 for (HeadersVector::const_iterator it = response_headers.begin();
757 it != response_headers.end(); ++it) {
758 load_info.addResponseHeader(WebString::fromLatin1(it->first),
759 WebString::fromLatin1(it->second));
760 }
761 response->setHTTPLoadInfo(load_info);
762 }
763
764 const net::HttpResponseHeaders* headers = info.headers.get();
765 if (!headers)
766 return;
767
768 WebURLResponse::HTTPVersion version = WebURLResponse::Unknown;
769 if (headers->GetHttpVersion() == net::HttpVersion(0, 9))
770 version = WebURLResponse::HTTP_0_9;
771 else if (headers->GetHttpVersion() == net::HttpVersion(1, 0))
772 version = WebURLResponse::HTTP_1_0;
773 else if (headers->GetHttpVersion() == net::HttpVersion(1, 1))
774 version = WebURLResponse::HTTP_1_1;
775 response->setHTTPVersion(version);
776 response->setHTTPStatusCode(headers->response_code());
777 response->setHTTPStatusText(WebString::fromLatin1(headers->GetStatusText()));
778
779 // TODO(darin): We should leverage HttpResponseHeaders for this, and this
780 // should be using the same code as ResourceDispatcherHost.
781 // TODO(jungshik): Figure out the actual value of the referrer charset and
782 // pass it to GetSuggestedFilename.
783 std::string value;
784 headers->EnumerateHeader(NULL, "content-disposition", &value);
785 response->setSuggestedFileName(
786 net::GetSuggestedFilename(url,
787 value,
788 std::string(), // referrer_charset
789 std::string(), // suggested_name
790 std::string(), // mime_type
791 std::string())); // default_name
792
793 Time time_val;
794 if (headers->GetLastModifiedValue(&time_val))
795 response->setLastModifiedDate(time_val.ToDoubleT());
796
797 // Build up the header map.
798 void* iter = NULL;
799 std::string name;
800 while (headers->EnumerateHeaderLines(&iter, &name, &value)) {
801 response->addHTTPHeaderField(WebString::fromLatin1(name),
802 WebString::fromLatin1(value));
803 }
804 }
805
807 void WebURLLoaderImpl::loadSynchronously(const WebURLRequest& request, 806 void WebURLLoaderImpl::loadSynchronously(const WebURLRequest& request,
808 WebURLResponse& response, 807 WebURLResponse& response,
809 WebURLError& error, 808 WebURLError& error,
810 WebData& data) { 809 WebData& data) {
811 ResourceLoaderBridge::SyncLoadResponse sync_load_response; 810 ResourceLoaderBridge::SyncLoadResponse sync_load_response;
812 context_->Start(request, &sync_load_response, platform_); 811 context_->Start(request, &sync_load_response, platform_);
813 812
814 const GURL& final_url = sync_load_response.url; 813 const GURL& final_url = sync_load_response.url;
815 814
816 // TODO(tc): For file loads, we may want to include a more descriptive 815 // TODO(tc): For file loads, we may want to include a more descriptive
(...skipping 27 matching lines...) Expand all
844 843
845 void WebURLLoaderImpl::setDefersLoading(bool value) { 844 void WebURLLoaderImpl::setDefersLoading(bool value) {
846 context_->SetDefersLoading(value); 845 context_->SetDefersLoading(value);
847 } 846 }
848 847
849 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority) { 848 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority) {
850 context_->DidChangePriority(new_priority); 849 context_->DidChangePriority(new_priority);
851 } 850 }
852 851
853 } // namespace webkit_glue 852 } // namespace webkit_glue
OLDNEW
« content/renderer/npapi/webplugin_impl.cc ('K') | « webkit/child/weburlloader_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698