*aReturn = nsnull;
nsresult rv; if (!aQualifiedName.IsEmpty()) { rv = nsContentUtils::CheckQName(aQualifiedName); NS_ENSURE_SUCCESS(rv, rv); }
nsDOMImplementation::CreateDocument(const nsAString& aNamespaceURI,                                    const nsAString& aQualifiedName,                                    nsIDOMDocumentType* aDoctype,                                    nsIDOMDocument** aReturn){  NS_ENSURE_ARG_POINTER(aReturn);  *aReturn = nsnull;  if (aDoctype) {    nsCOMPtr<nsIDOMDocument> owner;    aDoctype->GetOwnerDocument(getter_AddRefs(owner));    if (owner) {      return NS_ERROR_DOM_WRONG_DOCUMENT_ERR;    }  }  nsresult rv = NS_NewDOMDocument(aReturn, aNamespaceURI, aQualifiedName,                                  aDoctype, mBaseURI);  nsIDocShell *docShell = nsContentUtils::GetDocShellFromCaller();  if (docShell) {    nsCOMPtr<nsIPresContext> presContext;    docShell->GetPresContext(getter_AddRefs(presContext));    if (presContext) {      nsCOMPtr<nsISupports> container = presContext->GetContainer();      nsCOMPtr<nsIDocument> document = do_QueryInterface(*aReturn);      if (document) {        document->SetContainer(container);      }    }  }  return rv;}