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