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 #include "base/android/jni_android.h" | 5 #include "base/android/jni_android.h" |
6 | 6 |
7 #include "base/android/scoped_java_ref.h" | |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 | 9 |
9 namespace { | 10 namespace { |
10 JavaVM* g_jvm = 0; | 11 JavaVM* g_jvm = 0; |
11 jobject g_application_context = NULL; | 12 jobject g_application_context = NULL; |
12 } | 13 } |
13 | 14 |
14 namespace base { | 15 namespace base { |
15 namespace android { | 16 namespace android { |
16 | 17 |
(...skipping 22 matching lines...) Expand all Loading... | |
39 void InitApplicationContext(jobject context) { | 40 void InitApplicationContext(jobject context) { |
40 DCHECK(!g_application_context); | 41 DCHECK(!g_application_context); |
41 g_application_context = context; | 42 g_application_context = context; |
42 } | 43 } |
43 | 44 |
44 jobject GetApplicationContext() { | 45 jobject GetApplicationContext() { |
45 DCHECK(g_application_context); | 46 DCHECK(g_application_context); |
46 return g_application_context; | 47 return g_application_context; |
47 } | 48 } |
48 | 49 |
50 jmethodID GetMethodIDFromClassName(JNIEnv* env, | |
51 const char* const class_name, | |
52 const char* const method, | |
53 const char* const jni_signature) { | |
54 ScopedJavaLocalRef<jclass> clazz(env, env->FindClass(class_name)); | |
55 return GetMethodID(env, clazz.obj(), method, jni_signature); | |
56 } | |
57 | |
49 jmethodID GetMethodID(JNIEnv* env, | 58 jmethodID GetMethodID(JNIEnv* env, |
50 jclass clazz, | 59 jclass clazz, |
51 const char* const method, | 60 const char* const method, |
52 const char* const jni_signature) { | 61 const char* const jni_signature) { |
53 jmethodID id = env->GetMethodID(clazz, method, jni_signature); | 62 jmethodID id = env->GetMethodID(clazz, method, jni_signature); |
54 DCHECK(id) << method; | 63 DCHECK(id) << method; |
55 CheckException(env); | 64 CheckException(env); |
56 return id; | 65 return id; |
57 } | 66 } |
58 | 67 |
59 jmethodID GetStaticMethodID(JNIEnv* env, | 68 jmethodID GetStaticMethodID(JNIEnv* env, |
60 jclass clazz, | 69 jclass clazz, |
61 const char* const method, | 70 const char* const method, |
62 const char* const jni_signature) { | 71 const char* const jni_signature) { |
63 jmethodID id = env->GetStaticMethodID(clazz, method, jni_signature); | 72 jmethodID id = env->GetStaticMethodID(clazz, method, jni_signature); |
64 DCHECK(id) << method; | 73 DCHECK(id) << method; |
65 CheckException(env); | 74 CheckException(env); |
66 return id; | 75 return id; |
67 } | 76 } |
68 | 77 |
78 jfieldID GetFieldID(JNIEnv* env, | |
79 jclass clazz, | |
80 const char* const field, | |
M-A Ruel
2011/11/11 13:31:13
const char* field,
making the pointer itself cons
Steve Block
2011/11/11 16:05:20
Done.
| |
81 const char* const jni_signature) { | |
82 jfieldID id = env->GetFieldID(clazz, field, jni_signature); | |
83 DCHECK(id) << field; | |
84 CheckException(env); | |
85 return id; | |
86 } | |
87 | |
69 bool CheckException(JNIEnv* env) { | 88 bool CheckException(JNIEnv* env) { |
70 if (env->ExceptionCheck() == JNI_FALSE) | 89 if (env->ExceptionCheck() == JNI_FALSE) |
71 return false; | 90 return false; |
72 env->ExceptionDescribe(); | 91 env->ExceptionDescribe(); |
73 env->ExceptionClear(); | 92 env->ExceptionClear(); |
74 return true; | 93 return true; |
75 } | 94 } |
76 | 95 |
77 } // namespace android | 96 } // namespace android |
78 } // namespace base | 97 } // namespace base |
OLD | NEW |