Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Attributes
AutoPushJSContext Class Reference
Collaboration diagram for AutoPushJSContext:
Collaboration graph

List of all members.

Public Member Functions

 AutoPushJSContext (nsISupports *aSecuritySupports, JSContext *cx)
 ~AutoPushJSContext ()
nsresult ResultOfPush ()

Private Attributes

nsCOMPtr< nsIJSContextStackmContextStack
JSStackFrame mFrame
nsresult mPushResult

Detailed Description

Definition at line 92 of file nsCLiveconnect.cpp.

Constructor & Destructor Documentation

AutoPushJSContext::AutoPushJSContext ( nsISupports *  aSecuritySupports,
JSContext cx 

Definition at line 109 of file nsCLiveconnect.cpp.

                                     : mContext(cx), mPushResult(NS_OK)
    nsCOMPtr<nsIJSContextStack> contextStack =

    JSContext* currentCX;
    if(contextStack &&
       // Don't push if the current context is already on the stack.
       (NS_FAILED(contextStack->Peek(&currentCX)) ||
        cx != currentCX) )
        if (NS_SUCCEEDED(contextStack->Push(cx)))
            // Leave the reference in mContextStack to
            // indicate that we need to pop it in our dtor.

    nsCOMPtr<nsIScriptSecurityManager> secMan(
        do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &mPushResult));

    if (NS_FAILED(mPushResult))

    nsCOMPtr<nsIPrincipal> principal;
    mPushResult = secMan->GetPrincipalFromContext(cx, getter_AddRefs(principal));

    if (NS_FAILED(mPushResult))
        JS_ReportError(cx, "failed to get a principal");

    // See if JavaScript is enabled for the current window
    PRBool jsEnabled = PR_FALSE;
    mPushResult = secMan->CanExecuteScripts(cx, principal, &jsEnabled);
    if (!jsEnabled)
        mPushResult = NS_ERROR_FAILURE;

    memset(&mFrame, 0, sizeof(mFrame));

    if (NS_SUCCEEDED(mPushResult))
        // See if there are any scripts on the stack.
        // If not, we need to add a dummy frame with a principal.

        PRBool hasScript = PR_FALSE;
        JSStackFrame* tempFP = cx->fp;
        while (tempFP)
            if (tempFP->script)
                hasScript = PR_TRUE;
            tempFP = tempFP->down;

        if (!hasScript)
            JSPrincipals* jsprinc;
            principal->GetJSPrincipals(cx, &jsprinc);

            mFrame.script = JS_CompileScriptForPrincipals(cx, JS_GetGlobalObject(cx),
                                                          jsprinc, "", 0, "", 1);
            JSPRINCIPALS_DROP(cx, jsprinc);

            if (mFrame.script)
                mFrame.down = cx->fp;
                cx->fp = &mFrame;
                mPushResult = NS_ERROR_OUT_OF_MEMORY;

Here is the call graph for this function:

Definition at line 190 of file nsCLiveconnect.cpp.

Member Function Documentation

Definition at line 100 of file nsCLiveconnect.cpp.

{ return mPushResult; };

Here is the caller graph for this function:

Member Data Documentation

Definition at line 104 of file nsCLiveconnect.cpp.

Definition at line 100 of file nsCLiveconnect.cpp.

Definition at line 105 of file nsCLiveconnect.cpp.

Definition at line 106 of file nsCLiveconnect.cpp.

The documentation for this class was generated from the following file: