Bug 1439036: Fix some other miscellaneous issues with the caller. r?bz draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sat, 17 Feb 2018 01:46:35 +0100
changeset 756599 827806297cfad239ca8ece432724d9099e5a5bdd
parent 756598 c0d55e060c882ba42eb5340b4f51b564747ae803
child 756620 f6e7a722579f1223cb39d5e9202723caa22453cc
child 756626 4184b3c315e41a6c2a49699514abd683e30f969e
push id99496
push userbmo:emilio@crisal.io
push dateSat, 17 Feb 2018 00:48:38 +0000
reviewersbz
bugs1439036
milestone60.0a1
Bug 1439036: Fix some other miscellaneous issues with the caller. r?bz While we're here... MozReview-Commit-ID: 7B79vec0bYS
editor/libeditor/HTMLAnonymousNodeEditor.cpp
--- a/editor/libeditor/HTMLAnonymousNodeEditor.cpp
+++ b/editor/libeditor/HTMLAnonymousNodeEditor.cpp
@@ -292,35 +292,38 @@ HTMLEditor::DeleteRefToAnonymousNode(Man
   nsIContent* parentContent = aContent->GetParent();
   if (NS_WARN_IF(!parentContent)) {
     // aContent was already removed?
     return;
   }
 
   nsAutoScriptBlocker scriptBlocker;
   // Need to check whether aShell has been destroyed (but not yet deleted).
-  // In that case presContext->GetPresShell() returns nullptr.
   // See bug 338129.
-  if (aContent->IsInComposedDoc() && aShell && aShell->GetPresContext() &&
-      aShell->GetPresContext()->GetPresShell() == aShell) {
-    nsCOMPtr<nsIDocumentObserver> docObserver = do_QueryInterface(aShell);
-    if (docObserver) {
-      // Call BeginUpdate() so that the nsCSSFrameConstructor/PresShell
-      // knows we're messing with the frame tree.
-      nsCOMPtr<nsIDocument> document = GetDocument();
-      if (document) {
-        docObserver->BeginUpdate(document, UPDATE_CONTENT_MODEL);
-      }
+  if (aContent->IsInComposedDoc() && aShell && !aShell->IsDestroying()) {
+    // Call BeginUpdate() so that the nsCSSFrameConstructor/PresShell
+    // knows we're messing with the frame tree.
+    //
+    // FIXME(emilio): Shouldn't this use the document update mechanism instead?
+    // Also, is it really needed? This is NAC anyway.
+    nsCOMPtr<nsIDocument> document = GetDocument();
+    if (document) {
+      aShell->BeginUpdate(document, UPDATE_CONTENT_MODEL);
+    }
 
-      docObserver->ContentRemoved(aContent->GetComposedDoc(),
-                                  parentContent, aContent,
-                                  aContent->GetPreviousSibling());
-      if (document) {
-        docObserver->EndUpdate(document, UPDATE_CONTENT_MODEL);
-      }
+    MOZ_ASSERT(aContent->IsRootOfAnonymousSubtree());
+    MOZ_ASSERT(!aContent->GetPreviousSibling(), "NAC has no siblings");
+
+    // FIXME(emilio): This is the only caller to PresShell::ContentRemoved that
+    // passes NAC into it. This is not great!
+    aShell->ContentRemoved(
+      aContent->GetComposedDoc(), parentContent, aContent, nullptr);
+
+    if (document) {
+      aShell->EndUpdate(document, UPDATE_CONTENT_MODEL);
     }
   }
 
   // The ManualNACPtr destructor will invoke UnbindFromTree.
 }
 
 // The following method is mostly called by a selection listener. When a
 // selection change is notified, the method is called to check if resizing