nsresult nsVideoFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements) { nsNodeInfoManager *nodeInfoManager = GetContent()->GetCurrentDoc()->NodeInfoManager(); nsCOMPtr<nsINodeInfo> nodeInfo; if (HasVideoElement()) { // Create an anonymous image element as a child to hold the poster // image. We may not have a poster image now, but one could be added // before we load, or on a subsequent load. nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::img, nsnull, kNameSpaceID_XHTML); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); mPosterImage = NS_NewHTMLImageElement(nodeInfo); NS_ENSURE_TRUE(mPosterImage, NS_ERROR_OUT_OF_MEMORY); // Set the nsImageLoadingContent::ImageState() to 0. This means that the // image will always report its state as 0, so it will never be reframed // to show frames for loading or the broken image icon. This is important, // as the image is native anonymous, and so can't be reframed (currently). nsCOMPtr<nsIImageLoadingContent> imgContent = do_QueryInterface(mPosterImage); NS_ENSURE_TRUE(imgContent, NS_ERROR_FAILURE); imgContent->ForceImageState(PR_TRUE, 0); nsresult res = UpdatePosterSource(PR_FALSE); NS_ENSURE_SUCCESS(res,res); if (!aElements.AppendElement(mPosterImage)) return NS_ERROR_OUT_OF_MEMORY; } // Set up "videocontrols" XUL element which will be XBL-bound to the // actual controls. nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::videocontrols, nsnull, kNameSpaceID_XUL); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); nsresult rv = NS_NewElement(getter_AddRefs(mVideoControls), kNameSpaceID_XUL, nodeInfo, PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); if (!aElements.AppendElement(mVideoControls)) return NS_ERROR_OUT_OF_MEMORY; return NS_OK; }
static NS_IMETHODIMP CreateHTMLImgElement(nsISupports* aOuter, REFNSIID aIID, void** aResult) { *aResult = nsnull; if (aOuter) return NS_ERROR_NO_AGGREGATION; // Note! NS_NewHTMLImageElement is special cased to handle a null nodeinfo nsIContent* inst = NS_NewHTMLImageElement(nsnull); nsresult rv = NS_ERROR_OUT_OF_MEMORY; if (inst) { NS_ADDREF(inst); rv = inst->QueryInterface(aIID, aResult); NS_RELEASE(inst); } return rv; }
nsresult ImageDocument::CreateSyntheticDocument() { // Synthesize an html document that refers to the image nsresult rv = MediaDocument::CreateSyntheticDocument(); NS_ENSURE_SUCCESS(rv, rv); // Add the image element Element* body = GetBodyElement(); if (!body) { NS_WARNING("no body on image document!"); return NS_ERROR_FAILURE; } nsCOMPtr<nsINodeInfo> nodeInfo; nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::img, nullptr, kNameSpaceID_XHTML, nsIDOMNode::ELEMENT_NODE); mImageContent = NS_NewHTMLImageElement(nodeInfo.forget()); if (!mImageContent) { return NS_ERROR_OUT_OF_MEMORY; } nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mImageContent); NS_ENSURE_TRUE(imageLoader, NS_ERROR_UNEXPECTED); nsAutoCString src; mDocumentURI->GetSpec(src); // Push a null JSContext on the stack so that code that runs within // the below code doesn't think it's being called by JS. See bug // 604262. nsCxPusher pusher; pusher.PushNull(); NS_ConvertUTF8toUTF16 srcString(src); // Make sure not to start the image load from here... imageLoader->SetLoadingEnabled(false); mImageContent->SetAttr(kNameSpaceID_None, nsGkAtoms::src, srcString, false); mImageContent->SetAttr(kNameSpaceID_None, nsGkAtoms::alt, srcString, false); body->AppendChildTo(mImageContent, false); imageLoader->SetLoadingEnabled(true); return NS_OK; }