Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / android / download / chrome_download_delegate.cc
blob6f731f5a107660d75aa4e83750c52de9cfaa4df0
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"
7 #include <jni.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/bind.h"
13 #include "base/callback.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_infobar_delegate.h"
17 #include "chrome/browser/android/tab_android.h"
18 #include "chrome/browser/download/download_extensions.h"
19 #include "chrome/browser/infobars/infobar_service.h"
20 #include "chrome/grit/generated_resources.h"
21 #include "content/public/browser/android/download_controller_android.h"
22 #include "jni/ChromeDownloadDelegate_jni.h"
23 #include "ui/base/l10n/l10n_util.h"
25 // Gets the download warning text for the given file name.
26 static jstring GetDownloadWarningText(
27 JNIEnv* env, jclass clazz, jstring filename) {
28 return base::android::ConvertUTF8ToJavaString(
29 env, l10n_util::GetStringFUTF8(
30 IDS_PROMPT_DANGEROUS_DOWNLOAD,
31 base::android::ConvertJavaStringToUTF16(env, filename))).Release();
34 // Returns true if a file name is dangerous, or false otherwise.
35 static jboolean IsDownloadDangerous(
36 JNIEnv* env, jclass clazz, jstring filename) {
37 base::FilePath path(base::android::ConvertJavaStringToUTF8(env, filename));
38 return download_util::GetFileDangerLevel(path) !=
39 download_util::NOT_DANGEROUS;
42 // Called when a dangerous download is validated.
43 static void DangerousDownloadValidated(
44 JNIEnv* env, jclass clazz, jobject tab, jint download_id, jboolean accept) {
45 TabAndroid* tab_android = TabAndroid::GetNativeTab(env, tab);
46 content::DownloadControllerAndroid::Get()->DangerousDownloadValidated(
47 tab_android->web_contents(), download_id, accept);
50 // static
51 void ChromeDownloadDelegate::EnqueueDownloadManagerRequest(
52 jobject chrome_download_delegate,
53 bool overwrite,
54 jobject download_info) {
55 JNIEnv* env = base::android::AttachCurrentThread();
57 Java_ChromeDownloadDelegate_enqueueDownloadManagerRequestFromNative(
58 env, chrome_download_delegate, overwrite, download_info);
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);
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);
79 chrome::android::AndroidDownloadManagerOverwriteInfoBarDelegate::Create(
80 InfoBarService::FromWebContents(tab_android->web_contents()), file_name,
81 dir_name, dir_full_path, delegate, download_info);
84 bool RegisterChromeDownloadDelegate(JNIEnv* env) {
85 return RegisterNativesImpl(env);