summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/android/chrome_web_contents_delegate_android.cc18
-rw-r--r--chrome/browser/android/chrome_web_contents_delegate_android.h4
-rw-r--r--chrome/browser/android/intercept_download_resource_throttle.cc45
-rw-r--r--chrome/browser/android/intercept_download_resource_throttle.h46
-rw-r--r--chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc6
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--content/browser/android/download_controller_android_impl.cc20
-rw-r--r--content/browser/android/download_controller_android_impl.h2
-rw-r--r--content/public/browser/android/download_controller_android.h5
9 files changed, 110 insertions, 38 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_
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 0a1e277..18e4f19 100644
--- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
+++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
@@ -61,6 +61,7 @@
#endif
#if defined(OS_ANDROID)
+#include "chrome/browser/android/intercept_download_resource_throttle.h"
#include "components/navigation_interception/intercept_navigation_delegate.h"
#endif
@@ -330,6 +331,11 @@ void ChromeResourceDispatcherHostDelegate::DownloadStarting(
throttles->push_back(new DownloadResourceThrottle(
download_request_limiter_, child_id, route_id, request_id,
request->method()));
+#if defined(OS_ANDROID)
+ throttles->push_back(
+ new chrome::InterceptDownloadResourceThrottle(
+ request, child_id, route_id, request_id));
+#endif
}
// If this isn't a new request, we've seen this before and added the standard
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index f15e615..c089aaa 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -95,6 +95,8 @@
'browser/android/infobar_stubs.cc',
'browser/android/intent_helper.cc',
'browser/android/intent_helper.h',
+ 'browser/android/intercept_download_resource_throttle.cc',
+ 'browser/android/intercept_download_resource_throttle.h',
'browser/android/provider/blocking_ui_thread_async_request.cc',
'browser/android/provider/blocking_ui_thread_async_request.h',
'browser/android/provider/bookmark_model_observer_task.cc',
diff --git a/content/browser/android/download_controller_android_impl.cc b/content/browser/android/download_controller_android_impl.cc
index 2ade0d0..d8f5d91 100644
--- a/content/browser/android/download_controller_android_impl.cc
+++ b/content/browser/android/download_controller_android_impl.cc
@@ -79,10 +79,8 @@ void DownloadControllerAndroidImpl::Init(JNIEnv* env, jobject obj) {
}
void DownloadControllerAndroidImpl::CreateGETDownload(
- RenderViewHost* render_view_host,
- int request_id) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- int render_process_id = render_view_host->GetProcess()->GetID();
+ int render_process_id, int render_view_id, int request_id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
GlobalRequestID global_id(render_process_id, request_id);
// We are yielding the UI thread and render_view_host may go away by
@@ -91,14 +89,12 @@ void DownloadControllerAndroidImpl::CreateGETDownload(
GetDownloadInfoCB cb = base::Bind(
&DownloadControllerAndroidImpl::StartAndroidDownload,
base::Unretained(this), render_process_id,
- render_view_host->GetRoutingID());
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(
- &DownloadControllerAndroidImpl::PrepareDownloadInfo,
- base::Unretained(this), global_id,
- base::Bind(&DownloadControllerAndroidImpl::StartDownloadOnUIThread,
- base::Unretained(this), cb)));
+ render_view_id);
+
+ PrepareDownloadInfo(
+ global_id,
+ base::Bind(&DownloadControllerAndroidImpl::StartDownloadOnUIThread,
+ base::Unretained(this), cb));
}
void DownloadControllerAndroidImpl::PrepareDownloadInfo(
diff --git a/content/browser/android/download_controller_android_impl.h b/content/browser/android/download_controller_android_impl.h
index 6dc87e2..b0917fb 100644
--- a/content/browser/android/download_controller_android_impl.h
+++ b/content/browser/android/download_controller_android_impl.h
@@ -75,7 +75,7 @@ class DownloadControllerAndroidImpl : public DownloadControllerAndroid,
virtual ~DownloadControllerAndroidImpl();
// DownloadControllerAndroid implementation.
- virtual void CreateGETDownload(RenderViewHost* source,
+ virtual void CreateGETDownload(int render_process_id, int render_view_id,
int request_id) OVERRIDE;
virtual void OnPostDownloadStarted(DownloadItem* download_item) OVERRIDE;
diff --git a/content/public/browser/android/download_controller_android.h b/content/public/browser/android/download_controller_android.h
index df0470e..b413205 100644
--- a/content/public/browser/android/download_controller_android.h
+++ b/content/public/browser/android/download_controller_android.h
@@ -9,8 +9,6 @@
namespace content {
class DownloadItem;
-class RenderViewHost;
-class WebContents;
// Interface to request GET downloads and send notifications for POST
// downloads.
@@ -21,7 +19,8 @@ class CONTENT_EXPORT DownloadControllerAndroid {
// Starts a new download request with Android. Should be called on the
// UI thread.
- virtual void CreateGETDownload(RenderViewHost* source, int request_id) = 0;
+ virtual void CreateGETDownload(int render_process_id, int render_view_id,
+ int request_id) = 0;
// Should be called when a POST download is started. Notifies the embedding
// app about the download. Should be called on the UI thread.