OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "select_file_dialog_android.h" | |
6 | |
7 #include "base/android/jni_android.h" | |
8 #include "base/android/jni_string.h" | |
9 #include "base/android/jni_array.h" | |
10 #include "base/android/scoped_java_ref.h" | |
11 #include "base/logging.h" | |
12 #include "base/string_split.h" | |
13 #include "base/string_util.h" | |
14 #include "base/utf_string_conversions.h" | |
15 #include "jni/SelectFileDialog_jni.h" | |
16 #include "ui/gfx/android/window_android.h" | |
17 | |
18 namespace ui { | |
19 | |
20 // static | |
21 SelectFileDialogImpl* SelectFileDialogImpl::Create(Listener* listener, | |
22 ui::SelectFilePolicy* policy) { | |
23 return new SelectFileDialogImpl(listener, policy); | |
24 } | |
25 | |
26 SelectFileDialogImpl::SelectFileDialogImpl(Listener* listener, | |
sky
2012/09/17 20:53:44
Remember, order of implementation needs to match o
aurimas (slooooooooow)
2012/09/17 22:20:48
Done.
| |
27 ui::SelectFilePolicy* policy) | |
28 : ui::SelectFileDialog(listener, policy), | |
29 is_running_(false) { | |
30 JNIEnv* env = base::android::AttachCurrentThread(); | |
31 java_object_.Reset( | |
32 Java_SelectFileDialog_create(env, reinterpret_cast<jint>(this))); | |
33 } | |
34 | |
35 SelectFileDialogImpl::~SelectFileDialogImpl() { | |
36 } | |
37 | |
38 void SelectFileDialogImpl::OnFileSelected(JNIEnv* env, | |
39 jobject javaObject, | |
40 jstring filepath) { | |
41 if (listener_) { | |
42 std::string path = base::android::ConvertJavaStringToUTF8(env, filepath); | |
43 listener_->FileSelected(FilePath(path), 0, NULL); | |
44 } | |
45 | |
46 is_running_ = false; | |
47 } | |
48 | |
49 void SelectFileDialogImpl::OnFileNotSelected(JNIEnv* env, jobject javaObject) { | |
50 if (listener_) | |
51 listener_->FileSelectionCanceled(NULL); | |
52 | |
53 is_running_ = false; | |
54 } | |
55 | |
56 bool SelectFileDialogImpl::IsRunning(gfx::NativeWindow) const { | |
57 return is_running_; | |
58 } | |
59 | |
60 void SelectFileDialogImpl::ListenerDestroyed() { | |
61 listener_ = NULL; | |
62 } | |
63 | |
64 void SelectFileDialogImpl::SelectFileImpl( | |
65 ui::SelectFileDialog::Type type, | |
66 const string16& title, | |
67 const FilePath& default_path, | |
68 const SelectFileDialog::FileTypeInfo* file_types, | |
69 int file_type_index, | |
70 const std::string& default_extension, | |
71 gfx::NativeWindow owning_window, | |
72 void* params) { | |
73 JNIEnv* env = base::android::AttachCurrentThread(); | |
74 | |
75 std::vector<string16> accept_types = | |
76 *(reinterpret_cast<std::vector<string16>*>(params)); | |
77 | |
78 // The last string in params is expected to be the string with capture value. | |
79 ScopedJavaLocalRef<jstring> capture_value = | |
80 base::android::ConvertUTF16ToJavaString(env, | |
81 StringToLowerASCII(accept_types.back())); | |
82 base::android::CheckException(env); | |
83 accept_types.pop_back(); | |
84 | |
85 // The rest params elements are expected to be accept_types. | |
86 ScopedJavaLocalRef<jobjectArray> accept_types_java = | |
87 base::android::ToJavaArrayOfStrings(env, accept_types); | |
88 | |
89 Java_SelectFileDialog_selectFile(env, java_object_.obj(), | |
90 accept_types_java.obj(), | |
91 capture_value.obj(), | |
92 owning_window->GetJavaObject().obj()); | |
93 is_running_ = true; | |
94 } | |
95 | |
96 bool SelectFileDialogImpl::HasMultipleFileTypeChoicesImpl() { | |
97 NOTIMPLEMENTED(); | |
98 return false; | |
99 } | |
100 | |
101 bool SelectFileDialogImpl::RegisterSelectFileDialog(JNIEnv* env) { | |
102 return RegisterNativesImpl(env); | |
103 } | |
104 | |
105 SelectFileDialog* CreateAndroidSelectFileDialog( | |
106 SelectFileDialog::Listener* listener, | |
107 SelectFilePolicy* policy) { | |
108 return SelectFileDialogImpl::Create(listener, policy); | |
109 } | |
110 | |
111 } // namespace ui | |
OLD | NEW |