image->SetHTMLAttribute(nsHTMLAtoms::alt, val, PR_FALSE);
nsCOMPtr<nsIStringBundle> bundle; nsCOMPtr<nsIStringBundleService> stringService = do_GetService(kStringBundleServiceCID, &rv); if (NS_SUCCEEDED(rv) && stringService) rv = stringService->CreateBundle(NSIMAGEDOCUMENT_PROPERTIES_URI, getter_AddRefs(bundle)); if (NS_SUCCEEDED(rv) && bundle) { const PRUnichar* formatString[1] = { src_string.get() }; nsXPIDLString errorMsg; rv = bundle->FormatStringFromName(NS_LITERAL_STRING("InvalidImage").get(), formatString, 1, getter_Copies(errorMsg));  nsHTMLValue errorText(errorMsg); image->SetHTMLAttribute(nsHTMLAtoms::alt, errorText, PR_FALSE); }
nsImageDocument::CreateSyntheticDocument(){  // Synthesize an html document that refers to the image  nsresult rv;  nsCOMPtr<nsINodeInfo> nodeInfo;  rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::html, nsnull,                                     kNameSpaceID_None,                                     *getter_AddRefs(nodeInfo));  NS_ENSURE_SUCCESS(rv, rv);  nsIHTMLContent* root;  rv = NS_NewHTMLHtmlElement(&root, nodeInfo);  if (NS_OK != rv) {    return rv;  }  root->SetDocument(this, PR_FALSE, PR_TRUE);  SetRootContent(root);  rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::body, nsnull,                                     kNameSpaceID_None,                                     *getter_AddRefs(nodeInfo));  NS_ENSURE_SUCCESS(rv, rv);  nsIHTMLContent* body;  rv = NS_NewHTMLBodyElement(&body, nodeInfo);  if (NS_OK != rv) {    return rv;  }  body->SetDocument(this, PR_FALSE, PR_TRUE);  rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::p, nsnull, kNameSpaceID_None,                                     *getter_AddRefs(nodeInfo));  NS_ENSURE_SUCCESS(rv, rv);  nsIHTMLContent* center;  rv = NS_NewHTMLParagraphElement(&center, nodeInfo);  if (NS_OK != rv) {    return rv;  }  center->SetDocument(this, PR_FALSE, PR_TRUE);  rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::img, nsnull,                                     kNameSpaceID_None,                                     *getter_AddRefs(nodeInfo));  NS_ENSURE_SUCCESS(rv, rv);  nsIHTMLContent* image;  rv = NS_NewHTMLImageElement(&image, nodeInfo);  if (NS_OK != rv) {    return rv;  }  image->SetDocument(this, PR_FALSE, PR_TRUE);  nsCAutoString src;  mDocumentURL->GetSpec(src);  NS_ConvertUTF8toUCS2 src_string(src);  nsHTMLValue val(src_string);  image->SetHTMLAttribute(nsHTMLAtoms::src, val, PR_FALSE);  image->SetHTMLAttribute(nsHTMLAtoms::alt, val, PR_FALSE);  root->AppendChildTo(body, PR_FALSE, PR_FALSE);  center->AppendChildTo(image, PR_FALSE, PR_FALSE);  body->AppendChildTo(center, PR_FALSE, PR_FALSE);  NS_RELEASE(image);  NS_RELEASE(center);  NS_RELEASE(body);  NS_RELEASE(root);  return NS_OK;}