Bug 1425702 - Part 2: Reset nsIDocument::{mIsTopLevelContentDocument,mIsContentDocument} when a document is removed from its docshell. r?bz
MozReview-Commit-ID: DWfYRvouofj
--- 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);
}