| 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 <string> | 9 #include <string> |
| 10 #include <type_traits> | 10 #include <type_traits> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 static ScopedJavaLocalRef<jstring> GetDownloadWarningText( | 35 static ScopedJavaLocalRef<jstring> GetDownloadWarningText( |
| 36 JNIEnv* env, | 36 JNIEnv* env, |
| 37 const JavaParamRef<jclass>& clazz, | 37 const JavaParamRef<jclass>& clazz, |
| 38 const JavaParamRef<jstring>& filename) { | 38 const JavaParamRef<jstring>& filename) { |
| 39 return base::android::ConvertUTF8ToJavaString( | 39 return base::android::ConvertUTF8ToJavaString( |
| 40 env, l10n_util::GetStringFUTF8( | 40 env, l10n_util::GetStringFUTF8( |
| 41 IDS_PROMPT_DANGEROUS_DOWNLOAD, | 41 IDS_PROMPT_DANGEROUS_DOWNLOAD, |
| 42 base::android::ConvertJavaStringToUTF16(env, filename))); | 42 base::android::ConvertJavaStringToUTF16(env, filename))); |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Returns true if a file name is dangerous, or false otherwise. | |
| 46 static jboolean IsDownloadDangerous(JNIEnv* env, | |
| 47 const JavaParamRef<jclass>& clazz, | |
| 48 const JavaParamRef<jstring>& filename) { | |
| 49 base::FilePath path(base::android::ConvertJavaStringToUTF8(env, filename)); | |
| 50 return safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel( | |
| 51 path) != safe_browsing::DownloadFileType::NOT_DANGEROUS; | |
| 52 } | |
| 53 | |
| 54 // static | 45 // static |
| 55 bool ChromeDownloadDelegate::EnqueueDownloadManagerRequest( | 46 bool ChromeDownloadDelegate::EnqueueDownloadManagerRequest( |
| 56 jobject chrome_download_delegate, | 47 jobject chrome_download_delegate, |
| 57 bool overwrite, | 48 bool overwrite, |
| 58 jobject download_info) { | 49 jobject download_info) { |
| 59 JNIEnv* env = base::android::AttachCurrentThread(); | 50 JNIEnv* env = base::android::AttachCurrentThread(); |
| 60 | 51 |
| 61 return Java_ChromeDownloadDelegate_enqueueDownloadManagerRequestFromNative( | 52 return Java_ChromeDownloadDelegate_enqueueDownloadManagerRequestFromNative( |
| 62 env, chrome_download_delegate, overwrite, download_info); | 53 env, chrome_download_delegate, overwrite, download_info); |
| 63 } | 54 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 auto* web_contents = WebContents::FromJavaWebContents(jweb_contents); | 134 auto* web_contents = WebContents::FromJavaWebContents(jweb_contents); |
| 144 ChromeDownloadDelegate::CreateForWebContents(web_contents); | 135 ChromeDownloadDelegate::CreateForWebContents(web_contents); |
| 145 ChromeDownloadDelegate::FromWebContents(web_contents)->SetJavaRef(env, obj); | 136 ChromeDownloadDelegate::FromWebContents(web_contents)->SetJavaRef(env, obj); |
| 146 } | 137 } |
| 147 | 138 |
| 148 bool RegisterChromeDownloadDelegate(JNIEnv* env) { | 139 bool RegisterChromeDownloadDelegate(JNIEnv* env) { |
| 149 return RegisterNativesImpl(env); | 140 return RegisterNativesImpl(env); |
| 150 } | 141 } |
| 151 | 142 |
| 152 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeDownloadDelegate); | 143 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeDownloadDelegate); |
| OLD | NEW |