Bug 578696 part 10. Stop holding strong refs when calling ContentInserted. r=sicking
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 21 Jul 2010 11:33:32 -0400
changeset 48015 cccefcd4cedabb59e28475d5497c4a333f4c48a2
parent 48014 1c424f1f465e1433b6f003e4a02336be25c96657
child 48016 b20c759afb7c187dc99b2ba41a72a314419ec200
push id14533
push userbzbarsky@mozilla.com
push dateWed, 21 Jul 2010 15:42:13 +0000
treeherdermozilla-central@b20c759afb7c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs578696
milestone2.0b3pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 578696 part 10. Stop holding strong refs when calling ContentInserted. r=sicking
content/base/public/nsIMutationObserver.h
content/base/src/nsNodeUtils.cpp
content/xul/document/src/nsXULDocument.cpp
--- a/content/base/public/nsIMutationObserver.h
+++ b/content/base/public/nsIMutationObserver.h
@@ -229,16 +229,22 @@ public:
    * @param aDocument  The owner-document of aContent, or, when aContainer
    *                   is null, the container that had the child inserted.
    *                   Can be null.
    * @param aContainer The container that had new a child inserted. Can be
    *                   null to indicate that the child was inserted into
    *                   aDocument
    * @param aChild     The newly inserted child.
    * @param aIndexInContainer The index in the container of the new child.
+   *
+   * @note Callers of this method might not hold a strong reference to the
+   *       observer.  The observer is responsible for making sure it stays
+   *       alive for the duration of the call as needed.  The observer may
+   *       assume that this call will happen when there are script blockers on
+   *       the stack.
    */
   virtual void ContentInserted(nsIDocument *aDocument,
                                nsIContent* aContainer,
                                nsIContent* aChild,
                                PRInt32 aIndexInContainer) = 0;
 
   /**
    * Notification that a content node has been removed from the child list of
--- a/content/base/src/nsNodeUtils.cpp
+++ b/content/base/src/nsNodeUtils.cpp
@@ -178,17 +178,17 @@ nsNodeUtils::ContentInserted(nsINode* aC
     container = static_cast<nsIContent*>(aContainer);
     document = doc;
   }
   else {
     container = nsnull;
     document = static_cast<nsIDocument*>(aContainer);
   }
 
-  IMPL_STRONGREF_MUTATION_NOTIFICATION(ContentInserted, aContainer,
+  IMPL_MUTATION_NOTIFICATION(ContentInserted, aContainer,
                              (document, container, aChild, aIndexInContainer));
 }
 
 void
 nsNodeUtils::ContentRemoved(nsINode* aContainer,
                             nsIContent* aChild,
                             PRInt32 aIndexInContainer)
 {
--- a/content/xul/document/src/nsXULDocument.cpp
+++ b/content/xul/document/src/nsXULDocument.cpp
@@ -1116,16 +1116,19 @@ nsXULDocument::ContentAppended(nsIDocume
 void
 nsXULDocument::ContentInserted(nsIDocument* aDocument,
                                nsIContent* aContainer,
                                nsIContent* aChild,
                                PRInt32 aIndexInContainer)
 {
     NS_ASSERTION(aDocument == this, "unexpected doc");
 
+    // Might not need this, but be safe for now.
+    nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this);
+
     AddSubtreeToDocument(aChild);
 }
 
 void
 nsXULDocument::ContentRemoved(nsIDocument* aDocument,
                               nsIContent* aContainer,
                               nsIContent* aChild,
                               PRInt32 aIndexInContainer)