OLD | NEW |
1 // Copyright (c) 2010 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/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 return ResourceType::PREFETCH; | 139 return ResourceType::PREFETCH; |
140 default: | 140 default: |
141 NOTREACHED(); | 141 NOTREACHED(); |
142 return ResourceType::SUB_RESOURCE; | 142 return ResourceType::SUB_RESOURCE; |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 // Extracts the information from a data: url. | 146 // Extracts the information from a data: url. |
147 bool GetInfoFromDataURL(const GURL& url, | 147 bool GetInfoFromDataURL(const GURL& url, |
148 ResourceResponseInfo* info, | 148 ResourceResponseInfo* info, |
149 std::string* data, URLRequestStatus* status) { | 149 std::string* data, |
| 150 net::URLRequestStatus* status) { |
150 std::string mime_type; | 151 std::string mime_type; |
151 std::string charset; | 152 std::string charset; |
152 if (net::DataURL::Parse(url, &mime_type, &charset, data)) { | 153 if (net::DataURL::Parse(url, &mime_type, &charset, data)) { |
153 *status = URLRequestStatus(URLRequestStatus::SUCCESS, 0); | 154 *status = net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0); |
154 info->request_time = Time::Now(); | 155 info->request_time = Time::Now(); |
155 info->response_time = Time::Now(); | 156 info->response_time = Time::Now(); |
156 info->headers = NULL; | 157 info->headers = NULL; |
157 info->mime_type.swap(mime_type); | 158 info->mime_type.swap(mime_type); |
158 info->charset.swap(charset); | 159 info->charset.swap(charset); |
159 info->security_info.clear(); | 160 info->security_info.clear(); |
160 info->content_length = -1; | 161 info->content_length = -1; |
161 | 162 |
162 return true; | 163 return true; |
163 } | 164 } |
164 | 165 |
165 *status = URLRequestStatus(URLRequestStatus::FAILED, net::ERR_INVALID_URL); | 166 *status = net::URLRequestStatus(net::URLRequestStatus::FAILED, |
| 167 net::ERR_INVALID_URL); |
166 return false; | 168 return false; |
167 } | 169 } |
168 | 170 |
169 typedef ResourceDevToolsInfo::HeadersVector HeadersVector; | 171 typedef ResourceDevToolsInfo::HeadersVector HeadersVector; |
170 | 172 |
171 void PopulateURLResponse( | 173 void PopulateURLResponse( |
172 const GURL& url, | 174 const GURL& url, |
173 const ResourceResponseInfo& info, | 175 const ResourceResponseInfo& info, |
174 WebURLResponse* response) { | 176 WebURLResponse* response) { |
175 response->setURL(url); | 177 response->setURL(url); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 virtual bool OnReceivedRedirect( | 289 virtual bool OnReceivedRedirect( |
288 const GURL& new_url, | 290 const GURL& new_url, |
289 const ResourceResponseInfo& info, | 291 const ResourceResponseInfo& info, |
290 bool* has_new_first_party_for_cookies, | 292 bool* has_new_first_party_for_cookies, |
291 GURL* new_first_party_for_cookies); | 293 GURL* new_first_party_for_cookies); |
292 virtual void OnReceivedResponse( | 294 virtual void OnReceivedResponse( |
293 const ResourceResponseInfo& info, bool content_filtered); | 295 const ResourceResponseInfo& info, bool content_filtered); |
294 virtual void OnDownloadedData(int len); | 296 virtual void OnDownloadedData(int len); |
295 virtual void OnReceivedData(const char* data, int len); | 297 virtual void OnReceivedData(const char* data, int len); |
296 virtual void OnReceivedCachedMetadata(const char* data, int len); | 298 virtual void OnReceivedCachedMetadata(const char* data, int len); |
297 virtual void OnCompletedRequest( | 299 virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
298 const URLRequestStatus& status, | 300 const std::string& security_info, |
299 const std::string& security_info, | 301 const base::Time& completion_time); |
300 const base::Time& completion_time); | |
301 | 302 |
302 private: | 303 private: |
303 friend class base::RefCounted<Context>; | 304 friend class base::RefCounted<Context>; |
304 ~Context() {} | 305 ~Context() {} |
305 | 306 |
306 // We can optimize the handling of data URLs in most cases. | 307 // We can optimize the handling of data URLs in most cases. |
307 bool CanHandleDataURL(const GURL& url) const; | 308 bool CanHandleDataURL(const GURL& url) const; |
308 void HandleDataURL(); | 309 void HandleDataURL(); |
309 | 310 |
310 WebURLLoaderImpl* loader_; | 311 WebURLLoaderImpl* loader_; |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 } | 615 } |
615 } | 616 } |
616 | 617 |
617 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata( | 618 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata( |
618 const char* data, int len) { | 619 const char* data, int len) { |
619 if (client_) | 620 if (client_) |
620 client_->didReceiveCachedMetadata(loader_, data, len); | 621 client_->didReceiveCachedMetadata(loader_, data, len); |
621 } | 622 } |
622 | 623 |
623 void WebURLLoaderImpl::Context::OnCompletedRequest( | 624 void WebURLLoaderImpl::Context::OnCompletedRequest( |
624 const URLRequestStatus& status, | 625 const net::URLRequestStatus& status, |
625 const std::string& security_info, | 626 const std::string& security_info, |
626 const base::Time& completion_time) { | 627 const base::Time& completion_time) { |
627 if (ftp_listing_delegate_.get()) { | 628 if (ftp_listing_delegate_.get()) { |
628 ftp_listing_delegate_->OnCompletedRequest(); | 629 ftp_listing_delegate_->OnCompletedRequest(); |
629 ftp_listing_delegate_.reset(NULL); | 630 ftp_listing_delegate_.reset(NULL); |
630 } else if (multipart_delegate_.get()) { | 631 } else if (multipart_delegate_.get()) { |
631 multipart_delegate_->OnCompletedRequest(); | 632 multipart_delegate_->OnCompletedRequest(); |
632 multipart_delegate_.reset(NULL); | 633 multipart_delegate_.reset(NULL); |
633 } | 634 } |
634 | 635 |
635 // Prevent any further IPC to the browser now that we're complete, but | 636 // Prevent any further IPC to the browser now that we're complete, but |
636 // don't delete it to keep any downloaded temp files alive. | 637 // don't delete it to keep any downloaded temp files alive. |
637 DCHECK(!completed_bridge_.get()); | 638 DCHECK(!completed_bridge_.get()); |
638 completed_bridge_.swap(bridge_); | 639 completed_bridge_.swap(bridge_); |
639 | 640 |
640 if (client_) { | 641 if (client_) { |
641 if (status.status() != URLRequestStatus::SUCCESS) { | 642 if (status.status() != net::URLRequestStatus::SUCCESS) { |
642 int error_code; | 643 int error_code; |
643 if (status.status() == URLRequestStatus::HANDLED_EXTERNALLY) { | 644 if (status.status() == net::URLRequestStatus::HANDLED_EXTERNALLY) { |
644 // By marking this request as aborted we insure that we don't navigate | 645 // By marking this request as aborted we insure that we don't navigate |
645 // to an error page. | 646 // to an error page. |
646 error_code = net::ERR_ABORTED; | 647 error_code = net::ERR_ABORTED; |
647 } else { | 648 } else { |
648 error_code = status.os_error(); | 649 error_code = status.os_error(); |
649 } | 650 } |
650 WebURLError error; | 651 WebURLError error; |
651 error.domain = WebString::fromUTF8(net::kErrorDomain); | 652 error.domain = WebString::fromUTF8(net::kErrorDomain); |
652 error.reason = error_code; | 653 error.reason = error_code; |
653 error.unreachableURL = request_.url(); | 654 error.unreachableURL = request_.url(); |
(...skipping 30 matching lines...) Expand all Loading... |
684 std::string mime_type, unused_charset; | 685 std::string mime_type, unused_charset; |
685 if (net::DataURL::Parse(url, &mime_type, &unused_charset, NULL) && | 686 if (net::DataURL::Parse(url, &mime_type, &unused_charset, NULL) && |
686 net::IsSupportedMimeType(mime_type)) | 687 net::IsSupportedMimeType(mime_type)) |
687 return true; | 688 return true; |
688 | 689 |
689 return false; | 690 return false; |
690 } | 691 } |
691 | 692 |
692 void WebURLLoaderImpl::Context::HandleDataURL() { | 693 void WebURLLoaderImpl::Context::HandleDataURL() { |
693 ResourceResponseInfo info; | 694 ResourceResponseInfo info; |
694 URLRequestStatus status; | 695 net::URLRequestStatus status; |
695 std::string data; | 696 std::string data; |
696 | 697 |
697 if (GetInfoFromDataURL(request_.url(), &info, &data, &status)) { | 698 if (GetInfoFromDataURL(request_.url(), &info, &data, &status)) { |
698 OnReceivedResponse(info, false); | 699 OnReceivedResponse(info, false); |
699 if (!data.empty()) | 700 if (!data.empty()) |
700 OnReceivedData(data.data(), data.size()); | 701 OnReceivedData(data.data(), data.size()); |
701 } | 702 } |
702 | 703 |
703 OnCompletedRequest(status, info.security_info, base::Time::Now()); | 704 OnCompletedRequest(status, info.security_info, base::Time::Now()); |
704 } | 705 } |
(...skipping 12 matching lines...) Expand all Loading... |
717 WebURLResponse& response, | 718 WebURLResponse& response, |
718 WebURLError& error, | 719 WebURLError& error, |
719 WebData& data) { | 720 WebData& data) { |
720 ResourceLoaderBridge::SyncLoadResponse sync_load_response; | 721 ResourceLoaderBridge::SyncLoadResponse sync_load_response; |
721 context_->Start(request, &sync_load_response); | 722 context_->Start(request, &sync_load_response); |
722 | 723 |
723 const GURL& final_url = sync_load_response.url; | 724 const GURL& final_url = sync_load_response.url; |
724 | 725 |
725 // TODO(tc): For file loads, we may want to include a more descriptive | 726 // TODO(tc): For file loads, we may want to include a more descriptive |
726 // status code or status text. | 727 // status code or status text. |
727 const URLRequestStatus::Status& status = sync_load_response.status.status(); | 728 const net::URLRequestStatus::Status& status = |
728 if (status != URLRequestStatus::SUCCESS && | 729 sync_load_response.status.status(); |
729 status != URLRequestStatus::HANDLED_EXTERNALLY) { | 730 if (status != net::URLRequestStatus::SUCCESS && |
| 731 status != net::URLRequestStatus::HANDLED_EXTERNALLY) { |
730 response.setURL(final_url); | 732 response.setURL(final_url); |
731 error.domain = WebString::fromUTF8(net::kErrorDomain); | 733 error.domain = WebString::fromUTF8(net::kErrorDomain); |
732 error.reason = sync_load_response.status.os_error(); | 734 error.reason = sync_load_response.status.os_error(); |
733 error.unreachableURL = final_url; | 735 error.unreachableURL = final_url; |
734 return; | 736 return; |
735 } | 737 } |
736 | 738 |
737 PopulateURLResponse(final_url, sync_load_response, &response); | 739 PopulateURLResponse(final_url, sync_load_response, &response); |
738 | 740 |
739 data.assign(sync_load_response.data.data(), | 741 data.assign(sync_load_response.data.data(), |
(...skipping 10 matching lines...) Expand all Loading... |
750 | 752 |
751 void WebURLLoaderImpl::cancel() { | 753 void WebURLLoaderImpl::cancel() { |
752 context_->Cancel(); | 754 context_->Cancel(); |
753 } | 755 } |
754 | 756 |
755 void WebURLLoaderImpl::setDefersLoading(bool value) { | 757 void WebURLLoaderImpl::setDefersLoading(bool value) { |
756 context_->SetDefersLoading(value); | 758 context_->SetDefersLoading(value); |
757 } | 759 } |
758 | 760 |
759 } // namespace webkit_glue | 761 } // namespace webkit_glue |
OLD | NEW |