From 728defdd2339208228e334a0e5583c5b0179b8cb Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 3 Dec 2013 09:40:11 -0500 Subject: [PATCH] Bug 945572 part 6. Make NS_NewElement take an Element** outparam instead of an nsIContent** one. r=smaug --- .../base/public/nsContentCreatorFunctions.h | 2 +- content/base/src/nsDocument.cpp | 12 ++++++--- content/base/src/nsNameSpaceManager.cpp | 27 +++++-------------- content/xbl/src/nsXBLPrototypeBinding.cpp | 4 ++- content/xml/document/src/nsXMLContentSink.cpp | 7 ++--- content/xslt/src/xslt/txMozillaXMLOutput.h | 3 ++- .../content/src/nsXULContextMenuBuilder.cpp | 11 ++++---- .../xul/content/src/nsXULContextMenuBuilder.h | 8 +++++- content/xul/document/src/XULDocument.cpp | 5 +--- .../xul/templates/src/nsXULContentBuilder.cpp | 24 ++++++++--------- parser/html/nsHtml5TreeOperation.cpp | 4 +-- 11 files changed, 51 insertions(+), 56 deletions(-) diff --git a/content/base/public/nsContentCreatorFunctions.h b/content/base/public/nsContentCreatorFunctions.h index d2a6160894be..71adf48587df 100644 --- a/content/base/public/nsContentCreatorFunctions.h +++ b/content/base/public/nsContentCreatorFunctions.h @@ -29,7 +29,7 @@ class Element; } // namespace mozilla nsresult -NS_NewElement(nsIContent** aResult, +NS_NewElement(mozilla::dom::Element** aResult, already_AddRefed aNodeInfo, mozilla::dom::FromParser aFromParser); diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 4ff79b53cd09..807c7a8a1a69 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -4983,13 +4983,13 @@ nsIDocument::CreateElementNS(const nsAString& aNamespaceURI, return nullptr; } - nsCOMPtr content; - rv = NS_NewElement(getter_AddRefs(content), nodeInfo.forget(), + nsCOMPtr element; + rv = NS_NewElement(getter_AddRefs(element), nodeInfo.forget(), NOT_FROM_PARSER); if (rv.Failed()) { return nullptr; } - return dont_AddRef(content.forget().get()->AsElement()); + return element.forget(); } NS_IMETHODIMP @@ -7567,7 +7567,11 @@ nsDocument::CreateElem(const nsAString& aName, nsIAtom *aPrefix, int32_t aNamesp getter_AddRefs(nodeInfo)); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); - return NS_NewElement(aResult, nodeInfo.forget(), NOT_FROM_PARSER); + nsCOMPtr element; + nsresult rv = NS_NewElement(getter_AddRefs(element), nodeInfo.forget(), + NOT_FROM_PARSER); + element.forget(aResult); + return rv; } bool diff --git a/content/base/src/nsNameSpaceManager.cpp b/content/base/src/nsNameSpaceManager.cpp index 7f6fe980f419..4d9103d0fde9 100644 --- a/content/base/src/nsNameSpaceManager.cpp +++ b/content/base/src/nsNameSpaceManager.cpp @@ -189,45 +189,30 @@ NameSpaceManagerImpl::GetNameSpaceID(const nsAString& aURI) } nsresult -NS_NewElement(nsIContent** aResult, +NS_NewElement(Element** aResult, already_AddRefed aNodeInfo, FromParser aFromParser) { int32_t ns = aNodeInfo.get()->NamespaceID(); if (ns == kNameSpaceID_XHTML) { - nsCOMPtr el; - nsresult rv = NS_NewHTMLElement(getter_AddRefs(el), aNodeInfo, aFromParser); - el.forget(aResult); - return rv; + return NS_NewHTMLElement(aResult, aNodeInfo, aFromParser); } #ifdef MOZ_XUL if (ns == kNameSpaceID_XUL) { - nsCOMPtr el; - nsresult rv = NS_NewXULElement(getter_AddRefs(el), aNodeInfo); - el.forget(aResult); - return rv; + return NS_NewXULElement(aResult, aNodeInfo); } #endif if (ns == kNameSpaceID_MathML) { - nsCOMPtr el; - nsresult rv = NS_NewMathMLElement(getter_AddRefs(el), aNodeInfo); - el.forget(aResult); - return rv; + return NS_NewMathMLElement(aResult, aNodeInfo); } if (ns == kNameSpaceID_SVG) { - nsCOMPtr el; - nsresult rv = NS_NewSVGElement(getter_AddRefs(el), aNodeInfo, aFromParser); - el.forget(aResult); - return rv; + return NS_NewSVGElement(aResult, aNodeInfo, aFromParser); } if (ns == kNameSpaceID_XBL && aNodeInfo.get()->Equals(nsGkAtoms::children)) { NS_ADDREF(*aResult = new XBLChildrenElement(aNodeInfo)); return NS_OK; } - nsCOMPtr el; - nsresult rv = NS_NewXMLElement(getter_AddRefs(el), aNodeInfo); - el.forget(aResult); - return el; + return NS_NewXMLElement(aResult, aNodeInfo); } bool diff --git a/content/xbl/src/nsXBLPrototypeBinding.cpp b/content/xbl/src/nsXBLPrototypeBinding.cpp index fcf8feff3b11..a6320a9d6713 100644 --- a/content/xbl/src/nsXBLPrototypeBinding.cpp +++ b/content/xbl/src/nsXBLPrototypeBinding.cpp @@ -1332,7 +1332,9 @@ nsXBLPrototypeBinding::ReadContentNode(nsIObjectInputStream* aStream, } else { #endif - NS_NewElement(getter_AddRefs(content), nodeInfo.forget(), NOT_FROM_PARSER); + nsCOMPtr element; + NS_NewElement(getter_AddRefs(element), nodeInfo.forget(), NOT_FROM_PARSER); + content = element; for (uint32_t i = 0; i < attrCount; i++) { rv = ReadNamespace(aStream, namespaceID); diff --git a/content/xml/document/src/nsXMLContentSink.cpp b/content/xml/document/src/nsXMLContentSink.cpp index b35808ed327d..efeaa0bcd366 100644 --- a/content/xml/document/src/nsXMLContentSink.cpp +++ b/content/xml/document/src/nsXMLContentSink.cpp @@ -59,6 +59,7 @@ #include "nsTextNode.h" #include "mozilla/dom/CDATASection.h" #include "mozilla/dom/Comment.h" +#include "mozilla/dom/Element.h" #include "mozilla/dom/ProcessingInstruction.h" using namespace mozilla::dom; @@ -462,7 +463,7 @@ nsXMLContentSink::CreateElement(const PRUnichar** aAtts, uint32_t aAttsCount, nsresult rv = NS_OK; nsCOMPtr ni = aNodeInfo; - nsCOMPtr content; + nsCOMPtr content; rv = NS_NewElement(getter_AddRefs(content), ni.forget(), aFromParser); NS_ENSURE_SUCCESS(rv, rv); @@ -489,7 +490,7 @@ nsXMLContentSink::CreateElement(const PRUnichar** aAtts, uint32_t aAttsCount, } if (!aNodeInfo->NamespaceEquals(kNameSpaceID_SVG)) { - content.swap(*aResult); + content.forget(aResult); return NS_OK; } @@ -510,7 +511,7 @@ nsXMLContentSink::CreateElement(const PRUnichar** aAtts, uint32_t aAttsCount, } } - content.swap(*aResult); + content.forget(aResult); return NS_OK; } diff --git a/content/xslt/src/xslt/txMozillaXMLOutput.h b/content/xslt/src/xslt/txMozillaXMLOutput.h index 0d35fbde154a..634285469517 100644 --- a/content/xslt/src/xslt/txMozillaXMLOutput.h +++ b/content/xslt/src/xslt/txMozillaXMLOutput.h @@ -14,6 +14,7 @@ #include "nsICSSLoaderObserver.h" #include "txStack.h" #include "mozilla/Attributes.h" +#include "mozilla/dom/Element.h" class nsIContent; class nsIDOMDocument; @@ -96,7 +97,7 @@ private: // adding attributes to it). // until then the opened element is // kept in mOpenedElement - nsCOMPtr mOpenedElement; + nsCOMPtr mOpenedElement; nsRefPtr mNodeInfoManager; nsCOMArray mCurrentNodeStack; diff --git a/content/xul/content/src/nsXULContextMenuBuilder.cpp b/content/xul/content/src/nsXULContextMenuBuilder.cpp index 6e342aac3fb9..fe9dce6df17b 100644 --- a/content/xul/content/src/nsXULContextMenuBuilder.cpp +++ b/content/xul/content/src/nsXULContextMenuBuilder.cpp @@ -10,6 +10,7 @@ #include "nsIDOMHTMLMenuItemElement.h" #include "nsXULContextMenuBuilder.h" #include "nsIDocument.h" +#include "mozilla/dom/Element.h" using namespace mozilla; using namespace mozilla::dom; @@ -46,13 +47,13 @@ nsXULContextMenuBuilder::OpenContainer(const nsAString& aLabel) if (!mCurrentNode) { mCurrentNode = mFragment; } else { - nsCOMPtr menu; + nsCOMPtr menu; nsresult rv = CreateElement(nsGkAtoms::menu, nullptr, getter_AddRefs(menu)); NS_ENSURE_SUCCESS(rv, rv); menu->SetAttr(kNameSpaceID_None, nsGkAtoms::label, aLabel, false); - nsCOMPtr menuPopup; + nsCOMPtr menuPopup; rv = CreateElement(nsGkAtoms::menupopup, nullptr, getter_AddRefs(menuPopup)); NS_ENSURE_SUCCESS(rv, rv); @@ -77,7 +78,7 @@ nsXULContextMenuBuilder::AddItemFor(nsIDOMHTMLMenuItemElement* aElement, return NS_ERROR_NOT_INITIALIZED; } - nsCOMPtr menuitem; + nsCOMPtr menuitem; nsCOMPtr element = do_QueryInterface(aElement); nsresult rv = CreateElement(nsGkAtoms::menuitem, element, getter_AddRefs(menuitem)); @@ -129,7 +130,7 @@ nsXULContextMenuBuilder::AddSeparator() return NS_ERROR_NOT_INITIALIZED; } - nsCOMPtr menuseparator; + nsCOMPtr menuseparator; nsresult rv = CreateElement(nsGkAtoms::menuseparator, nullptr, getter_AddRefs(menuseparator)); NS_ENSURE_SUCCESS(rv, rv); @@ -203,7 +204,7 @@ nsXULContextMenuBuilder::Click(const nsAString& aGeneratedItemId) nsresult nsXULContextMenuBuilder::CreateElement(nsIAtom* aTag, nsIDOMHTMLElement* aHTMLElement, - nsIContent** aResult) + Element** aResult) { *aResult = nullptr; diff --git a/content/xul/content/src/nsXULContextMenuBuilder.h b/content/xul/content/src/nsXULContextMenuBuilder.h index bfd9be7aa916..de2ed9072e12 100644 --- a/content/xul/content/src/nsXULContextMenuBuilder.h +++ b/content/xul/content/src/nsXULContextMenuBuilder.h @@ -14,6 +14,12 @@ class nsIContent; class nsIDocument; class nsIDOMHTMLElement; +namespace mozilla { +namespace dom { +class Element; +} // namespace dom +} // namespace mozilla + class nsXULContextMenuBuilder : public nsIMenuBuilder, public nsIXULContextMenuBuilder { @@ -31,7 +37,7 @@ public: protected: nsresult CreateElement(nsIAtom* aTag, nsIDOMHTMLElement* aHTMLElement, - nsIContent** aResult); + mozilla::dom::Element** aResult); nsCOMPtr mFragment; nsCOMPtr mDocument; diff --git a/content/xul/document/src/XULDocument.cpp b/content/xul/document/src/XULDocument.cpp index 0cd64b03ca58..ac2851288a2c 100644 --- a/content/xul/document/src/XULDocument.cpp +++ b/content/xul/document/src/XULDocument.cpp @@ -3732,15 +3732,12 @@ XULDocument::CreateElementFromPrototype(nsXULPrototypeElement* aPrototype, aPrototype->mNodeInfo->NamespaceID(), nsIDOMNode::ELEMENT_NODE); if (!newNodeInfo) return NS_ERROR_OUT_OF_MEMORY; - nsCOMPtr content; nsCOMPtr xtfNi = newNodeInfo; - rv = NS_NewElement(getter_AddRefs(content), newNodeInfo.forget(), + rv = NS_NewElement(getter_AddRefs(result), newNodeInfo.forget(), NOT_FROM_PARSER); if (NS_FAILED(rv)) return rv; - result = content->AsElement(); - rv = AddAttributes(aPrototype, result); if (NS_FAILED(rv)) return rv; } diff --git a/content/xul/templates/src/nsXULContentBuilder.cpp b/content/xul/templates/src/nsXULContentBuilder.cpp index 22af8a804dd8..0db1ff42cb03 100644 --- a/content/xul/templates/src/nsXULContentBuilder.cpp +++ b/content/xul/templates/src/nsXULContentBuilder.cpp @@ -32,6 +32,7 @@ #include "nsNodeUtils.h" #include "mozAutoDocUpdate.h" #include "nsTextNode.h" +#include "mozilla/dom/Element.h" #include "pldhash.h" #include "rdf.h" @@ -248,7 +249,7 @@ protected: nsresult CreateElement(int32_t aNameSpaceID, nsIAtom* aTag, - nsIContent** aResult); + Element** aResult); /** * Set the container and empty attributes on a node. If @@ -583,9 +584,11 @@ nsXULContentBuilder::BuildContentFromTemplate(nsIContent *aTemplateNode, else if (isGenerationElement) { // It's the "resource" element. Create a new element using // the namespace ID and tag from the template element. - rv = CreateElement(nameSpaceID, tag, getter_AddRefs(realKid)); + nsCOMPtr element; + rv = CreateElement(nameSpaceID, tag, getter_AddRefs(element)); if (NS_FAILED(rv)) return rv; + realKid = element.forget(); // Add the resource element to the content support map so // we can remove the match based on the content node later. @@ -649,8 +652,10 @@ nsXULContentBuilder::BuildContentFromTemplate(nsIContent *aTemplateNode, } else { // It's just a generic element. Create it! - rv = CreateElement(nameSpaceID, tag, getter_AddRefs(realKid)); + nsCOMPtr element; + rv = CreateElement(nameSpaceID, tag, getter_AddRefs(element)); if (NS_FAILED(rv)) return rv; + realKid = element.forget(); } if (realKid && !realKidAlreadyExisted) { @@ -1234,7 +1239,7 @@ nsXULContentBuilder::EnsureElementHasGenericChild(nsIContent* parent, if (rv == NS_RDF_NO_VALUE) { // we need to construct a new child element. - nsCOMPtr element; + nsCOMPtr element; rv = CreateElement(nameSpaceID, tag, getter_AddRefs(element)); if (NS_FAILED(rv)) @@ -1352,25 +1357,18 @@ nsXULContentBuilder::GetElementsForResult(nsIXULTemplateResult* aResult, nsresult nsXULContentBuilder::CreateElement(int32_t aNameSpaceID, nsIAtom* aTag, - nsIContent** aResult) + Element** aResult) { nsCOMPtr doc = mRoot->GetDocument(); NS_ASSERTION(doc != nullptr, "not initialized"); if (! doc) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr result; nsCOMPtr nodeInfo = doc->NodeInfoManager()->GetNodeInfo(aTag, nullptr, aNameSpaceID, nsIDOMNode::ELEMENT_NODE); - nsresult rv = NS_NewElement(getter_AddRefs(result), nodeInfo.forget(), - NOT_FROM_PARSER); - if (NS_FAILED(rv)) - return rv; - - result.forget(aResult); - return NS_OK; + return NS_NewElement(aResult, nodeInfo.forget(), NOT_FROM_PARSER); } nsresult diff --git a/parser/html/nsHtml5TreeOperation.cpp b/parser/html/nsHtml5TreeOperation.cpp index a6b42c6e7f5d..412487c778f5 100644 --- a/parser/html/nsHtml5TreeOperation.cpp +++ b/parser/html/nsHtml5TreeOperation.cpp @@ -357,7 +357,7 @@ nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder, name = nsHtml5Atoms::select; } - nsCOMPtr newContent; + nsCOMPtr newContent; nsCOMPtr nodeInfo = aBuilder->GetNodeInfoManager()-> GetNodeInfo(name, nullptr, ns, nsIDOMNode::ELEMENT_NODE); NS_ASSERTION(nodeInfo, "Got null nodeinfo."); @@ -404,7 +404,7 @@ nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder, nsIDOMNode::ELEMENT_NODE); for (uint32_t i = 0; i < theContent.Length(); ++i) { - nsCOMPtr optionElt; + nsCOMPtr optionElt; nsCOMPtr ni = optionNodeInfo; NS_NewElement(getter_AddRefs(optionElt), ni.forget(),