Chromium Code Reviews| 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/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 ResourceResponseInfo* info, | 113 ResourceResponseInfo* info, |
| 114 std::string* data, | 114 std::string* data, |
| 115 net::URLRequestStatus* status) { | 115 net::URLRequestStatus* status) { |
| 116 std::string mime_type; | 116 std::string mime_type; |
| 117 std::string charset; | 117 std::string charset; |
| 118 if (net::DataURL::Parse(url, &mime_type, &charset, data)) { | 118 if (net::DataURL::Parse(url, &mime_type, &charset, data)) { |
| 119 *status = net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0); | 119 *status = net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0); |
| 120 // Assure same time for all time fields of data: URLs. | 120 // Assure same time for all time fields of data: URLs. |
| 121 Time now = Time::Now(); | 121 Time now = Time::Now(); |
| 122 info->load_timing.base_time = now; | 122 info->load_timing.base_time = now; |
| 123 info->load_timing.base_ticks = base::TimeTicks::Now(); | |
| 123 info->request_time = now; | 124 info->request_time = now; |
| 124 info->response_time = now; | 125 info->response_time = now; |
| 125 info->headers = NULL; | 126 info->headers = NULL; |
| 126 info->mime_type.swap(mime_type); | 127 info->mime_type.swap(mime_type); |
| 127 info->charset.swap(charset); | 128 info->charset.swap(charset); |
| 128 info->security_info.clear(); | 129 info->security_info.clear(); |
| 129 info->content_length = -1; | 130 info->content_length = -1; |
| 130 info->encoded_data_length = 0; | 131 info->encoded_data_length = 0; |
| 131 | 132 |
| 132 return true; | 133 return true; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 162 WebString::fromUTF8(info.socket_address.host())); | 163 WebString::fromUTF8(info.socket_address.host())); |
| 163 response->setRemotePort(info.socket_address.port()); | 164 response->setRemotePort(info.socket_address.port()); |
| 164 response->setConnectionID(info.connection_id); | 165 response->setConnectionID(info.connection_id); |
| 165 response->setConnectionReused(info.connection_reused); | 166 response->setConnectionReused(info.connection_reused); |
| 166 response->setDownloadFilePath(FilePathToWebString(info.download_file_path)); | 167 response->setDownloadFilePath(FilePathToWebString(info.download_file_path)); |
| 167 | 168 |
| 168 const ResourceLoadTimingInfo& timing_info = info.load_timing; | 169 const ResourceLoadTimingInfo& timing_info = info.load_timing; |
| 169 if (!timing_info.base_time.is_null()) { | 170 if (!timing_info.base_time.is_null()) { |
| 170 WebURLLoadTiming timing; | 171 WebURLLoadTiming timing; |
| 171 timing.initialize(); | 172 timing.initialize(); |
| 172 timing.setRequestTime(timing_info.base_time.ToDoubleT()); | 173 timing.setRequestTime( |
| 174 timing_info.base_ticks.ToInternalValue() / | |
| 175 static_cast<double>(base::Time::kMicrosecondsPerSecond)); | |
|
wtc
2011/08/26 23:39:15
Perhaps we should convert the base::TimeTicks to a
| |
| 173 timing.setProxyStart(timing_info.proxy_start); | 176 timing.setProxyStart(timing_info.proxy_start); |
| 174 timing.setProxyEnd(timing_info.proxy_end); | 177 timing.setProxyEnd(timing_info.proxy_end); |
| 175 timing.setDNSStart(timing_info.dns_start); | 178 timing.setDNSStart(timing_info.dns_start); |
| 176 timing.setDNSEnd(timing_info.dns_end); | 179 timing.setDNSEnd(timing_info.dns_end); |
| 177 timing.setConnectStart(timing_info.connect_start); | 180 timing.setConnectStart(timing_info.connect_start); |
| 178 timing.setConnectEnd(timing_info.connect_end); | 181 timing.setConnectEnd(timing_info.connect_end); |
| 179 timing.setSSLStart(timing_info.ssl_start); | 182 timing.setSSLStart(timing_info.ssl_start); |
| 180 timing.setSSLEnd(timing_info.ssl_end); | 183 timing.setSSLEnd(timing_info.ssl_end); |
| 181 timing.setSendStart(timing_info.send_start); | 184 timing.setSendStart(timing_info.send_start); |
| 182 timing.setSendEnd(timing_info.send_end); | 185 timing.setSendEnd(timing_info.send_end); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 bool* has_new_first_party_for_cookies, | 275 bool* has_new_first_party_for_cookies, |
| 273 GURL* new_first_party_for_cookies); | 276 GURL* new_first_party_for_cookies); |
| 274 virtual void OnReceivedResponse(const ResourceResponseInfo& info); | 277 virtual void OnReceivedResponse(const ResourceResponseInfo& info); |
| 275 virtual void OnDownloadedData(int len); | 278 virtual void OnDownloadedData(int len); |
| 276 virtual void OnReceivedData(const char* data, | 279 virtual void OnReceivedData(const char* data, |
| 277 int data_length, | 280 int data_length, |
| 278 int encoded_data_length); | 281 int encoded_data_length); |
| 279 virtual void OnReceivedCachedMetadata(const char* data, int len); | 282 virtual void OnReceivedCachedMetadata(const char* data, int len); |
| 280 virtual void OnCompletedRequest(const net::URLRequestStatus& status, | 283 virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
| 281 const std::string& security_info, | 284 const std::string& security_info, |
| 282 const base::Time& completion_time); | 285 const base::TimeTicks& completion_time); |
| 283 | 286 |
| 284 private: | 287 private: |
| 285 friend class base::RefCounted<Context>; | 288 friend class base::RefCounted<Context>; |
| 286 ~Context() {} | 289 ~Context() {} |
| 287 | 290 |
| 288 // We can optimize the handling of data URLs in most cases. | 291 // We can optimize the handling of data URLs in most cases. |
| 289 bool CanHandleDataURL(const GURL& url) const; | 292 bool CanHandleDataURL(const GURL& url) const; |
| 290 void HandleDataURL(); | 293 void HandleDataURL(); |
| 291 | 294 |
| 292 WebURLLoaderImpl* loader_; | 295 WebURLLoaderImpl* loader_; |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 587 | 590 |
| 588 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata( | 591 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata( |
| 589 const char* data, int len) { | 592 const char* data, int len) { |
| 590 if (client_) | 593 if (client_) |
| 591 client_->didReceiveCachedMetadata(loader_, data, len); | 594 client_->didReceiveCachedMetadata(loader_, data, len); |
| 592 } | 595 } |
| 593 | 596 |
| 594 void WebURLLoaderImpl::Context::OnCompletedRequest( | 597 void WebURLLoaderImpl::Context::OnCompletedRequest( |
| 595 const net::URLRequestStatus& status, | 598 const net::URLRequestStatus& status, |
| 596 const std::string& security_info, | 599 const std::string& security_info, |
| 597 const base::Time& completion_time) { | 600 const base::TimeTicks& completion_time) { |
| 598 if (ftp_listing_delegate_.get()) { | 601 if (ftp_listing_delegate_.get()) { |
| 599 ftp_listing_delegate_->OnCompletedRequest(); | 602 ftp_listing_delegate_->OnCompletedRequest(); |
| 600 ftp_listing_delegate_.reset(NULL); | 603 ftp_listing_delegate_.reset(NULL); |
| 601 } else if (multipart_delegate_.get()) { | 604 } else if (multipart_delegate_.get()) { |
| 602 multipart_delegate_->OnCompletedRequest(); | 605 multipart_delegate_->OnCompletedRequest(); |
| 603 multipart_delegate_.reset(NULL); | 606 multipart_delegate_.reset(NULL); |
| 604 } | 607 } |
| 605 | 608 |
| 606 // Prevent any further IPC to the browser now that we're complete, but | 609 // Prevent any further IPC to the browser now that we're complete, but |
| 607 // don't delete it to keep any downloaded temp files alive. | 610 // don't delete it to keep any downloaded temp files alive. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 619 error_code = status.os_error(); | 622 error_code = status.os_error(); |
| 620 } | 623 } |
| 621 WebURLError error; | 624 WebURLError error; |
| 622 if (error_code == net::ERR_ABORTED) | 625 if (error_code == net::ERR_ABORTED) |
| 623 error.isCancellation = true; | 626 error.isCancellation = true; |
| 624 error.domain = WebString::fromUTF8(net::kErrorDomain); | 627 error.domain = WebString::fromUTF8(net::kErrorDomain); |
| 625 error.reason = error_code; | 628 error.reason = error_code; |
| 626 error.unreachableURL = request_.url(); | 629 error.unreachableURL = request_.url(); |
| 627 client_->didFail(loader_, error); | 630 client_->didFail(loader_, error); |
| 628 } else { | 631 } else { |
| 629 client_->didFinishLoading(loader_, completion_time.ToDoubleT()); | 632 client_->didFinishLoading( |
| 633 loader_, completion_time.ToInternalValue() / | |
| 634 static_cast<double>(base::Time::kMicrosecondsPerSecond)); | |
| 630 } | 635 } |
| 631 } | 636 } |
| 632 | 637 |
| 633 // We are done with the bridge now, and so we need to release the reference | 638 // We are done with the bridge now, and so we need to release the reference |
| 634 // to ourselves that we took on behalf of the bridge. This may cause our | 639 // to ourselves that we took on behalf of the bridge. This may cause our |
| 635 // destruction. | 640 // destruction. |
| 636 Release(); | 641 Release(); |
| 637 } | 642 } |
| 638 | 643 |
| 639 bool WebURLLoaderImpl::Context::CanHandleDataURL(const GURL& url) const { | 644 bool WebURLLoaderImpl::Context::CanHandleDataURL(const GURL& url) const { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 663 ResourceResponseInfo info; | 668 ResourceResponseInfo info; |
| 664 net::URLRequestStatus status; | 669 net::URLRequestStatus status; |
| 665 std::string data; | 670 std::string data; |
| 666 | 671 |
| 667 if (GetInfoFromDataURL(request_.url(), &info, &data, &status)) { | 672 if (GetInfoFromDataURL(request_.url(), &info, &data, &status)) { |
| 668 OnReceivedResponse(info); | 673 OnReceivedResponse(info); |
| 669 if (!data.empty()) | 674 if (!data.empty()) |
| 670 OnReceivedData(data.data(), data.size(), 0); | 675 OnReceivedData(data.data(), data.size(), 0); |
| 671 } | 676 } |
| 672 | 677 |
| 673 OnCompletedRequest(status, info.security_info, base::Time::Now()); | 678 OnCompletedRequest(status, info.security_info, base::TimeTicks::Now()); |
| 674 } | 679 } |
| 675 | 680 |
| 676 // WebURLLoaderImpl ----------------------------------------------------------- | 681 // WebURLLoaderImpl ----------------------------------------------------------- |
| 677 | 682 |
| 678 WebURLLoaderImpl::WebURLLoaderImpl() | 683 WebURLLoaderImpl::WebURLLoaderImpl() |
| 679 : ALLOW_THIS_IN_INITIALIZER_LIST(context_(new Context(this))) { | 684 : ALLOW_THIS_IN_INITIALIZER_LIST(context_(new Context(this))) { |
| 680 } | 685 } |
| 681 | 686 |
| 682 WebURLLoaderImpl::~WebURLLoaderImpl() { | 687 WebURLLoaderImpl::~WebURLLoaderImpl() { |
| 683 cancel(); | 688 cancel(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 | 730 |
| 726 void WebURLLoaderImpl::setDefersLoading(bool value) { | 731 void WebURLLoaderImpl::setDefersLoading(bool value) { |
| 727 context_->SetDefersLoading(value); | 732 context_->SetDefersLoading(value); |
| 728 } | 733 } |
| 729 | 734 |
| 730 void WebURLLoaderImpl::UpdateRoutingId(int new_routing_id) { | 735 void WebURLLoaderImpl::UpdateRoutingId(int new_routing_id) { |
| 731 context_->UpdateRoutingId(new_routing_id); | 736 context_->UpdateRoutingId(new_routing_id); |
| 732 } | 737 } |
| 733 | 738 |
| 734 } // namespace webkit_glue | 739 } // namespace webkit_glue |
| OLD | NEW |