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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "jni/SelectFileDialog_jni.h" | 15 #include "jni/SelectFileDialog_jni.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams. h" | |
16 #include "ui/android/window_android.h" | 17 #include "ui/android/window_android.h" |
17 | 18 |
18 namespace ui { | 19 namespace ui { |
19 | 20 |
20 // static | 21 // static |
21 SelectFileDialogImpl* SelectFileDialogImpl::Create(Listener* listener, | 22 SelectFileDialogImpl* SelectFileDialogImpl::Create(Listener* listener, |
22 ui::SelectFilePolicy* policy) { | 23 ui::SelectFilePolicy* policy) { |
23 return new SelectFileDialogImpl(listener, policy); | 24 return new SelectFileDialogImpl(listener, policy); |
24 } | 25 } |
25 | 26 |
(...skipping 29 matching lines...) Expand all Loading... | |
55 ui::SelectFileDialog::Type type, | 56 ui::SelectFileDialog::Type type, |
56 const string16& title, | 57 const string16& title, |
57 const base::FilePath& default_path, | 58 const base::FilePath& default_path, |
58 const SelectFileDialog::FileTypeInfo* file_types, | 59 const SelectFileDialog::FileTypeInfo* file_types, |
59 int file_type_index, | 60 int file_type_index, |
60 const std::string& default_extension, | 61 const std::string& default_extension, |
61 gfx::NativeWindow owning_window, | 62 gfx::NativeWindow owning_window, |
62 void* params) { | 63 void* params) { |
63 JNIEnv* env = base::android::AttachCurrentThread(); | 64 JNIEnv* env = base::android::AttachCurrentThread(); |
64 | 65 |
65 std::vector<string16> accept_types = | 66 #if defined(NEW_MEDIA_CAPTURE_IMPLEMENTATION) |
66 *(reinterpret_cast<std::vector<string16>*>(params)); | 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<string16>, bool> AcceptTypes; | |
70 AcceptTypes accept_types = *(reinterpret_cast<AcceptTypes*>(params)); | |
67 | 71 |
68 // The last string in params is expected to be the string with capture value. | 72 // The latest version of the HTML Media Capture spec says the "capture" |
73 // attribute should be a boolean, and implementations are supposed to infer | |
74 // which application to launch based on the value of the "accept" attribute. | |
75 // However, since we have already shipped an implementation of an earlier | |
76 // version of the spec in which the "capture" attribute was an enum, we need | |
77 // to keep compatibility for a while. We do that by creating a valid string | |
78 // value accepted by SelectFileDialog.java based on the contents of the | |
79 // "accept" attribute. This approximation is not 100% compatible with the | |
80 // previous behavior, as we cannot infer a value for "capture" if "accept" is | |
81 // set to something like "*/*" or "audio/*,video/*". | |
82 // FIXME: We need to phase out support for the old version of the spec at | |
83 // some point. | |
joth
2013/05/15 20:03:59
We don't use FIXME in chromium. You could link to
| |
84 bool has_capture_attribute = accept_types.second; | |
85 string16 normalized_capture_value; | |
86 | |
87 if (has_capture_attribute && accept_types.size() == 1) { | |
88 if (StartsWithASCII(accept_types.front(), "image/*", false)) { | |
89 normalized_capture_value = "camera"; | |
90 } else if (StartsWithASCII(accept_types.front(), "video/*", false)) { | |
91 normalized_capture_value = "camcorder"; | |
92 } else if (StartsWithASCII(accept_types.front(), "audio/*", false)) { | |
93 normalized_capture_value = "microphone"; | |
94 } | |
95 } | |
96 | |
97 ScopedJavaLocalRef<jstring> capture_value = | |
98 base::android::ConvertUTF16ToJavaString(env, normalized_capture_value); | |
99 #else | |
100 typedef std::pair<std::vector<string16>, string16> AcceptTypes; | |
101 AcceptTypes accept_types = *(reinterpret_cast<AcceptTypes*>(params)); | |
102 | |
69 ScopedJavaLocalRef<jstring> capture_value = | 103 ScopedJavaLocalRef<jstring> capture_value = |
70 base::android::ConvertUTF16ToJavaString(env, | 104 base::android::ConvertUTF16ToJavaString(env, |
71 StringToLowerASCII(accept_types.back())); | 105 StringToLowerASCII(accept_types.second)); |
106 #endif | |
72 base::android::CheckException(env); | 107 base::android::CheckException(env); |
73 accept_types.pop_back(); | |
74 | 108 |
75 // The rest params elements are expected to be accept_types. | |
76 ScopedJavaLocalRef<jobjectArray> accept_types_java = | 109 ScopedJavaLocalRef<jobjectArray> accept_types_java = |
77 base::android::ToJavaArrayOfStrings(env, accept_types); | 110 base::android::ToJavaArrayOfStrings(env, accept_types.first); |
78 | 111 |
79 Java_SelectFileDialog_selectFile(env, java_object_.obj(), | 112 Java_SelectFileDialog_selectFile(env, java_object_.obj(), |
80 accept_types_java.obj(), | 113 accept_types_java.obj(), |
81 capture_value.obj(), | 114 capture_value.obj(), |
82 owning_window->GetJavaObject().obj()); | 115 owning_window->GetJavaObject().obj()); |
83 is_running_ = true; | 116 is_running_ = true; |
84 } | 117 } |
85 | 118 |
86 bool SelectFileDialogImpl::RegisterSelectFileDialog(JNIEnv* env) { | 119 bool SelectFileDialogImpl::RegisterSelectFileDialog(JNIEnv* env) { |
87 return RegisterNativesImpl(env); | 120 return RegisterNativesImpl(env); |
(...skipping 16 matching lines...) Expand all Loading... | |
104 return false; | 137 return false; |
105 } | 138 } |
106 | 139 |
107 SelectFileDialog* CreateAndroidSelectFileDialog( | 140 SelectFileDialog* CreateAndroidSelectFileDialog( |
108 SelectFileDialog::Listener* listener, | 141 SelectFileDialog::Listener* listener, |
109 SelectFilePolicy* policy) { | 142 SelectFilePolicy* policy) { |
110 return SelectFileDialogImpl::Create(listener, policy); | 143 return SelectFileDialogImpl::Create(listener, policy); |
111 } | 144 } |
112 | 145 |
113 } // namespace ui | 146 } // namespace ui |
OLD | NEW |