From 103b9ddec69449e14ad90184ffe105f1aa04e18e Mon Sep 17 00:00:00 2001 From: "beard%netscape.com" Date: Tue, 8 Sep 1998 19:11:50 +0000 Subject: [PATCH] Lazy LiveConnect fixes. --- lib/libmocha/lm_init.c | 3 ++- lib/libmocha/lm_win.c | 6 +++-- modules/oji/src/jvmmgr.cpp | 49 ++++++++++++++++++++------------------ modules/oji/src/jvmmgr.h | 4 ++-- 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/lib/libmocha/lm_init.c b/lib/libmocha/lm_init.c index d62e8d303867..0d0169d40261 100644 --- a/lib/libmocha/lm_init.c +++ b/lib/libmocha/lm_init.c @@ -715,7 +715,8 @@ lm_ReallyInitMocha(void) lm_crippled_context = lm_crippled_decoder->js_context; #if defined(OJI) - (void)JVM_MaybeStartupLiveConnect(lm_crippled_context, JS_GetGlobalObject(lm_crippled_context)); + if (JVM_MaybeStartupLiveConnect()) + JSJ_InitJSContext(lm_crippled_context, JS_GetGlobalObject(lm_crippled_context), NULL); #elif defined(JAVA) LJ_JSJ_Init(); diff --git a/lib/libmocha/lm_win.c b/lib/libmocha/lm_win.c index 8efd2d2c43c2..9d9799596104 100644 --- a/lib/libmocha/lm_win.c +++ b/lib/libmocha/lm_win.c @@ -3238,8 +3238,10 @@ lm_InitWindowContent(MochaDecoder *decoder) return JS_FALSE; #if defined(OJI) - JVM_MaybeStartupLiveConnect(cx, obj); -#if 0 +#if 1 + if (JVM_MaybeStartupLiveConnect()) + JSJ_InitJSContext(cx, obj, NULL); +#else { PRBool jvmMochaPrefsEnabled = PR_FALSE; if (NPL_IsJVMAndMochaPrefsEnabled() == PR_TRUE) { diff --git a/modules/oji/src/jvmmgr.cpp b/modules/oji/src/jvmmgr.cpp index 749e372e849e..63d68f07fca5 100644 --- a/modules/oji/src/jvmmgr.cpp +++ b/modules/oji/src/jvmmgr.cpp @@ -724,29 +724,29 @@ nsJVMMgr::GetJVMStatus(void) } PRBool -nsJVMMgr::MaybeStartupLiveConnect(JSContext* cx, JSObject* obj) +nsJVMMgr::MaybeStartupLiveConnect() { if (fJSJavaVM) return PR_TRUE; - if (IsLiveConnectEnabled()) { - JSJ_Init(&jsj_callbacks); - nsIJVMPlugin* plugin = GetJVMPlugin(); - if (plugin) { - const char* classpath = NULL; - nsresult err = plugin->GetClassPath(&classpath); - if (err) return err; - JavaVM* javaVM = NULL; - err = plugin->GetJavaVM(&javaVM); - if (err) return err; - fJSJavaVM = JSJ_ConnectToJavaVM(javaVM, classpath); - if (fJSJavaVM) { - JSJ_InitJSContext(cx, obj, NULL); - } - // plugin->Release(); // GetJVMPlugin no longer calls AddRef - return PR_TRUE; - } - } + do { + if (IsLiveConnectEnabled() && StartupJVM() == nsJVMStatus_Running) { + JSJ_Init(&jsj_callbacks); + nsIJVMPlugin* plugin = GetJVMPlugin(); + if (plugin) { + const char* classpath = NULL; + nsresult err = plugin->GetClassPath(&classpath); + if (err != NS_OK) break; + JavaVM* javaVM = NULL; + err = plugin->GetJavaVM(&javaVM); + if (err != NS_OK) break; + fJSJavaVM = JSJ_ConnectToJavaVM(javaVM, classpath); + if (fJSJavaVM != NULL) + return PR_TRUE; + // plugin->Release(); // GetJVMPlugin no longer calls AddRef + } + } + } while (0); return PR_FALSE; } @@ -764,8 +764,11 @@ nsJVMMgr::MaybeShutdownLiveConnect(void) PRBool nsJVMMgr::IsLiveConnectEnabled(void) { - return LM_GetMochaEnabled() - && GetJVMStatus() == nsJVMStatus_Running; + if (LM_GetMochaEnabled()) { + nsJVMStatus status = GetJVMStatus(); + return (status == nsJVMStatus_Enabled || status == nsJVMStatus_Running); + } + return PR_FALSE; } //////////////////////////////////////////////////////////////////////////////// @@ -1207,12 +1210,12 @@ JVM_GetJNIEnv(void) } PR_IMPLEMENT(PRBool) -JVM_MaybeStartupLiveConnect(JSContext* cx, JSObject* obj) +JVM_MaybeStartupLiveConnect() { PRBool result = PR_FALSE; nsJVMMgr* mgr = JVM_GetJVMMgr(); if (mgr) { - result = mgr->MaybeStartupLiveConnect(cx, obj); + result = mgr->MaybeStartupLiveConnect(); mgr->Release(); } return result; diff --git a/modules/oji/src/jvmmgr.h b/modules/oji/src/jvmmgr.h index 2eb680e08a9b..29c0cdf28e69 100644 --- a/modules/oji/src/jvmmgr.h +++ b/modules/oji/src/jvmmgr.h @@ -76,7 +76,7 @@ public: const char* GetJavaErrorString(JNIEnv* env); nsresult AddToClassPath(const char* dirPath); - PRBool MaybeStartupLiveConnect(JSContext* cx, JSObject* obj); + PRBool MaybeStartupLiveConnect(void); PRBool MaybeShutdownLiveConnect(void); PRBool IsLiveConnectEnabled(void); JSJavaVM* GetJSJavaVM() { return fJSJavaVM; } @@ -213,7 +213,7 @@ PR_EXTERN(JNIEnv*) JVM_GetJNIEnv(void); PR_EXTERN(PRBool) -JVM_MaybeStartupLiveConnect(JSContext* cx, JSObject* obj); +JVM_MaybeStartupLiveConnect(void); PR_EXTERN(PRBool) JVM_MaybeShutdownLiveConnect(void);