Frameworks changes to enable File Reader and blob.slice APIs.

Rather than just storing the name of the file that the user chose in the file picker,
store the full path to the file. That way we can open it using the file API and still
extract the filename itself by simply chopping off all but the last path segment.

Change-Id: I25f2fe818deda8ca848f0da02cf45ae97d2127fb
This commit is contained in:
Ben Murdoch
2010-05-28 11:07:15 +01:00
parent c8f302fb5d
commit 65b4cdabb0
2 changed files with 17 additions and 14 deletions

View File

@@ -51,7 +51,7 @@ final class JWebCoreJavaBridge extends Handler {
/* package */
static final int REFRESH_PLUGINS = 100;
private HashMap<String, String> mContentUriToFileNameMap;
private HashMap<String, String> mContentUriToFilePathMap;
/**
* Construct a new JWebCoreJavaBridge to interface with
@@ -273,9 +273,9 @@ final class JWebCoreJavaBridge extends Handler {
}
// Called on the WebCore thread through JNI.
private String resolveFileNameForContentUri(String uri) {
if (mContentUriToFileNameMap != null) {
String fileName = mContentUriToFileNameMap.get(uri);
private String resolveFilePathForContentUri(String uri) {
if (mContentUriToFilePathMap != null) {
String fileName = mContentUriToFilePathMap.get(uri);
if (fileName != null) {
return fileName;
}
@@ -287,11 +287,11 @@ final class JWebCoreJavaBridge extends Handler {
return jUri.getLastPathSegment();
}
public void storeFileNameForContentUri(String fileName, String contentUri) {
if (mContentUriToFileNameMap == null) {
mContentUriToFileNameMap = new HashMap<String, String>();
public void storeFilePathForContentUri(String path, String contentUri) {
if (mContentUriToFilePathMap == null) {
mContentUriToFilePathMap = new HashMap<String, String>();
}
mContentUriToFileNameMap.put(contentUri, fileName);
mContentUriToFilePathMap.put(contentUri, path);
}
private native void nativeConstructor();

View File

@@ -32,7 +32,8 @@ import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.provider.OpenableColumns;
import android.provider.MediaStore;
import android.provider.MediaStore.Images.Media;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.KeyEvent;
@@ -283,24 +284,26 @@ final class WebViewCore {
private String openFileChooser(String acceptType) {
Uri uri = mCallbackProxy.openFileChooser(acceptType);
if (uri != null) {
String fileName = "";
String filePath = "";
// Note - querying for MediaStore.Images.Media.DATA
// seems to work for all content URIs, not just images
Cursor cursor = mContext.getContentResolver().query(
uri,
new String[] { OpenableColumns.DISPLAY_NAME },
new String[] { MediaStore.Images.Media.DATA },
null, null, null);
if (cursor != null) {
try {
if (cursor.moveToNext()) {
fileName = cursor.getString(0);
filePath = cursor.getString(0);
}
} finally {
cursor.close();
}
} else {
fileName = uri.getLastPathSegment();
filePath = uri.getLastPathSegment();
}
String uriString = uri.toString();
BrowserFrame.sJavaBridge.storeFileNameForContentUri(fileName, uriString);
BrowserFrame.sJavaBridge.storeFilePathForContentUri(filePath, uriString);
return uriString;
}
return "";