Skip to content

Commit

Permalink
Add DownloadControllerAndroid public interface for android.
Browse files Browse the repository at this point in the history
BUG=


Review URL: https://chromiumcodereview.appspot.com/11112022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161964 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
nileshagrawal@chromium.org committed Oct 15, 2012
1 parent 5752e6b commit 7f8619f
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 98 deletions.
17 changes: 17 additions & 0 deletions android_webview/native/aw_web_contents_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include "android_webview/browser/find_helper.h"
#include "android_webview/native/aw_contents.h"
#include "android_webview/native/aw_javascript_dialog_creator.h"
#include "content/public/browser/android/download_controller_android.h"
#include "content/public/browser/web_contents.h"
#include "net/http/http_request_headers.h"

using content::WebContents;

Expand Down Expand Up @@ -47,4 +49,19 @@ void AwWebContentsDelegate::FindReply(WebContents* web_contents,
final_update);
}

bool AwWebContentsDelegate::CanDownload(content::RenderViewHost* source,
int request_id,
const std::string& request_method) {
if (request_method == net::HttpRequestHeaders::kGetMethod) {
content::DownloadControllerAndroid::Get()->CreateGETDownload(
source, request_id);
}
return false;
}

void AwWebContentsDelegate::OnStartDownload(WebContents* source,
content::DownloadItem* download) {
NOTREACHED(); // We always return false in CanDownload.
}

} // namespace android_webview
5 changes: 5 additions & 0 deletions android_webview/native/aw_web_contents_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class AwWebContentsDelegate
const gfx::Rect& selection_rect,
int active_match_ordinal,
bool final_update) OVERRIDE;
virtual bool CanDownload(content::RenderViewHost* source,
int request_id,
const std::string& request_method) OVERRIDE;
virtual void OnStartDownload(content::WebContents* source,
content::DownloadItem* download) OVERRIDE;
};

} // namespace android_webview
Expand Down
21 changes: 21 additions & 0 deletions chrome/browser/android/chrome_web_contents_delegate_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
#include "chrome/browser/ui/find_bar/find_notification_details.h"
#include "chrome/browser/ui/find_bar/find_tab_helper.h"
#include "chrome/common/chrome_notification_types.h"
#include "content/public/browser/android/download_controller_android.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/file_chooser_params.h"
#include "jni/ChromeWebContentsDelegateAndroid_jni.h"
#include "net/http/http_request_headers.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/rect_f.h"

Expand Down Expand Up @@ -234,5 +236,24 @@ ChromeWebContentsDelegateAndroid::GetJavaScriptDialogCreator() {
return GetJavaScriptDialogCreatorInstance();
}

bool ChromeWebContentsDelegateAndroid::CanDownload(
content::RenderViewHost* source,
int request_id,
const std::string& request_method) {
if (request_method == net::HttpRequestHeaders::kGetMethod) {
content::DownloadControllerAndroid::Get()->CreateGETDownload(
source, request_id);
return false;
}
return true;
}

void ChromeWebContentsDelegateAndroid::OnStartDownload(
WebContents* source,
content::DownloadItem* download) {
content::DownloadControllerAndroid::Get()->OnPostDownloadStarted(
source, download);
}

} // namespace android
} // namespace chrome
5 changes: 5 additions & 0 deletions chrome/browser/android/chrome_web_contents_delegate_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class ChromeWebContentsDelegateAndroid
const gfx::RectF& active_rect) OVERRIDE;
virtual content::JavaScriptDialogCreator*
GetJavaScriptDialogCreator() OVERRIDE;
virtual bool CanDownload(content::RenderViewHost* source,
int request_id,
const std::string& request_method) OVERRIDE;
virtual void OnStartDownload(content::WebContents* source,
content::DownloadItem* download) OVERRIDE;

