| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 SelectFileDialog::Type type, | 99 SelectFileDialog::Type type, |
| 100 const base::string16& title, | 100 const base::string16& title, |
| 101 const base::FilePath& default_path, | 101 const base::FilePath& default_path, |
| 102 const SelectFileDialog::FileTypeInfo* file_types, | 102 const SelectFileDialog::FileTypeInfo* file_types, |
| 103 int file_type_index, | 103 int file_type_index, |
| 104 const std::string& default_extension, | 104 const std::string& default_extension, |
| 105 gfx::NativeWindow owning_window, | 105 gfx::NativeWindow owning_window, |
| 106 void* params) { | 106 void* params) { |
| 107 JNIEnv* env = base::android::AttachCurrentThread(); | 107 JNIEnv* env = base::android::AttachCurrentThread(); |
| 108 | 108 |
| 109 // The first element in the pair is a list of accepted types, the second | 109 ScopedJavaLocalRef<jstring> capture_value; |
| 110 // indicates whether the device's capture capabilities should be used. | 110 std::vector<base::string16> accept_types; |
| 111 typedef std::pair<std::vector<base::string16>, bool> AcceptTypes; | |
| 112 AcceptTypes accept_types = std::make_pair(std::vector<base::string16>(), | |
| 113 false); | |
| 114 | 111 |
| 115 if (params) | 112 if (params) { |
| 116 accept_types = *(reinterpret_cast<AcceptTypes*>(params)); | 113 accept_types = *(reinterpret_cast<std::vector<base::string16>*>(params)); |
| 114 |
| 115 // The last string in params is expected to be the string |
| 116 // with capture value. |
| 117 capture_value = |
| 118 base::android::ConvertUTF16ToJavaString(env, accept_types.back()); |
| 119 base::android::CheckException(env); |
| 120 accept_types.pop_back(); |
| 121 } else { |
| 122 capture_value = base::android::ConvertUTF8ToJavaString(env, "environment"); |
| 123 } |
| 117 | 124 |
| 118 ScopedJavaLocalRef<jobjectArray> accept_types_java = | 125 ScopedJavaLocalRef<jobjectArray> accept_types_java = |
| 119 base::android::ToJavaArrayOfStrings(env, accept_types.first); | 126 base::android::ToJavaArrayOfStrings(env, accept_types); |
| 120 | 127 |
| 121 bool accept_multiple_files = SelectFileDialog::SELECT_OPEN_MULTI_FILE == type; | 128 bool accept_multiple_files = SelectFileDialog::SELECT_OPEN_MULTI_FILE == type; |
| 122 | 129 |
| 123 Java_SelectFileDialog_selectFile(env, java_object_, accept_types_java, | 130 Java_SelectFileDialog_selectFile(env, java_object_, accept_types_java, |
| 124 accept_types.second, accept_multiple_files, | 131 capture_value, accept_multiple_files, |
| 125 owning_window->GetJavaObject()); | 132 owning_window->GetJavaObject()); |
| 126 } | 133 } |
| 127 | 134 |
| 128 bool SelectFileDialogImpl::RegisterSelectFileDialog(JNIEnv* env) { | 135 bool SelectFileDialogImpl::RegisterSelectFileDialog(JNIEnv* env) { |
| 129 return RegisterNativesImpl(env); | 136 return RegisterNativesImpl(env); |
| 130 } | 137 } |
| 131 | 138 |
| 132 SelectFileDialogImpl::~SelectFileDialogImpl() { | 139 SelectFileDialogImpl::~SelectFileDialogImpl() { |
| 133 } | 140 } |
| 134 | 141 |
| 135 SelectFileDialogImpl::SelectFileDialogImpl(Listener* listener, | 142 SelectFileDialogImpl::SelectFileDialogImpl(Listener* listener, |
| 136 SelectFilePolicy* policy) | 143 SelectFilePolicy* policy) |
| 137 : SelectFileDialog(listener, policy) { | 144 : SelectFileDialog(listener, policy) { |
| 138 JNIEnv* env = base::android::AttachCurrentThread(); | 145 JNIEnv* env = base::android::AttachCurrentThread(); |
| 139 java_object_.Reset( | 146 java_object_.Reset( |
| 140 Java_SelectFileDialog_create(env, reinterpret_cast<intptr_t>(this))); | 147 Java_SelectFileDialog_create(env, reinterpret_cast<intptr_t>(this))); |
| 141 } | 148 } |
| 142 | 149 |
| 143 bool SelectFileDialogImpl::HasMultipleFileTypeChoicesImpl() { | 150 bool SelectFileDialogImpl::HasMultipleFileTypeChoicesImpl() { |
| 144 NOTIMPLEMENTED(); | 151 NOTIMPLEMENTED(); |
| 145 return false; | 152 return false; |
| 146 } | 153 } |
| 147 | 154 |
| 148 SelectFileDialog* CreateSelectFileDialog(SelectFileDialog::Listener* listener, | 155 SelectFileDialog* CreateSelectFileDialog(SelectFileDialog::Listener* listener, |
| 149 SelectFilePolicy* policy) { | 156 SelectFilePolicy* policy) { |
| 150 return SelectFileDialogImpl::Create(listener, policy); | 157 return SelectFileDialogImpl::Create(listener, policy); |
| 151 } | 158 } |
| 152 | 159 |
| 153 } // namespace ui | 160 } // namespace ui |
| OLD | NEW |