Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: content/child/web_url_loader_impl.cc

Issue 480413007: [WebURLLoaderImpl] Don't respond to data URL request if downloadToFile is set (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 bool stale_copy_in_cache, 240 bool stale_copy_in_cache,
241 const std::string& security_info, 241 const std::string& security_info,
242 const base::TimeTicks& completion_time, 242 const base::TimeTicks& completion_time,
243 int64 total_transfer_size) OVERRIDE; 243 int64 total_transfer_size) OVERRIDE;
244 244
245 private: 245 private:
246 friend class base::RefCounted<Context>; 246 friend class base::RefCounted<Context>;
247 virtual ~Context() {} 247 virtual ~Context() {}
248 248
249 // We can optimize the handling of data URLs in most cases. 249 // We can optimize the handling of data URLs in most cases.
250 bool CanHandleDataURL(const GURL& url) const; 250 bool IsHandlableDataURLRequest() const;
251 void HandleDataURL(); 251 void HandleDataURL();
252 252
253 WebURLLoaderImpl* loader_; 253 WebURLLoaderImpl* loader_;
254 WebURLRequest request_; 254 WebURLRequest request_;
255 WebURLLoaderClient* client_; 255 WebURLLoaderClient* client_;
256 ResourceDispatcher* resource_dispatcher_; 256 ResourceDispatcher* resource_dispatcher_;
257 WebReferrerPolicy referrer_policy_; 257 WebReferrerPolicy referrer_policy_;
258 scoped_ptr<ResourceLoaderBridge> bridge_; 258 scoped_ptr<ResourceLoaderBridge> bridge_;
259 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; 259 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_;
260 scoped_ptr<MultipartResponseDelegate> multipart_delegate_; 260 scoped_ptr<MultipartResponseDelegate> multipart_delegate_;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 return false; 308 return false;
309 } 309 }
310 310
311 void WebURLLoaderImpl::Context::Start(const WebURLRequest& request, 311 void WebURLLoaderImpl::Context::Start(const WebURLRequest& request,
312 SyncLoadResponse* sync_load_response) { 312 SyncLoadResponse* sync_load_response) {
313 DCHECK(!bridge_.get()); 313 DCHECK(!bridge_.get());
314 314
315 request_ = request; // Save the request. 315 request_ = request; // Save the request.
316 316
317 GURL url = request.url(); 317 GURL url = request.url();
318 if (url.SchemeIs("data") && CanHandleDataURL(url)) { 318 if (IsHandlableDataURLRequest()) {
darin (slow to review) 2014/09/09 05:59:11 Hmm, "Handleable" is probably a better spelling th
tyoshino (SeeGerritForStatus) 2014/09/09 07:11:59 Thanks for suggestion.
319 if (sync_load_response) { 319 if (sync_load_response) {
320 // This is a sync load. Do the work now. 320 // This is a sync load. Do the work now.
321 sync_load_response->url = url; 321 sync_load_response->url = url;
322 sync_load_response->error_code = 322 sync_load_response->error_code =
323 GetInfoFromDataURL(sync_load_response->url, sync_load_response, 323 GetInfoFromDataURL(sync_load_response->url, sync_load_response,
324 &sync_load_response->data); 324 &sync_load_response->data);
325 } else { 325 } else {
326 base::MessageLoop::current()->PostTask( 326 base::MessageLoop::current()->PostTask(
327 FROM_HERE, base::Bind(&Context::HandleDataURL, this)); 327 FROM_HERE, base::Bind(&Context::HandleDataURL, this));
328 } 328 }
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 stale_copy_in_cache, 651 stale_copy_in_cache,
652 error_code)); 652 error_code));
653 } else { 653 } else {
654 client_->didFinishLoading( 654 client_->didFinishLoading(
655 loader_, (completion_time - TimeTicks()).InSecondsF(), 655 loader_, (completion_time - TimeTicks()).InSecondsF(),
656 total_transfer_size); 656 total_transfer_size);
657 } 657 }
658 } 658 }
659 } 659 }
660 660
661 bool WebURLLoaderImpl::Context::CanHandleDataURL(const GURL& url) const { 661 bool WebURLLoaderImpl::Context::IsHandlableDataURLRequest() const {
662 DCHECK(url.SchemeIs("data")); 662 if (!request_.url().SchemeIs("data"))
663 return false;
663 664
664 // Optimize for the case where we can handle a data URL locally. We must 665 // Optimize for the case where we can handle a data URL locally. We must
665 // skip this for data URLs targetted at frames since those could trigger a 666 // skip this for data URLs targetted at frames since those could trigger a
666 // download. 667 // download.
667 // 668 //
668 // NOTE: We special case MIME types we can render both for performance 669 // NOTE: We special case MIME types we can render both for performance
669 // reasons as well as to support unit tests, which do not have an underlying 670 // reasons as well as to support unit tests, which do not have an underlying
670 // ResourceLoaderBridge implementation. 671 // ResourceLoaderBridge implementation.
671 672
672 #if defined(OS_ANDROID) 673 #if defined(OS_ANDROID)
673 // For compatibility reasons on Android we need to expose top-level data:// 674 // For compatibility reasons on Android we need to expose top-level data://
674 // to the browser. 675 // to the browser.
675 if (request_.frameType() == WebURLRequest::FrameTypeTopLevel) 676 if (request_.frameType() == WebURLRequest::FrameTypeTopLevel)
676 return false; 677 return false;
677 #endif 678 #endif
678 679
679 if (request_.frameType() != WebURLRequest::FrameTypeTopLevel && 680 if (request_.frameType() != WebURLRequest::FrameTypeTopLevel &&
680 request_.frameType() != WebURLRequest::FrameTypeNested) 681 request_.frameType() != WebURLRequest::FrameTypeNested)
681 return true; 682 return true;
682 683
683 std::string mime_type, unused_charset; 684 std::string mime_type, unused_charset;
684 if (net::DataURL::Parse(url, &mime_type, &unused_charset, NULL) && 685 if (net::DataURL::Parse(request_.url(), &mime_type, &unused_charset, NULL) &&
685 net::IsSupportedMimeType(mime_type)) 686 net::IsSupportedMimeType(mime_type))
686 return true; 687 return true;
687 688
688 return false; 689 return false;
689 } 690 }
690 691
691 void WebURLLoaderImpl::Context::HandleDataURL() { 692 void WebURLLoaderImpl::Context::HandleDataURL() {
692 ResourceResponseInfo info; 693 ResourceResponseInfo info;
693 std::string data; 694 std::string data;
694 695
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 int intra_priority_value) { 890 int intra_priority_value) {
890 context_->DidChangePriority(new_priority, intra_priority_value); 891 context_->DidChangePriority(new_priority, intra_priority_value);
891 } 892 }
892 893
893 bool WebURLLoaderImpl::attachThreadedDataReceiver( 894 bool WebURLLoaderImpl::attachThreadedDataReceiver(
894 blink::WebThreadedDataReceiver* threaded_data_receiver) { 895 blink::WebThreadedDataReceiver* threaded_data_receiver) {
895 return context_->AttachThreadedDataReceiver(threaded_data_receiver); 896 return context_->AttachThreadedDataReceiver(threaded_data_receiver);
896 } 897 }
897 898
898 } // namespace content 899 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698