jclass netscape_oji_ProxyClassLoader = env->FindClass("netscape/oji/ProxyClassLoader"); if (!netscape_oji_ProxyClassLoader) {
jclass netscape_oji_ProxyClassLoaderFac = env->FindClass("netscape/oji/ProxyClassLoaderFactory"); if (!netscape_oji_ProxyClassLoaderFac) {
static nsresult getScriptClassLoader(JNIEnv* env, jobject* classloader){    // get the current JSContext from the context stack service.    nsresult rv;    nsCOMPtr<nsIJSContextStack> contexts = do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv);    if (NS_FAILED(rv)) return rv;    JSContext* cx;    rv = contexts->Peek(&cx);    if (NS_FAILED(rv)) return rv;        // lookup "window.navigator.javaclasses", if it exists, this is the class loader bound    // to this page.    JSObject* window = JS_GetGlobalObject(cx);    if (!window) return NS_ERROR_FAILURE;    jsval navigator;    if (!JS_GetProperty(cx, window, "navigator", &navigator)) return NS_ERROR_FAILURE;        jsval javaclasses;    if (JS_GetProperty(cx, JSVAL_TO_OBJECT(navigator), "javaclasses", &javaclasses)) {        // unwrap this, the way LiveConnect does it.        if (JSJ_ConvertJSValueToJavaObject(cx, javaclasses, classloader))            return NS_OK;    }    nsCOMPtr<nsIURI> codebase;    rv = getScriptCodebase(cx, getter_AddRefs(codebase));    if (NS_FAILED(rv)) return rv;        // create a netscape.oji.ProxyClassLoader instance.    nsXPIDLCString spec;    rv = codebase->GetSpec(getter_Copies(spec));    if (NS_FAILED(rv)) return rv;        jstring jspec = env->NewStringUTF(spec);    if (!spec) {        env->ExceptionClear();        return NS_ERROR_FAILURE;    }    jclass netscape_oji_ProxyClassLoader = env->FindClass("netscape/oji/ProxyClassLoader");    if (!netscape_oji_ProxyClassLoader) {        env->ExceptionClear();        return NS_ERROR_FAILURE;    }    jmethodID constructorID = env->GetMethodID(netscape_oji_ProxyClassLoader, "<init>", "(Ljava/lang/String;)V");    if (!constructorID) {        env->ExceptionClear();        return NS_ERROR_FAILURE;    }    *classloader = env->NewObject(netscape_oji_ProxyClassLoader, constructorID, jspec);    if (!*classloader) {        env->ExceptionClear();        return NS_ERROR_FAILURE;    }    env->DeleteLocalRef(jspec);    env->DeleteLocalRef(netscape_oji_ProxyClassLoader);        // now, cache the class loader in "window.navigator.javaclasses"    if (JSJ_ConvertJavaObjectToJSValue(cx, *classloader, &javaclasses)) {        JS_SetProperty(cx, JSVAL_TO_OBJECT(navigator), "javaclasses", &javaclasses);    }        return NS_OK;}