Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/download/ChromeDownloadDelegate.java

Issue 580043002: [Android] Prompt with infobar on filename conflict (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed nits Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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) {
qinmin 2015/02/20 01:00:40 java doc
Changwan Ryu 2015/02/23 06:50:37 Done.
+ 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() {
Ted C 2015/02/20 01:48:08 We are really trying to avoid any java only infoba
Changwan Ryu 2015/02/23 06:50:37 Hmm... I don't have a clear idea how this should b
Ted C 2015/02/23 18:48:15 Couldn't you just have a different native Download
+ @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();

Powered by Google App Engine
This is Rietveld 408576698