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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 SelectFileDialog::Type type, | 55 SelectFileDialog::Type type, |
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 // The first element in the pair is a list of accepted types, the second |
66 std::vector<base::string16> accept_types; | 66 // indicates whether the device's capture capabilities should be used. |
| 67 typedef std::pair<std::vector<base::string16>, bool> AcceptTypes; |
| 68 AcceptTypes accept_types = std::make_pair(std::vector<base::string16>(), |
| 69 false); |
| 70 |
67 if (params) { | 71 if (params) { |
68 accept_types = *(reinterpret_cast<std::vector<base::string16>*>(params)); | 72 accept_types = *(reinterpret_cast<AcceptTypes*>(params)); |
69 | |
70 // The last string in params is expected to be the string | |
71 // with capture value. | |
72 capture_value = base::android::ConvertUTF16ToJavaString(env, | |
73 StringToLowerASCII(accept_types.back())); | |
74 base::android::CheckException(env); | |
75 accept_types.pop_back(); | |
76 } else { | |
77 capture_value = base::android::ConvertUTF8ToJavaString(env, "filesystem"); | |
78 } | 73 } |
79 | 74 |
80 // The rest params elements are expected to be accept_types. | |
81 ScopedJavaLocalRef<jobjectArray> accept_types_java = | 75 ScopedJavaLocalRef<jobjectArray> accept_types_java = |
82 base::android::ToJavaArrayOfStrings(env, accept_types); | 76 base::android::ToJavaArrayOfStrings(env, accept_types.first); |
83 | 77 |
84 Java_SelectFileDialog_selectFile(env, java_object_.obj(), | 78 Java_SelectFileDialog_selectFile(env, java_object_.obj(), |
85 accept_types_java.obj(), | 79 accept_types_java.obj(), |
86 capture_value.obj(), | 80 accept_types.second, |
87 owning_window->GetJavaObject().obj()); | 81 owning_window->GetJavaObject().obj()); |
88 is_running_ = true; | 82 is_running_ = true; |
89 } | 83 } |
90 | 84 |
91 bool SelectFileDialogImpl::RegisterSelectFileDialog(JNIEnv* env) { | 85 bool SelectFileDialogImpl::RegisterSelectFileDialog(JNIEnv* env) { |
92 return RegisterNativesImpl(env); | 86 return RegisterNativesImpl(env); |
93 } | 87 } |
94 | 88 |
95 SelectFileDialogImpl::~SelectFileDialogImpl() { | 89 SelectFileDialogImpl::~SelectFileDialogImpl() { |
96 } | 90 } |
(...skipping 11 matching lines...) Expand all Loading... |
108 return false; | 102 return false; |
109 } | 103 } |
110 | 104 |
111 SelectFileDialog* CreateAndroidSelectFileDialog( | 105 SelectFileDialog* CreateAndroidSelectFileDialog( |
112 SelectFileDialog::Listener* listener, | 106 SelectFileDialog::Listener* listener, |
113 SelectFilePolicy* policy) { | 107 SelectFilePolicy* policy) { |
114 return SelectFileDialogImpl::Create(listener, policy); | 108 return SelectFileDialogImpl::Create(listener, policy); |
115 } | 109 } |
116 | 110 |
117 } // namespace ui | 111 } // namespace ui |
OLD | NEW |