summaryrefslogtreecommitdiffstats
path: root/ui/android
diff options
context:
space:
mode:
authormiguelg@chromium.org <miguelg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-04 13:09:41 +0000
committermiguelg@chromium.org <miguelg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-04 13:09:41 +0000
commitf2263355914e2bf005f392e222f61988207be6b5 (patch)
tree7d6abe361024c99326558452ac89def25847fa0f /ui/android
parent22f27c999d89eb5d93f178d6e9941e73542df56a (diff)
downloadchromium_src-f2263355914e2bf005f392e222f61988207be6b5.zip
chromium_src-f2263355914e2bf005f392e222f61988207be6b5.tar.gz
chromium_src-f2263355914e2bf005f392e222f61988207be6b5.tar.bz2
Figure out the display name for a content uri.
Plumb it through the File listener so blink can display the right content on <input type=file> elements. BUG=338929 NOTRY=true Review URL: https://codereview.chromium.org/150283002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@248707 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/android')
-rw-r--r--ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java39
1 files changed, 32 insertions, 7 deletions
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 6d85a35..56c432c 100644
--- a/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
+++ b/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
@@ -7,6 +7,7 @@ package org.chromium.ui.base;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
+import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
@@ -129,6 +130,28 @@ 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) {
+ 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);
+ }
+ } 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.
@@ -147,7 +170,7 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{
if (results == null) {
// If we have a successful return but no data, then assume this is the camera returning
// the photo that we requested.
- nativeOnFileSelected(mNativeSelectFileDialog, mCameraOutputUri.getPath());
+ nativeOnFileSelected(mNativeSelectFileDialog, mCameraOutputUri.getPath(), "");
// Broadcast to the media scanner that there's a new photo on the device so it will
// show up right away in the gallery (rather than waiting until the next time the media
@@ -157,15 +180,17 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{
return;
}
- if ("file".equals(results.getData().getScheme())) {
+ if (ContentResolver.SCHEME_FILE.equals(results.getData().getScheme())) {
nativeOnFileSelected(mNativeSelectFileDialog,
- results.getData().getSchemeSpecificPart());
+ results.getData().getSchemeSpecificPart(), "");
return;
}
- if (results.getScheme() != null
- && results.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
- nativeOnFileSelected(mNativeSelectFileDialog, results.getData().toString());
+ if (ContentResolver.SCHEME_CONTENT.equals(results.getScheme())) {
+ nativeOnFileSelected(mNativeSelectFileDialog,
+ results.getData().toString(),
+ resolveFileName(results.getData(),
+ contentResolver));
return;
}
@@ -233,6 +258,6 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{
}
private native void nativeOnFileSelected(long nativeSelectFileDialogImpl,
- String filePath);
+ String filePath, String displayName);
private native void nativeOnFileNotSelected(long nativeSelectFileDialogImpl);
}