NS_DEFINE_IID(kLiveConnectCID, NS_CLIVECONNECT_CID); NS_DEFINE_IID(kILiveConnectIID, NS_ILIVECONNECT_IID); nsresult result = theServiceManager->GetService(kLiveConnectCID, kILiveConnectIID, (nsISupports**)&theLiveConnectManager); if (result != NS_OK) return result;
if (&NS_GetGlobalComponentManager) { NS_GetGlobalComponentManager(&theComponentManager); }  nsresult result = theServiceManager->GetService(kLiveConnectCID, NS_GET_IID(nsILiveconnect), (nsISupports**)&theLiveConnectManager); if (result != NS_OK) return result;
nsresult InitLiveConnectSupport(MRJPlugin* jvmPlugin){	theJVMPlugin = jvmPlugin;	NS_DEFINE_IID(kLiveConnectCID, NS_CLIVECONNECT_CID);	NS_DEFINE_IID(kILiveConnectIID, NS_ILIVECONNECT_IID);	nsresult result = theServiceManager->GetService(kLiveConnectCID, kILiveConnectIID,													(nsISupports**)&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,    };        JNIEnv* env = NULL;    nsrefcnt count = jvmPlugin->GetJNIEnv(&env);    if (count > 0 && 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");    		netscape_javascript_JSObject_internal = env->GetFieldID(netscape_javascript_JSObject, "internal", "I");		    env->RegisterNatives(netscape_javascript_JSObject, nativeMethods, sizeof(nativeMethods) / sizeof(JNINativeMethod));		    if (env->ExceptionOccurred()) {				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;");	    }	    	    jvmPlugin->ReleaseJNIEnv(env);    }        return result;}