Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
lcglue.cpp File Reference
#include "prthread.h"
#include "nsJVMManager.h"
#include "nsIPluginInstancePeer2.h"
#include "ProxyJNI.h"
#include "lcglue.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsISecurityContext.h"
#include "nsCSecurityContext.h"
#include "nsCRT.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptObjectPrincipal.h"
#include "nsIServiceManager.h"
#include "nsIScriptSecurityManager.h"
#include "nsNetUtil.h"
#include "jscntxt.h"

Go to the source code of this file.

Classes

class  ThreadLocalStorage< T >
 Template based Thread Local Storage. More...

Functions

static NS_DEFINE_CID (kJVMManagerCID, NS_JVMMANAGER_CID)
static void PR_CALLBACK detach_JVMContext (void *storage)
JVMContextGetJVMContext ()
JS_BEGIN_EXTERN_C map_jsj_thread_to_js_context_impl (JSJavaThreadState *jsj_env, void *java_applet_obj, JNIEnv *env, char **errp)
 map_js_context_to_jsj_thread_impl (JSContext *cx, char **errp)
 map_java_object_to_js_object_impl (JNIEnv *env, void *pluginInstancePtr, char **errp)
 get_JSPrincipals_from_java_caller_impl (JNIEnv *pJNIEnv, JSContext *pJSContext, void **ppNSIPrincipalArrayIN, int numPrincipals, void *pNSISecurityContext)
 get_java_wrapper_impl (JNIEnv *pJNIEnv, lcjsobject a_jsobject)
 unwrap_java_wrapper_impl (JNIEnv *pJNIEnv, jobject java_wrapper)
 enter_js_from_java_impl (JNIEnv *jEnv, char **errp, void **pNSIPrincipaArray, int numPrincipals, void *pNSISecurityContext, void *java_applet_obj)
 exit_js_impl (JNIEnv *jEnv, JSContext *cx)
 create_java_vm_impl (SystemJavaVM **jvm, JNIEnv **initialEnv, void *initargs)
 destroy_java_vm_impl (SystemJavaVM *jvm, JNIEnv *initialEnv)
 attach_current_thread_impl (SystemJavaVM *jvm)
 detach_current_thread_impl (SystemJavaVM *jvm, JNIEnv *env)
 get_java_vm_impl (JNIEnv *env)
void JVM_InitLCGlue (void)

Variables

int XP_PROGRESS_STARTING_JAVA
int XP_PROGRESS_STARTING_JAVA_DONE
int XP_JAVA_NO_CLASSES
int XP_JAVA_GENERAL_FAILURE
int XP_JAVA_STARTUP_FAILED
int XP_JAVA_DEBUGGER_FAILED
static JS_END_EXTERN_C JSJCallbacks jsj_callbacks

Function Documentation

Definition at line 361 of file lcglue.cpp.

{
    return JVM_GetJNIEnv();
}

Here is the call graph for this function:

create_java_vm_impl ( SystemJavaVM **  jvm,
JNIEnv **  initialEnv,
void initargs 
)

Definition at line 337 of file lcglue.cpp.

{
    // const char* classpath = (const char*)initargs;
    nsCOMPtr<nsIJVMManager> serv = do_GetService(kJVMManagerCID);
    if (!serv)
        return PR_FALSE;
    *initialEnv = JVM_GetJNIEnv();
    if (!*initialEnv)
        return PR_FALSE;
    // serv will be released when this function returns, but that's OK because
    // the XPCOM service manager will keep it alive.
    *jvm = NS_REINTERPRET_CAST(SystemJavaVM*, serv.get());
    return PR_TRUE;
}

Here is the call graph for this function:

destroy_java_vm_impl ( SystemJavaVM jvm,
JNIEnv initialEnv 
)

Definition at line 353 of file lcglue.cpp.

{
    JVM_ReleaseJNIEnv(initialEnv);
    // need to release jvm
    return PR_TRUE;
}

Here is the call graph for this function:

Definition at line 367 of file lcglue.cpp.

{
    JVM_ReleaseJNIEnv(env);
    return PR_TRUE;
}

Here is the call graph for this function:

static void PR_CALLBACK detach_JVMContext ( void storage) [static]

Definition at line 91 of file lcglue.cpp.

{
       JVMContext* context = NS_REINTERPRET_CAST(JVMContext*, storage);
       
       JNIEnv* proxyEnv = context->proxyEnv;
       if (proxyEnv != NULL) {
              DeleteProxyJNI(proxyEnv);
              context->proxyEnv = NULL;
       }
       
       delete context;
}

Here is the call graph for this function:

Here is the caller graph for this function:

enter_js_from_java_impl ( JNIEnv jEnv,
char **  errp,
void **  pNSIPrincipaArray,
int  numPrincipals,
void pNSISecurityContext,
void java_applet_obj 
)

Definition at line 312 of file lcglue.cpp.

{
       return PR_TRUE;
}
exit_js_impl ( JNIEnv jEnv,
JSContext cx 
)

Definition at line 321 of file lcglue.cpp.

{
    // The main idea is to execute terminate function if have any;
    if (cx)
    {
        nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);

        if (scriptContext)
        {
            scriptContext->ScriptEvaluated(PR_TRUE);
        }
    }
    return;
}

Here is the call graph for this function:

Definition at line 374 of file lcglue.cpp.

{
    // only one SystemJavaVM for the whole browser, so it doesn't depend on env
    nsresult rv;
    nsCOMPtr<nsIJVMManager> managerService = do_GetService(kJVMManagerCID, &rv);
    if (NS_FAILED(rv)) return NULL;
    SystemJavaVM* jvm = NS_REINTERPRET_CAST(SystemJavaVM*, managerService.get());  
    return jvm;
}

Here is the call graph for this function:

get_java_wrapper_impl ( JNIEnv pJNIEnv,
lcjsobject  a_jsobject 
)

Definition at line 270 of file lcglue.cpp.

{
    nsresult       err    = NS_OK;
    jobject  pJSObjectWrapper = NULL;
    nsCOMPtr<nsIJVMManager> managerService = do_GetService(kJVMManagerCID, &err);
    if (NS_FAILED(err)) return NULL;
    nsJVMManager* pJVMMgr = (nsJVMManager *)managerService.get();  
    if (pJVMMgr != NULL) {
      nsIJVMPlugin* pJVMPI = pJVMMgr->GetJVMPlugin();
      if (pJVMPI != NULL) {
         err = pJVMPI->GetJavaWrapper(pJNIEnv, a_jsobject, &pJSObjectWrapper);
      }
    }
    if ( err != NS_OK )
    {
       return NULL;
    }
    return pJSObjectWrapper;
}

Here is the call graph for this function:

get_JSPrincipals_from_java_caller_impl ( JNIEnv pJNIEnv,
JSContext pJSContext,
void **  ppNSIPrincipalArrayIN,
int  numPrincipals,
void pNSISecurityContext 
)

Definition at line 250 of file lcglue.cpp.

{
    nsresult rv;
    nsCOMPtr<nsIScriptSecurityManager> secMan = 
        do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
    if (NS_FAILED(rv))
        return NULL;

    nsCOMPtr<nsIPrincipal> principal;
    rv = secMan->GetPrincipalFromContext(pJSContext,
                                         getter_AddRefs(principal));
    if (NS_FAILED(rv))
        return NULL;

    JSPrincipals* jsprincipals = NULL;
    principal->GetJSPrincipals(pJSContext, &jsprincipals);
    return jsprincipals;
}

Here is the call graph for this function:

Definition at line 104 of file lcglue.cpp.

