NS_ENSURE_ARG_POINTER(mChannel);
nsEvaluateStringProxy::EvaluateString(char **aRetValue, PRBool *aIsUndefined){    nsresult rv;        NS_ENSURE_ARG_POINTER(mChannel);    nsCOMPtr<nsIInterfaceRequestor> callbacks;    rv = mChannel->GetNotificationCallbacks(getter_AddRefs(callbacks));    if (NS_FAILED(rv)) return rv;    // The event sink must be a script global Object Owner or we fail.    nsCOMPtr<nsIScriptGlobalObjectOwner> globalOwner;    callbacks->GetInterface(NS_GET_IID(nsIScriptGlobalObjectOwner),                            getter_AddRefs(globalOwner));    NS_ENSURE_TRUE(globalOwner, NS_ERROR_FAILURE);    // So far so good: get the script context from its owner.    nsCOMPtr<nsIScriptGlobalObject> global;    globalOwner->GetScriptGlobalObject(getter_AddRefs(global));    NS_ENSURE_TRUE(global, NS_ERROR_FAILURE);    nsCOMPtr<nsIScriptContext> scriptContext;    rv = global->GetContext(getter_AddRefs(scriptContext));    if (NS_FAILED(rv)) return rv;    // Get principal of code for execution    NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager,                    NS_SCRIPTSECURITYMANAGER_PROGID, &rv);    if (NS_FAILED(rv)) return rv;    // Get principal    nsCOMPtr<nsIPrincipal> principal;    nsCOMPtr<nsIURI> referringUri;    // XXX this is wrong: see bugs 31818 and 29831. Norris is looking at it.    rv = mChannel->GetOriginalURI(getter_AddRefs(referringUri));    if (NS_FAILED(rv)) {        // No referrer available. Use the current javascript: URI, which will mean         // that this script will be in another trust domain than any other script        // since SameOrigin should be false for anything other than the same        // javascript: URI.#if 0        nsCOMPtr<nsIDocShell> docShell;        docShell = do_QueryInterface(globalOwner, &rv);        if (NS_FAILED(rv)) return rv;        rv = docShell->GetCurrentURI(getter_AddRefs(referringUri));#else        rv = mChannel->GetURI(getter_AddRefs(referringUri));#endif        if (NS_FAILED(rv)) return rv;    }    rv = securityManager->GetCodebasePrincipal(referringUri,                                                getter_AddRefs(principal));    if (NS_FAILED(rv)) return rv;    nsCOMPtr<nsIURI> jsURI;    rv = mChannel->GetURI(getter_AddRefs(jsURI));    if (NS_FAILED(rv)) return rv;    nsXPIDLCString script;    rv = jsURI->GetPath(getter_Copies(script));    if (NS_FAILED(rv)) return rv;    // Finally, we have everything needed to evaluate the expression.    nsString result;    rv = scriptContext->EvaluateString(nsString(script),                                       nsnull,  // obj                                       principal,                                       nsnull,  // url                                       0,       // line no                                       nsnull,                                       result,                                       aIsUndefined);    // XXXbe this should not decimate! pass back UCS-2 to necko    *aRetValue = result.ToNewCString();    return rv;}