Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/child/web_url_loader_impl.h" | 7 #include "content/child/web_url_loader_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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 bool stale_copy_in_cache, | 237 bool stale_copy_in_cache, |
| 238 const std::string& security_info, | 238 const std::string& security_info, |
| 239 const base::TimeTicks& completion_time, | 239 const base::TimeTicks& completion_time, |
| 240 int64 total_transfer_size) OVERRIDE; | 240 int64 total_transfer_size) OVERRIDE; |
| 241 | 241 |
| 242 private: | 242 private: |
| 243 friend class base::RefCounted<Context>; | 243 friend class base::RefCounted<Context>; |
| 244 virtual ~Context() {} | 244 virtual ~Context() {} |
| 245 | 245 |
| 246 // We can optimize the handling of data URLs in most cases. | 246 // We can optimize the handling of data URLs in most cases. |
| 247 bool CanHandleDataURL(const GURL& url) const; | 247 bool IsHandlableDataURLRequest() const; |
| 248 void HandleDataURL(); | 248 void HandleDataURL(); |
| 249 | 249 |
| 250 WebURLLoaderImpl* loader_; | 250 WebURLLoaderImpl* loader_; |
| 251 WebURLRequest request_; | 251 WebURLRequest request_; |
| 252 WebURLLoaderClient* client_; | 252 WebURLLoaderClient* client_; |
| 253 ResourceDispatcher* resource_dispatcher_; | 253 ResourceDispatcher* resource_dispatcher_; |
| 254 WebReferrerPolicy referrer_policy_; | 254 WebReferrerPolicy referrer_policy_; |
| 255 scoped_ptr<ResourceLoaderBridge> bridge_; | 255 scoped_ptr<ResourceLoaderBridge> bridge_; |
| 256 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; | 256 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; |
| 257 scoped_ptr<MultipartResponseDelegate> multipart_delegate_; | 257 scoped_ptr<MultipartResponseDelegate> multipart_delegate_; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 return false; | 305 return false; |
| 306 } | 306 } |
| 307 | 307 |
| 308 void WebURLLoaderImpl::Context::Start(const WebURLRequest& request, | 308 void WebURLLoaderImpl::Context::Start(const WebURLRequest& request, |
| 309 SyncLoadResponse* sync_load_response) { | 309 SyncLoadResponse* sync_load_response) { |
| 310 DCHECK(!bridge_.get()); | 310 DCHECK(!bridge_.get()); |
| 311 | 311 |
| 312 request_ = request; // Save the request. | 312 request_ = request; // Save the request. |
| 313 | 313 |
| 314 GURL url = request.url(); | 314 GURL url = request.url(); |
| 315 if (url.SchemeIs("data") && CanHandleDataURL(url)) { | 315 if (IsHandlableDataURLRequest()) { |
|
eseidel
2014/09/04 16:31:25
I would have used the active voice "CanHandleDataU
tyoshino (SeeGerritForStatus)
2014/09/05 14:05:09
In the name, I also wanted to mean that we're chec
| |
| 316 if (sync_load_response) { | 316 if (sync_load_response) { |
| 317 // This is a sync load. Do the work now. | 317 // This is a sync load. Do the work now. |
| 318 sync_load_response->url = url; | 318 sync_load_response->url = url; |
| 319 std::string data; | 319 std::string data; |
| 320 GetInfoFromDataURL(sync_load_response->url, sync_load_response, | 320 GetInfoFromDataURL(sync_load_response->url, sync_load_response, |
| 321 &sync_load_response->data, | 321 &sync_load_response->data, |
| 322 &sync_load_response->error_code); | 322 &sync_load_response->error_code); |
| 323 } else { | 323 } else { |
| 324 base::MessageLoop::current()->PostTask( | 324 base::MessageLoop::current()->PostTask( |
| 325 FROM_HERE, base::Bind(&Context::HandleDataURL, this)); | 325 FROM_HERE, base::Bind(&Context::HandleDataURL, this)); |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 649 stale_copy_in_cache, | 649 stale_copy_in_cache, |
| 650 error_code)); | 650 error_code)); |
| 651 } else { | 651 } else { |
| 652 client_->didFinishLoading( | 652 client_->didFinishLoading( |
| 653 loader_, (completion_time - TimeTicks()).InSecondsF(), | 653 loader_, (completion_time - TimeTicks()).InSecondsF(), |
| 654 total_transfer_size); | 654 total_transfer_size); |
| 655 } | 655 } |
| 656 } | 656 } |
| 657 } | 657 } |
| 658 | 658 |
| 659 bool WebURLLoaderImpl::Context::CanHandleDataURL(const GURL& url) const { | 659 bool WebURLLoaderImpl::Context::IsHandlableDataURLRequest() const { |
| 660 DCHECK(url.SchemeIs("data")); | 660 GURL url = request_.url(); |
| 661 if (!url.SchemeIs("data")) | |
| 662 return false; | |
| 663 | |
| 664 // The fast paths for data URL, Start() and HandleDataURL(), don't support | |
| 665 // the downloadToFile option. | |
| 666 if (request_.downloadToFile()) | |
| 667 return false; | |
| 661 | 668 |
| 662 // Optimize for the case where we can handle a data URL locally. We must | 669 // Optimize for the case where we can handle a data URL locally. We must |
| 663 // skip this for data URLs targetted at frames since those could trigger a | 670 // skip this for data URLs targetted at frames since those could trigger a |
| 664 // download. | 671 // download. |
| 665 // | 672 // |
| 666 // NOTE: We special case MIME types we can render both for performance | 673 // NOTE: We special case MIME types we can render both for performance |
| 667 // reasons as well as to support unit tests, which do not have an underlying | 674 // reasons as well as to support unit tests, which do not have an underlying |
| 668 // ResourceLoaderBridge implementation. | 675 // ResourceLoaderBridge implementation. |
| 669 | 676 |
| 670 #if defined(OS_ANDROID) | 677 #if defined(OS_ANDROID) |
| 671 // For compatibility reasons on Android we need to expose top-level data:// | 678 // For compatibility reasons on Android we need to expose top-level data:// |
| 672 // to the browser. | 679 // to the browser. |
| 673 if (request_.frameType() == WebURLRequest::FrameTypeTopLevel) | 680 if (request_.frameType() == WebURLRequest::FrameTypeTopLevel) |
| 674 return false; | 681 return false; |
| 675 #endif | 682 #endif |
| 676 | 683 |
| 677 if (request_.frameType() != WebURLRequest::FrameTypeTopLevel && | 684 if (request_.frameType() != WebURLRequest::FrameTypeTopLevel && |
| 678 request_.frameType() != WebURLRequest::FrameTypeNested) | 685 request_.frameType() != WebURLRequest::FrameTypeNested) |
| 679 return true; | 686 return true; |
| 680 | 687 |
| 681 std::string mime_type, unused_charset; | 688 std::string mime_type, unused_charset; |
| 682 if (net::DataURL::Parse(url, &mime_type, &unused_charset, NULL) && | 689 if (net::DataURL::Parse(request_.url(), &mime_type, &unused_charset, NULL) && |
| 683 net::IsSupportedMimeType(mime_type)) | 690 net::IsSupportedMimeType(mime_type)) |
| 684 return true; | 691 return true; |
| 685 | 692 |
| 686 return false; | 693 return false; |
| 687 } | 694 } |
| 688 | 695 |
| 689 void WebURLLoaderImpl::Context::HandleDataURL() { | 696 void WebURLLoaderImpl::Context::HandleDataURL() { |
| 690 ResourceResponseInfo info; | 697 ResourceResponseInfo info; |
| 691 int error_code; | 698 int error_code; |
| 692 std::string data; | 699 std::string data; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 886 int intra_priority_value) { | 893 int intra_priority_value) { |
| 887 context_->DidChangePriority(new_priority, intra_priority_value); | 894 context_->DidChangePriority(new_priority, intra_priority_value); |
| 888 } | 895 } |
| 889 | 896 |
| 890 bool WebURLLoaderImpl::attachThreadedDataReceiver( | 897 bool WebURLLoaderImpl::attachThreadedDataReceiver( |
| 891 blink::WebThreadedDataReceiver* threaded_data_receiver) { | 898 blink::WebThreadedDataReceiver* threaded_data_receiver) { |
| 892 return context_->AttachThreadedDataReceiver(threaded_data_receiver); | 899 return context_->AttachThreadedDataReceiver(threaded_data_receiver); |
| 893 } | 900 } |
| 894 | 901 |
| 895 } // namespace content | 902 } // namespace content |
| OLD | NEW |