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 #ifndef BASE_ANDROID_JNI_ARRAY_H_ | 5 #ifndef BASE_ANDROID_JNI_ARRAY_H_ |
6 #define BASE_ANDROID_JNI_ARRAY_H_ | 6 #define BASE_ANDROID_JNI_ARRAY_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/string16.h" | 14 #include "base/string16.h" |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 namespace android { | 17 namespace android { |
18 | 18 |
19 // Returns a new Java byte array converted from the given bytes array. | 19 // Returns a new Java byte array converted from the given bytes array. |
20 ScopedJavaLocalRef<jbyteArray> ToJavaByteArray( | 20 BASE_EXPORT ScopedJavaLocalRef<jbyteArray> ToJavaByteArray( |
21 JNIEnv* env, const uint8* bytes, size_t len); | 21 JNIEnv* env, const uint8* bytes, size_t len); |
22 | 22 |
23 // Returns a array of Java byte array converted from |v|. | 23 // Returns a array of Java byte array converted from |v|. |
24 ScopedJavaLocalRef<jobjectArray> ToJavaArrayOfByteArray( | 24 BASE_EXPORT ScopedJavaLocalRef<jobjectArray> ToJavaArrayOfByteArray( |
25 JNIEnv* env, const std::vector<std::string>& v); | 25 JNIEnv* env, const std::vector<std::string>& v); |
26 | 26 |
27 ScopedJavaLocalRef<jobjectArray> ToJavaArrayOfStrings( | 27 BASE_EXPORT ScopedJavaLocalRef<jobjectArray> ToJavaArrayOfStrings( |
28 JNIEnv* env, const std::vector<std::string>& v); | 28 JNIEnv* env, const std::vector<std::string>& v); |
29 | 29 |
30 ScopedJavaLocalRef<jobjectArray> ToJavaArrayOfStrings( | 30 BASE_EXPORT ScopedJavaLocalRef<jobjectArray> ToJavaArrayOfStrings( |
31 JNIEnv* env, const std::vector<string16>& v); | 31 JNIEnv* env, const std::vector<string16>& v); |
32 | 32 |
33 // Converts a Java string array to a native array. | 33 // Converts a Java string array to a native array. |
34 void AppendJavaStringArrayToStringVector(JNIEnv* env, | 34 BASE_EXPORT void AppendJavaStringArrayToStringVector( |
35 jobjectArray array, | 35 JNIEnv* env, |
36 std::vector<string16>* out); | 36 jobjectArray array, |
| 37 std::vector<string16>* out); |
37 | 38 |
38 void AppendJavaStringArrayToStringVector(JNIEnv* env, | 39 BASE_EXPORT void AppendJavaStringArrayToStringVector( |
39 jobjectArray array, | 40 JNIEnv* env, |
40 std::vector<std::string>* out); | 41 jobjectArray array, |
| 42 std::vector<std::string>* out); |
41 | 43 |
42 // Appends the Java bytes in |bytes_array| onto the end of |out|. | 44 // Appends the Java bytes in |bytes_array| onto the end of |out|. |
43 void AppendJavaByteArrayToByteVector(JNIEnv* env, | 45 BASE_EXPORT void AppendJavaByteArrayToByteVector( |
44 jbyteArray byte_array, | 46 JNIEnv* env, |
45 std::vector<uint8>* out); | 47 jbyteArray byte_array, |
| 48 std::vector<uint8>* out); |
46 | 49 |
47 // Replaces the content of |out| with the Java bytes in |bytes_array|. | 50 // Replaces the content of |out| with the Java bytes in |bytes_array|. |
48 void JavaByteArrayToByteVector(JNIEnv* env, | 51 BASE_EXPORT void JavaByteArrayToByteVector( |
49 jbyteArray byte_array, | 52 JNIEnv* env, |
50 std::vector<uint8>* out); | 53 jbyteArray byte_array, |
| 54 std::vector<uint8>* out); |
51 | 55 |
52 // Replaces the content of |out| with the Java ints in |int_array|. | 56 // Replaces the content of |out| with the Java ints in |int_array|. |
53 void JavaIntArrayToIntVector(JNIEnv* env, | 57 BASE_EXPORT void JavaIntArrayToIntVector( |
54 jintArray int_array, | 58 JNIEnv* env, |
55 std::vector<int>* out); | 59 jintArray int_array, |
| 60 std::vector<int>* out); |
56 | 61 |
57 } // namespace android | 62 } // namespace android |
58 } // namespace base | 63 } // namespace base |
59 | 64 |
60 #endif // BASE_ANDROID_JNI_ARRAY_H_ | 65 #endif // BASE_ANDROID_JNI_ARRAY_H_ |
OLD | NEW |