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

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: add a test 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..316ba8ca7cdea2b81f7f6fda34e0c7dfc99d7482 100644
--- a/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
+++ b/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
@@ -5,6 +5,7 @@
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;
@@ -50,10 +51,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 +81,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 +190,32 @@ 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.
+ if (results.getData() == null && results.getClipData() != null) {
Miguel Garcia 2014/08/05 18:01:00 can you check that the |results| intent in fact co
Peter Beverloo 2014/08/05 18:44:53 |results| is the resulting Intent, not the content
+ 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 +295,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