diff --git a/dom/base/nsFrameLoader.cpp b/dom/base/nsFrameLoader.cpp index 773552c1f50a..a95babb1bdeb 100644 --- a/dom/base/nsFrameLoader.cpp +++ b/dom/base/nsFrameLoader.cpp @@ -47,6 +47,7 @@ #include "nsPIWindowRoot.h" #include "nsLayoutUtils.h" #include "nsView.h" +#include "nsViewManager.h" #include "nsBaseWidget.h" #include "nsQueryObject.h" #include "ReferrerInfo.h" @@ -992,6 +993,14 @@ bool nsFrameLoader::Show(nsSubDocumentFrame* frame) { ds->SetScrollbarPreference(GetScrollbarPreference(mOwnerContent)); const bool marginsChanged = ds->UpdateFrameMargins(GetMarginAttributes(mOwnerContent)); + + nsView* view = frame->EnsureInnerView(); + if (!view) { + return false; + } + + + if (PresShell* presShell = ds->GetPresShell()) { if (marginsChanged) { @@ -1000,11 +1009,21 @@ bool nsFrameLoader::Show(nsSubDocumentFrame* frame) { NS_FRAME_IS_DIRTY); } } - return true; - } + nsView* childView = presShell->GetViewManager()->GetRootView(); + MOZ_DIAGNOSTIC_ASSERT(childView); + if (childView->GetParent() == view) { + + + return true; + } - nsView* view = frame->EnsureInnerView(); - if (!view) return false; + + + MOZ_DIAGNOSTIC_ASSERT(!view->GetFirstChild()); + MOZ_DIAGNOSTIC_ASSERT(!childView->GetParent(), "Stale view?"); + nsSubDocumentFrame::InsertViewsInReverseOrder(childView, view); + nsSubDocumentFrame::EndSwapDocShellsForViews(view->GetFirstChild()); + } RefPtr baseWindow = GetDocShell(); baseWindow->InitWindow(nullptr, view->GetWidget(), 0, 0, size.width, @@ -1016,6 +1035,9 @@ bool nsFrameLoader::Show(nsSubDocumentFrame* frame) { + + + if (RefPtr presShell = GetDocShell()->GetPresShell()) { Document* doc = presShell->GetDocument(); nsHTMLDocument* htmlDoc = diff --git a/layout/generic/nsSubDocumentFrame.cpp b/layout/generic/nsSubDocumentFrame.cpp index 80e198f726d1..954ab78f69b5 100644 --- a/layout/generic/nsSubDocumentFrame.cpp +++ b/layout/generic/nsSubDocumentFrame.cpp @@ -116,10 +116,6 @@ class AsyncFrameInit : public Runnable { WeakFrame mFrame; }; -static void InsertViewsInReverseOrder(nsView* aSibling, nsView* aParent); - -static void EndSwapDocShellsForViews(nsView* aView); - void nsSubDocumentFrame::Init(nsIContent* aContent, nsContainerFrame* aParent, nsIFrame* aPrevInFlow) { MOZ_ASSERT(aContent); @@ -148,8 +144,8 @@ void nsSubDocumentFrame::Init(nsIContent* aContent, nsContainerFrame* aParent, nsView* detachedView = detachedFrame ? detachedFrame->GetView() : nullptr; if (detachedView) { - ::InsertViewsInReverseOrder(detachedView, mInnerView); - ::EndSwapDocShellsForViews(mInnerView->GetFirstChild()); + InsertViewsInReverseOrder(detachedView, mInnerView); + EndSwapDocShellsForViews(mInnerView->GetFirstChild()); } else if (hadFrame) { frameloader->Hide(); @@ -921,7 +917,7 @@ class nsHideViewer final : public Runnable { mFrameLoader->SetDetachedSubdocFrame(nullptr); nsSubDocumentFrame* frame = do_QueryFrame(mFrameElement->GetPrimaryFrame()); - if (!frame) { + if (!frame || frame->FrameLoader() != mFrameLoader) { PropagateIsUnderHiddenEmbedderElement(mFrameLoader, true); if (mHideViewerIfFrameless) { @@ -1080,7 +1076,9 @@ static nsView* BeginSwapDocShellsForViews(nsView* aSibling) { return removedViews; } -static void InsertViewsInReverseOrder(nsView* aSibling, nsView* aParent) { + +void nsSubDocumentFrame::InsertViewsInReverseOrder(nsView* aSibling, + nsView* aParent) { MOZ_ASSERT(aParent, "null view"); MOZ_ASSERT(!aParent->GetFirstChild(), "inserting into non-empty list"); @@ -1115,8 +1113,8 @@ nsresult nsSubDocumentFrame::BeginSwapDocShells(nsIFrame* aOther) { nsView* otherSubdocViews = other->mInnerView->GetFirstChild(); nsView* otherRemovedViews = ::BeginSwapDocShellsForViews(otherSubdocViews); - ::InsertViewsInReverseOrder(ourRemovedViews, other->mInnerView); - ::InsertViewsInReverseOrder(otherRemovedViews, mInnerView); + InsertViewsInReverseOrder(ourRemovedViews, other->mInnerView); + InsertViewsInReverseOrder(otherRemovedViews, mInnerView); } mFrameLoader.swap(other->mFrameLoader); return NS_OK; @@ -1147,7 +1145,8 @@ static CallState EndSwapDocShellsForDocument(Document& aDocument) { return CallState::Continue; } -static void EndSwapDocShellsForViews(nsView* aSibling) { + +void nsSubDocumentFrame::EndSwapDocShellsForViews(nsView* aSibling) { for (; aSibling; aSibling = aSibling->GetNextSibling()) { if (Document* doc = ::GetDocumentFromView(aSibling)) { ::EndSwapDocShellsForDocument(*doc); @@ -1178,10 +1177,10 @@ void nsSubDocumentFrame::EndSwapDocShells(nsIFrame* aOther) { AutoWeakFrame weakOther(aOther); if (mInnerView) { - ::EndSwapDocShellsForViews(mInnerView->GetFirstChild()); + EndSwapDocShellsForViews(mInnerView->GetFirstChild()); } if (other->mInnerView) { - ::EndSwapDocShellsForViews(other->mInnerView->GetFirstChild()); + EndSwapDocShellsForViews(other->mInnerView->GetFirstChild()); } diff --git a/layout/generic/nsSubDocumentFrame.h b/layout/generic/nsSubDocumentFrame.h index 4dc28e88ed44..886e4f1656dd 100644 --- a/layout/generic/nsSubDocumentFrame.h +++ b/layout/generic/nsSubDocumentFrame.h @@ -96,6 +96,10 @@ class nsSubDocumentFrame final : public nsAtomicContainerFrame, nsIDocShell* GetDocShell() const; nsresult BeginSwapDocShells(nsIFrame* aOther); void EndSwapDocShells(nsIFrame* aOther); + + static void InsertViewsInReverseOrder(nsView* aSibling, nsView* aParent); + static void EndSwapDocShellsForViews(nsView* aView); + nsView* EnsureInnerView(); nsPoint GetExtraOffset() const; nsIFrame* GetSubdocumentRootFrame(); diff --git a/layout/reftests/bugs/1624118-ref.html b/layout/reftests/bugs/1624118-ref.html new file mode 100644 index 000000000000..3c10ed7406fb --- /dev/null +++ b/layout/reftests/bugs/1624118-ref.html @@ -0,0 +1,2 @@ + + diff --git a/layout/reftests/bugs/1624118.html b/layout/reftests/bugs/1624118.html new file mode 100644 index 000000000000..a6b4a1465af4 --- /dev/null +++ b/layout/reftests/bugs/1624118.html @@ -0,0 +1,18 @@ + + + + diff --git a/layout/reftests/bugs/reftest.list b/layout/reftests/bugs/reftest.list index 7630cb9d6d93..0e6c7d1bc7e4 100644 --- a/layout/reftests/bugs/reftest.list +++ b/layout/reftests/bugs/reftest.list @@ -2074,6 +2074,7 @@ skip-if(!OSX) != 1608124-2.html 1608124-2-notref.html fuzzy(0-145,0-48536) == 1614788-1.svg 1614788-1-ref.svg # large fuzz necesary to test bug: 239,202824 is how much it differs when bug exists == blob-fallback-clip.html blob-fallback-clip-ref.html fuzzy-if(OSX,0-42,0-4) fuzzy-if(winWidget,249-249,999-999) == 1617515-1.html 1617515-1-ref.html +== 1624118.html 1624118-ref.html fuzzy(0-2,0-21184) == 1626259-1.html 1626259-1-ref.html fuzzy(0-2,0-21184) == 1626259-2.html 1626259-2-ref.html != 1642583-1.html 1642583-1-ref.html