| OLD | NEW |
| 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" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "chrome/browser/android/download/android_download_manager_overwrite_inf
obar_delegate.h" | 16 #include "chrome/browser/android/download/android_download_manager_overwrite_inf
obar_delegate.h" |
| 17 #include "chrome/browser/android/tab_android.h" | 17 #include "chrome/browser/android/tab_android.h" |
| 18 #include "chrome/browser/download/download_extensions.h" | 18 #include "chrome/browser/download/download_extensions.h" |
| 19 #include "chrome/browser/infobars/infobar_service.h" | 19 #include "chrome/browser/infobars/infobar_service.h" |
| 20 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
| 21 #include "content/public/browser/android/download_controller_android.h" | 21 #include "content/public/browser/android/download_controller_android.h" |
| 22 #include "jni/ChromeDownloadDelegate_jni.h" | 22 #include "jni/ChromeDownloadDelegate_jni.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 24 | 24 |
| 25 // Gets the download warning text for the given file name. | 25 // Gets the download warning text for the given file name. |
| 26 static ScopedJavaLocalRef<jstring> GetDownloadWarningText(JNIEnv* env, | 26 static jstring GetDownloadWarningText( |
| 27 jclass clazz, | 27 JNIEnv* env, jclass clazz, jstring filename) { |
| 28 jstring filename) { | |
| 29 return base::android::ConvertUTF8ToJavaString( | 28 return base::android::ConvertUTF8ToJavaString( |
| 30 env, l10n_util::GetStringFUTF8( | 29 env, l10n_util::GetStringFUTF8( |
| 31 IDS_PROMPT_DANGEROUS_DOWNLOAD, | 30 IDS_PROMPT_DANGEROUS_DOWNLOAD, |
| 32 base::android::ConvertJavaStringToUTF16(env, filename))); | 31 base::android::ConvertJavaStringToUTF16(env, filename))).Release(); |
| 33 } | 32 } |
| 34 | 33 |
| 35 // Returns true if a file name is dangerous, or false otherwise. | 34 // Returns true if a file name is dangerous, or false otherwise. |
| 36 static jboolean IsDownloadDangerous( | 35 static jboolean IsDownloadDangerous( |
| 37 JNIEnv* env, jclass clazz, jstring filename) { | 36 JNIEnv* env, jclass clazz, jstring filename) { |
| 38 base::FilePath path(base::android::ConvertJavaStringToUTF8(env, filename)); | 37 base::FilePath path(base::android::ConvertJavaStringToUTF8(env, filename)); |
| 39 return download_util::GetFileDangerLevel(path) != | 38 return download_util::GetFileDangerLevel(path) != |
| 40 download_util::NOT_DANGEROUS; | 39 download_util::NOT_DANGEROUS; |
| 41 } | 40 } |
| 42 | 41 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 base::android::ConvertJavaStringToUTF8(env, jdir_full_path); | 77 base::android::ConvertJavaStringToUTF8(env, jdir_full_path); |
| 79 | 78 |
| 80 chrome::android::AndroidDownloadManagerOverwriteInfoBarDelegate::Create( | 79 chrome::android::AndroidDownloadManagerOverwriteInfoBarDelegate::Create( |
| 81 InfoBarService::FromWebContents(tab_android->web_contents()), file_name, | 80 InfoBarService::FromWebContents(tab_android->web_contents()), file_name, |
| 82 dir_name, dir_full_path, delegate, download_info); | 81 dir_name, dir_full_path, delegate, download_info); |
| 83 } | 82 } |
| 84 | 83 |
| 85 bool RegisterChromeDownloadDelegate(JNIEnv* env) { | 84 bool RegisterChromeDownloadDelegate(JNIEnv* env) { |
| 86 return RegisterNativesImpl(env); | 85 return RegisterNativesImpl(env); |
| 87 } | 86 } |
| OLD | NEW |