private:
// NotificationObserver implementation.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
joth@chromium.org
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/download_item.h"
#include "content/public/browser/invalidate_type.h"
#include "content/public/browser/page_navigator.h"
#include "content/public/browser/navigation_controller.h"
Expand All @@ -18,21 +17,14 @@
#include "content/public/common/page_transition_types.h"
#include "content/public/common/referrer.h"
#include "jni/WebContentsDelegateAndroid_jni.h"
#include "net/http/http_request_headers.h"
#include "ui/gfx/rect.h"
#include "webkit/glue/window_open_disposition.h"

using base::android::AttachCurrentThread;
using base::android::CheckException;
using base::android::ConvertUTF8ToJavaString;
using base::android::ConvertUTF16ToJavaString;
using base::android::GetClass;
using base::android::GetMethodID;
using base::android::HasClass;
using base::android::ScopedJavaLocalRef;
using content::DownloadItem;
using content::JavaScriptDialogCreator;
using content::RenderViewHost;
using content::WebContents;

namespace web_contents_delegate_android {
Expand Down Expand Up @@ -274,28 +266,6 @@ void WebContentsDelegateAndroid::UpdateTargetURL(WebContents* source,
java_url.obj());
}

bool WebContentsDelegateAndroid::CanDownload(
RenderViewHost* source,
int request_id,
const std::string& request_method) {
if (request_method == net::HttpRequestHeaders::kGetMethod) {
// TODO(leandrogracia): re-enable this when calling DownloadController
// doesn't introduce a DEPS layering violation.
// DownloadController::GetInstance()->CreateGETDownload(
// source, request_id);
return false;
}
return true;
}

void WebContentsDelegateAndroid::OnStartDownload(WebContents* source,
DownloadItem* download) {
// TODO(leandrogracia): re-enable this when calling DownloadController
// doesn't introduce a DEPS layering violation.
// DownloadController::GetInstance()->OnPostDownloadStarted(
// source, download);
}

bool WebContentsDelegateAndroid::ShouldOverrideLoading(const GURL& url) {
if (!url.is_valid())
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "net/base/net_errors.h"

namespace content {
class DownloadItem;
class JavaScriptDialogCreator;
class RenderViewHost;
class WebContents;
Expand Down Expand Up @@ -94,11 +93,6 @@ class WebContentsDelegateAndroid : public content::WebContentsDelegate {
virtual void UpdateTargetURL(content::WebContents* source,
int32 page_id,
const GURL& url) OVERRIDE;
virtual bool CanDownload(content::RenderViewHost* source,
int request_id,
const std::string& request_method) OVERRIDE;
virtual void OnStartDownload(content::WebContents* source,
content::DownloadItem* download) OVERRIDE;
virtual bool ShouldOverrideLoading(const GURL& url) OVERRIDE;
virtual void HandleKeyboardEvent(
content::WebContents* source,
Expand Down
6 changes: 3 additions & 3 deletions content/browser/android/browser_jni_registrar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "content/browser/android/content_video_view.h"
#include "content/browser/android/content_view_core_impl.h"
#include "content/browser/android/content_view_statics.h"
#include "content/browser/android/download_controller.h"
#include "content/browser/android/download_controller_android_impl.h"
#include "content/browser/android/load_url_params.h"
#include "content/browser/android/sandboxed_process_launcher.h"
#include "content/browser/android/surface_texture_peer_browser_impl.h"
Expand All @@ -33,8 +33,8 @@ base::android::RegistrationMethod kContentRegisteredMethods[] = {
{ "ContentSettings", content::ContentSettings::RegisterContentSettings },
{ "ContentVideoView", content::ContentVideoView::RegisterContentVideoView },
{ "ContentViewCore", content::RegisterContentViewCore },
{ "DownloadController",
content::DownloadController::RegisterDownloadController },
{ "DownloadControllerAndroidImpl",
content::DownloadControllerAndroidImpl::RegisterDownloadController },
{ "RegisterImeAdapter", content::RegisterImeAdapter },
{ "JavaBoundObject", JavaBoundObject::RegisterJavaBoundObject },
{ "LoadUrlParams", content::RegisterLoadUrlParams },
Expand Down
Loading

0 comments on commit 7f8619f

Please sign in to comment.