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

Side by Side Diff: content/browser/renderer_host/resource_dispatcher_host.cc

Issue 7192016: chrome.experimental.downloads (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: merged db_handle, id; onCreated, onErased Created 9 years, 5 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading
6 6
7 #include "content/browser/renderer_host/resource_dispatcher_host.h" 7 #include "content/browser/renderer_host/resource_dispatcher_host.h"
8 8
9 #include <set> 9 #include <set>
10 #include <string>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/bind.h" 13 #include "base/bind.h"
13 #include "base/command_line.h" 14 #include "base/command_line.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
16 #include "base/message_loop.h" 17 #include "base/message_loop.h"
17 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
18 #include "base/shared_memory.h" 19 #include "base/shared_memory.h"
19 #include "base/stl_util-inl.h" 20 #include "base/stl_util-inl.h"
20 #include "base/time.h" 21 #include "base/time.h"
22 #include "base/values.h"
21 #include "chrome/browser/download/download_file_manager.h" 23 #include "chrome/browser/download/download_file_manager.h"
22 #include "chrome/browser/download/download_manager.h" 24 #include "chrome/browser/download/download_manager.h"
23 #include "chrome/browser/download/download_request_limiter.h" 25 #include "chrome/browser/download/download_request_limiter.h"
24 #include "chrome/browser/download/download_util.h" 26 #include "chrome/browser/download/download_util.h"
25 #include "chrome/browser/download/save_file_manager.h" 27 #include "chrome/browser/download/save_file_manager.h"
26 #include "chrome/browser/renderer_host/download_resource_handler.h" 28 #include "chrome/browser/renderer_host/download_resource_handler.h"
27 #include "chrome/browser/renderer_host/save_file_resource_handler.h" 29 #include "chrome/browser/renderer_host/save_file_resource_handler.h"
28 #include "content/browser/appcache/chrome_appcache_service.h" 30 #include "content/browser/appcache/chrome_appcache_service.h"
29 #include "content/browser/cert_store.h" 31 #include "content/browser/cert_store.h"
30 #include "content/browser/child_process_security_policy.h" 32 #include "content/browser/child_process_security_policy.h"
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 674
673 // We are explicitly forcing the download of 'url'. 675 // We are explicitly forcing the download of 'url'.
674 void ResourceDispatcherHost::BeginDownload( 676 void ResourceDispatcherHost::BeginDownload(
675 const GURL& url, 677 const GURL& url,
676 const GURL& referrer, 678 const GURL& referrer,
677 const DownloadSaveInfo& save_info, 679 const DownloadSaveInfo& save_info,
678 bool prompt_for_save_location, 680 bool prompt_for_save_location,
679 int child_id, 681 int child_id,
680 int route_id, 682 int route_id,
681 const content::ResourceContext& context) { 683 const content::ResourceContext& context) {
682 if (is_shutdown_) 684 net::URLRequest* request = new net::URLRequest(url, this);
685 request->set_method("GET");
686 request->set_referrer(MaybeStripReferrer(referrer).spec());
687 BeginDownload(
688 request,
689 save_info,
690 prompt_for_save_location,
691 DownloadResourceHandler::OnStartedCallback(),
692 child_id,
693 route_id,
694 context);
695 }
696
697 void ResourceDispatcherHost::BeginDownload(
698 net::URLRequest* request,
699 const DownloadSaveInfo& save_info,
700 bool prompt_for_save_location,
701 DownloadResourceHandler::OnStartedCallback started_cb,
702 int child_id,
703 int route_id,
704 const content::ResourceContext& context) {
705 CHECK(request);
706 scoped_ptr<net::URLRequest> delete_request(request);
707 if (is_shutdown_) {
683 return; 708 return;
709 }
710 const GURL& url = request->original_url();
711 request->set_referrer(MaybeStripReferrer(GURL(request->referrer())).spec());
684 712
685 // Check if the renderer is permitted to request the requested URL. 713 // Check if the renderer is permitted to request the requested URL.
686 if (!ChildProcessSecurityPolicy::GetInstance()-> 714 if (!ChildProcessSecurityPolicy::GetInstance()->
687 CanRequestURL(child_id, url)) { 715 CanRequestURL(child_id, url)) {
688 VLOG(1) << "Denied unauthorized download request for " 716 VLOG(1) << "Denied unauthorized download request for "
689 << url.possibly_invalid_spec(); 717 << url.possibly_invalid_spec();
690 return; 718 return;
691 } 719 }
692 720
693 BrowserThread::PostTask( 721 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableFunction(
694 BrowserThread::UI, FROM_HERE, 722 &download_util::NotifyDownloadInitiated, child_id, route_id));
695 NewRunnableFunction(&download_util::NotifyDownloadInitiated,
696 child_id, route_id));
697
698 net::URLRequest* request = new net::URLRequest(url, this);
699 723
700 request_id_--; 724 request_id_--;
701 725
702 scoped_refptr<ResourceHandler> handler( 726 scoped_refptr<ResourceHandler> handler(
703 new DownloadResourceHandler(this, 727 new DownloadResourceHandler(this,
704 child_id, 728 child_id,
705 route_id, 729 route_id,
706 request_id_, 730 request_id_,
707 url, 731 url,
708 download_file_manager_.get(), 732 download_file_manager_.get(),
709 request, 733 delete_request.release(),
710 prompt_for_save_location, 734 prompt_for_save_location,
735 started_cb,
711 save_info)); 736 save_info));
712 737
713 if (delegate_) 738 if (delegate_) {
714 handler = delegate_->DownloadStarting(handler, child_id, route_id); 739 handler = delegate_->DownloadStarting(handler, child_id, route_id);
740 }
715 741
716 const net::URLRequestContext* request_context = context.request_context(); 742 const net::URLRequestContext* request_context = context.request_context();
717
718 if (!request_context->job_factory()->IsHandledURL(url)) { 743 if (!request_context->job_factory()->IsHandledURL(url)) {
719 VLOG(1) << "Download request for unsupported protocol: " 744 VLOG(1) << "Download request for unsupported protocol: "
720 << url.possibly_invalid_spec(); 745 << url.possibly_invalid_spec();
721 return; 746 return;
722 } 747 }
723 748
724 request->set_method("GET");
725 request->set_referrer(MaybeStripReferrer(referrer).spec());
726 request->set_context(context.request_context()); 749 request->set_context(context.request_context());
727 request->set_load_flags(request->load_flags() | 750 request->set_load_flags(request->load_flags() |
728 net::LOAD_IS_DOWNLOAD); 751 net::LOAD_IS_DOWNLOAD);
729 752
730 ResourceDispatcherHostRequestInfo* extra_info = 753 ResourceDispatcherHostRequestInfo* extra_info =
731 CreateRequestInfoForBrowserRequest( 754 CreateRequestInfoForBrowserRequest(
732 handler, child_id, route_id, true, context); 755 handler, child_id, route_id, true/*download*/, context);
733 SetRequestInfo(request, extra_info); // Request takes ownership. 756 SetRequestInfo(request, extra_info); // Request takes ownership.
734 757
735 BeginRequestInternal(request); 758 BeginRequestInternal(request);
736 } 759 }
737 760
738 // This function is only used for saving feature. 761 // This function is only used for saving feature.
739 void ResourceDispatcherHost::BeginSaveFile( 762 void ResourceDispatcherHost::BeginSaveFile(
740 const GURL& url, 763 const GURL& url,
741 const GURL& referrer, 764 const GURL& referrer,
742 int child_id, 765 int child_id,
(...skipping 1261 matching lines...) Expand 10 before | Expand all | Expand 10 after
2004 return HTTP_AUTH_RESOURCE_BLOCKED_CROSS; 2027 return HTTP_AUTH_RESOURCE_BLOCKED_CROSS;
2005 } 2028 }
2006 2029
2007 bool ResourceDispatcherHost::allow_cross_origin_auth_prompt() { 2030 bool ResourceDispatcherHost::allow_cross_origin_auth_prompt() {
2008 return allow_cross_origin_auth_prompt_; 2031 return allow_cross_origin_auth_prompt_;
2009 } 2032 }
2010 2033
2011 void ResourceDispatcherHost::set_allow_cross_origin_auth_prompt(bool value) { 2034 void ResourceDispatcherHost::set_allow_cross_origin_auth_prompt(bool value) {
2012 allow_cross_origin_auth_prompt_ = value; 2035 allow_cross_origin_auth_prompt_ = value;
2013 } 2036 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/resource_dispatcher_host.h ('k') | net/url_request/url_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698