From 4ae32f5f11f2914196d6d0d195dcbc59d37b92bc Mon Sep 17 00:00:00 2001 From: Ben Murdoch Date: Tue, 18 May 2010 14:30:39 +0100 Subject: [PATCH] Allow passing of accept types from WebCore to Java for the file picker. Requires a change in external/webkit and packages/apps/Browser. Change-Id: I0fe5f0edb00be0f329f07e42e84f88aced543d17 --- core/java/android/webkit/CallbackProxy.java | 27 ++++++++++++++++--- core/java/android/webkit/WebChromeClient.java | 6 +++-- core/java/android/webkit/WebViewCore.java | 6 +++-- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/core/java/android/webkit/CallbackProxy.java b/core/java/android/webkit/CallbackProxy.java index 9521b490a501a..fdcbe3d2516d3 100644 --- a/core/java/android/webkit/CallbackProxy.java +++ b/core/java/android/webkit/CallbackProxy.java @@ -41,6 +41,7 @@ import com.android.internal.R; import java.net.MalformedURLException; import java.net.URL; import java.util.HashMap; +import java.util.Map; /** * This class is a proxy class for handling WebCore -> UI thread messaging. All @@ -725,7 +726,8 @@ class CallbackProxy extends Handler { case OPEN_FILE_CHOOSER: if (mWebChromeClient != null) { - mWebChromeClient.openFileChooser((UploadFile) msg.obj); + UploadFileMessageData data = (UploadFileMessageData)msg.obj; + mWebChromeClient.openFileChooser(data.getUploadFile(), data.getAcceptType()); } break; @@ -1431,6 +1433,24 @@ class CallbackProxy extends Handler { sendMessage(msg); } + private static class UploadFileMessageData { + private UploadFile mCallback; + private String mAcceptType; + + public UploadFileMessageData(UploadFile uploadFile, String acceptType) { + mCallback = uploadFile; + mAcceptType = acceptType; + } + + public UploadFile getUploadFile() { + return mCallback; + } + + public String getAcceptType() { + return mAcceptType; + } + } + private class UploadFile implements ValueCallback { private Uri mValue; public void onReceiveValue(Uri value) { @@ -1447,13 +1467,14 @@ class CallbackProxy extends Handler { /** * Called by WebViewCore to open a file chooser. */ - /* package */ Uri openFileChooser() { + /* package */ Uri openFileChooser(String acceptType) { if (mWebChromeClient == null) { return null; } Message myMessage = obtainMessage(OPEN_FILE_CHOOSER); UploadFile uploadFile = new UploadFile(); - myMessage.obj = uploadFile; + UploadFileMessageData data = new UploadFileMessageData(uploadFile, acceptType); + myMessage.obj = data; synchronized (this) { sendMessage(myMessage); try { diff --git a/core/java/android/webkit/WebChromeClient.java b/core/java/android/webkit/WebChromeClient.java index 1d5aac7fb3c03..ad53508db21f3 100644 --- a/core/java/android/webkit/WebChromeClient.java +++ b/core/java/android/webkit/WebChromeClient.java @@ -314,10 +314,12 @@ public class WebChromeClient { /** * Tell the client to open a file chooser. * @param uploadFile A ValueCallback to set the URI of the file to upload. - * onReceiveValue must be called to wake up the thread. + * onReceiveValue must be called to wake up the thread.a + * @param acceptType The value of the 'accept' attribute of the input tag + * associated with this file picker. * @hide */ - public void openFileChooser(ValueCallback uploadFile) { + public void openFileChooser(ValueCallback uploadFile, String acceptType) { uploadFile.onReceiveValue(null); } } diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java index c1330223bdedc..974fcaaa83a78 100644 --- a/core/java/android/webkit/WebViewCore.java +++ b/core/java/android/webkit/WebViewCore.java @@ -276,10 +276,12 @@ final class WebViewCore { /** * Called by JNI. Open a file chooser to upload a file. + * @param acceptType The value of the 'accept' attribute of the + * input tag associated with this file picker. * @return String version of the URI. */ - private String openFileChooser() { - Uri uri = mCallbackProxy.openFileChooser(); + private String openFileChooser(String acceptType) { + Uri uri = mCallbackProxy.openFileChooser(acceptType); if (uri != null) { String fileName = ""; Cursor cursor = mContext.getContentResolver().query(