mOwnerDocument->GetShellAt(0, getter_AddRefs(shell));
doc->GetShellAt(0, getter_AddRefs(shell));
nsHTMLImageElement::SetSrcInner(nsIURI* aBaseURL,                                const nsAReadableString& aSrc){  nsresult result = SetAttr(kNameSpaceID_HTML, nsHTMLAtoms::src, aSrc,                            PR_TRUE);  if (NS_SUCCEEDED(result) && mOwnerDocument) {    nsCOMPtr<nsIPresShell> shell;    mOwnerDocument->GetShellAt(0, getter_AddRefs(shell));    if (shell) {      nsCOMPtr<nsIPresContext> context;      result = shell->GetPresContext(getter_AddRefs(context));      if (context) {        nsSize size;        nsHTMLValue val;        float p2t;        context->GetScaledPixelsToTwips(&p2t);        result = GetHTMLAttribute(nsHTMLAtoms::width, val);        if (NS_CONTENT_ATTR_HAS_VALUE == result) {          size.width = NSIntPixelsToTwips(val.GetIntValue(), p2t);        }        else {          size.width = 0;        }        result = GetHTMLAttribute(nsHTMLAtoms::height, val);        if (NS_CONTENT_ATTR_HAS_VALUE == result) {          size.height = NSIntPixelsToTwips(val.GetIntValue(), p2t);        }        else {          size.height = 0;        }        nsAutoString url;        if (aBaseURL) {          result = NS_MakeAbsoluteURI(url, aSrc, aBaseURL);          if (NS_FAILED(result)) {            url.Assign(aSrc);          }        }        else {          url.Assign(aSrc);        }        nsSize* specifiedSize = nsnull;        if ((size.width > 0) || (size.height > 0)) {          specifiedSize = &size;        }        nsCOMPtr<nsIURI> uri;        result = NS_NewURI(getter_AddRefs(uri), aSrc, 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<nsISupports> sup(do_QueryInterface(context));        nsCOMPtr<nsIDocument> doc;        nsCOMPtr<nsILoadGroup> loadGroup;        shell->GetDocument(getter_AddRefs(doc));        if (doc) {          doc->GetDocumentLoadGroup(getter_AddRefs(loadGroup));        }        il->LoadImage(uri, loadGroup, this, sup, nsIRequest::LOAD_NORMAL,                      nsnull, nsnull, getter_AddRefs(mRequest));      }    }    // Only do this the first time since it's only there for    // backwards compatability    NS_RELEASE(mOwnerDocument);  }  return result;}