зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1384162 part 2 - Mondernize nsContentDLF::CreateBlankDocument. r=bz
MozReview-Commit-ID: CxAeysZbbuw --HG-- extra : rebase_source : 86e3a24c20db5cd8db958333ab61e2aafa0865aa
This commit is contained in:
Родитель
1358c75c5d
Коммит
ae7bb9dd45
|
@ -8187,8 +8187,7 @@ nsDocShell::CreateAboutBlankContentViewer(nsIPrincipal* aPrincipal,
|
|||
principal = aPrincipal;
|
||||
}
|
||||
// generate (about:blank) document to load
|
||||
nsContentDLF::CreateBlankDocument(mLoadGroup, principal,
|
||||
getter_AddRefs(blankDoc));
|
||||
blankDoc = nsContentDLF::CreateBlankDocument(mLoadGroup, principal);
|
||||
if (blankDoc) {
|
||||
// Hack: set the base URI manually, since this document never
|
||||
// got Reset() with a channel.
|
||||
|
|
|
@ -263,78 +263,63 @@ nsContentDLF::CreateInstanceForDocument(nsISupports* aContainer,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* static */ nsresult
|
||||
/* static */ already_AddRefed<nsIDocument>
|
||||
nsContentDLF::CreateBlankDocument(nsILoadGroup* aLoadGroup,
|
||||
nsIPrincipal* aPrincipal,
|
||||
nsIDocument** aDocument)
|
||||
nsIPrincipal* aPrincipal)
|
||||
{
|
||||
*aDocument = nullptr;
|
||||
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
// create a new blank HTML document
|
||||
nsCOMPtr<nsIDocument> blankDoc(do_CreateInstance(kHTMLDocumentCID));
|
||||
|
||||
if (blankDoc) {
|
||||
// initialize
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING("about:blank"));
|
||||
if (uri) {
|
||||
blankDoc->ResetToURI(uri, aLoadGroup, aPrincipal);
|
||||
rv = NS_OK;
|
||||
}
|
||||
if (!blankDoc) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// initialize
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING("about:blank"));
|
||||
if (!uri) {
|
||||
return nullptr;
|
||||
}
|
||||
blankDoc->ResetToURI(uri, aLoadGroup, aPrincipal);
|
||||
|
||||
// add some simple content structure
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
nsNodeInfoManager *nim = blankDoc->NodeInfoManager();
|
||||
|
||||
nsNodeInfoManager *nim = blankDoc->NodeInfoManager();
|
||||
RefPtr<mozilla::dom::NodeInfo> htmlNodeInfo;
|
||||
|
||||
RefPtr<mozilla::dom::NodeInfo> htmlNodeInfo;
|
||||
// generate an html html element
|
||||
htmlNodeInfo = nim->GetNodeInfo(nsGkAtoms::html, 0, kNameSpaceID_XHTML,
|
||||
nsIDOMNode::ELEMENT_NODE);
|
||||
nsCOMPtr<nsIContent> htmlElement =
|
||||
NS_NewHTMLHtmlElement(htmlNodeInfo.forget());
|
||||
|
||||
// generate an html html element
|
||||
htmlNodeInfo = nim->GetNodeInfo(nsGkAtoms::html, 0, kNameSpaceID_XHTML,
|
||||
nsIDOMNode::ELEMENT_NODE);
|
||||
nsCOMPtr<nsIContent> htmlElement =
|
||||
NS_NewHTMLHtmlElement(htmlNodeInfo.forget());
|
||||
// generate an html head element
|
||||
htmlNodeInfo = nim->GetNodeInfo(nsGkAtoms::head, 0, kNameSpaceID_XHTML,
|
||||
nsIDOMNode::ELEMENT_NODE);
|
||||
nsCOMPtr<nsIContent> headElement =
|
||||
NS_NewHTMLHeadElement(htmlNodeInfo.forget());
|
||||
|
||||
// generate an html head element
|
||||
htmlNodeInfo = nim->GetNodeInfo(nsGkAtoms::head, 0, kNameSpaceID_XHTML,
|
||||
nsIDOMNode::ELEMENT_NODE);
|
||||
nsCOMPtr<nsIContent> headElement =
|
||||
NS_NewHTMLHeadElement(htmlNodeInfo.forget());
|
||||
// generate an html body elemment
|
||||
htmlNodeInfo = nim->GetNodeInfo(nsGkAtoms::body, 0, kNameSpaceID_XHTML,
|
||||
nsIDOMNode::ELEMENT_NODE);
|
||||
nsCOMPtr<nsIContent> bodyElement =
|
||||
NS_NewHTMLBodyElement(htmlNodeInfo.forget());
|
||||
|
||||
// generate an html body elemment
|
||||
htmlNodeInfo = nim->GetNodeInfo(nsGkAtoms::body, 0, kNameSpaceID_XHTML,
|
||||
nsIDOMNode::ELEMENT_NODE);
|
||||
nsCOMPtr<nsIContent> bodyElement =
|
||||
NS_NewHTMLBodyElement(htmlNodeInfo.forget());
|
||||
|
||||
// blat in the structure
|
||||
if (htmlElement && headElement && bodyElement) {
|
||||
NS_ASSERTION(blankDoc->GetChildCount() == 0,
|
||||
"Shouldn't have children");
|
||||
rv = blankDoc->AppendChildTo(htmlElement, false);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = htmlElement->AppendChildTo(headElement, false);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// XXXbz Why not notifying here?
|
||||
htmlElement->AppendChildTo(bodyElement, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
// blat in the structure
|
||||
NS_ASSERTION(blankDoc->GetChildCount() == 0,
|
||||
"Shouldn't have children");
|
||||
if (!htmlElement || !headElement || !bodyElement ||
|
||||
NS_FAILED(blankDoc->AppendChildTo(htmlElement, false)) ||
|
||||
NS_FAILED(htmlElement->AppendChildTo(headElement, false)) ||
|
||||
// XXXbz Why not notifying here?
|
||||
NS_FAILED(htmlElement->AppendChildTo(bodyElement, false))) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// add a nice bow
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
blankDoc->SetDocumentCharacterSetSource(kCharsetFromDocTypeDefault);
|
||||
blankDoc->SetDocumentCharacterSet(UTF_8_ENCODING);
|
||||
|
||||
blankDoc.forget(aDocument);
|
||||
}
|
||||
return rv;
|
||||
blankDoc->SetDocumentCharacterSetSource(kCharsetFromDocTypeDefault);
|
||||
blankDoc->SetDocumentCharacterSet(UTF_8_ENCODING);
|
||||
return blankDoc.forget();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -51,9 +51,8 @@ public:
|
|||
* principal. aPrincipal is allowed to be null, in which case the
|
||||
* new document will get the about:blank codebase principal.
|
||||
*/
|
||||
static nsresult CreateBlankDocument(nsILoadGroup* aLoadGroup,
|
||||
nsIPrincipal* aPrincipal,
|
||||
nsIDocument** aDocument);
|
||||
static already_AddRefed<nsIDocument>
|
||||
CreateBlankDocument(nsILoadGroup* aLoadGroup, nsIPrincipal* aPrincipal);
|
||||
|
||||
private:
|
||||
static nsresult EnsureUAStyleSheet();
|
||||
|
|
Загрузка…
Ссылка в новой задаче