| Index: chrome/android/java/src/org/chromium/chrome/browser/download/ChromeDownloadDelegate.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/ChromeDownloadDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/download/ChromeDownloadDelegate.java
|
| index d03d98fb8ab7aff8fb84a599da3c6782847c23bc..9b182d3496b9acad17eae3740dff728447b3f113 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/download/ChromeDownloadDelegate.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/download/ChromeDownloadDelegate.java
|
| @@ -22,6 +22,7 @@ import org.chromium.base.VisibleForTesting;
|
| import org.chromium.chrome.R;
|
| import org.chromium.chrome.browser.Tab;
|
| import org.chromium.chrome.browser.infobar.ConfirmInfoBar;
|
| +import org.chromium.chrome.browser.infobar.DownloadOverwriteInfoBar;
|
| import org.chromium.chrome.browser.infobar.InfoBar;
|
| import org.chromium.chrome.browser.infobar.InfoBarListeners;
|
| import org.chromium.chrome.browser.tabmodel.TabModelSelector;
|
| @@ -306,12 +307,56 @@ public class ChromeDownloadDelegate
|
| confirmDangerousDownload(downloadInfo);
|
| }
|
|
|
| + private boolean launchInfoBarIfFileExists(final DownloadInfo info) {
|
| + String fileName = info.getFileName();
|
| + File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
|
| + if (!dir.mkdir() && !dir.isDirectory()) return false;
|
| + String dirName = dir.getName();
|
| + final File file = new File(dir, info.getFileName());
|
| + String fullDirPath = file.getParent();
|
| + if (!file.exists()) return false;
|
| + if (TextUtils.isEmpty(fileName) || TextUtils.isEmpty(dirName)
|
| + || TextUtils.isEmpty(fullDirPath)) {
|
| + return false;
|
| + }
|
| +
|
| + InfoBar infoBar = new DownloadOverwriteInfoBar(0, new DownloadOverwriteInfoBar.Callback() {
|
| + @Override
|
| + public void onCloseButtonClicked(DownloadOverwriteInfoBar infoBar) {
|
| + infoBar.dismissJavaOnlyInfoBar();
|
| + }
|
| +
|
| + @Override
|
| + public void onAction(DownloadOverwriteInfoBar infoBar, int action) {
|
| + if (action == InfoBar.ACTION_TYPE_OVERWRITE) {
|
| + // Android DownloadManager does not have an overwriting option.
|
| + // We remove the file here instead.
|
| + file.delete();
|
| + }
|
| + if (action == InfoBar.ACTION_TYPE_OVERWRITE
|
| + || action == InfoBar.ACTION_TYPE_CREATE_NEW_FILE) {
|
| + enqueueDownloadManagerRequestInternal(info);
|
| + }
|
| + infoBar.dismissJavaOnlyInfoBar();
|
| + }
|
| + }, fileName, dirName, fullDirPath);
|
| + infoBar.setExpireOnNavigation(false);
|
| + mTab.getInfoBarContainer().addInfoBar(infoBar);
|
| + return true;
|
| + }
|
| +
|
| /**
|
| * Sends the download request to Android download manager.
|
| *
|
| * @param info Download information about the download.
|
| */
|
| protected void enqueueDownloadManagerRequest(final DownloadInfo info) {
|
| + if (!launchInfoBarIfFileExists(info)) {
|
| + enqueueDownloadManagerRequestInternal(info);
|
| + }
|
| + }
|
| +
|
| + private void enqueueDownloadManagerRequestInternal(final DownloadInfo info) {
|
| DownloadManagerService.getDownloadManagerService(
|
| mContext.getApplicationContext()).enqueueDownloadManagerRequest(info, true);
|
| closeBlankTab();
|
|
|