diff --git a/dom/base/Document.h b/dom/base/Document.h index 8eccf66133f3..a52c61addffc 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -3878,7 +3878,12 @@ class Document : public nsINode, void SetAllowDeclarativeShadowRoots(bool aAllowDeclarativeShadowRoots); bool AllowsDeclarativeShadowRoots() const; - void SuspendDOMNotifications() { mSuspendDOMNotifications = true; } + void SuspendDOMNotifications() { + MOZ_ASSERT(IsHTMLDocument(), + "Currently suspending DOM notifications is supported only on " + "HTML documents."); + mSuspendDOMNotifications = true; + } void ResumeDOMNotifications() { mSuspendDOMNotifications = false; } diff --git a/dom/base/MutationObservers.cpp b/dom/base/MutationObservers.cpp index a4bcdf88d4dd..e3e7c8b02ef9 100644 --- a/dom/base/MutationObservers.cpp +++ b/dom/base/MutationObservers.cpp @@ -81,9 +81,6 @@ template OwnerDoc(); - if (doc->DOMNotificationsSuspended()) { - return; - } nsDOMMutationEnterLeave enterLeave(doc); #ifdef DEBUG diff --git a/parser/html/nsHtml5TreeOperation.cpp b/parser/html/nsHtml5TreeOperation.cpp index cb6fda5a5b54..9adfad34bdeb 100644 --- a/parser/html/nsHtml5TreeOperation.cpp +++ b/parser/html/nsHtml5TreeOperation.cpp @@ -257,9 +257,10 @@ nsresult nsHtml5TreeOperation::Append(nsIContent* aNode, nsIContent* aParent, MOZ_ASSERT(aBuilder); MOZ_ASSERT(aBuilder->IsInDocUpdate()); ErrorResult rv; - nsHtml5OtherDocUpdate update(aParent->OwnerDoc(), aBuilder->GetDocument()); + Document* ownerDoc = aParent->OwnerDoc(); + nsHtml5OtherDocUpdate update(ownerDoc, aBuilder->GetDocument()); aParent->AppendChildTo(aNode, false, rv); - if (!rv.Failed()) { + if (!rv.Failed() && !ownerDoc->DOMNotificationsSuspended()) { aNode->SetParserHasNotified(); MutationObservers::NotifyContentAppended(aParent, aNode); } @@ -303,8 +304,10 @@ nsresult nsHtml5TreeOperation::AppendToDocument( return rv.StealNSResult(); } - aNode->SetParserHasNotified(); - MutationObservers::NotifyContentInserted(doc, aNode); + if (!doc->DOMNotificationsSuspended()) { + aNode->SetParserHasNotified(); + MutationObservers::NotifyContentInserted(doc, aNode); + } NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(), "Someone forgot to block scripts");