From 263d228e8465f7f705c458186859baeee4591423 Mon Sep 17 00:00:00 2001 From: "edburns%acm.org" Date: Thu, 12 Jul 2001 20:32:09 +0000 Subject: [PATCH] bug=80906 ra=edburns author=Nikolay Igotti Minor update to prevent some crashes. --- java/pluggable-jvm/wf_moz6/doc/set_env.sh | 4 +-- .../wf_moz6/src/nsAppletHTMLObject.cpp | 4 +-- .../wf_moz6/src/nsJavaHTMLObjectFactory.cpp | 31 +++++++++++-------- .../wf_moz6/src/nsJavaHTMLObjectFactory.h | 7 +++-- .../wf_moz6/src/nsJavaObjectInfo.cpp | 3 +- .../wf_moz6/src/nsPluggableJVM.cpp | 11 ++++--- .../wf_moz6/src/nsWFSecureEnv.cpp | 4 +-- 7 files changed, 37 insertions(+), 27 deletions(-) diff --git a/java/pluggable-jvm/wf_moz6/doc/set_env.sh b/java/pluggable-jvm/wf_moz6/doc/set_env.sh index 6c3bc31202c..39cccdfcef0 100644 --- a/java/pluggable-jvm/wf_moz6/doc/set_env.sh +++ b/java/pluggable-jvm/wf_moz6/doc/set_env.sh @@ -16,7 +16,7 @@ # Portions created by Sun Microsystems Inc are Copyright (C) 2001 # All Rights Reserved. # -# $Id: set_env.sh,v 1.1 2001-05-10 18:12:39 edburns%acm.org Exp $ +# $Id: set_env.sh,v 1.2 2001-07-12 20:32:06 edburns%acm.org Exp $ # # # Contributor(s): @@ -26,7 +26,7 @@ # Set those variables # for me this var set in .bashrc so I don't need it here #WFJDKHOME=/usr/java/jdk1.3.0_02 -WFDIR=/usr/local/home/nike/mozilla/wf +WFDIR=/work/wf.ed # end of customizable part CURDIR=`pwd` diff --git a/java/pluggable-jvm/wf_moz6/src/nsAppletHTMLObject.cpp b/java/pluggable-jvm/wf_moz6/src/nsAppletHTMLObject.cpp index 0a84db87f2f..882fd1625da 100644 --- a/java/pluggable-jvm/wf_moz6/src/nsAppletHTMLObject.cpp +++ b/java/pluggable-jvm/wf_moz6/src/nsAppletHTMLObject.cpp @@ -16,7 +16,7 @@ * Portions created by Sun Microsystems Inc are Copyright (C) 2001 * All Rights Reserved. * - * $Id: nsAppletHTMLObject.cpp,v 1.1 2001-05-10 18:12:41 edburns%acm.org Exp $ + * $Id: nsAppletHTMLObject.cpp,v 1.2 2001-07-12 20:32:07 edburns%acm.org Exp $ * * * Contributor(s): @@ -78,7 +78,7 @@ nsAppletHTMLObject::Initialize(nsIPluginInstancePeer *peer) m_peer = peer; NS_ADDREF(m_peer); peer->QueryInterface(kIPluginInstancePeer2IID, - (void **)&m_peer2); + (void **)&m_peer2); m_jobject = new nsJavaHTMLObject(m_factory); NS_ADDREF(m_jobject); res = nsServiceManager::GetService(kPluginManagerCID, diff --git a/java/pluggable-jvm/wf_moz6/src/nsJavaHTMLObjectFactory.cpp b/java/pluggable-jvm/wf_moz6/src/nsJavaHTMLObjectFactory.cpp index 108414304e5..186ba8ee01b 100644 --- a/java/pluggable-jvm/wf_moz6/src/nsJavaHTMLObjectFactory.cpp +++ b/java/pluggable-jvm/wf_moz6/src/nsJavaHTMLObjectFactory.cpp @@ -16,7 +16,7 @@ * Portions created by Sun Microsystems Inc are Copyright (C) 2001 * All Rights Reserved. * - * $Id: nsJavaHTMLObjectFactory.cpp,v 1.1 2001-05-10 18:12:42 edburns%acm.org Exp $ + * $Id: nsJavaHTMLObjectFactory.cpp,v 1.2 2001-07-12 20:32:08 edburns%acm.org Exp $ * * * Contributor(s): @@ -38,6 +38,7 @@ #include "nsWFSecurityContext.h" #include "nsIThread.h" #include "nsIJVMConsole.h" +#include "nsCRT.h" static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIPluginIID, NS_IPLUGIN_IID); @@ -69,12 +70,12 @@ NS_IMPL_THREADSAFE_ISUPPORTS5(nsJavaHTMLObjectFactory, \ nsIFactory, \ nsIPlugin, \ nsIJVMPlugin, \ - nsIJVMConsole, \ + nsIJVMConsole, \ nsIBrowserJavaSupport) static int GetProxyForURL(void* handle, - char* url, - char* *proxy) + char* url, + char* *proxy) { nsresult res; nsIBrowserJavaSupport* obj = (nsIBrowserJavaSupport*)handle; @@ -100,19 +101,20 @@ nsJavaHTMLObjectFactory::nsJavaHTMLObjectFactory() { mainIThread->GetPRThread(&m_mainThread); instance = this; m_jsjRecursion = 0; + m_wrapper = nsnull; } nsJavaHTMLObjectFactory::~nsJavaHTMLObjectFactory() { OJI_LOG("nsJavaHTMLObjectFactory::~nsJavaHTMLObjectFactory"); NS_RELEASE(m_jvm); - free(m_wrapper); + if (m_wrapper) free(m_wrapper); } NS_METHOD nsJavaHTMLObjectFactory::Create(nsISupports* outer, - const nsIID& aIID, - void* *aInstancePtr) + const nsIID& aIID, + void* *aInstancePtr) { //OJI_LOG2("nsJavaHTMLObjectFactory::Create with %p", outer); //OJI_LOG2("it is %s", aIID.ToString()); @@ -124,7 +126,9 @@ nsJavaHTMLObjectFactory::Create(nsISupports* outer, if (!instance) { instance = new nsJavaHTMLObjectFactory(); - rv = instance->Initialize(); + // XXX: instance never will be freed, need to be rewritten + NS_ADDREF(instance); + rv = instance->Initialize(); if (NS_FAILED(rv)) return rv; } @@ -136,8 +140,8 @@ nsJavaHTMLObjectFactory::Create(nsISupports* outer, if (aIID.Equals(kIPluginInstanceIID) || aIID.Equals(kIJavaHTMLObjectIID)) { return instance->CreateInstance(outer, - aIID, - aInstancePtr); + aIID, + aInstancePtr); } OJI_LOG2("nsJavaHTMLObjectFactory::Create: no matching ifaces for %s", aIID.ToString()); @@ -146,8 +150,8 @@ nsJavaHTMLObjectFactory::Create(nsISupports* outer, NS_IMETHODIMP nsJavaHTMLObjectFactory::CreateInstance(nsISupports *aOuter, - const nsIID & aIID, - void **result) + const nsIID & aIID, + void **result) { *result = NULL; if (aOuter != NULL) @@ -155,7 +159,8 @@ nsJavaHTMLObjectFactory::CreateInstance(nsISupports *aOuter, OJI_LOG("Aggregation of nsJavaHTMLObjectFactory failed"); return NS_ERROR_NO_AGGREGATION; } - if (!m_jvm) return NS_ERROR_FAILURE; + // m_env is set if JVM is started up + if (!m_jvm || !m_env) return NS_ERROR_FAILURE; // XXX: remove me when it'll be called by Mozilla //if (NS_FAILED(Initialize())) return NS_ERROR_FAILURE; if (aIID.Equals(kIJavaHTMLObjectIID)) diff --git a/java/pluggable-jvm/wf_moz6/src/nsJavaHTMLObjectFactory.h b/java/pluggable-jvm/wf_moz6/src/nsJavaHTMLObjectFactory.h index ace672384d7..43997cf0660 100644 --- a/java/pluggable-jvm/wf_moz6/src/nsJavaHTMLObjectFactory.h +++ b/java/pluggable-jvm/wf_moz6/src/nsJavaHTMLObjectFactory.h @@ -16,7 +16,7 @@ * Portions created by Sun Microsystems Inc are Copyright (C) 2001 * All Rights Reserved. * - * $Id: nsJavaHTMLObjectFactory.h,v 1.1 2001-05-10 18:12:42 edburns%acm.org Exp $ + * $Id: nsJavaHTMLObjectFactory.h,v 1.2 2001-07-12 20:32:09 edburns%acm.org Exp $ * * * Contributor(s): @@ -107,8 +107,9 @@ class nsJavaHTMLObjectFactory : public nsIPlugin, BrowserSupportWrapper* m_wrapper; JNIEnv* m_env; NS_IMETHOD doGetProxyForURL(const char* url, - char* *target); - NS_IMETHOD doJSCall(jint jstid, struct JSObject_CallInfo** call); + char* *target); + NS_IMETHOD doJSCall(jint jstid, + struct JSObject_CallInfo** call); NS_IMETHOD initLiveConnect(); PRThread* m_mainThread; jint m_jsjRecursion; diff --git a/java/pluggable-jvm/wf_moz6/src/nsJavaObjectInfo.cpp b/java/pluggable-jvm/wf_moz6/src/nsJavaObjectInfo.cpp index 6cfb1968620..7dec6f20d1f 100644 --- a/java/pluggable-jvm/wf_moz6/src/nsJavaObjectInfo.cpp +++ b/java/pluggable-jvm/wf_moz6/src/nsJavaObjectInfo.cpp @@ -16,7 +16,7 @@ * Portions created by Sun Microsystems Inc are Copyright (C) 2001 * All Rights Reserved. * - * $Id: nsJavaObjectInfo.cpp,v 1.1 2001-05-10 18:12:42 edburns%acm.org Exp $ + * $Id: nsJavaObjectInfo.cpp,v 1.2 2001-07-12 20:32:09 edburns%acm.org Exp $ * * * Contributor(s): @@ -29,6 +29,7 @@ #include "nsIWFInstanceWrapper.h" #include "nsIPluginInstance.h" #include "wf_moz6_common.h" +#include static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID); static NS_DEFINE_IID(kIWFInstanceWrapperIID, NS_IWFINSTANCEWRAPPER_IID); diff --git a/java/pluggable-jvm/wf_moz6/src/nsPluggableJVM.cpp b/java/pluggable-jvm/wf_moz6/src/nsPluggableJVM.cpp index 3e90200e3cb..a655122e4da 100644 --- a/java/pluggable-jvm/wf_moz6/src/nsPluggableJVM.cpp +++ b/java/pluggable-jvm/wf_moz6/src/nsPluggableJVM.cpp @@ -16,7 +16,7 @@ * Portions created by Sun Microsystems Inc are Copyright (C) 2001 * All Rights Reserved. * - * $Id: nsPluggableJVM.cpp,v 1.1 2001-05-10 18:12:42 edburns%acm.org Exp $ + * $Id: nsPluggableJVM.cpp,v 1.2 2001-07-12 20:32:09 edburns%acm.org Exp $ * * * Contributor(s): @@ -48,8 +48,8 @@ nsPluggableJVM::~nsPluggableJVM() OJI_LOG("nsPluggableJVM::~nsPluggableJVM"); if (m_jvmp_context) { - if (m_extID) - (m_jvmp_context->JVMP_UnregisterExtension)(m_ctx, m_extID); + if (m_ctx != nsnull && m_extID != 0) + (m_jvmp_context->JVMP_UnregisterExtension)(m_ctx, m_extID); } } @@ -168,6 +168,7 @@ nsPluggableJVM::GetJNIEnv(JNIEnv* *env) JVMP_CallingContext* ctx; int res; + if (!m_jvmp_context) return NS_ERROR_FAILURE; res = (m_jvmp_context->JVMP_GetCallingContext)(&ctx); if (res != JNI_TRUE) return NS_ERROR_FAILURE; *env = ctx->env; @@ -176,7 +177,8 @@ nsPluggableJVM::GetJNIEnv(JNIEnv* *env) static int newPrincipalsFromStrings(jbyte** *resprin, - jint* *reslen, jint num, ...) + jint* *reslen, + jint num, ...) { jint* prins_len; jbyte* *prins; @@ -277,6 +279,7 @@ nsPluggableJVM::ShutdownJVM(PRBool fullShutdown, nsPluggableJVMStatus *status) { if ((m_jvmp_context->JVMP_UnregisterExtension(m_ctx, m_extID) != JNI_TRUE)) return NS_ERROR_FAILURE; + m_extID = 0; if ((m_jvmp_context->JVMP_StopJVM(m_ctx) != JNI_TRUE)) return NS_ERROR_FAILURE; m_jvmp_context = NULL; diff --git a/java/pluggable-jvm/wf_moz6/src/nsWFSecureEnv.cpp b/java/pluggable-jvm/wf_moz6/src/nsWFSecureEnv.cpp index 8381e9a8017..b42dec9c8ae 100644 --- a/java/pluggable-jvm/wf_moz6/src/nsWFSecureEnv.cpp +++ b/java/pluggable-jvm/wf_moz6/src/nsWFSecureEnv.cpp @@ -16,7 +16,7 @@ * Portions created by Sun Microsystems Inc are Copyright (C) 2001 * All Rights Reserved. * - * $Id: nsWFSecureEnv.cpp,v 1.1 2001-05-10 18:12:44 edburns%acm.org Exp $ + * $Id: nsWFSecureEnv.cpp,v 1.2 2001-07-12 20:32:09 edburns%acm.org Exp $ * * * Contributor(s): @@ -181,7 +181,7 @@ nsWFSecureEnv::CallMethod(/*[in]*/ jni_type ret_type, { // XXX: do smth meaningful with possible Java exception if (call->jException) { - m_jvm->DeleteLocalRef(call->jException); + m_jvm->DeleteGlobalRef(call->jException); rv = NS_ERROR_FAILURE; } else { *result = call->data.__callMethod.result;