Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
LiveConnectNativeMethods.cpp File Reference
#include <memory>
#include "LiveConnectNativeMethods.h"
#include "nsIComponentManagerObsolete.h"
#include "nsIPluginManager.h"
#include "nsIJVMManager.h"
#include "nsILiveconnect.h"
#include "nsIPluginInstancePeer2.h"
#include "MRJPlugin.h"
#include "MRJContext.h"
#include "MRJSession.h"
#include "MRJSecurityContext.h"
#include "CSecureEnv.h"
#include "JavaMessageQueue.h"
#include "MRJMonitor.h"
#include "NativeMonitor.h"
#include "RunnableMixin.h"
#include "StringUtils.h"
#include "netscape_javascript_JSObject.h"

Go to the source code of this file.

Classes

class  MessageRunnable
 Wraps a JavaMessage in an nsIRunnable form, so that it runs on the correct native thread. More...
class  GetMemberMessage
class  GetSlotMessage
class  SetMemberMessage
class  SetSlotMessage
class  RemoveMemberMessage
class  CallMessage
class  EvalMessage
class  ToStringMessage
class  GetWindowMessage
class  FinalizeMessage

Functions

static NS_DEFINE_IID (kLiveConnectCID, NS_CLIVECONNECT_CID)
static NS_DEFINE_IID (kComponentManagerCID, NS_COMPONENTMANAGER_CID)
static nsresult getGlobalComponentManager (nsIComponentManagerObsolete **result)
nsresult InitLiveConnectSupport (MRJPlugin *jvmPlugin)
nsresult ShutdownLiveConnectSupport ()
jobject Wrap_JSObject (JNIEnv *env, jsobject js_obj)
jsobject Unwrap_JSObject (JNIEnv *env, jobject java_wrapper_obj)
static jobject NewLocalRef (JNIEnv *env, jobject global_ref)
static jobject ToGlobalRef (JNIEnv *env, jobject localRef)
static jobject ToLocalRef (JNIEnv *env, jobject globalRef)
static jobject GetCurrentThread (JNIEnv *env)
static MRJSecurityContextgetSecurityContext (MRJPluginInstance *pluginInstance)
nsILiveconnectgetLiveconnectInstance (MRJSecurityContext *securityContext)
static jobject GetCurrentClassLoader (JNIEnv *env)
static jobject GetObjectClassLoader (JNIEnv *env, jobject object)
static MRJPluginInstanceGetCurrentInstance (JNIEnv *env)
 Maps the given JNIEnv to a given plugin instance by comparing the current class loader with the class loader of the applet of each plugin instance.
static MRJPluginInstanceGetCurrentInstance (JNIEnv *env, jobject applet)
 Maps the given applet to a given plugin instance by walking the PluginInstance list looking for an instance which contains the current applet.
static PRUint32 getJavaScriptThread (JNIEnv *env)
static void sendMessage (JNIEnv *env, JavaMessage *msg)
 Sends a message by rendezvousing with an existing JavaScript thread, or creates a new one if none exists for this thread already.
static nsIPrincipalnewCodebasePrincipal (const char *codebaseURL)
JNIEXPORT jobject JNICALL Java_netscape_javascript_JSObject_getMember (JNIEnv *env, jobject java_wrapper_obj, jstring property_name_jstr)
JNIEXPORT jobject JNICALL Java_netscape_javascript_JSObject_getSlot (JNIEnv *env, jobject java_wrapper_obj, jint slot)
JNIEXPORT void JNICALL Java_netscape_javascript_JSObject_setMember (JNIEnv *env, jobject java_wrapper_obj, jstring property_name_jstr, jobject java_obj)
JNIEXPORT void JNICALL Java_netscape_javascript_JSObject_setSlot (JNIEnv *env, jobject java_wrapper_obj, jint slot, jobject java_obj)
JNIEXPORT void JNICALL Java_netscape_javascript_JSObject_removeMember (JNIEnv *env, jobject java_wrapper_obj, jstring property_name_jstr)
JNIEXPORT jobject JNICALL Java_netscape_javascript_JSObject_call (JNIEnv *env, jobject java_wrapper_obj, jstring function_name_jstr, jobjectArray java_args)
JNIEXPORT jobject JNICALL Java_netscape_javascript_JSObject_eval (JNIEnv *env, jobject java_wrapper_obj, jstring script_jstr)
JNIEXPORT jstring JNICALL Java_netscape_javascript_JSObject_toString (JNIEnv *env, jobject java_wrapper_obj)
JNIEXPORT jobject JNICALL Java_netscape_javascript_JSObject_getWindow (JNIEnv *env, jclass js_object_class, jobject java_applet_obj)
JNIEXPORT void JNICALL Java_netscape_javascript_JSObject_finalize (JNIEnv *env, jobject java_wrapper_obj)