{
       /* Use NSPR thread private data to manage the per-thread JNIEnv* association. */
       static ThreadLocalStorage<JVMContext*> localContext((PRThreadPrivateDTOR)&detach_JVMContext);
       JVMContext* context = localContext.get();
       if (context == NULL) {
              context = new JVMContext;
              context->proxyEnv = NULL;
              context->jsj_env = NULL;
              localContext.set(context);
       }
       return context;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 404 of file lcglue.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

map_java_object_to_js_object_impl ( JNIEnv env,
void pluginInstancePtr,
char **  errp 
)

Definition at line 197 of file lcglue.cpp.

{
       JSObject        *window = NULL;
       PRBool           mayscript = PR_FALSE;
       PRBool           jvmMochaPrefsEnabled = PR_TRUE;
       nsresult         err = NS_OK;

       *errp = NULL;

       if (pluginInstancePtr == NULL) {
              env->ThrowNew(env->FindClass("java/lang/NullPointerException"), "plugin instance is NULL");
              return NULL;
       }

       //TODO: Check if Mocha is enabled. To get to any mocha api, we should use service 
       //      manager and get to the appropriate service.
       // jvmMochaPrefsEnabled = LM_GetMochaEnabled();
       if (!jvmMochaPrefsEnabled) {
              *errp = strdup("JSObject.getWindow() failed: java preference is disabled");
              return NULL;
       }

       /*
        * Check for the mayscript tag.
        */
       nsIPluginInstance* pluginInstance = NS_REINTERPRET_CAST(nsIPluginInstance*, pluginInstancePtr);
       nsIPluginInstancePeer* pluginPeer;
       if (pluginInstance->GetPeer(&pluginPeer) == NS_OK) {
              nsIJVMPluginTagInfo* tagInfo;
              if (pluginPeer->QueryInterface(NS_GET_IID(nsIJVMPluginTagInfo), (void**) &tagInfo) == NS_OK) {
                     err = tagInfo->GetMayScript(&mayscript);
                     // PR_ASSERT(err != NS_OK ? mayscript == PR_FALSE : PR_TRUE);
                     NS_RELEASE(tagInfo);
              }
              if ( !mayscript ) {
                     *errp = strdup("JSObject.getWindow() requires mayscript attribute on this Applet");
              } else {
                     nsIPluginInstancePeer2* pluginPeer2 = nsnull;
                     if (pluginPeer->QueryInterface(NS_GET_IID(nsIPluginInstancePeer2),
                                                   (void**) &pluginPeer2) == NS_OK) {
                            err = pluginPeer2->GetJSWindow(&window);
                            NS_RELEASE(pluginPeer2);
                     }
              }
              NS_RELEASE(pluginPeer);
       }

       //TODO: Get to the window object using DOM.
       // window = getDOMWindow().getScriptOwner().getJSObject().
       return window;
}

Here is the call graph for this function:

map_js_context_to_jsj_thread_impl ( JSContext cx,
char **  errp 
)

Definition at line 155 of file lcglue.cpp.

{
       *errp = NULL;

    // FIXME:  how do we ever break the association between the jsj_env and the
    // JVMContext? This needs to be figured out. Otherwise, we'll end up with the
    // same dangling JSContext problem we are trying to weed out.

       JVMContext* context = GetJVMContext();
       JSJavaThreadState* jsj_env = context->jsj_env;
       if (jsj_env != NULL)
              return jsj_env;

       JSJavaVM* js_jvm = NULL;
       nsresult rv;
       nsCOMPtr<nsIJVMManager> managerService = do_GetService(kJVMManagerCID, &rv);
       if (NS_FAILED(rv)) return NULL;
       nsJVMManager* pJVMMgr = (nsJVMManager*) managerService.get();  
       if (pJVMMgr != NULL) {
              js_jvm = pJVMMgr->GetJSJavaVM();
              if (js_jvm == NULL) {
                     *errp = strdup("Failed to attach to a Java VM.");
                     return NULL;
              }
       }

       jsj_env = JSJ_AttachCurrentThreadToJava(js_jvm, NULL, NULL);
       context->jsj_env = jsj_env;

       return jsj_env;
}

Here is the call graph for this function:

JS_BEGIN_EXTERN_C map_jsj_thread_to_js_context_impl ( JSJavaThreadState jsj_env,
void java_applet_obj,
JNIEnv env,
char **  errp 
)

Definition at line 127 of file lcglue.cpp.

{
       // Guess what? This design is totally invalid under Gecko, because there isn't a 1 to 1 mapping
       // between NSPR threads and JSContexts. We have to ask the plugin instance peer what JSContext
       // it lives in to make any sense of all this.
       JSContext* context = NULL;
       if (java_applet_obj != NULL) {
              nsIPluginInstance* pluginInstance = NS_REINTERPRET_CAST(nsIPluginInstance*, java_applet_obj);
               nsIPluginInstancePeer* pluginPeer = NULL;
              if (pluginInstance->GetPeer(&pluginPeer) == NS_OK) {
                     nsIPluginInstancePeer2* pluginPeer2 = NULL;
                     if (pluginPeer->QueryInterface(NS_GET_IID(nsIPluginInstancePeer2), (void**) &pluginPeer2) == NS_OK) {
                            pluginPeer2->GetJSContext(&context);
                            NS_RELEASE(pluginPeer2);
                     }
                     NS_RELEASE(pluginPeer);
              }
       }
       return context;
}
static NS_DEFINE_CID ( kJVMManagerCID  ,
NS_JVMMANAGER_CID   
) [static]
unwrap_java_wrapper_impl ( JNIEnv pJNIEnv,
jobject  java_wrapper 
)

Definition at line 291 of file lcglue.cpp.

{
    lcjsobject obj = 0;
    nsresult       err    = NS_OK;
    nsCOMPtr<nsIJVMManager> managerService = do_GetService(kJVMManagerCID, &err);
    if (NS_FAILED(err)) return 0;
    nsJVMManager* pJVMMgr = (nsJVMManager *)managerService.get();  
    if (pJVMMgr != NULL) {
      nsIJVMPlugin* pJVMPI = pJVMMgr->GetJVMPlugin();
      if (pJVMPI != NULL) {
         err = pJVMPI->UnwrapJavaWrapper(pJNIEnv, java_wrapper, &obj);
      }
    }
    if ( err != NS_OK )
    {
       return 0;
    }
    return obj;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 62 of file lcglue.cpp.

Definition at line 60 of file lcglue.cpp.

Definition at line 59 of file lcglue.cpp.

Definition at line 61 of file lcglue.cpp.

Definition at line 57 of file lcglue.cpp.

Definition at line 58 of file lcglue.cpp.