nsnull, 0,
url, 1,
nsresult nsJSThunk::EvaluateScript(){    nsresult rv;    NS_ENSURE_ARG_POINTER(mChannel);    // Get the script string to evaluate...    nsXPIDLCString script;    rv = mURI->GetPath(getter_Copies(script));    if (NS_FAILED(rv)) return rv;    // If mURI is just "javascript:", we bring up the JavaScript console    // and return NS_ERROR_DOM_RETVAL_UNDEFINED.    if (*((const char*)script) == '\0') {        rv = BringUpConsole();        if (NS_FAILED(rv)) return NS_ERROR_FAILURE;        return NS_ERROR_DOM_RETVAL_UNDEFINED;    }    // Get an interface requestor from the channel callbacks.    nsCOMPtr<nsIInterfaceRequestor> callbacks;    rv = mChannel->GetNotificationCallbacks(getter_AddRefs(callbacks));    NS_ASSERTION(NS_SUCCEEDED(rv) && callbacks,                 "Unable to get an nsIInterfaceRequestor from the channel");    if (NS_FAILED(rv) || !callbacks) {        return NS_ERROR_FAILURE;    }    // The requestor must be able to get a script global object owner.    nsCOMPtr<nsIScriptGlobalObjectOwner> globalOwner;    rv = callbacks->GetInterface(NS_GET_IID(nsIScriptGlobalObjectOwner),                                 getter_AddRefs(globalOwner));    NS_ASSERTION(NS_SUCCEEDED(rv) && globalOwner,                  "Unable to get an nsIScriptGlobalObjectOwner from the "                 "InterfaceRequestor!");    if (NS_FAILED(rv) || !globalOwner) {        return NS_ERROR_FAILURE;    }    // So far so good: get the script context from its owner.    nsCOMPtr<nsIScriptGlobalObject> global;    rv = globalOwner->GetScriptGlobalObject(getter_AddRefs(global));    NS_ASSERTION(NS_SUCCEEDED(rv) && global,                 "Unable to get an nsIScriptGlobalObject from the "                 "ScriptGlobalObjectOwner!");    if (NS_FAILED(rv) || !global) {        return NS_ERROR_FAILURE;    }    nsCOMPtr<nsIScriptContext> scriptContext;    rv = global->GetContext(getter_AddRefs(scriptContext));    if (NS_FAILED(rv))        return rv;    if (!scriptContext) return NS_ERROR_FAILURE;    // Get principal of code for execution    nsCOMPtr<nsISupports> owner;    rv = mChannel->GetOwner(getter_AddRefs(owner));    nsCOMPtr<nsIPrincipal> principal;    if (NS_FAILED(rv))        return rv;    nsCOMPtr<nsIScriptSecurityManager> securityManager;    securityManager = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);    if (NS_FAILED(rv))        return rv;    if (owner) {        principal = do_QueryInterface(owner, &rv);        NS_ASSERTION(principal, "Channel's owner is not a principal");        if (!principal)            return NS_ERROR_FAILURE;        //-- Don't run if the script principal is different from the        //   principal of the context, with two exceptions: we allow        //   the script to run if the script has the system principal        //   or the context is about:blank.        nsCOMPtr<nsIPrincipal> objectPrincipal;        rv = securityManager->GetObjectPrincipal(                                (JSContext*)scriptContext->GetNativeContext(),                                global->GetGlobalJSObject(),                                getter_AddRefs(objectPrincipal));        if (NS_FAILED(rv))            return rv;        PRBool equals = PR_FALSE;        if ((NS_FAILED(objectPrincipal->Equals(principal, &equals)) || !equals)) {            // If the principals aren't equal            nsCOMPtr<nsIPrincipal> systemPrincipal;            securityManager->GetSystemPrincipal(getter_AddRefs(systemPrincipal));            if (principal.get() != systemPrincipal.get()) {                // and the script to be run does not have the system principal                nsCOMPtr<nsICodebasePrincipal>                     objectCodebase(do_QueryInterface(objectPrincipal));                nsXPIDLCString objectOrigin;                rv = objectCodebase->GetOrigin(getter_Copies(objectOrigin));                if (PL_strcmp("about:blank", objectOrigin) != 0) {                    // and the target window is not about:blank, then                    // don't run the script. Print a message to the console and                    // return undefined.                    nsCOMPtr<nsIConsoleService>                         console(do_GetService("@mozilla.org/consoleservice;1"));                    if (console) {                            console->LogStringMessage(                                NS_LITERAL_STRING("Attempt to load a javascript: URL from one host\nin a window displaying content from another host\nwas blocked by the security manager.").get());                    }                    return NS_ERROR_DOM_RETVAL_UNDEFINED;                }            }        }    }    else {        // No owner from channel, use the current URI to generate a principal        rv = securityManager->GetCodebasePrincipal(mURI,                                                    getter_AddRefs(principal));        if (NS_FAILED(rv) || !principal) {            return NS_ERROR_FAILURE;        }    }    // Finally, we have everything needed to evaluate the expression.    nsString result;    PRBool bIsUndefined;    {        NS_ConvertUTF8toUCS2 scriptString(script);        rv = scriptContext->EvaluateString(scriptString,                                           nsnull,      // obj                                           principal,                                           nsnull,      // url                                           0,           // line no                                           nsnull,                                           result,                                           &bIsUndefined);    }    if (NS_FAILED(rv)) {        rv = NS_ERROR_MALFORMED_URI;    }    else if (bIsUndefined) {        rv = NS_ERROR_DOM_RETVAL_UNDEFINED;    }    else {        // XXXbe this should not decimate! pass back UCS-2 to necko        mResult = ToNewCString(result);        mLength = result.Length();    }    return rv;}