Index: ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java |
diff --git a/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java b/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java |
index 070443d4d3afedb375ca23d2e9c35e34ad4d15e7..3e61ea3c1184d4af1ea447f0bd4e4de551713e9b 100644 |
--- a/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java |
+++ b/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java |
@@ -6,9 +6,11 @@ package org.chromium.ui.base; |
import android.annotation.TargetApi; |
import android.app.Activity; |
+import android.app.AlertDialog; |
import android.content.ClipData; |
import android.content.ContentResolver; |
import android.content.Context; |
+import android.content.DialogInterface; |
import android.content.Intent; |
import android.net.Uri; |
import android.os.AsyncTask; |
@@ -24,6 +26,7 @@ import org.chromium.ui.R; |
import java.io.File; |
import java.io.IOException; |
+import java.lang.ref.WeakReference; |
import java.util.ArrayList; |
import java.util.Arrays; |
import java.util.List; |
@@ -56,6 +59,55 @@ class SelectFileDialog implements WindowAndroid.IntentCallback { |
} |
/** |
+ * Show a dialog asking whether a user wants to overwrite an existing file. |
+ * |
+ * <p>You will see this if you try to download a file when there already exists a file with |
+ * the same name. |
+ * |
+ * @param path The file path that may be overridden. |
+ * @param window The WindowAndroid that can launch a dialog. |
+ */ |
+ @CalledByNative |
+ public void showOverwriteDialog(final String path, final WindowAndroid window) { |
Ted C
2014/09/19 22:31:40
I think this is only called from native right? It
Changwan Ryu
2014/09/22 14:02:37
Done.
|
+ WeakReference<Activity> weakRefActivity = window.getActivity(); |
+ Activity activity = weakRefActivity.get(); |
+ if (activity == null) { |
+ onFileNotSelected(); |
+ return; |
+ } |
+ String title = activity.getResources().getString(R.string.file_overwrite_dialog_title); |
+ String message = activity.getResources().getString(R.string.file_overwrite_dialog_message); |
+ new AlertDialog.Builder(activity) |
+ .setTitle(title) |
+ .setMessage(message) |
+ .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { |
+ @Override |
+ public void onClick(DialogInterface dialog, int which) { |
+ nativeOnFileSelected(mNativeSelectFileDialog, path, |
+ path); |
Ted C
2014/09/19 22:31:40
this should fit on the prior line now.
Changwan Ryu
2014/09/22 14:02:37
Done.
|
+ } |
+ }) |
+ .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { |
+ @Override |
+ public void onClick(DialogInterface dialog, int which) { |
+ String newUniquePath = nativeGetUniqueFilePath(mNativeSelectFileDialog, path); |
+ if (!TextUtils.isEmpty(newUniquePath)) { |
+ nativeOnFileSelected(mNativeSelectFileDialog, newUniquePath, newUniquePath); |
+ } else { |
+ window.showError(R.string.failed_to_get_unique_path_error); |
+ } |
+ } |
+ }) |
+ .setOnDismissListener(new DialogInterface.OnDismissListener() { |
+ @Override |
+ public void onDismiss(DialogInterface dialog) { |
+ onFileNotSelected(); |
+ } |
+ }) |
+ .show(); |
+ } |
+ |
+ /** |
* Creates and starts an intent based on the passed fileTypes and capture value. |
* @param fileTypes MIME types requested (i.e. "image/*") |
* @param capture The capture value as described in http://www.w3.org/TR/html-media-capture/ |
@@ -66,7 +118,9 @@ class SelectFileDialog implements WindowAndroid.IntentCallback { |
@CalledByNative |
private void selectFile( |
String[] fileTypes, boolean capture, boolean multiple, WindowAndroid window) { |
+ |
qinmin
2014/09/20 05:06:58
remove this line
Changwan Ryu
2014/09/22 14:02:37
Done.
|
mFileTypes = new ArrayList<String>(Arrays.asList(fileTypes)); |
+ |
mCapture = capture; |
Intent chooser = new Intent(Intent.ACTION_CHOOSER); |
@@ -340,4 +394,5 @@ class SelectFileDialog implements WindowAndroid.IntentCallback { |
private native void nativeOnMultipleFilesSelected(long nativeSelectFileDialogImpl, |
String[] filePathArray, String[] displayNameArray); |
private native void nativeOnFileNotSelected(long nativeSelectFileDialogImpl); |
+ private native String nativeGetUniqueFilePath(long nativeSelectFileDialogImpl, String path); |
} |