Bug 1629866 - Store ChildSHistory on the BrowsingContext. r=nika,smaug

Differential Revision: https://phabricator.services.mozilla.com/D70997
This commit is contained in:
Peter Van der Beken
2020-05-13 13:41:16 +00:00
parent c3062e6316
commit 07d061c584
15 changed files with 158 additions and 121 deletions

View File

@@ -423,10 +423,6 @@ nsDocShell::~nsDocShell() {
Destroy();
if (mSessionHistory) {
mSessionHistory->LegacySHistory()->ClearRootBrowsingContext();
}
if (mContentViewer) {
mContentViewer->Close(nullptr);
mContentViewer->Destroy();
@@ -544,7 +540,7 @@ void nsDocShell::DestroyChildren() {
NS_IMPL_CYCLE_COLLECTION_WEAK_PTR_INHERITED(nsDocShell, nsDocLoader,
mScriptGlobal, mInitialClientSource,
mSessionHistory, mBrowsingContext,
mBrowsingContext,
mChromeEventHandler)
NS_IMPL_ADDREF_INHERITED(nsDocShell, nsDocLoader)
@@ -2955,8 +2951,8 @@ nsresult nsDocShell::AddChildSHEntryInternal(nsISHEntry* aCloneRef,
uint32_t aLoadType,
bool aCloneChildren) {
nsresult rv = NS_OK;
if (mSessionHistory) {
rv = mSessionHistory->LegacySHistory()->AddChildSHEntryHelper(
if (GetSessionHistory()) {
rv = GetSessionHistory()->LegacySHistory()->AddChildSHEntryHelper(
aCloneRef, aNewEntry, mBrowsingContext, aCloneChildren);
} else {
/* Just pass this along */
@@ -3010,13 +3006,8 @@ nsresult nsDocShell::AddChildSHEntryToParent(nsISHEntry* aNewEntry,
NS_IMETHODIMP
nsDocShell::RemoveFromSessionHistory() {
nsCOMPtr<nsIDocShellTreeItem> root;
GetInProcessSameTypeRootTreeItem(getter_AddRefs(root));
nsCOMPtr<nsIWebNavigation> rootAsWebnav = do_QueryInterface(root);
if (!rootAsWebnav) {
return NS_OK;
}
RefPtr<ChildSHistory> sessionHistory = rootAsWebnav->GetSessionHistory();
RefPtr<ChildSHistory> sessionHistory =
mBrowsingContext->Top()->GetChildSessionHistory();
if (!sessionHistory) {
return NS_OK;
}
@@ -4081,26 +4072,10 @@ nsDocShell::GetCurrentURI(nsIURI** aURI) {
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::InitSessionHistory() {
MOZ_ASSERT(!mIsBeingDestroyed);
// Make sure that we are the root DocShell, and set a handle to root docshell
// in the session history.
nsCOMPtr<nsIDocShellTreeItem> root;
GetInProcessSameTypeRootTreeItem(getter_AddRefs(root));
if (root != this) {
return NS_ERROR_FAILURE;
}
mSessionHistory = new ChildSHistory(this);
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GetSessionHistoryXPCOM(nsISupports** aSessionHistory) {
NS_ENSURE_ARG_POINTER(aSessionHistory);
RefPtr<ChildSHistory> shistory = mSessionHistory;
RefPtr<ChildSHistory> shistory = GetSessionHistory();
shistory.forget(aSessionHistory);
return NS_OK;
}
@@ -4321,12 +4296,11 @@ nsDocShell::Destroy() {
mScriptGlobal = nullptr;
}
if (mSessionHistory) {
if (GetSessionHistory()) {
// We want to destroy these content viewers now rather than
// letting their destruction wait for the session history
// entries to get garbage collected. (Bug 488394)
mSessionHistory->EvictLocalContentViewers();
mSessionHistory = nullptr;
GetSessionHistory()->EvictLocalContentViewers();
}
if (mWillChangeProcess) {
@@ -7520,13 +7494,13 @@ nsresult nsDocShell::CreateContentViewer(const nsACString& aContentType,
// Be sure to have a correct mLSHE, it may have been cleared by
// EndPageLoad. See bug 302115.
if (mSessionHistory && !mLSHE) {
int32_t idx = mSessionHistory->LegacySHistory()->GetRequestedIndex();
ChildSHistory* shistory = GetSessionHistory();
if (shistory && !mLSHE) {
int32_t idx = shistory->LegacySHistory()->GetRequestedIndex();
if (idx == -1) {
idx = mSessionHistory->Index();
idx = shistory->Index();
}
mSessionHistory->LegacySHistory()->GetEntryAtIndex(idx,
getter_AddRefs(mLSHE));
shistory->LegacySHistory()->GetEntryAtIndex(idx, getter_AddRefs(mLSHE));
}
mLoadType = LOAD_ERROR_PAGE;
@@ -8446,11 +8420,11 @@ nsresult nsDocShell::HandleSameDocumentNavigation(
/* Set the title for the SH entry for this target url. so that
* SH menus in go/back/forward buttons won't be empty for this.
*/
if (mSessionHistory) {
int32_t index = mSessionHistory->Index();
ChildSHistory* shistory = GetSessionHistory();
if (shistory) {
int32_t index = shistory->Index();
nsCOMPtr<nsISHEntry> shEntry;
mSessionHistory->LegacySHistory()->GetEntryAtIndex(index,
getter_AddRefs(shEntry));
shistory->LegacySHistory()->GetEntryAtIndex(index, getter_AddRefs(shEntry));
NS_ENSURE_TRUE(shEntry, NS_ERROR_FAILURE);
shEntry->SetTitle(mTitle);
}
@@ -10095,12 +10069,9 @@ bool nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel,
(IsForceReloadType(aLoadType) && IsFrame()));
// Create SH Entry (mLSHE) only if there is a SessionHistory object in the
// current frame or in the root docshell.
RefPtr<ChildSHistory> rootSH = mSessionHistory;
if (!rootSH) {
// Get the handle to SH from the root docshell
rootSH = GetRootSessionHistory();
}
// in the root browsing context.
RefPtr<ChildSHistory> rootSH =
mBrowsingContext->Top()->GetChildSessionHistory();
if (!rootSH) {
updateSHistory = false;
updateGHistory = false; // XXX Why global history too?
@@ -10203,11 +10174,11 @@ bool nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel,
aPrincipalToInherit, aStoragePrincipalToInherit,
aCsp, aCloneSHChildren, getter_AddRefs(mLSHE));
}
} else if (mSessionHistory && mLSHE && mURIResultedInDocument) {
} else if (GetSessionHistory() && mLSHE && mURIResultedInDocument) {
// Even if we don't add anything to SHistory, ensure the current index
// points to the same SHEntry as our mLSHE.
mSessionHistory->LegacySHistory()->EnsureCorrectEntryAtCurrIndex(mLSHE);
GetSessionHistory()->LegacySHistory()->EnsureCorrectEntryAtCurrIndex(mLSHE);
}
// If this is a POST request, we do not want to include this in global
@@ -10846,11 +10817,11 @@ nsresult nsDocShell::AddToSessionHistory(
loadReplace, referrerInfo, srcdoc, srcdocEntry, baseURI,
saveLayoutState, expired);
if (root == static_cast<nsIDocShellTreeItem*>(this) && mSessionHistory) {
if (root == static_cast<nsIDocShellTreeItem*>(this) && GetSessionHistory()) {
bool shouldPersist = ShouldAddToSessionHistory(aURI, aChannel);
Maybe<int32_t> previousEntryIndex;
Maybe<int32_t> loadedEntryIndex;
rv = mSessionHistory->LegacySHistory()->AddToRootSessionHistory(
rv = GetSessionHistory()->LegacySHistory()->AddToRootSessionHistory(
aCloneChildren, mOSHE, mBrowsingContext, entry, mLoadType,
shouldPersist, &previousEntryIndex, &loadedEntryIndex);
@@ -12259,9 +12230,9 @@ nsDocShell::ResumeRedirectedLoad(uint64_t aIdentifier, int32_t aHistoryIndex) {
// If we're performing a history load, locate the correct history entry,
// and set the relevant bits on our loadState.
if (aHistoryIndex >= 0 && self->mSessionHistory) {
if (aHistoryIndex >= 0 && self->GetSessionHistory()) {
nsCOMPtr<nsISHistory> legacySHistory =
self->mSessionHistory->LegacySHistory();
self->GetSessionHistory()->LegacySHistory();
nsCOMPtr<nsISHEntry> entry;
nsresult rv = legacySHistory->GetEntryAtIndex(aHistoryIndex,