diff options
20 files changed, 186 insertions, 88 deletions
diff --git a/chrome/browser/browser_process.h b/chrome/browser/browser_process.h index 0e19d7d..7395bbe 100644 --- a/chrome/browser/browser_process.h +++ b/chrome/browser/browser_process.h @@ -184,6 +184,7 @@ class BrowserProcess { virtual void SetApplicationLocale(const std::string& locale) = 0; virtual DownloadStatusUpdater* download_status_updater() = 0; + virtual DownloadRequestLimiter* download_request_limiter() = 0; // Returns the object that watches for changes in the closeable state of tab. virtual TabCloseableStateWatcher* tab_closeable_state_watcher() = 0; diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index 4c2427b..0a8a385 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -24,6 +24,7 @@ #include "chrome/browser/component_updater/component_updater_service.h" #include "chrome/browser/debugger/devtools_protocol_handler.h" #include "chrome/browser/debugger/remote_debugging_server.h" +#include "chrome/browser/download/download_request_limiter.h" #include "chrome/browser/extensions/extension_event_router_forwarder.h" #include "chrome/browser/extensions/extension_tab_id_map.h" #include "chrome/browser/extensions/user_script_listener.h" @@ -586,6 +587,13 @@ DownloadStatusUpdater* BrowserProcessImpl::download_status_updater() { return &download_status_updater_; } +DownloadRequestLimiter* BrowserProcessImpl::download_request_limiter() { + DCHECK(CalledOnValidThread()); + if (!download_request_limiter_) + download_request_limiter_ = new DownloadRequestLimiter(); + return download_request_limiter_; +} + TabCloseableStateWatcher* BrowserProcessImpl::tab_closeable_state_watcher() { DCHECK(CalledOnValidThread()); if (!tab_closeable_state_watcher_.get()) diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h index 67ebad8..47e0f07 100644 --- a/chrome/browser/browser_process_impl.h +++ b/chrome/browser/browser_process_impl.h @@ -97,6 +97,7 @@ class BrowserProcessImpl : public BrowserProcess, virtual const std::string& GetApplicationLocale(); virtual void SetApplicationLocale(const std::string& locale); virtual DownloadStatusUpdater* download_status_updater(); + virtual DownloadRequestLimiter* download_request_limiter(); virtual TabCloseableStateWatcher* tab_closeable_state_watcher(); virtual BackgroundModeManager* background_mode_manager(); virtual StatusTray* status_tray(); @@ -282,6 +283,8 @@ class BrowserProcessImpl : public BrowserProcess, // so we don't have to worry about lazy initialization. DownloadStatusUpdater download_status_updater_; + scoped_refptr<DownloadRequestLimiter> download_request_limiter_; + // Ensures that the observers of plugin/print disable/enable state // notifications are properly added and removed. PrefChangeRegistrar pref_change_registrar_; diff --git a/chrome/browser/download/download_request_limiter_observer.cc b/chrome/browser/download/download_request_limiter_observer.cc new file mode 100644 index 0000000..94fde71 --- /dev/null +++ b/chrome/browser/download/download_request_limiter_observer.cc @@ -0,0 +1,22 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/download/download_request_limiter_observer.h" + +#include "chrome/browser/browser_process.h" +#include "chrome/browser/download/download_request_limiter.h" + +DownloadRequestLimiterObserver::DownloadRequestLimiterObserver( + TabContents* tab_contents) + : TabContentsObserver(tab_contents) { +} + +DownloadRequestLimiterObserver::~DownloadRequestLimiterObserver() { +} + +void DownloadRequestLimiterObserver::DidGetUserGesture() { + if (!g_browser_process->download_request_limiter()) + return; // NULL in unitests. + g_browser_process->download_request_limiter()->OnUserGesture(tab_contents()); +} diff --git a/chrome/browser/download/download_request_limiter_observer.h b/chrome/browser/download/download_request_limiter_observer.h new file mode 100644 index 0000000..d5d6135 --- /dev/null +++ b/chrome/browser/download/download_request_limiter_observer.h @@ -0,0 +1,25 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_OBSERVER_H_ +#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_OBSERVER_H_ + +#include "content/browser/tab_contents/tab_contents_observer.h" + +class TabContents; + +// Watches for user gesture notifications. +class DownloadRequestLimiterObserver : public TabContentsObserver { + public: + explicit DownloadRequestLimiterObserver(TabContents* tab_contents); + virtual ~DownloadRequestLimiterObserver(); + + // TabContentsObserver overrides. + virtual void DidGetUserGesture() OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiterObserver); +}; + +#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_OBSERVER_H_ diff --git a/chrome/browser/renderer_host/download_throttling_resource_handler.cc b/chrome/browser/download/download_throttling_resource_handler.cc index f320c65..e6655df 100644 --- a/chrome/browser/renderer_host/download_throttling_resource_handler.cc +++ b/chrome/browser/download/download_throttling_resource_handler.cc @@ -2,18 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/renderer_host/download_throttling_resource_handler.h" +#include "chrome/browser/download/download_throttling_resource_handler.h" #include "base/logging.h" #include "chrome/browser/download/download_util.h" -#include "content/browser/download/download_resource_handler.h" #include "content/browser/renderer_host/resource_dispatcher_host.h" #include "content/common/resource_response.h" #include "net/base/io_buffer.h" #include "net/base/mime_sniffer.h" DownloadThrottlingResourceHandler::DownloadThrottlingResourceHandler( + ResourceHandler* next_handler, ResourceDispatcherHost* host, + DownloadRequestLimiter* limiter, net::URLRequest* request, const GURL& url, int render_process_host_id, @@ -26,6 +27,8 @@ DownloadThrottlingResourceHandler::DownloadThrottlingResourceHandler( render_process_host_id_(render_process_host_id), render_view_id_(render_view_id), request_id_(request_id), + next_handler_(next_handler), + request_allowed_(false), tmp_buffer_length_(0), ignore_on_read_complete_(in_complete), request_closed_(false) { @@ -40,7 +43,7 @@ DownloadThrottlingResourceHandler::DownloadThrottlingResourceHandler( // released in ContinueDownload() and CancelDownload(). AddRef(); - host_->download_request_limiter()->CanDownloadOnIOThread( + limiter->CanDownloadOnIOThread( render_process_host_id_, render_view_id, request_id, this); BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, @@ -55,8 +58,8 @@ bool DownloadThrottlingResourceHandler::OnUploadProgress(int request_id, uint64 position, uint64 size) { DCHECK(!request_closed_); - if (download_handler_.get()) - return download_handler_->OnUploadProgress(request_id, position, size); + if (request_allowed_) + return next_handler_->OnUploadProgress(request_id, position, size); return true; } @@ -66,9 +69,8 @@ bool DownloadThrottlingResourceHandler::OnRequestRedirected( ResourceResponse* response, bool* defer) { DCHECK(!request_closed_); - if (download_handler_.get()) { - return download_handler_->OnRequestRedirected( - request_id, url, response, defer); + if (request_allowed_) { + return next_handler_->OnRequestRedirected(request_id, url, response, defer); } url_ = url; return true; @@ -78,8 +80,8 @@ bool DownloadThrottlingResourceHandler::OnResponseStarted( int request_id, ResourceResponse* response) { DCHECK(!request_closed_); - if (download_handler_.get()) - return download_handler_->OnResponseStarted(request_id, response); + if (request_allowed_) + return next_handler_->OnResponseStarted(request_id, response); response_ = response; return true; } @@ -88,8 +90,8 @@ bool DownloadThrottlingResourceHandler::OnWillStart(int request_id, const GURL& url, bool* defer) { DCHECK(!request_closed_); - if (download_handler_.get()) - return download_handler_->OnWillStart(request_id, url, defer); + if (request_allowed_) + return next_handler_->OnWillStart(request_id, url, defer); return true; } @@ -98,8 +100,8 @@ bool DownloadThrottlingResourceHandler::OnWillRead(int request_id, int* buf_size, int min_size) { DCHECK(!request_closed_); - if (download_handler_.get()) - return download_handler_->OnWillRead(request_id, buf, buf_size, min_size); + if (request_allowed_) + return next_handler_->OnWillRead(request_id, buf, buf_size, min_size); // We should only have this invoked once, as such we only deal with one // tmp buffer. @@ -129,12 +131,12 @@ bool DownloadThrottlingResourceHandler::OnReadCompleted(int request_id, if (tmp_buffer_.get()) { DCHECK(!tmp_buffer_length_); tmp_buffer_length_ = *bytes_read; - if (download_handler_.get()) + if (request_allowed_) CopyTmpBufferToDownloadHandler(); return true; } - if (download_handler_.get()) - return download_handler_->OnReadCompleted(request_id, bytes_read); + if (request_allowed_) + return next_handler_->OnReadCompleted(request_id, bytes_read); return true; } @@ -143,9 +145,9 @@ bool DownloadThrottlingResourceHandler::OnResponseCompleted( const net::URLRequestStatus& status, const std::string& security_info) { DCHECK(!request_closed_); - if (download_handler_.get()) - return download_handler_->OnResponseCompleted(request_id, status, - security_info); + if (request_allowed_) + return next_handler_->OnResponseCompleted(request_id, status, + security_info); // For a download, if ResourceDispatcher::Read() fails, // ResourceDispatcher::OnresponseStarted() will call @@ -159,8 +161,8 @@ bool DownloadThrottlingResourceHandler::OnResponseCompleted( void DownloadThrottlingResourceHandler::OnRequestClosed() { DCHECK(!request_closed_); - if (download_handler_.get()) - download_handler_->OnRequestClosed(); + if (request_allowed_) + next_handler_->OnRequestClosed(); request_closed_ = true; } @@ -171,20 +173,10 @@ void DownloadThrottlingResourceHandler::CancelDownload() { } void DownloadThrottlingResourceHandler::ContinueDownload() { - DCHECK(!download_handler_.get()); if (!request_closed_) { - download_handler_ = - new DownloadResourceHandler(host_, - render_process_host_id_, - render_view_id_, - request_id_, - url_, - host_->download_file_manager(), - request_, - false, - DownloadSaveInfo()); + request_allowed_ = true; if (response_.get()) - download_handler_->OnResponseStarted(request_id_, response_.get()); + next_handler_->OnResponseStarted(request_id_, response_.get()); if (tmp_buffer_length_) CopyTmpBufferToDownloadHandler(); @@ -199,11 +191,11 @@ void DownloadThrottlingResourceHandler::CopyTmpBufferToDownloadHandler() { // Copy over the tmp buffer. net::IOBuffer* buffer; int buf_size; - if (download_handler_->OnWillRead(request_id_, &buffer, &buf_size, - tmp_buffer_length_)) { + if (next_handler_->OnWillRead(request_id_, &buffer, &buf_size, + tmp_buffer_length_)) { CHECK(buf_size >= tmp_buffer_length_); memcpy(buffer->data(), tmp_buffer_->data(), tmp_buffer_length_); - download_handler_->OnReadCompleted(request_id_, &tmp_buffer_length_); + next_handler_->OnReadCompleted(request_id_, &tmp_buffer_length_); } tmp_buffer_length_ = 0; tmp_buffer_ = NULL; diff --git a/chrome/browser/renderer_host/download_throttling_resource_handler.h b/chrome/browser/download/download_throttling_resource_handler.h index 1fab3eaf0..23708c8 100644 --- a/chrome/browser/renderer_host/download_throttling_resource_handler.h +++ b/chrome/browser/download/download_throttling_resource_handler.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_RENDERER_HOST_DOWNLOAD_THROTTLING_RESOURCE_HANDLER_H_ -#define CHROME_BROWSER_RENDERER_HOST_DOWNLOAD_THROTTLING_RESOURCE_HANDLER_H_ +#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_THROTTLING_RESOURCE_HANDLER_H_ +#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_THROTTLING_RESOURCE_HANDLER_H_ #pragma once #include <string> @@ -24,14 +24,16 @@ class URLRequest; // download and asks the DownloadRequestLimiter if the download should be // allowed. The DownloadRequestLimiter notifies us asynchronously as to whether // the download is allowed or not. If the download is allowed the request is -// resumed, a DownloadResourceHandler is created and all EventHandler methods -// are delegated to it. If the download is not allowed the request is canceled. +// resumed, all EventHandler methods are delegated to it to the original +// handler. If the download is not allowed the request is canceled. class DownloadThrottlingResourceHandler : public ResourceHandler, public DownloadRequestLimiter::Callback { public: - DownloadThrottlingResourceHandler(ResourceDispatcherHost* host, + DownloadThrottlingResourceHandler(ResourceHandler* next_handler, + ResourceDispatcherHost* host, + DownloadRequestLimiter* limiter, net::URLRequest* request, const GURL& url, int render_process_host_id, @@ -71,9 +73,11 @@ class DownloadThrottlingResourceHandler int render_view_id_; int request_id_; - // Handles the actual download. This is only created if the download is - // allowed to continue. - scoped_refptr<DownloadResourceHandler> download_handler_; + // The original handler. + scoped_refptr<ResourceHandler> next_handler_; + + // Set to true when we know that the request is allowed to start. + bool request_allowed_; // Response supplied to OnResponseStarted. Only non-null if OnResponseStarted // is invoked. @@ -97,4 +101,4 @@ class DownloadThrottlingResourceHandler DISALLOW_COPY_AND_ASSIGN(DownloadThrottlingResourceHandler); }; -#endif // CHROME_BROWSER_RENDERER_HOST_DOWNLOAD_THROTTLING_RESOURCE_HANDLER_H_ +#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_THROTTLING_RESOURCE_HANDLER_H_ 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 52067e4..333b10d 100644 --- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc +++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc @@ -7,6 +7,9 @@ #include "base/logging.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/content_settings/host_content_settings_map.h" +#include "chrome/browser/download/download_request_limiter.h" +#include "chrome/browser/download/download_throttling_resource_handler.h" +#include "chrome/browser/download/download_util.h" #include "chrome/browser/external_protocol/external_protocol_handler.h" #include "chrome/browser/net/load_timing_observer.h" #include "chrome/browser/prerender/prerender_manager.h" @@ -56,6 +59,7 @@ ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate( ResourceDispatcherHost* resource_dispatcher_host, prerender::PrerenderTracker* prerender_tracker) : resource_dispatcher_host_(resource_dispatcher_host), + download_request_limiter_(g_browser_process->download_request_limiter()), safe_browsing_(g_browser_process->safe_browsing_service()), prerender_tracker_(prerender_tracker) { } @@ -142,20 +146,36 @@ ResourceHandler* ChromeResourceDispatcherHostDelegate::RequestBeginning( } ResourceHandler* ChromeResourceDispatcherHostDelegate::DownloadStarting( - ResourceHandler* handler, - const content::ResourceContext& resource_context, - int child_id, - int route_id) { + ResourceHandler* handler, + const content::ResourceContext& resource_context, + net::URLRequest* request, + int child_id, + int route_id, + int request_id, + bool is_new_request, + bool in_complete) { + + // If this isn't a new request, we've seen this before and added the safe + // browsing resource handler 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 throttling handler. + if (is_new_request) { #if defined(ENABLE_SAFE_BROWSING) - ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>( - resource_context.GetUserData(NULL)); - if (!io_data->safe_browsing_enabled()->GetValue()) - return handler; + ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>( + resource_context.GetUserData(NULL)); + if (!io_data->safe_browsing_enabled()->GetValue()) + return handler; - return CreateSafeBrowsingResourceHandler(handler, child_id, route_id, false); + return CreateSafeBrowsingResourceHandler( + handler, child_id, route_id, false); #else - return handler; + return handler; #endif + } + + return new DownloadThrottlingResourceHandler( + handler, resource_dispatcher_host_, download_request_limiter_, request, + request->url(), child_id, route_id, request_id, in_complete); } bool ChromeResourceDispatcherHostDelegate::ShouldDeferStart( 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 181c860..e2ab211 100644 --- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h +++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h @@ -10,6 +10,7 @@ #include "base/memory/ref_counted.h" #include "content/browser/renderer_host/resource_dispatcher_host_delegate.h" +class DownloadRequestLimiter; class ResourceDispatcherHost; class SafeBrowsingService; @@ -47,8 +48,12 @@ class ChromeResourceDispatcherHostDelegate virtual ResourceHandler* DownloadStarting( ResourceHandler* handler, const content::ResourceContext& resource_context, + net::URLRequest* request, int child_id, - int route_id) OVERRIDE; + int route_id, + int request_id, + bool is_new_request, + bool in_complete) OVERRIDE; virtual bool ShouldDeferStart( net::URLRequest* request, const content::ResourceContext& resource_context) OVERRIDE; @@ -78,6 +83,7 @@ class ChromeResourceDispatcherHostDelegate ResourceHandler* handler, int child_id, int route_id, bool subresource); ResourceDispatcherHost* resource_dispatcher_host_; + scoped_refptr<DownloadRequestLimiter> download_request_limiter_; scoped_refptr<SafeBrowsingService> safe_browsing_; prerender::PrerenderTracker* prerender_tracker_; diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc index 8d749c2..dd6e3d4 100644 --- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc +++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc @@ -17,6 +17,7 @@ #include "chrome/browser/content_settings/tab_specific_content_settings.h" #include "chrome/browser/custom_handlers/protocol_handler_registry.h" #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h" +#include "chrome/browser/download/download_request_limiter_observer.h" #include "chrome/browser/extensions/extension_tab_helper.h" #include "chrome/browser/extensions/extension_webnavigation_api.h" #include "chrome/browser/external_protocol/external_protocol_observer.h" @@ -158,6 +159,8 @@ TabContentsWrapper::TabContentsWrapper(TabContents* contents) // Create the per-tab observers. external_protocol_observer_.reset(new ExternalProtocolObserver(contents)); + download_request_limiter_observer_.reset( + new DownloadRequestLimiterObserver(contents)); file_select_observer_.reset(new FileSelectObserver(contents)); plugin_observer_.reset(new PluginObserver(this)); prerender_observer_.reset(new prerender::PrerenderObserver(this)); diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h index 5a553c6..f32d2c2 100644 --- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h +++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h @@ -32,6 +32,7 @@ class AutofillManager; class AutomationTabHelper; class BlockedContentTabHelper; class BookmarkTabHelper; +class DownloadRequestLimiterObserver; class Extension; class ExtensionTabHelper; class ExtensionWebNavigationTabObserver; @@ -334,6 +335,7 @@ class TabContentsWrapper : public TabContentsObserver, // (These provide no API for callers; objects that need to exist 1:1 with tabs // and silently do their thing live here.) + scoped_ptr<DownloadRequestLimiterObserver> download_request_limiter_observer_; scoped_ptr<ExternalProtocolObserver> external_protocol_observer_; scoped_ptr<FileSelectObserver> file_select_observer_; scoped_ptr<PluginObserver> plugin_observer_; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index bf61b62..e108d58 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -868,12 +868,16 @@ 'browser/download/download_request_infobar_delegate.h', 'browser/download/download_request_limiter.cc', 'browser/download/download_request_limiter.h', + 'browser/download/download_request_limiter_observer.cc', + 'browser/download/download_request_limiter_observer.h', 'browser/download/download_safe_browsing_client.cc', 'browser/download/download_safe_browsing_client.h', 'browser/download/download_shelf.h', 'browser/download/download_shelf_context_menu.cc', 'browser/download/download_shelf_context_menu.h', 'browser/download/download_started_animation.h', + 'browser/download/download_throttling_resource_handler.cc', + 'browser/download/download_throttling_resource_handler.h', 'browser/download/download_util.cc', 'browser/download/download_util.h', 'browser/download/drag_download_file.cc', @@ -1867,8 +1871,6 @@ 'browser/renderer_host/chrome_render_view_host_observer.h', 'browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc', 'browser/renderer_host/chrome_resource_dispatcher_host_delegate.h', - 'browser/renderer_host/download_throttling_resource_handler.cc', - 'browser/renderer_host/download_throttling_resource_handler.h', 'browser/renderer_host/gtk_im_context_wrapper.cc', 'browser/renderer_host/gtk_im_context_wrapper.h', 'browser/renderer_host/gtk_key_bindings_handler.cc', diff --git a/chrome/test/base/testing_browser_process.cc b/chrome/test/base/testing_browser_process.cc index 96f5a2c..e0ffb93 100644 --- a/chrome/test/base/testing_browser_process.cc +++ b/chrome/test/base/testing_browser_process.cc @@ -223,6 +223,10 @@ DownloadStatusUpdater* TestingBrowserProcess::download_status_updater() { return NULL; } +DownloadRequestLimiter* TestingBrowserProcess::download_request_limiter() { + return NULL; +} + bool TestingBrowserProcess::plugin_finder_disabled() const { return false; } diff --git a/chrome/test/base/testing_browser_process.h b/chrome/test/base/testing_browser_process.h index 17fabb0..d27228e 100644 --- a/chrome/test/base/testing_browser_process.h +++ b/chrome/test/base/testing_browser_process.h @@ -102,6 +102,7 @@ class TestingBrowserProcess : public BrowserProcess { virtual const std::string& GetApplicationLocale(); virtual void SetApplicationLocale(const std::string& app_locale); virtual DownloadStatusUpdater* download_status_updater(); + virtual DownloadRequestLimiter* download_request_limiter(); virtual bool plugin_finder_disabled() const; virtual void CheckForInspectorFiles() {} diff --git a/content/browser/download/download_file.cc b/content/browser/download/download_file.cc index 95b6078..b1cb9cd 100644 --- a/content/browser/download/download_file.cc +++ b/content/browser/download/download_file.cc @@ -8,7 +8,6 @@ #include "base/file_util.h" #include "base/stringprintf.h" -#include "chrome/browser/download/download_util.h" #include "content/browser/browser_thread.h" #include "content/browser/download/download_create_info.h" #include "content/browser/download/download_manager.h" diff --git a/content/browser/renderer_host/buffered_resource_handler.cc b/content/browser/renderer_host/buffered_resource_handler.cc index 2810c5d..97b063f 100644 --- a/content/browser/renderer_host/buffered_resource_handler.cc +++ b/content/browser/renderer_host/buffered_resource_handler.cc @@ -9,9 +9,9 @@ #include "base/logging.h" #include "base/metrics/histogram.h" #include "base/string_util.h" -#include "chrome/browser/renderer_host/download_throttling_resource_handler.h" #include "content/browser/browser_thread.h" #include "content/browser/content_browser_client.h" +#include "content/browser/download/download_resource_handler.h" #include "content/browser/renderer_host/resource_dispatcher_host.h" #include "content/browser/renderer_host/resource_dispatcher_host_delegate.h" #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" @@ -308,15 +308,24 @@ bool BufferedResourceHandler::CompleteResponseStarted(int request_id, info->set_is_download(true); - DownloadThrottlingResourceHandler* download_handler = - new DownloadThrottlingResourceHandler(host_, - request_, - request_->url(), - info->child_id(), - info->route_id(), - request_id, - in_complete); - UseAlternateResourceHandler(request_id, download_handler); + scoped_refptr<ResourceHandler> handler( + new DownloadResourceHandler(host_, + info->child_id(), + info->route_id(), + info->request_id(), + request_->url(), + host_->download_file_manager(), + request_, + false, + DownloadSaveInfo())); + + if (host_->delegate()) { + handler = host_->delegate()->DownloadStarting( + handler, *info->context(), request_, info->child_id(), + info->route_id(), info->request_id(), false, in_complete); + } + + UseAlternateResourceHandler(request_id, handler); } return real_handler_->OnResponseStarted(request_id, response_); } diff --git a/content/browser/renderer_host/resource_dispatcher_host.cc b/content/browser/renderer_host/resource_dispatcher_host.cc index a3c4bd4..716cd12 100644 --- a/content/browser/renderer_host/resource_dispatcher_host.cc +++ b/content/browser/renderer_host/resource_dispatcher_host.cc @@ -18,7 +18,6 @@ #include "base/metrics/histogram.h" #include "base/shared_memory.h" #include "base/stl_util.h" -#include "chrome/browser/download/download_request_limiter.h" #include "chrome/browser/download/download_util.h" #include "content/browser/appcache/chrome_appcache_service.h" #include "content/browser/cert_store.h" @@ -241,7 +240,6 @@ ResourceDispatcherHost::ResourceDispatcherHost( const ResourceQueue::DelegateSet& resource_queue_delegates) : ALLOW_THIS_IN_INITIALIZER_LIST( download_file_manager_(new DownloadFileManager(this))), - download_request_limiter_(new DownloadRequestLimiter()), ALLOW_THIS_IN_INITIALIZER_LIST( save_file_manager_(new SaveFileManager(this))), webkit_thread_(new WebKitThread), @@ -745,8 +743,9 @@ void ResourceDispatcherHost::BeginDownload( save_info)); if (delegate_) { - handler = delegate_->DownloadStarting(handler, context, child_id, - route_id); + handler = delegate_->DownloadStarting( + handler, context, request, child_id, route_id, request_id_, true, + false); } const net::URLRequestContext* request_context = context.request_context(); @@ -1688,8 +1687,6 @@ void ResourceDispatcherHost::OnResponseCompleted(net::URLRequest* request) { } void ResourceDispatcherHost::OnUserGesture(TabContents* tab) { - download_request_limiter()->OnUserGesture(tab); - last_user_gesture_time_ = TimeTicks::Now(); } diff --git a/content/browser/renderer_host/resource_dispatcher_host.h b/content/browser/renderer_host/resource_dispatcher_host.h index e97fc57..706ecfe 100644 --- a/content/browser/renderer_host/resource_dispatcher_host.h +++ b/content/browser/renderer_host/resource_dispatcher_host.h @@ -31,7 +31,6 @@ class CrossSiteResourceHandler; class DownloadFileManager; -class DownloadRequestLimiter; class LoginHandler; class NotificationDetails; class PluginService; @@ -147,10 +146,6 @@ class ResourceDispatcherHost : public net::URLRequest::Delegate { return download_file_manager_; } - DownloadRequestLimiter* download_request_limiter() const { - return download_request_limiter_.get(); - } - SaveFileManager* save_file_manager() const { return save_file_manager_; } @@ -463,9 +458,6 @@ class ResourceDispatcherHost : public net::URLRequest::Delegate { // We own the download file writing thread and manager scoped_refptr<DownloadFileManager> download_file_manager_; - // Determines whether a download is allowed. - scoped_refptr<DownloadRequestLimiter> download_request_limiter_; - // We own the save file manager. scoped_refptr<SaveFileManager> save_file_manager_; diff --git a/content/browser/renderer_host/resource_dispatcher_host_delegate.h b/content/browser/renderer_host/resource_dispatcher_host_delegate.h index 0a181c1..16440fd 100644 --- a/content/browser/renderer_host/resource_dispatcher_host_delegate.h +++ b/content/browser/renderer_host/resource_dispatcher_host_delegate.h @@ -14,6 +14,7 @@ class GURL; class ResourceDispatcherHostLoginDelegate; class ResourceHandler; class ResourceMessageFilter; +class TabContents; struct ResourceHostMsg_Request; struct ResourceResponse; @@ -50,13 +51,21 @@ class ResourceDispatcherHostDelegate { int child_id, int route_id) = 0; - // Called when a download is starting, after the resource handles from the - // content layer have been added. + // Allows an embedder to add additional resource handlers for a download. + // |is_new_request| is true if this is a request that is just starting, i.e. + // the content layer has just added its own resource handlers; it's false if + // this was originally a non-download request that had some resource handlers + // applied already and now we found out it's a download. + // |in_complete| is true if this is invoked from |OnResponseCompleted|. virtual ResourceHandler* DownloadStarting( ResourceHandler* handler, const content::ResourceContext& resource_context, + net::URLRequest* request, int child_id, - int route_id) = 0; + int route_id, + int request_id, + bool is_new_request, + bool in_complete) = 0; // Called to determine whether a request's start should be deferred. This // is only called if the ResourceHandler associated with the request does diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index 977a19b..12791ed 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -13,7 +13,6 @@ #include "base/string_util.h" #include "base/time.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/download/download_request_limiter.h" #include "chrome/browser/download/download_util.h" #include "content/browser/browser_context.h" #include "content/browser/child_process_security_policy.h" |