nsCOMPtr<nsIDocument> document; result = shell->GetDocument(getter_AddRefs(document)); if (NS_FAILED(result)) return result;
nsCOMPtr<nsIScriptGlobalObject> globalObject; result = doc->GetScriptGlobalObject(getter_AddRefs(globalObject)); if (NS_FAILED(result)) return result;
nsHTMLImageElement::SetSrcInner(nsIURI* aBaseURL,                                const nsAString& aSrc){  nsresult result = SetAttr(kNameSpaceID_None, nsHTMLAtoms::src, aSrc,                            PR_TRUE);  NS_ENSURE_SUCCESS(result, result);  if (!mDocument) {    nsCOMPtr<nsIDocument> doc;    mNodeInfo->GetDocument(*getter_AddRefs(doc));    nsCOMPtr<nsIPresShell> shell;    doc->GetShellAt(0, getter_AddRefs(shell));    if (shell) {      nsCOMPtr<nsIPresContext> context;      result = shell->GetPresContext(getter_AddRefs(context));      if (context) {        nsAutoString url;        if (aBaseURL) {          result = NS_MakeAbsoluteURI(url, aSrc, aBaseURL);          if (NS_FAILED(result)) {            url.Assign(aSrc);          }        }        else {          url.Assign(aSrc);        }        nsCOMPtr<nsIURI> uri;        result = NS_NewURI(getter_AddRefs(uri), aSrc, nsnull, aBaseURL);        if (NS_FAILED(result)) return result;        nsCOMPtr<nsIDocument> document;        result = shell->GetDocument(getter_AddRefs(document));        if (NS_FAILED(result)) return result;        nsCOMPtr<nsIScriptGlobalObject> globalObject;        result = document->GetScriptGlobalObject(getter_AddRefs(globalObject));        if (NS_FAILED(result)) return result;        nsCOMPtr<nsIDOMWindow> domWin(do_QueryInterface(globalObject));        PRBool shouldLoad = PR_TRUE;        result =          NS_CheckContentLoadPolicy(nsIContentPolicy::IMAGE,                                    uri,                                    NS_STATIC_CAST(nsIDOMHTMLImageElement *,                                                   this),                                    domWin, &shouldLoad);        if (NS_SUCCEEDED(result) && !shouldLoad) {          return NS_OK;        }        // If we have a loader we're in the middle of loading a image,        // we'll cancel that load and start a new one.        // if (mRequest) {        //   mRequest->Cancel() ?? cancel the load?        // }        nsCOMPtr<imgILoader> il(do_GetService("@mozilla.org/image/loader;1"));        if (!il) {          return NS_ERROR_FAILURE;        }        nsCOMPtr<nsIDocument> doc;        nsCOMPtr<nsILoadGroup> loadGroup;        nsCOMPtr<nsIURI> documentURI;        shell->GetDocument(getter_AddRefs(doc));        if (doc) {          doc->GetDocumentLoadGroup(getter_AddRefs(loadGroup));          // Get the documment URI for the referrer.          doc->GetDocumentURL(getter_AddRefs(documentURI));        }        // XXX: initialDocumentURI is NULL!        il->LoadImage(uri, nsnull, documentURI, loadGroup, this, context, nsIRequest::LOAD_NORMAL,                      nsnull, nsnull, getter_AddRefs(mRequest));      }    }  } else {    nsIImageFrame* imageFrame;    GetImageFrame(&imageFrame);    if (!imageFrame) {      // If we don't have an image frame, reconstruct the frame      // so that the new image can load.      nsCOMPtr<nsIPresShell> shell;      mDocument->GetShellAt(0, getter_AddRefs(shell));      if (shell) {        shell->RecreateFramesFor(this);      }    }  }  return result;}