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); | |
Miguel Garcia
2014/08/05 18:01:00
can you DCHECK that env->GetArrayLength(filepaths)
Peter Beverloo
2014/08/05 18:44:53
Done.
| |
58 for (int i = 0; i < length; ++i) { | |
59 std::string path = ConvertJavaStringToUTF8( | |
60 env, static_cast<jstring>(env->GetObjectArrayElement(filepaths, i))); | |
61 std::string display_name = ConvertJavaStringToUTF8( | |
62 env, | |
63 static_cast<jstring>(env->GetObjectArrayElement(display_names, i))); | |
64 | |
35 base::FilePath file_path = base::FilePath(path); | 65 base::FilePath file_path = base::FilePath(path); |
66 | |
36 ui::SelectedFileInfo file_info; | 67 ui::SelectedFileInfo file_info; |
37 file_info.file_path = file_path; | 68 file_info.file_path = file_path; |
38 file_info.local_path = file_path; | 69 file_info.local_path = file_path; |
39 if (!file_name.empty()) | 70 file_info.display_name = display_name; |
40 file_info.display_name = file_name; | 71 |
41 listener_->FileSelectedWithExtraInfo(file_info, 0, NULL); | 72 selected_files.push_back(file_info); |
42 } | 73 } |
74 | |
75 listener_->MultiFilesSelectedWithExtraInfo(selected_files, NULL); | |
43 } | 76 } |
44 | 77 |
45 void SelectFileDialogImpl::OnFileNotSelected( | 78 void SelectFileDialogImpl::OnFileNotSelected( |
46 JNIEnv* env, | 79 JNIEnv* env, |
47 jobject java_object) { | 80 jobject java_object) { |
48 if (listener_) | 81 if (listener_) |
49 listener_->FileSelectionCanceled(NULL); | 82 listener_->FileSelectionCanceled(NULL); |
50 } | 83 } |
51 | 84 |
52 bool SelectFileDialogImpl::IsRunning(gfx::NativeWindow) const { | 85 bool SelectFileDialogImpl::IsRunning(gfx::NativeWindow) const { |
(...skipping 14 matching lines...) Expand all Loading... | |
67 gfx::NativeWindow owning_window, | 100 gfx::NativeWindow owning_window, |
68 void* params) { | 101 void* params) { |
69 JNIEnv* env = base::android::AttachCurrentThread(); | 102 JNIEnv* env = base::android::AttachCurrentThread(); |
70 | 103 |
71 // The first element in the pair is a list of accepted types, the second | 104 // 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. | 105 // indicates whether the device's capture capabilities should be used. |
73 typedef std::pair<std::vector<base::string16>, bool> AcceptTypes; | 106 typedef std::pair<std::vector<base::string16>, bool> AcceptTypes; |
74 AcceptTypes accept_types = std::make_pair(std::vector<base::string16>(), | 107 AcceptTypes accept_types = std::make_pair(std::vector<base::string16>(), |
75 false); | 108 false); |
76 | 109 |
77 if (params) { | 110 if (params) |
78 accept_types = *(reinterpret_cast<AcceptTypes*>(params)); | 111 accept_types = *(reinterpret_cast<AcceptTypes*>(params)); |
79 } | |
80 | 112 |
81 ScopedJavaLocalRef<jobjectArray> accept_types_java = | 113 ScopedJavaLocalRef<jobjectArray> accept_types_java = |
82 base::android::ToJavaArrayOfStrings(env, accept_types.first); | 114 base::android::ToJavaArrayOfStrings(env, accept_types.first); |
83 | 115 |
116 bool accept_multiple_files = SelectFileDialog::SELECT_OPEN_MULTI_FILE == type; | |
Miguel Garcia
2014/08/05 18:01:00
Can you check that you are in JB MR2 or higher jus
Peter Beverloo
2014/08/05 18:44:53
I can add this check in the Java file, but I don't
| |
117 | |
84 Java_SelectFileDialog_selectFile(env, java_object_.obj(), | 118 Java_SelectFileDialog_selectFile(env, java_object_.obj(), |
85 accept_types_java.obj(), | 119 accept_types_java.obj(), |
86 accept_types.second, | 120 accept_types.second, |
121 accept_multiple_files, | |
87 owning_window->GetJavaObject().obj()); | 122 owning_window->GetJavaObject().obj()); |
88 } | 123 } |
89 | 124 |
90 bool SelectFileDialogImpl::RegisterSelectFileDialog(JNIEnv* env) { | 125 bool SelectFileDialogImpl::RegisterSelectFileDialog(JNIEnv* env) { |
91 return RegisterNativesImpl(env); | 126 return RegisterNativesImpl(env); |
92 } | 127 } |
93 | 128 |
94 SelectFileDialogImpl::~SelectFileDialogImpl() { | 129 SelectFileDialogImpl::~SelectFileDialogImpl() { |
95 } | 130 } |
96 | 131 |
(...skipping 10 matching lines...) Expand all Loading... | |
107 return false; | 142 return false; |
108 } | 143 } |
109 | 144 |
110 SelectFileDialog* CreateAndroidSelectFileDialog( | 145 SelectFileDialog* CreateAndroidSelectFileDialog( |
111 SelectFileDialog::Listener* listener, | 146 SelectFileDialog::Listener* listener, |
112 SelectFilePolicy* policy) { | 147 SelectFilePolicy* policy) { |
113 return SelectFileDialogImpl::Create(listener, policy); | 148 return SelectFileDialogImpl::Create(listener, policy); |
114 } | 149 } |
115 | 150 |
116 } // namespace ui | 151 } // namespace ui |
OLD | NEW |