From ea481fdedca834a6d7d70bb85b0da573e61411ca Mon Sep 17 00:00:00 2001 From: "peter%propagandism.org" Date: Tue, 23 Sep 2003 13:46:20 +0000 Subject: [PATCH] Fix for bug 85798 (INUSE_ATTRIBUTE_ERR expected when using setNamedItem()). r=sicking, sr=jst. Fix for bug 127205 (setNamedItemNS() in NamedNodeMap doesn't set the item properly). r=sicking, sr=jst. git-svn-id: svn://10.0.0.236/trunk@147164 18797224-902f-48f8-a5cc-f745e15eee43 --- .../content/base/src/nsDOMAttributeMap.cpp | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/mozilla/content/base/src/nsDOMAttributeMap.cpp b/mozilla/content/base/src/nsDOMAttributeMap.cpp index 204e7582986..e3f85d5ae6d 100644 --- a/mozilla/content/base/src/nsDOMAttributeMap.cpp +++ b/mozilla/content/base/src/nsDOMAttributeMap.cpp @@ -74,7 +74,7 @@ NS_INTERFACE_MAP_END NS_IMPL_ADDREF(nsDOMAttributeMap) NS_IMPL_RELEASE(nsDOMAttributeMap) -nsresult +NS_IMETHODIMP nsDOMAttributeMap::GetNamedItem(const nsAString& aAttrName, nsIDOMNode** aAttribute) { @@ -105,7 +105,7 @@ nsDOMAttributeMap::GetNamedItem(const nsAString& aAttrName, return rv; } -nsresult +NS_IMETHODIMP nsDOMAttributeMap::SetNamedItem(nsIDOMNode *aNode, nsIDOMNode **aReturn) { NS_ENSURE_ARG_POINTER(aReturn); @@ -127,6 +127,16 @@ nsDOMAttributeMap::SetNamedItem(nsIDOMNode *aNode, nsIDOMNode **aReturn) return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; } + nsCOMPtr owner; + attribute->GetOwnerElement(getter_AddRefs(owner)); + if (owner) { + nsCOMPtr ownerSupports = do_QueryInterface(owner); + nsCOMPtr thisSupports = do_QueryInterface(mContent); + if (ownerSupports != thisSupports) { + return NS_ERROR_DOM_INUSE_ATTRIBUTE_ERR; + } + } + nsAutoString name, value; attribute->GetName(name); @@ -155,6 +165,12 @@ nsDOMAttributeMap::SetNamedItem(nsIDOMNode *aNode, nsIDOMNode **aReturn) attribute->GetValue(value); rv = mContent->SetAttr(ni, value, PR_TRUE); + + // Not all attributes implement nsIAttribute. + nsCOMPtr attr = do_QueryInterface(aNode); + if (attr) { + attr->SetContent(mContent); + } } return rv; @@ -202,7 +218,7 @@ nsDOMAttributeMap::RemoveNamedItem(const nsAString& aName, } -nsresult +NS_IMETHODIMP nsDOMAttributeMap::Item(PRUint32 aIndex, nsIDOMNode** aReturn) { NS_ENSURE_ARG_POINTER(aReturn); @@ -258,7 +274,7 @@ nsDOMAttributeMap::GetLength(PRUint32 *aLength) return rv; } -nsresult +NS_IMETHODIMP nsDOMAttributeMap::GetNamedItemNS(const nsAString& aNamespaceURI, const nsAString& aLocalName, nsIDOMNode** aReturn) @@ -309,7 +325,7 @@ nsDOMAttributeMap::GetNamedItemNS(const nsAString& aNamespaceURI, return rv; } -nsresult +NS_IMETHODIMP nsDOMAttributeMap::SetNamedItemNS(nsIDOMNode* aArg, nsIDOMNode** aReturn) { NS_ENSURE_ARG_POINTER(aReturn); @@ -327,10 +343,19 @@ nsDOMAttributeMap::SetNamedItemNS(nsIDOMNode* aArg, nsIDOMNode** aReturn) return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; } + nsCOMPtr owner; + attribute->GetOwnerElement(getter_AddRefs(owner)); + if (owner) { + nsCOMPtr ownerSupports = do_QueryInterface(owner); + nsCOMPtr thisSupports = do_QueryInterface(mContent); + if (ownerSupports != thisSupports) { + return NS_ERROR_DOM_INUSE_ATTRIBUTE_ERR; + } + } + nsAutoString name, nsURI, value; attribute->GetName(name); - attribute->GetPrefix(name); attribute->GetNamespaceURI(nsURI); nsCOMPtr ni; @@ -364,12 +389,18 @@ nsDOMAttributeMap::SetNamedItemNS(nsIDOMNode* aArg, nsIDOMNode** aReturn) attribute->GetValue(value); rv = mContent->SetAttr(ni, value, PR_TRUE); + + // Not all attributes implement nsIAttribute. + nsCOMPtr attr = do_QueryInterface(aArg); + if (attr) { + attr->SetContent(mContent); + } } return rv; } -nsresult +NS_IMETHODIMP nsDOMAttributeMap::RemoveNamedItemNS(const nsAString& aNamespaceURI, const nsAString& aLocalName, nsIDOMNode** aReturn)