summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrdsmith@chromium.org <rdsmith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-15 15:27:06 +0000
committerrdsmith@chromium.org <rdsmith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-15 15:27:06 +0000
commita53e2f91b2dff8f5f5a1c80f69881a7ad21d00e7 (patch)
treeaa954ee72763177383f7835af86eaf37fef9571d
parentfcbdeb7ddc579fac96844efc9540c27b2c770633 (diff)
downloadchromium_src-a53e2f91b2dff8f5f5a1c80f69881a7ad21d00e7.zip
chromium_src-a53e2f91b2dff8f5f5a1c80f69881a7ad21d00e7.tar.gz
chromium_src-a53e2f91b2dff8f5f5a1c80f69881a7ad21d00e7.tar.bz2
Add flag to specify if explicitly requested download is from web.
This allows interposing the DownloadResourceThrottle on all web downloads, not just those occuring because of navigations. BUG=127522 R=darin@chromium.org TEST=Retry example in referenced issue; look for throttling message. Review URL: https://chromiumcodereview.appspot.com/10381122 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137137 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/download/download_extension_api.cc1
-rw-r--r--chrome/browser/plugin_installer.cc1
-rw-r--r--chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc21
-rw-r--r--chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h2
-rw-r--r--content/browser/download/download_manager_impl.cc1
-rw-r--r--content/browser/renderer_host/buffered_resource_handler.cc1
-rw-r--r--content/browser/renderer_host/render_message_filter.cc1
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host_impl.cc7
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host_impl.h2
-rw-r--r--content/public/browser/download_url_parameters.cc21
-rw-r--r--content/public/browser/download_url_parameters.h5
-rw-r--r--content/public/browser/resource_dispatcher_host.h5
-rw-r--r--content/public/browser/resource_dispatcher_host_delegate.cc2
-rw-r--r--content/public/browser/resource_dispatcher_host_delegate.h2
14 files changed, 46 insertions, 26 deletions
diff --git a/chrome/browser/download/download_extension_api.cc b/chrome/browser/download/download_extension_api.cc
index cdf0193..70db7d6 100644
--- a/chrome/browser/download/download_extension_api.cc
+++ b/chrome/browser/download/download_extension_api.cc
@@ -502,6 +502,7 @@ void DownloadsDownloadFunction::BeginDownloadOnIOThread() {
net::Error error = iodata_->rdh->BeginDownload(
request.Pass(),
+ false, // is_content_initiated
iodata_->resource_context,
iodata_->render_process_host_id,
iodata_->render_view_host_routing_id,
diff --git a/chrome/browser/plugin_installer.cc b/chrome/browser/plugin_installer.cc
index 7f2f66a..75e9cf2 100644
--- a/chrome/browser/plugin_installer.cc
+++ b/chrome/browser/plugin_installer.cc
@@ -44,6 +44,7 @@ void BeginDownload(
scoped_ptr<net::URLRequest> request(new net::URLRequest(url, NULL));
net::Error error = rdh->BeginDownload(
request.Pass(),
+ false, // is_content_initiated
resource_context,
render_process_host_id,
render_view_host_routing_id,
diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
index 92def35a..29fcd22 100644
--- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
+++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
@@ -203,27 +203,28 @@ void ChromeResourceDispatcherHostDelegate::DownloadStarting(
int child_id,
int route_id,
int request_id,
- bool is_new_request,
+ bool is_content_initiated,
ScopedVector<content::ResourceThrottle>* throttles) {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&NotifyDownloadInitiatedOnUI, child_id, route_id));
- // If this isn't a new request, we've seen this before and added the safe
- // browsing resource throttle already so no need to add it again. This code
- // path is only hit for requests initiated through the browser, and not the
- // web, so no need to add the download throttle.
- if (is_new_request) {
+ // If it's from the web, we don't trust it, so we push the throttle on.
+ if (is_content_initiated) {
+ throttles->push_back(new DownloadResourceThrottle(
+ download_request_limiter_, child_id, route_id, request_id,
+ request->method()));
+ }
+
+ // If this isn't a new request, we've seen this before and added the standard
+ // resource throttles already so no need to add it again.
+ if (!request->is_pending()) {
AppendStandardResourceThrottles(request,
resource_context,
child_id,
route_id,
ResourceType::MAIN_FRAME,
throttles);
- } else {
- throttles->push_back(new DownloadResourceThrottle(
- download_request_limiter_, child_id, route_id, request_id,
- request->method()));
}
}
diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h
index a1f0790..8c35999 100644
--- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h
+++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h
@@ -59,7 +59,7 @@ class ChromeResourceDispatcherHostDelegate
int child_id,
int route_id,
int request_id,
- bool is_new_request,
+ bool is_content_initiated,
ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE;
virtual bool AcceptSSLClientCertificateRequest(
net::URLRequest* request,
diff --git a/content/browser/download/download_manager_impl.cc b/content/browser/download/download_manager_impl.cc
index dc655bf..cf9ae3a 100644
--- a/content/browser/download/download_manager_impl.cc
+++ b/content/browser/download/download_manager_impl.cc
@@ -83,6 +83,7 @@ void BeginDownload(content::DownloadUrlParameters* params) {
}
resource_dispatcher_host->BeginDownload(
request.Pass(),
+ params->content_initiated(),
params->resource_context(),
params->render_process_host_id(),
params->render_view_host_routing_id(),
diff --git a/content/browser/renderer_host/buffered_resource_handler.cc b/content/browser/renderer_host/buffered_resource_handler.cc
index 23e2e7b..7cd8aed 100644
--- a/content/browser/renderer_host/buffered_resource_handler.cc
+++ b/content/browser/renderer_host/buffered_resource_handler.cc
@@ -300,6 +300,7 @@ bool BufferedResourceHandler::CompleteResponseStarted(int request_id) {
info->GetChildID(),
info->GetRouteID(),
info->GetRequestID(),
+ true, // is_content_initiated
DownloadSaveInfo(),
DownloadResourceHandler::OnStartedCallback()));
diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc
index 783de11..7908f34 100644
--- a/content/browser/renderer_host/render_message_filter.cc
+++ b/content/browser/renderer_host/render_message_filter.cc
@@ -723,6 +723,7 @@ void RenderMessageFilter::OnDownloadUrl(const IPC::Message& message,
download_stats::RecordDownloadSource(download_stats::INITIATED_BY_RENDERER);
resource_dispatcher_host_->BeginDownload(
request.Pass(),
+ true, // is_content_initiated
resource_context_,
render_process_id_,
message.routing_id(),
diff --git a/content/browser/renderer_host/resource_dispatcher_host_impl.cc b/content/browser/renderer_host/resource_dispatcher_host_impl.cc
index 45b3092..ce87cd6 100644
--- a/content/browser/renderer_host/resource_dispatcher_host_impl.cc
+++ b/content/browser/renderer_host/resource_dispatcher_host_impl.cc
@@ -465,6 +465,7 @@ void ResourceDispatcherHostImpl::CancelRequestsForContext(
net::Error ResourceDispatcherHostImpl::BeginDownload(
scoped_ptr<net::URLRequest> request,
+ bool is_content_initiated,
ResourceContext* context,
int child_id,
int route_id,
@@ -513,7 +514,8 @@ net::Error ResourceDispatcherHostImpl::BeginDownload(
// |started_callback|.
scoped_refptr<ResourceHandler> handler(
CreateResourceHandlerForDownload(request.get(), context, child_id,
- route_id, request_id_, save_info,
+ route_id, request_id_,
+ is_content_initiated, save_info,
started_callback));
if (!request_context->job_factory()->IsHandledURL(url)) {
@@ -575,6 +577,7 @@ ResourceDispatcherHostImpl::CreateResourceHandlerForDownload(
int child_id,
int route_id,
int request_id,
+ bool is_content_initiated,
const DownloadSaveInfo& save_info,
const DownloadResourceHandler::OnStartedCallback& started_cb) {
scoped_refptr<ResourceHandler> handler(
@@ -584,7 +587,7 @@ ResourceDispatcherHostImpl::CreateResourceHandlerForDownload(
if (delegate_) {
ScopedVector<ResourceThrottle> throttles;
delegate_->DownloadStarting(request, context, child_id, route_id,
- request_id, !request->is_pending(), &throttles);
+ request_id, is_content_initiated, &throttles);
if (!throttles.empty()) {
handler = new ThrottlingResourceHandler(this, handler, child_id,
request_id, throttles.Pass());
diff --git a/content/browser/renderer_host/resource_dispatcher_host_impl.h b/content/browser/renderer_host/resource_dispatcher_host_impl.h
index c306c46..463fffa 100644
--- a/content/browser/renderer_host/resource_dispatcher_host_impl.h
+++ b/content/browser/renderer_host/resource_dispatcher_host_impl.h
@@ -76,6 +76,7 @@ class CONTENT_EXPORT ResourceDispatcherHostImpl
virtual void SetAllowCrossOriginAuthPrompt(bool value) OVERRIDE;
virtual net::Error BeginDownload(
scoped_ptr<net::URLRequest> request,
+ bool is_content_initiated,
ResourceContext* context,
int child_id,
int route_id,
@@ -252,6 +253,7 @@ class CONTENT_EXPORT ResourceDispatcherHostImpl
int child_id,
int route_id,
int request_id,
+ bool is_content_initiated,
const DownloadSaveInfo& save_info,
const DownloadResourceHandler::OnStartedCallback& started_cb);
diff --git a/content/public/browser/download_url_parameters.cc b/content/public/browser/download_url_parameters.cc
index 64102fa..bff885a 100644
--- a/content/public/browser/download_url_parameters.cc
+++ b/content/public/browser/download_url_parameters.cc
@@ -21,16 +21,17 @@ DownloadUrlParameters::DownloadUrlParameters(
int render_view_host_routing_id,
ResourceContext* resource_context,
const DownloadSaveInfo& save_info)
- : load_flags_(0),
- method_("GET"),
- post_id_(-1),
- prefer_cache_(false),
- render_process_host_id_(render_process_host_id),
- render_view_host_routing_id_(render_view_host_routing_id),
- resource_context_(resource_context),
- resource_dispatcher_host_(ResourceDispatcherHost::Get()),
- save_info_(save_info),
- url_(url) {
+ : content_initiated_(false),
+ load_flags_(0),
+ method_("GET"),
+ post_id_(-1),
+ prefer_cache_(false),
+ render_process_host_id_(render_process_host_id),
+ render_view_host_routing_id_(render_view_host_routing_id),
+ resource_context_(resource_context),
+ resource_dispatcher_host_(ResourceDispatcherHost::Get()),
+ save_info_(save_info),
+ url_(url) {
DCHECK(resource_dispatcher_host_);
}
diff --git a/content/public/browser/download_url_parameters.h b/content/public/browser/download_url_parameters.h
index 40cec1c..ba36cfa 100644
--- a/content/public/browser/download_url_parameters.h
+++ b/content/public/browser/download_url_parameters.h
@@ -58,6 +58,9 @@ class CONTENT_EXPORT DownloadUrlParameters {
~DownloadUrlParameters();
+ void set_content_initiated(bool content_initiated) {
+ content_initiated_ = content_initiated;
+ }
void add_request_header(const std::string& name, const std::string& value) {
request_headers_.push_back(make_pair(name, value));
}
@@ -81,6 +84,7 @@ class CONTENT_EXPORT DownloadUrlParameters {
}
const OnStartedCallback& callback() const { return callback_; }
+ bool content_initiated() const { return content_initiated_; }
int load_flags() const { return load_flags_; }
const std::string& method() const { return method_; }
const std::string& post_body() const { return post_body_; }
@@ -109,6 +113,7 @@ class CONTENT_EXPORT DownloadUrlParameters {
private:
OnStartedCallback callback_;
+ bool content_initiated_;
RequestHeadersType request_headers_;
int load_flags_;
std::string method_;
diff --git a/content/public/browser/resource_dispatcher_host.h b/content/public/browser/resource_dispatcher_host.h
index 1eb4c44..030dd75 100644
--- a/content/public/browser/resource_dispatcher_host.h
+++ b/content/public/browser/resource_dispatcher_host.h
@@ -37,9 +37,12 @@ class CONTENT_EXPORT ResourceDispatcherHost {
// Initiates a download by explicit request of the renderer, e.g. due to
// alt-clicking a link. If the download is started, |started_callback| will
// be called on the UI thread with the DownloadId; otherwise an error code
- // will be returned.
+ // will be returned. |is_content_initiated| is used to indicate that
+ // the request was generated from a web page, and hence may not be
+ // as trustworthy as a browser generated request.
virtual net::Error BeginDownload(
scoped_ptr<net::URLRequest> request,
+ bool is_content_initiated,
ResourceContext* context,
int child_id,
int route_id,
diff --git a/content/public/browser/resource_dispatcher_host_delegate.cc b/content/public/browser/resource_dispatcher_host_delegate.cc
index 3dc1c7e..b3d9ea7 100644
--- a/content/public/browser/resource_dispatcher_host_delegate.cc
+++ b/content/public/browser/resource_dispatcher_host_delegate.cc
@@ -33,7 +33,7 @@ void ResourceDispatcherHostDelegate::DownloadStarting(
int child_id,
int route_id,
int request_id,
- bool is_new_request,
+ bool is_content_initiated,
ScopedVector<ResourceThrottle>* throttles) {
}
diff --git a/content/public/browser/resource_dispatcher_host_delegate.h b/content/public/browser/resource_dispatcher_host_delegate.h
index 4c2fef0..19cd6cf 100644
--- a/content/public/browser/resource_dispatcher_host_delegate.h
+++ b/content/public/browser/resource_dispatcher_host_delegate.h
@@ -72,7 +72,7 @@ class CONTENT_EXPORT ResourceDispatcherHostDelegate {
int child_id,
int route_id,
int request_id,
- bool is_new_request,
+ bool is_content_initiated,
ScopedVector<ResourceThrottle>* throttles);
// Called when an SSL Client Certificate is requested. If false is returned,