Back to index

lightning-sunbird  0.9+nobinonly
nsJNI.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039  * Proxy JNI implementation.
00040  */
00041 
00042 #include "jni.h"
00043 #include "nsISecureJNI2.h"
00044 #include "nsHashtable.h"
00045 #include "nsVoidArray.h"
00046 #include "plstr.h"
00047 
00048 // Method Signature Processing.
00049 
00050 static jni_type get_jni_type(char sig)
00051 {
00052        switch (sig) {
00053        case 'L':
00054        case '[':
00055               return jobject_type;
00056        case 'Z':
00057               return jboolean_type;
00058        case 'B':
00059               return jbyte_type;
00060        case 'C':
00061               return jchar_type;
00062        case 'S':
00063               return jshort_type;
00064        case 'I':
00065               return jint_type;
00066        case 'J':
00067               return jlong_type;
00068        case 'F':
00069               return jfloat_type;
00070        case 'D':
00071               return jdouble_type;
00072        case 'V':
00073               return jvoid_type;
00074        }
00075        return jvoid_type;
00076 }
00077 
00078 static PRBool get_method_type(const char* sig, PRUint32& arg_count, jni_type*& arg_types, jni_type& return_type)
00079 {
00080        arg_count = 0;
00081        if (sig[0] == '(') {
00082               nsVoidArray vec;
00083               ++sig;
00084               while (*sig != ')' && *sig) {
00085                      char arg_sig = *sig++;
00086                      jni_type arg_type = get_jni_type(arg_sig);
00087                      if (arg_type == jobject_type) {
00088                             // could be an array or an object.
00089                             while (*sig == '[') ++sig;
00090                             if (*sig == 'L') {
00091                                    // skip over "className;"
00092                                    ++sig;
00093                                    while (*sig != ';') ++sig;
00094                             }
00095                             // skip over scalar or ';'.
00096                             ++sig;
00097                      }
00098                      vec.AppendElement((void*)arg_type);
00099               }
00100               arg_count = vec.Count();
00101               arg_types = new jni_type[arg_count];
00102               for (int index = arg_count - 1; index >= 0; --index)
00103                      arg_types[index] = jni_type(vec.ElementAt(index));
00104               if (*sig == ')') {
00105                      char return_sig = *++sig;
00106                      return_type = get_jni_type(return_sig);
00107               }
00108        }
00109        return PR_FALSE;
00110 }
00111 
00112 class JNIHashKey : public nsHashKey {
00113 public:
00114        JNIHashKey(void* key) : mKey(key) {}
00115 
00116        virtual PRUint32 HashValue(void) const { return PRUint32(mKey); }
00117        virtual PRBool Equals(const nsHashKey *aKey) const { return mKey == ((JNIHashKey*)aKey)->mKey; }
00118        virtual nsHashKey *Clone(void) const { return new JNIHashKey(mKey); }
00119 
00120 private:
00121        void* mKey;
00122 };
00123 
00124 struct JNIMember {
00125        char* mName;
00126        char* mSignature;
00127        
00128        JNIMember(const char* name, const char* sig);
00129        ~JNIMember();
00130 };
00131 
00132 JNIMember::JNIMember(const char* name, const char* sig)
00133        : mName(NULL), mSignature(NULL)
00134 {
00135        mName = PL_strdup(name);
00136        mSignature = PL_strdup(sig);
00137 }
00138 
00139 JNIMember::~JNIMember()
00140 {
00141        PL_strfree(mName);
00142        PL_strfree(mSignature);
00143 }
00144 
00145 struct JNIField : JNIMember {
00146        jfieldID mFieldID;
00147        jni_type mFieldType;
00148        
00149        JNIField(const char* name, const char* sig, jfieldID fieldID);
00150 };
00151 
00152 JNIField::JNIField(const char* name, const char* sig, jfieldID fieldID)
00153        : JNIMember(name, sig), mFieldID(fieldID), mFieldType(get_jni_type(*sig))
00154 {
00155 }
00156 
00157 struct JNIMethod : JNIMember {
00158        jmethodID mMethodID;
00159        PRUint32 mArgCount;
00160        jni_type* mArgTypes;
00161        jni_type mReturnType;
00162        
00163        JNIMethod(const char* name, const char* sig, jmethodID methodID);
00164        ~JNIMethod();
00165        
00166        jvalue* marshallArgs(va_list args);
00167 };
00168 
00169 JNIMethod::JNIMethod(const char* name, const char* sig, jmethodID methodID)
00170        : JNIMember(name, sig), mMethodID(methodID), mArgCount(0), mArgTypes(NULL), mReturnType(jvoid_type)
00171 {
00172        get_method_type(sig, mArgCount, mArgTypes, mReturnType);
00173 }
00174 
00175 JNIMethod::~JNIMethod()
00176 {
00177        if (mArgTypes != NULL)
00178               delete[] mArgTypes;
00179 }
00180 
00184 jvalue* JNIMethod::marshallArgs(va_list args)
00185 {
00186        PRUint32 argCount = mArgCount;
00187        jni_type* argTypes = mArgTypes;
00188        jvalue* jargs = new jvalue[argCount];
00189        if (jargs != NULL) {
00190               for (int i = 0; i < argCount; i++) {
00191                      switch (argTypes[i]) {
00192                      case jobject_type:
00193                             jargs[i].l = va_arg(args, jobject);
00194                             break;
00195                      case jboolean_type:
00196                             jargs[i].z = va_arg(args, jboolean);
00197                             break;
00198                      case jbyte_type:
00199                             jargs[i].b = va_arg(args, jbyte);
00200                             break;
00201                      case jchar_type:
00202                             jargs[i].b = va_arg(args, jbyte);
00203                             break;
00204                      case jshort_type:
00205                             jargs[i].s = va_arg(args, jshort);
00206                             break;
00207                      case jint_type:
00208                             jargs[i].i = va_arg(args, jint);
00209                             break;
00210                      case jlong_type:
00211                             jargs[i].j = va_arg(args, jlong);
00212                             break;
00213                      case jfloat_type:
00214                             jargs[i].f = va_arg(args, jfloat);
00215                             break;
00216                      case jdouble_type:
00217                             jargs[i].d = va_arg(args, jdouble);
00218                             break;
00219                      }
00220               }
00221        }
00222        return jargs;
00223 }
00224 
00229 class MarshalledArgs {
00230 public:
00231        MarshalledArgs(JNIMethod* forMethod, va_list args) : mArgs(forMethod->marshallArgs(args)) {}
00232        ~MarshalledArgs() { delete[] mArgs; }
00233 
00234        operator jvalue* () { return mArgs; }
00235        
00236 private:
00237        jvalue* mArgs;
00238 };
00239 
00240 class nsJNIEnv : public JNIEnv {
00241 private:
00242        static JNINativeInterface_ theFuncs;
00243        static nsHashtable* theIDTable;
00244        nsISecureJNI2* mSecureEnv;
00245        nsISecurityContext* mContext;
00246        jobject mJavaThread;
00247        
00248        static nsJNIEnv& nsJNIEnvRef(JNIEnv* env) { return *(nsJNIEnv*)env; }
00249 
00250        nsISecureJNI2* operator->() { return mSecureEnv; }
00251        nsISecurityContext* getContext() { return mContext; }
00252        
00253        static jint JNICALL GetVersion(JNIEnv* env)
00254        {
00255               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00256               jint version = 0;
00257               nsresult result =  secureEnv->GetVersion(&version);
00258               return version;
00259        }
00260 
00261        static jclass JNICALL DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len)
00262        {
00263               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00264               jclass outClass = NULL;
00265               nsresult result = secureEnv->DefineClass(name, loader, buf, len, &outClass);
00266               return outClass;
00267        }
00268 
00269        static jclass JNICALL FindClass(JNIEnv *env, const char *name)
00270        {
00271               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00272               jclass outClass = NULL;
00273               nsresult result = secureEnv->FindClass(name, &outClass);
00274               return outClass;
00275        }
00276 
00277        static jclass JNICALL GetSuperclass(JNIEnv *env, jclass sub)
00278        {
00279               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00280               jclass outSuper = NULL;
00281               nsresult result = secureEnv->GetSuperclass(sub, &outSuper);
00282               return outSuper;
00283        }
00284 
00285        static jboolean JNICALL IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
00286        {
00287               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00288               jboolean outIsAssignable = FALSE;
00289               nsresult result = secureEnv->IsAssignableFrom(sub, sup, &outIsAssignable);
00290               return outIsAssignable;
00291        }
00292        
00293        static jint Throw(JNIEnv *env, jthrowable obj)
00294        {
00295               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00296               jint outStatus = FALSE;
00297               nsresult result = secureEnv->Throw(obj, &outStatus);
00298               return outStatus;
00299        }
00300        
00301        static jint JNICALL ThrowNew(JNIEnv *env, jclass clazz, const char *msg)
00302        {
00303               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00304               jint outStatus = FALSE;
00305               nsresult result = secureEnv->ThrowNew(clazz, msg, &outStatus);
00306               return outStatus;
00307        }
00308        
00309        static jthrowable JNICALL ExceptionOccurred(JNIEnv *env)
00310        {
00311               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00312               jthrowable outThrowable = NULL;
00313               nsresult result = secureEnv->ExceptionOccurred(&outThrowable);
00314               return outThrowable;
00315        }
00316 
00317        static void JNICALL ExceptionDescribe(JNIEnv *env)
00318        {
00319               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00320               nsresult result = secureEnv->ExceptionDescribe();
00321        }
00322        
00323        static void JNICALL ExceptionClear(JNIEnv *env)
00324        {
00325               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00326               nsresult result = secureEnv->ExceptionClear();
00327        }
00328        
00329        static void JNICALL FatalError(JNIEnv *env, const char *msg)
00330        {
00331               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00332               nsresult result = secureEnv->FatalError(msg);
00333        }
00334 
00335        static jobject JNICALL NewGlobalRef(JNIEnv *env, jobject lobj)
00336        {
00337               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00338               jobject outGlobalRef = NULL;
00339               nsresult result = secureEnv->NewGlobalRef(lobj, &outGlobalRef);
00340               return outGlobalRef;
00341        }
00342        
00343        static void JNICALL DeleteGlobalRef(JNIEnv *env, jobject gref)
00344        {
00345               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00346               nsresult result = secureEnv->DeleteGlobalRef(gref);
00347        }
00348        
00349        static void JNICALL DeleteLocalRef(JNIEnv *env, jobject obj)
00350        {
00351               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00352               nsresult result = secureEnv->DeleteLocalRef(obj);
00353        }
00354        
00355        static jboolean JNICALL IsSameObject(JNIEnv *env, jobject obj1, jobject obj2)
00356        {
00357               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00358               jboolean outIsSameObject = FALSE;
00359               nsresult result = secureEnv->IsSameObject(obj1, obj2, &outIsSameObject);
00360               return outIsSameObject;
00361        }
00362 
00363        static jobject JNICALL AllocObject(JNIEnv *env, jclass clazz)
00364        {
00365               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00366               jobject outObject = NULL;
00367               nsresult result = secureEnv->AllocObject(clazz, &outObject);
00368               return outObject;
00369        }
00370        
00371        static jobject JNICALL NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
00372        {
00373               va_list args; va_start(args, methodID);
00374               jobject outObject = NewObjectV(env, clazz, methodID, args);
00375               va_end(args);
00376               return outObject;
00377        }
00378        
00379        static jobject JNICALL NewObjectV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
00380        {
00381               jobject outObject = NULL;
00382               
00383               // convert the va_list into an array of jvalues.
00384               JNIMethod* method = (JNIMethod*)methodID;
00385               MarshalledArgs jargs(method, args);
00386               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00387               nsresult result = secureEnv->NewObject(clazz, method->mMethodID, jargs, &outObject, secureEnv.getContext());
00388               
00389               return outObject;
00390        }
00391 
00392        static jobject JNICALL NewObjectA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
00393        {
00394               jobject outObject = NULL;
00395               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00396               JNIMethod* method = (JNIMethod*)methodID;
00397               nsresult result = secureEnv->NewObject(clazz, method->mMethodID, args, &outObject, secureEnv.getContext());
00398               return outObject;
00399        }
00400 
00401        static jclass JNICALL GetObjectClass(JNIEnv *env, jobject obj)
00402        {
00403               jclass outClass = NULL;
00404               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00405               nsresult result = secureEnv->GetObjectClass(obj, &outClass);
00406               return outClass;
00407        }
00408        
00409        static jboolean JNICALL IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
00410        {
00411               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00412               jboolean outIsInstanceOf = FALSE;
00413               nsresult result = secureEnv->IsInstanceOf(obj, clazz, &outIsInstanceOf);
00414               return outIsInstanceOf;
00415        }
00416 
00417        static jmethodID JNICALL GetMethodID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
00418        {
00419               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00420               jmethodID outMethodID = NULL;
00421               nsresult result = secureEnv->GetMethodID(clazz, name, sig, &outMethodID);
00422               if (result == NS_OK) {
00423                      JNIHashKey key(outMethodID);
00424                      JNIMethod* method = (JNIMethod*) theIDTable->Get(&key);
00425                      if (method == NULL) {
00426                             method = new JNIMethod(name, sig, outMethodID);
00427                             theIDTable->Put(&key, method);
00428                      }
00429                      outMethodID = jmethodID(method);
00430               }
00431               return outMethodID;
00432        }
00433        
00438        // Virtual Invokers.
00439        
00440        static jvalue InvokeMethod(JNIEnv *env, jobject obj, JNIMethod* method, jvalue* args)
00441        {
00442               jvalue outValue = { NULL };
00443               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00444               nsresult result = secureEnv->CallMethod(method->mReturnType, obj, method->mMethodID, args, &outValue, secureEnv.getContext());
00445               return outValue;
00446        }
00447        
00448        static jvalue InvokeMethod(JNIEnv *env, jobject obj, JNIMethod* method, va_list args)
00449        {
00450               // convert the va_list into an array of jvalues.
00451               MarshalledArgs jargs(method, args);
00452               return InvokeMethod(env, obj, method, jargs);
00453        }
00454        
00455        static void InvokeVoidMethod(JNIEnv *env, jobject obj, JNIMethod* method, jvalue* args)
00456        {
00457               jvalue unusedValue;
00458               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00459               nsresult result = secureEnv->CallMethod(jvoid_type, obj, method->mMethodID, args, &unusedValue, secureEnv.getContext());
00460        }
00461 
00462        static void InvokeVoidMethod(JNIEnv *env, jobject obj, JNIMethod* method, va_list args)
00463        {
00464               // convert the va_list into an array of jvalues.
00465               MarshalledArgs jargs(method, args);
00466               InvokeVoidMethod(env, obj, method, jargs);
00467        }
00468 
00469 #define IMPLEMENT_METHOD_FAMILY(methodName, returnType, jvalueField) \
00470        static returnType JNICALL methodName(JNIEnv *env, jobject obj, jmethodID methodID, ...)                                \
00471        {                                                                                                                                                                                     \
00472               va_list args; va_start(args, methodID);                                                                                                            \
00473               returnType result = InvokeMethod(env, obj, (JNIMethod*)methodID, args).jvalueField;                             \
00474               va_end(args);                                                                                                                                                    \
00475               return result;                                                                                                                                                          \
00476        }                                                                                                                                                                                     \
00477                                                                                                                                                                                              \
00478        static returnType JNICALL methodName##V(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)             \
00479        {                                                                                                                                                                                     \
00480               return InvokeMethod(env, obj, (JNIMethod*)methodID, args).jvalueField;                                                        \
00481        }                                                                                                                                                                                     \
00482                                                                                                                                                                                              \
00483        static returnType JNICALL methodName##A(JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)     \
00484        {                                                                                                                                                                                     \
00485               return InvokeMethod(env, obj, (JNIMethod*)methodID, args).jvalueField;                                                        \
00486        }                                                                                                                                                                                     \
00487 
00488        // Pattern on which IMPLEMENT_METHOD_FAMILY is based.
00489        /*
00490        static jobject JNICALL CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
00491        {
00492               va_list args; va_start(args, methodID);
00493               jobject outObject = InvokeMethod(env, obj, (JNIMethod*)methodID, args).l;
00494               va_end(args);
00495               return outObject;
00496        }
00497        
00498        static jobject JNICALL CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
00499        {
00500               return InvokeMethod(env, obj, (JNIMethod*)methodID, args).l;
00501        }
00502        
00503        static jobject JNICALL CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
00504        {
00505               return InvokeMethod(env, obj, (JNIMethod*)methodID, args).l;
00506        }
00507        */
00508        
00509        IMPLEMENT_METHOD_FAMILY(CallObjectMethod, jobject, l)
00510        IMPLEMENT_METHOD_FAMILY(CallBooleanMethod, jboolean, z)
00511        IMPLEMENT_METHOD_FAMILY(CallByteMethod, jbyte, b)
00512        IMPLEMENT_METHOD_FAMILY(CallCharMethod, jchar, c)
00513        IMPLEMENT_METHOD_FAMILY(CallShortMethod, jshort, s)
00514        IMPLEMENT_METHOD_FAMILY(CallIntMethod, jint, i)
00515        IMPLEMENT_METHOD_FAMILY(CallLongMethod, jlong, j)
00516        IMPLEMENT_METHOD_FAMILY(CallFloatMethod, jfloat, f)
00517        IMPLEMENT_METHOD_FAMILY(CallDoubleMethod, jdouble, d)
00518 
00519 #undef IMPLEMENT_METHOD_FAMILY
00520 
00521        static void JNICALL CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
00522        {
00523               va_list args; va_start(args, methodID);
00524               InvokeVoidMethod(env, obj, (JNIMethod*)methodID, args);
00525               va_end(args);
00526        }
00527        
00528        static void JNICALL CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
00529        {
00530               InvokeVoidMethod(env, obj, (JNIMethod*)methodID, args);
00531        }
00532        
00533        static void JNICALL CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
00534        {
00535               InvokeVoidMethod(env, obj, (JNIMethod*)methodID, args);
00536        }
00537 
00538        // Non-virtual Invokers.
00539 
00540        static jvalue InvokeNonVirtualMethod(JNIEnv *env, jobject obj, jclass clazz, JNIMethod* method, jvalue* args)
00541        {
00542               jvalue outValue = { NULL };
00543               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00544               nsresult result = secureEnv->CallNonvirtualMethod(method->mReturnType, obj, clazz, method->mMethodID, args, &outValue, secureEnv.getContext());
00545               return outValue;
00546        }
00547        
00548        static jvalue InvokeNonVirtualMethod(JNIEnv *env, jobject obj, jclass clazz, JNIMethod* method, va_list args)
00549        {
00550               // convert the va_list into an array of jvalues.
00551               MarshalledArgs jargs(method, args);
00552               return InvokeNonVirtualMethod(env, obj, clazz, method, jargs);
00553        }
00554        
00555        static void InvokeNonVirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz, JNIMethod* method, jvalue* args)
00556        {
00557               jvalue unusedValue;
00558               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00559               nsresult result = secureEnv->CallNonvirtualMethod(jvoid_type, obj, clazz, method->mMethodID, args, &unusedValue, secureEnv.getContext());
00560        }
00561 
00562        static void InvokeNonVirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz, JNIMethod* method, va_list args)
00563        {
00564               // convert the va_list into an array of jvalues.
00565               MarshalledArgs jargs(method, args);
00566               InvokeNonVirtualVoidMethod(env, obj, clazz, method, jargs);
00567        }
00568 
00569 #define IMPLEMENT_METHOD_FAMILY(methodName, returnType, jvalueField) \
00570        static returnType JNICALL methodName(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)                         \
00571        {                                                                                                                                                                                                          \
00572               va_list args; va_start(args, methodID);                                                                                                                                 \
00573               returnType result = InvokeNonVirtualMethod(env, obj, clazz, (JNIMethod*)methodID, args).jvalueField;                   \
00574               va_end(args);                                                                                                                                                                         \
00575               return result;                                                                                                                                                                               \
00576        }                                                                                                                                                                                                          \
00577                                                                                                                                                                                                                   \
00578        static returnType JNICALL methodName##V(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)      \
00579        {                                                                                                                                                                                                          \
00580               return InvokeNonVirtualMethod(env, obj, clazz, (JNIMethod*)methodID, args).jvalueField;                                              \
00581        }                                                                                                                                                                                                          \
00582                                                                                                                                                                                                                   \
00583        static returnType JNICALL methodName##A(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)     \
00584        {                                                                                                                                                                                                          \
00585               return InvokeNonVirtualMethod(env, obj, clazz, (JNIMethod*)methodID, args).jvalueField;                                              \
00586        }                                                                                                                                                                                                          \
00587 
00588        IMPLEMENT_METHOD_FAMILY(CallNonvirtualObjectMethod, jobject, l)
00589        IMPLEMENT_METHOD_FAMILY(CallNonvirtualBooleanMethod, jboolean, z)
00590        IMPLEMENT_METHOD_FAMILY(CallNonvirtualByteMethod, jbyte, b)
00591        IMPLEMENT_METHOD_FAMILY(CallNonvirtualCharMethod, jchar, c)
00592        IMPLEMENT_METHOD_FAMILY(CallNonvirtualShortMethod, jshort, s)
00593        IMPLEMENT_METHOD_FAMILY(CallNonvirtualIntMethod, jint, i)
00594        IMPLEMENT_METHOD_FAMILY(CallNonvirtualLongMethod, jlong, j)
00595        IMPLEMENT_METHOD_FAMILY(CallNonvirtualFloatMethod, jfloat, f)
00596        IMPLEMENT_METHOD_FAMILY(CallNonvirtualDoubleMethod, jdouble, d)
00597 
00598 #undef IMPLEMENT_METHOD_FAMILY
00599 
00600        static void JNICALL CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
00601        {
00602               va_list args; va_start(args, methodID);
00603               InvokeNonVirtualVoidMethod(env, obj, clazz, (JNIMethod*)methodID, args);
00604               va_end(args);
00605        }
00606        
00607        static void JNICALL CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
00608        {
00609               InvokeNonVirtualVoidMethod(env, obj, clazz, (JNIMethod*)methodID, args);
00610        }
00611        
00612        static void JNICALL CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
00613        {
00614               InvokeNonVirtualVoidMethod(env, obj, clazz, (JNIMethod*)methodID, args);
00615        }
00616 
00617        // Instance Fields
00618 
00619        static jfieldID JNICALL GetFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
00620        {
00621               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00622               jfieldID outFieldID = NULL;
00623               nsresult result = secureEnv->GetFieldID(clazz, name, sig, &outFieldID);
00624               if (result == NS_OK) {
00625                      JNIHashKey key(outFieldID);
00626                      JNIField* field = (JNIField*) theIDTable->Get(&key);
00627                      if (field == NULL) {
00628                             field = new JNIField(name, sig, outFieldID);
00629                             theIDTable->Put(&key, field);
00630                      }
00631                      outFieldID = jfieldID(field);
00632               }
00633               return outFieldID;
00634        }
00635 
00636        static jvalue GetField(JNIEnv* env, jobject obj, JNIField* field)
00637        {
00638               jvalue outValue = { NULL };
00639               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00640               nsresult result = secureEnv->GetField(field->mFieldType, obj, field->mFieldID, &outValue, secureEnv.getContext());
00641               return outValue;
00642        }
00643 
00644 #define IMPLEMENT_GET_FIELD(methodName, returnType, jvalueField)                                                \
00645        static returnType JNICALL methodName(JNIEnv *env, jobject obj, jfieldID fieldID)           \
00646        {                                                                                                                                                         \
00647               return GetField(env, obj, (JNIField*)fieldID).jvalueField;                                               \
00648        }                                                                                                                                                         \
00649 
00650        IMPLEMENT_GET_FIELD(GetObjectField, jobject, l)
00651        IMPLEMENT_GET_FIELD(GetBooleanField, jboolean, z)
00652        IMPLEMENT_GET_FIELD(GetByteField, jbyte, b)
00653        IMPLEMENT_GET_FIELD(GetCharField, jchar, c)
00654        IMPLEMENT_GET_FIELD(GetShortField, jshort, s)
00655        IMPLEMENT_GET_FIELD(GetIntField, jint, i)
00656        IMPLEMENT_GET_FIELD(GetLongField, jlong, j)
00657        IMPLEMENT_GET_FIELD(GetFloatField, jfloat, f)
00658        IMPLEMENT_GET_FIELD(GetDoubleField, jdouble, d)
00659 
00660 #undef IMPLEMENT_GET_FIELD
00661 
00662        static void SetField(JNIEnv* env, jobject obj, JNIField* field, jvalue value)
00663        {
00664               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00665               nsresult result = secureEnv->SetField(field->mFieldType, obj, field->mFieldID, value, secureEnv.getContext());
00666        }
00667 
00668 #define IMPLEMENT_SET_FIELD(methodName, fieldType, jvalueField)                                                                      \
00669        static void JNICALL methodName(JNIEnv *env, jobject obj, jfieldID fieldID, fieldType value)              \
00670        {                                                                                                                                                                       \
00671               jvalue fieldValue;                                                                                                                                 \
00672               fieldValue.jvalueField = value;                                                                                                             \
00673               SetField(env, obj, (JNIField*)fieldID, fieldValue);                                                                           \
00674        }                                                                                                                                                                       \
00675 
00676        IMPLEMENT_SET_FIELD(SetObjectField, jobject, l)
00677        IMPLEMENT_SET_FIELD(SetBooleanField, jboolean, z)
00678        IMPLEMENT_SET_FIELD(SetByteField, jbyte, b)
00679        IMPLEMENT_SET_FIELD(SetCharField, jchar, c)
00680        IMPLEMENT_SET_FIELD(SetShortField, jshort, s)
00681        IMPLEMENT_SET_FIELD(SetIntField, jint, i)
00682        IMPLEMENT_SET_FIELD(SetLongField, jlong, j)
00683        IMPLEMENT_SET_FIELD(SetFloatField, jfloat, f)
00684        IMPLEMENT_SET_FIELD(SetDoubleField, jdouble, d)
00685 
00686 #undef IMPLEMENT_SET_FIELD
00687 
00688        // Static Methods
00689 
00690        static jmethodID JNICALL GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
00691        {
00692               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00693               jmethodID outMethodID = NULL;
00694               nsresult result = secureEnv->GetStaticMethodID(clazz, name, sig, &outMethodID);
00695               if (result == NS_OK) {
00696                      JNIHashKey key(outMethodID);
00697                      JNIMethod* method = (JNIMethod*) theIDTable->Get(&key);
00698                      if (method == NULL) {
00699                             method = new JNIMethod(name, sig, outMethodID);
00700                             theIDTable->Put(&key, method);
00701                      }
00702                      outMethodID = jmethodID(method);
00703               }
00704               return outMethodID;
00705        }
00706 
00707        // jobject (JNICALL *CallStaticObjectMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
00708        
00709        // Static Invokers.
00710        
00711        static jvalue InvokeStaticMethod(JNIEnv *env, jclass clazz, JNIMethod* method, jvalue* args)
00712        {
00713               jvalue outValue = { NULL };
00714               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00715               nsresult result = secureEnv->CallStaticMethod(method->mReturnType, clazz, method->mMethodID, args, &outValue, secureEnv.getContext());
00716               return outValue;
00717        }
00718        
00719        static jvalue InvokeStaticMethod(JNIEnv *env, jclass clazz, JNIMethod* method, va_list args)
00720        {
00721               // convert the va_list into an array of jvalues.
00722               MarshalledArgs jargs(method, args);
00723               return InvokeStaticMethod(env, clazz, method, jargs);
00724        }
00725        
00726        static void InvokeStaticVoidMethod(JNIEnv *env, jclass clazz, JNIMethod* method, jvalue* args)
00727        {
00728               jvalue unusedValue;
00729               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00730               nsresult result = secureEnv->CallStaticMethod(jvoid_type, clazz, method->mMethodID, args, &unusedValue, secureEnv.getContext());
00731        }
00732 
00733        static void InvokeStaticVoidMethod(JNIEnv *env, jclass clazz, JNIMethod* method, va_list args)
00734        {
00735               // convert the va_list into an array of jvalues.
00736               MarshalledArgs jargs(method, args);
00737               InvokeStaticVoidMethod(env, clazz, method, jargs);
00738        }
00739 
00740 #define IMPLEMENT_METHOD_FAMILY(methodName, returnType, jvalueField) \
00741        static returnType JNICALL methodName(JNIEnv *env, jclass clazz, jmethodID methodID, ...)                        \
00742        {                                                                                                                                                                                     \
00743               va_list args; va_start(args, methodID);                                                                                                            \
00744               returnType result = InvokeStaticMethod(env, clazz, (JNIMethod*)methodID, args).jvalueField;                     \
00745               va_end(args);                                                                                                                                                    \
00746               return result;                                                                                                                                                          \
00747        }                                                                                                                                                                                     \
00748                                                                                                                                                                                              \
00749        static returnType JNICALL methodName##V(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)     \
00750        {                                                                                                                                                                                     \
00751               return InvokeStaticMethod(env, clazz, (JNIMethod*)methodID, args).jvalueField;                                         \
00752        }                                                                                                                                                                                     \
00753                                                                                                                                                                                              \
00754        static returnType JNICALL methodName##A(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue * args)    \
00755        {                                                                                                                                                                                     \
00756               return InvokeStaticMethod(env, clazz, (JNIMethod*)methodID, args).jvalueField;                                         \
00757        }                                                                                                                                                                                     \
00758 
00759        IMPLEMENT_METHOD_FAMILY(CallStaticObjectMethod, jobject, l)
00760        IMPLEMENT_METHOD_FAMILY(CallStaticBooleanMethod, jboolean, z)
00761        IMPLEMENT_METHOD_FAMILY(CallStaticByteMethod, jbyte, b)
00762        IMPLEMENT_METHOD_FAMILY(CallStaticCharMethod, jchar, c)
00763        IMPLEMENT_METHOD_FAMILY(CallStaticShortMethod, jshort, s)
00764        IMPLEMENT_METHOD_FAMILY(CallStaticIntMethod, jint, i)
00765        IMPLEMENT_METHOD_FAMILY(CallStaticLongMethod, jlong, j)
00766        IMPLEMENT_METHOD_FAMILY(CallStaticFloatMethod, jfloat, f)
00767        IMPLEMENT_METHOD_FAMILY(CallStaticDoubleMethod, jdouble, d)
00768 
00769 #undef IMPLEMENT_METHOD_FAMILY
00770 
00771        static void JNICALL CallStaticVoidMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
00772        {
00773               va_list args; va_start(args, methodID);
00774               InvokeStaticVoidMethod(env, clazz, (JNIMethod*)methodID, args);
00775               va_end(args);
00776        }
00777        
00778        static void JNICALL CallStaticVoidMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
00779        {
00780               InvokeStaticVoidMethod(env, clazz, (JNIMethod*)methodID, args);
00781        }
00782        
00783        static void JNICALL CallStaticVoidMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue * args)
00784        {
00785               InvokeStaticVoidMethod(env, clazz, (JNIMethod*)methodID, args);
00786        }
00787 
00788        // Static Fields
00789 
00790        static jfieldID JNICALL GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
00791        {
00792               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00793               jfieldID outFieldID = NULL;
00794               nsresult result = secureEnv->GetStaticFieldID(clazz, name, sig, &outFieldID);
00795               if (result == NS_OK) {
00796                      JNIHashKey key(outFieldID);
00797                      JNIField* field = (JNIField*) theIDTable->Get(&key);
00798                      if (field == NULL) {
00799                             field = new JNIField(name, sig, outFieldID);
00800                             theIDTable->Put(&key, field);
00801                      }
00802                      outFieldID = jfieldID(field);
00803               }
00804               return outFieldID;
00805        }
00806 
00807        static jvalue GetStaticField(JNIEnv* env, jclass clazz, JNIField* field)
00808        {
00809               jvalue outValue = { NULL };
00810               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00811               nsresult result = secureEnv->GetStaticField(field->mFieldType, clazz, field->mFieldID, &outValue, secureEnv.getContext());
00812               return outValue;
00813        }
00814 
00815 #define IMPLEMENT_GET_FIELD(methodName, returnType, jvalueField)                                                \
00816        static returnType JNICALL methodName(JNIEnv *env, jclass clazz, jfieldID fieldID)          \
00817        {                                                                                                                                                         \
00818               return GetStaticField(env, clazz, (JNIField*)fieldID).jvalueField;                                \
00819        }                                                                                                                                                         \
00820 
00821        IMPLEMENT_GET_FIELD(GetStaticObjectField, jobject, l)
00822        IMPLEMENT_GET_FIELD(GetStaticBooleanField, jboolean, z)
00823        IMPLEMENT_GET_FIELD(GetStaticByteField, jbyte, b)
00824        IMPLEMENT_GET_FIELD(GetStaticCharField, jchar, c)
00825        IMPLEMENT_GET_FIELD(GetStaticShortField, jshort, s)
00826        IMPLEMENT_GET_FIELD(GetStaticIntField, jint, i)
00827        IMPLEMENT_GET_FIELD(GetStaticLongField, jlong, j)
00828        IMPLEMENT_GET_FIELD(GetStaticFloatField, jfloat, f)
00829        IMPLEMENT_GET_FIELD(GetStaticDoubleField, jdouble, d)
00830 
00831 #undef IMPLEMENT_GET_FIELD
00832 
00833        static void SetStaticField(JNIEnv* env, jclass clazz, JNIField* field, jvalue value)
00834        {
00835               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00836               nsresult result = secureEnv->SetStaticField(field->mFieldType, clazz, field->mFieldID, value, secureEnv.getContext());
00837        }
00838 
00839 #define IMPLEMENT_SET_FIELD(methodName, fieldType, jvalueField)                                                                      \
00840        static void JNICALL methodName(JNIEnv *env, jclass clazz, jfieldID fieldID, fieldType value)      \
00841        {                                                                                                                                                                       \
00842               jvalue fieldValue;                                                                                                                                 \
00843               fieldValue.jvalueField = value;                                                                                                             \
00844               SetStaticField(env, clazz, (JNIField*)fieldID, fieldValue);                                                            \
00845        }                                                                                                                                                                       \
00846 
00847        IMPLEMENT_SET_FIELD(SetStaticObjectField, jobject, l)
00848        IMPLEMENT_SET_FIELD(SetStaticBooleanField, jboolean, z)
00849        IMPLEMENT_SET_FIELD(SetStaticByteField, jbyte, b)
00850        IMPLEMENT_SET_FIELD(SetStaticCharField, jchar, c)
00851        IMPLEMENT_SET_FIELD(SetStaticShortField, jshort, s)
00852        IMPLEMENT_SET_FIELD(SetStaticIntField, jint, i)
00853        IMPLEMENT_SET_FIELD(SetStaticLongField, jlong, j)
00854        IMPLEMENT_SET_FIELD(SetStaticFloatField, jfloat, f)
00855        IMPLEMENT_SET_FIELD(SetStaticDoubleField, jdouble, d)
00856 
00857 #undef IMPLEMENT_SET_FIELD
00858 
00859        static jstring JNICALL NewString(JNIEnv *env, const jchar *unicode, jsize len)
00860        {
00861               jstring outString;
00862               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00863               nsresult result = secureEnv->NewString(unicode, len, &outString);
00864               return outString;
00865        }
00866        
00867        static jsize JNICALL GetStringLength(JNIEnv *env, jstring str)
00868        {
00869               jsize outLength;
00870               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00871               nsresult result = secureEnv->GetStringLength(str, &outLength);
00872               return outLength;
00873        }
00874        
00875        static const jchar* JNICALL GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
00876        {
00877               jchar* outChars = NULL;
00878               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00879               nsresult result = secureEnv->GetStringChars(str, isCopy, &outChars);
00880               return outChars;
00881        }
00882        
00883        static void JNICALL ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
00884        {
00885               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00886               nsresult result = secureEnv->ReleaseStringChars(str, chars);
00887        }
00888 
00889        static jstring JNICALL NewStringUTF(JNIEnv *env, const char *utf)
00890        {
00891               jstring outString;
00892               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00893               nsresult result = secureEnv->NewStringUTF(utf, &outString);
00894               return outString;
00895        }
00896        
00897        static jsize JNICALL GetStringUTFLength(JNIEnv *env, jstring str)
00898        {
00899               jsize outLength;
00900               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00901               nsresult result = secureEnv->GetStringUTFLength(str, &outLength);
00902               return outLength;
00903        }
00904        
00905        static const char* JNICALL GetStringUTFChars(JNIEnv *env, jstring str, jboolean *isCopy)
00906        {
00907               const char* outChars = NULL;
00908               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00909               nsresult result = secureEnv->GetStringUTFChars(str, isCopy, &outChars);
00910               return outChars;
00911        }
00912        
00913        static void JNICALL ReleaseStringUTFChars(JNIEnv *env, jstring str, const char* chars)
00914        {
00915               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00916               nsresult result = secureEnv->ReleaseStringUTFChars(str, chars);
00917        }
00918 
00919        static jsize JNICALL GetArrayLength(JNIEnv *env, jarray array)
00920        {
00921               jsize outLength;
00922               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00923               nsresult result = secureEnv->GetArrayLength(array, &outLength);
00924               return outLength;
00925        }
00926 
00927        static jobjectArray JNICALL NewObjectArray(JNIEnv *env, jsize len, jclass clazz, jobject initVal)
00928        {
00929               jobjectArray outArray = NULL;
00930               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00931               nsresult result = secureEnv->NewObjectArray(len, clazz, initVal, &outArray);
00932               return outArray;
00933        }
00934 
00935        static jobject JNICALL GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)
00936        {
00937               jobject outObject = NULL;
00938               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00939               nsresult result = secureEnv->GetObjectArrayElement(array, index, &outObject);
00940               return outObject;
00941        }
00942 
00943        static void JNICALL SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject val)
00944        {
00945               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
00946               nsresult result = secureEnv->SetObjectArrayElement(array, index, val);
00947        }
00948 
00949 #define IMPLEMENT_NEW_ARRAY(methodName, type)                                                                                               \
00950        static type##Array JNICALL methodName(JNIEnv *env, jsize len)                                                          \
00951        {                                                                                                                                                                       \
00952               type##Array outArray = NULL;                                                                                                                \
00953               nsJNIEnv& secureEnv = nsJNIEnvRef(env);                                                                                              \
00954               nsresult result = secureEnv->NewArray(type##_type, len, (jarray*)&outArray);                      \
00955               return outArray;                                                                                                                                   \
00956        }                                                                                                                                                                       \
00957 
00958        IMPLEMENT_NEW_ARRAY(NewBooleanArray, jboolean)
00959        IMPLEMENT_NEW_ARRAY(NewByteArray, jbyte)
00960        IMPLEMENT_NEW_ARRAY(NewCharArray, jchar)
00961        IMPLEMENT_NEW_ARRAY(NewShortArray, jshort)
00962        IMPLEMENT_NEW_ARRAY(NewIntArray, jint)
00963        IMPLEMENT_NEW_ARRAY(NewLongArray, jlong)
00964        IMPLEMENT_NEW_ARRAY(NewFloatArray, jfloat)
00965        IMPLEMENT_NEW_ARRAY(NewDoubleArray, jdouble)
00966 
00967 #undef IMPLEMENT_NEW_ARRAY
00968 
00969 #define IMPLEMENT_GET_ARRAY_ELEMENTS(methodName, type)                                                                                             \
00970        static type* JNICALL methodName(JNIEnv *env, type##Array array, jboolean *isCopy)                                      \
00971        {                                                                                                                                                                                     \
00972               type* outElements = NULL;                                                                                                                                 \
00973               nsJNIEnv& secureEnv = nsJNIEnvRef(env);                                                                                                            \
00974               nsresult result = secureEnv->GetArrayElements(type##_type, array, isCopy, &outElements);                 \
00975               return outElements;                                                                                                                                              \
00976        }                                                                                                                                                                                     \
00977 
00978        IMPLEMENT_GET_ARRAY_ELEMENTS(GetBooleanArrayElements, jboolean)
00979        IMPLEMENT_GET_ARRAY_ELEMENTS(GetByteArrayElements, jbyte)
00980        IMPLEMENT_GET_ARRAY_ELEMENTS(GetCharArrayElements, jchar)
00981        IMPLEMENT_GET_ARRAY_ELEMENTS(GetShortArrayElements, jshort)
00982        IMPLEMENT_GET_ARRAY_ELEMENTS(GetIntArrayElements, jint)
00983        IMPLEMENT_GET_ARRAY_ELEMENTS(GetLongArrayElements, jlong)
00984        IMPLEMENT_GET_ARRAY_ELEMENTS(GetFloatArrayElements, jfloat)
00985        IMPLEMENT_GET_ARRAY_ELEMENTS(GetDoubleArrayElements, jdouble)
00986 
00987 #undef IMPLEMENT_GET_ARRAY_ELEMENTS
00988 
00989 #define IMPLEMENT_RELEASE_ARRAY_ELEMENTS(methodName, type)                                                                                         \
00990        static void JNICALL methodName(JNIEnv *env, type##Array array, type* elems, jint mode)                                 \
00991        {                                                                                                                                                                                     \
00992               nsJNIEnv& secureEnv = nsJNIEnvRef(env);                                                                                                            \
00993               nsresult result = secureEnv->ReleaseArrayElements(type##_type, array, elems, mode);                             \
00994        }                                                                                                                                                                                     \
00995 
00996        IMPLEMENT_RELEASE_ARRAY_ELEMENTS(ReleaseBooleanArrayElements, jboolean)
00997        IMPLEMENT_RELEASE_ARRAY_ELEMENTS(ReleaseByteArrayElements, jbyte)
00998        IMPLEMENT_RELEASE_ARRAY_ELEMENTS(ReleaseCharArrayElements, jchar)
00999        IMPLEMENT_RELEASE_ARRAY_ELEMENTS(ReleaseShortArrayElements, jshort)
01000        IMPLEMENT_RELEASE_ARRAY_ELEMENTS(ReleaseIntArrayElements, jint)
01001        IMPLEMENT_RELEASE_ARRAY_ELEMENTS(ReleaseLongArrayElements, jlong)
01002        IMPLEMENT_RELEASE_ARRAY_ELEMENTS(ReleaseFloatArrayElements, jfloat)
01003        IMPLEMENT_RELEASE_ARRAY_ELEMENTS(ReleaseDoubleArrayElements, jdouble)
01004 
01005 #undef IMPLEMENT_RELEASE_ARRAY_ELEMENTS
01006 
01007 #define IMPLEMENT_GET_ARRAY_REGION(methodName, type)                                                                                               \
01008        static void JNICALL methodName(JNIEnv *env, type##Array array, jsize start, jsize len, type* buf)        \
01009        {                                                                                                                                                                                     \
01010               nsJNIEnv& secureEnv = nsJNIEnvRef(env);                                                                                                            \
01011               nsresult result = secureEnv->GetArrayRegion(type##_type, array, start, len, buf);                               \
01012        }                                                                                                                                                                                     \
01013 
01014        IMPLEMENT_GET_ARRAY_REGION(GetBooleanArrayRegion, jboolean)
01015        IMPLEMENT_GET_ARRAY_REGION(GetByteArrayRegion, jbyte)
01016        IMPLEMENT_GET_ARRAY_REGION(GetCharArrayRegion, jchar)
01017        IMPLEMENT_GET_ARRAY_REGION(GetShortArrayRegion, jshort)
01018        IMPLEMENT_GET_ARRAY_REGION(GetIntArrayRegion, jint)
01019        IMPLEMENT_GET_ARRAY_REGION(GetLongArrayRegion, jlong)
01020        IMPLEMENT_GET_ARRAY_REGION(GetFloatArrayRegion, jfloat)
01021        IMPLEMENT_GET_ARRAY_REGION(GetDoubleArrayRegion, jdouble)
01022 
01023 #undef IMPLEMENT_GET_ARRAY_REGION
01024 
01025 #define IMPLEMENT_SET_ARRAY_REGION(methodName, type)                                                                                               \
01026        static void JNICALL methodName(JNIEnv *env, type##Array array, jsize start, jsize len, type* buf)        \
01027        {                                                                                                                                                                                     \
01028               nsJNIEnv& secureEnv = nsJNIEnvRef(env);                                                                                                            \
01029               nsresult result = secureEnv->SetArrayRegion(type##_type, array, start, len, buf);                               \
01030        }                                                                                                                                                                                     \
01031 
01032        IMPLEMENT_SET_ARRAY_REGION(SetBooleanArrayRegion, jboolean)
01033        IMPLEMENT_SET_ARRAY_REGION(SetByteArrayRegion, jbyte)
01034        IMPLEMENT_SET_ARRAY_REGION(SetCharArrayRegion, jchar)
01035        IMPLEMENT_SET_ARRAY_REGION(SetShortArrayRegion, jshort)
01036        IMPLEMENT_SET_ARRAY_REGION(SetIntArrayRegion, jint)
01037        IMPLEMENT_SET_ARRAY_REGION(SetLongArrayRegion, jlong)
01038        IMPLEMENT_SET_ARRAY_REGION(SetFloatArrayRegion, jfloat)
01039        IMPLEMENT_SET_ARRAY_REGION(SetDoubleArrayRegion, jdouble)
01040 
01041 #undef IMPLEMENT_SET_ARRAY_REGION
01042 
01043        static jint JNICALL RegisterNatives(JNIEnv *env, jclass clazz, const JNINativeMethod *methods, jint nMethods)
01044        {
01045               jint outStatus = 0;
01046               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
01047               nsresult result = secureEnv->RegisterNatives(clazz, methods, nMethods, &outStatus);
01048               return outStatus;
01049        }
01050        
01051        static jint JNICALL UnregisterNatives(JNIEnv *env, jclass clazz)
01052        {
01053               jint outStatus = 0;
01054               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
01055               nsresult result = secureEnv->UnregisterNatives(clazz, &outStatus);
01056               return outStatus;
01057        }
01058 
01059        static jint JNICALL MonitorEnter(JNIEnv *env, jobject obj)
01060        {
01061               jint outStatus = 0;
01062               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
01063               nsresult result = secureEnv->MonitorEnter(obj, &outStatus);
01064               return outStatus;
01065        }
01066        
01067        static jint JNICALL JNICALL MonitorExit(JNIEnv *env, jobject obj)
01068        {
01069               jint outStatus = 0;
01070               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
01071               nsresult result = secureEnv->MonitorExit(obj, &outStatus);
01072               return outStatus;
01073        }
01074 
01075        static jint JNICALL GetJavaVM(JNIEnv *env, JavaVM **vm)
01076        {
01077               jint outStatus = 0;
01078               nsJNIEnv& secureEnv = nsJNIEnvRef(env);
01079               nsresult result = secureEnv->GetJavaVM(vm, &outStatus);
01080               return outStatus;
01081        }
01082 
01083 public:
01084        nsJNIEnv(nsISecureJNI2* secureEnv);
01085        ~nsJNIEnv();
01086 };
01087 
01088 JNINativeInterface_ nsJNIEnv::theFuncs = {
01089        NULL,  // void *reserved0;
01090        NULL,  // void *reserved1;
01091        NULL,  // void *reserved2;
01092 
01093        NULL,  // void *reserved3;
01094 
01095        // jint (JNICALL *GetVersion)(JNIEnv *env);      
01096        &GetVersion,
01097 
01098        // jclass (JNICALL *DefineClass) (JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len);
01099        &DefineClass,
01100        
01101        // jclass (JNICALL *FindClass) (JNIEnv *env, const char *name);
01102        &FindClass,
01103 
01104        NULL,  // void *reserved4;
01105        NULL,  // void *reserved5;
01106        NULL,  // void *reserved6;
01107 
01108        // jclass (JNICALL *GetSuperclass) (JNIEnv *env, jclass sub);
01109        &GetSuperclass,
01110        
01111        // jboolean (JNICALL *IsAssignableFrom) (JNIEnv *env, jclass sub, jclass sup);
01112        &IsAssignableFrom,
01113        
01114        NULL, // void *reserved7;
01115 
01116        // jint (JNICALL *Throw) (JNIEnv *env, jthrowable obj);
01117        &Throw,
01118        
01119        // jint (JNICALL *ThrowNew) (JNIEnv *env, jclass clazz, const char *msg);
01120        &ThrowNew,
01121        
01122        // jthrowable (JNICALL *ExceptionOccurred) (JNIEnv *env);
01123        &ExceptionOccurred,
01124        
01125        // void (JNICALL *ExceptionDescribe) (JNIEnv *env);
01126        &ExceptionDescribe,
01127        
01128        // void (JNICALL *ExceptionClear) (JNIEnv *env);
01129        &ExceptionClear,
01130        
01131        // void (JNICALL *FatalError) (JNIEnv *env, const char *msg);
01132        &FatalError,
01133        
01134        NULL, // void *reserved8;
01135        NULL, // void *reserved9;
01136 
01137        // jobject (JNICALL *NewGlobalRef) (JNIEnv *env, jobject lobj);
01138        &NewGlobalRef,
01139        
01140        // void (JNICALL *DeleteGlobalRef) (JNIEnv *env, jobject gref);
01141        &DeleteGlobalRef,
01142        
01143        // void (JNICALL *DeleteLocalRef) (JNIEnv *env, jobject obj);
01144        &DeleteLocalRef,
01145        
01146        // jboolean (JNICALL *IsSameObject) (JNIEnv *env, jobject obj1, jobject obj2);
01147        &IsSameObject,
01148        
01149        NULL, // void *reserved10;
01150        NULL, // void *reserved11;
01151 
01152        // jobject (JNICALL *AllocObject) (JNIEnv *env, jclass clazz);
01153        &AllocObject,
01154        
01155 #define REFERENCE_METHOD_FAMILY(methodName) &methodName, &methodName##V, &methodName##A,
01156 
01157        // jobject (JNICALL *NewObject) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01158        // jobject (JNICALL *NewObjectV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01159        // jobject (JNICALL *NewObjectA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01160        REFERENCE_METHOD_FAMILY(NewObject)
01161        
01162        // jclass (JNICALL *GetObjectClass) (JNIEnv *env, jobject obj);
01163        &GetObjectClass,
01164        
01165        // jboolean (JNICALL *IsInstanceOf) (JNIEnv *env, jobject obj, jclass clazz);
01166        &IsInstanceOf,
01167 
01168        // jmethodID (JNICALL *GetMethodID)(JNIEnv *env, jclass clazz, const char *name, const char *sig);
01169        &GetMethodID,
01170 
01171        // jobject (JNICALL *CallObjectMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01172        // jobject (JNICALL *CallObjectMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01173        // jobject (JNICALL *CallObjectMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args);
01174        REFERENCE_METHOD_FAMILY(CallObjectMethod)
01175        
01176        // jboolean (JNICALL *CallBooleanMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01177        // jboolean (JNICALL *CallBooleanMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01178        // jboolean (JNICALL *CallBooleanMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args);
01179        REFERENCE_METHOD_FAMILY(CallBooleanMethod)
01180 
01181        // jbyte (JNICALL *CallByteMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01182        // jbyte (JNICALL *CallByteMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01183        // jbyte (JNICALL *CallByteMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);
01184        REFERENCE_METHOD_FAMILY(CallByteMethod)
01185 
01186        // jchar (JNICALL *CallCharMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01187        // jchar (JNICALL *CallCharMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01188        // jchar (JNICALL *CallCharMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);
01189        REFERENCE_METHOD_FAMILY(CallCharMethod)
01190 
01191        // jshort (JNICALL *CallShortMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01192        // jshort (JNICALL *CallShortMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01193        // jshort (JNICALL *CallShortMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);
01194        REFERENCE_METHOD_FAMILY(CallShortMethod)
01195 
01196        // jint (JNICALL *CallIntMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01197        // jint (JNICALL *CallIntMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01198        // jint (JNICALL *CallIntMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);
01199        REFERENCE_METHOD_FAMILY(CallIntMethod)
01200 
01201        // jlong (JNICALL *CallLongMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01202        // jlong (JNICALL *CallLongMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01203        // jlong (JNICALL *CallLongMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);
01204        REFERENCE_METHOD_FAMILY(CallLongMethod)
01205 
01206        // jfloat (JNICALL *CallFloatMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01207        // jfloat (JNICALL *CallFloatMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01208        // jfloat (JNICALL *CallFloatMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);
01209        REFERENCE_METHOD_FAMILY(CallFloatMethod)
01210 
01211        // jdouble (JNICALL *CallDoubleMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01212        // jdouble (JNICALL *CallDoubleMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01213        // jdouble (JNICALL *CallDoubleMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);
01214        REFERENCE_METHOD_FAMILY(CallDoubleMethod)
01215 
01216        // void (JNICALL *CallVoidMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01217        // void (JNICALL *CallVoidMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01218        // void (JNICALL *CallVoidMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args);
01219        REFERENCE_METHOD_FAMILY(CallVoidMethod)
01220 
01221        // jobject (JNICALL *CallNonvirtualObjectMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01222        // jobject (JNICALL *CallNonvirtualObjectMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01223        // jobject (JNICALL *CallNonvirtualObjectMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args);
01224        REFERENCE_METHOD_FAMILY(CallNonvirtualObjectMethod)
01225 
01226        // jboolean (JNICALL *CallNonvirtualBooleanMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01227        // jboolean (JNICALL *CallNonvirtualBooleanMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01228        // jboolean (JNICALL *CallNonvirtualBooleanMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args);
01229        REFERENCE_METHOD_FAMILY(CallNonvirtualBooleanMethod)
01230 
01231        // jbyte (JNICALL *CallNonvirtualByteMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01232        // jbyte (JNICALL *CallNonvirtualByteMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01233        // jbyte (JNICALL *CallNonvirtualByteMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);
01234        REFERENCE_METHOD_FAMILY(CallNonvirtualByteMethod)
01235 
01236        // jchar (JNICALL *CallNonvirtualCharMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01237        // jchar (JNICALL *CallNonvirtualCharMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01238        // jchar (JNICALL *CallNonvirtualCharMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);
01239        REFERENCE_METHOD_FAMILY(CallNonvirtualCharMethod)
01240 
01241        // jshort (JNICALL *CallNonvirtualShortMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01242        // jshort (JNICALL *CallNonvirtualShortMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01243        // jshort (JNICALL *CallNonvirtualShortMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);
01244        REFERENCE_METHOD_FAMILY(CallNonvirtualShortMethod)
01245 
01246        // jint (JNICALL *CallNonvirtualIntMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01247        // jint (JNICALL *CallNonvirtualIntMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01248        // jint (JNICALL *CallNonvirtualIntMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);
01249        REFERENCE_METHOD_FAMILY(CallNonvirtualIntMethod)
01250 
01251        // jlong (JNICALL *CallNonvirtualLongMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01252        // jlong (JNICALL *CallNonvirtualLongMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01253        // jlong (JNICALL *CallNonvirtualLongMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);
01254        REFERENCE_METHOD_FAMILY(CallNonvirtualLongMethod)
01255 
01256        // jfloat (JNICALL *CallNonvirtualFloatMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01257        // jfloat (JNICALL *CallNonvirtualFloatMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01258        // jfloat (JNICALL *CallNonvirtualFloatMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);
01259        REFERENCE_METHOD_FAMILY(CallNonvirtualFloatMethod)
01260 
01261        // jdouble (JNICALL *CallNonvirtualDoubleMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01262        // jdouble (JNICALL *CallNonvirtualDoubleMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01263        // jdouble (JNICALL *CallNonvirtualDoubleMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);
01264        REFERENCE_METHOD_FAMILY(CallNonvirtualDoubleMethod)
01265 
01266        // void (JNICALL *CallNonvirtualVoidMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01267        // void (JNICALL *CallNonvirtualVoidMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01268        // void (JNICALL *CallNonvirtualVoidMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args);
01269        REFERENCE_METHOD_FAMILY(CallNonvirtualVoidMethod)
01270 
01271        // jfieldID (JNICALL *GetFieldID) (JNIEnv *env, jclass clazz, const char *name, const char *sig);
01272        &GetFieldID,
01273 
01274        // jobject (JNICALL *GetObjectField) (JNIEnv *env, jobject obj, jfieldID fieldID);
01275        // jboolean (JNICALL *GetBooleanField) (JNIEnv *env, jobject obj, jfieldID fieldID);
01276        // jbyte (JNICALL *GetByteField) (JNIEnv *env, jobject obj, jfieldID fieldID);
01277        // jchar (JNICALL *GetCharField) (JNIEnv *env, jobject obj, jfieldID fieldID);
01278        // jshort (JNICALL *GetShortField) (JNIEnv *env, jobject obj, jfieldID fieldID);
01279        // jint (JNICALL *GetIntField) (JNIEnv *env, jobject obj, jfieldID fieldID);
01280        // jlong (JNICALL *GetLongField) (JNIEnv *env, jobject obj, jfieldID fieldID);
01281        // jfloat (JNICALL *GetFloatField) (JNIEnv *env, jobject obj, jfieldID fieldID);
01282        // jdouble (JNICALL *GetDoubleField) (JNIEnv *env, jobject obj, jfieldID fieldID);
01283        &GetObjectField, &GetBooleanField, &GetByteField, &GetCharField, &GetShortField, &GetIntField, &GetLongField,
01284        &GetFloatField, &GetDoubleField,
01285 
01286        // void (JNICALL *SetObjectField) (JNIEnv *env, jobject obj, jfieldID fieldID, jobject val);
01287        // void (JNICALL *SetBooleanField) (JNIEnv *env, jobject obj, jfieldID fieldID, jboolean val);
01288        // void (JNICALL *SetByteField) (JNIEnv *env, jobject obj, jfieldID fieldID, jbyte val);
01289        // void (JNICALL *SetCharField) (JNIEnv *env, jobject obj, jfieldID fieldID, jchar val);
01290        // void (JNICALL *SetShortField) (JNIEnv *env, jobject obj, jfieldID fieldID, jshort val);
01291        // void (JNICALL *SetIntField) (JNIEnv *env, jobject obj, jfieldID fieldID, jint val);
01292        // void (JNICALL *SetLongField) (JNIEnv *env, jobject obj, jfieldID fieldID, jlong val);
01293        // void (JNICALL *SetFloatField) (JNIEnv *env, jobject obj, jfieldID fieldID, jfloat val);
01294        // void (JNICALL *SetDoubleField) (JNIEnv *env, jobject obj, jfieldID fieldID, jdouble val);
01295        &SetObjectField, &SetBooleanField, &SetByteField, &SetCharField, &SetShortField, &SetIntField, &SetLongField,
01296        &SetFloatField, &SetDoubleField,
01297 
01298        // jmethodID (JNICALL *GetStaticMethodID) (JNIEnv *env, jclass clazz, const char *name, const char *sig);
01299        &GetStaticMethodID,
01300 
01301        // jobject (JNICALL *CallStaticObjectMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01302        // jobject (JNICALL *CallStaticObjectMethodV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01303        // jobject (JNICALL *CallStaticObjectMethodA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01304        REFERENCE_METHOD_FAMILY(CallStaticObjectMethod)
01305 
01306        // jboolean (JNICALL *CallStaticBooleanMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01307        // jboolean (JNICALL *CallStaticBooleanMethodV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01308        // jboolean (JNICALL *CallStaticBooleanMethodA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01309        REFERENCE_METHOD_FAMILY(CallStaticBooleanMethod)
01310 
01311        // jbyte (JNICALL *CallStaticByteMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01312        // jbyte (JNICALL *CallStaticByteMethodV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01313        // jbyte (JNICALL *CallStaticByteMethodA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01314        REFERENCE_METHOD_FAMILY(CallStaticByteMethod)
01315 
01316        // jchar (JNICALL *CallStaticCharMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01317        // jchar (JNICALL *CallStaticCharMethodV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01318        // jchar (JNICALL *CallStaticCharMethodA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01319        REFERENCE_METHOD_FAMILY(CallStaticCharMethod)
01320 
01321        // jshort (JNICALL *CallStaticShortMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01322        // jshort (JNICALL *CallStaticShortMethodV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01323        // jshort (JNICALL *CallStaticShortMethodA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01324        REFERENCE_METHOD_FAMILY(CallStaticShortMethod)
01325 
01326        // jint (JNICALL *CallStaticIntMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01327        // jint (JNICALL *CallStaticIntMethodV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01328        // jint (JNICALL *CallStaticIntMethodA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01329        REFERENCE_METHOD_FAMILY(CallStaticIntMethod)
01330 
01331        // jlong (JNICALL *CallStaticLongMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01332        // jlong (JNICALL *CallStaticLongMethodV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01333        // jlong (JNICALL *CallStaticLongMethodA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01334        REFERENCE_METHOD_FAMILY(CallStaticLongMethod)
01335 
01336        // jfloat (JNICALL *CallStaticFloatMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01337        // jfloat (JNICALL *CallStaticFloatMethodV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01338        // jfloat (JNICALL *CallStaticFloatMethodA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01339        REFERENCE_METHOD_FAMILY(CallStaticFloatMethod)
01340 
01341        // jdouble (JNICALL *CallStaticDoubleMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01342        // jdouble (JNICALL *CallStaticDoubleMethodV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01343        // jdouble (JNICALL *CallStaticDoubleMethodA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01344        REFERENCE_METHOD_FAMILY(CallStaticDoubleMethod)
01345 
01346        // void (JNICALL *CallStaticVoidMethod) (JNIEnv *env, jclass cls, jmethodID methodID, ...);
01347        // void (JNICALL *CallStaticVoidMethodV) (JNIEnv *env, jclass cls, jmethodID methodID, va_list args);
01348        // void (JNICALL *CallStaticVoidMethodA) (JNIEnv *env, jclass cls, jmethodID methodID, jvalue * args);
01349        REFERENCE_METHOD_FAMILY(CallStaticVoidMethod)
01350 
01351        // jfieldID (JNICALL *GetStaticFieldID) (JNIEnv *env, jclass clazz, const char *name, const char *sig);
01352        &GetStaticFieldID,
01353        
01354        // jobject (JNICALL *GetStaticObjectField) (JNIEnv *env, jclass clazz, jfieldID fieldID);
01355        // jboolean (JNICALL *GetStaticBooleanField) (JNIEnv *env, jclass clazz, jfieldID fieldID);
01356        // jbyte (JNICALL *GetStaticByteField) (JNIEnv *env, jclass clazz, jfieldID fieldID);
01357        // jchar (JNICALL *GetStaticCharField) (JNIEnv *env, jclass clazz, jfieldID fieldID);
01358        // jshort (JNICALL *GetStaticShortField) (JNIEnv *env, jclass clazz, jfieldID fieldID);
01359        // jint (JNICALL *GetStaticIntField) (JNIEnv *env, jclass clazz, jfieldID fieldID);
01360        // jlong (JNICALL *GetStaticLongField) (JNIEnv *env, jclass clazz, jfieldID fieldID);
01361        // jfloat (JNICALL *GetStaticFloatField) (JNIEnv *env, jclass clazz, jfieldID fieldID);
01362        // jdouble (JNICALL *GetStaticDoubleField) (JNIEnv *env, jclass clazz, jfieldID fieldID);
01363        &GetStaticObjectField, &GetStaticBooleanField, &GetStaticByteField, &GetStaticCharField, &GetStaticShortField,
01364        &GetStaticIntField, &GetStaticLongField, &GetStaticFloatField, &GetStaticDoubleField,
01365 
01366        // void (JNICALL *SetStaticObjectField) (JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value);
01367        // void (JNICALL *SetStaticBooleanField) (JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value);
01368        // void (JNICALL *SetStaticByteField) (JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value);
01369        // void (JNICALL *SetStaticCharField) (JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value);
01370        // void (JNICALL *SetStaticShortField) (JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value);
01371        // void (JNICALL *SetStaticIntField) (JNIEnv *env, jclass clazz, jfieldID fieldID, jint value);
01372        // void (JNICALL *SetStaticLongField) (JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value);
01373        // void (JNICALL *SetStaticFloatField) (JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value);
01374        // void (JNICALL *SetStaticDoubleField) (JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value);
01375        &SetStaticObjectField, &SetStaticBooleanField, &SetStaticByteField, &SetStaticCharField, &SetStaticShortField,
01376        &SetStaticIntField, &SetStaticLongField, &SetStaticFloatField, &SetStaticDoubleField,
01377 
01378        // jstring (JNICALL *NewString) (JNIEnv *env, const jchar *unicode, jsize len);
01379        // jsize (JNICALL *GetStringLength) (JNIEnv *env, jstring str);
01380        // const jchar *(JNICALL *GetStringChars) (JNIEnv *env, jstring str, jboolean *isCopy);
01381        // void (JNICALL *ReleaseStringChars) (JNIEnv *env, jstring str, const jchar *chars);
01382        &NewString, &GetStringLength, &GetStringChars, &ReleaseStringChars,
01383 
01384        // jstring (JNICALL *NewStringUTF) (JNIEnv *env, const char *utf);
01385        // jsize (JNICALL *GetStringUTFLength) (JNIEnv *env, jstring str);
01386        // const char* (JNICALL *GetStringUTFChars) (JNIEnv *env, jstring str, jboolean *isCopy);
01387        // void (JNICALL *ReleaseStringUTFChars) (JNIEnv *env, jstring str, const char* chars);
01388        &NewStringUTF, &GetStringUTFLength, &GetStringUTFChars, &ReleaseStringUTFChars,
01389 
01390        // jsize (JNICALL *GetArrayLength) (JNIEnv *env, jarray array);
01391        &GetArrayLength,
01392 
01393        // jobjectArray (JNICALL *NewObjectArray) (JNIEnv *env, jsize len, jclass clazz, jobject init);
01394        // jobject (JNICALL *GetObjectArrayElement) (JNIEnv *env, jobjectArray array, jsize index);
01395        // void (JNICALL *SetObjectArrayElement) (JNIEnv *env, jobjectArray array, jsize index, jobject val);
01396        &NewObjectArray, &GetObjectArrayElement, &SetObjectArrayElement,
01397 
01398        // jbooleanArray (JNICALL *NewBooleanArray) (JNIEnv *env, jsize len);
01399        // jbyteArray (JNICALL *NewByteArray) (JNIEnv *env, jsize len);
01400        // jcharArray (JNICALL *NewCharArray) (JNIEnv *env, jsize len);
01401        // jshortArray (JNICALL *NewShortArray) (JNIEnv *env, jsize len);
01402        // jintArray (JNICALL *NewIntArray) (JNIEnv *env, jsize len);
01403        // jlongArray (JNICALL *NewLongArray) (JNIEnv *env, jsize len);
01404        // jfloatArray (JNICALL *NewFloatArray) (JNIEnv *env, jsize len);
01405        // jdoubleArray (JNICALL *NewDoubleArray) (JNIEnv *env, jsize len);
01406        &NewBooleanArray, &NewByteArray, &NewCharArray, &NewShortArray, 
01407        &NewIntArray, &NewLongArray, &NewFloatArray, &NewDoubleArray,
01408 
01409        // jboolean * (JNICALL *GetBooleanArrayElements) (JNIEnv *env, jbooleanArray array, jboolean *isCopy);
01410        // jbyte * (JNICALL *GetByteArrayElements) (JNIEnv *env, jbyteArray array, jboolean *isCopy);
01411        // jchar * (JNICALL *GetCharArrayElements) (JNIEnv *env, jcharArray array, jboolean *isCopy);
01412        // jshort * (JNICALL *GetShortArrayElements) (JNIEnv *env, jshortArray array, jboolean *isCopy);
01413        // jint * (JNICALL *GetIntArrayElements) (JNIEnv *env, jintArray array, jboolean *isCopy);
01414        // jlong * (JNICALL *GetLongArrayElements) (JNIEnv *env, jlongArray array, jboolean *isCopy);
01415        // jfloat * (JNICALL *GetFloatArrayElements) (JNIEnv *env, jfloatArray array, jboolean *isCopy);
01416        // jdouble * (JNICALL *GetDoubleArrayElements) (JNIEnv *env, jdoubleArray array, jboolean *isCopy);
01417        &GetBooleanArrayElements, &GetByteArrayElements, &GetCharArrayElements, &GetShortArrayElements, 
01418        &GetIntArrayElements, &GetLongArrayElements, &GetFloatArrayElements, &GetDoubleArrayElements, 
01419 
01420        // void (JNICALL *ReleaseBooleanArrayElements)(JNIEnv *env, jbooleanArray array, jboolean *elems, jint mode);
01421        // void (JNICALL *ReleaseByteArrayElements) (JNIEnv *env, jbyteArray array, jbyte *elems, jint mode);
01422        // void (JNICALL *ReleaseCharArrayElements) (JNIEnv *env, jcharArray array, jchar *elems, jint mode);
01423        // void (JNICALL *ReleaseShortArrayElements) (JNIEnv *env, jshortArray array, jshort *elems, jint mode);
01424        // void (JNICALL *ReleaseIntArrayElements) (JNIEnv *env, jintArray array, jint *elems, jint mode);
01425        // void (JNICALL *ReleaseLongArrayElements) (JNIEnv *env, jlongArray array, jlong *elems, jint mode);
01426        // void (JNICALL *ReleaseFloatArrayElements) (JNIEnv *env, jfloatArray array, jfloat *elems, jint mode);
01427        // void (JNICALL *ReleaseDoubleArrayElements) (JNIEnv *env, jdoubleArray array, jdouble *elems, jint mode);
01428        &ReleaseBooleanArrayElements, &ReleaseByteArrayElements, &ReleaseCharArrayElements, &ReleaseShortArrayElements, 
01429        &ReleaseIntArrayElements, &ReleaseLongArrayElements, &ReleaseFloatArrayElements, &ReleaseDoubleArrayElements, 
01430 
01431        // void (JNICALL *GetBooleanArrayRegion) (JNIEnv *env, jbooleanArray array, jsize start, jsize l, jboolean *buf);
01432        // void (JNICALL *GetByteArrayRegion) (JNIEnv *env, jbyteArray array, jsize start, jsize len, jbyte *buf);
01433        // void (JNICALL *GetCharArrayRegion) (JNIEnv *env, jcharArray array, jsize start, jsize len, jchar *buf);
01434        // void (JNICALL *GetShortArrayRegion) (JNIEnv *env, jshortArray array, jsize start, jsize len, jshort *buf);
01435        // void (JNICALL *GetIntArrayRegion) (JNIEnv *env, jintArray array, jsize start, jsize len, jint *buf);
01436        // void (JNICALL *GetLongArrayRegion) (JNIEnv *env, jlongArray array, jsize start, jsize len, jlong *buf);
01437        // void (JNICALL *GetFloatArrayRegion) (JNIEnv *env, jfloatArray array, jsize start, jsize len, jfloat *buf);
01438        // void (JNICALL *GetDoubleArrayRegion) (JNIEnv *env, jdoubleArray array, jsize start, jsize len, jdouble *buf);
01439        &GetBooleanArrayRegion, &GetByteArrayRegion, &GetCharArrayRegion, &GetShortArrayRegion, 
01440        &GetIntArrayRegion, &GetLongArrayRegion, &GetFloatArrayRegion, &GetDoubleArrayRegion, 
01441 
01442        // void (JNICALL *SetBooleanArrayRegion) (JNIEnv *env, jbooleanArray array, jsize start, jsize l, jboolean *buf);
01443        // void (JNICALL *SetByteArrayRegion) (JNIEnv *env, jbyteArray array, jsize start, jsize len, jbyte *buf);
01444        // void (JNICALL *SetCharArrayRegion) (JNIEnv *env, jcharArray array, jsize start, jsize len, jchar *buf);
01445        // void (JNICALL *SetShortArrayRegion) (JNIEnv *env, jshortArray array, jsize start, jsize len, jshort *buf);
01446        // void (JNICALL *SetIntArrayRegion) (JNIEnv *env, jintArray array, jsize start, jsize len, jint *buf);
01447        // void (JNICALL *SetLongArrayRegion) (JNIEnv *env, jlongArray array, jsize start, jsize len, jlong *buf);
01448        // void (JNICALL *SetFloatArrayRegion) (JNIEnv *env, jfloatArray array, jsize start, jsize len, jfloat *buf);
01449        // void (JNICALL *SetDoubleArrayRegion) (JNIEnv *env, jdoubleArray array, jsize start, jsize len, jdouble *buf);
01450        &SetBooleanArrayRegion, &SetByteArrayRegion, &SetCharArrayRegion, &SetShortArrayRegion, 
01451        &SetIntArrayRegion, &SetLongArrayRegion, &SetFloatArrayRegion, &SetDoubleArrayRegion, 
01452 
01453        // jint (JNICALL *RegisterNatives) (JNIEnv *env, jclass clazz, const JNINativeMethod *methods, jint nMethods);
01454        // jint (JNICALL *UnregisterNatives) (JNIEnv *env, jclass clazz);
01455        &RegisterNatives, &UnregisterNatives,
01456 
01457        // jint (JNICALL *MonitorEnter) (JNIEnv *env, jobject obj);
01458        // jint (JNICALL *MonitorExit) (JNIEnv *env, jobject obj);
01459        &MonitorEnter, &MonitorExit,
01460 
01461        // jint (JNICALL *GetJavaVM) (JNIEnv *env, JavaVM **vm);
01462        &GetJavaVM
01463 };
01464 
01465 nsHashtable* nsJNIEnv::theIDTable = NULL;
01466 
01467 nsJNIEnv::nsJNIEnv(nsISecureJNI2* secureEnv)
01468        :      mSecureEnv(secureEnv), mContext(NULL), mJavaThread(NULL)
01469 {
01470        this->functions = &theFuncs;
01471        if (theIDTable == NULL)
01472               theIDTable = new nsHashtable();
01473 }
01474 
01475 nsJNIEnv::~nsJNIEnv()
01476 {
01477        this->functions = NULL;
01478 }