OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/android/download_controller_android_impl.h" | 5 #include "content/browser/android/download_controller_android_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/android/context_utils.h" | 9 #include "base/android/context_utils.h" |
10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "content/browser/renderer_host/render_view_host_impl.h" | 25 #include "content/browser/renderer_host/render_view_host_impl.h" |
26 #include "content/browser/web_contents/web_contents_impl.h" | 26 #include "content/browser/web_contents/web_contents_impl.h" |
27 #include "content/public/browser/browser_context.h" | 27 #include "content/public/browser/browser_context.h" |
28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
29 #include "content/public/browser/download_url_parameters.h" | 29 #include "content/public/browser/download_url_parameters.h" |
30 #include "content/public/browser/global_request_id.h" | 30 #include "content/public/browser/global_request_id.h" |
31 #include "content/public/browser/resource_request_info.h" | 31 #include "content/public/browser/resource_request_info.h" |
32 #include "content/public/common/content_client.h" | 32 #include "content/public/common/content_client.h" |
33 #include "content/public/common/referrer.h" | 33 #include "content/public/common/referrer.h" |
34 #include "jni/DownloadController_jni.h" | 34 #include "jni/DownloadController_jni.h" |
| 35 #include "net/base/filename_util.h" |
35 #include "net/cookies/cookie_options.h" | 36 #include "net/cookies/cookie_options.h" |
36 #include "net/cookies/cookie_store.h" | 37 #include "net/cookies/cookie_store.h" |
37 #include "net/http/http_content_disposition.h" | 38 #include "net/http/http_content_disposition.h" |
38 #include "net/http/http_request_headers.h" | 39 #include "net/http/http_request_headers.h" |
39 #include "net/http/http_response_headers.h" | 40 #include "net/http/http_response_headers.h" |
40 #include "net/url_request/url_request.h" | 41 #include "net/url_request/url_request.h" |
41 #include "net/url_request/url_request_context.h" | 42 #include "net/url_request/url_request_context.h" |
42 | 43 |
43 using base::android::ConvertUTF8ToJavaString; | 44 using base::android::ConvertUTF8ToJavaString; |
44 using base::android::ScopedJavaLocalRef; | 45 using base::android::ScopedJavaLocalRef; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 } | 205 } |
205 | 206 |
206 JNIEnv* env = base::android::AttachCurrentThread(); | 207 JNIEnv* env = base::android::AttachCurrentThread(); |
207 // Make copy on the heap so we can pass the pointer through JNI. | 208 // Make copy on the heap so we can pass the pointer through JNI. |
208 intptr_t callback_id = reinterpret_cast<intptr_t>( | 209 intptr_t callback_id = reinterpret_cast<intptr_t>( |
209 new DownloadControllerAndroid::AcquireFileAccessPermissionCallback(cb)); | 210 new DownloadControllerAndroid::AcquireFileAccessPermissionCallback(cb)); |
210 Java_DownloadController_requestFileAccess( | 211 Java_DownloadController_requestFileAccess( |
211 env, GetJavaObject()->Controller(env).obj(), view.obj(), callback_id); | 212 env, GetJavaObject()->Controller(env).obj(), view.obj(), callback_id); |
212 } | 213 } |
213 | 214 |
| 215 void DownloadControllerAndroidImpl::SetDefaultDownloadFileName( |
| 216 const std::string& file_name) { |
| 217 default_file_name_ = file_name; |
| 218 } |
| 219 |
214 bool DownloadControllerAndroidImpl::HasFileAccessPermission( | 220 bool DownloadControllerAndroidImpl::HasFileAccessPermission( |
215 ScopedJavaLocalRef<jobject> j_content_view_core) { | 221 ScopedJavaLocalRef<jobject> j_content_view_core) { |
216 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 222 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
217 DCHECK(!j_content_view_core.is_null()); | 223 DCHECK(!j_content_view_core.is_null()); |
218 | 224 |
219 JNIEnv* env = base::android::AttachCurrentThread(); | 225 JNIEnv* env = base::android::AttachCurrentThread(); |
220 return Java_DownloadController_hasFileAccess( | 226 return Java_DownloadController_hasFileAccess( |
221 env, GetJavaObject()->Controller(env).obj(), j_content_view_core.obj()); | 227 env, GetJavaObject()->Controller(env).obj(), j_content_view_core.obj()); |
222 } | 228 } |
223 | 229 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 ConvertUTF8ToJavaString(env, info.user_agent); | 387 ConvertUTF8ToJavaString(env, info.user_agent); |
382 ScopedJavaLocalRef<jstring> jcontent_disposition = | 388 ScopedJavaLocalRef<jstring> jcontent_disposition = |
383 ConvertUTF8ToJavaString(env, info.content_disposition); | 389 ConvertUTF8ToJavaString(env, info.content_disposition); |
384 ScopedJavaLocalRef<jstring> jmime_type = | 390 ScopedJavaLocalRef<jstring> jmime_type = |
385 ConvertUTF8ToJavaString(env, info.original_mime_type); | 391 ConvertUTF8ToJavaString(env, info.original_mime_type); |
386 ScopedJavaLocalRef<jstring> jcookie = | 392 ScopedJavaLocalRef<jstring> jcookie = |
387 ConvertUTF8ToJavaString(env, info.cookie); | 393 ConvertUTF8ToJavaString(env, info.cookie); |
388 ScopedJavaLocalRef<jstring> jreferer = | 394 ScopedJavaLocalRef<jstring> jreferer = |
389 ConvertUTF8ToJavaString(env, info.referer); | 395 ConvertUTF8ToJavaString(env, info.referer); |
390 | 396 |
391 // Try parsing the content disposition header to get a | 397 // net::GetSuggestedFilename will fallback to "download" as filename. |
392 // explicitly specified filename if available. | |
393 net::HttpContentDisposition header(info.content_disposition, ""); | |
394 ScopedJavaLocalRef<jstring> jfilename = | 398 ScopedJavaLocalRef<jstring> jfilename = |
395 ConvertUTF8ToJavaString(env, header.filename()); | 399 base::android::ConvertUTF16ToJavaString( |
| 400 env, net::GetSuggestedFilename(info.url, info.content_disposition, |
| 401 std::string(), // referrer_charset |
| 402 std::string(), // suggested_name |
| 403 info.original_mime_type, |
| 404 default_file_name_)); |
396 | 405 |
397 Java_DownloadController_newHttpGetDownload( | 406 Java_DownloadController_newHttpGetDownload( |
398 env, GetJavaObject()->Controller(env).obj(), view.obj(), jurl.obj(), | 407 env, GetJavaObject()->Controller(env).obj(), view.obj(), jurl.obj(), |
399 juser_agent.obj(), jcontent_disposition.obj(), jmime_type.obj(), | 408 juser_agent.obj(), jcontent_disposition.obj(), jmime_type.obj(), |
400 jcookie.obj(), jreferer.obj(), info.has_user_gesture, jfilename.obj(), | 409 jcookie.obj(), jreferer.obj(), info.has_user_gesture, jfilename.obj(), |
401 info.total_bytes); | 410 info.total_bytes); |
402 } | 411 } |
403 | 412 |
404 void DownloadControllerAndroidImpl::OnDownloadStarted( | 413 void DownloadControllerAndroidImpl::OnDownloadStarted( |
405 DownloadItem* download_item) { | 414 DownloadItem* download_item) { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 } | 581 } |
573 | 582 |
574 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 583 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
575 if (info) | 584 if (info) |
576 has_user_gesture = info->HasUserGesture(); | 585 has_user_gesture = info->HasUserGesture(); |
577 } | 586 } |
578 | 587 |
579 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} | 588 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} |
580 | 589 |
581 } // namespace content | 590 } // namespace content |
OLD | NEW |