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 | 32f3f8826f396fd17c1c77770d073d0abf15c904 (patch) | |
tree | a1cb100c516af764e45e485a9e7d0785818aca0f | |
parent | a2b56b295b8bd089b74c5d93148edafe7e6da912 (diff) | |
download | uxp-32f3f8826f396fd17c1c77770d073d0abf15c904.tar.gz |
Bug 1276438 part 2. Move the implementation of the .body setter from nsHTMLDocument to nsIDocument.
Tag UXP Issue #1344
Tag UXP Issue #252
-rw-r--r-- | dom/base/nsDocument.cpp | 25 | ||||
-rw-r--r-- | dom/base/nsIDocument.h | 2 | ||||
-rw-r--r-- | dom/html/nsHTMLDocument.cpp | 25 | ||||
-rw-r--r-- | dom/html/nsHTMLDocument.h | 2 |
4 files changed, 28 insertions, 26 deletions
diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 83c2e5bb75..69cbff16c6 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() { diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index b3879c624e..e44ab047ea 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -1040,6 +1040,8 @@ public: // Get the "body" in the sense of document.body: The first <body> or // <frameset> that's a child of a root <html> nsGenericHTMLElement* GetBody(); + // Set the "body" in the sense of document.body. + void SetBody(nsGenericHTMLElement* aBody, mozilla::ErrorResult& rv); /** * Accessors to the collection of stylesheets owned by this document. diff --git a/dom/html/nsHTMLDocument.cpp b/dom/html/nsHTMLDocument.cpp index 23c73298d7..1eeef737af 100644 --- a/dom/html/nsHTMLDocument.cpp +++ b/dom/html/nsHTMLDocument.cpp @@ -1034,31 +1034,6 @@ nsHTMLDocument::SetBody(nsIDOMHTMLElement* aBody) return rv.StealNSResult(); } -void -nsHTMLDocument::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); - } -} - NS_IMETHODIMP nsHTMLDocument::GetHead(nsIDOMHTMLHeadElement** aHead) { diff --git a/dom/html/nsHTMLDocument.h b/dom/html/nsHTMLDocument.h index 02fc22d422..c9e46b3faf 100644 --- a/dom/html/nsHTMLDocument.h +++ b/dom/html/nsHTMLDocument.h @@ -176,7 +176,7 @@ public: mozilla::ErrorResult& rv); void GetSupportedNames(nsTArray<nsString>& aNames); using nsIDocument::GetBody; - void SetBody(nsGenericHTMLElement* aBody, mozilla::ErrorResult& rv); + using nsIDocument::SetBody; mozilla::dom::HTMLSharedElement *GetHead() { return static_cast<mozilla::dom::HTMLSharedElement*>(GetHeadElement()); } |