Back to index

lightning-sunbird  0.9+nobinonly
nsJSPrincipals.cpp File Reference
#include "nsString.h"
#include "nsIObjectOutputStream.h"
#include "nsIObjectInputStream.h"
#include "nsJSPrincipals.h"
#include "plstr.h"
#include "nsXPIDLString.h"
#include "nsCOMPtr.h"
#include "jsapi.h"
#include "jsxdrapi.h"
#include "nsIJSRuntimeService.h"
#include "nsIServiceManager.h"
#include "nsMemory.h"

Go to the source code of this file.


 nsGetPrincipalArray (JSContext *cx, JSPrincipals *prin)
 nsGlobalPrivilegesEnabled (JSContext *cx, JSPrincipals *jsprin)
 nsJSPrincipalsSubsume (JSPrincipals *jsprin, JSPrincipals *other)
 nsDestroyJSPrincipals (JSContext *cx, struct JSPrincipals *jsprin)
 nsTranscodeJSPrincipals (JSXDRState *xdr, JSPrincipals **jsprinp)

Function Documentation

nsDestroyJSPrincipals ( JSContext cx,
struct JSPrincipals jsprin 

Definition at line 76 of file nsJSPrincipals.cpp.

    nsJSPrincipals *nsjsprin = NS_STATIC_CAST(nsJSPrincipals *, jsprin);

    // We need to destroy the nsIPrincipal. We'll do this by adding
    // to the refcount and calling release

    // Note that we don't want to use NS_IF_RELEASE because it will try
    // to set nsjsprin->nsIPrincipalPtr to nsnull *after* nsjsprin has
    // already been destroyed.
    // The refcount logging considers AddRef-to-1 to indicate creation,
    // so trick it into thinking it's otherwise, but balance the
    // Release() we do below.
    if (nsjsprin->nsIPrincipalPtr)
    // The nsIPrincipal that we release owns the JSPrincipal struct,
    // so we don't need to worry about "codebase"

Here is the caller graph for this function:

nsGetPrincipalArray ( JSContext cx,
JSPrincipals prin 

Definition at line 52 of file nsJSPrincipals.cpp.

    return nsnull;

Here is the caller graph for this function:

Definition at line 58 of file nsJSPrincipals.cpp.

    return JS_TRUE;

Here is the caller graph for this function:

nsJSPrincipalsSubsume ( JSPrincipals jsprin,
JSPrincipals other 

Definition at line 64 of file nsJSPrincipals.cpp.

    nsJSPrincipals *nsjsprin = NS_STATIC_CAST(nsJSPrincipals *, jsprin);
    nsJSPrincipals *nsother  = NS_STATIC_CAST(nsJSPrincipals *, other);

    JSBool result;
    nsresult rv = nsjsprin->nsIPrincipalPtr->Subsumes(nsother->nsIPrincipalPtr,
    return NS_SUCCEEDED(rv) && result;

Here is the caller graph for this function:

nsTranscodeJSPrincipals ( JSXDRState xdr,
JSPrincipals **  jsprinp 

Definition at line 103 of file nsJSPrincipals.cpp.

    nsresult rv;

    if (xdr->mode == JSXDR_ENCODE) {
        nsIObjectOutputStream *stream =
            NS_REINTERPRET_CAST(nsIObjectOutputStream*, xdr->userdata);

        // Flush xdr'ed data to the underlying object output stream.
        uint32 size;
        char *data = (char*) ::JS_XDRMemGetData(xdr, &size);

        rv = stream->Write32(size);
        if (NS_SUCCEEDED(rv)) {
            rv = stream->WriteBytes(data, size);
            if (NS_SUCCEEDED(rv)) {

                // Require that GetJSPrincipals has been called already by the
                // code that compiled the script that owns the principals.
                nsJSPrincipals *nsjsprin =
                    NS_STATIC_CAST(nsJSPrincipals*, *jsprinp);

                rv = stream->WriteObject(nsjsprin->nsIPrincipalPtr, PR_TRUE);
    } else {
        NS_ASSERTION(JS_XDRMemDataLeft(xdr) == 0, "XDR out of sync?!");
        nsIObjectInputStream *stream =
            NS_REINTERPRET_CAST(nsIObjectInputStream*, xdr->userdata);

        nsCOMPtr<nsIPrincipal> prin;
        rv = stream->ReadObject(PR_TRUE, getter_AddRefs(prin));
        if (NS_SUCCEEDED(rv)) {
            PRUint32 size;
            rv = stream->Read32(&size);
            if (NS_SUCCEEDED(rv)) {
                char *data = nsnull;
                if (size != 0)
                    rv = stream->ReadBytes(size, &data);
                if (NS_SUCCEEDED(rv)) {
                    char *olddata;
                    uint32 oldsize;

                    // Any decode-mode JSXDRState whose userdata points to an
                    // nsIObjectInputStream instance must use nsMemory to Alloc
                    // and Free its data buffer.  Swap the new buffer we just
                    // read for the old, exhausted data.
                    olddata = (char*) ::JS_XDRMemGetData(xdr, &oldsize);
                    ::JS_XDRMemSetData(xdr, data, size);

                    prin->GetJSPrincipals(xdr->cx, jsprinp);

    if (NS_FAILED(rv)) {
        ::JS_ReportError(xdr->cx, "can't %scode principals (failure code %x)",
                         (xdr->mode == JSXDR_ENCODE) ? "en" : "de",
                         (unsigned int) rv);
        return JS_FALSE;
    return JS_TRUE;

Here is the call graph for this function:

Here is the caller graph for this function: