OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/glue/weburlloader_impl.h" | 7 #include "webkit/glue/weburlloader_impl.h" |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon
se.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon
se.h" |
31 #include "webkit/glue/ftp_directory_listing_response_delegate.h" | 31 #include "webkit/glue/ftp_directory_listing_response_delegate.h" |
32 #include "webkit/glue/multipart_response_delegate.h" | 32 #include "webkit/glue/multipart_response_delegate.h" |
33 #include "webkit/glue/resource_loader_bridge.h" | 33 #include "webkit/glue/resource_loader_bridge.h" |
34 #include "webkit/glue/webkit_glue.h" | 34 #include "webkit/glue/webkit_glue.h" |
35 #include "webkit/glue/webkitplatformsupport_impl.h" | 35 #include "webkit/glue/webkitplatformsupport_impl.h" |
36 #include "webkit/glue/weburlrequest_extradata_impl.h" | 36 #include "webkit/glue/weburlrequest_extradata_impl.h" |
37 | 37 |
38 using base::Time; | 38 using base::Time; |
39 using base::TimeDelta; | 39 using base::TimeTicks; |
40 using WebKit::WebData; | 40 using WebKit::WebData; |
41 using WebKit::WebHTTPBody; | 41 using WebKit::WebHTTPBody; |
42 using WebKit::WebHTTPHeaderVisitor; | 42 using WebKit::WebHTTPHeaderVisitor; |
43 using WebKit::WebHTTPLoadInfo; | 43 using WebKit::WebHTTPLoadInfo; |
44 using WebKit::WebReferrerPolicy; | 44 using WebKit::WebReferrerPolicy; |
45 using WebKit::WebSecurityPolicy; | 45 using WebKit::WebSecurityPolicy; |
46 using WebKit::WebString; | 46 using WebKit::WebString; |
47 using WebKit::WebURL; | 47 using WebKit::WebURL; |
48 using WebKit::WebURLError; | 48 using WebKit::WebURLError; |
49 using WebKit::WebURLLoadTiming; | 49 using WebKit::WebURLLoadTiming; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 ResourceResponseInfo* info, | 117 ResourceResponseInfo* info, |
118 std::string* data, | 118 std::string* data, |
119 net::URLRequestStatus* status) { | 119 net::URLRequestStatus* status) { |
120 std::string mime_type; | 120 std::string mime_type; |
121 std::string charset; | 121 std::string charset; |
122 if (net::DataURL::Parse(url, &mime_type, &charset, data)) { | 122 if (net::DataURL::Parse(url, &mime_type, &charset, data)) { |
123 *status = net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0); | 123 *status = net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0); |
124 // Assure same time for all time fields of data: URLs. | 124 // Assure same time for all time fields of data: URLs. |
125 Time now = Time::Now(); | 125 Time now = Time::Now(); |
126 info->load_timing.base_time = now; | 126 info->load_timing.base_time = now; |
| 127 info->load_timing.base_ticks = TimeTicks::Now(); |
127 info->request_time = now; | 128 info->request_time = now; |
128 info->response_time = now; | 129 info->response_time = now; |
129 info->headers = NULL; | 130 info->headers = NULL; |
130 info->mime_type.swap(mime_type); | 131 info->mime_type.swap(mime_type); |
131 info->charset.swap(charset); | 132 info->charset.swap(charset); |
132 info->security_info.clear(); | 133 info->security_info.clear(); |
133 info->content_length = -1; | 134 info->content_length = -1; |
134 info->encoded_data_length = 0; | 135 info->encoded_data_length = 0; |
135 | 136 |
136 return true; | 137 return true; |
(...skipping 29 matching lines...) Expand all Loading... |
166 WebString::fromUTF8(info.socket_address.host())); | 167 WebString::fromUTF8(info.socket_address.host())); |
167 response->setRemotePort(info.socket_address.port()); | 168 response->setRemotePort(info.socket_address.port()); |
168 response->setConnectionID(info.connection_id); | 169 response->setConnectionID(info.connection_id); |
169 response->setConnectionReused(info.connection_reused); | 170 response->setConnectionReused(info.connection_reused); |
170 response->setDownloadFilePath(FilePathToWebString(info.download_file_path)); | 171 response->setDownloadFilePath(FilePathToWebString(info.download_file_path)); |
171 | 172 |
172 const ResourceLoadTimingInfo& timing_info = info.load_timing; | 173 const ResourceLoadTimingInfo& timing_info = info.load_timing; |
173 if (!timing_info.base_time.is_null()) { | 174 if (!timing_info.base_time.is_null()) { |
174 WebURLLoadTiming timing; | 175 WebURLLoadTiming timing; |
175 timing.initialize(); | 176 timing.initialize(); |
176 timing.setRequestTime(timing_info.base_time.ToDoubleT()); | 177 timing.setRequestTime((timing_info.base_ticks - TimeTicks()).InSecondsF()); |
177 timing.setProxyStart(timing_info.proxy_start); | 178 timing.setProxyStart(timing_info.proxy_start); |
178 timing.setProxyEnd(timing_info.proxy_end); | 179 timing.setProxyEnd(timing_info.proxy_end); |
179 timing.setDNSStart(timing_info.dns_start); | 180 timing.setDNSStart(timing_info.dns_start); |
180 timing.setDNSEnd(timing_info.dns_end); | 181 timing.setDNSEnd(timing_info.dns_end); |
181 timing.setConnectStart(timing_info.connect_start); | 182 timing.setConnectStart(timing_info.connect_start); |
182 timing.setConnectEnd(timing_info.connect_end); | 183 timing.setConnectEnd(timing_info.connect_end); |
183 timing.setSSLStart(timing_info.ssl_start); | 184 timing.setSSLStart(timing_info.ssl_start); |
184 timing.setSSLEnd(timing_info.ssl_end); | 185 timing.setSSLEnd(timing_info.ssl_end); |
185 timing.setSendStart(timing_info.send_start); | 186 timing.setSendStart(timing_info.send_start); |
186 timing.setSendEnd(timing_info.send_end); | 187 timing.setSendEnd(timing_info.send_end); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 bool* has_new_first_party_for_cookies, | 278 bool* has_new_first_party_for_cookies, |
278 GURL* new_first_party_for_cookies); | 279 GURL* new_first_party_for_cookies); |
279 virtual void OnReceivedResponse(const ResourceResponseInfo& info); | 280 virtual void OnReceivedResponse(const ResourceResponseInfo& info); |
280 virtual void OnDownloadedData(int len); | 281 virtual void OnDownloadedData(int len); |
281 virtual void OnReceivedData(const char* data, | 282 virtual void OnReceivedData(const char* data, |
282 int data_length, | 283 int data_length, |
283 int encoded_data_length); | 284 int encoded_data_length); |
284 virtual void OnReceivedCachedMetadata(const char* data, int len); | 285 virtual void OnReceivedCachedMetadata(const char* data, int len); |
285 virtual void OnCompletedRequest(const net::URLRequestStatus& status, | 286 virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
286 const std::string& security_info, | 287 const std::string& security_info, |
287 const base::Time& completion_time); | 288 const base::TimeTicks& completion_time); |
288 | 289 |
289 private: | 290 private: |
290 friend class base::RefCounted<Context>; | 291 friend class base::RefCounted<Context>; |
291 ~Context() {} | 292 ~Context() {} |
292 | 293 |
293 // We can optimize the handling of data URLs in most cases. | 294 // We can optimize the handling of data URLs in most cases. |
294 bool CanHandleDataURL(const GURL& url) const; | 295 bool CanHandleDataURL(const GURL& url) const; |
295 void HandleDataURL(); | 296 void HandleDataURL(); |
296 | 297 |
297 WebURLLoaderImpl* loader_; | 298 WebURLLoaderImpl* loader_; |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 | 604 |
604 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata( | 605 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata( |
605 const char* data, int len) { | 606 const char* data, int len) { |
606 if (client_) | 607 if (client_) |
607 client_->didReceiveCachedMetadata(loader_, data, len); | 608 client_->didReceiveCachedMetadata(loader_, data, len); |
608 } | 609 } |
609 | 610 |
610 void WebURLLoaderImpl::Context::OnCompletedRequest( | 611 void WebURLLoaderImpl::Context::OnCompletedRequest( |
611 const net::URLRequestStatus& status, | 612 const net::URLRequestStatus& status, |
612 const std::string& security_info, | 613 const std::string& security_info, |
613 const base::Time& completion_time) { | 614 const base::TimeTicks& completion_time) { |
614 if (ftp_listing_delegate_.get()) { | 615 if (ftp_listing_delegate_.get()) { |
615 ftp_listing_delegate_->OnCompletedRequest(); | 616 ftp_listing_delegate_->OnCompletedRequest(); |
616 ftp_listing_delegate_.reset(NULL); | 617 ftp_listing_delegate_.reset(NULL); |
617 } else if (multipart_delegate_.get()) { | 618 } else if (multipart_delegate_.get()) { |
618 multipart_delegate_->OnCompletedRequest(); | 619 multipart_delegate_->OnCompletedRequest(); |
619 multipart_delegate_.reset(NULL); | 620 multipart_delegate_.reset(NULL); |
620 } | 621 } |
621 | 622 |
622 // Prevent any further IPC to the browser now that we're complete, but | 623 // Prevent any further IPC to the browser now that we're complete, but |
623 // don't delete it to keep any downloaded temp files alive. | 624 // don't delete it to keep any downloaded temp files alive. |
(...skipping 11 matching lines...) Expand all Loading... |
635 error_code = status.error(); | 636 error_code = status.error(); |
636 } | 637 } |
637 WebURLError error; | 638 WebURLError error; |
638 if (error_code == net::ERR_ABORTED) | 639 if (error_code == net::ERR_ABORTED) |
639 error.isCancellation = true; | 640 error.isCancellation = true; |
640 error.domain = WebString::fromUTF8(net::kErrorDomain); | 641 error.domain = WebString::fromUTF8(net::kErrorDomain); |
641 error.reason = error_code; | 642 error.reason = error_code; |
642 error.unreachableURL = request_.url(); | 643 error.unreachableURL = request_.url(); |
643 client_->didFail(loader_, error); | 644 client_->didFail(loader_, error); |
644 } else { | 645 } else { |
645 client_->didFinishLoading(loader_, completion_time.ToDoubleT()); | 646 client_->didFinishLoading( |
| 647 loader_, (completion_time - TimeTicks()).InSecondsF()); |
646 } | 648 } |
647 } | 649 } |
648 | 650 |
649 // We are done with the bridge now, and so we need to release the reference | 651 // We are done with the bridge now, and so we need to release the reference |
650 // to ourselves that we took on behalf of the bridge. This may cause our | 652 // to ourselves that we took on behalf of the bridge. This may cause our |
651 // destruction. | 653 // destruction. |
652 Release(); | 654 Release(); |
653 } | 655 } |
654 | 656 |
655 bool WebURLLoaderImpl::Context::CanHandleDataURL(const GURL& url) const { | 657 bool WebURLLoaderImpl::Context::CanHandleDataURL(const GURL& url) const { |
(...skipping 23 matching lines...) Expand all Loading... |
679 ResourceResponseInfo info; | 681 ResourceResponseInfo info; |
680 net::URLRequestStatus status; | 682 net::URLRequestStatus status; |
681 std::string data; | 683 std::string data; |
682 | 684 |
683 if (GetInfoFromDataURL(request_.url(), &info, &data, &status)) { | 685 if (GetInfoFromDataURL(request_.url(), &info, &data, &status)) { |
684 OnReceivedResponse(info); | 686 OnReceivedResponse(info); |
685 if (!data.empty()) | 687 if (!data.empty()) |
686 OnReceivedData(data.data(), data.size(), 0); | 688 OnReceivedData(data.data(), data.size(), 0); |
687 } | 689 } |
688 | 690 |
689 OnCompletedRequest(status, info.security_info, base::Time::Now()); | 691 OnCompletedRequest(status, info.security_info, base::TimeTicks::Now()); |
690 } | 692 } |
691 | 693 |
692 // WebURLLoaderImpl ----------------------------------------------------------- | 694 // WebURLLoaderImpl ----------------------------------------------------------- |
693 | 695 |
694 WebURLLoaderImpl::WebURLLoaderImpl(WebKitPlatformSupportImpl* platform) | 696 WebURLLoaderImpl::WebURLLoaderImpl(WebKitPlatformSupportImpl* platform) |
695 : ALLOW_THIS_IN_INITIALIZER_LIST(context_(new Context(this))), | 697 : ALLOW_THIS_IN_INITIALIZER_LIST(context_(new Context(this))), |
696 platform_(platform) { | 698 platform_(platform) { |
697 } | 699 } |
698 | 700 |
699 WebURLLoaderImpl::~WebURLLoaderImpl() { | 701 WebURLLoaderImpl::~WebURLLoaderImpl() { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 | 744 |
743 void WebURLLoaderImpl::setDefersLoading(bool value) { | 745 void WebURLLoaderImpl::setDefersLoading(bool value) { |
744 context_->SetDefersLoading(value); | 746 context_->SetDefersLoading(value); |
745 } | 747 } |
746 | 748 |
747 void WebURLLoaderImpl::UpdateRoutingId(int new_routing_id) { | 749 void WebURLLoaderImpl::UpdateRoutingId(int new_routing_id) { |
748 context_->UpdateRoutingId(new_routing_id); | 750 context_->UpdateRoutingId(new_routing_id); |
749 } | 751 } |
750 | 752 |
751 } // namespace webkit_glue | 753 } // namespace webkit_glue |
OLD | NEW |