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 "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 236 |
237 // Register for updates to the DownloadItem. | 237 // Register for updates to the DownloadItem. |
238 download_item->AddObserver(this); | 238 download_item->AddObserver(this); |
239 | 239 |
240 ScopedJavaLocalRef<jobject> view = | 240 ScopedJavaLocalRef<jobject> view = |
241 GetContentViewCoreFromWebContents(download_item->GetWebContents()); | 241 GetContentViewCoreFromWebContents(download_item->GetWebContents()); |
242 // The view went away. Can't proceed. | 242 // The view went away. Can't proceed. |
243 if (view.is_null()) | 243 if (view.is_null()) |
244 return; | 244 return; |
245 | 245 |
| 246 ScopedJavaLocalRef<jstring> jmime_type = |
| 247 ConvertUTF8ToJavaString(env, download_item->GetMimeType()); |
| 248 ScopedJavaLocalRef<jstring> jfilename = ConvertUTF8ToJavaString( |
| 249 env, download_item->GetTargetFilePath().BaseName().value()); |
246 Java_DownloadController_onDownloadStarted( | 250 Java_DownloadController_onDownloadStarted( |
247 env, GetJavaObject()->Controller(env).obj(), view.obj()); | 251 env, GetJavaObject()->Controller(env).obj(), view.obj(), jfilename.obj(), |
| 252 jmime_type.obj()); |
248 } | 253 } |
249 | 254 |
250 void DownloadControllerAndroidImpl::OnDownloadUpdated(DownloadItem* item) { | 255 void DownloadControllerAndroidImpl::OnDownloadUpdated(DownloadItem* item) { |
251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
252 if (item->IsDangerous() && !item->IsCancelled()) | 257 if (item->IsDangerous() && !item->IsCancelled()) |
253 OnDangerousDownload(item); | 258 OnDangerousDownload(item); |
254 | 259 |
255 if (!item->IsComplete()) | 260 if (!item->IsComplete()) |
256 return; | 261 return; |
257 | 262 |
258 // Multiple OnDownloadUpdated() notifications may be issued while the download | 263 // Multiple OnDownloadUpdated() notifications may be issued while the download |
259 // is in the COMPLETE state. Only handle one. | 264 // is in the COMPLETE state. Only handle one. |
260 item->RemoveObserver(this); | 265 item->RemoveObserver(this); |
261 | 266 |
262 ScopedJavaLocalRef<jobject> view_core = GetContentViewCoreFromWebContents( | 267 // Call onDownloadCompleted |
263 item->GetWebContents()); | |
264 if (view_core.is_null()) { | |
265 // We can get NULL WebContents from the DownloadItem. | |
266 return; | |
267 } | |
268 | |
269 // Call onHttpPostDownloadCompleted | |
270 JNIEnv* env = base::android::AttachCurrentThread(); | 268 JNIEnv* env = base::android::AttachCurrentThread(); |
271 ScopedJavaLocalRef<jstring> jurl = | 269 ScopedJavaLocalRef<jstring> jurl = |
272 ConvertUTF8ToJavaString(env, item->GetURL().spec()); | 270 ConvertUTF8ToJavaString(env, item->GetURL().spec()); |
273 ScopedJavaLocalRef<jstring> jcontent_disposition = | |
274 ConvertUTF8ToJavaString(env, item->GetContentDisposition()); | |
275 ScopedJavaLocalRef<jstring> jmime_type = | 271 ScopedJavaLocalRef<jstring> jmime_type = |
276 ConvertUTF8ToJavaString(env, item->GetMimeType()); | 272 ConvertUTF8ToJavaString(env, item->GetMimeType()); |
277 ScopedJavaLocalRef<jstring> jpath = | 273 ScopedJavaLocalRef<jstring> jpath = |
278 ConvertUTF8ToJavaString(env, item->GetTargetFilePath().value()); | 274 ConvertUTF8ToJavaString(env, item->GetTargetFilePath().value()); |
| 275 ScopedJavaLocalRef<jstring> jfilename = ConvertUTF8ToJavaString( |
| 276 env, item->GetTargetFilePath().BaseName().value()); |
279 | 277 |
280 Java_DownloadController_onDownloadCompleted(env, | 278 Java_DownloadController_onDownloadCompleted( |
281 GetJavaObject()->Controller(env).obj(), view_core.obj(), jurl.obj(), | 279 env, GetJavaObject()->Controller(env).obj(), |
282 jcontent_disposition.obj(), jmime_type.obj(), jpath.obj(), | 280 base::android::GetApplicationContext(), jurl.obj(), jmime_type.obj(), |
283 item->GetReceivedBytes(), true); | 281 jfilename.obj(), jpath.obj(), item->GetReceivedBytes(), true); |
284 } | 282 } |
285 | 283 |
286 void DownloadControllerAndroidImpl::OnDangerousDownload(DownloadItem* item) { | 284 void DownloadControllerAndroidImpl::OnDangerousDownload(DownloadItem* item) { |
287 JNIEnv* env = base::android::AttachCurrentThread(); | 285 JNIEnv* env = base::android::AttachCurrentThread(); |
288 ScopedJavaLocalRef<jstring> jfilename = ConvertUTF8ToJavaString( | 286 ScopedJavaLocalRef<jstring> jfilename = ConvertUTF8ToJavaString( |
289 env, item->GetTargetFilePath().BaseName().value()); | 287 env, item->GetTargetFilePath().BaseName().value()); |
290 ScopedJavaLocalRef<jobject> view_core = GetContentViewCoreFromWebContents( | 288 ScopedJavaLocalRef<jobject> view_core = GetContentViewCoreFromWebContents( |
291 item->GetWebContents()); | 289 item->GetWebContents()); |
292 if (!view_core.is_null()) { | 290 if (!view_core.is_null()) { |
293 Java_DownloadController_onDangerousDownload( | 291 Java_DownloadController_onDangerousDownload( |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 referer = referer_url.spec(); | 381 referer = referer_url.spec(); |
384 if (!request->url_chain().empty()) { | 382 if (!request->url_chain().empty()) { |
385 original_url = request->url_chain().front(); | 383 original_url = request->url_chain().front(); |
386 url = request->url_chain().back(); | 384 url = request->url_chain().back(); |
387 } | 385 } |
388 } | 386 } |
389 | 387 |
390 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} | 388 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} |
391 | 389 |
392 } // namespace content | 390 } // namespace content |
OLD | NEW |