Back to index

lightning-sunbird  0.9+nobinonly
Functions
nsXPITriggerInfo.cpp File Reference
#include "nscore.h"
#include "nsXPITriggerInfo.h"
#include "nsNetUtil.h"
#include "nsDebug.h"
#include "nsIServiceManager.h"
#include "nsIEventQueueService.h"
#include "nsIJSContextStack.h"
#include "nsIScriptSecurityManager.h"
#include "nsICryptoHash.h"

Go to the source code of this file.

Functions

static NS_DEFINE_IID (kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID)
static void destroyTriggerEvent (XPITriggerEvent *event)
static voidhandleTriggerEvent (XPITriggerEvent *event)

Function Documentation

static void destroyTriggerEvent ( XPITriggerEvent event) [static]

Definition at line 240 of file nsXPITriggerInfo.cpp.

{
    JS_BeginRequest(event->cx);
    JS_RemoveRoot( event->cx, &event->cbval );
    JS_EndRequest(event->cx);
    delete event;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void* handleTriggerEvent ( XPITriggerEvent event) [static]

Definition at line 248 of file nsXPITriggerInfo.cpp.

{
    jsval  ret;
    void*  mark;
    jsval* args;

    JS_BeginRequest(event->cx);
    args = JS_PushArguments( event->cx, &mark, "Wi",
                             event->URL.get(),
                             event->status );
    if ( args )
    {
        // This code is all in a JS request, and here we're about to
        // push the context onto the context stack and also push
        // arguments. Be very very sure that no early returns creep in
        // here w/o doing the proper cleanup!

        const char *errorStr = nsnull;

        nsCOMPtr<nsIJSContextStack> stack =
            do_GetService("@mozilla.org/js/xpc/ContextStack;1");
        if (stack)
            stack->Push(event->cx);
        
        nsCOMPtr<nsIScriptSecurityManager> secman = 
            do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
        
        if (!secman)
        {
            errorStr = "Could not get script security manager service";
        }

        nsCOMPtr<nsIPrincipal> principal;
        if (!errorStr)
        {
            secman->GetSubjectPrincipal(getter_AddRefs(principal));
            if (!principal)
            {
                errorStr = "Could not get principal from script security manager";
            }
        }

        if (!errorStr)
        {
            PRBool equals = PR_FALSE;
            principal->Equals(event->princ, &equals);

            if (!equals)
            {
                errorStr = "Principal of callback context is different than InstallTriggers";
            }
        }

        if (errorStr)
        {
            JS_ReportError(event->cx, errorStr);
        }
        else
        {
            JS_CallFunctionValue(event->cx,
                                 JSVAL_TO_OBJECT(event->global),
                                 event->cbval,
                                 2,
                                 args,
                                 &ret);
        }

        if (stack)
            stack->Pop(nsnull);

        JS_PopArguments( event->cx, mark );
    }
    JS_EndRequest(event->cx);

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function: