Skip to content

Commit

Permalink
Bug 1666881 - Make fission.sessionHistoryInParent require a restart w…
Browse files Browse the repository at this point in the history
…hen switching. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D91260
  • Loading branch information
petervanderbeken committed Sep 25, 2020
1 parent 956cce1 commit b14a771
Show file tree
Hide file tree
Showing 17 changed files with 123 additions and 106 deletions.
10 changes: 6 additions & 4 deletions docshell/base/BrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ void BrowsingContext::CreateFromIPC(BrowsingContext::IPCInitializer&& aInit,
context->mCreatedDynamically = aInit.mCreatedDynamically;
if (context->GetHasSessionHistory()) {
context->CreateChildSHistory();
if (StaticPrefs::fission_sessionHistoryInParent()) {
if (StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
context->GetChildSessionHistory()->SetIndexAndLength(
aInit.mSessionHistoryIndex, aInit.mSessionHistoryCount, nsID());
}
Expand Down Expand Up @@ -2084,7 +2084,8 @@ BrowsingContext::IPCInitializer BrowsingContext::GetIPCInitializer() {
init.mUseRemoteSubframes = mUseRemoteSubframes;
init.mCreatedDynamically = mCreatedDynamically;
init.mOriginAttributes = mOriginAttributes;
if (mChildSessionHistory && StaticPrefs::fission_sessionHistoryInParent()) {
if (mChildSessionHistory &&
StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
init.mSessionHistoryIndex = mChildSessionHistory->Index();
init.mSessionHistoryCount = mChildSessionHistory->Count();
}
Expand Down Expand Up @@ -2582,7 +2583,7 @@ void BrowsingContext::InitSessionHistory() {
}

ChildSHistory* BrowsingContext::GetChildSessionHistory() {
if (!StaticPrefs::fission_sessionHistoryInParent()) {
if (!StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
// For now we're checking that the session history object for the child
// process is available before returning the ChildSHistory object, because
// it is the actual implementation that ChildSHistory forwards to. This can
Expand Down Expand Up @@ -2640,7 +2641,8 @@ bool BrowsingContext::CanSet(FieldIndex<IDX_PendingInitialization>,

void BrowsingContext::SessionHistoryChanged(int32_t aIndexDelta,
int32_t aLengthDelta) {
if (XRE_IsParentProcess() || StaticPrefs::fission_sessionHistoryInParent()) {
if (XRE_IsParentProcess() ||
StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
// This method is used to test index and length for the session history
// in child process only.
return;
Expand Down
119 changes: 61 additions & 58 deletions docshell/base/nsDocShell.cpp

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions docshell/build/nsDocShellModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ namespace mozilla {
// The one time initialization for this module
nsresult InitDocShellModule() {
mozilla::dom::BrowsingContext::Init();
nsresult rv = nsSHistory::Startup();
NS_ENSURE_SUCCESS(rv, rv);

return NS_OK;
}
Expand Down
24 changes: 13 additions & 11 deletions docshell/shistory/ChildSHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,23 @@ void ChildSHistory::SetIsInProcess(bool aIsInProcess) {
return;
}

if (mHistory || StaticPrefs::fission_sessionHistoryInParent()) {
if (mHistory || StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
return;
}

mHistory = new nsSHistory(mBrowsingContext);
}

int32_t ChildSHistory::Count() {
if (StaticPrefs::fission_sessionHistoryInParent() || mAsyncHistoryLength) {
if (StaticPrefs::fission_sessionHistoryInParent_AtStartup() ||
mAsyncHistoryLength) {
uint32_t length = mLength;
for (uint32_t i = 0; i < mPendingSHistoryChanges.Length(); ++i) {
length += mPendingSHistoryChanges[i].mLengthDelta;
}

if (mAsyncHistoryLength) {
MOZ_ASSERT(!StaticPrefs::fission_sessionHistoryInParent());
MOZ_ASSERT(!StaticPrefs::fission_sessionHistoryInParent_AtStartup());
// XXX The assertion may be too strong here, but it fires only
// when the pref is enabled.
MOZ_ASSERT(mHistory->GetCount() == int32_t(length));
Expand All @@ -59,14 +60,15 @@ int32_t ChildSHistory::Count() {
}

int32_t ChildSHistory::Index() {
if (StaticPrefs::fission_sessionHistoryInParent() || mAsyncHistoryLength) {
if (StaticPrefs::fission_sessionHistoryInParent_AtStartup() ||
mAsyncHistoryLength) {
uint32_t index = mIndex;
for (uint32_t i = 0; i < mPendingSHistoryChanges.Length(); ++i) {
index += mPendingSHistoryChanges[i].mIndexDelta;
}

if (mAsyncHistoryLength) {
MOZ_ASSERT(!StaticPrefs::fission_sessionHistoryInParent());
MOZ_ASSERT(!StaticPrefs::fission_sessionHistoryInParent_AtStartup());
int32_t realIndex;
mHistory->GetIndex(&realIndex);
// XXX The assertion may be too strong here, but it fires only
Expand Down Expand Up @@ -106,7 +108,7 @@ void ChildSHistory::SetIndexAndLength(uint32_t aIndex, uint32_t aLength,
}

void ChildSHistory::Reload(uint32_t aReloadFlags, ErrorResult& aRv) {
if (StaticPrefs::fission_sessionHistoryInParent()) {
if (StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
if (XRE_IsParentProcess()) {
nsISHistory* shistory =
mBrowsingContext->Canonical()->GetSessionHistory();
Expand Down Expand Up @@ -150,7 +152,7 @@ void ChildSHistory::Go(int32_t aOffset, bool aRequireUserInteraction,
}

// See Bug 1650095.
if (StaticPrefs::fission_sessionHistoryInParent()) {
if (StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
break;
}

Expand Down Expand Up @@ -188,7 +190,7 @@ void ChildSHistory::AsyncGo(int32_t aOffset, bool aRequireUserInteraction,
}

void ChildSHistory::GotoIndex(int32_t aIndex, ErrorResult& aRv) {
if (StaticPrefs::fission_sessionHistoryInParent()) {
if (StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
nsCOMPtr<nsISHistory> shistory = mHistory;
mBrowsingContext->HistoryGo(aIndex, [shistory](int32_t&& aRequestedIndex) {
// FIXME Should probably only do this for non-fission.
Expand All @@ -206,13 +208,13 @@ void ChildSHistory::RemovePendingHistoryNavigations() {
}

void ChildSHistory::EvictLocalContentViewers() {
if (!StaticPrefs::fission_sessionHistoryInParent()) {
if (!StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
mHistory->EvictAllContentViewers();
}
}

nsISHistory* ChildSHistory::GetLegacySHistory(ErrorResult& aError) {
if (StaticPrefs::fission_sessionHistoryInParent()) {
if (StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
aError.ThrowTypeError(
"legacySHistory is not available with session history in the parent.");
return nullptr;
Expand Down Expand Up @@ -249,7 +251,7 @@ nsISupports* ChildSHistory::GetParentObject() const {
}

void ChildSHistory::SetAsyncHistoryLength(bool aEnable, ErrorResult& aRv) {
if (StaticPrefs::fission_sessionHistoryInParent() || !mHistory) {
if (StaticPrefs::fission_sessionHistoryInParent_AtStartup() || !mHistory) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
Expand Down
19 changes: 13 additions & 6 deletions docshell/shistory/nsSHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ nsSHistory::nsSHistory(BrowsingContext* aRootBC)
mIndex(-1),
mRequestedIndex(-1),
mRootDocShellID(aRootBC->GetHistoryID()) {
static bool sCalledStartup = false;
if (!sCalledStartup) {
Startup();
sCalledStartup = true;
}

// Add this new SHistory object to the list
gSHistoryList.insertBack(this);

Expand Down Expand Up @@ -329,7 +335,7 @@ uint32_t nsSHistory::CalcMaxTotalViewers() {
// static
void nsSHistory::UpdatePrefs() {
Preferences::GetInt(PREF_SHISTORY_SIZE, &gHistoryMaxSize);
if (StaticPrefs::fission_sessionHistoryInParent()) {
if (StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
sHistoryMaxTotalViewers = 0;
return;
}
Expand Down Expand Up @@ -430,7 +436,7 @@ nsresult nsSHistory::WalkHistoryEntries(nsISHEntry* aRootEntry,
// If the SH pref is on and we are in the parent process, update
// canonical BC directly
bool foundChild = false;
if (StaticPrefs::fission_sessionHistoryInParent() &&
if (StaticPrefs::fission_sessionHistoryInParent_AtStartup() &&
XRE_IsParentProcess()) {
if (child->Canonical()->HasHistoryEntry(childEntry)) {
childBC = child;
Expand Down Expand Up @@ -681,7 +687,7 @@ nsresult nsSHistory::SetChildHistoryEntry(nsISHEntry* aEntry,
void nsSHistory::HandleEntriesToSwapInDocShell(
mozilla::dom::BrowsingContext* aBC, nsISHEntry* aOldEntry,
nsISHEntry* aNewEntry) {
bool shPref = StaticPrefs::fission_sessionHistoryInParent();
bool shPref = StaticPrefs::fission_sessionHistoryInParent_AtStartup();
if (aBC->IsInProcess() || !shPref) {
nsDocShell* docshell = static_cast<nsDocShell*>(aBC->GetDocShell());
if (docshell) {
Expand Down Expand Up @@ -1825,7 +1831,7 @@ void nsSHistory::InitiateLoad(nsISHEntry* aFrameEntry,
// a same-document navigation (see nsDocShell::IsSameDocumentNavigation), so
// record that here in the LoadingSessionHistoryEntry.
bool loadingFromActiveEntry;
if (StaticPrefs::fission_sessionHistoryInParent()) {
if (StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
loadingFromActiveEntry =
aFrameBC->Canonical()->GetActiveSessionHistoryEntry() == aFrameEntry;
} else {
Expand All @@ -1836,7 +1842,7 @@ void nsSHistory::InitiateLoad(nsISHEntry* aFrameEntry,
loadState->SetLoadIsFromSessionHistory(mRequestedIndex, Length(),
loadingFromActiveEntry);

if (StaticPrefs::fission_sessionHistoryInParent()) {
if (StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
nsCOMPtr<SessionHistoryEntry> she = do_QueryInterface(aFrameEntry);
aFrameBC->Canonical()->AddLoadingSessionHistoryEntry(
loadState->GetLoadingSessionHistoryInfo()->mLoadId, she);
Expand All @@ -1861,7 +1867,8 @@ void nsSHistory::InitiateLoad(nsISHEntry* aFrameEntry,
NS_IMETHODIMP
nsSHistory::CreateEntry(nsISHEntry** aEntry) {
nsCOMPtr<nsISHEntry> entry;
if (XRE_IsParentProcess() && StaticPrefs::fission_sessionHistoryInParent()) {
if (XRE_IsParentProcess() &&
StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
entry = new SessionHistoryEntry();
} else {
entry = new nsSHEntry();
Expand Down
2 changes: 1 addition & 1 deletion docshell/shistory/nsSHistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class nsSHistory : public mozilla::LinkedListElement<nsSHistory>,
NS_DECL_ISUPPORTS
NS_DECL_NSISHISTORY

// One time initialization method called upon docshell module construction
// One time initialization method
static nsresult Startup();
static void Shutdown();
static void UpdatePrefs();
Expand Down
3 changes: 2 additions & 1 deletion dom/base/nsCCUncollectableMarker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ void MarkDocShell(nsIDocShellTreeItem* aNode, bool aCleanupJS) {
nsISHistory* legacyHistory =
history ? history->GetLegacySHistory(ignore) : nullptr;
if (legacyHistory) {
MOZ_DIAGNOSTIC_ASSERT(!StaticPrefs::fission_sessionHistoryInParent());
MOZ_DIAGNOSTIC_ASSERT(
!StaticPrefs::fission_sessionHistoryInParent_AtStartup());
int32_t historyCount = history->Count();
for (int32_t i = 0; i < historyCount; ++i) {
nsCOMPtr<nsISHEntry> shEntry;
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsFrameLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,7 @@ void nsFrameLoader::StartDestroy(bool aForProcessSwitch) {
RefPtr<ChildSHistory> childSHistory =
browsingContext->Top()->GetChildSessionHistory();
if (childSHistory) {
if (StaticPrefs::fission_sessionHistoryInParent()) {
if (StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
browsingContext->RemoveFromSessionHistory();
} else {
AutoTArray<nsID, 16> ids({browsingContext->GetHistoryID()});
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsGlobalWindowOuter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6348,7 +6348,7 @@ bool nsGlobalWindowOuter::IsOnlyTopLevelDocumentInSHistory() {
// Disabled since IsFrame() is buggy in Fission
// MOZ_ASSERT(mBrowsingContext->IsTop());

if (StaticPrefs::fission_sessionHistoryInParent()) {
if (StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
return mBrowsingContext->GetIsSingleToplevelInHistory();
}

Expand Down
2 changes: 1 addition & 1 deletion dom/ipc/BrowserChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3450,7 +3450,7 @@ nsresult BrowserChild::CanCancelContentJS(

// If we have session history in the parent we've already performed
// the checks following, so we can return early.
if (StaticPrefs::fission_sessionHistoryInParent()) {
if (StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
*aCanCancel = true;
return NS_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/ipc/BrowserParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3519,7 +3519,7 @@ bool BrowserParent::CanCancelContentJS(
nsIURI* aNavigationURI) const {
// Pre-checking if we can cancel content js in the parent is only
// supported when session history in the parent is enabled.
if (!StaticPrefs::fission_sessionHistoryInParent()) {
if (!StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
// If session history in the parent isn't enabled, this check will
// be fully done in BrowserChild::CanCancelContentJS
return true;
Expand Down
2 changes: 1 addition & 1 deletion layout/base/nsDocumentViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@ nsDocumentViewer::Show(void) {
treeItem->GetInProcessSameTypeRootTreeItem(getter_AddRefs(root));
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(root);
RefPtr<ChildSHistory> history = webNav->GetSessionHistory();
if (!StaticPrefs::fission_sessionHistoryInParent() && history) {
if (!StaticPrefs::fission_sessionHistoryInParent_AtStartup() && history) {
int32_t prevIndex, loadedIndex;
nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(treeItem);
docShell->GetPreviousEntryIndex(&prevIndex);
Expand Down
2 changes: 1 addition & 1 deletion modules/libpref/init/StaticPrefList.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3590,7 +3590,7 @@
- name: fission.sessionHistoryInParent
type: bool
value: false
mirror: always
mirror: once

# Allow renaming of process names to the origin on nightly
# Setting this pref creates a privacy leak, but helps greatly with
Expand Down
3 changes: 2 additions & 1 deletion netwerk/ipc/DocumentLoadListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,8 @@ auto DocumentLoadListener::Open(nsDocShellLoadState* aLoadState,
mSrcdocData = aLoadState->SrcdocData();
mBaseURI = aLoadState->BaseURI();
mOriginalUriString = aLoadState->GetOriginalURIString();
if (documentContext && StaticPrefs::fission_sessionHistoryInParent()) {
if (documentContext &&
StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
// It's hard to know at this point whether session history will be enabled
// in the browsing context, so we always create an entry for a load here.
mLoadingSessionHistoryInfo =
Expand Down
3 changes: 2 additions & 1 deletion netwerk/ipc/ParentProcessDocumentChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ ParentProcessDocumentChannel::RedirectToRealChannel(
mStreamFilterEndpoints = std::move(aStreamFilterEndpoints);

if (mDocumentLoadListener->IsDocumentLoad() &&
StaticPrefs::fission_sessionHistoryInParent() && GetDocShell()) {
StaticPrefs::fission_sessionHistoryInParent_AtStartup() &&
GetDocShell()) {
GetDocShell()->SetLoadingSessionHistoryInfo(
*mDocumentLoadListener->GetLoadingSessionHistoryInfo());
}
Expand Down
22 changes: 15 additions & 7 deletions toolkit/components/sessionstore/SessionStoreListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ ContentSessionStore::ContentSessionStore(nsIDocShell* aDocShell)
mFormDataChanged(NO_CHANGE),
mStorageStatus(NO_STORAGE),
mDocCapChanged(false),
mSHistoryInParent(StaticPrefs::fission_sessionHistoryInParent()),
mSHistoryChanged(false),
mSHistoryChangedFromParent(false) {
MOZ_ASSERT(mDocShell);
Expand Down Expand Up @@ -117,6 +116,16 @@ void ContentSessionStore::ResetStorageChanges() {
mValues.Clear();
}

void ContentSessionStore::SetSHistoryChanged() {
mSHistoryChanged = StaticPrefs::fission_sessionHistoryInParent_AtStartup();
}

// Request "collect sessionHistory" from the parent process
void ContentSessionStore::SetSHistoryFromParentChanged() {
mSHistoryChangedFromParent =
StaticPrefs::fission_sessionHistoryInParent_AtStartup();
}

void ContentSessionStore::OnDocumentStart() {
mScrollChanged = PAGELOADEDSTART;
mFormDataChanged = PAGELOADEDSTART;
Expand All @@ -128,7 +137,7 @@ void ContentSessionStore::OnDocumentStart() {

SetFullStorageNeeded();

if (mSHistoryInParent) {
if (StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
mSHistoryChanged = true;
}
}
Expand All @@ -137,7 +146,7 @@ void ContentSessionStore::OnDocumentEnd() {
mScrollChanged = WITH_CHANGE;
SetFullStorageNeeded();

if (mSHistoryInParent) {
if (StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
mSHistoryChanged = true;
}
}
Expand Down Expand Up @@ -168,8 +177,7 @@ TabListener::TabListener(nsIDocShell* aDocShell, Element* aElement)
mUpdatedTimer(nullptr),
mTimeoutDisabled(false),
mUpdateInterval(15000),
mEpoch(0),
mSHistoryInParent(StaticPrefs::fission_sessionHistoryInParent()) {
mEpoch(0) {
MOZ_ASSERT(mDocShell);
}

Expand Down Expand Up @@ -219,7 +227,7 @@ nsresult TabListener::Init() {
eventTarget->AddSystemEventListener(u"mozvisualscroll"_ns, this, false);
eventTarget->AddSystemEventListener(u"input"_ns, this, false);

if (mSHistoryInParent) {
if (StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
eventTarget->AddSystemEventListener(u"DOMTitleChanged"_ns, this, false);
}

Expand Down Expand Up @@ -809,7 +817,7 @@ void TabListener::RemoveListeners() {
eventTarget->RemoveSystemEventListener(u"mozvisualscroll"_ns, this,
false);
eventTarget->RemoveSystemEventListener(u"input"_ns, this, false);
if (mSHistoryInParent) {
if (StaticPrefs::fission_sessionHistoryInParent_AtStartup()) {
eventTarget->RemoveSystemEventListener(u"DOMTitleChanged"_ns, this,
false);
}
Expand Down
Loading

0 comments on commit b14a771

Please sign in to comment.