Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
nsReadConfig.cpp File Reference
#include "nsReadConfig.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsIAppStartup.h"
#include "nsDirectoryServiceDefs.h"
#include "nsIAutoConfig.h"
#include "nsIComponentManager.h"
#include "nsIFile.h"
#include "nsIObserverService.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsIPromptService.h"
#include "nsIServiceManager.h"
#include "nsIStringBundle.h"
#include "nsXPFEComponentsCID.h"
#include "nsXPIDLString.h"
#include "nsNetUtil.h"
#include "prmem.h"
#include "nsString.h"
#include "nsCRT.h"
#include "nspr.h"

Go to the source code of this file.


nsresult EvaluateAdminConfigScript (const char *js_buffer, size_t length, const char *filename, PRBool bGlobalContext, PRBool bCallbacks, PRBool skipFirstLine)
nsresult CentralizedAdminPrefManagerInit ()
nsresult CentralizedAdminPrefManagerFinish ()
static void DisplayError (void)



Function Documentation

Definition at line 178 of file nsJSConfigTriggers.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 124 of file nsJSConfigTriggers.cpp.

    nsresult rv;
    JSRuntime *rt;

    // If autoconfig_cx already created, no need to create it again
    if (autoconfig_cx) 
        return NS_OK;

    // We need the XPCONNECT service
    nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID(), &rv);
    if (NS_FAILED(rv)) {
        return rv;

    // Get the JS RunTime
    nsCOMPtr<nsIJSRuntimeService> rtsvc = 
        do_GetService(";1", &rv);
    if (NS_SUCCEEDED(rv))
        rv = rtsvc->GetRuntime(&rt);

    if (NS_FAILED(rv)) {
        NS_ERROR("Couldn't get JS RunTime");
        return rv;

    // Create a new JS context for autoconfig JS script
    autoconfig_cx = JS_NewContext(rt, 1024);
    if (!autoconfig_cx)
        return NS_ERROR_OUT_OF_MEMORY;

    JS_SetErrorReporter(autoconfig_cx, autoConfigErrorReporter);

    // Create a new Security Manger and set it for the new JS context
    nsCOMPtr<nsIXPCSecurityManager> secman =
        NS_STATIC_CAST(nsIXPCSecurityManager*, new AutoConfigSecMan());
    xpc->SetSecurityManagerForJSContext(autoconfig_cx, secman, 0);

    autoconfig_glob = JS_NewObject(autoconfig_cx, &global_class, NULL, NULL);
    if (autoconfig_glob) {
        if (JS_InitStandardClasses(autoconfig_cx, autoconfig_glob)) {
            // XPCONNECT enable this JS context
            rv = xpc->InitClasses(autoconfig_cx, autoconfig_glob);
            if (NS_SUCCEEDED(rv)) 
                return NS_OK;

    // failue exit... clean up the JS context
    autoconfig_cx = nsnull;
    return NS_ERROR_FAILURE;

Here is the call graph for this function:

Here is the caller graph for this function:

static void DisplayError ( void  ) [static]

Definition at line 76 of file nsReadConfig.cpp.

    nsresult rv;

    nsCOMPtr<nsIPromptService> promptService = do_GetService(";1");
    if (!promptService)

    nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID);
    if (!bundleService)

    nsCOMPtr<nsIStringBundle> bundle;
    if (!bundle)

    nsXPIDLString title;
    rv = bundle->GetStringFromName(NS_LITERAL_STRING("readConfigTitle").get(), getter_Copies(title));
    if (NS_FAILED(rv))

    nsXPIDLString err;
    rv = bundle->GetStringFromName(NS_LITERAL_STRING("readConfigMsg").get(), getter_Copies(err));
    if (NS_FAILED(rv))

    promptService->Alert(nsnull, title.get(), err.get());

Here is the call graph for this function:

nsresult EvaluateAdminConfigScript ( const char *  js_buffer,
size_t  length,
const char *  filename,
PRBool  bGlobalContext,
PRBool  bCallbacks,
PRBool  skipFirstLine 

Definition at line 185 of file nsJSConfigTriggers.cpp.

    JSBool ok;
    jsval result;

    if (skipFirstLine) {
        /* In order to protect the privacy of the JavaScript preferences file 
         * from loading by the browser, we make the first line unparseable
         * by JavaScript. We must skip that line here before executing 
         * the JavaScript code.
        unsigned int i = 0;
        while (i < length) {
            char c = js_buffer[i++];
            if (c == '\r') {
                if (js_buffer[i] == '\n')
            if (c == '\n')

        length -= i;
        js_buffer += i;

    nsresult rv;
    nsCOMPtr<nsIJSContextStack> cxstack = 
    rv = cxstack->Push(autoconfig_cx);
    if (NS_FAILED(rv)) {
        NS_ERROR("coudn't push the context on the stack");
        return rv;

    ok = JS_EvaluateScript(autoconfig_cx, autoconfig_glob,
                           js_buffer, length, filename, 0, &result);


    JSContext *cx;
    NS_ASSERTION(cx == autoconfig_cx, "AutoConfig JS contexts didn't match");

    if (ok)
        return NS_OK;
    return NS_ERROR_FAILURE;

Here is the call graph for this function:

Variable Documentation

Definition at line 59 of file nsAutoConfig.cpp.