From 2f6958666779177f1c1264258a9e0ef309afeaac Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Sun, 11 Oct 2020 19:26:51 +0000 Subject: [PATCH] Bug 1668940 - Tabs that crash in the background fail to restore with SHIP. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D92662 --- docshell/base/nsDocShell.cpp | 25 +++++++++++++------------ docshell/base/nsDocShell.h | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index d2920f05f86e..17fa0b869de3 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -3987,13 +3987,6 @@ nsresult nsDocShell::LoadErrorPage(nsIURI* aErrorURI, nsIURI* aFailedURI, // identifier, the error page won't persist. mLSHE->AbandonBFCacheEntry(); } - if (mozilla::SessionHistoryInParent()) { - // Commit the loading entry for the real load here, Embed will not commit - // the loading entry for the error page. History will then contain an entry - // for the real load, and the error page won't persist if we try loading - // that entry again. - MoveLoadingToActiveEntry(true); - } RefPtr loadState = new nsDocShellLoadState(aErrorURI); loadState->SetTriggeringPrincipal(nsContentUtils::GetSystemPrincipal()); @@ -4003,6 +3996,12 @@ nsresult nsDocShell::LoadErrorPage(nsIURI* aErrorURI, nsIURI* aFailedURI, loadState->SetLoadType(LOAD_ERROR_PAGE); loadState->SetFirstParty(true); loadState->SetSourceBrowsingContext(mBrowsingContext); + if (mozilla::SessionHistoryInParent() && mLoadingEntry) { + // We keep the loading entry for the load that failed here. If the user + // reloads we want to try to reload the original load, not the error page. + loadState->SetLoadingSessionHistoryInfo( + MakeUnique(*mLoadingEntry)); + } return InternalLoad(loadState); } @@ -5705,7 +5704,7 @@ nsresult nsDocShell::Embed(nsIContentViewer* aContentViewer, if (!aIsTransientAboutBlank && mozilla::SessionHistoryInParent()) { MOZ_LOG(gSHLog, LogLevel::Debug, ("document %p Embed", this)); - MoveLoadingToActiveEntry(mLoadType != LOAD_ERROR_PAGE); + MoveLoadingToActiveEntry(); } bool updateHistory = true; @@ -13242,7 +13241,7 @@ void nsDocShell::SetLoadingSessionHistoryInfo( mLoadingEntry = MakeUnique(aLoadingInfo); } -void nsDocShell::MoveLoadingToActiveEntry(bool aCommit) { +void nsDocShell::MoveLoadingToActiveEntry() { MOZ_ASSERT(mozilla::SessionHistoryInParent()); MOZ_LOG(gSHLog, LogLevel::Debug, @@ -13261,12 +13260,14 @@ void nsDocShell::MoveLoadingToActiveEntry(bool aCommit) { mLoadingEntry.swap(loadingEntry); } - if (mActiveEntry && aCommit) { + if (mActiveEntry) { MOZ_ASSERT(loadingEntry); nsID changeID = {}; + uint32_t loadType = + mLoadType == LOAD_ERROR_PAGE ? mFailedLoadType : mLoadType; if (XRE_IsParentProcess()) { mBrowsingContext->Canonical()->SessionHistoryCommit(loadingEntry->mLoadId, - changeID, mLoadType); + changeID, loadType); } else { RefPtr rootSH = GetRootSessionHistory(); if (rootSH) { @@ -13282,7 +13283,7 @@ void nsDocShell::MoveLoadingToActiveEntry(bool aCommit) { } ContentChild* cc = ContentChild::GetSingleton(); mozilla::Unused << cc->SendHistoryCommit( - mBrowsingContext, loadingEntry->mLoadId, changeID, mLoadType); + mBrowsingContext, loadingEntry->mLoadId, changeID, loadType); } } } diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index 2316f5645482..02b8bc9745f9 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -1104,7 +1104,7 @@ class nsDocShell final : public nsDocLoader, // Sets the active entry to the current loading entry. If aCommit is true then // SessionHistoryCommit will be called on the CanonicalBrowsingContext // (directly or over IPC). - void MoveLoadingToActiveEntry(bool aCommit); + void MoveLoadingToActiveEntry(); private: // data members nsString mTitle;