| 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 ScopedJavaLocalRef<jstring> jreferer = | 229 ScopedJavaLocalRef<jstring> jreferer = |
| 230 ConvertUTF8ToJavaString(env, info.referer); | 230 ConvertUTF8ToJavaString(env, info.referer); |
| 231 | 231 |
| 232 Java_DownloadController_newHttpGetDownload( | 232 Java_DownloadController_newHttpGetDownload( |
| 233 env, GetJavaObject()->Controller(env).obj(), view.obj(), jurl.obj(), | 233 env, GetJavaObject()->Controller(env).obj(), view.obj(), jurl.obj(), |
| 234 juser_agent.obj(), jcontent_disposition.obj(), jmime_type.obj(), | 234 juser_agent.obj(), jcontent_disposition.obj(), jmime_type.obj(), |
| 235 jcookie.obj(), jreferer.obj(), info.total_bytes); | 235 jcookie.obj(), jreferer.obj(), info.total_bytes); |
| 236 } | 236 } |
| 237 | 237 |
| 238 void DownloadControllerAndroidImpl::OnPostDownloadStarted( | 238 void DownloadControllerAndroidImpl::OnPostDownloadStarted( |
| 239 WebContents* web_contents, | |
| 240 DownloadItem* download_item) { | 239 DownloadItem* download_item) { |
| 241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 241 if (!download_item->GetWebContents()) |
| 242 return; |
| 243 |
| 242 JNIEnv* env = AttachCurrentThread(); | 244 JNIEnv* env = AttachCurrentThread(); |
| 243 | 245 |
| 244 // Register for updates to the DownloadItem. | 246 // Register for updates to the DownloadItem. |
| 245 download_item->AddObserver(this); | 247 download_item->AddObserver(this); |
| 246 | 248 |
| 247 ScopedJavaLocalRef<jobject> view = | 249 ScopedJavaLocalRef<jobject> view = |
| 248 GetContentViewCoreFromWebContents(web_contents); | 250 GetContentViewCoreFromWebContents(download_item->GetWebContents()); |
| 249 // The view went away. Can't proceed. | 251 // The view went away. Can't proceed. |
| 250 if (view.is_null()) | 252 if (view.is_null()) |
| 251 return; | 253 return; |
| 252 | 254 |
| 253 Java_DownloadController_onHttpPostDownloadStarted( | 255 Java_DownloadController_onHttpPostDownloadStarted( |
| 254 env, GetJavaObject()->Controller(env).obj(), view.obj()); | 256 env, GetJavaObject()->Controller(env).obj(), view.obj()); |
| 255 } | 257 } |
| 256 | 258 |
| 257 void DownloadControllerAndroidImpl::OnDownloadUpdated(DownloadItem* item) { | 259 void DownloadControllerAndroidImpl::OnDownloadUpdated(DownloadItem* item) { |
| 258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 259 | 261 |
| 260 if (item->GetState() != DownloadItem::COMPLETE) | 262 if (!item->IsComplete()) |
| 261 return; | 263 return; |
| 262 | 264 |
| 265 // Multiple OnDownloadUpdated() notifications may be issued while the download |
| 266 // is in the COMPLETE state. Only handle one. |
| 267 item->RemoveObserver(this); |
| 268 |
| 263 // Call onHttpPostDownloadCompleted | 269 // Call onHttpPostDownloadCompleted |
| 264 JNIEnv* env = AttachCurrentThread(); | 270 JNIEnv* env = AttachCurrentThread(); |
| 265 ScopedJavaLocalRef<jstring> jurl = | 271 ScopedJavaLocalRef<jstring> jurl = |
| 266 ConvertUTF8ToJavaString(env, item->GetURL().spec()); | 272 ConvertUTF8ToJavaString(env, item->GetURL().spec()); |
| 267 ScopedJavaLocalRef<jstring> jcontent_disposition = | 273 ScopedJavaLocalRef<jstring> jcontent_disposition = |
| 268 ConvertUTF8ToJavaString(env, item->GetContentDisposition()); | 274 ConvertUTF8ToJavaString(env, item->GetContentDisposition()); |
| 269 ScopedJavaLocalRef<jstring> jmime_type = | 275 ScopedJavaLocalRef<jstring> jmime_type = |
| 270 ConvertUTF8ToJavaString(env, item->GetMimeType()); | 276 ConvertUTF8ToJavaString(env, item->GetMimeType()); |
| 271 ScopedJavaLocalRef<jstring> jpath = | 277 ScopedJavaLocalRef<jstring> jpath = |
| 272 ConvertUTF8ToJavaString(env, item->GetFullPath().value()); | 278 ConvertUTF8ToJavaString(env, item->GetFullPath().value()); |
| 273 | 279 |
| 274 ScopedJavaLocalRef<jobject> view_core = GetContentViewCoreFromWebContents( | 280 ScopedJavaLocalRef<jobject> view_core = GetContentViewCoreFromWebContents( |
| 275 item->GetWebContents()); | 281 item->GetWebContents()); |
| 276 if (view_core.is_null()) { | 282 if (view_core.is_null()) { |
| 277 // We can get NULL WebContents from the DownloadItem. | 283 // We can get NULL WebContents from the DownloadItem. |
| 278 return; | 284 return; |
| 279 } | 285 } |
| 280 | 286 |
| 281 Java_DownloadController_onHttpPostDownloadCompleted(env, | 287 Java_DownloadController_onHttpPostDownloadCompleted(env, |
| 282 GetJavaObject()->Controller(env).obj(), view_core.obj(), jurl.obj(), | 288 GetJavaObject()->Controller(env).obj(), view_core.obj(), jurl.obj(), |
| 283 jcontent_disposition.obj(), jmime_type.obj(), jpath.obj(), | 289 jcontent_disposition.obj(), jmime_type.obj(), jpath.obj(), |
| 284 item->GetReceivedBytes(), true); | 290 item->GetReceivedBytes(), true); |
| 285 } | 291 } |
| 286 | 292 |
| 287 void DownloadControllerAndroidImpl::OnDownloadOpened(DownloadItem* item) { | |
| 288 } | |
| 289 | |
| 290 ScopedJavaLocalRef<jobject> DownloadControllerAndroidImpl::GetContentView( | 293 ScopedJavaLocalRef<jobject> DownloadControllerAndroidImpl::GetContentView( |
| 291 int render_process_id, int render_view_id) { | 294 int render_process_id, int render_view_id) { |
| 292 RenderViewHost* render_view_host = | 295 RenderViewHost* render_view_host = |
| 293 RenderViewHost::FromID(render_process_id, render_view_id); | 296 RenderViewHost::FromID(render_process_id, render_view_id); |
| 294 | 297 |
| 295 if (!render_view_host) | 298 if (!render_view_host) |
| 296 return ScopedJavaLocalRef<jobject>(); | 299 return ScopedJavaLocalRef<jobject>(); |
| 297 | 300 |
| 298 WebContents* web_contents = | 301 WebContents* web_contents = |
| 299 render_view_host->GetDelegate()->GetAsWebContents(); | 302 render_view_host->GetDelegate()->GetAsWebContents(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 referer = referer_url.spec(); | 353 referer = referer_url.spec(); |
| 351 if (!request->url_chain().empty()) { | 354 if (!request->url_chain().empty()) { |
| 352 original_url = request->url_chain().front(); | 355 original_url = request->url_chain().front(); |
| 353 url = request->url_chain().back(); | 356 url = request->url_chain().back(); |
| 354 } | 357 } |
| 355 } | 358 } |
| 356 | 359 |
| 357 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} | 360 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} |
| 358 | 361 |
| 359 } // namespace content | 362 } // namespace content |
| OLD | NEW |