Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: chrome/browser/android/download/chrome_download_delegate.cc

Issue 580043002: [Android] Prompt with infobar on filename conflict (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changed function order according to headers Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/download/chrome_download_delegate.h" 5 #include "chrome/browser/android/download/chrome_download_delegate.h"
6 6
7 #include <jni.h> 7 #include <jni.h>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
11 #include "base/android/scoped_java_ref.h" 11 #include "base/android/scoped_java_ref.h"
12 #include "base/bind.h"
13 #include "base/callback.h"
12 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/memory/weak_ptr.h"
16 #include "chrome/browser/android/download/android_download_manager_overwrite_inf obar_delegate.h"
13 #include "chrome/browser/android/tab_android.h" 17 #include "chrome/browser/android/tab_android.h"
14 #include "chrome/browser/download/download_extensions.h" 18 #include "chrome/browser/download/download_extensions.h"
19 #include "chrome/browser/infobars/infobar_service.h"
15 #include "chrome/grit/generated_resources.h" 20 #include "chrome/grit/generated_resources.h"
16 #include "content/public/browser/android/download_controller_android.h" 21 #include "content/public/browser/android/download_controller_android.h"
17 #include "jni/ChromeDownloadDelegate_jni.h" 22 #include "jni/ChromeDownloadDelegate_jni.h"
18 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
19 24
20 bool RegisterChromeDownloadDeleagte(JNIEnv* env) {
21 return RegisterNativesImpl(env);
22 }
23
24 // Gets the download warning text for the given file name. 25 // Gets the download warning text for the given file name.
25 static jstring GetDownloadWarningText( 26 static jstring GetDownloadWarningText(
26 JNIEnv* env, jclass clazz, jstring filename) { 27 JNIEnv* env, jclass clazz, jstring filename) {
27 return base::android::ConvertUTF8ToJavaString( 28 return base::android::ConvertUTF8ToJavaString(
28 env, l10n_util::GetStringFUTF8( 29 env, l10n_util::GetStringFUTF8(
29 IDS_PROMPT_DANGEROUS_DOWNLOAD, 30 IDS_PROMPT_DANGEROUS_DOWNLOAD,
30 base::android::ConvertJavaStringToUTF16(env, filename))).Release(); 31 base::android::ConvertJavaStringToUTF16(env, filename))).Release();
31 } 32 }
32 33
33 // Returns true if a file name is dangerous, or false otherwise. 34 // Returns true if a file name is dangerous, or false otherwise.
34 static jboolean IsDownloadDangerous( 35 static jboolean IsDownloadDangerous(
35 JNIEnv* env, jclass clazz, jstring filename) { 36 JNIEnv* env, jclass clazz, jstring filename) {
36 base::FilePath path(base::android::ConvertJavaStringToUTF8(env, filename)); 37 base::FilePath path(base::android::ConvertJavaStringToUTF8(env, filename));
37 return download_util::GetFileDangerLevel(path) != 38 return download_util::GetFileDangerLevel(path) !=
38 download_util::NOT_DANGEROUS; 39 download_util::NOT_DANGEROUS;
39 } 40 }
40 41
41 // Called when a dangerous download is validated. 42 // Called when a dangerous download is validated.
42 static void DangerousDownloadValidated( 43 static void DangerousDownloadValidated(
43 JNIEnv* env, jclass clazz, jobject tab, jint download_id, jboolean accept) { 44 JNIEnv* env, jclass clazz, jobject tab, jint download_id, jboolean accept) {
44 TabAndroid* tab_android = TabAndroid::GetNativeTab(env, tab); 45 TabAndroid* tab_android = TabAndroid::GetNativeTab(env, tab);
45 content::DownloadControllerAndroid::Get()->DangerousDownloadValidated( 46 content::DownloadControllerAndroid::Get()->DangerousDownloadValidated(
46 tab_android->web_contents(), download_id, accept); 47 tab_android->web_contents(), download_id, accept);
47 } 48 }
49
50 // static
51 void ChromeDownloadDelegate::EnqueueDownloadManagerRequest(
52 jobject chrome_download_delegate,
53 bool overwrite,
54 jobject download_info) {
55 JNIEnv* env = base::android::AttachCurrentThread();
56
57 Java_ChromeDownloadDelegate_enqueueDownloadManagerRequestFromNative(
58 env, chrome_download_delegate, overwrite, download_info);
59 }
60
61 // Called when we need to interrupt download and ask users whether to overwrite
62 // an existing file.
63 static void LaunchDownloadOverwriteInfoBar(JNIEnv* env,
64 jclass clazz,
65 jobject delegate,
66 jobject tab,
67 jobject download_info,
68 jstring jfile_name,
69 jstring jdir_name,
70 jstring jdir_full_path) {
71 TabAndroid* tab_android = TabAndroid::GetNativeTab(env, tab);
72
73 std::string file_name =
74 base::android::ConvertJavaStringToUTF8(env, jfile_name);
75 std::string dir_name = base::android::ConvertJavaStringToUTF8(env, jdir_name);
76 std::string dir_full_path =
77 base::android::ConvertJavaStringToUTF8(env, jdir_full_path);
78
79 chrome::android::AndroidDownloadManagerOverwriteInfoBarDelegate::Create(
80 InfoBarService::FromWebContents(tab_android->web_contents()), file_name,
81 dir_name, dir_full_path, delegate, download_info);
82 }
83
84 bool RegisterChromeDownloadDelegate(JNIEnv* env) {
85 return RegisterNativesImpl(env);
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698