Back to index

lightning-sunbird  0.9+nobinonly
ProxyJNI.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 "nscore.h"
00043 #include "jvmmgr.h"
00044 #include "nsISecureEnv.h"
00045 #include "nsIJVMPlugin.h"
00046 #include "nsHashtable.h"
00047 #include "nsVoidArray.h"
00048 #include "plstr.h"
00049 #include "ProxyClassLoader.h"
00050 
00051 #include "ProxyJNI.h"
00052 #include "nsDataHashtable.h"
00053 
00054 #ifdef DEBUG
00055 #include "nsDebug.h"
00056 #endif
00057 
00058 // Method Signature Processing.
00059 
00060 static jni_type get_jni_type(char sig)
00061 {
00062     switch (sig) {
00063     case 'L':
00064     case '[':
00065         return jobject_type;
00066     case 'Z':
00067         return jboolean_type;
00068     case 'B':
00069         return jbyte_type;
00070     case 'C':
00071         return jchar_type;
00072     case 'S':
00073         return jshort_type;
00074     case 'I':
00075         return jint_type;
00076     case 'J':
00077         return jlong_type;
00078     case 'F':
00079         return jfloat_type;
00080     case 'D':
00081         return jdouble_type;
00082     case 'V':
00083         return jvoid_type;
00084     }
00085     return jvoid_type;
00086 }
00087 
00088 static PRBool get_method_type(const char* sig, PRUint32& arg_count, jni_type*& arg_types, jni_type& return_type)
00089 {
00090     arg_count = 0;
00091     if (sig[0] == '(') {
00092         nsVoidArray vec;
00093         ++sig;
00094         while (*sig != ')' && *sig) {
00095             char arg_sig = *sig;
00096             jni_type arg_type = get_jni_type(arg_sig);
00097             if (arg_type == jobject_type) {
00098                 // could be an array or an object.
00099                 while (*sig == '[') ++sig;
00100                 if (*sig == 'L') {
00101                     // skip over "className;"
00102                     ++sig;
00103                     while (*sig != ';') ++sig;
00104                 }
00105             }
00106             // skip over scalar or ';'.
00107             ++sig;
00108             vec.AppendElement((void *) arg_type);
00109         }
00110         arg_count = vec.Count();
00111         arg_types = new jni_type[arg_count];
00112         for (int index = arg_count - 1; index >= 0; --index)
00113             arg_types[index] = jni_type((jint)NS_PTR_TO_INT32(vec.ElementAt(index)));
00114         if (*sig == ')') {
00115             char return_sig = *++sig;
00116             return_type = get_jni_type(return_sig);
00117         }
00118     }
00119     return PR_FALSE;
00120 }
00121 
00122 struct JNIMember {
00123     char* mName;
00124     char* mSignature;
00125     
00126     JNIMember(const char* name, const char* sig);
00127     ~JNIMember();
00128 };
00129 
00130 JNIMember::JNIMember(const char* name, const char* sig)
00131     : mName(NULL), mSignature(NULL)
00132 {
00133     mName = PL_strdup(name);
00134     mSignature = PL_strdup(sig);
00135 }
00136 
00137 JNIMember::~JNIMember()
00138 {
00139     PL_strfree(mName);
00140     PL_strfree(mSignature);
00141 }
00142 
00143 struct JNIField : JNIMember {
00144     jfieldID mFieldID;
00145     jni_type mFieldType;
00146     
00147     JNIField(const char* name, const char* sig, jfieldID fieldID);
00148 };
00149 
00150 JNIField::JNIField(const char* name, const char* sig, jfieldID fieldID)
00151     : JNIMember(name, sig), mFieldID(fieldID), mFieldType(get_jni_type(*sig))
00152 {
00153 }
00154 
00155 struct JNIMethod : JNIMember {
00156     jmethodID mMethodID;
00157     PRUint32 mArgCount;
00158     jni_type* mArgTypes;
00159     jni_type mReturnType;
00160     
00161     JNIMethod(const char* name, const char* sig, jmethodID methodID);
00162     ~JNIMethod();
00163     
00164     jvalue* marshallArgs(va_list args);
00165 };
00166 
00167 JNIMethod::JNIMethod(const char* name, const char* sig, jmethodID methodID)
00168     : JNIMember(name, sig), mMethodID(methodID), mArgCount(0), mArgTypes(NULL), mReturnType(jvoid_type)
00169 {
00170     get_method_type(sig, mArgCount, mArgTypes, mReturnType);
00171 }
00172 
00173 JNIMethod::~JNIMethod()
00174 {
00175     if (mArgTypes != NULL)
00176         delete[] mArgTypes;
00177 }
00178 
00182 jvalue* JNIMethod::marshallArgs(va_list args)
00183 {
00184     jvalue* jargs = NULL;
00185     PRUint32 argCount = mArgCount;
00186     if (argCount > 0) {
00187         jni_type* argTypes = mArgTypes;
00188         jargs = new jvalue[argCount];
00189         if (jargs != NULL) {
00190             for (PRUint32 i = 0; i < argCount; i++) {
00191                 switch (argTypes[i]) {
00192                 case jobject_type:
00193                     jargs[i].l = NS_STATIC_CAST(jobject, va_arg(args, void*));
00194                     break;
00195                 case jboolean_type:
00196                     jargs[i].z = NS_STATIC_CAST(jboolean, va_arg(args, jint));
00197                     break;
00198                 case jbyte_type:
00199                     jargs[i].b = NS_STATIC_CAST(jbyte, va_arg(args, jint));
00200                     break;
00201                 case jchar_type:
00202                     jargs[i].c = NS_STATIC_CAST(jchar, va_arg(args, jint));
00203                     break;
00204                 case jshort_type:
00205                     jargs[i].s = NS_STATIC_CAST(jshort, va_arg(args, jint));
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 = NS_STATIC_CAST(jfloat, va_arg(args, jdouble));
00215                     break;
00216                 case jdouble_type:
00217                     jargs[i].d = va_arg(args, jdouble);
00218                     break;
00219                 }
00220             }
00221         }
00222     }
00223     return jargs;
00224 }
00225 
00226 struct JavaClassMember {
00227     jclass clazz;
00228     void*  memberID;
00229 
00230     JavaClassMember(jclass cl, void* mID)
00231         { clazz = cl; memberID = mID;}
00232 };
00233 
00234 class JavaClassMemberKey : public PLDHashEntryHdr
00235 {
00236 public:
00237   typedef const JavaClassMember& KeyType;
00238   typedef const JavaClassMember* KeyTypePointer;
00239   
00240   JavaClassMemberKey(KeyTypePointer aKey) : mValue(*aKey) { }
00241   JavaClassMemberKey(const JavaClassMemberKey& toCopy) : mValue(toCopy.mValue) { }
00242   ~JavaClassMemberKey() { }
00243 
00244   KeyType GetKey() const { return mValue; }
00245   KeyTypePointer GetKeyPointer() const { return &mValue; }
00246   PRBool KeyEquals(KeyTypePointer aKey) const { return aKey->clazz == mValue.clazz && aKey->memberID == mValue.memberID; }
00247 
00248   static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
00249   static PLDHashNumber HashKey(KeyTypePointer aKey) 
00250   { 
00251     PRUint32 v1 = NS_PTR_TO_INT32(aKey->clazz);
00252     PRUint32 v2 = NS_PTR_TO_INT32(aKey->memberID);
00253     return v1 ^ v2;
00254   }
00255   enum { ALLOW_MEMMOVE = PR_TRUE };
00256 
00257 private:
00258   const JavaClassMember mValue;
00259 };
00260 
00265 class MarshalledArgs {
00266 public:
00267     MarshalledArgs(JNIMethod* forMethod, va_list args) : mArgs(forMethod->marshallArgs(args)) {}
00268     ~MarshalledArgs() { if (mArgs != NULL) delete[] mArgs; }
00269 
00270     operator jvalue* () { return mArgs; }
00271     
00272 private:
00273     jvalue* mArgs;
00274 };
00275 
00276 static jvalue kErrorValue;
00277 
00278 class ProxyJNIEnv : public JNIEnv {
00279 private:
00280     static JNINativeInterface_ theFuncs;
00281     static nsDataHashtable<JavaClassMemberKey, void*>* theIDTable;
00282     nsISecureEnv* mSecureEnv;
00283     nsISecurityContext* mContext;
00284     jbool mInProxyFindClass;
00285 
00286     static ProxyJNIEnv& GetProxyEnv(JNIEnv* env) { return *(ProxyJNIEnv*)env; }
00287 
00288     nsISecurityContext* getContext() { 
00289         if (!mContext) {
00290             return  JVM_GetJSSecurityContext();
00291         } else {
00292             mContext->AddRef();
00293             return mContext;
00294         }
00295     }
00296 
00297     static jint JNICALL GetVersion(JNIEnv* env)
00298     {
00299         jint version = 0;
00300         nsISecureEnv* secureEnv = GetSecureEnv(env);
00301         nsresult result;
00302         result = secureEnv->GetVersion(&version);
00303         return version;
00304     }
00305 
00306     static jclass JNICALL DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len)
00307     {
00308         jclass outClass = NULL;
00309         nsISecureEnv* secureEnv = GetSecureEnv(env);
00310         nsresult result;
00311         result = secureEnv->DefineClass(name, loader, buf, len, &outClass);
00312         return outClass;
00313     }
00314 
00315     static jclass JNICALL FindClass(JNIEnv *env, const char *name)
00316     {
00317         jclass outClass = NULL;
00318         ProxyJNIEnv& proxyEnv = GetProxyEnv(env);
00319         nsISecureEnv* secureEnv = proxyEnv.mSecureEnv;
00320         nsresult result;
00321         result = secureEnv->FindClass(name, &outClass);
00322         if ((NS_FAILED(result) || !outClass) && !proxyEnv.mInProxyFindClass) {
00323             proxyEnv.mInProxyFindClass = JNI_TRUE;
00324             outClass = ProxyFindClass(env, name);
00325             proxyEnv.mInProxyFindClass = JNI_FALSE;
00326         }
00327         return outClass;
00328     }
00329 
00330 #ifdef JDK1_2
00331     static jmethodID JNICALL FromReflectedMethod(JNIEnv *env, jobject method)
00332     {
00333         return NULL;
00334     }
00335     
00336     static jfieldID JNICALL FromReflectedField(JNIEnv *env, jobject field)
00337     {
00338         return NULL;
00339     }
00340 
00341     static jobject JNICALL ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID methodID, jboolean isStatic)
00342     {
00343         return NULL;
00344     }
00345 #endif
00346 
00347     static jclass JNICALL GetSuperclass(JNIEnv *env, jclass sub)
00348     {
00349         nsISecureEnv* secureEnv = GetSecureEnv(env);
00350         jclass outSuper = NULL;
00351         nsresult result;
00352         result = secureEnv->GetSuperclass(sub, &outSuper);
00353         return outSuper;
00354     }
00355 
00356     static jboolean JNICALL IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
00357     {
00358         nsISecureEnv* secureEnv = GetSecureEnv(env);
00359         jboolean outIsAssignable = PR_FALSE;
00360         nsresult result;
00361         result = secureEnv->IsAssignableFrom(sub, sup, &outIsAssignable);
00362         return outIsAssignable;
00363     }
00364     
00365 #ifdef JDK1_2
00366     static jobject JNICALL ToReflectedField(JNIEnv *env, jclass cls, jfieldID fieldID, jboolean isStatic)
00367     {
00368         return NULL;
00369     }
00370 #endif
00371     
00372     static jint JNICALL Throw(JNIEnv *env, jthrowable obj)
00373     {
00374         nsISecureEnv* secureEnv = GetSecureEnv(env);
00375         jint outStatus = PR_FALSE;
00376         nsresult result;
00377         result = secureEnv->Throw(obj, &outStatus);
00378         return outStatus;
00379     }
00380     
00381     static jint JNICALL ThrowNew(JNIEnv *env, jclass clazz, const char *msg)
00382     {
00383         nsISecureEnv* secureEnv = GetSecureEnv(env);
00384         jint outStatus = PR_FALSE;
00385         nsresult result;
00386         result = secureEnv->ThrowNew(clazz, msg, &outStatus);
00387         return outStatus;
00388     }
00389     
00390     static jthrowable JNICALL ExceptionOccurred(JNIEnv *env)
00391     {
00392         nsISecureEnv* secureEnv = GetSecureEnv(env);
00393         jthrowable outThrowable = NULL;
00394         nsresult result;
00395         result = secureEnv->ExceptionOccurred(&outThrowable);
00396         return outThrowable;
00397     }
00398 
00399     static void JNICALL ExceptionDescribe(JNIEnv *env)
00400     {
00401         nsISecureEnv* secureEnv = GetSecureEnv(env);
00402         nsresult result;
00403         result = secureEnv->ExceptionDescribe();
00404     }
00405     
00406     static void JNICALL ExceptionClear(JNIEnv *env)
00407     {
00408         nsISecureEnv* secureEnv = GetSecureEnv(env);
00409         nsresult result;
00410         result = secureEnv->ExceptionClear();
00411     }
00412     
00413     static void JNICALL FatalError(JNIEnv *env, const char *msg)
00414     {
00415         nsISecureEnv* secureEnv = GetSecureEnv(env);
00416         nsresult result;
00417         result = secureEnv->FatalError(msg);
00418     }
00419 
00420 #ifdef JDK1_2
00421     static jint JNICALL PushLocalFrame(JNIEnv *env, jint capacity)
00422     {
00423         return 0;
00424     }
00425     
00426     static jobject JNICALL PopLocalFrame(JNIEnv *env, jobject result)
00427     {
00428         return NULL;
00429     }
00430 #endif
00431 
00432     static jobject JNICALL NewGlobalRef(JNIEnv *env, jobject lobj)
00433     {
00434         nsISecureEnv* secureEnv = GetSecureEnv(env);
00435         jobject outGlobalRef = NULL;
00436         nsresult result;
00437         result = secureEnv->NewGlobalRef(lobj, &outGlobalRef);
00438         return outGlobalRef;
00439     }
00440     
00441     static void JNICALL DeleteGlobalRef(JNIEnv *env, jobject gref)
00442     {
00443         nsISecureEnv* secureEnv = GetSecureEnv(env);
00444         nsresult result;
00445         result = secureEnv->DeleteGlobalRef(gref);
00446     }
00447     
00448     static void JNICALL DeleteLocalRef(JNIEnv *env, jobject obj)
00449     {
00450         nsISecureEnv* secureEnv = GetSecureEnv(env);
00451         nsresult result;
00452         result = secureEnv->DeleteLocalRef(obj);
00453     }
00454     
00455     static jboolean JNICALL IsSameObject(JNIEnv *env, jobject obj1, jobject obj2)
00456     {
00457         nsISecureEnv* secureEnv = GetSecureEnv(env);
00458         jboolean outIsSameObject = PR_FALSE;
00459         nsresult result;
00460         result = secureEnv->IsSameObject(obj1, obj2, &outIsSameObject);
00461         return outIsSameObject;
00462     }
00463 
00464 #ifdef JDK1_2
00465     static jobject JNICALL NewLocalRef(JNIEnv *env, jobject ref)
00466     {
00467         return NULL;
00468     }
00469     
00470     static jint JNICALL EnsureLocalCapacity(JNIEnv *env, jint capacity)
00471     {
00472         return -1;
00473     }
00474 #endif
00475 
00476     static jobject JNICALL AllocObject(JNIEnv *env, jclass clazz)
00477     {
00478         nsISecureEnv* secureEnv = GetSecureEnv(env);
00479         jobject outObject = NULL;
00480         nsresult result;
00481         result = secureEnv->AllocObject(clazz, &outObject);
00482         return outObject;
00483     }
00484     
00485     static jobject JNICALL NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
00486     {
00487         va_list args; va_start(args, methodID);
00488         jobject outObject = NewObjectV(env, clazz, methodID, args);
00489         va_end(args);
00490         return outObject;
00491     }
00492     
00493     static jobject JNICALL NewObjectV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
00494     {
00495         jobject outObject = NULL;
00496         
00497         // convert the va_list into an array of jvalues.
00498         JNIMethod* method = (JNIMethod*)methodID;
00499         MarshalledArgs jargs(method, args);
00500         ProxyJNIEnv& proxyEnv = GetProxyEnv(env);
00501         nsISecureEnv* secureEnv = GetSecureEnv(env);
00502         nsISecurityContext* securityContext = proxyEnv.getContext();
00503         nsresult result;
00504         result = secureEnv->NewObject(clazz, method->mMethodID, jargs, &outObject, securityContext);
00505         NS_IF_RELEASE(securityContext);
00506         
00507         return outObject;
00508     }
00509 
00510     static jobject JNICALL NewObjectA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
00511     {
00512         jobject outObject = NULL;
00513         ProxyJNIEnv& proxyEnv = GetProxyEnv(env);
00514         nsISecureEnv* secureEnv = GetSecureEnv(env);
00515         JNIMethod* method = (JNIMethod*)methodID;
00516         nsISecurityContext* securityContext = proxyEnv.getContext();
00517         nsresult result;
00518         result = secureEnv->NewObject(clazz, method->mMethodID, args, &outObject, securityContext);
00519         NS_IF_RELEASE(securityContext);
00520         return outObject;
00521     }
00522 
00523     static jclass JNICALL GetObjectClass(JNIEnv *env, jobject obj)
00524     {
00525         jclass outClass = NULL;
00526         nsISecureEnv* secureEnv = GetSecureEnv(env);
00527         nsresult result;
00528         result = secureEnv->GetObjectClass(obj, &outClass);
00529         return outClass;
00530     }
00531     
00532     static jboolean JNICALL IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
00533     {
00534         nsISecureEnv* secureEnv = GetSecureEnv(env);
00535         jboolean outIsInstanceOf = PR_FALSE;
00536         nsresult result;
00537         result = secureEnv->IsInstanceOf(obj, clazz, &outIsInstanceOf);
00538         return outIsInstanceOf;
00539     }
00540 
00541     static jmethodID JNICALL GetMethodID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
00542     {
00543         nsISecureEnv* secureEnv = GetSecureEnv(env);
00544         jmethodID outMethodID = NULL;
00545         nsresult result = secureEnv->GetMethodID(clazz, name, sig, &outMethodID);
00546         if (result == NS_OK && outMethodID != NULL) {
00547             JavaClassMember key(clazz, outMethodID);
00548             JNIMethod* method;
00549             PRBool bFound = theIDTable && theIDTable->Get(key, (void **)&method);
00550             if (!bFound) {
00551                 method = new JNIMethod(name, sig, outMethodID);
00552                 if (theIDTable)
00553                     theIDTable->Put(key, method);
00554             }
00555             outMethodID = jmethodID(method);
00556         }
00557         return outMethodID;
00558     }
00559     
00564     // Virtual Invokers.
00565     
00566     static jvalue InvokeMethod(JNIEnv *env, jobject obj, JNIMethod* method, jvalue* args)
00567     {
00568         jvalue outValue;
00569         ProxyJNIEnv& proxyEnv = GetProxyEnv(env);
00570         nsISecureEnv* secureEnv = GetSecureEnv(env);
00571         nsISecurityContext* securityContext = proxyEnv.getContext();
00572         nsresult rv = secureEnv->CallMethod(method->mReturnType, obj, method->mMethodID, args, &outValue, securityContext);
00573         NS_IF_RELEASE(securityContext);
00574         return NS_SUCCEEDED(rv) ? outValue : kErrorValue;
00575     }
00576     
00577     static jvalue InvokeMethod(JNIEnv *env, jobject obj, JNIMethod* method, va_list args)
00578     {
00579         // convert the va_list into an array of jvalues.
00580         MarshalledArgs jargs(method, args);
00581         return InvokeMethod(env, obj, method, jargs);
00582     }
00583     
00584     static void InvokeVoidMethod(JNIEnv *env, jobject obj, JNIMethod* method, jvalue* args)
00585     {
00586         jvalue unusedValue;
00587         ProxyJNIEnv& proxyEnv = GetProxyEnv(env);
00588         nsISecureEnv* secureEnv = GetSecureEnv(env);
00589         nsISecurityContext* securityContext = proxyEnv.getContext();
00590         nsresult result;
00591         result = secureEnv->CallMethod(jvoid_type, obj, method->mMethodID, args, &unusedValue, securityContext);
00592         NS_IF_RELEASE(securityContext);
00593     }
00594 
00595     static void InvokeVoidMethod(JNIEnv *env, jobject obj, JNIMethod* method, va_list args)
00596     {
00597         // convert the va_list into an array of jvalues.
00598         MarshalledArgs jargs(method, args);
00599         InvokeVoidMethod(env, obj, method, jargs);
00600     }
00601 
00602 #define IMPLEMENT_METHOD_FAMILY(methodName, returnType, jvalueField) \
00603     static returnType JNICALL methodName(JNIEnv *env, jobject obj, jmethodID methodID, ...)                 \
00604     {                                                                                                       \
00605         va_list args; va_start(args, methodID);                                                             \
00606         returnType result = InvokeMethod(env, obj, (JNIMethod*)methodID, args).jvalueField;                 \
00607         va_end(args);                                                                                       \
00608         return result;                                                                                      \
00609     }                                                                                                       \
00610                                                                                                             \
00611     static returnType JNICALL methodName##V(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)     \
00612     {                                                                                                       \
00613         return InvokeMethod(env, obj, (JNIMethod*)methodID, args).jvalueField;                              \
00614     }                                                                                                       \
00615                                                                                                             \
00616     static returnType JNICALL methodName##A(JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)    \
00617     {                                                                                                       \
00618         return InvokeMethod(env, obj, (JNIMethod*)methodID, args).jvalueField;                              \
00619     }                                                                                                       \
00620 
00621     // Pattern on which IMPLEMENT_METHOD_FAMILY is based.
00622     /*
00623     static jobject JNICALL CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
00624     {
00625         va_list args; va_start(args, methodID);
00626         jobject outObject = InvokeMethod(env, obj, (JNIMethod*)methodID, args).l;
00627         va_end(args);
00628         return outObject;
00629     }
00630     
00631     static jobject JNICALL CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
00632     {
00633         return InvokeMethod(env, obj, (JNIMethod*)methodID, args).l;
00634     }
00635     
00636     static jobject JNICALL CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
00637     {
00638         return InvokeMethod(env, obj, (JNIMethod*)methodID, args).l;
00639     }
00640     */
00641     
00642     IMPLEMENT_METHOD_FAMILY(CallObjectMethod, jobject, l)
00643     IMPLEMENT_METHOD_FAMILY(CallBooleanMethod, jboolean, z)
00644     IMPLEMENT_METHOD_FAMILY(CallByteMethod, jbyte, b)
00645     IMPLEMENT_METHOD_FAMILY(CallCharMethod, jchar, c)
00646     IMPLEMENT_METHOD_FAMILY(CallShortMethod, jshort, s)
00647     IMPLEMENT_METHOD_FAMILY(CallIntMethod, jint, i)
00648     IMPLEMENT_METHOD_FAMILY(CallLongMethod, jlong, j)
00649     IMPLEMENT_METHOD_FAMILY(CallFloatMethod, jfloat, f)
00650     IMPLEMENT_METHOD_FAMILY(CallDoubleMethod, jdouble, d)
00651 
00652 #undef IMPLEMENT_METHOD_FAMILY
00653 
00654     static void JNICALL CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
00655     {
00656         va_list args; va_start(args, methodID);
00657         InvokeVoidMethod(env, obj, (JNIMethod*)methodID, args);
00658         va_end(args);
00659     }
00660     
00661     static void JNICALL CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
00662     {
00663         InvokeVoidMethod(env, obj, (JNIMethod*)methodID, args);
00664     }
00665     
00666     static void JNICALL CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
00667     {
00668         InvokeVoidMethod(env, obj, (JNIMethod*)methodID, args);
00669     }
00670 
00671     // Non-virtual Invokers.
00672 
00673     static jvalue InvokeNonVirtualMethod(JNIEnv *env, jobject obj, jclass clazz, JNIMethod* method, jvalue* args)
00674     {
00675         jvalue outValue;
00676         ProxyJNIEnv& proxyEnv = GetProxyEnv(env);
00677         nsISecureEnv* secureEnv = GetSecureEnv(env);
00678         nsISecurityContext* securityContext = proxyEnv.getContext();
00679         nsresult rv = secureEnv->CallNonvirtualMethod(method->mReturnType, obj, clazz, method->mMethodID, args, &outValue, securityContext);
00680         NS_IF_RELEASE(securityContext);
00681         return NS_SUCCEEDED(rv) ? outValue : kErrorValue;
00682     }
00683     
00684     static jvalue InvokeNonVirtualMethod(JNIEnv *env, jobject obj, jclass clazz, JNIMethod* method, va_list args)
00685     {
00686         // convert the va_list into an array of jvalues.
00687         MarshalledArgs jargs(method, args);
00688         return InvokeNonVirtualMethod(env, obj, clazz, method, jargs);
00689     }
00690     
00691     static void InvokeNonVirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz, JNIMethod* method, jvalue* args)
00692     {
00693         jvalue unusedValue;
00694         ProxyJNIEnv& proxyEnv = GetProxyEnv(env);
00695         nsISecureEnv* secureEnv = GetSecureEnv(env);
00696         nsISecurityContext* securityContext = proxyEnv.getContext();
00697         nsresult result;
00698         result = secureEnv->CallNonvirtualMethod(jvoid_type, obj, clazz, method->mMethodID, args, &unusedValue, securityContext);
00699         NS_IF_RELEASE(securityContext);
00700     }
00701 
00702     static void InvokeNonVirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz, JNIMethod* method, va_list args)
00703     {
00704         // convert the va_list into an array of jvalues.
00705         MarshalledArgs jargs(method, args);
00706         InvokeNonVirtualVoidMethod(env, obj, clazz, method, jargs);
00707     }
00708 
00709 #define IMPLEMENT_METHOD_FAMILY(methodName, returnType, jvalueField) \
00710     static returnType JNICALL methodName(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)               \
00711     {                                                                                                                   \
00712         va_list args; va_start(args, methodID);                                                                         \
00713         returnType result = InvokeNonVirtualMethod(env, obj, clazz, (JNIMethod*)methodID, args).jvalueField;            \
00714         va_end(args);                                                                                                   \
00715         return result;                                                                                                  \
00716     }                                                                                                                   \
00717                                                                                                                         \
00718     static returnType JNICALL methodName##V(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)   \
00719     {                                                                                                                   \
00720         return InvokeNonVirtualMethod(env, obj, clazz, (JNIMethod*)methodID, args).jvalueField;                         \
00721     }                                                                                                                   \
00722                                                                                                                         \
00723     static returnType JNICALL methodName##A(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)  \
00724     {                                                                                                                   \
00725         return InvokeNonVirtualMethod(env, obj, clazz, (JNIMethod*)methodID, args).jvalueField;                         \
00726     }                                                                                                                   \
00727 
00728     IMPLEMENT_METHOD_FAMILY(CallNonvirtualObjectMethod, jobject, l)
00729     IMPLEMENT_METHOD_FAMILY(CallNonvirtualBooleanMethod, jboolean, z)
00730     IMPLEMENT_METHOD_FAMILY(CallNonvirtualByteMethod, jbyte, b)
00731     IMPLEMENT_METHOD_FAMILY(CallNonvirtualCharMethod, jchar, c)
00732     IMPLEMENT_METHOD_FAMILY(CallNonvirtualShortMethod, jshort, s)
00733     IMPLEMENT_METHOD_FAMILY(CallNonvirtualIntMethod, jint, i)
00734     IMPLEMENT_METHOD_FAMILY(CallNonvirtualLongMethod, jlong, j)
00735     IMPLEMENT_METHOD_FAMILY(CallNonvirtualFloatMethod, jfloat, f)
00736     IMPLEMENT_METHOD_FAMILY(CallNonvirtualDoubleMethod, jdouble, d)
00737 
00738 #undef IMPLEMENT_METHOD_FAMILY
00739 
00740     static void JNICALL CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
00741     {
00742         va_list args; va_start(args, methodID);
00743         InvokeNonVirtualVoidMethod(env, obj, clazz, (JNIMethod*)methodID, args);
00744         va_end(args);
00745     }
00746     
00747     static void JNICALL CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
00748     {
00749         InvokeNonVirtualVoidMethod(env, obj, clazz, (JNIMethod*)methodID, args);
00750     }
00751     
00752     static void JNICALL CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
00753     {
00754         InvokeNonVirtualVoidMethod(env, obj, clazz, (JNIMethod*)methodID, args);
00755     }
00756 
00757     // Instance Fields
00758 
00759     static jfieldID JNICALL GetFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
00760     {
00761         nsISecureEnv* secureEnv = GetSecureEnv(env);
00762         jfieldID outFieldID = NULL;
00763         nsresult result = secureEnv->GetFieldID(clazz, name, sig, &outFieldID);
00764         if (result == NS_OK && outFieldID != NULL) {
00765             JavaClassMember key(clazz, outFieldID);
00766             JNIField* field;
00767             PRBool bFound = theIDTable && theIDTable->Get(key, (void **)&field);
00768             if (!bFound) {
00769                 field = new JNIField(name, sig, outFieldID);
00770                 if (theIDTable)
00771                     theIDTable->Put(key, field);
00772             }
00773             outFieldID = jfieldID(field);
00774         }
00775         return outFieldID;
00776     }
00777 
00778     static jvalue GetField(JNIEnv* env, jobject obj, JNIField* field)
00779     {
00780         jvalue outValue;
00781         ProxyJNIEnv& proxyEnv = GetProxyEnv(env);
00782         nsISecureEnv* secureEnv = GetSecureEnv(env);
00783         nsISecurityContext* securityContext = proxyEnv.getContext();
00784         nsresult rv = secureEnv->GetField(field->mFieldType, obj, field->mFieldID, &outValue, securityContext);
00785         NS_IF_RELEASE(securityContext);
00786         return NS_SUCCEEDED(rv) ? outValue : kErrorValue;
00787     }
00788 
00789 #define IMPLEMENT_GET_FIELD(methodName, returnType, jvalueField)                            \
00790     static returnType JNICALL methodName(JNIEnv *env, jobject obj, jfieldID fieldID)        \
00791     {                                                                                       \
00792         return GetField(env, obj, (JNIField*)fieldID).jvalueField;                          \
00793     }                                                                                       \
00794 
00795     IMPLEMENT_GET_FIELD(GetObjectField, jobject, l)
00796     IMPLEMENT_GET_FIELD(GetBooleanField, jboolean, z)
00797     IMPLEMENT_GET_FIELD(GetByteField, jbyte, b)
00798     IMPLEMENT_GET_FIELD(GetCharField, jchar, c)
00799     IMPLEMENT_GET_FIELD(GetShortField, jshort, s)
00800     IMPLEMENT_GET_FIELD(GetIntField, jint, i)
00801     IMPLEMENT_GET_FIELD(GetLongField, jlong, j)
00802     IMPLEMENT_GET_FIELD(GetFloatField, jfloat, f)
00803     IMPLEMENT_GET_FIELD(GetDoubleField, jdouble, d)
00804 
00805 #undef IMPLEMENT_GET_FIELD
00806 
00807     static void SetField(JNIEnv* env, jobject obj, JNIField* field, jvalue value)
00808     {
00809         ProxyJNIEnv& proxyEnv = GetProxyEnv(env);
00810         nsISecureEnv* secureEnv = GetSecureEnv(env);
00811         nsISecurityContext* securityContext = proxyEnv.getContext();
00812         nsresult result;
00813         result = secureEnv->SetField(field->mFieldType, obj, field->mFieldID, value, securityContext);
00814         NS_IF_RELEASE(securityContext);
00815     }
00816 
00817 #define IMPLEMENT_SET_FIELD(methodName, fieldType, jvalueField)                                     \
00818     static void JNICALL methodName(JNIEnv *env, jobject obj, jfieldID fieldID, fieldType value)     \
00819     {                                                                                               \
00820         jvalue fieldValue;                                                                          \
00821         fieldValue.jvalueField = value;                                                             \
00822         SetField(env, obj, (JNIField*)fieldID, fieldValue);                                         \
00823     }                                                                                               \
00824 
00825     IMPLEMENT_SET_FIELD(SetObjectField, jobject, l)
00826     IMPLEMENT_SET_FIELD(SetBooleanField, jboolean, z)
00827     IMPLEMENT_SET_FIELD(SetByteField, jbyte, b)
00828     IMPLEMENT_SET_FIELD(SetCharField, jchar, c)
00829     IMPLEMENT_SET_FIELD(SetShortField, jshort, s)
00830     IMPLEMENT_SET_FIELD(SetIntField, jint, i)
00831     IMPLEMENT_SET_FIELD(SetLongField, jlong, j)
00832     IMPLEMENT_SET_FIELD(SetFloatField, jfloat, f)
00833     IMPLEMENT_SET_FIELD(SetDoubleField, jdouble, d)
00834 
00835 #undef IMPLEMENT_SET_FIELD
00836 
00837     // Static Methods
00838 
00839     static jmethodID JNICALL GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
00840     {
00841         nsISecureEnv* secureEnv = GetSecureEnv(env);
00842         jmethodID outMethodID = NULL;
00843         nsresult result = secureEnv->GetStaticMethodID(clazz, name, sig, &outMethodID);
00844         if (result == NS_OK && outMethodID != NULL) {
00845             JavaClassMember key(clazz, outMethodID);
00846             JNIMethod* method;
00847             PRBool bFound = theIDTable && theIDTable->Get(key, (void **)&method);
00848             if (!bFound) {
00849                 method = new JNIMethod(name, sig, outMethodID);
00850                 if (theIDTable)
00851                     theIDTable->Put(key, method);
00852             }
00853             outMethodID = jmethodID(method);
00854         }
00855         return outMethodID;
00856     }
00857 
00858     // jobject (JNICALL *CallStaticObjectMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
00859     
00860     // Static Invokers.
00861     
00862     static jvalue InvokeStaticMethod(JNIEnv *env, jclass clazz, JNIMethod* method, jvalue* args)
00863     {
00864         jvalue outValue;
00865         ProxyJNIEnv& proxyEnv = GetProxyEnv(env);
00866         nsISecureEnv* secureEnv = GetSecureEnv(env);
00867         nsISecurityContext* securityContext = proxyEnv.getContext();
00868         nsresult rv = secureEnv->CallStaticMethod(method->mReturnType, clazz, method->mMethodID, args, &outValue, securityContext);
00869         NS_IF_RELEASE(securityContext);
00870         return NS_SUCCEEDED(rv) ? outValue : kErrorValue;
00871     }
00872     
00873     static jvalue InvokeStaticMethod(JNIEnv *env, jclass clazz, JNIMethod* method, va_list args)
00874     {
00875         // convert the va_list into an array of jvalues.
00876         MarshalledArgs jargs(method, args);
00877         return InvokeStaticMethod(env, clazz, method, jargs);
00878     }
00879     
00880     static void InvokeStaticVoidMethod(JNIEnv *env, jclass clazz, JNIMethod* method, jvalue* args)
00881     {
00882         jvalue unusedValue;
00883         ProxyJNIEnv& proxyEnv = GetProxyEnv(env);
00884         nsISecureEnv* secureEnv = GetSecureEnv(env);
00885         nsISecurityContext* securityContext = proxyEnv.getContext();
00886         nsresult result;
00887         result = secureEnv->CallStaticMethod(jvoid_type, clazz, method->mMethodID, args, &unusedValue, securityContext);
00888         NS_IF_RELEASE(securityContext);
00889     }
00890 
00891     static void InvokeStaticVoidMethod(JNIEnv *env, jclass clazz, JNIMethod* method, va_list args)
00892     {
00893         // convert the va_list into an array of jvalues.
00894         MarshalledArgs jargs(method, args);
00895         InvokeStaticVoidMethod(env, clazz, method, jargs);
00896     }
00897 
00898 #define IMPLEMENT_METHOD_FAMILY(methodName, returnType, jvalueField) \
00899     static returnType JNICALL methodName(JNIEnv *env, jclass clazz, jmethodID methodID, ...)                \
00900     {                                                                                                       \
00901         va_list args; va_start(args, methodID);                                                             \
00902         returnType result = InvokeStaticMethod(env, clazz, (JNIMethod*)methodID, args).jvalueField;         \
00903         va_end(args);                                                                                       \
00904         return result;                                                                                      \
00905     }                                                                                                       \
00906                                                                                                             \
00907     static returnType JNICALL methodName##V(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)    \
00908     {                                                                                                       \
00909         return InvokeStaticMethod(env, clazz, (JNIMethod*)methodID, args).jvalueField;                      \
00910     }                                                                                                       \
00911                                                                                                             \
00912     static returnType JNICALL methodName##A(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue * args)   \
00913     {                                                                                                       \
00914         return InvokeStaticMethod(env, clazz, (JNIMethod*)methodID, args).jvalueField;                      \
00915     }                                                                                                       \
00916 
00917     IMPLEMENT_METHOD_FAMILY(CallStaticObjectMethod, jobject, l)
00918     IMPLEMENT_METHOD_FAMILY(CallStaticBooleanMethod, jboolean, z)
00919     IMPLEMENT_METHOD_FAMILY(CallStaticByteMethod, jbyte, b)
00920     IMPLEMENT_METHOD_FAMILY(CallStaticCharMethod, jchar, c)
00921     IMPLEMENT_METHOD_FAMILY(CallStaticShortMethod, jshort, s)
00922     IMPLEMENT_METHOD_FAMILY(CallStaticIntMethod, jint, i)
00923     IMPLEMENT_METHOD_FAMILY(CallStaticLongMethod, jlong, j)
00924     IMPLEMENT_METHOD_FAMILY(CallStaticFloatMethod, jfloat, f)
00925     IMPLEMENT_METHOD_FAMILY(CallStaticDoubleMethod, jdouble, d)
00926 
00927 #undef IMPLEMENT_METHOD_FAMILY
00928 
00929     static void JNICALL CallStaticVoidMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
00930     {
00931         va_list args; va_start(args, methodID);
00932         InvokeStaticVoidMethod(env, clazz, (JNIMethod*)methodID, args);
00933         va_end(args);
00934     }
00935     
00936     static void JNICALL CallStaticVoidMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
00937     {
00938         InvokeStaticVoidMethod(env, clazz, (JNIMethod*)methodID, args);
00939     }
00940     
00941     static void JNICALL CallStaticVoidMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue * args)
00942     {
00943         InvokeStaticVoidMethod(env, clazz, (JNIMethod*)methodID, args);
00944     }
00945 
00946     // Static Fields
00947 
00948     static jfieldID JNICALL GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
00949     {
00950         nsISecureEnv* secureEnv = GetSecureEnv(env);
00951         jfieldID outFieldID = NULL;
00952         nsresult result = secureEnv->GetStaticFieldID(clazz, name, sig, &outFieldID);
00953         if (result == NS_OK && outFieldID != NULL) {
00954             JavaClassMember key(clazz, outFieldID);
00955             JNIField* field;
00956             PRBool bFound = theIDTable && theIDTable->Get(key, (void **)&field);
00957             if (!bFound) {
00958                 field = new JNIField(name, sig, outFieldID);
00959                 if (theIDTable)
00960                     theIDTable->Put(key, field);
00961             }
00962             outFieldID = jfieldID(field);
00963         }
00964         return outFieldID;
00965     }
00966 
00967     static jvalue GetStaticField(JNIEnv* env, jclass clazz, JNIField* field)
00968     {
00969         jvalue outValue;
00970         ProxyJNIEnv& proxyEnv = GetProxyEnv(env);
00971         nsISecureEnv* secureEnv = GetSecureEnv(env);
00972         nsISecurityContext* securityContext = proxyEnv.getContext();
00973         nsresult rv = secureEnv->GetStaticField(field->mFieldType, clazz, field->mFieldID, &outValue, securityContext);
00974         NS_IF_RELEASE(securityContext);
00975         return NS_SUCCEEDED(rv) ? outValue : kErrorValue;
00976     }
00977 
00978 #define IMPLEMENT_GET_FIELD(methodName, returnType, jvalueField)                            \
00979     static returnType JNICALL methodName(JNIEnv *env, jclass clazz, jfieldID fieldID)       \
00980     {                                                                                       \
00981         return GetStaticField(env, clazz, (JNIField*)fieldID).jvalueField;                  \
00982     }                                                                                       \
00983 
00984     IMPLEMENT_GET_FIELD(GetStaticObjectField, jobject, l)
00985     IMPLEMENT_GET_FIELD(GetStaticBooleanField, jboolean, z)
00986     IMPLEMENT_GET_FIELD(GetStaticByteField, jbyte, b)
00987     IMPLEMENT_GET_FIELD(GetStaticCharField, jchar, c)
00988     IMPLEMENT_GET_FIELD(GetStaticShortField, jshort, s)
00989     IMPLEMENT_GET_FIELD(GetStaticIntField, jint, i)
00990     IMPLEMENT_GET_FIELD(GetStaticLongField, jlong, j)
00991     IMPLEMENT_GET_FIELD(GetStaticFloatField, jfloat, f)
00992     IMPLEMENT_GET_FIELD(GetStaticDoubleField, jdouble, d)
00993 
00994 #undef IMPLEMENT_GET_FIELD
00995 
00996     static void SetStaticField(JNIEnv* env, jclass clazz, JNIField* field, jvalue value)
00997     {
00998         ProxyJNIEnv& proxyEnv = GetProxyEnv(env);
00999         nsISecureEnv* secureEnv = GetSecureEnv(env);
01000         nsISecurityContext* securityContext = proxyEnv.getContext();
01001         nsresult result;
01002         result = secureEnv->SetStaticField(field->mFieldType, clazz, field->mFieldID, value, securityContext);
01003         NS_IF_RELEASE(securityContext);
01004     }
01005 
01006 #define IMPLEMENT_SET_FIELD(methodName, fieldType, jvalueField)                                     \
01007     static void JNICALL methodName(JNIEnv *env, jclass clazz, jfieldID fieldID, fieldType value)    \
01008     {                                                                                               \
01009         jvalue fieldValue;                                                                          \
01010         fieldValue.jvalueField = value;                                                             \
01011         SetStaticField(env, clazz, (JNIField*)fieldID, fieldValue);                                 \
01012     }                                                                                               \
01013 
01014     IMPLEMENT_SET_FIELD(SetStaticObjectField, jobject, l)
01015     IMPLEMENT_SET_FIELD(SetStaticBooleanField, jboolean, z)
01016     IMPLEMENT_SET_FIELD(SetStaticByteField, jbyte, b)
01017     IMPLEMENT_SET_FIELD(SetStaticCharField, jchar, c)
01018     IMPLEMENT_SET_FIELD(SetStaticShortField, jshort, s)
01019     IMPLEMENT_SET_FIELD(SetStaticIntField, jint, i)
01020     IMPLEMENT_SET_FIELD(SetStaticLongField, jlong, j)
01021     IMPLEMENT_SET_FIELD(SetStaticFloatField, jfloat, f)
01022     IMPLEMENT_SET_FIELD(SetStaticDoubleField, jdouble, d)
01023 
01024 #undef IMPLEMENT_SET_FIELD
01025 
01026     static jstring JNICALL NewString(JNIEnv *env, const jchar *unicode, jsize len)
01027     {
01028         jstring outString;
01029         nsISecureEnv* secureEnv = GetSecureEnv(env);
01030         nsresult result;
01031         result = secureEnv->NewString(unicode, len, &outString);
01032         return outString;
01033     }
01034     
01035     static jsize JNICALL GetStringLength(JNIEnv *env, jstring str)
01036     {
01037         jsize outLength;
01038         nsISecureEnv* secureEnv = GetSecureEnv(env);
01039         nsresult result;
01040         result = secureEnv->GetStringLength(str, &outLength);
01041         return outLength;
01042     }
01043     
01044     static const jchar* JNICALL GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
01045     {
01046         const jchar* outChars = NULL;
01047         nsISecureEnv* secureEnv = GetSecureEnv(env);
01048         nsresult result;
01049         result = secureEnv->GetStringChars(str, isCopy, &outChars);
01050         return outChars;
01051     }
01052     
01053     static void JNICALL ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
01054     {
01055         nsISecureEnv* secureEnv = GetSecureEnv(env);
01056         nsresult result;
01057         result = secureEnv->ReleaseStringChars(str, chars);
01058     }
01059 
01060     static jstring JNICALL NewStringUTF(JNIEnv *env, const char *utf)
01061     {
01062         jstring outString;
01063         nsISecureEnv* secureEnv = GetSecureEnv(env);
01064         nsresult result;
01065         result = secureEnv->NewStringUTF(utf, &outString);
01066         return outString;
01067     }
01068     
01069     static jsize JNICALL GetStringUTFLength(JNIEnv *env, jstring str)
01070     {
01071         jsize outLength;
01072         nsISecureEnv* secureEnv = GetSecureEnv(env);
01073         nsresult result;
01074         result = secureEnv->GetStringUTFLength(str, &outLength);
01075         return outLength;
01076     }
01077     
01078     static const char* JNICALL GetStringUTFChars(JNIEnv *env, jstring str, jboolean *isCopy)
01079     {
01080         const char* outChars = NULL;
01081         nsISecureEnv* secureEnv = GetSecureEnv(env);
01082         nsresult result;
01083         result = secureEnv->GetStringUTFChars(str, isCopy, &outChars);
01084         return outChars;
01085     }
01086     
01087     static void JNICALL ReleaseStringUTFChars(JNIEnv *env, jstring str, const char* chars)
01088     {
01089         nsISecureEnv* secureEnv = GetSecureEnv(env);
01090         nsresult result;
01091         result = secureEnv->ReleaseStringUTFChars(str, chars);
01092     }
01093 
01094     static jsize JNICALL GetArrayLength(JNIEnv *env, jarray array)
01095     {
01096         jsize outLength;
01097         nsISecureEnv* secureEnv = GetSecureEnv(env);
01098         nsresult result;
01099         result = secureEnv->GetArrayLength(array, &outLength);
01100         return outLength;
01101     }
01102 
01103     static jobjectArray JNICALL NewObjectArray(JNIEnv *env, jsize len, jclass clazz, jobject initVal)
01104     {
01105         jobjectArray outArray = NULL;
01106         nsISecureEnv* secureEnv = GetSecureEnv(env);
01107         nsresult result;
01108         result = secureEnv->NewObjectArray(len, clazz, initVal, &outArray);
01109         return outArray;
01110     }
01111 
01112     static jobject JNICALL GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)
01113     {
01114         jobject outObject = NULL;
01115         nsISecureEnv* secureEnv = GetSecureEnv(env);
01116         nsresult result;
01117         result = secureEnv->GetObjectArrayElement(array, index, &outObject);
01118         return outObject;
01119     }
01120 
01121     static void JNICALL SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject val)
01122     {
01123         nsISecureEnv* secureEnv = GetSecureEnv(env);
01124         nsresult result;
01125         result = secureEnv->SetObjectArrayElement(array, index, val);
01126     }
01127 
01128 #define IMPLEMENT_NEW_ARRAY(methodName, type)                                                       \
01129     static type##Array JNICALL methodName(JNIEnv *env, jsize len)                                   \
01130     {                                                                                               \
01131         type##Array outArray = NULL;                                                                \
01132         nsISecureEnv* secureEnv = GetSecureEnv(env);                                                \
01133         nsresult result; \
01134         result = secureEnv->NewArray(type##_type, len, (jarray*)&outArray);             \
01135         return outArray;                                                                            \
01136     }                                                                                               \
01137 
01138     IMPLEMENT_NEW_ARRAY(NewBooleanArray, jboolean)
01139     IMPLEMENT_NEW_ARRAY(NewByteArray, jbyte)
01140     IMPLEMENT_NEW_ARRAY(NewCharArray, jchar)
01141     IMPLEMENT_NEW_ARRAY(NewShortArray, jshort)
01142     IMPLEMENT_NEW_ARRAY(NewIntArray, jint)
01143     IMPLEMENT_NEW_ARRAY(NewLongArray, jlong)
01144     IMPLEMENT_NEW_ARRAY(NewFloatArray, jfloat)
01145     IMPLEMENT_NEW_ARRAY(NewDoubleArray, jdouble)
01146 
01147 #undef IMPLEMENT_NEW_ARRAY
01148 
01149 #define IMPLEMENT_GET_ARRAY_ELEMENTS(methodName, type)                                                      \
01150     static type* JNICALL methodName(JNIEnv *env, type##Array array, jboolean *isCopy)                       \
01151     {                                                                                                       \
01152         type* outElements = NULL;                                                                           \
01153         nsISecureEnv* secureEnv = GetSecureEnv(env);                                                        \
01154         nsresult result;    \
01155         result = secureEnv->GetArrayElements(type##_type, array, isCopy, &outElements);         \
01156         return outElements;                                                                                 \
01157     }                                                                                                       \
01158 
01159     IMPLEMENT_GET_ARRAY_ELEMENTS(GetBooleanArrayElements, jboolean)
01160     IMPLEMENT_GET_ARRAY_ELEMENTS(GetByteArrayElements, jbyte)
01161     IMPLEMENT_GET_ARRAY_ELEMENTS(GetCharArrayElements, jchar)
01162     IMPLEMENT_GET_ARRAY_ELEMENTS(GetShortArrayElements, jshort)
01163     IMPLEMENT_GET_ARRAY_ELEMENTS(GetIntArrayElements, jint)
01164     IMPLEMENT_GET_ARRAY_ELEMENTS(GetLongArrayElements, jlong)
01165     IMPLEMENT_GET_ARRAY_ELEMENTS(GetFloatArrayElements, jfloat)
01166     IMPLEMENT_GET_ARRAY_ELEMENTS(GetDoubleArrayElements, jdouble)
01167 
01168 #undef IMPLEMENT_GET_ARRAY_ELEMENTS
01169 
01170 #define IMPLEMENT_RELEASE_ARRAY_ELEMENTS(methodName, type)                                                  \
01171     static void JNICALL methodName(JNIEnv *env, type##Array array, type* elems, jint mode)                  \
01172     {                                                                                                       \
01173         nsISecureEnv* secureEnv = GetSecureEnv(env);                                                        \
01174         nsresult result;    \
01175         result = secureEnv->ReleaseArrayElements(type##_type, array, elems, mode);                  \
01176     }                                                                                                       \
01177 
01178     IMPLEMENT_RELEASE_ARRAY_ELEMENTS(ReleaseBooleanArrayElements, jboolean)
01179     IMPLEMENT_RELEASE_ARRAY_ELEMENTS(ReleaseByteArrayElements, jbyte)
01180     IMPLEMENT_RELEASE_ARRAY_ELEMENTS(ReleaseCharArrayElements, jchar)
01181     IMPLEMENT_RELEASE_ARRAY_ELEMENTS(ReleaseShortArrayElements, jshort)
01182     IMPLEMENT_RELEASE_ARRAY_ELEMENTS(ReleaseIntArrayElements, jint)
01183     IMPLEMENT_RELEASE_ARRAY_ELEMENTS(ReleaseLongArrayElements, jlong)
01184     IMPLEMENT_RELEASE_ARRAY_ELEMENTS(ReleaseFloatArrayElements, jfloat)
01185     IMPLEMENT_RELEASE_ARRAY_ELEMENTS(ReleaseDoubleArrayElements, jdouble)
01186 
01187 #undef IMPLEMENT_RELEASE_ARRAY_ELEMENTS
01188 
01189 #define IMPLEMENT_GET_ARRAY_REGION(methodName, type)                                                        \
01190     static void JNICALL methodName(JNIEnv *env, type##Array array, jsize start, jsize len, type* buf)       \
01191     {                                                                                                       \
01192         nsISecureEnv* secureEnv = GetSecureEnv(env);                                                        \
01193         nsresult result;    \
01194         result = secureEnv->GetArrayRegion(type##_type, array, start, len, buf);                    \
01195     }                                                                                                       \
01196 
01197     IMPLEMENT_GET_ARRAY_REGION(GetBooleanArrayRegion, jboolean)
01198     IMPLEMENT_GET_ARRAY_REGION(GetByteArrayRegion, jbyte)
01199     IMPLEMENT_GET_ARRAY_REGION(GetCharArrayRegion, jchar)
01200     IMPLEMENT_GET_ARRAY_REGION(GetShortArrayRegion, jshort)
01201     IMPLEMENT_GET_ARRAY_REGION(GetIntArrayRegion, jint)
01202     IMPLEMENT_GET_ARRAY_REGION(GetLongArrayRegion, jlong)
01203     IMPLEMENT_GET_ARRAY_REGION(GetFloatArrayRegion, jfloat)
01204     IMPLEMENT_GET_ARRAY_REGION(GetDoubleArrayRegion, jdouble)
01205 
01206 #undef IMPLEMENT_GET_ARRAY_REGION
01207 
01208 #define IMPLEMENT_SET_ARRAY_REGION(methodName, type)                                                        \
01209     static void JNICALL methodName(JNIEnv *env, type##Array array, jsize start, jsize len, type* buf)       \
01210     {                                                                                                       \
01211         nsISecureEnv* secureEnv = GetSecureEnv(env);                                                        \
01212         nsresult result;    \
01213         result = secureEnv->SetArrayRegion(type##_type, array, start, len, buf);                    \
01214     }                                                                                                       \
01215 
01216     IMPLEMENT_SET_ARRAY_REGION(SetBooleanArrayRegion, jboolean)
01217     IMPLEMENT_SET_ARRAY_REGION(SetByteArrayRegion, jbyte)
01218     IMPLEMENT_SET_ARRAY_REGION(SetCharArrayRegion, jchar)
01219     IMPLEMENT_SET_ARRAY_REGION(SetShortArrayRegion, jshort)
01220     IMPLEMENT_SET_ARRAY_REGION(SetIntArrayRegion, jint)
01221     IMPLEMENT_SET_ARRAY_REGION(SetLongArrayRegion, jlong)
01222     IMPLEMENT_SET_ARRAY_REGION(SetFloatArrayRegion, jfloat)
01223     IMPLEMENT_SET_ARRAY_REGION(SetDoubleArrayRegion, jdouble)
01224 
01225 #undef IMPLEMENT_SET_ARRAY_REGION
01226 
01227     static jint JNICALL RegisterNatives(JNIEnv *env, jclass clazz, const JNINativeMethod *methods, jint nMethods)
01228     {
01229         jint outStatus = -1;
01230         nsISecureEnv* secureEnv = GetSecureEnv(env);
01231         nsresult result;
01232         result = secureEnv->RegisterNatives(clazz, methods, nMethods, &outStatus);
01233         return outStatus;
01234     }
01235     
01236     static jint JNICALL UnregisterNatives(JNIEnv *env, jclass clazz)
01237     {
01238         jint outStatus = -1;
01239         nsISecureEnv* secureEnv = GetSecureEnv(env);
01240         nsresult result;
01241         result = secureEnv->UnregisterNatives(clazz, &outStatus);
01242         return outStatus;
01243     }
01244 
01245     static jint JNICALL MonitorEnter(JNIEnv *env, jobject obj)
01246     {
01247         jint outStatus = -1;
01248         nsISecureEnv* secureEnv = GetSecureEnv(env);
01249         nsresult result;
01250         result = secureEnv->MonitorEnter(obj, &outStatus);
01251         return outStatus;
01252     }
01253     
01254     static jint JNICALL JNICALL MonitorExit(JNIEnv *env, jobject obj)
01255     {
01256         jint outStatus = -1;
01257         nsISecureEnv* secureEnv = GetSecureEnv(env);
01258         nsresult result;
01259         result = secureEnv->MonitorExit(obj, &outStatus);
01260         return outStatus;
01261     }
01262 
01263     static jint JNICALL GetJavaVM(JNIEnv *env, JavaVM **vm)
01264     {
01265         jint outStatus = -1;
01266         nsISecureEnv* secureEnv = GetSecureEnv(env);
01267         nsresult result;
01268         result = secureEnv->GetJavaVM(vm, &outStatus);
01269         return outStatus;
01270     }
01271 
01272 public:
01273     ProxyJNIEnv(nsIJVMPlugin* jvmPlugin, nsISecureEnv* secureEnv);
01274     ~ProxyJNIEnv();
01275     
01276     nsISecureEnv* getSecureEnv() { return mSecureEnv; }
01277     void SetSecurityContext(nsISecurityContext *context) { 
01278         if (mContext)
01279             mContext->Release();
01280         mContext = context;
01281         mContext->AddRef();
01282     }
01283     
01284     nsresult GetSecurityContext(nsISecurityContext **context)
01285     {
01286         if (!context)
01287             return NS_ERROR_FAILURE;
01288 
01289         *context = getContext();
01290         return NS_OK;
01291     }
01292 };
01293 
01294 JNINativeInterface_ ProxyJNIEnv::theFuncs = {
01295     NULL,   // void *reserved0;
01296     NULL,   // void *reserved1;
01297     NULL,   // void *reserved2;
01298 
01299     NULL,   // void *reserved3;
01300 
01301     // jint (JNICALL *GetVersion)(JNIEnv *env); 
01302     &GetVersion,
01303 
01304     // jclass (JNICALL *DefineClass) (JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len);
01305     &DefineClass,
01306     
01307     // jclass (JNICALL *FindClass) (JNIEnv *env, const char *name);
01308     &FindClass,
01309 
01310 #ifdef JDK1_2
01311     // jmethodID (JNICALL *FromReflectedMethod) (JNIEnv *env, jobject method);
01312     &FromReflectedMethod,
01313     
01314     // jfieldID (JNICALL *FromReflectedField) (JNIEnv *env, jobject field);
01315     &FromReflectedField,
01316 
01317     // jobject (JNICALL *ToReflectedMethod) (JNIEnv *env, jclass cls, jmethodID methodID, jboolean isStatic);
01318     &ToReflectedMethod,
01319 #else
01320     NULL,   // void *reserved4;
01321     NULL,   // void *reserved5;
01322     NULL,   // void *reserved6;
01323 #endif
01324 
01325     // jclass (JNICALL *GetSuperclass) (JNIEnv *env, jclass sub);
01326     &GetSuperclass,
01327     
01328     // jboolean (JNICALL *IsAssignableFrom) (JNIEnv *env, jclass sub, jclass sup);
01329     &IsAssignableFrom,
01330     
01331 #ifdef JDK1_2
01332     // jobject (JNICALL *ToReflectedField) (JNIEnv *env, jclass cls, jfieldID fieldID, jboolean isStatic);
01333     &ToReflectedField,
01334 #else    
01335     NULL, // void *reserved7;
01336 #endif
01337 
01338     // jint (JNICALL *Throw) (JNIEnv *env, jthrowable obj);
01339     &Throw,
01340     
01341     // jint (JNICALL *ThrowNew) (JNIEnv *env, jclass clazz, const char *msg);
01342     &ThrowNew,
01343     
01344     // jthrowable (JNICALL *ExceptionOccurred) (JNIEnv *env);
01345     &ExceptionOccurred,
01346     
01347     // void (JNICALL *ExceptionDescribe) (JNIEnv *env);
01348     &ExceptionDescribe,
01349     
01350     // void (JNICALL *ExceptionClear) (JNIEnv *env);
01351     &ExceptionClear,
01352     
01353     // void (JNICALL *FatalError) (JNIEnv *env, const char *msg);
01354     &FatalError,
01355     
01356 #ifdef JDK1_2
01357     // jint (JNICALL *PushLocalFrame) (JNIEnv *env, jint capacity);
01358     &PushLocalFrame,
01359     
01360     // jobject (JNICALL *PopLocalFrame) (JNIEnv *env, jobject result);
01361     &PopLocalFrame,
01362 #else
01363     NULL, // void *reserved8;
01364     NULL, // void *reserved9;
01365 #endif
01366 
01367     // jobject (JNICALL *NewGlobalRef) (JNIEnv *env, jobject lobj);
01368     &NewGlobalRef,
01369     
01370     // void (JNICALL *DeleteGlobalRef) (JNIEnv *env, jobject gref);
01371     &DeleteGlobalRef,
01372     
01373     // void (JNICALL *DeleteLocalRef) (JNIEnv *env, jobject obj);
01374     &DeleteLocalRef,
01375     
01376     // jboolean (JNICALL *IsSameObject) (JNIEnv *env, jobject obj1, jobject obj2);
01377     &IsSameObject,
01378     
01379 #ifdef JDK1_2
01380     // jobject (JNICALL *NewLocalRef) (JNIEnv *env, jobject ref);
01381     &NewLocalRef,
01382     
01383     // jint (JNICALL *EnsureLocalCapacity) (JNIEnv *env, jint capacity);
01384     &EnsureLocalCapacity,
01385 #else
01386     NULL, // void *reserved10;
01387     NULL, // void *reserved11;
01388 #endif
01389 
01390     // jobject (JNICALL *AllocObject) (JNIEnv *env, jclass clazz);
01391     &AllocObject,
01392     
01393 #define REFERENCE_METHOD_FAMILY(methodName) &methodName, &methodName##V, &methodName##A,
01394 
01395     // jobject (JNICALL *NewObject) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01396     // jobject (JNICALL *NewObjectV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01397     // jobject (JNICALL *NewObjectA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01398     REFERENCE_METHOD_FAMILY(NewObject)
01399     
01400     // jclass (JNICALL *GetObjectClass) (JNIEnv *env, jobject obj);
01401     &GetObjectClass,
01402     
01403     // jboolean (JNICALL *IsInstanceOf) (JNIEnv *env, jobject obj, jclass clazz);
01404     &IsInstanceOf,
01405 
01406     // jmethodID (JNICALL *GetMethodID)(JNIEnv *env, jclass clazz, const char *name, const char *sig);
01407     &GetMethodID,
01408 
01409     // jobject (JNICALL *CallObjectMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01410     // jobject (JNICALL *CallObjectMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01411     // jobject (JNICALL *CallObjectMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args);
01412     REFERENCE_METHOD_FAMILY(CallObjectMethod)
01413     
01414     // jboolean (JNICALL *CallBooleanMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01415     // jboolean (JNICALL *CallBooleanMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01416     // jboolean (JNICALL *CallBooleanMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args);
01417     REFERENCE_METHOD_FAMILY(CallBooleanMethod)
01418 
01419     // jbyte (JNICALL *CallByteMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01420     // jbyte (JNICALL *CallByteMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01421     // jbyte (JNICALL *CallByteMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);
01422     REFERENCE_METHOD_FAMILY(CallByteMethod)
01423 
01424     // jchar (JNICALL *CallCharMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01425     // jchar (JNICALL *CallCharMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01426     // jchar (JNICALL *CallCharMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);
01427     REFERENCE_METHOD_FAMILY(CallCharMethod)
01428 
01429     // jshort (JNICALL *CallShortMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01430     // jshort (JNICALL *CallShortMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01431     // jshort (JNICALL *CallShortMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);
01432     REFERENCE_METHOD_FAMILY(CallShortMethod)
01433 
01434     // jint (JNICALL *CallIntMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01435     // jint (JNICALL *CallIntMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01436     // jint (JNICALL *CallIntMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);
01437     REFERENCE_METHOD_FAMILY(CallIntMethod)
01438 
01439     // jlong (JNICALL *CallLongMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01440     // jlong (JNICALL *CallLongMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01441     // jlong (JNICALL *CallLongMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);
01442     REFERENCE_METHOD_FAMILY(CallLongMethod)
01443 
01444     // jfloat (JNICALL *CallFloatMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01445     // jfloat (JNICALL *CallFloatMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01446     // jfloat (JNICALL *CallFloatMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);
01447     REFERENCE_METHOD_FAMILY(CallFloatMethod)
01448 
01449     // jdouble (JNICALL *CallDoubleMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01450     // jdouble (JNICALL *CallDoubleMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01451     // jdouble (JNICALL *CallDoubleMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);
01452     REFERENCE_METHOD_FAMILY(CallDoubleMethod)
01453 
01454     // void (JNICALL *CallVoidMethod) (JNIEnv *env, jobject obj, jmethodID methodID, ...);
01455     // void (JNICALL *CallVoidMethodV) (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
01456     // void (JNICALL *CallVoidMethodA) (JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args);
01457     REFERENCE_METHOD_FAMILY(CallVoidMethod)
01458 
01459     // jobject (JNICALL *CallNonvirtualObjectMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01460     // jobject (JNICALL *CallNonvirtualObjectMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01461     // jobject (JNICALL *CallNonvirtualObjectMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args);
01462     REFERENCE_METHOD_FAMILY(CallNonvirtualObjectMethod)
01463 
01464     // jboolean (JNICALL *CallNonvirtualBooleanMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01465     // jboolean (JNICALL *CallNonvirtualBooleanMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01466     // jboolean (JNICALL *CallNonvirtualBooleanMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args);
01467     REFERENCE_METHOD_FAMILY(CallNonvirtualBooleanMethod)
01468 
01469     // jbyte (JNICALL *CallNonvirtualByteMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01470     // jbyte (JNICALL *CallNonvirtualByteMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01471     // jbyte (JNICALL *CallNonvirtualByteMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);
01472     REFERENCE_METHOD_FAMILY(CallNonvirtualByteMethod)
01473 
01474     // jchar (JNICALL *CallNonvirtualCharMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01475     // jchar (JNICALL *CallNonvirtualCharMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01476     // jchar (JNICALL *CallNonvirtualCharMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);
01477     REFERENCE_METHOD_FAMILY(CallNonvirtualCharMethod)
01478 
01479     // jshort (JNICALL *CallNonvirtualShortMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01480     // jshort (JNICALL *CallNonvirtualShortMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01481     // jshort (JNICALL *CallNonvirtualShortMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);
01482     REFERENCE_METHOD_FAMILY(CallNonvirtualShortMethod)
01483 
01484     // jint (JNICALL *CallNonvirtualIntMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01485     // jint (JNICALL *CallNonvirtualIntMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01486     // jint (JNICALL *CallNonvirtualIntMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);
01487     REFERENCE_METHOD_FAMILY(CallNonvirtualIntMethod)
01488 
01489     // jlong (JNICALL *CallNonvirtualLongMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01490     // jlong (JNICALL *CallNonvirtualLongMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01491     // jlong (JNICALL *CallNonvirtualLongMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);
01492     REFERENCE_METHOD_FAMILY(CallNonvirtualLongMethod)
01493 
01494     // jfloat (JNICALL *CallNonvirtualFloatMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01495     // jfloat (JNICALL *CallNonvirtualFloatMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01496     // jfloat (JNICALL *CallNonvirtualFloatMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);
01497     REFERENCE_METHOD_FAMILY(CallNonvirtualFloatMethod)
01498 
01499     // jdouble (JNICALL *CallNonvirtualDoubleMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01500     // jdouble (JNICALL *CallNonvirtualDoubleMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01501     // jdouble (JNICALL *CallNonvirtualDoubleMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);
01502     REFERENCE_METHOD_FAMILY(CallNonvirtualDoubleMethod)
01503 
01504     // void (JNICALL *CallNonvirtualVoidMethod) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
01505     // void (JNICALL *CallNonvirtualVoidMethodV) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);
01506     // void (JNICALL *CallNonvirtualVoidMethodA) (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args);
01507     REFERENCE_METHOD_FAMILY(CallNonvirtualVoidMethod)
01508 
01509     // jfieldID (JNICALL *GetFieldID) (JNIEnv *env, jclass clazz, const char *name, const char *sig);
01510     &GetFieldID,
01511 
01512     // jobject (JNICALL *GetObjectField) (JNIEnv *env, jobject obj, jfieldID fieldID);
01513     // jboolean (JNICALL *GetBooleanField) (JNIEnv *env, jobject obj, jfieldID fieldID);
01514     // jbyte (JNICALL *GetByteField) (JNIEnv *env, jobject obj, jfieldID fieldID);
01515     // jchar (JNICALL *GetCharField) (JNIEnv *env, jobject obj, jfieldID fieldID);
01516     // jshort (JNICALL *GetShortField) (JNIEnv *env, jobject obj, jfieldID fieldID);
01517     // jint (JNICALL *GetIntField) (JNIEnv *env, jobject obj, jfieldID fieldID);
01518     // jlong (JNICALL *GetLongField) (JNIEnv *env, jobject obj, jfieldID fieldID);
01519     // jfloat (JNICALL *GetFloatField) (JNIEnv *env, jobject obj, jfieldID fieldID);
01520     // jdouble (JNICALL *GetDoubleField) (JNIEnv *env, jobject obj, jfieldID fieldID);
01521     &GetObjectField, &GetBooleanField, &GetByteField, &GetCharField, &GetShortField, &GetIntField, &GetLongField,
01522     &GetFloatField, &GetDoubleField,
01523 
01524     // void (JNICALL *SetObjectField) (JNIEnv *env, jobject obj, jfieldID fieldID, jobject val);
01525     // void (JNICALL *SetBooleanField) (JNIEnv *env, jobject obj, jfieldID fieldID, jboolean val);
01526     // void (JNICALL *SetByteField) (JNIEnv *env, jobject obj, jfieldID fieldID, jbyte val);
01527     // void (JNICALL *SetCharField) (JNIEnv *env, jobject obj, jfieldID fieldID, jchar val);
01528     // void (JNICALL *SetShortField) (JNIEnv *env, jobject obj, jfieldID fieldID, jshort val);
01529     // void (JNICALL *SetIntField) (JNIEnv *env, jobject obj, jfieldID fieldID, jint val);
01530     // void (JNICALL *SetLongField) (JNIEnv *env, jobject obj, jfieldID fieldID, jlong val);
01531     // void (JNICALL *SetFloatField) (JNIEnv *env, jobject obj, jfieldID fieldID, jfloat val);
01532     // void (JNICALL *SetDoubleField) (JNIEnv *env, jobject obj, jfieldID fieldID, jdouble val);
01533     &SetObjectField, &SetBooleanField, &SetByteField, &SetCharField, &SetShortField, &SetIntField, &SetLongField,
01534     &SetFloatField, &SetDoubleField,
01535 
01536     // jmethodID (JNICALL *GetStaticMethodID) (JNIEnv *env, jclass clazz, const char *name, const char *sig);
01537     &GetStaticMethodID,
01538 
01539     // jobject (JNICALL *CallStaticObjectMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01540     // jobject (JNICALL *CallStaticObjectMethodV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01541     // jobject (JNICALL *CallStaticObjectMethodA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01542     REFERENCE_METHOD_FAMILY(CallStaticObjectMethod)
01543 
01544     // jboolean (JNICALL *CallStaticBooleanMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01545     // jboolean (JNICALL *CallStaticBooleanMethodV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01546     // jboolean (JNICALL *CallStaticBooleanMethodA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01547     REFERENCE_METHOD_FAMILY(CallStaticBooleanMethod)
01548 
01549     // jbyte (JNICALL *CallStaticByteMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01550     // jbyte (JNICALL *CallStaticByteMethodV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01551     // jbyte (JNICALL *CallStaticByteMethodA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01552     REFERENCE_METHOD_FAMILY(CallStaticByteMethod)
01553 
01554     // jchar (JNICALL *CallStaticCharMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01555     // jchar (JNICALL *CallStaticCharMethodV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01556     // jchar (JNICALL *CallStaticCharMethodA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01557     REFERENCE_METHOD_FAMILY(CallStaticCharMethod)
01558 
01559     // jshort (JNICALL *CallStaticShortMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01560     // jshort (JNICALL *CallStaticShortMethodV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01561     // jshort (JNICALL *CallStaticShortMethodA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01562     REFERENCE_METHOD_FAMILY(CallStaticShortMethod)
01563 
01564     // jint (JNICALL *CallStaticIntMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01565     // jint (JNICALL *CallStaticIntMethodV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01566     // jint (JNICALL *CallStaticIntMethodA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01567     REFERENCE_METHOD_FAMILY(CallStaticIntMethod)
01568 
01569     // jlong (JNICALL *CallStaticLongMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01570     // jlong (JNICALL *CallStaticLongMethodV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01571     // jlong (JNICALL *CallStaticLongMethodA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01572     REFERENCE_METHOD_FAMILY(CallStaticLongMethod)
01573 
01574     // jfloat (JNICALL *CallStaticFloatMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01575     // jfloat (JNICALL *CallStaticFloatMethodV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01576     // jfloat (JNICALL *CallStaticFloatMethodA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01577     REFERENCE_METHOD_FAMILY(CallStaticFloatMethod)
01578 
01579     // jdouble (JNICALL *CallStaticDoubleMethod) (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
01580     // jdouble (JNICALL *CallStaticDoubleMethodV) (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
01581     // jdouble (JNICALL *CallStaticDoubleMethodA) (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);
01582     REFERENCE_METHOD_FAMILY(CallStaticDoubleMethod)
01583 
01584     // void (JNICALL *CallStaticVoidMethod) (JNIEnv *env, jclass cls, jmethodID methodID, ...);
01585     // void (JNICALL *CallStaticVoidMethodV) (JNIEnv *env, jclass cls, jmethodID methodID, va_list args);
01586     // void (JNICALL *CallStaticVoidMethodA) (JNIEnv *env, jclass cls, jmethodID methodID, jvalue * args);
01587     REFERENCE_METHOD_FAMILY(CallStaticVoidMethod)
01588 
01589     // jfieldID (JNICALL *GetStaticFieldID) (JNIEnv *env, jclass clazz, const char *name, const char *sig);
01590     &GetStaticFieldID,
01591     
01592     // jobject (JNICALL *GetStaticObjectField) (JNIEnv *env, jclass clazz, jfieldID fieldID);
01593     // jboolean (JNICALL *GetStaticBooleanField) (JNIEnv *env, jclass clazz, jfieldID fieldID);
01594     // jbyte (JNICALL *GetStaticByteField) (JNIEnv *env, jclass clazz, jfieldID fieldID);
01595     // jchar (JNICALL *GetStaticCharField) (JNIEnv *env, jclass clazz, jfieldID fieldID);
01596     // jshort (JNICALL *GetStaticShortField) (JNIEnv *env, jclass clazz, jfieldID fieldID);
01597     // jint (JNICALL *GetStaticIntField) (JNIEnv *env, jclass clazz, jfieldID fieldID);
01598     // jlong (JNICALL *GetStaticLongField) (JNIEnv *env, jclass clazz, jfieldID fieldID);
01599     // jfloat (JNICALL *GetStaticFloatField) (JNIEnv *env, jclass clazz, jfieldID fieldID);
01600     // jdouble (JNICALL *GetStaticDoubleField) (JNIEnv *env, jclass clazz, jfieldID fieldID);
01601     &GetStaticObjectField, &GetStaticBooleanField, &GetStaticByteField, &GetStaticCharField, &GetStaticShortField,
01602     &GetStaticIntField, &GetStaticLongField, &GetStaticFloatField, &GetStaticDoubleField,
01603 
01604     // void (JNICALL *SetStaticObjectField) (JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value);
01605     // void (JNICALL *SetStaticBooleanField) (JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value);
01606     // void (JNICALL *SetStaticByteField) (JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value);
01607     // void (JNICALL *SetStaticCharField) (JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value);
01608     // void (JNICALL *SetStaticShortField) (JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value);
01609     // void (JNICALL *SetStaticIntField) (JNIEnv *env, jclass clazz, jfieldID fieldID, jint value);
01610     // void (JNICALL *SetStaticLongField) (JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value);
01611     // void (JNICALL *SetStaticFloatField) (JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value);
01612     // void (JNICALL *SetStaticDoubleField) (JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value);
01613     &SetStaticObjectField, &SetStaticBooleanField, &SetStaticByteField, &SetStaticCharField, &SetStaticShortField,
01614     &SetStaticIntField, &SetStaticLongField, &SetStaticFloatField, &SetStaticDoubleField,
01615 
01616     // jstring (JNICALL *NewString) (JNIEnv *env, const jchar *unicode, jsize len);
01617     // jsize (JNICALL *GetStringLength) (JNIEnv *env, jstring str);
01618     // const jchar *(JNICALL *GetStringChars) (JNIEnv *env, jstring str, jboolean *isCopy);
01619     // void (JNICALL *ReleaseStringChars) (JNIEnv *env, jstring str, const jchar *chars);
01620     &NewString, &GetStringLength, &GetStringChars, &ReleaseStringChars,
01621 
01622     // jstring (JNICALL *NewStringUTF) (JNIEnv *env, const char *utf);
01623     // jsize (JNICALL *GetStringUTFLength) (JNIEnv *env, jstring str);
01624     // const char* (JNICALL *GetStringUTFChars) (JNIEnv *env, jstring str, jboolean *isCopy);
01625     // void (JNICALL *ReleaseStringUTFChars) (JNIEnv *env, jstring str, const char* chars);
01626     &NewStringUTF, &GetStringUTFLength, &GetStringUTFChars, &ReleaseStringUTFChars,
01627 
01628     // jsize (JNICALL *GetArrayLength) (JNIEnv *env, jarray array);
01629     &GetArrayLength,
01630 
01631     // jobjectArray (JNICALL *NewObjectArray) (JNIEnv *env, jsize len, jclass clazz, jobject init);
01632     // jobject (JNICALL *GetObjectArrayElement) (JNIEnv *env, jobjectArray array, jsize index);
01633     // void (JNICALL *SetObjectArrayElement) (JNIEnv *env, jobjectArray array, jsize index, jobject val);
01634     &NewObjectArray, &GetObjectArrayElement, &SetObjectArrayElement,
01635 
01636     // jbooleanArray (JNICALL *NewBooleanArray) (JNIEnv *env, jsize len);
01637     // jbyteArray (JNICALL *NewByteArray) (JNIEnv *env, jsize len);
01638     // jcharArray (JNICALL *NewCharArray) (JNIEnv *env, jsize len);
01639     // jshortArray (JNICALL *NewShortArray) (JNIEnv *env, jsize len);
01640     // jintArray (JNICALL *NewIntArray) (JNIEnv *env, jsize len);
01641     // jlongArray (JNICALL *NewLongArray) (JNIEnv *env, jsize len);
01642     // jfloatArray (JNICALL *NewFloatArray) (JNIEnv *env, jsize len);
01643     // jdoubleArray (JNICALL *NewDoubleArray) (JNIEnv *env, jsize len);
01644     &NewBooleanArray, &NewByteArray, &NewCharArray, &NewShortArray, 
01645     &NewIntArray, &NewLongArray, &NewFloatArray, &NewDoubleArray,
01646 
01647     // jboolean * (JNICALL *GetBooleanArrayElements) (JNIEnv *env, jbooleanArray array, jboolean *isCopy);
01648     // jbyte * (JNICALL *GetByteArrayElements) (JNIEnv *env, jbyteArray array, jboolean *isCopy);
01649     // jchar * (JNICALL *GetCharArrayElements) (JNIEnv *env, jcharArray array, jboolean *isCopy);
01650     // jshort * (JNICALL *GetShortArrayElements) (JNIEnv *env, jshortArray array, jboolean *isCopy);
01651     // jint * (JNICALL *GetIntArrayElements) (JNIEnv *env, jintArray array, jboolean *isCopy);
01652     // jlong * (JNICALL *GetLongArrayElements) (JNIEnv *env, jlongArray array, jboolean *isCopy);
01653     // jfloat * (JNICALL *GetFloatArrayElements) (JNIEnv *env, jfloatArray array, jboolean *isCopy);
01654     // jdouble * (JNICALL *GetDoubleArrayElements) (JNIEnv *env, jdoubleArray array, jboolean *isCopy);
01655     &GetBooleanArrayElements, &GetByteArrayElements, &GetCharArrayElements, &GetShortArrayElements, 
01656     &GetIntArrayElements, &GetLongArrayElements, &GetFloatArrayElements, &GetDoubleArrayElements, 
01657 
01658     // void (JNICALL *ReleaseBooleanArrayElements)(JNIEnv *env, jbooleanArray array, jboolean *elems, jint mode);
01659     // void (JNICALL *ReleaseByteArrayElements) (JNIEnv *env, jbyteArray array, jbyte *elems, jint mode);
01660     // void (JNICALL *ReleaseCharArrayElements) (JNIEnv *env, jcharArray array, jchar *elems, jint mode);
01661     // void (JNICALL *ReleaseShortArrayElements) (JNIEnv *env, jshortArray array, jshort *elems, jint mode);
01662     // void (JNICALL *ReleaseIntArrayElements) (JNIEnv *env, jintArray array, jint *elems, jint mode);
01663     // void (JNICALL *ReleaseLongArrayElements) (JNIEnv *env, jlongArray array, jlong *elems, jint mode);
01664     // void (JNICALL *ReleaseFloatArrayElements) (JNIEnv *env, jfloatArray array, jfloat *elems, jint mode);
01665     // void (JNICALL *ReleaseDoubleArrayElements) (JNIEnv *env, jdoubleArray array, jdouble *elems, jint mode);
01666     &ReleaseBooleanArrayElements, &ReleaseByteArrayElements, &ReleaseCharArrayElements, &ReleaseShortArrayElements, 
01667     &ReleaseIntArrayElements, &ReleaseLongArrayElements, &ReleaseFloatArrayElements, &ReleaseDoubleArrayElements, 
01668 
01669     // void (JNICALL *GetBooleanArrayRegion) (JNIEnv *env, jbooleanArray array, jsize start, jsize l, jboolean *buf);
01670     // void (JNICALL *GetByteArrayRegion) (JNIEnv *env, jbyteArray array, jsize start, jsize len, jbyte *buf);
01671     // void (JNICALL *GetCharArrayRegion) (JNIEnv *env, jcharArray array, jsize start, jsize len, jchar *buf);
01672     // void (JNICALL *GetShortArrayRegion) (JNIEnv *env, jshortArray array, jsize start, jsize len, jshort *buf);
01673     // void (JNICALL *GetIntArrayRegion) (JNIEnv *env, jintArray array, jsize start, jsize len, jint *buf);
01674     // void (JNICALL *GetLongArrayRegion) (JNIEnv *env, jlongArray array, jsize start, jsize len, jlong *buf);
01675     // void (JNICALL *GetFloatArrayRegion) (JNIEnv *env, jfloatArray array, jsize start, jsize len, jfloat *buf);
01676     // void (JNICALL *GetDoubleArrayRegion) (JNIEnv *env, jdoubleArray array, jsize start, jsize len, jdouble *buf);
01677     &GetBooleanArrayRegion, &GetByteArrayRegion, &GetCharArrayRegion, &GetShortArrayRegion, 
01678     &GetIntArrayRegion, &GetLongArrayRegion, &GetFloatArrayRegion, &GetDoubleArrayRegion, 
01679 
01680     // void (JNICALL *SetBooleanArrayRegion) (JNIEnv *env, jbooleanArray array, jsize start, jsize l, jboolean *buf);
01681     // void (JNICALL *SetByteArrayRegion) (JNIEnv *env, jbyteArray array, jsize start, jsize len, jbyte *buf);
01682     // void (JNICALL *SetCharArrayRegion) (JNIEnv *env, jcharArray array, jsize start, jsize len, jchar *buf);
01683     // void (JNICALL *SetShortArrayRegion) (JNIEnv *env, jshortArray array, jsize start, jsize len, jshort *buf);
01684     // void (JNICALL *SetIntArrayRegion) (JNIEnv *env, jintArray array, jsize start, jsize len, jint *buf);
01685     // void (JNICALL *SetLongArrayRegion) (JNIEnv *env, jlongArray array, jsize start, jsize len, jlong *buf);
01686     // void (JNICALL *SetFloatArrayRegion) (JNIEnv *env, jfloatArray array, jsize start, jsize len, jfloat *buf);
01687     // void (JNICALL *SetDoubleArrayRegion) (JNIEnv *env, jdoubleArray array, jsize start, jsize len, jdouble *buf);
01688     &SetBooleanArrayRegion, &SetByteArrayRegion, &SetCharArrayRegion, &SetShortArrayRegion, 
01689     &SetIntArrayRegion, &SetLongArrayRegion, &SetFloatArrayRegion, &SetDoubleArrayRegion, 
01690 
01691     // jint (JNICALL *RegisterNatives) (JNIEnv *env, jclass clazz, const JNINativeMethod *methods, jint nMethods);
01692     // jint (JNICALL *UnregisterNatives) (JNIEnv *env, jclass clazz);
01693     &RegisterNatives, &UnregisterNatives,
01694 
01695     // jint (JNICALL *MonitorEnter) (JNIEnv *env, jobject obj);
01696     // jint (JNICALL *MonitorExit) (JNIEnv *env, jobject obj);
01697     &MonitorEnter, &MonitorExit,
01698 
01699     // jint (JNICALL *GetJavaVM) (JNIEnv *env, JavaVM **vm);
01700     &GetJavaVM
01701 };
01702 
01703 nsDataHashtable<JavaClassMemberKey, void*>* ProxyJNIEnv::theIDTable = NULL;
01704 
01705 ProxyJNIEnv::ProxyJNIEnv(nsIJVMPlugin* jvmPlugin, nsISecureEnv* secureEnv)
01706     :   mSecureEnv(secureEnv), mContext(NULL), mInProxyFindClass(JNI_FALSE)
01707 {
01708     this->functions = &theFuncs;
01709     if (theIDTable == NULL) {
01710         theIDTable = new nsDataHashtable<JavaClassMemberKey, void*>;
01711         if (theIDTable) {
01712             if (!theIDTable->Init(16)) {
01713                 delete theIDTable;
01714                 theIDTable = NULL;
01715                 NS_WARNING("theIDTable initialization FAILED");
01716             }
01717         }
01718         else {
01719             NS_WARNING("theIDTable allocation FAILED");
01720         }
01721     }
01722     
01723     // Ask the JVM for a new nsISecureEnv, if none provided.
01724     if (secureEnv == NULL) {
01725         nsresult rv = jvmPlugin->CreateSecureEnv(this, &mSecureEnv);
01726 #ifdef DEBUG
01727         if (NS_FAILED(rv))
01728             NS_WARNING("CreateSecureEnv FAILED");
01729         else
01730             NS_WARNING("CreateSecureEnv OK");
01731 #endif
01732     }
01733 }
01734 
01735 ProxyJNIEnv::~ProxyJNIEnv()
01736 {
01737     this->functions = NULL;
01738     
01739     if (mSecureEnv != NULL)
01740         mSecureEnv->Release();
01741 }
01742 
01743 JNIEnv* CreateProxyJNI(nsIJVMPlugin* jvmPlugin, nsISecureEnv* inSecureEnv)
01744 {
01745     ProxyJNIEnv* proxyEnv = new ProxyJNIEnv(jvmPlugin, inSecureEnv);
01746     if (proxyEnv->getSecureEnv() == NULL) {
01747         delete proxyEnv;
01748         return NULL;
01749     }
01750     return proxyEnv;
01751 }
01752 
01753 void DeleteProxyJNI(JNIEnv* env)
01754 {
01755     ProxyJNIEnv* proxyEnv = (ProxyJNIEnv*)env;
01756     if (proxyEnv != NULL)
01757         delete proxyEnv;
01758 }
01759 
01760 nsISecureEnv* GetSecureEnv(JNIEnv* env)
01761 {
01762     ProxyJNIEnv* proxyEnv = (ProxyJNIEnv*)env;
01763     return proxyEnv->getSecureEnv();
01764 }
01765 
01766 PR_IMPLEMENT(void) SetSecurityContext(JNIEnv* env, nsISecurityContext *context) {
01767     ProxyJNIEnv* proxyEnv = (ProxyJNIEnv*)env;
01768     proxyEnv->SetSecurityContext(context);
01769 }
01770 
01771 PR_IMPLEMENT(nsresult) GetSecurityContext(JNIEnv* env, nsISecurityContext **context) {
01772     ProxyJNIEnv* proxyEnv = (ProxyJNIEnv*)env;
01773     return proxyEnv->GetSecurityContext(context);
01774 }