Bug 616076, no need for userdata in print documents, r=jst, a=blocking
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Wed, 08 Dec 2010 20:52:39 +0200
changeset 58904 19b83d59edbfcb6a5e40b91ce081731e7454804c
parent 58903 1655a76ea1880f530086c48b21f80ef93d190629
child 58905 98d58c46e409404452f8327b0ac22d1cda5b1e17
push idunknown
push userunknown
push dateunknown
reviewersjst, blocking
bugs616076
milestone2.0b8pre
Bug 616076, no need for userdata in print documents, r=jst, a=blocking
content/base/src/nsDOMAttribute.cpp
content/base/src/nsDocument.cpp
content/base/src/nsGenericDOMDataNode.h
content/base/src/nsGenericElement.h
content/base/src/nsNodeUtils.cpp
content/base/src/nsNodeUtils.h
--- a/content/base/src/nsDOMAttribute.cpp
+++ b/content/base/src/nsDOMAttribute.cpp
@@ -443,17 +443,17 @@ nsDOMAttribute::Clone(nsINodeInfo *aNode
   NS_ADDREF(*aResult);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::CloneNode(PRBool aDeep, nsIDOMNode** aResult)
 {
-  return nsNodeUtils::CloneNodeImpl(this, aDeep, aResult);
+  return nsNodeUtils::CloneNodeImpl(this, aDeep, PR_TRUE, aResult);
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::GetOwnerDocument(nsIDOMDocument** aOwnerDocument)
 {
   return nsINode::GetOwnerDocument(aOwnerDocument);
 }
 
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -5773,17 +5773,17 @@ NS_IMETHODIMP
 nsDocument::AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn)
 {
   return nsDocument::InsertBefore(aNewChild, nsnull, aReturn);
 }
 
 NS_IMETHODIMP
 nsDocument::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
 {
-  return nsNodeUtils::CloneNodeImpl(this, aDeep, aReturn);
+  return nsNodeUtils::CloneNodeImpl(this, aDeep, !mCreatingStaticClone, aReturn);
 }
 
 NS_IMETHODIMP
 nsDocument::Normalize()
 {
   for (PRUint32 i = 0; i < mChildren.ChildCount(); ++i) {
     nsCOMPtr<nsIDOMNode> node(do_QueryInterface(mChildren.ChildAt(i)));
     node->Normalize();
--- a/content/base/src/nsGenericDOMDataNode.h
+++ b/content/base/src/nsGenericDOMDataNode.h
@@ -480,14 +480,14 @@ private:
     return NS_OK;                                                           \
   }                                                                         \
   NS_IMETHOD IsSupported(const nsAString& aFeature,                         \
                       const nsAString& aVersion,                            \
                       PRBool* aReturn) {                                    \
     return nsGenericDOMDataNode::IsSupported(aFeature, aVersion, aReturn);  \
   }                                                                         \
   NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn) {                \
-    return nsNodeUtils::CloneNodeImpl(this, aDeep, aReturn);                \
+    return nsNodeUtils::CloneNodeImpl(this, aDeep, PR_TRUE, aReturn);       \
   }                                                                         \
   virtual nsGenericDOMDataNode *CloneDataNode(nsINodeInfo *aNodeInfo,       \
                                               PRBool aCloneText) const;
 
 #endif /* nsGenericDOMDataNode_h___ */
--- a/content/base/src/nsGenericElement.h
+++ b/content/base/src/nsGenericElement.h
@@ -539,17 +539,17 @@ public:
                                     const nsAString& aLocalName,
                                     nsIDOMNodeList** aReturn);
   NS_IMETHOD HasAttribute(const nsAString& aName, PRBool* aReturn);
   NS_IMETHOD HasAttributeNS(const nsAString& aNamespaceURI,
                             const nsAString& aLocalName,
                             PRBool* aReturn);
   nsresult CloneNode(PRBool aDeep, nsIDOMNode **aResult)
   {
-    return nsNodeUtils::CloneNodeImpl(this, aDeep, aResult);
+    return nsNodeUtils::CloneNodeImpl(this, aDeep, PR_TRUE, aResult);
   }
 
   //----------------------------------------
 
   /**
    * Add a script event listener with the given event handler name
    * (like onclick) and with the value as JS
    * @param aEventName the event listener name
--- a/content/base/src/nsNodeUtils.cpp
+++ b/content/base/src/nsNodeUtils.cpp
@@ -413,28 +413,30 @@ nsNodeUtils::TraverseUserData(nsINode* a
   }
 
   ownerDoc->PropertyTable(DOM_USER_DATA)->Enumerate(aNode, NoteUserData, &aCb);
   ownerDoc->PropertyTable(DOM_USER_DATA_HANDLER)->Enumerate(aNode, NoteUserData, &aCb);
 }
 
 /* static */
 nsresult
-nsNodeUtils::CloneNodeImpl(nsINode *aNode, PRBool aDeep, nsIDOMNode **aResult)
+nsNodeUtils::CloneNodeImpl(nsINode *aNode, PRBool aDeep,
+                           PRBool aCallUserDataHandlers,
+                           nsIDOMNode **aResult)
 {
   *aResult = nsnull;
 
   nsCOMPtr<nsIDOMNode> newNode;
   nsCOMArray<nsINode> nodesWithProperties;
   nsresult rv = Clone(aNode, aDeep, nsnull, nodesWithProperties,
                       getter_AddRefs(newNode));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsIDocument *ownerDoc = aNode->GetOwnerDoc();
-  if (ownerDoc) {
+  if (ownerDoc && aCallUserDataHandlers) {
     rv = CallUserDataHandlers(nodesWithProperties, ownerDoc,
                               nsIDOMUserDataHandler::NODE_CLONED, PR_TRUE);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   newNode.swap(*aResult);
 
   return NS_OK;
--- a/content/base/src/nsNodeUtils.h
+++ b/content/base/src/nsNodeUtils.h
@@ -237,19 +237,21 @@ public:
                                nsCycleCollectionTraversalCallback &aCb);
 
   /**
    * A basic implementation of the DOM cloneNode method. Calls nsINode::Clone to
    * do the actual cloning of the node.
    *
    * @param aNode the node to clone
    * @param aDeep if true all descendants will be cloned too
+   * @param aCallUserDataHandlers if true, user data handlers will be called
    * @param aResult the clone
    */
   static nsresult CloneNodeImpl(nsINode *aNode, PRBool aDeep,
+                                PRBool aCallUserDataHandlers,
                                 nsIDOMNode **aResult);
 
   /**
    * Release the UserData and UserDataHandlers for aNode.
    *
    * @param aNode the node to release the UserData and UserDataHandlers for
    */
   static void UnlinkUserData(nsINode *aNode);