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
3 // found in the LICENSE file.
5 #include "chrome/browser/android/download/chrome_download_delegate.h"
9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h"
11 #include "base/android/scoped_java_ref.h"
12 #include "base/files/file_path.h"
13 #include "chrome/browser/android/tab_android.h"
14 #include "chrome/browser/download/download_extensions.h"
15 #include "chrome/grit/generated_resources.h"
16 #include "content/public/browser/android/download_controller_android.h"
17 #include "jni/ChromeDownloadDelegate_jni.h"
18 #include "ui/base/l10n/l10n_util.h"
20 bool RegisterChromeDownloadDeleagte(JNIEnv
* env
) {
21 return RegisterNativesImpl(env
);
24 // Gets the download warning text for the given file name.
25 static jstring
GetDownloadWarningText(
26 JNIEnv
* env
, jclass clazz
, jstring filename
) {
27 return base::android::ConvertUTF8ToJavaString(
28 env
, l10n_util::GetStringFUTF8(
29 IDS_PROMPT_DANGEROUS_DOWNLOAD
,
30 base::android::ConvertJavaStringToUTF16(env
, filename
))).Release();
33 // Returns true if a file name is dangerous, or false otherwise.
34 static jboolean
IsDownloadDangerous(
35 JNIEnv
* env
, jclass clazz
, jstring filename
) {
36 base::FilePath
path(base::android::ConvertJavaStringToUTF8(env
, filename
));
37 return download_util::GetFileDangerLevel(path
) !=
38 download_util::NOT_DANGEROUS
;
41 // Called when a dangerous download is validated.
42 static void DangerousDownloadValidated(
43 JNIEnv
* env
, jclass clazz
, jobject tab
, jint download_id
, jboolean accept
) {
44 TabAndroid
* tab_android
= TabAndroid::GetNativeTab(env
, tab
);
45 content::DownloadControllerAndroid::Get()->DangerousDownloadValidated(
46 tab_android
->web_contents(), download_id
, accept
);