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

Unified Diff: ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java

Issue 443683002: Allow <input type="file" multiple /> to be used on Android JB MR2+. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 6 years, 4 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: 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 7391ac5ba349667b937c9d7b9d1eb03b7f579ecf..ae9ce199282543e6cb1b7af1d31063be9a39e8eb 100644
--- a/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
+++ b/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
@@ -5,10 +5,12 @@
package org.chromium.ui.base;
import android.app.Activity;
+import android.content.ClipData;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
+import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.TextUtils;
@@ -50,10 +52,12 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{
* 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/
+ * @param multiple Whether it should be possible to select multiple files.
* @param window The WindowAndroid that can show intents
*/
@CalledByNative
- private void selectFile(String[] fileTypes, boolean capture, WindowAndroid window) {
+ private void selectFile(
+ String[] fileTypes, boolean capture, boolean multiple, WindowAndroid window) {
mFileTypes = new ArrayList<String>(Arrays.asList(fileTypes));
mCapture = capture;
@@ -78,6 +82,10 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{
Intent getContentIntent = new Intent(Intent.ACTION_GET_CONTENT);
getContentIntent.addCategory(Intent.CATEGORY_OPENABLE);
+
+ if (multiple)
+ getContentIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
+
ArrayList<Intent> extraIntents = new ArrayList<Intent>();
if (!noSpecificType()) {
// Create a chooser based on the accept type that was specified in the webpage. Note
@@ -183,6 +191,35 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{
return;
}
+ // Path for when EXTRA_ALLOW_MULTIPLE Intent extra has been defined. Each of the selected
+ // files will be shared as an entry on the Intent's ClipData. This functionality is only
+ // available in Android JellyBean MR2 and higher.
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 &&
+ results.getData() == null &&
+ results.getClipData() != null) {
+ ClipData clipData = results.getClipData();
+
+ int itemCount = clipData.getItemCount();
+ if (itemCount == 0) {
+ onFileNotSelected();
+ return;
+ }
+
+ String[] filePathArray = new String[itemCount];
+ String[] displayNameArray = new String[itemCount];
+
+ for (int i = 0; i < itemCount; ++i) {
+ final Uri uri = clipData.getItemAt(i).getUri();
+
+ filePathArray[i] = uri.toString();
+ displayNameArray[i] = resolveFileName(uri, contentResolver);
+ }
+
+ nativeOnMultipleFilesSelected(mNativeSelectFileDialog,
+ filePathArray, displayNameArray);
+ return;
+ }
+
if (ContentResolver.SCHEME_FILE.equals(results.getData().getScheme())) {
nativeOnFileSelected(mNativeSelectFileDialog,
results.getData().getSchemeSpecificPart(), "");
@@ -262,5 +299,7 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{
private native void nativeOnFileSelected(long nativeSelectFileDialogImpl,
String filePath, String displayName);
+ private native void nativeOnMultipleFilesSelected(long nativeSelectFileDialogImpl,
+ String[] filePathArray, String[] displayNameArray);
private native void nativeOnFileNotSelected(long nativeSelectFileDialogImpl);
}

Powered by Google App Engine
This is Rietveld 408576698