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/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "jni/SelectFileDialog_jni.h" | 15 #include "jni/SelectFileDialog_jni.h" |
16 #include "ui/base/android/window_android.h" | 16 #include "ui/base/android/window_android.h" |
17 #include "ui/shell_dialogs/selected_file_info.h" | 17 #include "ui/shell_dialogs/selected_file_info.h" |
18 | 18 |
| 19 using base::android::ConvertJavaStringToUTF8; |
| 20 |
19 namespace ui { | 21 namespace ui { |
20 | 22 |
21 // static | 23 // static |
22 SelectFileDialogImpl* SelectFileDialogImpl::Create(Listener* listener, | 24 SelectFileDialogImpl* SelectFileDialogImpl::Create(Listener* listener, |
23 SelectFilePolicy* policy) { | 25 SelectFilePolicy* policy) { |
24 return new SelectFileDialogImpl(listener, policy); | 26 return new SelectFileDialogImpl(listener, policy); |
25 } | 27 } |
26 | 28 |
27 void SelectFileDialogImpl::OnFileSelected(JNIEnv* env, | 29 void SelectFileDialogImpl::OnFileSelected(JNIEnv* env, |
28 jobject java_object, | 30 jobject java_object, |
29 jstring filepath, | 31 jstring filepath, |
30 jstring display_name) { | 32 jstring display_name) { |
31 if (listener_) { | 33 if (!listener_) |
32 std::string path = base::android::ConvertJavaStringToUTF8(env, filepath); | 34 return; |
33 std::string file_name = | 35 |
34 base::android::ConvertJavaStringToUTF8(env, display_name); | 36 std::string path = ConvertJavaStringToUTF8(env, filepath); |
| 37 std::string file_name = ConvertJavaStringToUTF8(env, display_name); |
| 38 base::FilePath file_path = base::FilePath(path); |
| 39 ui::SelectedFileInfo file_info; |
| 40 file_info.file_path = file_path; |
| 41 file_info.local_path = file_path; |
| 42 if (!file_name.empty()) |
| 43 file_info.display_name = file_name; |
| 44 |
| 45 listener_->FileSelectedWithExtraInfo(file_info, 0, NULL); |
| 46 } |
| 47 |
| 48 void SelectFileDialogImpl::OnMultipleFilesSelected(JNIEnv* env, |
| 49 jobject java_object, |
| 50 jobjectArray filepaths, |
| 51 jobjectArray display_names) { |
| 52 if (!listener_) |
| 53 return; |
| 54 |
| 55 std::vector<ui::SelectedFileInfo> selected_files; |
| 56 |
| 57 jsize length = env->GetArrayLength(filepaths); |
| 58 DCHECK(length == env->GetArrayLength(display_names)); |
| 59 for (int i = 0; i < length; ++i) { |
| 60 std::string path = ConvertJavaStringToUTF8( |
| 61 env, static_cast<jstring>(env->GetObjectArrayElement(filepaths, i))); |
| 62 std::string display_name = ConvertJavaStringToUTF8( |
| 63 env, |
| 64 static_cast<jstring>(env->GetObjectArrayElement(display_names, i))); |
| 65 |
35 base::FilePath file_path = base::FilePath(path); | 66 base::FilePath file_path = base::FilePath(path); |
| 67 |
36 ui::SelectedFileInfo file_info; | 68 ui::SelectedFileInfo file_info; |
37 file_info.file_path = file_path; | 69 file_info.file_path = file_path; |
38 file_info.local_path = file_path; | 70 file_info.local_path = file_path; |
39 if (!file_name.empty()) | 71 file_info.display_name = display_name; |
40 file_info.display_name = file_name; | 72 |
41 listener_->FileSelectedWithExtraInfo(file_info, 0, NULL); | 73 selected_files.push_back(file_info); |
42 } | 74 } |
| 75 |
| 76 listener_->MultiFilesSelectedWithExtraInfo(selected_files, NULL); |
43 } | 77 } |
44 | 78 |
45 void SelectFileDialogImpl::OnFileNotSelected( | 79 void SelectFileDialogImpl::OnFileNotSelected( |
46 JNIEnv* env, | 80 JNIEnv* env, |
47 jobject java_object) { | 81 jobject java_object) { |
48 if (listener_) | 82 if (listener_) |
49 listener_->FileSelectionCanceled(NULL); | 83 listener_->FileSelectionCanceled(NULL); |
50 } | 84 } |
51 | 85 |
52 bool SelectFileDialogImpl::IsRunning(gfx::NativeWindow) const { | 86 bool SelectFileDialogImpl::IsRunning(gfx::NativeWindow) const { |
(...skipping 14 matching lines...) Expand all Loading... |
67 gfx::NativeWindow owning_window, | 101 gfx::NativeWindow owning_window, |
68 void* params) { | 102 void* params) { |
69 JNIEnv* env = base::android::AttachCurrentThread(); | 103 JNIEnv* env = base::android::AttachCurrentThread(); |
70 | 104 |
71 // The first element in the pair is a list of accepted types, the second | 105 // The first element in the pair is a list of accepted types, the second |
72 // indicates whether the device's capture capabilities should be used. | 106 // indicates whether the device's capture capabilities should be used. |
73 typedef std::pair<std::vector<base::string16>, bool> AcceptTypes; | 107 typedef std::pair<std::vector<base::string16>, bool> AcceptTypes; |
74 AcceptTypes accept_types = std::make_pair(std::vector<base::string16>(), | 108 AcceptTypes accept_types = std::make_pair(std::vector<base::string16>(), |
75 false); | 109 false); |
76 | 110 |
77 if (params) { | 111 if (params) |
78 accept_types = *(reinterpret_cast<AcceptTypes*>(params)); | 112 accept_types = *(reinterpret_cast<AcceptTypes*>(params)); |
79 } | |
80 | 113 |
81 ScopedJavaLocalRef<jobjectArray> accept_types_java = | 114 ScopedJavaLocalRef<jobjectArray> accept_types_java = |
82 base::android::ToJavaArrayOfStrings(env, accept_types.first); | 115 base::android::ToJavaArrayOfStrings(env, accept_types.first); |
83 | 116 |
| 117 bool accept_multiple_files = SelectFileDialog::SELECT_OPEN_MULTI_FILE == type; |
| 118 |
84 Java_SelectFileDialog_selectFile(env, java_object_.obj(), | 119 Java_SelectFileDialog_selectFile(env, java_object_.obj(), |
85 accept_types_java.obj(), | 120 accept_types_java.obj(), |
86 accept_types.second, | 121 accept_types.second, |
| 122 accept_multiple_files, |
87 owning_window->GetJavaObject().obj()); | 123 owning_window->GetJavaObject().obj()); |
88 } | 124 } |
89 | 125 |
90 bool SelectFileDialogImpl::RegisterSelectFileDialog(JNIEnv* env) { | 126 bool SelectFileDialogImpl::RegisterSelectFileDialog(JNIEnv* env) { |
91 return RegisterNativesImpl(env); | 127 return RegisterNativesImpl(env); |
92 } | 128 } |
93 | 129 |
94 SelectFileDialogImpl::~SelectFileDialogImpl() { | 130 SelectFileDialogImpl::~SelectFileDialogImpl() { |
95 } | 131 } |
96 | 132 |
(...skipping 10 matching lines...) Expand all Loading... |
107 return false; | 143 return false; |
108 } | 144 } |
109 | 145 |
110 SelectFileDialog* CreateAndroidSelectFileDialog( | 146 SelectFileDialog* CreateAndroidSelectFileDialog( |
111 SelectFileDialog::Listener* listener, | 147 SelectFileDialog::Listener* listener, |
112 SelectFilePolicy* policy) { | 148 SelectFilePolicy* policy) { |
113 return SelectFileDialogImpl::Create(listener, policy); | 149 return SelectFileDialogImpl::Create(listener, policy); |
114 } | 150 } |
115 | 151 |
116 } // namespace ui | 152 } // namespace ui |
OLD | NEW |