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 b4dc7e8dc6945c931bc86367635b7e605349111e..e4d284f52a1a9da03160c3ba7b0d37662ab08dfb 100644 |
| --- a/ui/shell_dialogs/select_file_dialog_android.cc |
| +++ b/ui/shell_dialogs/select_file_dialog_android.cc |
| @@ -63,23 +63,50 @@ void SelectFileDialogImpl::SelectFileImpl( |
| JNIEnv* env = base::android::AttachCurrentThread(); |
| ScopedJavaLocalRef<jstring> capture_value; |
| - std::vector<base::string16> accept_types; |
| - if (params) { |
| - accept_types = *(reinterpret_cast<std::vector<base::string16>*>(params)); |
| - // The last string in params is expected to be the string |
| - // with capture value. |
| - capture_value = base::android::ConvertUTF16ToJavaString(env, |
| - StringToLowerASCII(accept_types.back())); |
| + // 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<base::string16>, bool> AcceptTypes; |
| + AcceptTypes accept_types; |
| + |
| + if (params) { |
| + accept_types = *(reinterpret_cast<AcceptTypes*>(params)); |
| + |
| + // The latest version of the HTML Media Capture spec says the "capture" |
|
joth
2013/07/03 17:41:42
nit: 'latest' is ambiguous when read in future. In
|
| + // 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 |
|
joth
2013/07/03 17:41:42
likewise, could say versions of chrome up to M29 s
|
| + // 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/*". |
| + // TODO: crbug.com/240252 We need to phase out support for the old version |
| + // of the spec at some point. |
|
joth
2013/07/03 17:41:42
I'm still feeling mislead by this comment. An old
|
| + bool has_capture_attribute = accept_types.second; |
| + string16 normalized_capture_value; |
| + |
| + if (has_capture_attribute && accept_types.first.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"; |
| + } |
| + } |
| + |
| + capture_value = base::android::ConvertUTF16ToJavaString( |
| + env, normalized_capture_value); |
| base::android::CheckException(env); |
| - accept_types.pop_back(); |
| } else { |
| capture_value = base::android::ConvertUTF8ToJavaString(env, "filesystem"); |
| } |
| - // 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(), |