Index: content/browser/renderer_host/resource_dispatcher_host.cc |
diff --git a/content/browser/renderer_host/resource_dispatcher_host.cc b/content/browser/renderer_host/resource_dispatcher_host.cc |
index 314be906f6ca31d2c79d251bf518bc7bc024ab5f..622cf73457f05d799a5120261f054ed432c9e5ef 100644 |
--- a/content/browser/renderer_host/resource_dispatcher_host.cc |
+++ b/content/browser/renderer_host/resource_dispatcher_host.cc |
@@ -7,6 +7,7 @@ |
#include "content/browser/renderer_host/resource_dispatcher_host.h" |
#include <set> |
+#include <string> |
#include <vector> |
#include "base/bind.h" |
@@ -18,6 +19,7 @@ |
#include "base/shared_memory.h" |
#include "base/stl_util-inl.h" |
#include "base/time.h" |
+#include "base/values.h" |
#include "chrome/browser/download/download_file_manager.h" |
#include "chrome/browser/download/download_manager.h" |
#include "chrome/browser/download/download_request_limiter.h" |
@@ -679,8 +681,34 @@ void ResourceDispatcherHost::BeginDownload( |
int child_id, |
int route_id, |
const content::ResourceContext& context) { |
- if (is_shutdown_) |
+ net::URLRequest* request = new net::URLRequest(url, this); |
+ request->set_method("GET"); |
+ request->set_referrer(MaybeStripReferrer(referrer).spec()); |
+ BeginDownload( |
+ request, |
+ save_info, |
+ prompt_for_save_location, |
+ DownloadResourceHandler::OnStartedCallback(), |
+ child_id, |
+ route_id, |
+ context); |
+} |
+ |
+void ResourceDispatcherHost::BeginDownload( |
+ net::URLRequest* request, |
+ const DownloadSaveInfo& save_info, |
+ bool prompt_for_save_location, |
+ DownloadResourceHandler::OnStartedCallback started_cb, |
+ int child_id, |
+ int route_id, |
+ const content::ResourceContext& context) { |
+ CHECK(request); |
+ scoped_ptr<net::URLRequest> delete_request(request); |
+ if (is_shutdown_) { |
return; |
+ } |
+ const GURL& url = request->original_url(); |
+ request->set_referrer(MaybeStripReferrer(GURL(request->referrer())).spec()); |
// Check if the renderer is permitted to request the requested URL. |
if (!ChildProcessSecurityPolicy::GetInstance()-> |
@@ -690,12 +718,8 @@ void ResourceDispatcherHost::BeginDownload( |
return; |
} |
- BrowserThread::PostTask( |
- BrowserThread::UI, FROM_HERE, |
- NewRunnableFunction(&download_util::NotifyDownloadInitiated, |
- child_id, route_id)); |
- |
- net::URLRequest* request = new net::URLRequest(url, this); |
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableFunction( |
+ &download_util::NotifyDownloadInitiated, child_id, route_id)); |
request_id_--; |
@@ -706,30 +730,29 @@ void ResourceDispatcherHost::BeginDownload( |
request_id_, |
url, |
download_file_manager_.get(), |
- request, |
+ delete_request.release(), |
prompt_for_save_location, |
+ started_cb, |
save_info)); |
- if (delegate_) |
+ if (delegate_) { |
handler = delegate_->DownloadStarting(handler, child_id, route_id); |
+ } |
const net::URLRequestContext* request_context = context.request_context(); |
- |
if (!request_context->job_factory()->IsHandledURL(url)) { |
VLOG(1) << "Download request for unsupported protocol: " |
<< url.possibly_invalid_spec(); |
return; |
} |
- request->set_method("GET"); |
- request->set_referrer(MaybeStripReferrer(referrer).spec()); |
request->set_context(context.request_context()); |
request->set_load_flags(request->load_flags() | |
net::LOAD_IS_DOWNLOAD); |
ResourceDispatcherHostRequestInfo* extra_info = |
CreateRequestInfoForBrowserRequest( |
- handler, child_id, route_id, true, context); |
+ handler, child_id, route_id, true/*download*/, context); |
SetRequestInfo(request, extra_info); // Request takes ownership. |
BeginRequestInternal(request); |