Bug 578696 part 11. Stop holding strong refs when calling ContentRemoved and remove the now-unused IMPL_STRONGREF_MUTATION_NOTIFICATION macro. r=sicking

This commit is contained in:
Boris Zbarsky 2010-07-21 11:37:41 -04:00
parent 235296fdf0
commit 93922db9e1
7 changed files with 18 additions and 24 deletions

View File

@ -259,6 +259,12 @@ public:
* @param aChild The child that was removed.
* @param aIndexInContainer The index in the container which the child used
* to have.
*
* @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 ContentRemoved(nsIDocument *aDocument,
nsIContent* aContainer,

View File

@ -86,29 +86,6 @@ using namespace mozilla::dom;
} while (node); \
PR_END_MACRO
// This macro expects the ownerDocument of content_ to be in scope as
// |nsIDocument* doc|
#define IMPL_STRONGREF_MUTATION_NOTIFICATION(func_, content_, params_) \
PR_BEGIN_MACRO \
nsINode* node = content_; \
NS_ASSERTION(node->GetOwnerDoc() == doc, "Bogus document"); \
if (doc) { \
static_cast<nsIMutationObserver*>(doc->BindingManager())-> \
func_ params_; \
} \
do { \
nsINode::nsSlots* slots = node->GetExistingSlots(); \
if (slots && !slots->mMutationObservers.IsEmpty()) { \
/* No need to explicitly notify the first observer first \
since that'll happen anyway. */ \
NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS( \
slots->mMutationObservers, nsIMutationObserver, \
func_, params_); \
} \
node = node->GetNodeParent(); \
} while (node); \
PR_END_MACRO
void
nsNodeUtils::CharacterDataWillChange(nsIContent* aContent,
CharacterDataChangeInfo* aInfo)
@ -207,7 +184,7 @@ nsNodeUtils::ContentRemoved(nsINode* aContainer,
document = static_cast<nsIDocument*>(aContainer);
}
IMPL_STRONGREF_MUTATION_NOTIFICATION(ContentRemoved, aContainer,
IMPL_MUTATION_NOTIFICATION(ContentRemoved, aContainer,
(document, container, aChild, aIndexInContainer));
}

View File

@ -407,6 +407,8 @@ nsXMLEventsManager::ContentRemoved(nsIDocument* aDocument,
//And to remember: the same observer can be referenced by many
//XMLEventsListeners
nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this);
//If the content was an XML Events observer or handler
mListeners.Enumerate(EnumAndSetIncomplete, aChild);

View File

@ -1135,6 +1135,9 @@ nsXULDocument::ContentRemoved(nsIDocument* aDocument,
{
NS_ASSERTION(aDocument == this, "unexpected doc");
// Might not need this, but be safe for now.
nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this);
RemoveSubtreeFromDocument(aChild);
}

View File

@ -928,6 +928,8 @@ inDOMView::ContentRemoved(nsIDocument *aDocument, nsIContent* aContainer, nsICon
if (NS_FAILED(rv = RowToNode(row, &oldNode)))
return;
nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this);
// The parent may no longer be a container. Note that we don't want
// to access oldNode after calling RemoveNode, so do this now.
inDOMViewNode* parentNode = oldNode->parent;

View File

@ -1118,6 +1118,9 @@ nsTreeContentView::ContentRemoved(nsIDocument *aDocument,
return; // this is not for us
}
// Lots of codepaths under here that do all sorts of stuff, so be safe.
nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this);
if (tag == nsGkAtoms::treechildren) {
PRInt32 index = FindContent(aContainer);
if (index >= 0) {

View File

@ -163,6 +163,7 @@ void nsMenuGroupOwnerX::ContentRemoved(nsIDocument * aDocument,
nsIContent * aChild,
PRInt32 aIndexInContainer)
{
nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this);
nsChangeObserver* obs = LookupContentChangeObserver(aContainer);
if (obs)
obs->ObserveContentRemoved(aDocument, aChild, aIndexInContainer);