| 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 52ceac947789d5c10861daa5011adfd0ede7e40e..05186ebc77fc76b1e6f110d6777b1f1301508844 100644
|
| --- a/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
|
| +++ b/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
|
| @@ -9,14 +9,15 @@ 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.AsyncTask;
|
| import android.os.Build;
|
| import android.os.Environment;
|
| import android.provider.MediaStore;
|
| import android.text.TextUtils;
|
|
|
| import org.chromium.base.CalledByNative;
|
| +import org.chromium.base.ContentUriUtils;
|
| import org.chromium.base.JNINamespace;
|
| import org.chromium.ui.R;
|
|
|
| @@ -140,31 +141,6 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{
|
| }
|
|
|
| /**
|
| - * @return the display name of the @code uri if present in the database
|
| - * or an empty string otherwise.
|
| - */
|
| - private String resolveFileName(Uri uri, ContentResolver contentResolver) {
|
| - if (contentResolver == null || uri == null) return "";
|
| - Cursor cursor = null;
|
| - try {
|
| - cursor = contentResolver.query(uri, null, null, null, null);
|
| -
|
| - if (cursor != null && cursor.getCount() >= 1) {
|
| - cursor.moveToFirst();
|
| - int index = cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME);
|
| - if (index > -1) return cursor.getString(index);
|
| - }
|
| - } catch (NullPointerException e) {
|
| - // Some android models don't handle the provider call correctly.
|
| - // see crbug.com/345393
|
| - return "";
|
| - } finally {
|
| - if (cursor != null) cursor.close();
|
| - }
|
| - return "";
|
| - }
|
| -
|
| - /**
|
| * Callback method to handle the intent results and pass on the path to the native
|
| * SelectFileDialog.
|
| * @param window The window that has access to the application activity.
|
| @@ -208,18 +184,12 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{
|
| return;
|
| }
|
|
|
| - String[] filePathArray = new String[itemCount];
|
| - String[] displayNameArray = new String[itemCount];
|
| -
|
| + Uri[] filePathArray = new Uri[itemCount];
|
| for (int i = 0; i < itemCount; ++i) {
|
| - final Uri uri = clipData.getItemAt(i).getUri();
|
| -
|
| - filePathArray[i] = uri.toString();
|
| - displayNameArray[i] = resolveFileName(uri, contentResolver);
|
| + filePathArray[i] = clipData.getItemAt(i).getUri();
|
| }
|
| -
|
| - nativeOnMultipleFilesSelected(mNativeSelectFileDialog,
|
| - filePathArray, displayNameArray);
|
| + GetDisplayNameTask task = new GetDisplayNameTask(contentResolver, true);
|
| + task.execute(filePathArray);
|
| return;
|
| }
|
|
|
| @@ -230,10 +200,8 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{
|
| }
|
|
|
| if (ContentResolver.SCHEME_CONTENT.equals(results.getScheme())) {
|
| - nativeOnFileSelected(mNativeSelectFileDialog,
|
| - results.getData().toString(),
|
| - resolveFileName(results.getData(),
|
| - contentResolver));
|
| + GetDisplayNameTask task = new GetDisplayNameTask(contentResolver, false);
|
| + task.execute(results.getData());
|
| return;
|
| }
|
|
|
| @@ -295,6 +263,38 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{
|
| return false;
|
| }
|
|
|
| + private class GetDisplayNameTask extends AsyncTask<Uri, Void, String[]> {
|
| + String[] mFilePaths;
|
| + final ContentResolver mContentResolver;
|
| + final boolean mIsMultiple;
|
| +
|
| + public GetDisplayNameTask(ContentResolver contentResolver, boolean isMultiple) {
|
| + mContentResolver = contentResolver;
|
| + mIsMultiple = isMultiple;
|
| + }
|
| +
|
| + @Override
|
| + protected String[] doInBackground(Uri...uris) {
|
| + mFilePaths = new String[uris.length];
|
| + String[] displayNames = new String[uris.length];
|
| + for (int i = 0; i < uris.length; i++) {
|
| + mFilePaths[i] = uris[i].toString();
|
| + displayNames[i] = ContentUriUtils.getDisplayName(
|
| + uris[i], mContentResolver, MediaStore.MediaColumns.DISPLAY_NAME);
|
| + }
|
| + return displayNames;
|
| + }
|
| +
|
| + @Override
|
| + protected void onPostExecute(String[] result) {
|
| + if (mIsMultiple) {
|
| + nativeOnMultipleFilesSelected(mNativeSelectFileDialog, mFilePaths, result);
|
| + } else {
|
| + nativeOnFileSelected(mNativeSelectFileDialog, mFilePaths[0], result[0]);
|
| + }
|
| + }
|
| + }
|
| +
|
| @CalledByNative
|
| private static SelectFileDialog create(long nativeSelectFileDialog) {
|
| return new SelectFileDialog(nativeSelectFileDialog);
|
|
|