diff options
author | nileshagrawal@chromium.org <nileshagrawal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-13 04:51:54 +0000 |
---|---|---|
committer | nileshagrawal@chromium.org <nileshagrawal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-13 04:51:54 +0000 |
commit | c0c1c62e685f099600c6a9f920fc36b0296ff8e4 (patch) | |
tree | 38003bfacbb6681e2e85d0edf251da128eb78fad /chrome | |
parent | eaac1ad09b9829b77562eee9bc0766132b8326af (diff) | |
download | chromium_src-c0c1c62e685f099600c6a9f920fc36b0296ff8e4.zip chromium_src-c0c1c62e685f099600c6a9f920fc36b0296ff8e4.tar.gz chromium_src-c0c1c62e685f099600c6a9f920fc36b0296ff8e4.tar.bz2 |
Use WebContentsDelegate::CanDownload to intercept file downloads on Android.
On Android we need to
- Intercepts GET download requests, collects all information for the downlaod to be executed on the JAVA/app side.
- POST requests are handled normally.
Review URL: http://codereview.chromium.org/9464025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126336 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
10 files changed, 41 insertions, 18 deletions
diff --git a/chrome/browser/download/download_request_limiter.cc b/chrome/browser/download/download_request_limiter.cc index d9549ba..829e353 100644 --- a/chrome/browser/download/download_request_limiter.cc +++ b/chrome/browser/download/download_request_limiter.cc @@ -202,17 +202,20 @@ DownloadRequestLimiter::DownloadStatus return state ? state->download_status() : ALLOW_ONE_DOWNLOAD; } -void DownloadRequestLimiter::CanDownloadOnIOThread(int render_process_host_id, - int render_view_id, - int request_id, - const Callback& callback) { +void DownloadRequestLimiter::CanDownloadOnIOThread( + int render_process_host_id, + int render_view_id, + int request_id, + const std::string& request_method, + const Callback& callback) { // This is invoked on the IO thread. Schedule the task to run on the UI // thread so that we can query UI state. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, base::Bind(&DownloadRequestLimiter::CanDownload, this, - render_process_host_id, render_view_id, request_id, callback)); + render_process_host_id, render_view_id, request_id, + request_method, callback)); } void DownloadRequestLimiter::OnUserGesture(WebContents* tab) { @@ -250,6 +253,7 @@ DownloadRequestLimiter::TabDownloadState* DownloadRequestLimiter:: void DownloadRequestLimiter::CanDownload(int render_process_host_id, int render_view_id, int request_id, + const std::string& request_method, const Callback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -264,12 +268,14 @@ void DownloadRequestLimiter::CanDownload(int render_process_host_id, CanDownloadImpl( TabContentsWrapper::GetCurrentWrapperForContents(originating_tab), request_id, + request_method, callback); } void DownloadRequestLimiter::CanDownloadImpl( TabContentsWrapper* originating_tab, int request_id, + const std::string& request_method, const Callback& callback) { DCHECK(originating_tab); @@ -277,7 +283,8 @@ void DownloadRequestLimiter::CanDownloadImpl( // to cancel the download operation in chrome and let the host browser // take care of it. WebContents* tab = originating_tab->web_contents(); - if (tab->GetDelegate() && !tab->GetDelegate()->CanDownload(tab, request_id)) { + if (tab->GetDelegate() && !tab->GetDelegate()->CanDownload( + tab->GetRenderViewHost(), request_id, request_method)) { ScheduleNotification(callback, false); return; } diff --git a/chrome/browser/download/download_request_limiter.h b/chrome/browser/download/download_request_limiter.h index 629f145..457de30 100644 --- a/chrome/browser/download/download_request_limiter.h +++ b/chrome/browser/download/download_request_limiter.h @@ -176,6 +176,7 @@ class DownloadRequestLimiter void CanDownloadOnIOThread(int render_process_host_id, int render_view_id, int request_id, + const std::string& request_method, const Callback& callback); // Invoked when the user presses the mouse, enter key or space bar. This may @@ -218,12 +219,14 @@ class DownloadRequestLimiter void CanDownload(int render_process_host_id, int render_view_id, int request_id, + const std::string& request_method, const Callback& callback); // Does the work of updating the download status on the UI thread and // potentially prompting the user. void CanDownloadImpl(TabContentsWrapper* originating_tab, int request_id, + const std::string& request_method, const Callback& callback); // Invoked on the UI thread. Schedules a call to NotifyCallback on the io diff --git a/chrome/browser/download/download_request_limiter_unittest.cc b/chrome/browser/download/download_request_limiter_unittest.cc index fff7d64..1092ae6 100644 --- a/chrome/browser/download/download_request_limiter_unittest.cc +++ b/chrome/browser/download/download_request_limiter_unittest.cc @@ -41,7 +41,8 @@ class DownloadRequestLimiterTest : public TabContentsWrapperTestHarness { void CanDownload() { download_request_limiter_->CanDownloadImpl( contents_wrapper(), - -1, + -1, // request id + "GET", // request method base::Bind(&DownloadRequestLimiterTest::ContinueDownload, base::Unretained(this))); message_loop_.RunAllPending(); diff --git a/chrome/browser/download/download_resource_throttle.cc b/chrome/browser/download/download_resource_throttle.cc index 7ccedab..bb94776 100644 --- a/chrome/browser/download/download_resource_throttle.cc +++ b/chrome/browser/download/download_resource_throttle.cc @@ -12,7 +12,8 @@ DownloadResourceThrottle::DownloadResourceThrottle( DownloadRequestLimiter* limiter, int render_process_id, int render_view_id, - int request_id) + int request_id, + const std::string& request_method) : querying_limiter_(true), request_allowed_(false), request_deferred_(false) { @@ -20,6 +21,7 @@ DownloadResourceThrottle::DownloadResourceThrottle( render_process_id, render_view_id, request_id, + request_method, base::Bind(&DownloadResourceThrottle::ContinueDownload, AsWeakPtr())); } diff --git a/chrome/browser/download/download_resource_throttle.h b/chrome/browser/download/download_resource_throttle.h index d8dff6a..b014073 100644 --- a/chrome/browser/download/download_resource_throttle.h +++ b/chrome/browser/download/download_resource_throttle.h @@ -26,7 +26,8 @@ class DownloadResourceThrottle DownloadResourceThrottle(DownloadRequestLimiter* limiter, int render_process_id, int render_view_id, - int request_id); + int request_id, + const std::string& request_method); // content::ResourceThrottle implementation: virtual void WillStartRequest(bool* defer) OVERRIDE; diff --git a/chrome/browser/external_tab_container_win.cc b/chrome/browser/external_tab_container_win.cc index 5812742..db366f5 100644 --- a/chrome/browser/external_tab_container_win.cc +++ b/chrome/browser/external_tab_container_win.cc @@ -555,7 +555,9 @@ bool ExternalTabContainer::TakeFocus(bool reverse) { return true; } -bool ExternalTabContainer::CanDownload(WebContents* source, int request_id) { +bool ExternalTabContainer::CanDownload(RenderViewHost* render_view_host, + int request_id, + const std::string& request_method) { if (load_requests_via_automation_) { if (automation_) { // In case the host needs to show UI that needs to take the focus. diff --git a/chrome/browser/external_tab_container_win.h b/chrome/browser/external_tab_container_win.h index 72da46b..114b179 100644 --- a/chrome/browser/external_tab_container_win.h +++ b/chrome/browser/external_tab_container_win.h @@ -147,8 +147,9 @@ class ExternalTabContainer : public content::WebContentsDelegate, virtual void HandleKeyboardEvent( const NativeWebKeyboardEvent& event) OVERRIDE; virtual bool TakeFocus(bool reverse) OVERRIDE; - virtual bool CanDownload(content::WebContents* source, - int request_id) OVERRIDE; + virtual bool CanDownload(content::RenderViewHost* render_view_host, + int request_id, + const std::string& request_method) OVERRIDE; virtual bool OnGoToEntryOffset(int offset) OVERRIDE; virtual bool HandleContextMenu( const content::ContextMenuParams& params) OVERRIDE; diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc index a2764e1..4f6b0e3 100644 --- a/chrome/browser/instant/instant_loader.cc +++ b/chrome/browser/instant/instant_loader.cc @@ -232,8 +232,9 @@ class InstantLoader::TabContentsDelegateImpl // instant result when the drag ends, so that during the drag the page won't // move around. virtual void DragEnded() OVERRIDE; - virtual bool CanDownload(content::WebContents* source, - int request_id) OVERRIDE; + virtual bool CanDownload(content::RenderViewHost* render_view_host, + int request_id, + const std::string& request_method) OVERRIDE; virtual void HandleMouseUp() OVERRIDE; virtual void HandleMouseActivate() OVERRIDE; virtual bool OnGoToEntryOffset(int offset) OVERRIDE; @@ -484,8 +485,10 @@ void InstantLoader::TabContentsDelegateImpl::DragEnded() { CommitFromMouseReleaseIfNecessary(); } -bool InstantLoader::TabContentsDelegateImpl::CanDownload(WebContents* source, - int request_id) { +bool InstantLoader::TabContentsDelegateImpl::CanDownload( + RenderViewHost* render_view_host, + int request_id, + const std::string& request_method) { // Downloads are disabled. return false; } diff --git a/chrome/browser/prerender/prerender_contents.cc b/chrome/browser/prerender/prerender_contents.cc index 93d1029..eb29203 100644 --- a/chrome/browser/prerender/prerender_contents.cc +++ b/chrome/browser/prerender/prerender_contents.cc @@ -135,7 +135,9 @@ class PrerenderContents::TabContentsDelegateImpl return false; } - virtual bool CanDownload(WebContents* source, int request_id) OVERRIDE { + virtual bool CanDownload(RenderViewHost* render_view_host, + int request_id, + const std::string& request_method) OVERRIDE { prerender_contents_->Destroy(FINAL_STATUS_DOWNLOAD); // Cancel the download. return false; 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 9322586..c0da321 100644 --- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc +++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc @@ -203,7 +203,8 @@ void ChromeResourceDispatcherHostDelegate::DownloadStarting( throttles); } else { throttles->push_back(new DownloadResourceThrottle( - download_request_limiter_, child_id, route_id, request_id)); + download_request_limiter_, child_id, route_id, request_id, + request->method())); } } |