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()) { |
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; | |
tyoshino (SeeGerritForStatus)
2014/09/04 07:03:41
Hmm, it didn't compile. I don't remember if I forg
| |
661 | 663 |
662 // Optimize for the case where we can handle a data URL locally. We must | 664 // 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 | 665 // skip this for data URLs targetted at frames since those could trigger a |
664 // download. | 666 // download. |
665 // | 667 // |
666 // NOTE: We special case MIME types we can render both for performance | 668 // 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 | 669 // reasons as well as to support unit tests, which do not have an underlying |
668 // ResourceLoaderBridge implementation. | 670 // ResourceLoaderBridge implementation. |
669 | 671 |
670 #if defined(OS_ANDROID) | 672 #if defined(OS_ANDROID) |
671 // For compatibility reasons on Android we need to expose top-level data:// | 673 // For compatibility reasons on Android we need to expose top-level data:// |
672 // to the browser. | 674 // to the browser. |
673 if (request_.frameType() == WebURLRequest::FrameTypeTopLevel) | 675 if (request_.frameType() == WebURLRequest::FrameTypeTopLevel) |
674 return false; | 676 return false; |
675 #endif | 677 #endif |
676 | 678 |
677 if (request_.frameType() != WebURLRequest::FrameTypeTopLevel && | 679 if (request_.frameType() != WebURLRequest::FrameTypeTopLevel && |
678 request_.frameType() != WebURLRequest::FrameTypeNested) | 680 request_.frameType() != WebURLRequest::FrameTypeNested) |
679 return true; | 681 return true; |
680 | 682 |
681 std::string mime_type, unused_charset; | 683 std::string mime_type, unused_charset; |
682 if (net::DataURL::Parse(url, &mime_type, &unused_charset, NULL) && | 684 if (net::DataURL::Parse(request_.url(), &mime_type, &unused_charset, NULL) && |
683 net::IsSupportedMimeType(mime_type)) | 685 net::IsSupportedMimeType(mime_type)) |
684 return true; | 686 return true; |
685 | 687 |
686 return false; | 688 return false; |
687 } | 689 } |
688 | 690 |
689 void WebURLLoaderImpl::Context::HandleDataURL() { | 691 void WebURLLoaderImpl::Context::HandleDataURL() { |
690 ResourceResponseInfo info; | 692 ResourceResponseInfo info; |
691 int error_code; | 693 int error_code; |
692 std::string data; | 694 std::string data; |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
886 int intra_priority_value) { | 888 int intra_priority_value) { |
887 context_->DidChangePriority(new_priority, intra_priority_value); | 889 context_->DidChangePriority(new_priority, intra_priority_value); |
888 } | 890 } |
889 | 891 |
890 bool WebURLLoaderImpl::attachThreadedDataReceiver( | 892 bool WebURLLoaderImpl::attachThreadedDataReceiver( |
891 blink::WebThreadedDataReceiver* threaded_data_receiver) { | 893 blink::WebThreadedDataReceiver* threaded_data_receiver) { |
892 return context_->AttachThreadedDataReceiver(threaded_data_receiver); | 894 return context_->AttachThreadedDataReceiver(threaded_data_receiver); |
893 } | 895 } |
894 | 896 |
895 } // namespace content | 897 } // namespace content |
OLD | NEW |