Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Side by Side Diff: base/android/jni_android.h

Issue 9599010: JNI Bindings on Chrome for Android: unfork. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mark's comment Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/android/jni_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_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
11 #include "base/android/scoped_java_ref.h" 11 #include "base/android/scoped_java_ref.h"
12 #include "base/compiler_specific.h"
12 13
13 namespace base { 14 namespace base {
14 namespace android { 15 namespace android {
15 16
16 // Attach the current thread to the VM (if necessary) and return the JNIEnv*. 17 // Attach the current thread to the VM (if necessary) and return the JNIEnv*.
17 JNIEnv* AttachCurrentThread(); 18 JNIEnv* AttachCurrentThread();
18 19
19 // Detach the current thread from VM if it is attached. 20 // Detach the current thread from VM if it is attached.
20 void DetachFromVM(); 21 void DetachFromVM();
21 22
(...skipping 11 matching lines...) Expand all
33 // must NOT release it. 34 // must NOT release it.
34 const jobject GetApplicationContext(); 35 const jobject GetApplicationContext();
35 36
36 // Finds the class named |class_name| and returns it. 37 // Finds the class named |class_name| and returns it.
37 // Use this method instead of invoking directly the JNI FindClass method (to 38 // Use this method instead of invoking directly the JNI FindClass method (to
38 // prevent leaking local references). 39 // prevent leaking local references).
39 // This method triggers a fatal assertion if the class could not be found. 40 // This method triggers a fatal assertion if the class could not be found.
40 // Use HasClass if you need to check whether the class exists. 41 // Use HasClass if you need to check whether the class exists.
41 ScopedJavaLocalRef<jclass> GetClass(JNIEnv* env, const char* class_name); 42 ScopedJavaLocalRef<jclass> GetClass(JNIEnv* env, const char* class_name);
42 43
44 // Similar to the above, but the caller is responsible to manage the jclass
45 // lifetime.
46 jclass GetUnscopedClass(JNIEnv* env, const char* class_name) WARN_UNUSED_RESULT;
47
43 // Returns true iff the class |class_name| could be found. 48 // Returns true iff the class |class_name| could be found.
44 bool HasClass(JNIEnv* env, const char* class_name); 49 bool HasClass(JNIEnv* env, const char* class_name);
45 50
46 // Returns the method ID for the method with the specified name and signature. 51 // Returns the method ID for the method with the specified name and signature.
47 // This method triggers a fatal assertion if the method could not be found. 52 // This method triggers a fatal assertion if the method could not be found.
48 // Use HasMethod if you need to check whether a method exists. 53 // Use HasMethod if you need to check whether a method exists.
49 jmethodID GetMethodID(JNIEnv* env, 54 jmethodID GetMethodID(JNIEnv* env,
50 const JavaRef<jclass>& clazz, 55 const JavaRef<jclass>& clazz,
51 const char* method_name, 56 const char* method_name,
52 const char* jni_signature); 57 const char* jni_signature);
53 58
59 // Similar to GetMethodID, but takes a raw jclass.
60 jmethodID GetMethodID(JNIEnv* env,
61 jclass clazz,
62 const char* method_name,
63 const char* jni_signature);
64
54 // Returns the method ID for the static method with the specified name and 65 // Returns the method ID for the static method with the specified name and
55 // signature. 66 // signature.
56 // This method triggers a fatal assertion if the method could not be found. 67 // This method triggers a fatal assertion if the method could not be found.
57 // Use HasMethod if you need to check whether a method exists. 68 // Use HasMethod if you need to check whether a method exists.
58 jmethodID GetStaticMethodID(JNIEnv* env, 69 jmethodID GetStaticMethodID(JNIEnv* env,
59 const JavaRef<jclass>& clazz, 70 const JavaRef<jclass>& clazz,
60 const char* method_name, 71 const char* method_name,
61 const char* jni_signature); 72 const char* jni_signature);
62 73
74 // Similar to the GetStaticMethodID, but takes a raw jclass.
75 jmethodID GetStaticMethodID(JNIEnv* env,
76 jclass clazz,
77 const char* method_name,
78 const char* jni_signature);
79
80
63 // Returns true iff |clazz| has a method with the specified name and signature. 81 // Returns true iff |clazz| has a method with the specified name and signature.
64 bool HasMethod(JNIEnv* env, 82 bool HasMethod(JNIEnv* env,
65 const JavaRef<jclass>& clazz, 83 const JavaRef<jclass>& clazz,
66 const char* method_name, 84 const char* method_name,
67 const char* jni_signature); 85 const char* jni_signature);
68 86
69 // Gets the method ID from the class name. Clears the pending Java exception 87 // Gets the method ID from the class name. Clears the pending Java exception
70 // and returns NULL if the method is not found. Caches results. Note that 88 // and returns NULL if the method is not found. Caches results. Note that
71 // GetMethodID() below avoids a class lookup, but does not cache results. 89 // GetMethodID() below avoids a class lookup, but does not cache results.
72 // Strings passed to this function are held in the cache and MUST remain valid 90 // Strings passed to this function are held in the cache and MUST remain valid
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // and returns true. 124 // and returns true.
107 bool ClearException(JNIEnv* env); 125 bool ClearException(JNIEnv* env);
108 126
109 // This function will call CHECK() macro if there's any pending exception. 127 // This function will call CHECK() macro if there's any pending exception.
110 void CheckException(JNIEnv* env); 128 void CheckException(JNIEnv* env);
111 129
112 } // namespace android 130 } // namespace android
113 } // namespace base 131 } // namespace base
114 132
115 #endif // BASE_ANDROID_JNI_ANDROID_H_ 133 #endif // BASE_ANDROID_JNI_ANDROID_H_
OLDNEW
« no previous file with comments | « no previous file | base/android/jni_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698