From fbd88a1d662f9c8a97f5c758704f7c04cf62437a Mon Sep 17 00:00:00 2001 From: "peterv%propagandism.org" Date: Sun, 18 Jan 2004 11:59:21 +0000 Subject: [PATCH] Fix for bug 230439 (Remove anonymous nodeinfomanager and other cleanup) - share CreateElement. r=caillon, sr=jst. --- content/base/src/nsDocument.cpp | 27 +++++++++ content/base/src/nsDocument.h | 2 + content/html/document/src/nsHTMLDocument.cpp | 21 +------ content/xml/document/src/nsXMLDocument.cpp | 34 +---------- content/xml/document/src/nsXMLDocument.h | 2 - content/xul/document/src/nsXULDocument.cpp | 60 ++------------------ content/xul/document/src/nsXULDocument.h | 2 - 7 files changed, 36 insertions(+), 112 deletions(-) diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 5acc85fa812c..2f3a514d06d7 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -118,6 +118,7 @@ static NS_DEFINE_CID(kDOMEventGroupCID, NS_DOMEVENTGROUP_CID); #include "nsScriptEventManager.h" #include "nsIXPathEvaluatorInternal.h" +#include "nsIElementFactory.h" #ifdef DEBUG #include "nsICharsetAlias.h" @@ -4073,3 +4074,29 @@ nsDocument::RetrieveRelevantHeaders(nsIChannel *aChannel) } } } + +nsresult +nsDocument::CreateElement(nsINodeInfo *aNodeInfo, nsIDOMElement** aResult) +{ + *aResult = nsnull; + + PRInt32 namespaceID = aNodeInfo->NamespaceID(); + + nsCOMPtr elementFactory; + nsContentUtils::GetNSManagerWeakRef()->GetElementFactory(namespaceID, + getter_AddRefs(elementFactory)); + + nsresult rv; + nsCOMPtr content; + if (elementFactory) { + rv = elementFactory->CreateInstanceByTag(aNodeInfo, + getter_AddRefs(content)); + } else { + rv = NS_NewXMLElement(getter_AddRefs(content), aNodeInfo); + } + NS_ENSURE_SUCCESS(rv, rv); + + content->SetContentID(mNextContentID++); + + return CallQueryInterface(content, aResult); +} diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h index ad31dff27489..3aafe324d074 100644 --- a/content/base/src/nsDocument.h +++ b/content/base/src/nsDocument.h @@ -563,6 +563,8 @@ protected: nsCompatibility aCompatMode, nsIPresShell** aInstancePtrResult); + nsresult CreateElement(nsINodeInfo *aNodeInfo, nsIDOMElement** aResult); + nsDocument(); virtual ~nsDocument(); diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 3f509e014e5a..7e81e1c457d4 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -1487,26 +1487,7 @@ nsHTMLDocument::CreateElementNS(const nsAString& aNamespaceURI, getter_AddRefs(nodeInfo)); NS_ENSURE_SUCCESS(rv, rv); - PRInt32 namespaceID = nodeInfo->NamespaceID(); - - nsCOMPtr elementFactory; - nsContentUtils::GetNSManagerWeakRef()->GetElementFactory(namespaceID, - getter_AddRefs(elementFactory)); - - nsCOMPtr content; - - if (elementFactory) { - rv = elementFactory->CreateInstanceByTag(nodeInfo, - getter_AddRefs(content)); - } else { - rv = NS_NewXMLElement(getter_AddRefs(content), nodeInfo); - } - - NS_ENSURE_SUCCESS(rv, rv); - - content->SetContentID(mNextContentID++); - - return CallQueryInterface(content, aReturn); + return nsDocument::CreateElement(nodeInfo, aReturn); } diff --git a/content/xml/document/src/nsXMLDocument.cpp b/content/xml/document/src/nsXMLDocument.cpp index e847ee23e9d1..cae09f74f5fc 100644 --- a/content/xml/document/src/nsXMLDocument.cpp +++ b/content/xml/document/src/nsXMLDocument.cpp @@ -51,7 +51,6 @@ #include "nsIDocShell.h" #include "nsIMarkupDocumentViewer.h" #include "nsIDocumentLoader.h" -#include "nsIHTMLContent.h" #include "nsHTMLParts.h" #include "nsIHTMLStyleSheet.h" #include "nsIHTMLCSSStyleSheet.h" @@ -842,7 +841,7 @@ nsXMLDocument::CreateElement(const nsAString& aTagName, getter_AddRefs(nodeInfo)); NS_ENSURE_SUCCESS(rv, rv); - return CreateElement(nodeInfo, aReturn); + return nsDocument::CreateElement(nodeInfo, aReturn); } NS_IMETHODIMP @@ -957,7 +956,7 @@ nsXMLDocument::CreateElementNS(const nsAString& aNamespaceURI, getter_AddRefs(nodeInfo)); NS_ENSURE_SUCCESS(rv, rv); - return CreateElement(nodeInfo, aReturn); + return nsDocument::CreateElement(nodeInfo, aReturn); } // Id attribute matching function used by nsXMLDocument and @@ -1084,32 +1083,3 @@ nsXMLDocument::GetCSSLoader() return mCSSLoader; } - -nsresult -nsXMLDocument::CreateElement(nsINodeInfo *aNodeInfo, nsIDOMElement** aResult) -{ - *aResult = nsnull; - - nsresult rv; - - nsCOMPtr content; - - PRInt32 namespaceID = aNodeInfo->NamespaceID(); - - nsCOMPtr elementFactory; - nsContentUtils::GetNSManagerWeakRef()->GetElementFactory(namespaceID, - getter_AddRefs(elementFactory)); - - if (elementFactory) { - rv = elementFactory->CreateInstanceByTag(aNodeInfo, - getter_AddRefs(content)); - } else { - rv = NS_NewXMLElement(getter_AddRefs(content), aNodeInfo); - } - - NS_ENSURE_SUCCESS(rv, rv); - - content->SetContentID(mNextContentID++); - - return CallQueryInterface(content, aResult); -} diff --git a/content/xml/document/src/nsXMLDocument.h b/content/xml/document/src/nsXMLDocument.h index 8dc777a8902a..a2d598d112db 100644 --- a/content/xml/document/src/nsXMLDocument.h +++ b/content/xml/document/src/nsXMLDocument.h @@ -125,8 +125,6 @@ protected: virtual nsIStyleSheet* InternalGetStyleSheetAt(PRInt32 aIndex) const; virtual PRInt32 InternalGetNumberOfStyleSheets() const; - nsresult CreateElement(nsINodeInfo *aNodeInfo, nsIDOMElement** aResult); - virtual nsresult GetLoadGroup(nsILoadGroup **aLoadGroup); nsresult SetDefaultStylesheets(nsIURI* aUrl); diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index aa48d7f8f460..e84b78908989 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -1441,13 +1441,6 @@ nsXULDocument::CreateElement(const nsAString& aTagName, if (! aReturn) return NS_ERROR_NULL_POINTER; - nsresult rv; - - nsCOMPtr name, prefix; - - name = do_GetAtom(aTagName); - NS_ENSURE_TRUE(name, NS_ERROR_OUT_OF_MEMORY); - #ifdef PR_LOGGING if (PR_LOG_TEST(gXULLog, PR_LOG_DEBUG)) { char* tagCStr = ToNewCString(aTagName); @@ -1459,24 +1452,12 @@ nsXULDocument::CreateElement(const nsAString& aTagName, } #endif - *aReturn = nsnull; - - nsCOMPtr ni; - // CreateElement in the XUL document defaults to the XUL namespace. - mNodeInfoManager->GetNodeInfo(name, prefix, kNameSpaceID_XUL, + nsCOMPtr ni; + mNodeInfoManager->GetNodeInfo(aTagName, nsnull, kNameSpaceID_XUL, getter_AddRefs(ni)); - nsCOMPtr result; - rv = CreateElement(ni, getter_AddRefs(result)); - if (NS_FAILED(rv)) return rv; - - // get the DOM interface - rv = CallQueryInterface(result, aReturn); - NS_ASSERTION(NS_SUCCEEDED(rv), "not a DOM element"); - if (NS_FAILED(rv)) return rv; - - return NS_OK; + return nsDocument::CreateElement(ni, aReturn); } @@ -2327,40 +2308,6 @@ nsXULDocument::GetElementsByAttribute(nsIDOMNode* aNode, } -nsresult -nsXULDocument::CreateElement(nsINodeInfo *aNodeInfo, nsIContent** aResult) -{ - NS_ENSURE_ARG_POINTER(aNodeInfo); - NS_ENSURE_ARG_POINTER(aResult); - - nsresult rv; - nsCOMPtr result; - - if (aNodeInfo->NamespaceEquals(kNameSpaceID_XUL)) { - rv = nsXULElement::Create(aNodeInfo, getter_AddRefs(result)); - if (NS_FAILED(rv)) return rv; - } - else { - nsCOMPtr elementFactory; - GetElementFactory(aNodeInfo->NamespaceID(), - getter_AddRefs(elementFactory)); - - rv = elementFactory->CreateInstanceByTag(aNodeInfo, - getter_AddRefs(result)); - if (NS_FAILED(rv)) return rv; - - if (! result) - return NS_ERROR_UNEXPECTED; - } - - result->SetContentID(mNextContentID++); - - *aResult = result; - NS_ADDREF(*aResult); - return NS_OK; -} - - nsresult nsXULDocument::PrepareToLoad(nsISupports* aContainer, const char* aCommand, @@ -3419,6 +3366,7 @@ nsXULDocument::CreateElement(nsXULPrototypeElement* aPrototype, nsIContent** aRe if (! aPrototype) return NS_ERROR_NULL_POINTER; + *aResult = nsnull; nsresult rv = NS_OK; #ifdef PR_LOGGING diff --git a/content/xul/document/src/nsXULDocument.h b/content/xul/document/src/nsXULDocument.h index 5243ff1551c3..165820770291 100644 --- a/content/xul/document/src/nsXULDocument.h +++ b/content/xul/document/src/nsXULDocument.h @@ -201,8 +201,6 @@ protected: void SetIsPopup(PRBool isPopup) { mIsPopup = isPopup; }; - nsresult CreateElement(nsINodeInfo *aNodeInfo, nsIContent** aResult); - nsresult PrepareToLoad(nsISupports* aContainer, const char* aCommand, nsIChannel* aChannel,