OLD | NEW |
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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 GURL* new_first_party_for_cookies) OVERRIDE; | 238 GURL* new_first_party_for_cookies) OVERRIDE; |
239 virtual void OnReceivedResponse(const ResourceResponseInfo& info) OVERRIDE; | 239 virtual void OnReceivedResponse(const ResourceResponseInfo& info) OVERRIDE; |
240 virtual void OnDownloadedData(int len, int encoded_data_length) OVERRIDE; | 240 virtual void OnDownloadedData(int len, int encoded_data_length) OVERRIDE; |
241 virtual void OnReceivedData(const char* data, | 241 virtual void OnReceivedData(const char* data, |
242 int data_length, | 242 int data_length, |
243 int encoded_data_length) OVERRIDE; | 243 int encoded_data_length) OVERRIDE; |
244 virtual void OnReceivedCachedMetadata(const char* data, int len) OVERRIDE; | 244 virtual void OnReceivedCachedMetadata(const char* data, int len) OVERRIDE; |
245 virtual void OnCompletedRequest( | 245 virtual void OnCompletedRequest( |
246 int error_code, | 246 int error_code, |
247 bool was_ignored_by_handler, | 247 bool was_ignored_by_handler, |
| 248 bool stale_copy_in_cache, |
248 const std::string& security_info, | 249 const std::string& security_info, |
249 const base::TimeTicks& completion_time) OVERRIDE; | 250 const base::TimeTicks& completion_time) OVERRIDE; |
250 | 251 |
251 private: | 252 private: |
252 friend class base::RefCounted<Context>; | 253 friend class base::RefCounted<Context>; |
253 virtual ~Context() {} | 254 virtual ~Context() {} |
254 | 255 |
255 // We can optimize the handling of data URLs in most cases. | 256 // We can optimize the handling of data URLs in most cases. |
256 bool CanHandleDataURL(const GURL& url) const; | 257 bool CanHandleDataURL(const GURL& url) const; |
257 void HandleDataURL(); | 258 void HandleDataURL(); |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 | 592 |
592 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata( | 593 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata( |
593 const char* data, int len) { | 594 const char* data, int len) { |
594 if (client_) | 595 if (client_) |
595 client_->didReceiveCachedMetadata(loader_, data, len); | 596 client_->didReceiveCachedMetadata(loader_, data, len); |
596 } | 597 } |
597 | 598 |
598 void WebURLLoaderImpl::Context::OnCompletedRequest( | 599 void WebURLLoaderImpl::Context::OnCompletedRequest( |
599 int error_code, | 600 int error_code, |
600 bool was_ignored_by_handler, | 601 bool was_ignored_by_handler, |
| 602 bool stale_copy_in_cache, |
601 const std::string& security_info, | 603 const std::string& security_info, |
602 const base::TimeTicks& completion_time) { | 604 const base::TimeTicks& completion_time) { |
603 if (ftp_listing_delegate_) { | 605 if (ftp_listing_delegate_) { |
604 ftp_listing_delegate_->OnCompletedRequest(); | 606 ftp_listing_delegate_->OnCompletedRequest(); |
605 ftp_listing_delegate_.reset(NULL); | 607 ftp_listing_delegate_.reset(NULL); |
606 } else if (multipart_delegate_) { | 608 } else if (multipart_delegate_) { |
607 multipart_delegate_->OnCompletedRequest(); | 609 multipart_delegate_->OnCompletedRequest(); |
608 multipart_delegate_.reset(NULL); | 610 multipart_delegate_.reset(NULL); |
609 } | 611 } |
610 | 612 |
611 // Prevent any further IPC to the browser now that we're complete, but | 613 // Prevent any further IPC to the browser now that we're complete, but |
612 // don't delete it to keep any downloaded temp files alive. | 614 // don't delete it to keep any downloaded temp files alive. |
613 DCHECK(!completed_bridge_.get()); | 615 DCHECK(!completed_bridge_.get()); |
614 completed_bridge_.swap(bridge_); | 616 completed_bridge_.swap(bridge_); |
615 | 617 |
616 if (client_) { | 618 if (client_) { |
617 if (error_code != net::OK) { | 619 if (error_code != net::OK) { |
618 client_->didFail(loader_, CreateError(request_.url(), error_code)); | 620 client_->didFail(loader_, CreateError(request_.url(), |
| 621 stale_copy_in_cache, |
| 622 error_code)); |
619 } else { | 623 } else { |
620 client_->didFinishLoading( | 624 client_->didFinishLoading( |
621 loader_, (completion_time - TimeTicks()).InSecondsF()); | 625 loader_, (completion_time - TimeTicks()).InSecondsF()); |
622 } | 626 } |
623 } | 627 } |
624 | 628 |
625 // We are done with the bridge now, and so we need to release the reference | 629 // We are done with the bridge now, and so we need to release the reference |
626 // to ourselves that we took on behalf of the bridge. This may cause our | 630 // to ourselves that we took on behalf of the bridge. This may cause our |
627 // destruction. | 631 // destruction. |
628 Release(); | 632 Release(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 ResourceResponseInfo info; | 666 ResourceResponseInfo info; |
663 int error_code; | 667 int error_code; |
664 std::string data; | 668 std::string data; |
665 | 669 |
666 if (GetInfoFromDataURL(request_.url(), &info, &data, &error_code)) { | 670 if (GetInfoFromDataURL(request_.url(), &info, &data, &error_code)) { |
667 OnReceivedResponse(info); | 671 OnReceivedResponse(info); |
668 if (!data.empty()) | 672 if (!data.empty()) |
669 OnReceivedData(data.data(), data.size(), 0); | 673 OnReceivedData(data.data(), data.size(), 0); |
670 } | 674 } |
671 | 675 |
672 OnCompletedRequest(error_code, false, info.security_info, | 676 OnCompletedRequest(error_code, false, false, info.security_info, |
673 base::TimeTicks::Now()); | 677 base::TimeTicks::Now()); |
674 } | 678 } |
675 | 679 |
676 // WebURLLoaderImpl ----------------------------------------------------------- | 680 // WebURLLoaderImpl ----------------------------------------------------------- |
677 | 681 |
678 WebURLLoaderImpl::WebURLLoaderImpl(WebKitPlatformSupportImpl* platform) | 682 WebURLLoaderImpl::WebURLLoaderImpl(WebKitPlatformSupportImpl* platform) |
679 : context_(new Context(this)), | 683 : context_(new Context(this)), |
680 platform_(platform) { | 684 platform_(platform) { |
681 } | 685 } |
682 | 686 |
683 WebURLLoaderImpl::~WebURLLoaderImpl() { | 687 WebURLLoaderImpl::~WebURLLoaderImpl() { |
684 cancel(); | 688 cancel(); |
685 } | 689 } |
686 | 690 |
687 WebURLError WebURLLoaderImpl::CreateError(const WebURL& unreachable_url, | 691 WebURLError WebURLLoaderImpl::CreateError(const WebURL& unreachable_url, |
| 692 bool stale_copy_in_cache, |
688 int reason) { | 693 int reason) { |
689 WebURLError error; | 694 WebURLError error; |
690 error.domain = WebString::fromUTF8(net::kErrorDomain); | 695 error.domain = WebString::fromUTF8(net::kErrorDomain); |
691 error.reason = reason; | 696 error.reason = reason; |
692 error.unreachableURL = unreachable_url; | 697 error.unreachableURL = unreachable_url; |
| 698 error.staleCopyInCache = stale_copy_in_cache; |
693 if (reason == net::ERR_ABORTED) { | 699 if (reason == net::ERR_ABORTED) { |
694 error.isCancellation = true; | 700 error.isCancellation = true; |
695 } else if (reason == net::ERR_TEMPORARILY_THROTTLED) { | 701 } else if (reason == net::ERR_TEMPORARILY_THROTTLED) { |
696 error.localizedDescription = WebString::fromUTF8( | 702 error.localizedDescription = WebString::fromUTF8( |
697 kThrottledErrorDescription); | 703 kThrottledErrorDescription); |
698 } else { | 704 } else { |
699 error.localizedDescription = WebString::fromUTF8( | 705 error.localizedDescription = WebString::fromUTF8( |
700 net::ErrorToString(reason)); | 706 net::ErrorToString(reason)); |
701 } | 707 } |
702 return error; | 708 return error; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 | 856 |
851 void WebURLLoaderImpl::setDefersLoading(bool value) { | 857 void WebURLLoaderImpl::setDefersLoading(bool value) { |
852 context_->SetDefersLoading(value); | 858 context_->SetDefersLoading(value); |
853 } | 859 } |
854 | 860 |
855 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority) { | 861 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority) { |
856 context_->DidChangePriority(new_priority); | 862 context_->DidChangePriority(new_priority); |
857 } | 863 } |
858 | 864 |
859 } // namespace webkit_glue | 865 } // namespace webkit_glue |
OLD | NEW |