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 if (params) { | 67 typedef std::pair<std::vector<base::string16>, bool> AcceptTypes; |
68 accept_types = *(reinterpret_cast<std::vector<base::string16>*>(params)); | 68 AcceptTypes accept_types = std::make_pair(std::vector<base::string16>(), |
69 false); | |
70 if (params) accept_types = *(reinterpret_cast<AcceptTypes*>(params)); | |
joth
2013/07/04 18:09:07
this should be on two lines. or use 3 if you use
| |
69 | 71 |
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 } | |
79 | |
80 // The rest params elements are expected to be accept_types. | |
81 ScopedJavaLocalRef<jobjectArray> accept_types_java = | 72 ScopedJavaLocalRef<jobjectArray> accept_types_java = |
82 base::android::ToJavaArrayOfStrings(env, accept_types); | 73 base::android::ToJavaArrayOfStrings(env, accept_types.first); |
74 bool has_capture_attribute = accept_types.second; | |
83 | 75 |
84 Java_SelectFileDialog_selectFile(env, java_object_.obj(), | 76 Java_SelectFileDialog_selectFile(env, java_object_.obj(), |
85 accept_types_java.obj(), | 77 accept_types_java.obj(), |
86 capture_value.obj(), | 78 has_capture_attribute, |
87 owning_window->GetJavaObject().obj()); | 79 owning_window->GetJavaObject().obj()); |
88 is_running_ = true; | 80 is_running_ = true; |
89 } | 81 } |
90 | 82 |
91 bool SelectFileDialogImpl::RegisterSelectFileDialog(JNIEnv* env) { | 83 bool SelectFileDialogImpl::RegisterSelectFileDialog(JNIEnv* env) { |
92 return RegisterNativesImpl(env); | 84 return RegisterNativesImpl(env); |
93 } | 85 } |
94 | 86 |
95 SelectFileDialogImpl::~SelectFileDialogImpl() { | 87 SelectFileDialogImpl::~SelectFileDialogImpl() { |
96 } | 88 } |
(...skipping 11 matching lines...) Expand all Loading... | |
108 return false; | 100 return false; |
109 } | 101 } |
110 | 102 |
111 SelectFileDialog* CreateAndroidSelectFileDialog( | 103 SelectFileDialog* CreateAndroidSelectFileDialog( |
112 SelectFileDialog::Listener* listener, | 104 SelectFileDialog::Listener* listener, |
113 SelectFilePolicy* policy) { | 105 SelectFilePolicy* policy) { |
114 return SelectFileDialogImpl::Create(listener, policy); | 106 return SelectFileDialogImpl::Create(listener, policy); |
115 } | 107 } |
116 | 108 |
117 } // namespace ui | 109 } // namespace ui |
OLD | NEW |