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 "base/android/jni_array.h" | 5 #include "base/android/jni_array.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 if (!array) | 73 if (!array) |
74 return; | 74 return; |
75 jsize len = env->GetArrayLength(array); | 75 jsize len = env->GetArrayLength(array); |
76 for (jsize i = 0; i < len; ++i) { | 76 for (jsize i = 0; i < len; ++i) { |
77 ScopedJavaLocalRef<jstring> str(env, | 77 ScopedJavaLocalRef<jstring> str(env, |
78 static_cast<jstring>(env->GetObjectArrayElement(array, i))); | 78 static_cast<jstring>(env->GetObjectArrayElement(array, i))); |
79 out->push_back(ConvertJavaStringToUTF16(str)); | 79 out->push_back(ConvertJavaStringToUTF16(str)); |
80 } | 80 } |
81 } | 81 } |
82 | 82 |
| 83 void AppendJavaStringArrayToStringVector(JNIEnv* env, |
| 84 jobjectArray array, |
| 85 std::vector<std::string>* out) { |
| 86 DCHECK(out); |
| 87 if (!array) |
| 88 return; |
| 89 jsize len = env->GetArrayLength(array); |
| 90 for (jsize i = 0; i < len; ++i) { |
| 91 ScopedJavaLocalRef<jstring> str(env, |
| 92 static_cast<jstring>(env->GetObjectArrayElement(array, i))); |
| 93 out->push_back(ConvertJavaStringToUTF8(str)); |
| 94 } |
| 95 } |
| 96 |
83 void AppendJavaByteArrayToByteVector(JNIEnv* env, | 97 void AppendJavaByteArrayToByteVector(JNIEnv* env, |
84 jbyteArray byte_array, | 98 jbyteArray byte_array, |
85 std::vector<uint8>* out) { | 99 std::vector<uint8>* out) { |
86 DCHECK(out); | 100 DCHECK(out); |
87 if (!byte_array) | 101 if (!byte_array) |
88 return; | 102 return; |
89 jsize len = env->GetArrayLength(byte_array); | 103 jsize len = env->GetArrayLength(byte_array); |
90 jbyte* bytes = env->GetByteArrayElements(byte_array, NULL); | 104 jbyte* bytes = env->GetByteArrayElements(byte_array, NULL); |
91 out->insert(out->end(), bytes, bytes + len); | 105 out->insert(out->end(), bytes, bytes + len); |
92 env->ReleaseByteArrayElements(byte_array, bytes, JNI_ABORT); | 106 env->ReleaseByteArrayElements(byte_array, bytes, JNI_ABORT); |
93 } | 107 } |
94 | 108 |
95 void JavaByteArrayToByteVector(JNIEnv* env, | 109 void JavaByteArrayToByteVector(JNIEnv* env, |
96 jbyteArray byte_array, | 110 jbyteArray byte_array, |
97 std::vector<uint8>* out) { | 111 std::vector<uint8>* out) { |
98 DCHECK(out); | 112 DCHECK(out); |
99 out->clear(); | 113 out->clear(); |
100 AppendJavaByteArrayToByteVector(env, byte_array, out); | 114 AppendJavaByteArrayToByteVector(env, byte_array, out); |
101 } | 115 } |
102 | 116 |
103 } // namespace android | 117 } // namespace android |
104 } // namespace base | 118 } // namespace base |
OLD | NEW |