diff options
author | Gaming4JC <g4jc@hyperbola.info> | 2020-01-01 15:04:58 -0500 |
---|---|---|
committer | Gaming4JC <g4jc@hyperbola.info> | 2020-01-26 15:50:07 -0500 |
commit | 9c6aa6f4bc606b680ff8340fe524adc0a12391c4 (patch) | |
tree | a1cb100c516af764e45e485a9e7d0785818aca0f /dom/base/nsDocument.cpp | |
parent | d722ba23a6265319c4a2226bb56af3efbab488e0 (diff) | |
download | aura-central-9c6aa6f4bc606b680ff8340fe524adc0a12391c4.tar.gz |
Bug 1276438 part 2. Move the implementation of the .body setter from nsHTMLDocument to nsIDocument.
Tag UXP Issue mcp-graveyard/UXP%1344
Tag UXP Issue mcp-graveyard/UXP%252
Diffstat (limited to 'dom/base/nsDocument.cpp')
-rw-r--r-- | dom/base/nsDocument.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
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<Element> 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<Element> currentBody = GetBodyElement(); + if (currentBody) { + root->ReplaceChild(*newBody, *currentBody, rv); + } else { + root->AppendChild(*newBody, rv); + } +} + Element* nsDocument::GetTitleElement() { |