| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 package org.chromium.chrome.browser.download; | 5 package org.chromium.chrome.browser.download; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.app.DownloadManager; | 8 import android.app.DownloadManager; |
| 9 import android.content.ActivityNotFoundException; | 9 import android.content.ActivityNotFoundException; |
| 10 import android.content.BroadcastReceiver; | 10 import android.content.BroadcastReceiver; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 import org.chromium.base.ContextUtils; | 27 import org.chromium.base.ContextUtils; |
| 28 import org.chromium.base.Log; | 28 import org.chromium.base.Log; |
| 29 import org.chromium.base.ObserverList; | 29 import org.chromium.base.ObserverList; |
| 30 import org.chromium.base.ThreadUtils; | 30 import org.chromium.base.ThreadUtils; |
| 31 import org.chromium.base.VisibleForTesting; | 31 import org.chromium.base.VisibleForTesting; |
| 32 import org.chromium.base.annotations.CalledByNative; | 32 import org.chromium.base.annotations.CalledByNative; |
| 33 import org.chromium.base.annotations.SuppressFBWarnings; | 33 import org.chromium.base.annotations.SuppressFBWarnings; |
| 34 import org.chromium.base.metrics.RecordHistogram; | 34 import org.chromium.base.metrics.RecordHistogram; |
| 35 import org.chromium.chrome.R; | 35 import org.chromium.chrome.R; |
| 36 import org.chromium.chrome.browser.ChromeActivity; | 36 import org.chromium.chrome.browser.ChromeActivity; |
| 37 import org.chromium.chrome.browser.ChromeFeatureList; | |
| 38 import org.chromium.chrome.browser.download.ui.BackendProvider; | 37 import org.chromium.chrome.browser.download.ui.BackendProvider; |
| 39 import org.chromium.chrome.browser.download.ui.DownloadHistoryAdapter; | 38 import org.chromium.chrome.browser.download.ui.DownloadHistoryAdapter; |
| 40 import org.chromium.chrome.browser.externalnav.ExternalNavigationDelegateImpl; | 39 import org.chromium.chrome.browser.externalnav.ExternalNavigationDelegateImpl; |
| 41 import org.chromium.net.ConnectionType; | 40 import org.chromium.net.ConnectionType; |
| 42 import org.chromium.net.NetworkChangeNotifierAutoDetect; | 41 import org.chromium.net.NetworkChangeNotifierAutoDetect; |
| 43 import org.chromium.net.RegistrationPolicyAlwaysRegister; | 42 import org.chromium.net.RegistrationPolicyAlwaysRegister; |
| 44 import org.chromium.ui.widget.Toast; | 43 import org.chromium.ui.widget.Toast; |
| 45 | 44 |
| 46 import java.io.File; | 45 import java.io.File; |
| 47 import java.util.ArrayList; | 46 import java.util.ArrayList; |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 } | 771 } |
| 773 } | 772 } |
| 774 } | 773 } |
| 775 | 774 |
| 776 /** | 775 /** |
| 777 * Sends the download request to Android download manager. If |notifyComplet
ed| is true, | 776 * Sends the download request to Android download manager. If |notifyComplet
ed| is true, |
| 778 * a notification will be sent to the user once download is complete and the
downloaded | 777 * a notification will be sent to the user once download is complete and the
downloaded |
| 779 * content will be saved to the public directory on external storage. Otherw
ise, the | 778 * content will be saved to the public directory on external storage. Otherw
ise, the |
| 780 * download will be saved in the app directory and user will not get any not
ifications | 779 * download will be saved in the app directory and user will not get any not
ifications |
| 781 * after download completion. | 780 * after download completion. |
| 781 * This will be used by OMA downloads as we need Android DownloadManager to
encrypt the content. |
| 782 * TODO(qinmin): move this to DownloadManagerDelegate. | 782 * TODO(qinmin): move this to DownloadManagerDelegate. |
| 783 * | 783 * |
| 784 * @param info Download information about the download. | 784 * @param info Download information about the download. |
| 785 * @param notifyCompleted Whether to notify the user after Downloadmanager c
ompletes the | 785 * @param notifyCompleted Whether to notify the user after Downloadmanager c
ompletes the |
| 786 * download. | 786 * download. |
| 787 */ | 787 */ |
| 788 public void enqueueDownloadManagerRequest( | 788 public void enqueueDownloadManagerRequest( |
| 789 final DownloadItem item, boolean notifyCompleted) { | 789 final DownloadItem item, boolean notifyCompleted) { |
| 790 EnqueueDownloadRequestTask task = new EnqueueDownloadRequestTask(item); | 790 EnqueueDownloadRequestTask task = new EnqueueDownloadRequestTask(item); |
| 791 task.execute(notifyCompleted); | 791 task.execute(notifyCompleted); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 protected void setDownloadSnackbarController( | 1056 protected void setDownloadSnackbarController( |
| 1057 DownloadSnackbarController downloadSnackbarController) { | 1057 DownloadSnackbarController downloadSnackbarController) { |
| 1058 mDownloadSnackbarController = downloadSnackbarController; | 1058 mDownloadSnackbarController = downloadSnackbarController; |
| 1059 } | 1059 } |
| 1060 | 1060 |
| 1061 /** | 1061 /** |
| 1062 * Open the Activity which shows a list of all downloads. | 1062 * Open the Activity which shows a list of all downloads. |
| 1063 * @param context Application context | 1063 * @param context Application context |
| 1064 */ | 1064 */ |
| 1065 protected static void openDownloadsPage(Context context) { | 1065 protected static void openDownloadsPage(Context context) { |
| 1066 if (!ChromeFeatureList.isEnabled(ChromeFeatureList.SYSTEM_DOWNLOAD_MANAG
ER)) { | 1066 // Try to open Download Home. |
| 1067 // Try to open Download Home. | 1067 Activity lastActivity = ApplicationStatus.getLastTrackedFocusedActivity(
); |
| 1068 Activity lastActivity = ApplicationStatus.getLastTrackedFocusedActiv
ity(); | 1068 if (lastActivity instanceof ChromeActivity) { |
| 1069 if (lastActivity instanceof ChromeActivity) { | 1069 int state = ApplicationStatus.getStateForActivity(lastActivity); |
| 1070 int state = ApplicationStatus.getStateForActivity(lastActivity); | 1070 if (state >= ActivityState.CREATED && state <= ActivityState.RESUMED
) { |
| 1071 if (state >= ActivityState.CREATED && state <= ActivityState.RES
UMED) { | 1071 ChromeActivity chromeActivity = (ChromeActivity) lastActivity; |
| 1072 ChromeActivity chromeActivity = (ChromeActivity) lastActivit
y; | 1072 DownloadUtils.showDownloadManager( |
| 1073 DownloadUtils.showDownloadManager( | 1073 lastActivity, chromeActivity.getActivityTab()); |
| 1074 lastActivity, chromeActivity.getActivityTab()); | 1074 return; |
| 1075 return; | |
| 1076 } | |
| 1077 } | 1075 } |
| 1078 } | 1076 } |
| 1079 | 1077 |
| 1080 // Open the Android Download Manager. | 1078 // Open the Android Download Manager. |
| 1081 Intent pageView = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS); | 1079 Intent pageView = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS); |
| 1082 pageView.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 1080 pageView.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1083 try { | 1081 try { |
| 1084 context.startActivity(pageView); | 1082 context.startActivity(pageView); |
| 1085 } catch (ActivityNotFoundException e) { | 1083 } catch (ActivityNotFoundException e) { |
| 1086 Log.e(TAG, "Cannot find Downloads app", e); | 1084 Log.e(TAG, "Cannot find Downloads app", e); |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1657 boolean isNotificationDismissed); | 1655 boolean isNotificationDismissed); |
| 1658 private native void nativePauseDownload(long nativeDownloadManagerService, S
tring downloadGuid, | 1656 private native void nativePauseDownload(long nativeDownloadManagerService, S
tring downloadGuid, |
| 1659 boolean isOffTheRecord); | 1657 boolean isOffTheRecord); |
| 1660 private native void nativeRemoveDownload(long nativeDownloadManagerService,
String downloadGuid, | 1658 private native void nativeRemoveDownload(long nativeDownloadManagerService,
String downloadGuid, |
| 1661 boolean isOffTheRecord); | 1659 boolean isOffTheRecord); |
| 1662 private native void nativeGetAllDownloads( | 1660 private native void nativeGetAllDownloads( |
| 1663 long nativeDownloadManagerService, boolean isOffTheRecord); | 1661 long nativeDownloadManagerService, boolean isOffTheRecord); |
| 1664 private native void nativeCheckForExternallyRemovedDownloads( | 1662 private native void nativeCheckForExternallyRemovedDownloads( |
| 1665 long nativeDownloadManagerService, boolean isOffTheRecord); | 1663 long nativeDownloadManagerService, boolean isOffTheRecord); |
| 1666 } | 1664 } |
| OLD | NEW |