OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "select_file_dialog_android.h" | 5 #include "select_file_dialog_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 const base::string16& title, | 56 const base::string16& title, |
57 const base::FilePath& default_path, | 57 const base::FilePath& default_path, |
58 const SelectFileDialog::FileTypeInfo* file_types, | 58 const SelectFileDialog::FileTypeInfo* file_types, |
59 int file_type_index, | 59 int file_type_index, |
60 const std::string& default_extension, | 60 const std::string& default_extension, |
61 gfx::NativeWindow owning_window, | 61 gfx::NativeWindow owning_window, |
62 void* params) { | 62 void* params) { |
63 JNIEnv* env = base::android::AttachCurrentThread(); | 63 JNIEnv* env = base::android::AttachCurrentThread(); |
64 | 64 |
65 ScopedJavaLocalRef<jstring> capture_value; | 65 ScopedJavaLocalRef<jstring> capture_value; |
66 std::vector<base::string16> accept_types; | 66 |
67 // The first element in the pair is a list of accepted types, the second | |
68 // indicates whether the device's capture capabilities should be used. | |
69 typedef std::pair<std::vector<base::string16>, bool> AcceptTypes; | |
70 AcceptTypes accept_types; | |
71 | |
67 if (params) { | 72 if (params) { |
68 accept_types = *(reinterpret_cast<std::vector<base::string16>*>(params)); | 73 accept_types = *(reinterpret_cast<AcceptTypes*>(params)); |
69 | 74 |
70 // The last string in params is expected to be the string | 75 // 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
| |
71 // with capture value. | 76 // attribute should be a boolean, and implementations are supposed to infer |
72 capture_value = base::android::ConvertUTF16ToJavaString(env, | 77 // which application to launch based on the value of the "accept" |
73 StringToLowerASCII(accept_types.back())); | 78 // 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
| |
79 // an earlier version of the spec in which the "capture" attribute was an | |
80 // enum, we need to keep compatibility for a while. We do that by creating | |
81 // a valid string value accepted by SelectFileDialog.java based on the | |
82 // contents of the "accept" attribute. This approximation is not 100% | |
83 // compatible with the previous behavior, as we cannot infer a value for | |
84 // "capture" if "accept" is set to something like "*/*" or | |
85 // "audio/*,video/*". | |
86 // TODO: crbug.com/240252 We need to phase out support for the old version | |
87 // of the spec at some point. | |
joth
2013/07/03 17:41:42
I'm still feeling mislead by this comment. An old
| |
88 bool has_capture_attribute = accept_types.second; | |
89 string16 normalized_capture_value; | |
90 | |
91 if (has_capture_attribute && accept_types.first.size() == 1) { | |
92 if (StartsWithASCII(accept_types.front(), "image/*", false)) { | |
93 normalized_capture_value = "camera"; | |
94 } else if (StartsWithASCII(accept_types.front(), "video/*", false)) { | |
95 normalized_capture_value = "camcorder"; | |
96 } else if (StartsWithASCII(accept_types.front(), "audio/*", false)) { | |
97 normalized_capture_value = "microphone"; | |
98 } | |
99 } | |
100 | |
101 capture_value = base::android::ConvertUTF16ToJavaString( | |
102 env, normalized_capture_value); | |
74 base::android::CheckException(env); | 103 base::android::CheckException(env); |
75 accept_types.pop_back(); | |
76 } else { | 104 } else { |
77 capture_value = base::android::ConvertUTF8ToJavaString(env, "filesystem"); | 105 capture_value = base::android::ConvertUTF8ToJavaString(env, "filesystem"); |
78 } | 106 } |
79 | 107 |
80 // The rest params elements are expected to be accept_types. | |
81 ScopedJavaLocalRef<jobjectArray> accept_types_java = | 108 ScopedJavaLocalRef<jobjectArray> accept_types_java = |
82 base::android::ToJavaArrayOfStrings(env, accept_types); | 109 base::android::ToJavaArrayOfStrings(env, accept_types.first); |
83 | 110 |
84 Java_SelectFileDialog_selectFile(env, java_object_.obj(), | 111 Java_SelectFileDialog_selectFile(env, java_object_.obj(), |
85 accept_types_java.obj(), | 112 accept_types_java.obj(), |
86 capture_value.obj(), | 113 capture_value.obj(), |
joth
2013/07/03 17:41:42
Can't we go the full way and pass 'has_capture_att
| |
87 owning_window->GetJavaObject().obj()); | 114 owning_window->GetJavaObject().obj()); |
88 is_running_ = true; | 115 is_running_ = true; |
89 } | 116 } |
90 | 117 |
91 bool SelectFileDialogImpl::RegisterSelectFileDialog(JNIEnv* env) { | 118 bool SelectFileDialogImpl::RegisterSelectFileDialog(JNIEnv* env) { |
92 return RegisterNativesImpl(env); | 119 return RegisterNativesImpl(env); |
93 } | 120 } |
94 | 121 |
95 SelectFileDialogImpl::~SelectFileDialogImpl() { | 122 SelectFileDialogImpl::~SelectFileDialogImpl() { |
96 } | 123 } |
(...skipping 11 matching lines...) Expand all Loading... | |
108 return false; | 135 return false; |
109 } | 136 } |
110 | 137 |
111 SelectFileDialog* CreateAndroidSelectFileDialog( | 138 SelectFileDialog* CreateAndroidSelectFileDialog( |
112 SelectFileDialog::Listener* listener, | 139 SelectFileDialog::Listener* listener, |
113 SelectFilePolicy* policy) { | 140 SelectFilePolicy* policy) { |
114 return SelectFileDialogImpl::Create(listener, policy); | 141 return SelectFileDialogImpl::Create(listener, policy); |
115 } | 142 } |
116 | 143 |
117 } // namespace ui | 144 } // namespace ui |
OLD | NEW |