nsISupports* credentials = NS_REINTERPRET_CAST(nsISupports*, pNSISecurityContext); nsCOMPtr<nsISecurityContext> securityContext = do_QueryInterface(credentials); if (securityContext) { nsresult rv; nsCOMPtr<nsIScriptSecurityManager> ssm = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) { char codebase[512]; rv = securityContext->GetOrigin(codebase, sizeof(codebase) - 1); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIURI> codebaseURI; rv = NS_NewURI(getter_AddRefs(codebaseURI), nsDependentCString(codebase)); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIPrincipal> principal; rv = ssm->GetCodebasePrincipal(codebaseURI, getter_AddRefs(principal)); if (NS_SUCCEEDED(rv)) { JSPrincipals* jsprincipals; principal->GetJSPrincipals(pJSContext, &jsprincipals); return jsprincipals; } } } } } else { nsCOMPtr<nsIPrincipal> principal = do_QueryInterface(credentials); if (principal) { JSPrincipals* jsprincipals; principal->GetJSPrincipals(pJSContext, &jsprincipals); return jsprincipals; } } return NULL;
nsresult rv; nsCOMPtr<nsIScriptSecurityManager> secMan = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return NULL;  nsCOMPtr<nsIPrincipal> principal; rv = secMan->GetPrincipalFromContext(pJSContext, getter_AddRefs(principal)); if (NS_FAILED(rv)) return NULL;  JSPrincipals* jsprincipals = NULL; principal->GetJSPrincipals(pJSContext, &jsprincipals); return jsprincipals;
get_JSPrincipals_from_java_caller_impl(JNIEnv *pJNIEnv, JSContext *pJSContext, void  **ppNSIPrincipalArrayIN, int numPrincipals, void *pNSISecurityContext){    nsISupports* credentials = NS_REINTERPRET_CAST(nsISupports*, pNSISecurityContext);    nsCOMPtr<nsISecurityContext> securityContext = do_QueryInterface(credentials);    if (securityContext) {        nsresult rv;        nsCOMPtr<nsIScriptSecurityManager> ssm = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);        if (NS_SUCCEEDED(rv)) {            char codebase[512];            rv = securityContext->GetOrigin(codebase, sizeof(codebase) - 1);            if (NS_SUCCEEDED(rv)) {                nsCOMPtr<nsIURI> codebaseURI;                rv = NS_NewURI(getter_AddRefs(codebaseURI), nsDependentCString(codebase));                if (NS_SUCCEEDED(rv)) {                    nsCOMPtr<nsIPrincipal> principal;                    rv = ssm->GetCodebasePrincipal(codebaseURI, getter_AddRefs(principal));                    if (NS_SUCCEEDED(rv)) {                        JSPrincipals* jsprincipals;                        principal->GetJSPrincipals(pJSContext, &jsprincipals);                        return jsprincipals;                    }                }            }        }    } else {        nsCOMPtr<nsIPrincipal> principal = do_QueryInterface(credentials);        if (principal) {            JSPrincipals* jsprincipals;            principal->GetJSPrincipals(pJSContext, &jsprincipals);            return jsprincipals;        }    }    return NULL;}