diff options
author | Selim Gurun <sgurun@google.com> | 2014-06-17 19:52:30 -0700 |
---|---|---|
committer | Selim Gurun <sgurun@google.com> | 2014-06-18 13:28:54 -0700 |
commit | 4d59434c396e3d414ed4266103d6990a340331e1 (patch) | |
tree | 466f90b3181b9216a129d81183376103e78729a6 /src/com/android | |
parent | bdad2c0837e47926bddfc21980bd0b900fdc37d4 (diff) | |
download | packages_apps_Browser-4d59434c396e3d414ed4266103d6990a340331e1.zip packages_apps_Browser-4d59434c396e3d414ed4266103d6990a340331e1.tar.gz packages_apps_Browser-4d59434c396e3d414ed4266103d6990a340331e1.tar.bz2 |
Modify AOSP browser to take advantage of new filechooser API.
Bug: 6930981
Change-Id: Id73512cd6e859ea9316f02e8f0d973b6e15d969b
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/browser/Controller.java | 7 | ||||
-rw-r--r-- | src/com/android/browser/PreloadController.java | 5 | ||||
-rw-r--r-- | src/com/android/browser/Tab.java | 9 | ||||
-rw-r--r-- | src/com/android/browser/UploadHandler.java | 76 | ||||
-rw-r--r-- | src/com/android/browser/WebViewController.java | 3 |
5 files changed, 42 insertions, 58 deletions
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java index 70f4383..3e4ae66 100644 --- a/src/com/android/browser/Controller.java +++ b/src/com/android/browser/Controller.java @@ -75,6 +75,7 @@ import android.webkit.MimeTypeMap; import android.webkit.SslErrorHandler; import android.webkit.ValueCallback; import android.webkit.WebChromeClient; +import android.webkit.WebChromeClient.FileChooserParams; import android.webkit.WebIconDatabase; import android.webkit.WebSettings; import android.webkit.WebView; @@ -1922,9 +1923,9 @@ public class Controller // file chooser @Override - public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { + public void showFileChooser(ValueCallback<Uri[]> callback, FileChooserParams params) { mUploadHandler = new UploadHandler(this); - mUploadHandler.openFileChooser(uploadMsg, acceptType, capture); + mUploadHandler.openFileChooser(callback, params); } // thumbnails @@ -2709,7 +2710,7 @@ public class Controller @Override public void startVoiceRecognizer() { Intent voice = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); - voice.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, + voice.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); voice.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1); mActivity.startActivityForResult(voice, VOICE_RESULT); diff --git a/src/com/android/browser/PreloadController.java b/src/com/android/browser/PreloadController.java index acd9709..1929951 100644 --- a/src/com/android/browser/PreloadController.java +++ b/src/com/android/browser/PreloadController.java @@ -29,6 +29,7 @@ import android.webkit.HttpAuthHandler; import android.webkit.SslErrorHandler; import android.webkit.ValueCallback; import android.webkit.WebChromeClient.CustomViewCallback; +import android.webkit.WebChromeClient.FileChooserParams; import android.webkit.WebView; public class PreloadController implements WebViewController { @@ -203,8 +204,8 @@ public class PreloadController implements WebViewController { } @Override - public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { - if (LOGD_ENABLED) Log.d(LOGTAG, "openFileChooser()"); + public void showFileChooser(ValueCallback<Uri[]> callback, FileChooserParams params) { + if (LOGD_ENABLED) Log.d(LOGTAG, "showFileChooser()"); } @Override diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java index ea5ad89..84565e5 100644 --- a/src/com/android/browser/Tab.java +++ b/src/com/android/browser/Tab.java @@ -57,6 +57,7 @@ import android.webkit.URLUtil; import android.webkit.ValueCallback; import android.webkit.WebBackForwardList; import android.webkit.WebChromeClient; +import android.webkit.WebChromeClient.FileChooserParams; import android.webkit.WebHistoryItem; import android.webkit.WebResourceResponse; import android.webkit.WebStorage; @@ -1000,11 +1001,13 @@ class Tab implements PictureListener { } @Override - public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { + public boolean showFileChooser(WebView webView, ValueCallback<Uri[]> callback, + FileChooserParams params) { if (mInForeground) { - mWebViewController.openFileChooser(uploadMsg, acceptType, capture); + mWebViewController.showFileChooser(callback, params); + return true; } else { - uploadMsg.onReceiveValue(null); + return false; } } diff --git a/src/com/android/browser/UploadHandler.java b/src/com/android/browser/UploadHandler.java index a9560bb..c8d76d9 100644 --- a/src/com/android/browser/UploadHandler.java +++ b/src/com/android/browser/UploadHandler.java @@ -22,6 +22,7 @@ import android.content.Intent; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; +import android.webkit.WebChromeClient.FileChooserParams; import android.webkit.ValueCallback; import android.widget.Toast; @@ -29,14 +30,14 @@ import java.io.File; import java.util.Vector; /** - * Handle the file upload callbacks from WebView here + * Handle the file upload. This does not support selecting multiple files yet. */ public class UploadHandler { /* * The Object used to inform the WebView of the file to upload. */ - private ValueCallback<Uri> mUploadMessage; + private ValueCallback<Uri[]> mUploadMessage; private String mCameraFilePath; private boolean mHandled; @@ -85,99 +86,76 @@ public class UploadHandler { } } - mUploadMessage.onReceiveValue(result); + Uri[] uris = null; + if (result != null) { + uris = new Uri[1]; + uris[0] = result; + } + mUploadMessage.onReceiveValue(uris); mHandled = true; mCaughtActivityNotFoundException = false; } - void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { + void openFileChooser(ValueCallback<Uri[]> callback, FileChooserParams fileChooserParams) { final String imageMimeType = "image/*"; final String videoMimeType = "video/*"; final String audioMimeType = "audio/*"; - final String mediaSourceKey = "capture"; + final String mediaSourceValueCamera = "camera"; - final String mediaSourceValueFileSystem = "filesystem"; final String mediaSourceValueCamcorder = "camcorder"; final String mediaSourceValueMicrophone = "microphone"; - // According to the spec, media source can be 'filesystem' or 'camera' or 'camcorder' - // or 'microphone' and the default value should be 'filesystem'. - String mediaSource = mediaSourceValueFileSystem; - if (mUploadMessage != null) { // Already a file picker operation in progress. return; } - mUploadMessage = uploadMsg; + mUploadMessage = callback; // Parse the accept type. - String params[] = acceptType.split(";"); + String params[] = fileChooserParams.acceptTypes.split(";"); String mimeType = params[0]; - - if (capture.length() > 0) { - mediaSource = capture; - } - - if (capture.equals(mediaSourceValueFileSystem)) { - // To maintain backwards compatibility with the previous implementation - // of the media capture API, if the value of the 'capture' attribute is - // "filesystem", we should examine the accept-type for a MIME type that - // may specify a different capture value. - for (String p : params) { - String[] keyValue = p.split("="); - if (keyValue.length == 2) { - // Process key=value parameters. - if (mediaSourceKey.equals(keyValue[0])) { - mediaSource = keyValue[1]; - } - } - } - } + boolean capture = fileChooserParams.capture; //Ensure it is not still set from a previous upload. mCameraFilePath = null; if (mimeType.equals(imageMimeType)) { - if (mediaSource.equals(mediaSourceValueCamera)) { - // Specified 'image/*' and requested the camera, so go ahead and launch the - // camera directly. + if (capture) { + // Specified 'image/*' and requested capture. Launch the camera. startActivity(createCameraIntent()); return; } else { - // Specified just 'image/*', capture=filesystem, or an invalid capture parameter. - // In all these cases we show a traditional picker filetered on accept type - // so launch an intent for both the Camera and image/* OPENABLE. + // Specified just 'image/*', and no capture. Show a traditional picker filtered + // on accept type by sending an intent for both the Camera and image/* OPENABLE. Intent chooser = createChooserIntent(createCameraIntent()); chooser.putExtra(Intent.EXTRA_INTENT, createOpenableIntent(imageMimeType)); startActivity(chooser); return; } } else if (mimeType.equals(videoMimeType)) { - if (mediaSource.equals(mediaSourceValueCamcorder)) { - // Specified 'video/*' and requested the camcorder, so go ahead and launch the - // camcorder directly. + if (capture) { + // Specified 'video/*' and requested capture. Launch the camcorder. startActivity(createCamcorderIntent()); return; } else { - // Specified just 'video/*', capture=filesystem or an invalid capture parameter. - // In all these cases we show an intent for the traditional file picker, filtered - // on accept type so launch an intent for both camcorder and video/* OPENABLE. + // Specified just 'video/*', and no capture. Show a traditional file picker, + // filtered on accept type by sending an intent for both camcorder + // and video/* OPENABLE. Intent chooser = createChooserIntent(createCamcorderIntent()); chooser.putExtra(Intent.EXTRA_INTENT, createOpenableIntent(videoMimeType)); startActivity(chooser); return; } } else if (mimeType.equals(audioMimeType)) { - if (mediaSource.equals(mediaSourceValueMicrophone)) { - // Specified 'audio/*' and requested microphone, so go ahead and launch the sound - // recorder. + if (capture) { + // Specified 'audio/*' and requested capture. Launch the sound recorder. startActivity(createSoundRecorderIntent()); return; } else { - // Specified just 'audio/*', capture=filesystem of an invalid capture parameter. - // In all these cases so go ahead and launch an intent for both the sound + // Specified just 'audio/*', and no capture. Show a traditional file picker, + // filtered on accept type by sending an intent for both the sound // recorder and audio/* OPENABLE. Intent chooser = createChooserIntent(createSoundRecorderIntent()); chooser.putExtra(Intent.EXTRA_INTENT, createOpenableIntent(audioMimeType)); diff --git a/src/com/android/browser/WebViewController.java b/src/com/android/browser/WebViewController.java index 498f8e7..dfede35 100644 --- a/src/com/android/browser/WebViewController.java +++ b/src/com/android/browser/WebViewController.java @@ -28,6 +28,7 @@ import android.webkit.HttpAuthHandler; import android.webkit.SslErrorHandler; import android.webkit.ValueCallback; import android.webkit.WebChromeClient; +import android.webkit.WebChromeClient.FileChooserParams; import android.webkit.WebView; import java.util.List; @@ -93,7 +94,7 @@ public interface WebViewController { void onUpdatedSecurityState(Tab tab); - void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture); + void showFileChooser(ValueCallback<Uri[]> callback, FileChooserParams params); void endActionMode(); |