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