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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 std::string charset; | 150 std::string charset; |
151 if (net::DataURL::Parse(url, &mime_type, &charset, data)) { | 151 if (net::DataURL::Parse(url, &mime_type, &charset, data)) { |
152 *status = net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0); | 152 *status = net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0); |
153 info->request_time = Time::Now(); | 153 info->request_time = Time::Now(); |
154 info->response_time = Time::Now(); | 154 info->response_time = Time::Now(); |
155 info->headers = NULL; | 155 info->headers = NULL; |
156 info->mime_type.swap(mime_type); | 156 info->mime_type.swap(mime_type); |
157 info->charset.swap(charset); | 157 info->charset.swap(charset); |
158 info->security_info.clear(); | 158 info->security_info.clear(); |
159 info->content_length = -1; | 159 info->content_length = -1; |
| 160 info->raw_data_length = 0; |
160 info->load_timing.base_time = Time::Now(); | 161 info->load_timing.base_time = Time::Now(); |
161 | 162 |
162 return true; | 163 return true; |
163 } | 164 } |
164 | 165 |
165 *status = net::URLRequestStatus(net::URLRequestStatus::FAILED, | 166 *status = net::URLRequestStatus(net::URLRequestStatus::FAILED, |
166 net::ERR_INVALID_URL); | 167 net::ERR_INVALID_URL); |
167 return false; | 168 return false; |
168 } | 169 } |
169 | 170 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 | 289 |
289 // ResourceLoaderBridge::Peer methods: | 290 // ResourceLoaderBridge::Peer methods: |
290 virtual void OnUploadProgress(uint64 position, uint64 size); | 291 virtual void OnUploadProgress(uint64 position, uint64 size); |
291 virtual bool OnReceivedRedirect( | 292 virtual bool OnReceivedRedirect( |
292 const GURL& new_url, | 293 const GURL& new_url, |
293 const ResourceResponseInfo& info, | 294 const ResourceResponseInfo& info, |
294 bool* has_new_first_party_for_cookies, | 295 bool* has_new_first_party_for_cookies, |
295 GURL* new_first_party_for_cookies); | 296 GURL* new_first_party_for_cookies); |
296 virtual void OnReceivedResponse(const ResourceResponseInfo& info); | 297 virtual void OnReceivedResponse(const ResourceResponseInfo& info); |
297 virtual void OnDownloadedData(int len); | 298 virtual void OnDownloadedData(int len); |
298 virtual void OnReceivedData(const char* data, int len); | 299 virtual void OnReceivedData(const char* data, |
| 300 int data_length, |
| 301 int raw_data_length); |
299 virtual void OnReceivedCachedMetadata(const char* data, int len); | 302 virtual void OnReceivedCachedMetadata(const char* data, int len); |
300 virtual void OnCompletedRequest(const net::URLRequestStatus& status, | 303 virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
301 const std::string& security_info, | 304 const std::string& security_info, |
302 const base::Time& completion_time); | 305 const base::Time& completion_time); |
303 | 306 |
304 private: | 307 private: |
305 friend class base::RefCounted<Context>; | 308 friend class base::RefCounted<Context>; |
306 ~Context() {} | 309 ~Context() {} |
307 | 310 |
308 // We can optimize the handling of data URLs in most cases. | 311 // We can optimize the handling of data URLs in most cases. |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 } | 587 } |
585 | 588 |
586 response_url_ = response.url(); | 589 response_url_ = response.url(); |
587 } | 590 } |
588 | 591 |
589 void WebURLLoaderImpl::Context::OnDownloadedData(int len) { | 592 void WebURLLoaderImpl::Context::OnDownloadedData(int len) { |
590 if (client_) | 593 if (client_) |
591 client_->didDownloadData(loader_, len); | 594 client_->didDownloadData(loader_, len); |
592 } | 595 } |
593 | 596 |
594 void WebURLLoaderImpl::Context::OnReceivedData(const char* data, int len) { | 597 void WebURLLoaderImpl::Context::OnReceivedData(const char* data, |
| 598 int data_length, |
| 599 int raw_data_length) { |
595 if (!client_) | 600 if (!client_) |
596 return; | 601 return; |
597 | 602 |
598 // Temporary logging, see site_isolation_metrics.h/cc. | 603 // Temporary logging, see site_isolation_metrics.h/cc. |
599 SiteIsolationMetrics::SniffCrossOriginHTML(response_url_, data, len); | 604 SiteIsolationMetrics::SniffCrossOriginHTML(response_url_, data, data_length); |
600 | 605 |
601 if (ftp_listing_delegate_.get()) { | 606 if (ftp_listing_delegate_.get()) { |
602 // The FTP listing delegate will make the appropriate calls to | 607 // The FTP listing delegate will make the appropriate calls to |
603 // client_->didReceiveData and client_->didReceiveResponse. | 608 // client_->didReceiveData and client_->didReceiveResponse. |
604 ftp_listing_delegate_->OnReceivedData(data, len); | 609 ftp_listing_delegate_->OnReceivedData(data, data_length); |
605 } else if (multipart_delegate_.get()) { | 610 } else if (multipart_delegate_.get()) { |
606 // The multipart delegate will make the appropriate calls to | 611 // The multipart delegate will make the appropriate calls to |
607 // client_->didReceiveData and client_->didReceiveResponse. | 612 // client_->didReceiveData and client_->didReceiveResponse. |
608 multipart_delegate_->OnReceivedData(data, len); | 613 multipart_delegate_->OnReceivedData(data, data_length, raw_data_length); |
609 } else { | 614 } else { |
610 client_->didReceiveData(loader_, data, len, -1); | 615 client_->didReceiveData(loader_, data, data_length, raw_data_length); |
611 } | 616 } |
612 } | 617 } |
613 | 618 |
614 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata( | 619 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata( |
615 const char* data, int len) { | 620 const char* data, int len) { |
616 if (client_) | 621 if (client_) |
617 client_->didReceiveCachedMetadata(loader_, data, len); | 622 client_->didReceiveCachedMetadata(loader_, data, len); |
618 } | 623 } |
619 | 624 |
620 void WebURLLoaderImpl::Context::OnCompletedRequest( | 625 void WebURLLoaderImpl::Context::OnCompletedRequest( |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 } | 692 } |
688 | 693 |
689 void WebURLLoaderImpl::Context::HandleDataURL() { | 694 void WebURLLoaderImpl::Context::HandleDataURL() { |
690 ResourceResponseInfo info; | 695 ResourceResponseInfo info; |
691 net::URLRequestStatus status; | 696 net::URLRequestStatus status; |
692 std::string data; | 697 std::string data; |
693 | 698 |
694 if (GetInfoFromDataURL(request_.url(), &info, &data, &status)) { | 699 if (GetInfoFromDataURL(request_.url(), &info, &data, &status)) { |
695 OnReceivedResponse(info); | 700 OnReceivedResponse(info); |
696 if (!data.empty()) | 701 if (!data.empty()) |
697 OnReceivedData(data.data(), data.size()); | 702 OnReceivedData(data.data(), data.size(), 0); |
698 } | 703 } |
699 | 704 |
700 OnCompletedRequest(status, info.security_info, base::Time::Now()); | 705 OnCompletedRequest(status, info.security_info, base::Time::Now()); |
701 } | 706 } |
702 | 707 |
703 // WebURLLoaderImpl ----------------------------------------------------------- | 708 // WebURLLoaderImpl ----------------------------------------------------------- |
704 | 709 |
705 WebURLLoaderImpl::WebURLLoaderImpl() | 710 WebURLLoaderImpl::WebURLLoaderImpl() |
706 : ALLOW_THIS_IN_INITIALIZER_LIST(context_(new Context(this))) { | 711 : ALLOW_THIS_IN_INITIALIZER_LIST(context_(new Context(this))) { |
707 } | 712 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 | 753 |
749 void WebURLLoaderImpl::cancel() { | 754 void WebURLLoaderImpl::cancel() { |
750 context_->Cancel(); | 755 context_->Cancel(); |
751 } | 756 } |
752 | 757 |
753 void WebURLLoaderImpl::setDefersLoading(bool value) { | 758 void WebURLLoaderImpl::setDefersLoading(bool value) { |
754 context_->SetDefersLoading(value); | 759 context_->SetDefersLoading(value); |
755 } | 760 } |
756 | 761 |
757 } // namespace webkit_glue | 762 } // namespace webkit_glue |
OLD | NEW |