Chromium Code Reviews| 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/files/file_util.h" | |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/stringprintf.h" | |
| 14 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 15 #include "jni/SelectFileDialog_jni.h" | 17 #include "jni/SelectFileDialog_jni.h" |
| 16 #include "ui/base/android/window_android.h" | 18 #include "ui/base/android/window_android.h" |
| 17 #include "ui/shell_dialogs/selected_file_info.h" | 19 #include "ui/shell_dialogs/selected_file_info.h" |
| 18 | 20 |
| 19 using base::android::ConvertJavaStringToUTF8; | 21 using base::android::ConvertJavaStringToUTF8; |
| 22 using base::android::ConvertUTF8ToJavaString; | |
| 20 | 23 |
| 21 namespace ui { | 24 namespace ui { |
| 22 | 25 |
| 23 // static | 26 // static |
| 24 SelectFileDialogImpl* SelectFileDialogImpl::Create(Listener* listener, | 27 SelectFileDialogImpl* SelectFileDialogImpl::Create(Listener* listener, |
| 25 SelectFilePolicy* policy) { | 28 SelectFilePolicy* policy) { |
| 26 return new SelectFileDialogImpl(listener, policy); | 29 return new SelectFileDialogImpl(listener, policy); |
| 27 } | 30 } |
| 28 | 31 |
| 29 void SelectFileDialogImpl::OnFileSelected(JNIEnv* env, | 32 void SelectFileDialogImpl::OnFileSelected(JNIEnv* env, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 } | 87 } |
| 85 | 88 |
| 86 bool SelectFileDialogImpl::IsRunning(gfx::NativeWindow) const { | 89 bool SelectFileDialogImpl::IsRunning(gfx::NativeWindow) const { |
| 87 return listener_; | 90 return listener_; |
| 88 } | 91 } |
| 89 | 92 |
| 90 void SelectFileDialogImpl::ListenerDestroyed() { | 93 void SelectFileDialogImpl::ListenerDestroyed() { |
| 91 listener_ = NULL; | 94 listener_ = NULL; |
| 92 } | 95 } |
| 93 | 96 |
| 97 ScopedJavaLocalRef<jstring> SelectFileDialogImpl::GetUniqueFilePath( | |
| 98 JNIEnv* env, jobject java_object, jstring path) { | |
| 99 base::FilePath file_path(ConvertJavaStringToUTF8(env, path)); | |
| 100 | |
| 101 ScopedJavaLocalRef<jstring> result; | |
| 102 | |
| 103 // TODO(changwan): use GetUniquePath() instead once | |
| 104 // https://codereview.chromium.org/493363003/ lands. | |
| 105 int uniquifier = base::GetUniquePathNumber(file_path, | |
| 106 base::FilePath::StringType()); | |
| 107 if (uniquifier > 0) { | |
| 108 file_path = file_path.InsertBeforeExtensionASCII( | |
| 109 base::StringPrintf(" (%d)", uniquifier)); | |
| 110 result = ConvertUTF8ToJavaString(env, file_path.value()); | |
| 111 return ScopedJavaLocalRef<jstring>(result); | |
| 112 } | |
| 113 return result; | |
| 114 } | |
| 115 | |
| 94 void SelectFileDialogImpl::SelectFileImpl( | 116 void SelectFileDialogImpl::SelectFileImpl( |
| 95 SelectFileDialog::Type type, | 117 SelectFileDialog::Type type, |
| 96 const base::string16& title, | 118 const base::string16& title, |
| 97 const base::FilePath& default_path, | 119 const base::FilePath& default_path, |
| 98 const SelectFileDialog::FileTypeInfo* file_types, | 120 const SelectFileDialog::FileTypeInfo* file_types, |
| 99 int file_type_index, | 121 int file_type_index, |
| 100 const std::string& default_extension, | 122 const std::string& default_extension, |
| 101 gfx::NativeWindow owning_window, | 123 gfx::NativeWindow owning_window, |
| 102 void* params) { | 124 void* params) { |
| 103 JNIEnv* env = base::android::AttachCurrentThread(); | 125 JNIEnv* env = base::android::AttachCurrentThread(); |
| 104 | 126 |
| 127 if (type == SelectFileDialog::SELECT_SAVEAS_FILE) { | |
| 128 ScopedJavaLocalRef<jstring> jdefault_path = | |
|
Ted C
2014/09/19 22:31:40
this block is indented 2 too many
Changwan Ryu
2014/09/22 14:02:37
Done.
Changwan Ryu
2014/09/22 14:02:37
Done.
| |
| 129 ConvertUTF8ToJavaString(env, default_path.value()); | |
| 130 Java_SelectFileDialog_showOverwriteDialog( | |
| 131 env, java_object_.obj(), jdefault_path.obj(), | |
| 132 owning_window->GetJavaObject().obj()); | |
| 133 return; | |
| 134 } | |
| 135 | |
| 105 // The first element in the pair is a list of accepted types, the second | 136 // The first element in the pair is a list of accepted types, the second |
| 106 // indicates whether the device's capture capabilities should be used. | 137 // indicates whether the device's capture capabilities should be used. |
| 107 typedef std::pair<std::vector<base::string16>, bool> AcceptTypes; | 138 typedef std::pair<std::vector<base::string16>, bool> AcceptTypes; |
| 108 AcceptTypes accept_types = std::make_pair(std::vector<base::string16>(), | 139 AcceptTypes accept_types = std::make_pair(std::vector<base::string16>(), |
| 109 false); | 140 false); |
| 110 | 141 |
| 111 if (params) | 142 if (params) |
| 112 accept_types = *(reinterpret_cast<AcceptTypes*>(params)); | 143 accept_types = *(reinterpret_cast<AcceptTypes*>(params)); |
| 113 | 144 |
| 114 ScopedJavaLocalRef<jobjectArray> accept_types_java = | 145 ScopedJavaLocalRef<jobjectArray> accept_types_java = |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 143 return false; | 174 return false; |
| 144 } | 175 } |
| 145 | 176 |
| 146 SelectFileDialog* CreateAndroidSelectFileDialog( | 177 SelectFileDialog* CreateAndroidSelectFileDialog( |
| 147 SelectFileDialog::Listener* listener, | 178 SelectFileDialog::Listener* listener, |
| 148 SelectFilePolicy* policy) { | 179 SelectFilePolicy* policy) { |
| 149 return SelectFileDialogImpl::Create(listener, policy); | 180 return SelectFileDialogImpl::Create(listener, policy); |
| 150 } | 181 } |
| 151 | 182 |
| 152 } // namespace ui | 183 } // namespace ui |
| OLD | NEW |