Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/download_manager.h" | 23 #include "content/public/browser/download_manager.h" |
| 24 #include "content/public/browser/download_url_parameters.h" | 24 #include "content/public/browser/download_url_parameters.h" |
| 25 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
| 26 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
| 27 #include "content/public/common/referrer.h" | 27 #include "content/public/common/referrer.h" |
| 28 #include "jni/DownloadController_jni.h" | 28 #include "jni/DownloadController_jni.h" |
| 29 #include "net/base/filename_util.h" | 29 #include "net/base/filename_util.h" |
| 30 #include "ui/android/view_android.h" | 30 #include "ui/android/view_android.h" |
| 31 #include "ui/android/window_android.h" | 31 #include "ui/android/window_android.h" |
| 32 #include "ui/base/page_transition_types.h" | |
| 32 | 33 |
| 33 using base::android::ConvertUTF8ToJavaString; | 34 using base::android::ConvertUTF8ToJavaString; |
| 34 using base::android::ScopedJavaLocalRef; | 35 using base::android::ScopedJavaLocalRef; |
| 35 using content::BrowserContext; | 36 using content::BrowserContext; |
| 36 using content::BrowserThread; | 37 using content::BrowserThread; |
| 37 using content::ContextMenuParams; | 38 using content::ContextMenuParams; |
| 38 using content::DownloadItem; | 39 using content::DownloadItem; |
| 39 using content::DownloadManager; | 40 using content::DownloadManager; |
| 40 using content::WebContents; | 41 using content::WebContents; |
| 41 | 42 |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 ConvertUTF8ToJavaString(env, item->GetMimeType()); | 316 ConvertUTF8ToJavaString(env, item->GetMimeType()); |
| 316 ScopedJavaLocalRef<jstring> jpath = | 317 ScopedJavaLocalRef<jstring> jpath = |
| 317 ConvertUTF8ToJavaString(env, item->GetTargetFilePath().value()); | 318 ConvertUTF8ToJavaString(env, item->GetTargetFilePath().value()); |
| 318 ScopedJavaLocalRef<jstring> jfilename = ConvertUTF8ToJavaString( | 319 ScopedJavaLocalRef<jstring> jfilename = ConvertUTF8ToJavaString( |
| 319 env, item->GetTargetFilePath().BaseName().value()); | 320 env, item->GetTargetFilePath().BaseName().value()); |
| 320 ScopedJavaLocalRef<jstring> joriginal_url = | 321 ScopedJavaLocalRef<jstring> joriginal_url = |
| 321 ConvertUTF8ToJavaString(env, item->GetOriginalUrl().spec()); | 322 ConvertUTF8ToJavaString(env, item->GetOriginalUrl().spec()); |
| 322 ScopedJavaLocalRef<jstring> jreferrer_url = | 323 ScopedJavaLocalRef<jstring> jreferrer_url = |
| 323 ConvertUTF8ToJavaString(env, item->GetReferrerUrl().spec()); | 324 ConvertUTF8ToJavaString(env, item->GetReferrerUrl().spec()); |
| 324 | 325 |
| 326 ui::PageTransition base_transition = | |
| 327 ui::PageTransitionStripQualifier(item->GetTransitionType()); | |
| 328 bool user_initiated = | |
| 329 item->GetTransitionType() & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR || | |
| 330 base_transition == ui::PAGE_TRANSITION_TYPED || | |
|
Ted C
2016/06/22 23:58:03
could we use !PageTransitionIsWebTriggerable here
qinmin
2016/06/23 18:20:11
!PageTransitionIsWebTriggerable could be too broad
| |
| 331 base_transition == ui::PAGE_TRANSITION_AUTO_BOOKMARK || | |
| 332 base_transition == ui::PAGE_TRANSITION_GENERATED || | |
| 333 base_transition == ui::PAGE_TRANSITION_RELOAD || | |
| 334 base_transition == ui::PAGE_TRANSITION_KEYWORD; | |
| 335 bool hasUserGesture = item->HasUserGesture() || user_initiated; | |
| 325 switch (item->GetState()) { | 336 switch (item->GetState()) { |
| 326 case DownloadItem::IN_PROGRESS: { | 337 case DownloadItem::IN_PROGRESS: { |
| 327 base::TimeDelta time_delta; | 338 base::TimeDelta time_delta; |
| 328 item->TimeRemaining(&time_delta); | 339 item->TimeRemaining(&time_delta); |
| 329 Java_DownloadController_onDownloadUpdated( | 340 Java_DownloadController_onDownloadUpdated( |
| 330 env, GetJavaObject()->Controller(env).obj(), jurl.obj(), | 341 env, GetJavaObject()->Controller(env).obj(), jurl.obj(), |
| 331 jmime_type.obj(), jfilename.obj(), jpath.obj(), | 342 jmime_type.obj(), jfilename.obj(), jpath.obj(), |
| 332 item->GetReceivedBytes(), jguid.obj(), | 343 item->GetReceivedBytes(), jguid.obj(), |
| 333 item->PercentComplete(), time_delta.InMilliseconds(), | 344 item->PercentComplete(), time_delta.InMilliseconds(), |
| 334 item->HasUserGesture(), item->IsPaused(), | 345 hasUserGesture, item->IsPaused(), |
| 335 item->GetBrowserContext()->IsOffTheRecord()); | 346 item->GetBrowserContext()->IsOffTheRecord()); |
| 336 break; | 347 break; |
| 337 } | 348 } |
| 338 case DownloadItem::COMPLETE: | 349 case DownloadItem::COMPLETE: |
| 339 // Multiple OnDownloadUpdated() notifications may be issued while the | 350 // Multiple OnDownloadUpdated() notifications may be issued while the |
| 340 // download is in the COMPLETE state. Only handle one. | 351 // download is in the COMPLETE state. Only handle one. |
| 341 item->RemoveObserver(this); | 352 item->RemoveObserver(this); |
| 342 | 353 |
| 343 // Call onDownloadCompleted | 354 // Call onDownloadCompleted |
| 344 Java_DownloadController_onDownloadCompleted( | 355 Java_DownloadController_onDownloadCompleted( |
| 345 env, GetJavaObject()->Controller(env).obj(), jurl.obj(), | 356 env, GetJavaObject()->Controller(env).obj(), jurl.obj(), |
| 346 jmime_type.obj(), jfilename.obj(), jpath.obj(), | 357 jmime_type.obj(), jfilename.obj(), jpath.obj(), |
| 347 item->GetReceivedBytes(), jguid.obj(), | 358 item->GetReceivedBytes(), jguid.obj(), |
| 348 joriginal_url.obj(), jreferrer_url.obj(), item->HasUserGesture()); | 359 joriginal_url.obj(), jreferrer_url.obj(), hasUserGesture); |
| 349 DownloadController::RecordDownloadCancelReason( | 360 DownloadController::RecordDownloadCancelReason( |
| 350 DownloadController::CANCEL_REASON_NOT_CANCELED); | 361 DownloadController::CANCEL_REASON_NOT_CANCELED); |
| 351 break; | 362 break; |
| 352 case DownloadItem::CANCELLED: | 363 case DownloadItem::CANCELLED: |
| 353 Java_DownloadController_onDownloadCancelled( | 364 Java_DownloadController_onDownloadCancelled( |
| 354 env, GetJavaObject()->Controller(env).obj(), jguid.obj()); | 365 env, GetJavaObject()->Controller(env).obj(), jguid.obj()); |
| 355 break; | 366 break; |
| 356 case DownloadItem::INTERRUPTED: | 367 case DownloadItem::INTERRUPTED: |
| 357 // When device loses/changes network, we get a NETWORK_TIMEOUT, | 368 // When device loses/changes network, we get a NETWORK_TIMEOUT, |
| 358 // NETWORK_FAILED or NETWORK_DISCONNECTED error. Download should auto | 369 // NETWORK_FAILED or NETWORK_DISCONNECTED error. Download should auto |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 DownloadManager* dlm = | 422 DownloadManager* dlm = |
| 412 BrowserContext::GetDownloadManager(web_contents->GetBrowserContext()); | 423 BrowserContext::GetDownloadManager(web_contents->GetBrowserContext()); |
| 413 DownloadItem* item = dlm->GetDownloadByGuid(download_guid); | 424 DownloadItem* item = dlm->GetDownloadByGuid(download_guid); |
| 414 if (!item) | 425 if (!item) |
| 415 return; | 426 return; |
| 416 if (accept) | 427 if (accept) |
| 417 item->ValidateDangerousDownload(); | 428 item->ValidateDangerousDownload(); |
| 418 else | 429 else |
| 419 item->Remove(); | 430 item->Remove(); |
| 420 } | 431 } |
| OLD | NEW |