Variables

nsIPluginManagerthePluginManager
static MRJPlugintheJVMPlugin = NULL
static nsILiveconnecttheLiveConnectManager = NULL
static
nsIComponentManagerObsolete
theComponentManager = NULL
static jclass netscape_javascript_JSObject = NULL
static jmethodID netscape_javascript_JSObject_JSObject
static jfieldID netscape_javascript_JSObject_internal
static jclass netscape_oji_JNIUtils = NULL
static jmethodID netscape_oji_JNIUtils_NewLocalRef = NULL
static jmethodID netscape_oji_JNIUtils_GetCurrentThread = NULL
static jmethodID netscape_oji_JNIUtils_GetCurrentClassLoader = NULL
static jmethodID netscape_oji_JNIUtils_GetObjectClassLoader = NULL

Function Documentation

static jobject GetCurrentClassLoader ( JNIEnv env) [static]

Definition at line 287 of file LiveConnectNativeMethods.cpp.

Here is the caller graph for this function:

static MRJPluginInstance* GetCurrentInstance ( JNIEnv env) [static]

Maps the given JNIEnv to a given plugin instance by comparing the current class loader with the class loader of the applet of each plugin instance.

This could be made faster, but it's probably good enough. Note: the reference count of the plugin instance isn't affected by this call.

Definition at line 303 of file LiveConnectNativeMethods.cpp.

{
    MRJPluginInstance* pluginInstance = NULL;
    jobject classLoader = GetCurrentClassLoader(env);
    if (classLoader != NULL) {
        pluginInstance = MRJPluginInstance::getInstances();
        while (pluginInstance != NULL) {
            jobject applet;
            pluginInstance->GetJavaObject(&applet);
            jobject appletClassLoader = GetObjectClassLoader(env, applet);
            jboolean sameClassLoader = env->IsSameObject(appletClassLoader, classLoader);
            env->DeleteLocalRef(appletClassLoader);
            if (sameClassLoader)
                break;
            pluginInstance = pluginInstance->getNextInstance();
        }
        env->DeleteLocalRef(classLoader);
    }
    return pluginInstance;
}

Here is the call graph for this function:

static MRJPluginInstance* GetCurrentInstance ( JNIEnv env,
jobject  applet 
) [static]

Maps the given applet to a given plugin instance by walking the PluginInstance list looking for an instance which contains the current applet.

Note: the reference count of the plugin instance isn't affected by this call.

Definition at line 329 of file LiveConnectNativeMethods.cpp.

{
    MRJPluginInstance* pluginInstance = MRJPluginInstance::getInstances();
    while (pluginInstance != NULL) {
        jobject object = NULL;
        if (pluginInstance->GetJavaObject(&object) == NS_OK && env->IsSameObject(applet, object)) {
            return pluginInstance;
        }
        pluginInstance = pluginInstance->getNextInstance();
    }
    return NULL;
}

Here is the call graph for this function:

static jobject GetCurrentThread ( JNIEnv env) [static]

Definition at line 199 of file LiveConnectNativeMethods.cpp.

Here is the caller graph for this function:

Definition at line 84 of file LiveConnectNativeMethods.cpp.

