Chromium Code Reviews| Index: ui/shell_dialogs/select_file_dialog_android.cc |
| diff --git a/ui/shell_dialogs/select_file_dialog_android.cc b/ui/shell_dialogs/select_file_dialog_android.cc |
| index 2aa40073a028b14f4df5eb2bb98a046c0e2b8a68..786191719a16d84f688fa5750633f2bd1637ae4d 100644 |
| --- a/ui/shell_dialogs/select_file_dialog_android.cc |
| +++ b/ui/shell_dialogs/select_file_dialog_android.cc |
| @@ -13,6 +13,7 @@ |
| #include "base/strings/string_split.h" |
| #include "base/utf_string_conversions.h" |
| #include "jni/SelectFileDialog_jni.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h" |
| #include "ui/android/window_android.h" |
| namespace ui { |
| @@ -62,19 +63,51 @@ void SelectFileDialogImpl::SelectFileImpl( |
| void* params) { |
| JNIEnv* env = base::android::AttachCurrentThread(); |
| - std::vector<string16> accept_types = |
| - *(reinterpret_cast<std::vector<string16>*>(params)); |
| +#if defined(NEW_MEDIA_CAPTURE_IMPLEMENTATION) |
| + // The first element in the pair is a list of accepted types, the second |
| + // indicates whether the device's capture capabilities should be used. |
| + typedef std::pair<std::vector<string16>, bool> AcceptTypes; |
| + AcceptTypes accept_types = *(reinterpret_cast<AcceptTypes*>(params)); |
| + |
| + // The latest version of the HTML Media Capture spec says the "capture" |
| + // attribute should be a boolean, and implementations are supposed to infer |
| + // which application to launch based on the value of the "accept" attribute. |
| + // However, since we have already shipped an implementation of an earlier |
| + // version of the spec in which the "capture" attribute was an enum, we need |
| + // to keep compatibility for a while. We do that by creating a valid string |
| + // value accepted by SelectFileDialog.java based on the contents of the |
| + // "accept" attribute. This approximation is not 100% compatible with the |
| + // previous behavior, as we cannot infer a value for "capture" if "accept" is |
| + // set to something like "*/*" or "audio/*,video/*". |
| + // FIXME: We need to phase out support for the old version of the spec at |
| + // some point. |
|
joth
2013/05/15 20:03:59
We don't use FIXME in chromium. You could link to
|
| + bool has_capture_attribute = accept_types.second; |
| + string16 normalized_capture_value; |
| + |
| + if (has_capture_attribute && accept_types.size() == 1) { |
| + if (StartsWithASCII(accept_types.front(), "image/*", false)) { |
| + normalized_capture_value = "camera"; |
| + } else if (StartsWithASCII(accept_types.front(), "video/*", false)) { |
| + normalized_capture_value = "camcorder"; |
| + } else if (StartsWithASCII(accept_types.front(), "audio/*", false)) { |
| + normalized_capture_value = "microphone"; |
| + } |
| + } |
| + |
| + ScopedJavaLocalRef<jstring> capture_value = |
| + base::android::ConvertUTF16ToJavaString(env, normalized_capture_value); |
| +#else |
| + typedef std::pair<std::vector<string16>, string16> AcceptTypes; |
| + AcceptTypes accept_types = *(reinterpret_cast<AcceptTypes*>(params)); |
| - // The last string in params is expected to be the string with capture value. |
| ScopedJavaLocalRef<jstring> capture_value = |
| base::android::ConvertUTF16ToJavaString(env, |
| - StringToLowerASCII(accept_types.back())); |
| + StringToLowerASCII(accept_types.second)); |
| +#endif |
| base::android::CheckException(env); |
| - accept_types.pop_back(); |
| - // The rest params elements are expected to be accept_types. |
| ScopedJavaLocalRef<jobjectArray> accept_types_java = |
| - base::android::ToJavaArrayOfStrings(env, accept_types); |
| + base::android::ToJavaArrayOfStrings(env, accept_types.first); |
| Java_SelectFileDialog_selectFile(env, java_object_.obj(), |
| accept_types_java.obj(), |