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" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 SelectFileDialog::Type type, | 55 SelectFileDialog::Type type, |
| 56 const base::string16& title, | 56 const base::string16& title, |
| 57 const base::FilePath& default_path, | 57 const base::FilePath& default_path, |
| 58 const SelectFileDialog::FileTypeInfo* file_types, | 58 const SelectFileDialog::FileTypeInfo* file_types, |
| 59 int file_type_index, | 59 int file_type_index, |
| 60 const std::string& default_extension, | 60 const std::string& default_extension, |
| 61 gfx::NativeWindow owning_window, | 61 gfx::NativeWindow owning_window, |
| 62 void* params) { | 62 void* params) { |
| 63 JNIEnv* env = base::android::AttachCurrentThread(); | 63 JNIEnv* env = base::android::AttachCurrentThread(); |
| 64 | 64 |
| 65 ScopedJavaLocalRef<jstring> capture_value; | 65 // The first element in the pair is a list of accepted types, the second |
| 66 std::vector<base::string16> accept_types; | 66 // indicates whether the device's capture capabilities should be used. |
| 67 typedef std::pair<std::vector<base::string16>, bool> AcceptTypes; | |
| 68 AcceptTypes accept_types = std::make_pair(std::vector<base::string16>(), | |
| 69 false); | |
| 70 | |
| 67 if (params) { | 71 if (params) { |
| 68 accept_types = *(reinterpret_cast<std::vector<base::string16>*>(params)); | 72 accept_types = *(reinterpret_cast<AcceptTypes*>(params)); |
|
sky
2013/07/08 21:13:51
spacing is off here.
Raphael Kubo da Costa (rakuco)
2013/07/08 21:27:01
Done.
| |
| 69 | |
| 70 // The last string in params is expected to be the string | |
| 71 // with capture value. | |
| 72 capture_value = base::android::ConvertUTF16ToJavaString(env, | |
| 73 StringToLowerASCII(accept_types.back())); | |
| 74 base::android::CheckException(env); | |
| 75 accept_types.pop_back(); | |
| 76 } else { | |
| 77 capture_value = base::android::ConvertUTF8ToJavaString(env, "filesystem"); | |
| 78 } | 73 } |
| 79 | 74 |
| 80 // The rest params elements are expected to be accept_types. | |
| 81 ScopedJavaLocalRef<jobjectArray> accept_types_java = | 75 ScopedJavaLocalRef<jobjectArray> accept_types_java = |
| 82 base::android::ToJavaArrayOfStrings(env, accept_types); | 76 base::android::ToJavaArrayOfStrings(env, accept_types.first); |
| 77 bool has_capture_attribute = accept_types.second; | |
|
sky
2013/07/08 21:13:51
Is there a reason for the local rather then accepo
Raphael Kubo da Costa (rakuco)
2013/07/08 21:27:01
It seemed to be easier to understand that way. Wou
sky
2013/07/08 21:32:32
I like consistency. Since you don't declare a loca
Raphael Kubo da Costa (rakuco)
2013/07/08 21:38:12
Done.
| |
| 83 | 78 |
| 84 Java_SelectFileDialog_selectFile(env, java_object_.obj(), | 79 Java_SelectFileDialog_selectFile(env, java_object_.obj(), |
| 85 accept_types_java.obj(), | 80 accept_types_java.obj(), |
| 86 capture_value.obj(), | 81 has_capture_attribute, |
| 87 owning_window->GetJavaObject().obj()); | 82 owning_window->GetJavaObject().obj()); |
| 88 is_running_ = true; | 83 is_running_ = true; |
| 89 } | 84 } |
| 90 | 85 |
| 91 bool SelectFileDialogImpl::RegisterSelectFileDialog(JNIEnv* env) { | 86 bool SelectFileDialogImpl::RegisterSelectFileDialog(JNIEnv* env) { |
| 92 return RegisterNativesImpl(env); | 87 return RegisterNativesImpl(env); |
| 93 } | 88 } |
| 94 | 89 |
| 95 SelectFileDialogImpl::~SelectFileDialogImpl() { | 90 SelectFileDialogImpl::~SelectFileDialogImpl() { |
| 96 } | 91 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 108 return false; | 103 return false; |
| 109 } | 104 } |
| 110 | 105 |
| 111 SelectFileDialog* CreateAndroidSelectFileDialog( | 106 SelectFileDialog* CreateAndroidSelectFileDialog( |
| 112 SelectFileDialog::Listener* listener, | 107 SelectFileDialog::Listener* listener, |
| 113 SelectFilePolicy* policy) { | 108 SelectFilePolicy* policy) { |
| 114 return SelectFileDialogImpl::Create(listener, policy); | 109 return SelectFileDialogImpl::Create(listener, policy); |
| 115 } | 110 } |
| 116 | 111 |
| 117 } // namespace ui | 112 } // namespace ui |
| OLD | NEW |