Index: chrome/browser/android/download/chrome_download_delegate.cc |
diff --git a/chrome/browser/android/download/chrome_download_delegate.cc b/chrome/browser/android/download/chrome_download_delegate.cc |
index 96382979204d6b734040d2aa7980d67d80ed6d4c..9d2496cb1169471137eb3c70b9054bb3d584c89b 100644 |
--- a/chrome/browser/android/download/chrome_download_delegate.cc |
+++ b/chrome/browser/android/download/chrome_download_delegate.cc |
@@ -9,17 +9,20 @@ |
#include "base/android/jni_android.h" |
#include "base/android/jni_string.h" |
#include "base/android/scoped_java_ref.h" |
+#include "base/bind.h" |
+#include "base/callback.h" |
#include "base/files/file_path.h" |
+#include "base/memory/weak_ptr.h" |
+#include "chrome/browser/android/download/download_overwrite_infobar_delegate_for_android_download_manager.h" |
#include "chrome/browser/android/tab_android.h" |
#include "chrome/browser/download/download_extensions.h" |
+#include "chrome/browser/infobars/infobar_service.h" |
#include "chrome/grit/generated_resources.h" |
#include "content/public/browser/android/download_controller_android.h" |
#include "jni/ChromeDownloadDelegate_jni.h" |
#include "ui/base/l10n/l10n_util.h" |
-bool RegisterChromeDownloadDeleagte(JNIEnv* env) { |
- return RegisterNativesImpl(env); |
-} |
+using base::android::ScopedJavaGlobalRef; |
// Gets the download warning text for the given file name. |
static jstring GetDownloadWarningText( |
@@ -45,3 +48,47 @@ static void DangerousDownloadValidated( |
content::DownloadControllerAndroid::Get()->DangerousDownloadValidated( |
tab_android->web_contents(), download_id, accept); |
} |
+ |
+// static |
+void ChromeDownloadDelegate::EnqueueDownloadManagerRequest( |
+ JNIEnv* env, |
Ted C
2015/03/03 01:14:44
Unless you specifically need the calling env, we t
Changwan Ryu
2015/03/04 05:15:03
Done.
|
+ JavaObjectWeakGlobalRef chrome_download_delegate, |
+ bool overwrite, |
+ const ScopedJavaGlobalRef<jobject>& download_info) { |
+ ScopedJavaLocalRef<jobject> delegate = chrome_download_delegate.get(env); |
+ if (!delegate.obj()) |
+ return; |
+ |
+ Java_ChromeDownloadDelegate_enqueueDownloadManagerRequestFromNative( |
+ env, delegate.obj(), overwrite, download_info.obj()); |
+} |
+ |
+// Called when we need to interrupt download and ask users whether to overwrite |
+// an existing file. |
+static void LaunchDownloadOverwriteInfoBar(JNIEnv* env, |
+ jclass clazz, |
+ jobject delegate, |
+ jobject tab, |
+ jobject download_info, |
+ jstring jfile_name, |
+ jstring jdir_name, |
+ jstring jdir_full_path) { |
+ TabAndroid* tab_android = TabAndroid::GetNativeTab(env, tab); |
+ |
+ std::string file_name = |
+ base::android::ConvertJavaStringToUTF8(env, jfile_name); |
+ std::string dir_name = base::android::ConvertJavaStringToUTF8(env, jdir_name); |
+ std::string dir_full_path = |
+ base::android::ConvertJavaStringToUTF8(env, jdir_full_path); |
+ ScopedJavaGlobalRef<jobject> scoped_download_info; |
+ scoped_download_info.Reset(env, download_info); |
+ |
+ chrome::android::DownloadOverwriteInfoBarDelegateForAndroidDownloadManager:: |
+ Create(InfoBarService::FromWebContents(tab_android->web_contents()), |
+ file_name, dir_name, dir_full_path, |
+ JavaObjectWeakGlobalRef(env, delegate), scoped_download_info); |
Ted C
2015/03/03 01:14:44
why weak global ref? Do you really want the deleg
Changwan Ryu
2015/03/04 05:15:03
Changed to ScopedJavaGlobalRef
|
+} |
+ |
+bool RegisterChromeDownloadDelegate(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
+} |