Bug 1425702 - Part 2: Reset nsIDocument::{mIsTopLevelContentDocument,mIsContentDocument} when a document is removed from its docshell. r?bz draft
authorCameron McCormack <cam@mcc.id.au>
Sat, 16 Dec 2017 17:14:32 -0600
changeset 712522 dc7edf4c175d1fe3adc74c0a21f13e1cdc0bd2d1
parent 712521 a19a3798913ddc7a272355e1ff5a5998e4735eed
child 744071 addbc3e3da8f1a7986f88405bfc8885711fb9a97
push id93352
push userbmo:cam@mcc.id.au
push dateSat, 16 Dec 2017 23:49:44 +0000
reviewersbz
bugs1425702
milestone59.0a1
Bug 1425702 - Part 2: Reset nsIDocument::{mIsTopLevelContentDocument,mIsContentDocument} when a document is removed from its docshell. r?bz MozReview-Commit-ID: DWfYRvouofj
dom/base/nsDocument.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -5078,37 +5078,42 @@ void
 nsIDocument::SetContainer(nsDocShell* aContainer)
 {
   if (aContainer) {
     mDocumentContainer = aContainer;
   } else {
     mDocumentContainer = WeakPtr<nsDocShell>();
   }
 
+  bool isTopLevelContentDocument = false;
+  bool isContentDocument = false;
+
   EnumerateActivityObservers(NotifyActivityChanged, nullptr);
-  if (!aContainer) {
-    return;
-  }
-
-  // Get the Docshell
-  if (aContainer->ItemType() == nsIDocShellTreeItem::typeContent) {
-    // check if same type root
-    nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
-    aContainer->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
-    NS_ASSERTION(sameTypeRoot, "No document shell root tree item from document shell tree item!");
-
-    if (sameTypeRoot == aContainer) {
-      static_cast<nsDocument*>(this)->SetIsTopLevelContentDocument(true);
-    }
-
-    static_cast<nsDocument*>(this)->SetIsContentDocument(true);
-  }
-
-  mAncestorPrincipals = aContainer->AncestorPrincipals();
-  mAncestorOuterWindowIDs = aContainer->AncestorOuterWindowIDs();
+
+  if (aContainer) {
+    // Get the Docshell
+    if (aContainer->ItemType() == nsIDocShellTreeItem::typeContent) {
+      // check if same type root
+      nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
+      aContainer->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
+      NS_ASSERTION(sameTypeRoot, "No document shell root tree item from document shell tree item!");
+
+      if (sameTypeRoot == aContainer) {
+        isTopLevelContentDocument = true;
+      }
+      isContentDocument = true;
+    }
+
+    mAncestorPrincipals = aContainer->AncestorPrincipals();
+    mAncestorOuterWindowIDs = aContainer->AncestorOuterWindowIDs();
+  }
+
+  auto doc = static_cast<nsDocument*>(this);
+  doc->SetIsTopLevelContentDocument(isTopLevelContentDocument);
+  doc->SetIsContentDocument(isContentDocument);
 }
 
 nsISupports*
 nsIDocument::GetContainer() const
 {
   return static_cast<nsIDocShell*>(mDocumentContainer);
 }