From 65b4cdabb0b626635606c4b2dfec145c547d3396 Mon Sep 17 00:00:00 2001 From: Ben Murdoch Date: Fri, 28 May 2010 11:07:15 +0100 Subject: [PATCH] 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 --- core/java/android/webkit/JWebCoreJavaBridge.java | 16 ++++++++-------- core/java/android/webkit/WebViewCore.java | 15 +++++++++------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/core/java/android/webkit/JWebCoreJavaBridge.java b/core/java/android/webkit/JWebCoreJavaBridge.java index cfeb8fbaf901f..ecad26142319a 100644 --- a/core/java/android/webkit/JWebCoreJavaBridge.java +++ b/core/java/android/webkit/JWebCoreJavaBridge.java @@ -51,7 +51,7 @@ final class JWebCoreJavaBridge extends Handler { /* package */ static final int REFRESH_PLUGINS = 100; - private HashMap mContentUriToFileNameMap; + private HashMap 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(); + public void storeFilePathForContentUri(String path, String contentUri) { + if (mContentUriToFilePathMap == null) { + mContentUriToFilePathMap = new HashMap(); } - mContentUriToFileNameMap.put(contentUri, fileName); + mContentUriToFilePathMap.put(contentUri, path); } private native void nativeConstructor(); diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java index 850cc25d89aa5..5139ae80df0b7 100644 --- a/core/java/android/webkit/WebViewCore.java +++ b/core/java/android/webkit/WebViewCore.java @@ -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 "";