mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-26 04:09:50 +00:00
Bug 1765951 - Stop storing BC pointer in nsSHistory. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D146205
This commit is contained in:
parent
20c48b14ce
commit
d383ef7822
@ -1116,7 +1116,7 @@ void CanonicalBrowsingContext::RemoveFromSessionHistory(const nsID& aChangeID) {
|
||||
AutoTArray<nsID, 16> ids({GetHistoryID()});
|
||||
shistory->RemoveEntries(ids, shistory->GetIndexOfEntry(root), &didRemove);
|
||||
if (didRemove) {
|
||||
BrowsingContext* rootBC = shistory->GetBrowsingContext();
|
||||
RefPtr<BrowsingContext> rootBC = shistory->GetBrowsingContext();
|
||||
if (rootBC) {
|
||||
if (!rootBC->IsInProcess()) {
|
||||
if (ContentParent* cp = rootBC->Canonical()->GetContentParent()) {
|
||||
|
@ -160,11 +160,9 @@ class MOZ_STACK_CLASS SHistoryChangeNotifier {
|
||||
MOZ_ASSERT(mSHistory->HasOngoingUpdate());
|
||||
mSHistory->SetHasOngoingUpdate(false);
|
||||
|
||||
if (mozilla::SessionHistoryInParent() &&
|
||||
mSHistory->GetBrowsingContext()) {
|
||||
mSHistory->GetBrowsingContext()
|
||||
->Canonical()
|
||||
->HistoryCommitIndexAndLength();
|
||||
RefPtr<BrowsingContext> rootBC = mSHistory->GetBrowsingContext();
|
||||
if (mozilla::SessionHistoryInParent() && rootBC) {
|
||||
rootBC->Canonical()->HistoryCommitIndexAndLength();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -247,7 +245,7 @@ void nsSHistory::EvictContentViewerForEntry(nsISHEntry* aEntry) {
|
||||
}
|
||||
|
||||
nsSHistory::nsSHistory(BrowsingContext* aRootBC)
|
||||
: mRootBC(aRootBC),
|
||||
: mRootBC(aRootBC->Id()),
|
||||
mHasOngoingUpdate(false),
|
||||
mIndex(-1),
|
||||
mRequestedIndex(-1),
|
||||
@ -717,13 +715,13 @@ void nsSHistory::HandleEntriesToSwapInDocShell(
|
||||
}
|
||||
}
|
||||
|
||||
void nsSHistory::UpdateRootBrowsingContextState() {
|
||||
if (mRootBC && mRootBC->EverAttached()) {
|
||||
void nsSHistory::UpdateRootBrowsingContextState(BrowsingContext* aRootBC) {
|
||||
if (aRootBC && aRootBC->EverAttached()) {
|
||||
bool sameDocument = IsEmptyOrHasEntriesForSingleTopLevelPage();
|
||||
if (sameDocument != mRootBC->GetIsSingleToplevelInHistory()) {
|
||||
if (sameDocument != aRootBC->GetIsSingleToplevelInHistory()) {
|
||||
// If the browsing context is discarded then its session history is
|
||||
// invalid and will go away.
|
||||
Unused << mRootBC->SetIsSingleToplevelInHistory(sameDocument);
|
||||
Unused << aRootBC->SetIsSingleToplevelInHistory(sameDocument);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -801,7 +799,8 @@ nsSHistory::AddEntry(nsISHEntry* aSHEntry, bool aPersist) {
|
||||
|
||||
// If we have a root docshell, update the docshell id of the root shentry to
|
||||
// match the id of that docshell
|
||||
if (mRootBC) {
|
||||
RefPtr<BrowsingContext> rootBC = GetBrowsingContext();
|
||||
if (rootBC) {
|
||||
aSHEntry->SetDocshellID(mRootDocShellID);
|
||||
}
|
||||
|
||||
@ -1056,8 +1055,9 @@ nsSHistory::PurgeHistory(int32_t aNumEntries) {
|
||||
}
|
||||
}
|
||||
|
||||
if (mRootBC) {
|
||||
mRootBC->PreOrderWalk([&docshellIDToEntry](BrowsingContext* aBC) {
|
||||
RefPtr<BrowsingContext> rootBC = GetBrowsingContext();
|
||||
if (rootBC) {
|
||||
rootBC->PreOrderWalk([&docshellIDToEntry](BrowsingContext* aBC) {
|
||||
SessionHistoryEntry* entry = docshellIDToEntry.Get(aBC->GetHistoryID());
|
||||
Unused << aBC->SetHistoryEntryCount(
|
||||
entry ? uint32_t(entry->BCHistoryLength()) : 0);
|
||||
@ -1073,11 +1073,11 @@ nsSHistory::PurgeHistory(int32_t aNumEntries) {
|
||||
mRequestedIndex -= aNumEntries;
|
||||
mRequestedIndex = std::max(mRequestedIndex, -1);
|
||||
|
||||
if (mRootBC && mRootBC->GetDocShell()) {
|
||||
mRootBC->GetDocShell()->HistoryPurged(aNumEntries);
|
||||
if (rootBC && rootBC->GetDocShell()) {
|
||||
rootBC->GetDocShell()->HistoryPurged(aNumEntries);
|
||||
}
|
||||
|
||||
UpdateRootBrowsingContextState();
|
||||
UpdateRootBrowsingContextState(rootBC);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1911,8 +1911,11 @@ NS_IMETHODIMP_(void)
|
||||
nsSHistory::RemoveEntries(nsTArray<nsID>& aIDs, int32_t aStartIndex) {
|
||||
bool didRemove;
|
||||
RemoveEntries(aIDs, aStartIndex, &didRemove);
|
||||
if (didRemove && mRootBC && mRootBC->GetDocShell()) {
|
||||
mRootBC->GetDocShell()->DispatchLocationChangeEvent();
|
||||
if (didRemove) {
|
||||
RefPtr<BrowsingContext> rootBC = GetBrowsingContext();
|
||||
if (rootBC && rootBC->GetDocShell()) {
|
||||
rootBC->GetDocShell()->DispatchLocationChangeEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2052,7 +2055,8 @@ nsresult nsSHistory::LoadEntry(int32_t aIndex, long aLoadType,
|
||||
bool aUserActivation) {
|
||||
MOZ_LOG(gSHistoryLog, LogLevel::Debug,
|
||||
("LoadEntry(%d, 0x%lx, %u)", aIndex, aLoadType, aHistCmd));
|
||||
if (!mRootBC) {
|
||||
RefPtr<BrowsingContext> rootBC = GetBrowsingContext();
|
||||
if (!rootBC) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@ -2127,14 +2131,14 @@ nsresult nsSHistory::LoadEntry(int32_t aIndex, long aLoadType,
|
||||
|
||||
if (mRequestedIndex == mIndex) {
|
||||
// Possibly a reload case
|
||||
InitiateLoad(nextEntry, mRootBC, aLoadType, aLoadResults, aLoadCurrentEntry,
|
||||
InitiateLoad(nextEntry, rootBC, aLoadType, aLoadResults, aLoadCurrentEntry,
|
||||
aUserActivation, requestedOffset);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Going back or forward.
|
||||
bool differenceFound = LoadDifferingEntries(
|
||||
prevEntry, nextEntry, mRootBC, aLoadType, aLoadResults, aLoadCurrentEntry,
|
||||
prevEntry, nextEntry, rootBC, aLoadType, aLoadResults, aLoadCurrentEntry,
|
||||
aUserActivation, requestedOffset);
|
||||
if (!differenceFound) {
|
||||
// LoadNextPossibleEntry will change the offset by one, and in order
|
||||
@ -2163,7 +2167,7 @@ bool nsSHistory::LoadDifferingEntries(nsISHEntry* aPrevEntry,
|
||||
// Check the IDs to verify if the pages are different.
|
||||
if (prevID != nextID) {
|
||||
// Set the Subframe flag if not navigating the root docshell.
|
||||
aNextEntry->SetIsSubFrame(aParent != mRootBC);
|
||||
aNextEntry->SetIsSubFrame(aParent->Id() != mRootBC);
|
||||
InitiateLoad(aNextEntry, aParent, aLoadType, aLoadResults,
|
||||
aLoadCurrentEntry, aUserActivation, aOffset);
|
||||
return true;
|
||||
|
@ -174,16 +174,18 @@ class nsSHistory : public mozilla::LinkedListElement<nsSHistory>,
|
||||
|
||||
int32_t Length() { return int32_t(mEntries.Length()); }
|
||||
int32_t Index() { return mIndex; }
|
||||
mozilla::dom::BrowsingContext* GetBrowsingContext() { return mRootBC; }
|
||||
already_AddRefed<mozilla::dom::BrowsingContext> GetBrowsingContext() {
|
||||
return mozilla::dom::BrowsingContext::Get(mRootBC);
|
||||
}
|
||||
bool HasOngoingUpdate() { return mHasOngoingUpdate; }
|
||||
void SetHasOngoingUpdate(bool aVal) { mHasOngoingUpdate = aVal; }
|
||||
|
||||
void SetBrowsingContext(mozilla::dom::BrowsingContext* aRootBC) {
|
||||
if (mRootBC == aRootBC) {
|
||||
return;
|
||||
uint64_t newID = aRootBC ? aRootBC->Id() : 0;
|
||||
if (mRootBC != newID) {
|
||||
mRootBC = newID;
|
||||
UpdateRootBrowsingContextState(aRootBC);
|
||||
}
|
||||
mRootBC = aRootBC;
|
||||
UpdateRootBrowsingContextState();
|
||||
}
|
||||
|
||||
int32_t GetIndexForReplace() {
|
||||
@ -195,7 +197,10 @@ class nsSHistory : public mozilla::LinkedListElement<nsSHistory>,
|
||||
|
||||
// Update the root browsing context state when adding, removing or
|
||||
// replacing entries.
|
||||
void UpdateRootBrowsingContextState();
|
||||
void UpdateRootBrowsingContextState() {
|
||||
RefPtr<mozilla::dom::BrowsingContext> rootBC(GetBrowsingContext());
|
||||
UpdateRootBrowsingContextState(rootBC);
|
||||
}
|
||||
|
||||
void GetEpoch(uint64_t& aEpoch,
|
||||
mozilla::Maybe<mozilla::dom::ContentParentId>& aId) const {
|
||||
@ -213,12 +218,14 @@ class nsSHistory : public mozilla::LinkedListElement<nsSHistory>,
|
||||
protected:
|
||||
virtual ~nsSHistory();
|
||||
|
||||
// Weak reference. Do not refcount this.
|
||||
mozilla::dom::BrowsingContext* mRootBC;
|
||||
uint64_t mRootBC;
|
||||
|
||||
private:
|
||||
friend class nsSHistoryObserver;
|
||||
|
||||
void UpdateRootBrowsingContextState(
|
||||
mozilla::dom::BrowsingContext* aBrowsingContext);
|
||||
|
||||
bool LoadDifferingEntries(nsISHEntry* aPrevEntry, nsISHEntry* aNextEntry,
|
||||
mozilla::dom::BrowsingContext* aParent,
|
||||
long aLoadType,
|
||||
|
Loading…
x
Reference in New Issue
Block a user