NPError NPP_Initialize(void) { JavaVMInitArgs vm_args; jint ext_id; if (g_inited) return NPERR_NO_ERROR; if (g_jvmp_context != NULL) return NPERR_NO_ERROR; JVMP_ShmInit(1); if (loadPluginDLL() != JNI_TRUE) return NPERR_GENERIC_ERROR; memset(&vm_args, 0, sizeof(vm_args)); vm_args.version = JNI_VERSION_1_2; (g_jvmp_context->JVMP_GetDefaultJavaVMInitArgs)(&vm_args); if (initJVM(&g_jvm, &g_ctx, &vm_args) != JNI_TRUE) return NPERR_GENERIC_ERROR; if ((g_jvmp_context->JVMP_RegisterExtension) (g_ctx, "/ws/wf/build/unix/libwf_netscape4.so", &ext_id) != JNI_TRUE) return NPERR_GENERIC_ERROR; return DoDirtyInit(); }
NS_IMETHODIMP nsPluggableJVM::StartupJVM(const char *classPath, nsPluggableJVMStatus *status, jlong sup) { JavaVMInitArgs vm_args; jint res; OJI_LOG("nsPluggableJVM::StartupJVM"); *status = nsPluggableJVMStatus_Failed; if (sup == nsnull) return NS_ERROR_FAILURE; const char* plugin_home = getenv("WFHOME"); if (plugin_home == NULL) { OJI_LOG("Env variable JAVA_PLUGIN_HOME not set"); return NS_ERROR_FAILURE; } if (NS_FAILED(loadPluginDLL(plugin_home))) return NS_ERROR_FAILURE; memset(&vm_args, 0, sizeof(vm_args)); vm_args.version = JNI_VERSION_1_2; // XXX: add classpath here if (NS_FAILED(initJVM(&m_ctx, &vm_args))) return NS_ERROR_FAILURE; // initialize capability mechanism JVMP_SecurityCap cap; JVMP_FORBID_ALL_CAPS(cap); JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_SYSTEM); JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_SYSEVENT) JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_EVENT); JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_CALL); jbyte** prins; jint pnum = 2; jint* plen; if (!newPrincipalsFromStrings(&prins, &plen, pnum, "CAPS", "MOZILLA")) return JNI_FALSE; if ((m_jvmp_context->JVMP_EnableCapabilities) (m_ctx, &cap, pnum, plen, prins) != JNI_TRUE) { OJI_LOG("Can\'t enable caps"); return JNI_FALSE; }; deletePrincipals(prins, plen, pnum); SetConsoleVisibility(PR_TRUE); char* ext_dll = PR_GetLibraryName(plugin_home, LIBEXT); OJI_LOG2("JVMP_RegisterExtension: %s", ext_dll); res = (m_jvmp_context->JVMP_RegisterExtension)(m_ctx, ext_dll, &m_extID, sup); PR_Free(ext_dll); if (res != JNI_TRUE || m_extID == 0) return NS_ERROR_FAILURE; OJI_LOG("JVMP_RegisterExtension OK"); *status = nsPluggableJVMStatus_Running; return NS_OK; }