OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/download_controller.h" | 5 #include "chrome/browser/android/download/download_controller.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/android/context_utils.h" | 10 #include "base/android/context_utils.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 224 |
225 bool DownloadController::HasFileAccessPermission( | 225 bool DownloadController::HasFileAccessPermission( |
226 ui::WindowAndroid* window_android) { | 226 ui::WindowAndroid* window_android) { |
227 ScopedJavaLocalRef<jobject> jwindow_android = window_android->GetJavaObject(); | 227 ScopedJavaLocalRef<jobject> jwindow_android = window_android->GetJavaObject(); |
228 | 228 |
229 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 229 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
230 DCHECK(!jwindow_android.is_null()); | 230 DCHECK(!jwindow_android.is_null()); |
231 | 231 |
232 JNIEnv* env = base::android::AttachCurrentThread(); | 232 JNIEnv* env = base::android::AttachCurrentThread(); |
233 return Java_DownloadController_hasFileAccess( | 233 return Java_DownloadController_hasFileAccess( |
234 env, GetJavaObject()->Controller(env).obj(), jwindow_android.obj()); | 234 env, GetJavaObject()->Controller(env), jwindow_android); |
235 } | 235 } |
236 | 236 |
237 void DownloadController::CreateGETDownload( | 237 void DownloadController::CreateGETDownload( |
238 int render_process_id, int render_view_id, bool must_download, | 238 int render_process_id, int render_view_id, bool must_download, |
239 const DownloadInfo& info) { | 239 const DownloadInfo& info) { |
240 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 240 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
241 | 241 |
242 // We are yielding the UI thread and render_view_host may go away by | 242 // We are yielding the UI thread and render_view_host may go away by |
243 // the time we come back. Pass along render_process_id and render_view_id | 243 // the time we come back. Pass along render_process_id and render_view_id |
244 // to retrieve it later (if it still exists). | 244 // to retrieve it later (if it still exists). |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 base_transition == ui::PAGE_TRANSITION_AUTO_BOOKMARK || | 338 base_transition == ui::PAGE_TRANSITION_AUTO_BOOKMARK || |
339 base_transition == ui::PAGE_TRANSITION_GENERATED || | 339 base_transition == ui::PAGE_TRANSITION_GENERATED || |
340 base_transition == ui::PAGE_TRANSITION_RELOAD || | 340 base_transition == ui::PAGE_TRANSITION_RELOAD || |
341 base_transition == ui::PAGE_TRANSITION_KEYWORD; | 341 base_transition == ui::PAGE_TRANSITION_KEYWORD; |
342 bool hasUserGesture = item->HasUserGesture() || user_initiated; | 342 bool hasUserGesture = item->HasUserGesture() || user_initiated; |
343 switch (item->GetState()) { | 343 switch (item->GetState()) { |
344 case DownloadItem::IN_PROGRESS: { | 344 case DownloadItem::IN_PROGRESS: { |
345 base::TimeDelta time_delta; | 345 base::TimeDelta time_delta; |
346 item->TimeRemaining(&time_delta); | 346 item->TimeRemaining(&time_delta); |
347 Java_DownloadController_onDownloadUpdated( | 347 Java_DownloadController_onDownloadUpdated( |
348 env, GetJavaObject()->Controller(env).obj(), jurl.obj(), | 348 env, GetJavaObject()->Controller(env), jurl, jmime_type, jfilename, |
349 jmime_type.obj(), jfilename.obj(), jpath.obj(), | 349 jpath, item->GetReceivedBytes(), jguid, item->PercentComplete(), |
350 item->GetReceivedBytes(), jguid.obj(), | 350 time_delta.InMilliseconds(), hasUserGesture, item->IsPaused(), |
351 item->PercentComplete(), time_delta.InMilliseconds(), | |
352 hasUserGesture, item->IsPaused(), | |
353 item->GetBrowserContext()->IsOffTheRecord()); | 351 item->GetBrowserContext()->IsOffTheRecord()); |
354 break; | 352 break; |
355 } | 353 } |
356 case DownloadItem::COMPLETE: | 354 case DownloadItem::COMPLETE: |
357 // Multiple OnDownloadUpdated() notifications may be issued while the | 355 // Multiple OnDownloadUpdated() notifications may be issued while the |
358 // download is in the COMPLETE state. Only handle one. | 356 // download is in the COMPLETE state. Only handle one. |
359 item->RemoveObserver(this); | 357 item->RemoveObserver(this); |
360 | 358 |
361 // Call onDownloadCompleted | 359 // Call onDownloadCompleted |
362 Java_DownloadController_onDownloadCompleted( | 360 Java_DownloadController_onDownloadCompleted( |
363 env, GetJavaObject()->Controller(env).obj(), jurl.obj(), | 361 env, GetJavaObject()->Controller(env), jurl, jmime_type, jfilename, |
364 jmime_type.obj(), jfilename.obj(), jpath.obj(), | 362 jpath, item->GetReceivedBytes(), jguid, joriginal_url, jreferrer_url, |
365 item->GetReceivedBytes(), jguid.obj(), | 363 hasUserGesture); |
366 joriginal_url.obj(), jreferrer_url.obj(), hasUserGesture); | |
367 DownloadController::RecordDownloadCancelReason( | 364 DownloadController::RecordDownloadCancelReason( |
368 DownloadController::CANCEL_REASON_NOT_CANCELED); | 365 DownloadController::CANCEL_REASON_NOT_CANCELED); |
369 break; | 366 break; |
370 case DownloadItem::CANCELLED: | 367 case DownloadItem::CANCELLED: |
371 Java_DownloadController_onDownloadCancelled( | 368 Java_DownloadController_onDownloadCancelled( |
372 env, GetJavaObject()->Controller(env).obj(), jguid.obj()); | 369 env, GetJavaObject()->Controller(env), jguid); |
373 break; | 370 break; |
374 case DownloadItem::INTERRUPTED: | 371 case DownloadItem::INTERRUPTED: |
375 // When device loses/changes network, we get a NETWORK_TIMEOUT, | 372 // When device loses/changes network, we get a NETWORK_TIMEOUT, |
376 // NETWORK_FAILED or NETWORK_DISCONNECTED error. Download should auto | 373 // NETWORK_FAILED or NETWORK_DISCONNECTED error. Download should auto |
377 // resume in this case. | 374 // resume in this case. |
378 Java_DownloadController_onDownloadInterrupted( | 375 Java_DownloadController_onDownloadInterrupted( |
379 env, GetJavaObject()->Controller(env).obj(), jurl.obj(), | 376 env, GetJavaObject()->Controller(env), jurl, jmime_type, jfilename, |
380 jmime_type.obj(), jfilename.obj(), jpath.obj(), | 377 jpath, item->GetReceivedBytes(), jguid, item->CanResume(), |
381 item->GetReceivedBytes(), jguid.obj(), | 378 IsInterruptedDownloadAutoResumable(item), |
382 item->CanResume(), IsInterruptedDownloadAutoResumable(item), | |
383 item->GetBrowserContext()->IsOffTheRecord()); | 379 item->GetBrowserContext()->IsOffTheRecord()); |
384 item->RemoveObserver(this); | 380 item->RemoveObserver(this); |
385 break; | 381 break; |
386 case DownloadItem::MAX_DOWNLOAD_STATE: | 382 case DownloadItem::MAX_DOWNLOAD_STATE: |
387 NOTREACHED(); | 383 NOTREACHED(); |
388 } | 384 } |
389 } | 385 } |
390 | 386 |
391 void DownloadController::OnDangerousDownload(DownloadItem* item) { | 387 void DownloadController::OnDangerousDownload(DownloadItem* item) { |
392 WebContents* web_contents = item->GetWebContents(); | 388 WebContents* web_contents = item->GetWebContents(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 if (!item) | 428 if (!item) |
433 return; | 429 return; |
434 if (accept) { | 430 if (accept) { |
435 item->ValidateDangerousDownload(); | 431 item->ValidateDangerousDownload(); |
436 } else { | 432 } else { |
437 DownloadController::RecordDownloadCancelReason( | 433 DownloadController::RecordDownloadCancelReason( |
438 DownloadController::CANCEL_REASON_DANGEROUS_DOWNLOAD_INFOBAR_DISMISSED); | 434 DownloadController::CANCEL_REASON_DANGEROUS_DOWNLOAD_INFOBAR_DISMISSED); |
439 item->Remove(); | 435 item->Remove(); |
440 } | 436 } |
441 } | 437 } |
OLD | NEW |