From 32f3f8826f396fd17c1c77770d073d0abf15c904 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Wed, 1 Jan 2020 15:04:58 -0500 Subject: Bug 1276438 part 2. Move the implementation of the .body setter from nsHTMLDocument to nsIDocument. Tag UXP Issue #1344 Tag UXP Issue #252 --- dom/base/nsDocument.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'dom/base/nsDocument.cpp') diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 83c2e5bb7..69cbff16c 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -6556,6 +6556,31 @@ nsIDocument::GetBody() return nullptr; } +void +nsIDocument::SetBody(nsGenericHTMLElement* newBody, ErrorResult& rv) +{ + nsCOMPtr root = GetRootElement(); + + // The body element must be either a body tag or a frameset tag. And we must + // have a html root tag, otherwise GetBody will not return the newly set + // body. + if (!newBody || + !newBody->IsAnyOfHTMLElements(nsGkAtoms::body, nsGkAtoms::frameset) || + !root || !root->IsHTMLElement() || + !root->IsHTMLElement(nsGkAtoms::html)) { + rv.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR); + return; + } + + // Use DOM methods so that we pass through the appropriate security checks. + nsCOMPtr currentBody = GetBodyElement(); + if (currentBody) { + root->ReplaceChild(*newBody, *currentBody, rv); + } else { + root->AppendChild(*newBody, rv); + } +} + Element* nsDocument::GetTitleElement() { -- cgit v1.2.3