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
This commit is contained in:
Ben Murdoch
2010-05-18 14:30:39 +01:00
parent cc749dee63
commit 4ae32f5f11
3 changed files with 32 additions and 7 deletions

View File

@@ -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<Uri> {
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 {

View File

@@ -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<Uri> uploadFile) {
public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType) {
uploadFile.onReceiveValue(null);
}
}

View File

@@ -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(