diff options
author | nileshagrawal@chromium.org <nileshagrawal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-06 10:33:56 +0000 |
---|---|---|
committer | nileshagrawal@chromium.org <nileshagrawal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-06 10:33:56 +0000 |
commit | 8d6be6b2415793b58414a37f034560e5614443ae (patch) | |
tree | c7dfa031e6ef07bc27f64581259750eea1e578f6 /chrome/browser/android | |
parent | 6bda9633b9c24dbb5f4529586fc3317d111dd3f7 (diff) | |
download | chromium_src-8d6be6b2415793b58414a37f034560e5614443ae.zip chromium_src-8d6be6b2415793b58414a37f034560e5614443ae.tar.gz chromium_src-8d6be6b2415793b58414a37f034560e5614443ae.tar.bz2 |
Android: Use a ResourceThrottle to intercept GET downloads.
Earlier we used to pass all the relevant bits to WebContentsDelegate::CanDownload
This also allows for DownloadRequestLimiter to work on Android (show the infobar when multiple downloads are initiated from a page)
BUG=
Review URL: https://chromiumcodereview.appspot.com/13649009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192740 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/android')
4 files changed, 91 insertions, 22 deletions
diff --git a/chrome/browser/android/chrome_web_contents_delegate_android.cc b/chrome/browser/android/chrome_web_contents_delegate_android.cc index 0f6ccd6..1377afd 100644 --- a/chrome/browser/android/chrome_web_contents_delegate_android.cc +++ b/chrome/browser/android/chrome_web_contents_delegate_android.cc @@ -16,7 +16,6 @@ #include "chrome/browser/ui/find_bar/find_tab_helper.h" #include "chrome/browser/ui/media_stream_infobar_delegate.h" #include "chrome/common/chrome_notification_types.h" -#include "content/public/browser/android/download_controller_android.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_service.h" @@ -25,7 +24,6 @@ #include "content/public/common/file_chooser_params.h" #include "content/public/common/page_transition_types.h" #include "jni/ChromeWebContentsDelegateAndroid_jni.h" -#include "net/http/http_request_headers.h" #include "ui/gfx/rect.h" #include "ui/gfx/rect_f.h" @@ -228,22 +226,6 @@ ChromeWebContentsDelegateAndroid::GetJavaScriptDialogManager() { return GetJavaScriptDialogManagerInstance(); } -void ChromeWebContentsDelegateAndroid::CanDownload( - content::RenderViewHost* source, - int request_id, - const std::string& request_method, - const base::Callback<void(bool)>& callback) { - if (request_method == net::HttpRequestHeaders::kGetMethod) { - content::DownloadControllerAndroid::Get()->CreateGETDownload( - source, request_id); - callback.Run(false); - } - // DownloadControllerAndroid::OnPostDownloadStarted() is called for the - // started download by the default DownloadUIController::Delegate - // implementation. - callback.Run(true); -} - void ChromeWebContentsDelegateAndroid::DidNavigateToPendingEntry( content::WebContents* source) { navigation_start_time_ = base::TimeTicks::Now(); diff --git a/chrome/browser/android/chrome_web_contents_delegate_android.h b/chrome/browser/android/chrome_web_contents_delegate_android.h index 94ee39f..9e1db12 100644 --- a/chrome/browser/android/chrome_web_contents_delegate_android.h +++ b/chrome/browser/android/chrome_web_contents_delegate_android.h @@ -54,10 +54,6 @@ class ChromeWebContentsDelegateAndroid const gfx::RectF& active_rect) OVERRIDE; virtual content::JavaScriptDialogManager* GetJavaScriptDialogManager() OVERRIDE; - virtual void CanDownload(content::RenderViewHost* source, - int request_id, - const std::string& request_method, - const base::Callback<void(bool)>& callback) OVERRIDE; virtual void DidNavigateToPendingEntry(content::WebContents* source) OVERRIDE; virtual void DidNavigateMainFramePostCommit( content::WebContents* source) OVERRIDE; diff --git a/chrome/browser/android/intercept_download_resource_throttle.cc b/chrome/browser/android/intercept_download_resource_throttle.cc new file mode 100644 index 0000000..8f71890 --- /dev/null +++ b/chrome/browser/android/intercept_download_resource_throttle.cc @@ -0,0 +1,45 @@ +// Copyright (c) 2012 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/android/intercept_download_resource_throttle.h" + +#include "content/public/browser/android/download_controller_android.h" +#include "content/public/browser/resource_controller.h" +#include "net/http/http_request_headers.h" +#include "net/url_request/url_request.h" + +namespace chrome { + +InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle( + net::URLRequest* request, + int render_process_id, + int render_view_id, + int request_id) + : request_(request), + render_process_id_(render_process_id), + render_view_id_(render_view_id), + request_id_(request_id) { +} + +InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() { +} + +void InterceptDownloadResourceThrottle::WillStartRequest(bool* defer) { + ProcessDownloadRequest(); +} + +void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer) { + ProcessDownloadRequest(); +} + +void InterceptDownloadResourceThrottle::ProcessDownloadRequest() { + if (request_->method() != net::HttpRequestHeaders::kGetMethod) + return; + + content::DownloadControllerAndroid::Get()->CreateGETDownload( + render_process_id_, render_view_id_, request_id_); + controller()->Cancel(); +} + +} // namespace diff --git a/chrome/browser/android/intercept_download_resource_throttle.h b/chrome/browser/android/intercept_download_resource_throttle.h new file mode 100644 index 0000000..a42a502 --- /dev/null +++ b/chrome/browser/android/intercept_download_resource_throttle.h @@ -0,0 +1,46 @@ +// Copyright 2013 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_ANDROID_INTERCEPT_DOWNLOAD_RESOURCE_THROTTLE_H_ +#define CHROME_BROWSER_ANDROID_INTERCEPT_DOWNLOAD_RESOURCE_THROTTLE_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "content/public/browser/resource_throttle.h" + +namespace net { +class URLRequest; +} + +namespace chrome { + +// InterceptDownloadResourceThrottle checks if a download request should be +// handled by Chrome or passsed to the Android Download Manager. +class InterceptDownloadResourceThrottle : public content::ResourceThrottle { + public: + InterceptDownloadResourceThrottle(net::URLRequest* request, + int render_process_id, + int render_view_id, + int request_id); + + // content::ResourceThrottle implementation: + virtual void WillStartRequest(bool* defer) OVERRIDE; + virtual void WillProcessResponse(bool* defer) OVERRIDE; + + private: + virtual ~InterceptDownloadResourceThrottle(); + + void ProcessDownloadRequest(); + // Set to true when if we want chrome to handle the download. + const net::URLRequest* request_; + int render_process_id_; + int render_view_id_; + int request_id_; + + DISALLOW_COPY_AND_ASSIGN(InterceptDownloadResourceThrottle); +}; + +} // namespace + +#endif // CHROME_BROWSER_ANDROID_INTERCEPT_DOWNLOAD_RESOURCE_THROTTLE_H_ |