Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
nsSecurityManagerFactory.cpp File Reference
#include "nsCOMPtr.h"
#include "nsIModule.h"
#include "nsIGenericFactory.h"
#include "nsIScriptSecurityManager.h"
#include "nsScriptSecurityManager.h"
#include "nsIPrincipal.h"
#include "nsPrincipal.h"
#include "nsSystemPrincipal.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsIScriptExternalNameSet.h"
#include "nsIScriptContext.h"
#include "nsICategoryManager.h"
#include "nsXPIDLString.h"
#include "nsIServiceManager.h"
#include "nsString.h"
#include "nsPrefsCID.h"

Go to the source code of this file.

Classes

class  nsSecurityNameSet

Defines

#define NS_SECURITYNAMESET_CID
#define NS_SECURITYNAMESET_CONTRACTID   "@mozilla.org/security/script/nameset;1"

Functions

static char * getStringArgument (JSContext *cx, JSObject *obj, PRUint16 argNum, uintN argc, jsval *argv)
static void getUTF8StringArgument (JSContext *cx, JSObject *obj, PRUint16 argNum, uintN argc, jsval *argv, nsCString &aRetval)
 netscape_security_isPrivilegeEnabled (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 netscape_security_enablePrivilege (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 netscape_security_disablePrivilege (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 netscape_security_revertPrivilege (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 netscape_security_setCanEnablePrivilege (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 netscape_security_invalidate (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR (nsSystemPrincipal, nsScriptSecurityManager::SystemPrincipalSingletonConstructor) static NS_IMETHODIMP Construct_nsIScriptSecurityManager(nsISupports *aOuter
void PR_CALLBACK CapsModuleDtor (nsIModule *thisModules)

Variables

static JSFunctionSpec PrivilegeManager_static_methods []
REFNSIID aIID

Define Documentation

Value:
{ 0x7c02eadc, 0x76, 0x4d03, \
 { 0x99, 0x8d, 0x80, 0xd7, 0x79, 0xc4, 0x85, 0x89 } }

Definition at line 61 of file nsSecurityManagerFactory.cpp.

#define NS_SECURITYNAMESET_CONTRACTID   "@mozilla.org/security/script/nameset;1"

Definition at line 64 of file nsSecurityManagerFactory.cpp.


Function Documentation

Definition at line 469 of file nsSecurityManagerFactory.cpp.

Here is the call graph for this function:

static char* getStringArgument ( JSContext cx,
JSObject obj,
PRUint16  argNum,
uintN  argc,
jsval argv 
) [static]

Definition at line 88 of file nsSecurityManagerFactory.cpp.

{
    if (argc <= argNum || !JSVAL_IS_STRING(argv[argNum])) {
        JS_ReportError(cx, "String argument expected");
        return nsnull;
    }

    /*
     * We don't want to use JS_ValueToString because we want to be able
     * to have an object to represent a target in subsequent versions.
     */
    JSString *str = JSVAL_TO_STRING(argv[argNum]);
    if (!str)
        return nsnull;

    return JS_GetStringBytes(str);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void getUTF8StringArgument ( JSContext cx,
JSObject obj,
PRUint16  argNum,
uintN  argc,
jsval argv,
nsCString aRetval 
) [static]

Definition at line 107 of file nsSecurityManagerFactory.cpp.

{
    if (argc <= argNum || !JSVAL_IS_STRING(argv[argNum])) {
        JS_ReportError(cx, "String argument expected");
        aRetval.Truncate();
        return;
    }

    /*
     * We don't want to use JS_ValueToString because we want to be able
     * to have an object to represent a target in subsequent versions.
     */
    JSString *str = JSVAL_TO_STRING(argv[argNum]);
    if (!str) {
        aRetval.Truncate();
        return;
    }

    PRUnichar *data = (PRUnichar*)JS_GetStringChars(str);
    CopyUTF16toUTF8(data, aRetval);
}

Here is the call graph for this function:

Here is the caller graph for this function:

netscape_security_disablePrivilege ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
)

Definition at line 176 of file nsSecurityManagerFactory.cpp.

{
    char *cap = getStringArgument(cx, obj, 0, argc, argv);
    if (!cap)
        return JS_FALSE;

    nsresult rv;
    nsCOMPtr<nsIScriptSecurityManager> securityManager = 
             do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
    if (NS_FAILED(rv)) 
        return JS_FALSE;

    //    NS_ASSERTION(cx == GetCurrentContext(), "unexpected context");

    rv = securityManager->DisableCapability(cap);
    if (NS_FAILED(rv))
        return JS_FALSE;
    return JS_TRUE;
}

Here is the call graph for this function:

netscape_security_enablePrivilege ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
)

Definition at line 154 of file nsSecurityManagerFactory.cpp.

{
    char *cap = getStringArgument(cx, obj, 0, argc, argv);
    if (!cap)
        return JS_FALSE;

    nsresult rv;
    nsCOMPtr<nsIScriptSecurityManager> securityManager = 
             do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
    if (NS_FAILED(rv)) 
        return JS_FALSE;

    //    NS_ASSERTION(cx == GetCurrentContext(), "unexpected context");

    rv = securityManager->EnableCapability(cap);
    if (NS_FAILED(rv))
        return JS_FALSE;
    return JS_TRUE;
}

Here is the call graph for this function:

netscape_security_invalidate ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
)

Definition at line 246 of file nsSecurityManagerFactory.cpp.

{
    nsCAutoString principalFingerprint;
    getUTF8StringArgument(cx, obj, 0, argc, argv, principalFingerprint);
    if (principalFingerprint.IsEmpty())
        return JS_FALSE;

    nsresult rv;
    nsCOMPtr<nsIScriptSecurityManager> securityManager = 
             do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
    if (NS_FAILED(rv)) 
        return JS_FALSE;

    //    NS_ASSERTION(cx == GetCurrentContext(), "unexpected context");

    rv = securityManager->SetCanEnableCapability(principalFingerprint,
                                                 nsPrincipal::sInvalid,
                                                 nsIPrincipal::ENABLE_GRANTED);
    if (NS_FAILED(rv))
        return JS_FALSE;
    return JS_TRUE;
}

Here is the call graph for this function:

netscape_security_isPrivilegeEnabled ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
)

Definition at line 131 of file nsSecurityManagerFactory.cpp.

{
    JSBool result = JS_FALSE;
    char *cap = getStringArgument(cx, obj, 0, argc, argv);
    if (cap) {
        nsresult rv;
        nsCOMPtr<nsIScriptSecurityManager> securityManager = 
                 do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
        if (NS_SUCCEEDED(rv)) {
            //            NS_ASSERTION(cx == GetCurrentContext(), "unexpected context");

            rv = securityManager->IsCapabilityEnabled(cap, &result);
            if (NS_FAILED(rv)) 
                result = JS_FALSE;
        }
    }
    *rval = BOOLEAN_TO_JSVAL(result);
    return JS_TRUE;
}

Here is the call graph for this function:

netscape_security_revertPrivilege ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
)

Definition at line 198 of file nsSecurityManagerFactory.cpp.

{
    char *cap = getStringArgument(cx, obj, 0, argc, argv);
    if (!cap)
        return JS_FALSE;

    nsresult rv;
    nsCOMPtr<nsIScriptSecurityManager> securityManager = 
             do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
    if (NS_FAILED(rv)) 
        return JS_FALSE;

    //    NS_ASSERTION(cx == GetCurrentContext(), "unexpected context");

    rv = securityManager->RevertCapability(cap);
    if (NS_FAILED(rv))
        return JS_FALSE;
    return JS_TRUE;
}

Here is the call graph for this function:

netscape_security_setCanEnablePrivilege ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
)

Definition at line 220 of file nsSecurityManagerFactory.cpp.

{
    if (argc < 2) return JS_FALSE;
    nsCAutoString principalFingerprint;
    getUTF8StringArgument(cx, obj, 0, argc, argv, principalFingerprint);
    char *cap = getStringArgument(cx, obj, 1, argc, argv);
    if (principalFingerprint.IsEmpty() || !cap)
        return JS_FALSE;

    nsresult rv;
    nsCOMPtr<nsIScriptSecurityManager> securityManager = 
             do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
    if (NS_FAILED(rv)) 
        return JS_FALSE;

    //    NS_ASSERTION(cx == GetCurrentContext(), "unexpected context");

    rv = securityManager->SetCanEnableCapability(principalFingerprint, cap, 
                                                 nsIPrincipal::ENABLE_GRANTED);
    if (NS_FAILED(rv))
        return JS_FALSE;
    return JS_TRUE;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 349 of file nsSecurityManagerFactory.cpp.

Initial value:
 {
    { "isPrivilegeEnabled", netscape_security_isPrivilegeEnabled,   1},
    { "enablePrivilege",    netscape_security_enablePrivilege,      1},
    { "disablePrivilege",   netscape_security_disablePrivilege,     1},
    { "revertPrivilege",    netscape_security_revertPrivilege,      1},
    
    { "setCanEnablePrivilege", netscape_security_setCanEnablePrivilege,   2},
    { "invalidate",            netscape_security_invalidate,              1},
    {0}
}

Definition at line 270 of file nsSecurityManagerFactory.cpp.