OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_ANDROID_H_ | 5 #ifndef BASE_ANDROID_JNI_ANDROID_H_ |
6 #define BASE_ANDROID_JNI_ANDROID_H_ | 6 #define BASE_ANDROID_JNI_ANDROID_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 // Initializes the global application context object. The |context| should be | 24 // Initializes the global application context object. The |context| should be |
25 // the global reference of application context object. It is not necessarily | 25 // the global reference of application context object. It is not necessarily |
26 // called after InitVM(). | 26 // called after InitVM(). |
27 // TODO: We might combine InitVM() and InitApplicationContext() into one method. | 27 // TODO: We might combine InitVM() and InitApplicationContext() into one method. |
28 void InitApplicationContext(jobject context); | 28 void InitApplicationContext(jobject context); |
29 | 29 |
30 // Returns the application context assigned by InitApplicationContext(). | 30 // Returns the application context assigned by InitApplicationContext(). |
31 jobject GetApplicationContext(); | 31 jobject GetApplicationContext(); |
32 | 32 |
| 33 // Wraps a method ID. |
| 34 class MethodID { |
| 35 public: |
| 36 jmethodID id() { return id_; } |
| 37 protected: |
| 38 // Gets the method ID from the class name. Clears the pending Java exception |
| 39 // and returns NULL if the method is not found. Note that GetMethodID() below |
| 40 // avoids a class lookup, so should be used in preference when possible. |
| 41 MethodID(JNIEnv* env, const char* class_name, const char* method, |
| 42 const char* jni_signature); |
| 43 private: |
| 44 jmethodID id_; |
| 45 }; |
| 46 |
33 // Get the method ID for a method. Will clear the pending Java | 47 // Get the method ID for a method. Will clear the pending Java |
34 // exception and return 0 if the method is not found. | 48 // exception and return 0 if the method is not found. |
35 jmethodID GetMethodID(JNIEnv* env, | 49 jmethodID GetMethodID(JNIEnv* env, |
36 jclass clazz, | 50 jclass clazz, |
37 const char* const method, | 51 const char* const method, |
38 const char* const jni_signature); | 52 const char* const jni_signature); |
39 | 53 |
40 // Get the method ID for a class static method. Will clear the pending Java | 54 // Get the method ID for a class static method. Will clear the pending Java |
41 // exception and return 0 if the method is not found. | 55 // exception and return 0 if the method is not found. |
42 jmethodID GetStaticMethodID(JNIEnv* env, | 56 jmethodID GetStaticMethodID(JNIEnv* env, |
43 jclass clazz, | 57 jclass clazz, |
44 const char* const method, | 58 const char* const method, |
45 const char* const jni_signature); | 59 const char* const jni_signature); |
46 | 60 |
47 // Returns true if an exception is pending in the provided JNIEnv*. | 61 // Gets the field ID for a class field. Clears the pending Java exception and |
48 // If an exception is pending, it is printed. | 62 // returns NULL if the field is not found. |
| 63 jfieldID GetFieldID(JNIEnv* env, |
| 64 jclass clazz, |
| 65 const char* field, |
| 66 const char* jni_signature); |
| 67 |
| 68 // Returns true if an exception is pending in the provided JNIEnv*. If an |
| 69 // exception is pending, this function prints and then clears it. |
49 bool CheckException(JNIEnv* env); | 70 bool CheckException(JNIEnv* env); |
50 | 71 |
51 } // namespace android | 72 } // namespace android |
52 } // namespace base | 73 } // namespace base |
53 | 74 |
54 #endif // BASE_ANDROID_JNI_ANDROID_H_ | 75 #endif // BASE_ANDROID_JNI_ANDROID_H_ |
OLD | NEW |