{
    return MRJPlugin::GetService(kComponentManagerCID, NS_GET_IID(nsIComponentManagerObsolete), (void**)result);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRUint32 getJavaScriptThread ( JNIEnv env) [static]

Definition at line 386 of file LiveConnectNativeMethods.cpp.

{
    PRUint32 threadID = 0;
    MRJPluginInstance* pluginInstance = GetCurrentInstance(env);
    if (pluginInstance != NULL) {
        nsIPluginInstancePeer* peer;
        if (pluginInstance->GetPeer(&peer) == NS_OK) {
            nsIPluginInstancePeer2* peer2 = NULL;
            if (peer->QueryInterface(NS_GET_IID(nsIPluginInstancePeer2), (void**)&peer2) == NS_OK) {
                if (peer2->GetJSThread(&threadID) != NS_OK)
                    threadID = 0;
                NS_RELEASE(peer2);
            }
            NS_RELEASE(peer);
        }
    }
    return threadID;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsILiveconnect* getLiveconnectInstance ( MRJSecurityContext securityContext) [inline]

Definition at line 282 of file LiveConnectNativeMethods.cpp.

{
    return (securityContext ? securityContext->getConnection() : theLiveConnectManager);
}

Here is the call graph for this function:

static jobject GetObjectClassLoader ( JNIEnv env,
jobject  object 
) [static]

Definition at line 292 of file LiveConnectNativeMethods.cpp.

Here is the caller graph for this function:

static MRJSecurityContext* getSecurityContext ( MRJPluginInstance pluginInstance) [static]

Definition at line 268 of file LiveConnectNativeMethods.cpp.

{
    if (pluginInstance != NULL) {
        MRJContext* context = pluginInstance->getContext();
        MRJSecurityContext* securityContext = context->getSecurityContext();
        if (securityContext == NULL) {
            securityContext = new MRJSecurityContext(context->getDocumentBase());
            context->setSecurityContext(securityContext);
        }
        return securityContext;
    }
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 89 of file LiveConnectNativeMethods.cpp.

{
    theJVMPlugin = jvmPlugin;

    getGlobalComponentManager(&theComponentManager);

    nsresult result = MRJPlugin::GetService(kLiveConnectCID, NS_GET_IID(nsILiveconnect),
                                            (void**)&theLiveConnectManager);
    if (result != NS_OK)
        return result;
    
    // Manually load the required native methods.
    static JNINativeMethod nativeMethods[] = {
        "getMember", "(Ljava/lang/String;)Ljava/lang/Object;", (void*)&Java_netscape_javascript_JSObject_getMember,
        "getSlot", "(I)Ljava/lang/Object;", (void*)&Java_netscape_javascript_JSObject_getSlot,
        "setMember", "(Ljava/lang/String;Ljava/lang/Object;)V", (void*)&Java_netscape_javascript_JSObject_setMember,
        "setSlot", "(ILjava/lang/Object;)V", (void*)&Java_netscape_javascript_JSObject_setSlot,
        "removeMember", "(Ljava/lang/String;)V", (void*)&Java_netscape_javascript_JSObject_removeMember,
        "call", "(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/Object;", (void*)&Java_netscape_javascript_JSObject_call,
        "eval", "(Ljava/lang/String;)Ljava/lang/Object;", (void*)&Java_netscape_javascript_JSObject_eval,
        "toString", "()Ljava/lang/String;", (void*)&Java_netscape_javascript_JSObject_toString,
        "getWindow", "(Ljava/applet/Applet;)Lnetscape/javascript/JSObject;", (void*)&Java_netscape_javascript_JSObject_getWindow,
        "finalize", "()V", (void*)&Java_netscape_javascript_JSObject_finalize,
    };
    
    MRJSession* session = jvmPlugin->getSession();
    JNIEnv* env = session->getCurrentEnv();
    if (env != NULL) {
        jclass classJSObject = env->FindClass("netscape/javascript/JSObject");
        if (classJSObject != NULL) {
            // register LiveConnect native methods.
            netscape_javascript_JSObject = (jclass) env->NewGlobalRef(classJSObject);
            env->DeleteLocalRef(classJSObject);
            
            netscape_javascript_JSObject_JSObject = env->GetMethodID(netscape_javascript_JSObject, "<init>", "(I)V");
            if (env->ExceptionCheck()) {
                env->ExceptionClear();
                result = NS_ERROR_FAILURE;
            }

            netscape_javascript_JSObject_internal = env->GetFieldID(netscape_javascript_JSObject, "internal", "I");
            if (env->ExceptionCheck()) {
                env->ExceptionClear();
                result = NS_ERROR_FAILURE;
            }

            env->RegisterNatives(netscape_javascript_JSObject, nativeMethods, sizeof(nativeMethods) / sizeof(JNINativeMethod));
            if (env->ExceptionCheck()) {
                env->ExceptionClear();
                result = NS_ERROR_FAILURE;
            }
        }
        
        // load netscape.oji.JNIUtils class.
        jclass classJNIUtils = env->FindClass("netscape/oji/JNIUtils");
        if (classJNIUtils != NULL) {
            netscape_oji_JNIUtils = (jclass) env->NewGlobalRef(classJNIUtils);
            env->DeleteLocalRef(classJNIUtils);
            netscape_oji_JNIUtils_NewLocalRef = env->GetStaticMethodID(netscape_oji_JNIUtils, "NewLocalRef", "(Ljava/lang/Object;)Ljava/lang/Object;");
            netscape_oji_JNIUtils_GetCurrentThread = env->GetStaticMethodID(netscape_oji_JNIUtils, "GetCurrentThread", "()Ljava/lang/Object;");
            netscape_oji_JNIUtils_GetCurrentClassLoader = env->GetStaticMethodID(netscape_oji_JNIUtils, "GetCurrentClassLoader", "()Ljava/lang/Object;");
            netscape_oji_JNIUtils_GetObjectClassLoader = env->GetStaticMethodID(netscape_oji_JNIUtils, "GetObjectClassLoader", "(Ljava/lang/Object;)Ljava/lang/Object;");
        }
    }
    
    return result;
}

Here is the call graph for this function:

JNIEXPORT jobject JNICALL Java_netscape_javascript_JSObject_call ( JNIEnv env,
jobject  java_wrapper_obj,
jstring  function_name_jstr,
jobjectArray  java_args 
)

Definition at line 796 of file LiveConnectNativeMethods.cpp.

{
    if (function_name_jstr == NULL) {
        env->ThrowNew(env->FindClass("java/lang/NullPointerException"), "illegal null function name");
        return NULL;
    }

    /* Try to determine which plugin instance is responsible for this thread. This is done by checking class loaders. */
    MRJPluginInstance* pluginInstance = GetCurrentInstance(env);
    if (pluginInstance == NULL) {
        env->ThrowNew(env->FindClass("java/lang/NullPointerException"), "illegal JNIEnv (can't find plugin)");
        return NULL;
    }

    /* Get the Unicode string for the JS function name */
    jboolean is_copy;
    const jchar* function_name_ucs2 = env->GetStringChars(function_name_jstr, &is_copy);
    jsize function_name_len = env->GetStringLength(function_name_jstr);

    jsobject js_obj = Unwrap_JSObject(env, java_wrapper_obj);
    jobject jresult = NULL;

    CallMessage msg(pluginInstance, js_obj, function_name_ucs2, function_name_len, java_args, &jresult);
    sendMessage(env, &msg);

    env->ReleaseStringChars(function_name_jstr, function_name_ucs2);

    if (jresult != NULL)
        jresult = ToLocalRef(env, jresult);

    return jresult;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JNIEXPORT jobject JNICALL Java_netscape_javascript_JSObject_eval ( JNIEnv env,
jobject  java_wrapper_obj,
jstring  script_jstr 
)

Definition at line 859 of file LiveConnectNativeMethods.cpp.

{
    /* Get the Unicode string for the JS function name */
    if (script_jstr == NULL) {
        env->ThrowNew(env->FindClass("java/lang/NullPointerException"), "illegal null script string");
        return NULL;
    }
    jboolean is_copy;
    const jchar* script_ucs2 = env->GetStringChars(script_jstr, &is_copy);
    jsize script_len = env->GetStringLength(script_jstr);

    /* unwrap the JS object from the Java object. */
    jsobject js_obj = Unwrap_JSObject(env, java_wrapper_obj);
    jobject jresult = NULL;
    
    /* determine the plugin instance so we can obtain its codebase. */
    // beard: should file a bug with Apple that JMJNIToAWTContext doesn't work.
    MRJPluginInstance* pluginInstance = GetCurrentInstance(env);
    if (pluginInstance == NULL) {
        env->ThrowNew(env->FindClass("java/lang/NullPointerException"), "illegal JNIEnv (can't find plugin)");
        return NULL;
    }

    EvalMessage msg(pluginInstance, js_obj, script_ucs2, script_len, &jresult);
    sendMessage(env, &msg);
    
    if (jresult != NULL)
        jresult = ToLocalRef(env, jresult);

    env->ReleaseStringChars(script_jstr, script_ucs2);

    return jresult;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1002 of file LiveConnectNativeMethods.cpp.

{
    jsobject jsobj = Unwrap_JSObject(env, java_wrapper_obj);

    FinalizeMessage msg(jsobj);
    sendMessage(env, &msg);
}

Here is the call graph for this function:

Here is the caller graph for this function:

JNIEXPORT jobject JNICALL Java_netscape_javascript_JSObject_getMember ( JNIEnv env,
jobject  java_wrapper_obj,
jstring  property_name_jstr 
)

Definition at line 512 of file LiveConnectNativeMethods.cpp.

{
    if (property_name_jstr == NULL) {
        env->ThrowNew(env->FindClass("java/lang/NullPointerException"), "illegal null member name");
        return NULL;
    }

    MRJPluginInstance* pluginInstance = GetCurrentInstance(env);
    if (pluginInstance == NULL) {
        env->ThrowNew(env->FindClass("java/lang/NullPointerException"), "illegal JNIEnv (can't find plugin)");
        return NULL;
    }

    /* Get the Unicode string for the JS property name */
    jboolean is_copy;
    const jchar* property_name_ucs2 = env->GetStringChars(property_name_jstr, &is_copy);
    jsize property_name_len = env->GetStringLength(property_name_jstr);

    jsobject js_obj = Unwrap_JSObject(env, java_wrapper_obj);
    jobject member = NULL;

    GetMemberMessage msg(pluginInstance, js_obj, property_name_ucs2, property_name_len, &member);
    sendMessage(env, &msg);

    // convert the resulting reference back to a local reference.
    if (member != NULL)
        member = ToLocalRef(env, member);
    
    env->ReleaseStringChars(property_name_jstr, property_name_ucs2);

    return member;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 579 of file LiveConnectNativeMethods.cpp.

{
    MRJPluginInstance* pluginInstance = GetCurrentInstance(env);

    if (pluginInstance == NULL) {
        env->ThrowNew(env->FindClass("java/lang/NullPointerException"), "illegal JNIEnv (can't find plugin)");
        return NULL;
    }

    jsobject js_obj = Unwrap_JSObject(env, java_wrapper_obj);
    jobject member = NULL;
    
    GetSlotMessage msg(pluginInstance, js_obj, slot, &member);
    sendMessage(env, &msg);
    
    // convert the resulting reference back to a local reference.
    if (member != NULL)
        member = ToLocalRef(env, member);
    return member;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JNIEXPORT jobject JNICALL Java_netscape_javascript_JSObject_getWindow ( JNIEnv env,
jclass  js_object_class,
jobject  java_applet_obj 
)

Definition at line 966 of file LiveConnectNativeMethods.cpp.

{
    MRJPluginInstance* pluginInstance = GetCurrentInstance(env, java_applet_obj);
    if (pluginInstance != NULL) {
        jsobject jswindow = NULL;
        GetWindowMessage msg(pluginInstance, &jswindow);
        sendMessage(env, &msg);
        
        if (jswindow != NULL)
            return Wrap_JSObject(env, jswindow);
    }
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JNIEXPORT void JNICALL Java_netscape_javascript_JSObject_removeMember ( JNIEnv env,
jobject  java_wrapper_obj,
jstring  property_name_jstr 
)

Definition at line 735 of file LiveConnectNativeMethods.cpp.

{
    if (property_name_jstr == NULL) {
        env->ThrowNew(env->FindClass("java/lang/NullPointerException"), "illegal null member name");
        return;
    }

    MRJPluginInstance* pluginInstance = GetCurrentInstance(env);
    if (pluginInstance == NULL) {
        env->ThrowNew(env->FindClass("java/lang/NullPointerException"), "illegal JNIEnv (can't find plugin)");
        return;
    }

    /* Get the Unicode string for the JS property name */
    jboolean is_copy;
    const jchar* property_name_ucs2 = env->GetStringChars(property_name_jstr, &is_copy);
    jsize property_name_len = env->GetStringLength(property_name_jstr);

    jsobject js_obj = Unwrap_JSObject(env, java_wrapper_obj);
    RemoveMemberMessage msg(pluginInstance, js_obj, property_name_ucs2, property_name_len);
    
    sendMessage(env, &msg);
    
    env->ReleaseStringChars(property_name_jstr, property_name_ucs2);
}

Here is the call graph for this function:

Here is the caller graph for this function:

JNIEXPORT void JNICALL Java_netscape_javascript_JSObject_setMember ( JNIEnv env,
jobject  java_wrapper_obj,
jstring  property_name_jstr,
jobject  java_obj 
)

Definition at line 630 of file LiveConnectNativeMethods.cpp.

{
    if (property_name_jstr == NULL) {
        env->ThrowNew(env->FindClass("java/lang/NullPointerException"), "illegal null member name");
        return;
    }

    MRJPluginInstance* pluginInstance = GetCurrentInstance(env);
    if (pluginInstance == NULL) {
        env->ThrowNew(env->FindClass("java/lang/NullPointerException"), "illegal JNIEnv (can't find plugin)");
        return;
    }

    /* Get the Unicode string for the JS property name */
    jboolean is_copy;
    const jchar* property_name_ucs2 = env->GetStringChars(property_name_jstr, &is_copy);
    jsize property_name_len = env->GetStringLength(property_name_jstr);
    
    jsobject js_obj = Unwrap_JSObject(env, java_wrapper_obj);
    java_obj = ToGlobalRef(env, java_obj);

    SetMemberMessage msg(pluginInstance, js_obj, property_name_ucs2, property_name_len, java_obj);
    sendMessage(env, &msg);
    
    env->DeleteGlobalRef(java_obj);
    env->ReleaseStringChars(property_name_jstr, property_name_ucs2);
}

Here is the call graph for this function:

Here is the caller graph for this function:

JNIEXPORT void JNICALL Java_netscape_javascript_JSObject_setSlot ( JNIEnv env,
jobject  java_wrapper_obj,
jint  slot,
jobject  java_obj 
)

Definition at line 687 of file LiveConnectNativeMethods.cpp.

{
    MRJPluginInstance* pluginInstance = GetCurrentInstance(env);

    if (pluginInstance == NULL) {
        env->ThrowNew(env->FindClass("java/lang/NullPointerException"), "illegal JNIEnv (can't find plugin)");
        return;
    }

    jsobject js_obj = Unwrap_JSObject(env, java_wrapper_obj);
    java_obj = ToGlobalRef(env, java_obj);
    
    SetSlotMessage msg(pluginInstance, js_obj, slot, java_obj);
    sendMessage(env, &msg);
    env->DeleteGlobalRef(java_obj);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 922 of file LiveConnectNativeMethods.cpp.

{
    /* unwrap the JS object from the Java object. */
    jstring jresult = NULL;
    jsobject js_obj = Unwrap_JSObject(env, java_wrapper_obj);

    MRJPluginInstance* pluginInstance = GetCurrentInstance(env);
    if (pluginInstance == NULL) {
        env->ThrowNew(env->FindClass("java/lang/NullPointerException"), "illegal JNIEnv (can't find plugin)");
        return NULL;
    }

    ToStringMessage msg(pluginInstance, js_obj, &jresult);
    sendMessage(env, &msg);
    
    if (jresult != NULL)
        jresult = (jstring) ToLocalRef(env, jresult);
    
    return jresult;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsIPrincipal* newCodebasePrincipal ( const char *  codebaseURL) [static]

Definition at line 461 of file LiveConnectNativeMethods.cpp.

{
    nsIPrincipal* principal = NULL;
#if 0
    nsICapsManager* capsManager = NULL;
    static NS_DEFINE_IID(kICapsManagerIID, NS_ICAPSMANAGER_IID);
    if (thePluginManager->QueryInterface(kICapsManagerIID, &capsManager) == NS_OK) {
        if (capsManager->CreateCodebasePrincipal(codebaseURL, &principal) != NS_OK)
            principal = NULL;
        capsManager->Release();
    }
#endif
    return principal;
}
static jobject NewLocalRef ( JNIEnv env,
jobject  global_ref 
) [static]

Definition at line 180 of file LiveConnectNativeMethods.cpp.

Here is the caller graph for this function:

static NS_DEFINE_IID ( kLiveConnectCID  ,
NS_CLIVECONNECT_CID   
) [static]
static NS_DEFINE_IID ( kComponentManagerCID  ,
NS_COMPONENTMANAGER_CID   
) [static]
static void sendMessage ( JNIEnv env,
JavaMessage msg 
) [static]

Sends a message by rendezvousing with an existing JavaScript thread, or creates a new one if none exists for this thread already.

Definition at line 409 of file LiveConnectNativeMethods.cpp.

{
    // the main thread gets its own secure env, so it won't contend with other threads. this
    // is needed to handle finalization, which seems to get called from the main thread sometimes.
    if (env == theJVMPlugin->getSession()->getMainEnv()) {
        static CSecureEnv* mainEnv = NULL;
        if (mainEnv == NULL) {
            mainEnv = new CSecureEnv(theJVMPlugin, NULL, env);
            mainEnv->AddRef();
        }
        mainEnv->setJavaEnv(env);
        mainEnv->sendMessageFromJava(env, msg, true);
        return;
    }
    
    // If this is a call back into JavaScript from Java, there will be a secureEnv associated with this thread.
    jobject thread = GetCurrentThread(env);
    CSecureEnv* secureEnv = GetSecureJNI(env, thread);
    env->DeleteLocalRef(thread);
    if (secureEnv != NULL) {
        secureEnv->sendMessageFromJava(env, msg);
    } else {
        // spontaneous call in from Java. this communicates with a shared server thread. this is *VERY* slow right now.
        static MRJMonitor sharedMonitor(theJVMPlugin->getSession());
        // only 1 Java thread can use this at a time.
        sharedMonitor.enter();
        {
            static CSecureEnv* sharedEnv = NULL;
            if (sharedEnv == NULL) {
                sharedEnv = new CSecureEnv(theJVMPlugin, NULL, env);
                sharedEnv->AddRef();
            }
            sharedEnv->setJavaEnv(env);

            // In the current Seamonkey architecture, there's really only one thread that JavaScript
            // can execute in. We take advantage of that fact here. When we have a more multithreaded
            // system, this will have to be revisited.
            static PRUint32 theJavaScriptThread = getJavaScriptThread(env);
            
            // if the JavaScript thread is known, wrap the message in a MessageRunnable to handle
            // the message in the JavaScript thread.
            if (theJavaScriptThread != 0) {
                MessageRunnable* runnableMsg = new MessageRunnable(theJavaScriptThread, msg);
                NS_ADDREF(runnableMsg);
                sharedEnv->sendMessageFromJava(env, runnableMsg);
                NS_IF_RELEASE(runnableMsg);
            }
        }
        sharedMonitor.exit();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static jobject ToGlobalRef ( JNIEnv env,
jobject  localRef 
) [static]

Definition at line 185 of file LiveConnectNativeMethods.cpp.

{
    jobject globalRef = env->NewGlobalRef(localRef);
    env->DeleteLocalRef(localRef);
    return globalRef;
}
static jobject ToLocalRef ( JNIEnv env,
jobject  globalRef 
) [static]

Definition at line 192 of file LiveConnectNativeMethods.cpp.

{
    jobject localRef = NewLocalRef(env, globalRef);
    env->DeleteGlobalRef(globalRef);
    return localRef;
}

Here is the call graph for this function:

Here is the caller graph for this function:

jsobject Unwrap_JSObject ( JNIEnv env,
jobject  java_wrapper_obj 
)

Definition at line 175 of file LiveConnectNativeMethods.cpp.

{
    return env->GetIntField(java_wrapper_obj, netscape_javascript_JSObject_internal);
}
jobject Wrap_JSObject ( JNIEnv env,
jsobject  js_obj 
)

Definition at line 169 of file LiveConnectNativeMethods.cpp.

{
    jmethodID constructorID = env->GetMethodID(netscape_javascript_JSObject, "<init>", "(I)V");
    return env->NewObject(netscape_javascript_JSObject, constructorID, js_obj);
}

Variable Documentation

Definition at line 71 of file LiveConnectNativeMethods.cpp.

Definition at line 73 of file LiveConnectNativeMethods.cpp.

Definition at line 72 of file LiveConnectNativeMethods.cpp.

Definition at line 75 of file LiveConnectNativeMethods.cpp.

Definition at line 78 of file LiveConnectNativeMethods.cpp.

Definition at line 77 of file LiveConnectNativeMethods.cpp.

Definition at line 79 of file LiveConnectNativeMethods.cpp.

Definition at line 76 of file LiveConnectNativeMethods.cpp.

Definition at line 69 of file LiveConnectNativeMethods.cpp.

Definition at line 67 of file LiveConnectNativeMethods.cpp.

Definition at line 68 of file LiveConnectNativeMethods.cpp.

Definition at line 538 of file badapter.cpp.