| Index: ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
|
| diff --git a/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java b/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
|
| index 29f9e992a486e6e4d36746a29bb2a1efe2089fb7..1dfd9ddceb9ac8e94b4c8e83f1b409712a8d671c 100644
|
| --- a/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
|
| +++ b/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
|
| @@ -18,6 +18,7 @@ import android.os.AsyncTask;
|
| import android.os.Build;
|
| import android.provider.MediaStore;
|
| import android.text.TextUtils;
|
| +import android.webkit.MimeTypeMap;
|
|
|
| import org.chromium.base.ApiCompatibilityUtils;
|
| import org.chromium.base.ContentUriUtils;
|
| @@ -187,6 +188,9 @@ public class SelectFileDialog implements WindowAndroid.IntentCallback,
|
| * @param camera Intent for selecting files from camera.
|
| */
|
| private void launchSelectFileWithCameraIntent(boolean hasCameraPermission, Intent camera) {
|
| + RecordHistogram.recordEnumeratedHistogram("Android.SelectFileDialogScope",
|
| + determineSelectFileDialogScope(), SELECT_FILE_DIALOG_SCOPE_COUNT);
|
| +
|
| Intent camcorder = null;
|
| if (mSupportsVideoCapture && hasCameraPermission) {
|
| camcorder = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
|
| @@ -210,15 +214,19 @@ public class SelectFileDialog implements WindowAndroid.IntentCallback,
|
| if (mWindowAndroid.showIntent(soundRecorder, this, R.string.low_memory_error)) return;
|
| }
|
|
|
| + // Use new photo picker, if available.
|
| + Activity activity = mWindowAndroid.getActivity().get();
|
| + if (activity != null && usePhotoPicker(mFileTypes)
|
| + && UiUtils.showPhotoPicker(activity, this, mAllowMultiple)) {
|
| + return;
|
| + }
|
| +
|
| Intent getContentIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
|
|
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && mAllowMultiple) {
|
| getContentIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
|
| }
|
|
|
| - RecordHistogram.recordEnumeratedHistogram("Android.SelectFileDialogScope",
|
| - determineSelectFileDialogScope(), SELECT_FILE_DIALOG_SCOPE_COUNT);
|
| -
|
| ArrayList<Intent> extraIntents = new ArrayList<Intent>();
|
| if (!noSpecificType()) {
|
| // Create a chooser based on the accept type that was specified in the webpage. Note
|
| @@ -248,12 +256,6 @@ public class SelectFileDialog implements WindowAndroid.IntentCallback,
|
| if (soundRecorder != null) extraIntents.add(soundRecorder);
|
| }
|
|
|
| - // Use new photo picker, if available.
|
| - Activity activity = mWindowAndroid.getActivity().get();
|
| - if (activity != null && UiUtils.showPhotoPicker(activity, this, mAllowMultiple)) {
|
| - return;
|
| - }
|
| -
|
| Intent chooser = new Intent(Intent.ACTION_CHOOSER);
|
| if (!extraIntents.isEmpty()) {
|
| chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS,
|
| @@ -266,6 +268,41 @@ public class SelectFileDialog implements WindowAndroid.IntentCallback,
|
| }
|
| }
|
|
|
| + /**
|
| + * Determines if a photo picker can be used instead of the stock Android picker.
|
| + * @return True if only images types are being requested.
|
| + */
|
| + @VisibleForTesting
|
| + public static boolean usePhotoPicker(List<String> fileTypes) {
|
| + for (String type : fileTypes) {
|
| + String mimeType = ensureMimeType(type);
|
| + if (!mimeType.startsWith("image/")) return false;
|
| + }
|
| + return true;
|
| + }
|
| +
|
| + /**
|
| + * Convert |type| to MIME type (known types only).
|
| + * @param type The type to convert. Can be either a MIME type or an extension (should include
|
| + * the leading dot). If an extension is passed in, it is converted to the
|
| + * corresponding MIME type (via {@link MimeTypeMap}), or "application/octet-stream"
|
| + * if the MIME type is not known.
|
| + * @return The MIME type, if known, or "application/octet-stream" otherwise (or blank if input
|
| + * is blank).
|
| + */
|
| + @VisibleForTesting
|
| + public static String ensureMimeType(String type) {
|
| + if (type.length() == 0) return "";
|
| +
|
| + String extension = MimeTypeMap.getFileExtensionFromUrl(type);
|
| + if (extension.length() > 0) {
|
| + String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
| + if (mimeType != null) return mimeType;
|
| + return "application/octet-stream";
|
| + }
|
| + return type;
|
| + }
|
| +
|
| @Override
|
| public void onPickerUserAction(Action action, String[] photos) {
|
| UiUtils.dismissPhotoPicker();
|
|
|