| 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> |
| 11 | 11 |
| 12 #include "base/android/jni_android.h" | 12 #include "base/android/jni_android.h" |
| 13 #include "base/android/jni_string.h" | 13 #include "base/android/jni_string.h" |
| 14 #include "base/android/scoped_java_ref.h" | 14 #include "base/android/scoped_java_ref.h" |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/callback.h" | 16 #include "base/callback.h" |
| 17 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "chrome/browser/android/download/android_download_manager_overwrite_inf
obar_delegate.h" | 19 #include "chrome/browser/android/download/android_download_manager_overwrite_inf
obar_delegate.h" |
| 20 #include "chrome/browser/android/tab_android.h" | 20 #include "chrome/browser/android/tab_android.h" |
| 21 #include "chrome/browser/infobars/infobar_service.h" | 21 #include "chrome/browser/infobars/infobar_service.h" |
| 22 #include "chrome/browser/permissions/permission_update_infobar_delegate_android.
h" | 22 #include "chrome/browser/permissions/permission_update_infobar_delegate_android.
h" |
| 23 #include "chrome/common/safe_browsing/file_type_policies.h" | 23 #include "chrome/common/safe_browsing/file_type_policies.h" |
| 24 #include "chrome/grit/chromium_strings.h" | 24 #include "chrome/grit/chromium_strings.h" |
| 25 #include "chrome/grit/generated_resources.h" | 25 #include "chrome/grit/generated_resources.h" |
| 26 #include "content/public/browser/android/download_controller_android.h" | 26 #include "content/public/browser/android/download_controller_android.h" |
| 27 #include "jni/ChromeDownloadDelegate_jni.h" | 27 #include "jni/ChromeDownloadDelegate_jni.h" |
| 28 #include "net/base/filename_util.h" |
| 29 #include "net/cookies/cookie_options.h" |
| 30 #include "net/cookies/cookie_store.h" |
| 31 #include "net/http/http_content_disposition.h" |
| 32 #include "net/http/http_request_headers.h" |
| 33 #include "net/http/http_response_headers.h" |
| 34 #include "net/url_request/url_request.h" |
| 35 #include "net/url_request/url_request_context.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
| 29 | 37 |
| 38 using base::android::ConvertUTF8ToJavaString; |
| 39 using base::android::ScopedJavaLocalRef; |
| 30 using content::DownloadControllerAndroid; | 40 using content::DownloadControllerAndroid; |
| 31 | 41 |
| 32 // Gets the download warning text for the given file name. | 42 // Gets the download warning text for the given file name. |
| 33 static ScopedJavaLocalRef<jstring> GetDownloadWarningText( | 43 static ScopedJavaLocalRef<jstring> GetDownloadWarningText( |
| 34 JNIEnv* env, | 44 JNIEnv* env, |
| 35 const JavaParamRef<jclass>& clazz, | 45 const JavaParamRef<jclass>& clazz, |
| 36 const JavaParamRef<jstring>& filename) { | 46 const JavaParamRef<jstring>& filename) { |
| 37 return base::android::ConvertUTF8ToJavaString( | 47 return base::android::ConvertUTF8ToJavaString( |
| 38 env, l10n_util::GetStringFUTF8( | 48 env, l10n_util::GetStringFUTF8( |
| 39 IDS_PROMPT_DANGEROUS_DOWNLOAD, | 49 IDS_PROMPT_DANGEROUS_DOWNLOAD, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 std::vector<std::string> permissions; | 131 std::vector<std::string> permissions; |
| 122 permissions.push_back(permission); | 132 permissions.push_back(permission); |
| 123 | 133 |
| 124 PermissionUpdateInfoBarDelegate::Create( | 134 PermissionUpdateInfoBarDelegate::Create( |
| 125 tab_android->web_contents(), | 135 tab_android->web_contents(), |
| 126 permissions, | 136 permissions, |
| 127 IDS_MISSING_STORAGE_PERMISSION_DOWNLOAD_EDUCATION_TEXT, | 137 IDS_MISSING_STORAGE_PERMISSION_DOWNLOAD_EDUCATION_TEXT, |
| 128 *cb); | 138 *cb); |
| 129 } | 139 } |
| 130 | 140 |
| 141 ChromeDownloadDelegate::ChromeDownloadDelegate(jobject jdownload_delegate) { |
| 142 JNIEnv* env = base::android::AttachCurrentThread(); |
| 143 obj_.Reset(env, jdownload_delegate); |
| 144 } |
| 145 |
| 146 void ChromeDownloadDelegate::NewHTTPGetDownload( |
| 147 const std::string& url, |
| 148 const std::string& user_agent, |
| 149 const std::string& content_disposition, |
| 150 const std::string& mime_type, |
| 151 const std::string& cookie, |
| 152 const std::string& referer, |
| 153 const base::string16& file_name, |
| 154 int64_t content_length, |
| 155 bool has_user_gesture, |
| 156 bool must_download) { |
| 157 JNIEnv* env = base::android::AttachCurrentThread(); |
| 158 ScopedJavaLocalRef<jstring> jurl = |
| 159 ConvertUTF8ToJavaString(env, url); |
| 160 ScopedJavaLocalRef<jstring> juser_agent = |
| 161 ConvertUTF8ToJavaString(env, user_agent); |
| 162 ScopedJavaLocalRef<jstring> jcontent_disposition = |
| 163 ConvertUTF8ToJavaString(env, content_disposition); |
| 164 ScopedJavaLocalRef<jstring> jmime_type = |
| 165 ConvertUTF8ToJavaString(env, mime_type); |
| 166 ScopedJavaLocalRef<jstring> jcookie = |
| 167 ConvertUTF8ToJavaString(env, cookie); |
| 168 ScopedJavaLocalRef<jstring> jreferer = |
| 169 ConvertUTF8ToJavaString(env, referer); |
| 170 |
| 171 // net::GetSuggestedFilename will fallback to "download" as filename. |
| 172 ScopedJavaLocalRef<jstring> jfilename = |
| 173 base::android::ConvertUTF16ToJavaString(env, file_name); |
| 174 Java_ChromeDownloadDelegate_requestHttpGetDownload( |
| 175 env, obj_.obj(), |
| 176 jurl.obj(), juser_agent.obj(), jcontent_disposition.obj(), |
| 177 jmime_type.obj(), jcookie.obj(), jreferer.obj(), has_user_gesture, |
| 178 jfilename.obj(), content_length, must_download); |
| 179 } |
| 180 |
| 181 void ChromeDownloadDelegate::OnDownloadStarted(const std::string& filename, |
| 182 const std::string& mime_type) { |
| 183 JNIEnv* env = base::android::AttachCurrentThread(); |
| 184 ScopedJavaLocalRef<jstring> jfilename = ConvertUTF8ToJavaString( |
| 185 env, filename); |
| 186 ScopedJavaLocalRef<jstring> jmime_type = |
| 187 ConvertUTF8ToJavaString(env, mime_type); |
| 188 Java_ChromeDownloadDelegate_onDownloadStarted( |
| 189 env, obj_.obj(), jfilename.obj(), jmime_type.obj()); |
| 190 } |
| 191 |
| 192 void ChromeDownloadDelegate::OnDangerousDownload(const std::string& filename, |
| 193 const std::string& guid) { |
| 194 |
| 195 JNIEnv* env = base::android::AttachCurrentThread(); |
| 196 ScopedJavaLocalRef<jstring> jfilename = ConvertUTF8ToJavaString( |
| 197 env, filename); |
| 198 ScopedJavaLocalRef<jstring> jguid = ConvertUTF8ToJavaString(env, guid); |
| 199 Java_ChromeDownloadDelegate_onDangerousDownload( |
| 200 env, obj_.obj(), jfilename.obj(), jguid.obj()); |
| 201 } |
| 202 |
| 203 void ChromeDownloadDelegate::RequestFileAccess(intptr_t callback_id) { |
| 204 JNIEnv* env = base::android::AttachCurrentThread(); |
| 205 Java_ChromeDownloadDelegate_requestFileAccess( |
| 206 env, obj_.obj(), callback_id); |
| 207 } |
| 208 |
| 131 bool RegisterChromeDownloadDelegate(JNIEnv* env) { | 209 bool RegisterChromeDownloadDelegate(JNIEnv* env) { |
| 132 return RegisterNativesImpl(env); | 210 return RegisterNativesImpl(env); |
| 133 } | 211 } |
| OLD | NEW |