nsCOMPtr<nsISecurityContext> jscontext = dont_AddRef(JVM_GetJSSecurityContext());
if (java_applet_obj) { context->java_applet_obj = java_applet_obj; } else if (context->java_applet_obj) { java_applet_obj=context->java_applet_obj; }  JSContext *pJSCX    = map_jsj_thread_to_js_context_impl(nsnull,java_applet_obj,jEnv,errp); nsCOMPtr<nsIPrincipal> principal;  if (pNSISecurityContext != nsnull) { if (pJSCX) { JSPrincipals *jsprin = nsnull;  nsCOMPtr<nsIScriptContext> scriptContext = (nsIScriptContext*)JS_GetContextPrivate(pJSCX); if (scriptContext) { nsCOMPtr<nsIScriptGlobalObject> global = scriptContext->GetGlobalObject(); NS_ASSERTION(global, "script context has no global object");  if (global) { nsCOMPtr<nsIScriptObjectPrincipal> globalData = do_QueryInterface(global); if (globalData) { if (NS_FAILED(globalData->GetPrincipal(getter_AddRefs(principal)))) return NS_ERROR_FAILURE; } } } }    nsCOMPtr<nsISecurityContext> jscontext = dont_AddRef(new nsCSecurityContext(principal));
enter_js_from_java_impl(JNIEnv *jEnv, char **errp,                        void **pNSIPrincipaArray, int numPrincipals, void *pNSISecurityContext){	JVMContext* context = GetJVMContext();	JSContext *pJSCX = context->js_context;	if (pNSISecurityContext != NULL) {        nsCOMPtr<nsISecurityContext> jscontext = dont_AddRef(JVM_GetJSSecurityContext());        nsISecurityContext* jvcontext = NS_STATIC_CAST(nsISecurityContext*,pNSISecurityContext);                                        // Should be NS_DYNAMIC_CAST, but no such define exists.                                        // So for the sake of portability, we'll live                                         // dangerously and use brute force.        if( !jscontext || !jvcontext ) {            return PR_FALSE;        }        // Check that the origin + certificate are the same.        // If not, then return false.        const int buflen = 128;        char jsorigin[buflen];        char jvorigin[buflen];        *jsorigin = nsnull;        *jvorigin = nsnull;                jscontext->GetOrigin(jsorigin,buflen);        jvcontext->GetOrigin(jvorigin,buflen);        if( nsCRT::strcasecmp(jsorigin,jvorigin) ) {            return PR_FALSE;        }        char jscertid[buflen];        char jvcertid[buflen];        *jscertid = nsnull;        *jvcertid = nsnull;        jscontext->GetCertificateID(jscertid,buflen);        jvcontext->GetCertificateID(jvcertid,buflen);        if( nsCRT::strcasecmp(jscertid,jvcertid) ) {            return PR_FALSE;        }    } else {        return PR_FALSE;    }	return PR_TRUE;}