From 60b0bda8c8240d2f310183b255511d4d444686aa Mon Sep 17 00:00:00 2001 From: Chris Pearce Date: Wed, 15 Aug 2012 13:51:19 +1200 Subject: [PATCH] Bug 725770. r=bz --- docshell/base/Makefile.in | 3 +++ docshell/base/nsDocShell.cpp | 32 +++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/docshell/base/Makefile.in b/docshell/base/Makefile.in index f4b1c23f81c4..afd638a2ab07 100644 --- a/docshell/base/Makefile.in +++ b/docshell/base/Makefile.in @@ -94,4 +94,7 @@ LOCAL_INCLUDES += \ -I$(topsrcdir)/dom/base \ -I$(topsrcdir)/layout/base \ -I$(topsrcdir)/xpcom/ds \ + -I$(topsrcdir)/layout/generic \ + -I$(topsrcdir)/layout/xul/base/src \ + -I$(topsrcdir)/content/base/src \ $(NULL) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index bceb542f5bff..f75f67c0b89b 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -170,6 +170,7 @@ #include "nsEventStateManager.h" #include "nsIFrame.h" +#include "nsSubDocumentFrame.h" // for embedding #include "nsIWebBrowserChromeFocus.h" @@ -7162,7 +7163,7 @@ nsDocShell::RestoreFromHistory() // Make sure to blow away our mLoadingURI just in case. No loads // from inside this pagehide. mLoadingURI = nullptr; - + // Notify the old content viewer that it's being hidden. FirePageHideNotification(!mSavingOldViewer); @@ -7243,6 +7244,17 @@ nsDocShell::RestoreFromHistory() } } + nsCOMPtr container; + nsCOMPtr sibling; + if (rootViewParent && rootViewParent->GetParent()) { + nsIFrame* frame = rootViewParent->GetParent()->GetFrame(); + container = frame ? frame->GetContent() : nullptr; + } + if (rootViewSibling) { + nsIFrame *frame = rootViewSibling->GetFrame(); + sibling = frame ? frame->PresContext()->PresShell()->GetDocument() : nullptr; + } + // Transfer ownership to mContentViewer. By ensuring that either the // docshell or the session history, but not both, have references to the // content viewer, we prevent the viewer from being torn down after @@ -7331,7 +7343,7 @@ nsDocShell::RestoreFromHistory() // mLSHE is now our currently-loaded document. SetHistoryEntry(&mOSHE, mLSHE); - + // XXX special wyciwyg handling in Embed()? // We aren't going to restore any items from the LayoutHistoryState, @@ -7445,10 +7457,20 @@ nsDocShell::RestoreFromHistory() nsIView *newRootView = newVM ? newVM->GetRootView() : nullptr; // Insert the new root view at the correct location in the view tree. - if (rootViewParent) { + if (container) { + nsSubDocumentFrame* subDocFrame = do_QueryFrame(container->GetPrimaryFrame()); + rootViewParent = subDocFrame ? subDocFrame->EnsureInnerView() : nullptr; + } + if (sibling && + sibling->GetShell() && + sibling->GetShell()->GetViewManager()) { + rootViewSibling = sibling->GetShell()->GetViewManager()->GetRootView(); + } else { + rootViewSibling = nullptr; + } + if (rootViewParent && newRootView && newRootView->GetParent() != rootViewParent) { nsIViewManager *parentVM = rootViewParent->GetViewManager(); - - if (parentVM && newRootView) { + if (parentVM) { // InsertChild(parent, child, sib, true) inserts the child after // sib in content order, which is before sib in view order. BUT // when sib is null it inserts at the end of the the document