mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
Bug 1658821 - Move Id from SessionHistoryInfo to LoadingSessionHistoryInfo, r=peterv
Differential Revision: https://phabricator.services.mozilla.com/D86864
This commit is contained in:
parent
3e50b7e4ee
commit
0bd5beeadf
@ -292,32 +292,40 @@ CanonicalBrowsingContext::CreateLoadingSessionHistoryEntryForLoad(
|
||||
const LoadingSessionHistoryInfo* existingLoadingInfo =
|
||||
aLoadState->GetLoadingSessionHistoryInfo();
|
||||
if (existingLoadingInfo) {
|
||||
entry = SessionHistoryEntry::GetByInfoId(existingLoadingInfo->mInfo.Id());
|
||||
entry = SessionHistoryEntry::GetByLoadId(existingLoadingInfo->mLoadId);
|
||||
} else {
|
||||
entry = new SessionHistoryEntry(aLoadState, aChannel);
|
||||
}
|
||||
MOZ_DIAGNOSTIC_ASSERT(entry);
|
||||
|
||||
mLoadingEntries.AppendElement(entry);
|
||||
MOZ_ASSERT(SessionHistoryEntry::GetByInfoId(entry->Info().Id()) == entry);
|
||||
UniquePtr<LoadingSessionHistoryInfo> loadingInfo;
|
||||
if (existingLoadingInfo) {
|
||||
return MakeUnique<LoadingSessionHistoryInfo>(*existingLoadingInfo);
|
||||
loadingInfo = MakeUnique<LoadingSessionHistoryInfo>(*existingLoadingInfo);
|
||||
} else {
|
||||
loadingInfo = MakeUnique<LoadingSessionHistoryInfo>(entry);
|
||||
}
|
||||
return MakeUnique<LoadingSessionHistoryInfo>(entry->Info());
|
||||
|
||||
MOZ_ASSERT(SessionHistoryEntry::GetByLoadId(loadingInfo->mLoadId) == entry);
|
||||
mLoadingEntries.AppendElement(
|
||||
LoadingSessionHistoryEntry{loadingInfo->mLoadId, entry});
|
||||
return loadingInfo;
|
||||
}
|
||||
|
||||
void CanonicalBrowsingContext::SessionHistoryCommit(
|
||||
uint64_t aSessionHistoryEntryId, const nsID& aChangeID) {
|
||||
void CanonicalBrowsingContext::SessionHistoryCommit(uint64_t aLoadId,
|
||||
const nsID& aChangeID) {
|
||||
for (size_t i = 0; i < mLoadingEntries.Length(); ++i) {
|
||||
if (mLoadingEntries[i]->Info().Id() == aSessionHistoryEntryId) {
|
||||
if (mLoadingEntries[i].mLoadId == aLoadId) {
|
||||
nsISHistory* shistory = GetSessionHistory();
|
||||
if (!shistory) {
|
||||
SessionHistoryEntry::RemoveLoadId(aLoadId);
|
||||
mLoadingEntries.RemoveElementAt(i);
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<SessionHistoryEntry> oldActiveEntry = mActiveEntry.forget();
|
||||
mActiveEntry = mLoadingEntries[i];
|
||||
mActiveEntry = mLoadingEntries[i].mEntry;
|
||||
|
||||
SessionHistoryEntry::RemoveLoadId(aLoadId);
|
||||
mLoadingEntries.RemoveElementAt(i);
|
||||
if (IsTop()) {
|
||||
nsCOMPtr<nsISHistory> existingSHistory = mActiveEntry->GetShistory();
|
||||
@ -382,7 +390,7 @@ void CanonicalBrowsingContext::NotifyOnHistoryReload(
|
||||
aReloadActiveEntry.emplace(true);
|
||||
} else if (!mLoadingEntries.IsEmpty()) {
|
||||
aLoadState.emplace();
|
||||
mLoadingEntries.LastElement()->CreateLoadInfo(
|
||||
mLoadingEntries.LastElement().mEntry->CreateLoadInfo(
|
||||
getter_AddRefs(aLoadState.ref()));
|
||||
aReloadActiveEntry.emplace(false);
|
||||
}
|
||||
|
@ -100,8 +100,7 @@ class CanonicalBrowsingContext final : public BrowsingContext {
|
||||
|
||||
UniquePtr<LoadingSessionHistoryInfo> CreateLoadingSessionHistoryEntryForLoad(
|
||||
nsDocShellLoadState* aLoadState, nsIChannel* aChannel);
|
||||
void SessionHistoryCommit(uint64_t aSessionHistoryEntryId,
|
||||
const nsID& aChangeID);
|
||||
void SessionHistoryCommit(uint64_t aLoadId, const nsID& aChangeID);
|
||||
|
||||
// Calls the session history listeners' OnHistoryReload, storing the result in
|
||||
// aCanReload. If aCanReload is set to true and we have an active or a loading
|
||||
@ -284,7 +283,11 @@ class CanonicalBrowsingContext final : public BrowsingContext {
|
||||
|
||||
RefPtr<net::DocumentLoadListener> mCurrentLoad;
|
||||
|
||||
nsTArray<RefPtr<SessionHistoryEntry>> mLoadingEntries;
|
||||
struct LoadingSessionHistoryEntry {
|
||||
uint64_t mLoadId = 0;
|
||||
RefPtr<SessionHistoryEntry> mEntry;
|
||||
};
|
||||
nsTArray<LoadingSessionHistoryEntry> mLoadingEntries;
|
||||
RefPtr<SessionHistoryEntry> mActiveEntry;
|
||||
|
||||
RefPtr<nsSecureBrowserUI> mSecureBrowserUI;
|
||||
|
@ -5427,8 +5427,8 @@ nsresult nsDocShell::Embed(nsIContentViewer* aContentViewer,
|
||||
MOZ_ASSERT(loadingEntry);
|
||||
nsID changeID = {};
|
||||
if (XRE_IsParentProcess()) {
|
||||
mBrowsingContext->Canonical()->SessionHistoryCommit(mActiveEntry->Id(),
|
||||
changeID);
|
||||
mBrowsingContext->Canonical()->SessionHistoryCommit(
|
||||
loadingEntry->mLoadId, changeID);
|
||||
} else {
|
||||
RefPtr<ChildSHistory> rootSH = GetRootSessionHistory();
|
||||
if (rootSH) {
|
||||
@ -5443,8 +5443,8 @@ nsresult nsDocShell::Embed(nsIContentViewer* aContentViewer,
|
||||
}
|
||||
}
|
||||
ContentChild* cc = ContentChild::GetSingleton();
|
||||
mozilla::Unused << cc->SendHistoryCommit(mBrowsingContext,
|
||||
mActiveEntry->Id(), changeID);
|
||||
mozilla::Unused << cc->SendHistoryCommit(
|
||||
mBrowsingContext, loadingEntry->mLoadId, changeID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -510,7 +510,7 @@ void nsDocShellLoadState::SetSHEntry(nsISHEntry* aSHEntry) {
|
||||
mSHEntry = aSHEntry;
|
||||
nsCOMPtr<SessionHistoryEntry> she = do_QueryInterface(aSHEntry);
|
||||
if (she) {
|
||||
SetLoadingSessionHistoryInfo(LoadingSessionHistoryInfo(she->Info()));
|
||||
mLoadingSessionHistoryInfo = MakeUnique<LoadingSessionHistoryInfo>(she);
|
||||
} else {
|
||||
mLoadingSessionHistoryInfo = nullptr;
|
||||
}
|
||||
|
@ -15,11 +15,6 @@
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
static uint64_t gNextHistoryEntryId = 0;
|
||||
|
||||
SessionHistoryInfo::SessionHistoryInfo(uint64_t aExistingId)
|
||||
: mId(aExistingId) {}
|
||||
|
||||
SessionHistoryInfo::SessionHistoryInfo(nsDocShellLoadState* aLoadState,
|
||||
nsIChannel* aChannel)
|
||||
: mURI(aLoadState->URI()),
|
||||
@ -32,7 +27,6 @@ SessionHistoryInfo::SessionHistoryInfo(nsDocShellLoadState* aLoadState,
|
||||
mScrollPositionY(0),
|
||||
mSrcdocData(aLoadState->SrcdocData()),
|
||||
mBaseURI(aLoadState->BaseURI()),
|
||||
mId(++gNextHistoryEntryId),
|
||||
mLoadReplace(aLoadState->LoadReplace()),
|
||||
mURIWasModified(false),
|
||||
/* FIXME Should this be aLoadState->IsSrcdocLoad()? */
|
||||
@ -56,33 +50,45 @@ void SessionHistoryInfo::MaybeUpdateTitleFromURI() {
|
||||
}
|
||||
}
|
||||
|
||||
static uint64_t gLoadingSessionHistoryInfoLoadId = 0;
|
||||
|
||||
nsDataHashtable<nsUint64HashKey, SessionHistoryEntry*>*
|
||||
SessionHistoryEntry::sLoadIdToEntry = nullptr;
|
||||
|
||||
LoadingSessionHistoryInfo::LoadingSessionHistoryInfo(
|
||||
const SessionHistoryInfo& aInfo)
|
||||
: mInfo(aInfo) {}
|
||||
SessionHistoryEntry* aEntry)
|
||||
: mInfo(aEntry->Info()), mLoadId(++gLoadingSessionHistoryInfoLoadId) {
|
||||
if (!SessionHistoryEntry::sLoadIdToEntry) {
|
||||
SessionHistoryEntry::sLoadIdToEntry =
|
||||
new nsDataHashtable<nsUint64HashKey, SessionHistoryEntry*>();
|
||||
}
|
||||
SessionHistoryEntry::sLoadIdToEntry->Put(mLoadId, aEntry);
|
||||
}
|
||||
|
||||
static uint32_t gEntryID;
|
||||
nsDataHashtable<nsUint64HashKey, SessionHistoryEntry*>*
|
||||
SessionHistoryEntry::sInfoIdToEntry = nullptr;
|
||||
|
||||
SessionHistoryEntry* SessionHistoryEntry::GetByInfoId(uint64_t aId) {
|
||||
SessionHistoryEntry* SessionHistoryEntry::GetByLoadId(uint64_t aLoadId) {
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
if (!sInfoIdToEntry) {
|
||||
if (!sLoadIdToEntry) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return sInfoIdToEntry->Get(aId);
|
||||
return sLoadIdToEntry->Get(aLoadId);
|
||||
}
|
||||
|
||||
void SessionHistoryEntry::RemoveLoadId(uint64_t aLoadId) {
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
if (!sLoadIdToEntry) {
|
||||
return;
|
||||
}
|
||||
|
||||
sLoadIdToEntry->Remove(aLoadId);
|
||||
}
|
||||
|
||||
SessionHistoryEntry::SessionHistoryEntry()
|
||||
: mInfo(new SessionHistoryInfo(++gNextHistoryEntryId)),
|
||||
: mInfo(new SessionHistoryInfo()),
|
||||
mSharedInfo(new SHEntrySharedParentState()),
|
||||
mID(++gEntryID) {
|
||||
if (!sInfoIdToEntry) {
|
||||
sInfoIdToEntry =
|
||||
new nsDataHashtable<nsUint64HashKey, SessionHistoryEntry*>();
|
||||
}
|
||||
sInfoIdToEntry->Put(Info().Id(), this);
|
||||
}
|
||||
mID(++gEntryID) {}
|
||||
|
||||
SessionHistoryEntry::SessionHistoryEntry(nsDocShellLoadState* aLoadState,
|
||||
nsIChannel* aChannel)
|
||||
@ -95,19 +101,16 @@ SessionHistoryEntry::SessionHistoryEntry(nsDocShellLoadState* aLoadState,
|
||||
aLoadState->PartitionedPrincipalToInherit();
|
||||
mSharedInfo->mCsp = aLoadState->Csp();
|
||||
// FIXME Set remaining shared fields!
|
||||
|
||||
if (!sInfoIdToEntry) {
|
||||
sInfoIdToEntry =
|
||||
new nsDataHashtable<nsUint64HashKey, SessionHistoryEntry*>();
|
||||
}
|
||||
sInfoIdToEntry->Put(Info().Id(), this);
|
||||
}
|
||||
|
||||
SessionHistoryEntry::~SessionHistoryEntry() {
|
||||
sInfoIdToEntry->Remove(Info().Id());
|
||||
if (sInfoIdToEntry->IsEmpty()) {
|
||||
delete sInfoIdToEntry;
|
||||
sInfoIdToEntry = nullptr;
|
||||
if (sLoadIdToEntry) {
|
||||
sLoadIdToEntry->RemoveIf(
|
||||
[this](auto& aIter) { return aIter.Data() == this; });
|
||||
if (sLoadIdToEntry->IsEmpty()) {
|
||||
delete sLoadIdToEntry;
|
||||
sLoadIdToEntry = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1001,12 +1004,12 @@ void IPDLParamTraits<dom::LoadingSessionHistoryInfo>::Write(
|
||||
WriteIPDLParam(aMsg, aActor, info.mSrcdocData);
|
||||
WriteIPDLParam(aMsg, aActor, info.mBaseURI);
|
||||
WriteIPDLParam(aMsg, aActor, info.mLayoutHistoryState);
|
||||
WriteIPDLParam(aMsg, aActor, info.mId);
|
||||
WriteIPDLParam(aMsg, aActor, info.mLoadReplace);
|
||||
WriteIPDLParam(aMsg, aActor, info.mURIWasModified);
|
||||
WriteIPDLParam(aMsg, aActor, info.mIsSrcdocEntry);
|
||||
WriteIPDLParam(aMsg, aActor, info.mScrollRestorationIsManual);
|
||||
WriteIPDLParam(aMsg, aActor, info.mPersist);
|
||||
WriteIPDLParam(aMsg, aActor, aParam.mLoadId);
|
||||
WriteIPDLParam(aMsg, aActor, aParam.mIsLoadFromSessionHistory);
|
||||
WriteIPDLParam(aMsg, aActor, aParam.mRequestedIndex);
|
||||
WriteIPDLParam(aMsg, aActor, aParam.mSessionHistoryLength);
|
||||
@ -1031,12 +1034,12 @@ bool IPDLParamTraits<dom::LoadingSessionHistoryInfo>::Read(
|
||||
!ReadIPDLParam(aMsg, aIter, aActor, &info.mSrcdocData) ||
|
||||
!ReadIPDLParam(aMsg, aIter, aActor, &info.mBaseURI) ||
|
||||
!ReadIPDLParam(aMsg, aIter, aActor, &info.mLayoutHistoryState) ||
|
||||
!ReadIPDLParam(aMsg, aIter, aActor, &info.mId) ||
|
||||
!ReadIPDLParam(aMsg, aIter, aActor, &info.mLoadReplace) ||
|
||||
!ReadIPDLParam(aMsg, aIter, aActor, &info.mURIWasModified) ||
|
||||
!ReadIPDLParam(aMsg, aIter, aActor, &info.mIsSrcdocEntry) ||
|
||||
!ReadIPDLParam(aMsg, aIter, aActor, &info.mScrollRestorationIsManual) ||
|
||||
!ReadIPDLParam(aMsg, aIter, aActor, &info.mPersist) ||
|
||||
!ReadIPDLParam(aMsg, aIter, aActor, &aResult->mLoadId) ||
|
||||
!ReadIPDLParam(aMsg, aIter, aActor,
|
||||
&aResult->mIsLoadFromSessionHistory) ||
|
||||
!ReadIPDLParam(aMsg, aIter, aActor, &aResult->mRequestedIndex) ||
|
||||
|
@ -24,6 +24,7 @@ namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
struct LoadingSessionHistoryInfo;
|
||||
class SessionHistoryEntry;
|
||||
class SHEntrySharedParentState;
|
||||
|
||||
// SessionHistoryInfo stores session history data for a load. It can be sent
|
||||
@ -31,7 +32,6 @@ class SHEntrySharedParentState;
|
||||
class SessionHistoryInfo {
|
||||
public:
|
||||
SessionHistoryInfo() = default;
|
||||
explicit SessionHistoryInfo(uint64_t aExistingId);
|
||||
SessionHistoryInfo(nsDocShellLoadState* aLoadState, nsIChannel* aChannel);
|
||||
|
||||
bool operator==(const SessionHistoryInfo& aInfo) const {
|
||||
@ -59,8 +59,6 @@ class SessionHistoryInfo {
|
||||
|
||||
bool GetURIWasModified() const { return mURIWasModified; }
|
||||
|
||||
uint64_t Id() const { return mId; }
|
||||
|
||||
nsILayoutHistoryState* GetLayoutHistoryState() { return mLayoutHistoryState; }
|
||||
|
||||
void SetLayoutHistoryState(nsILayoutHistoryState* aState) {
|
||||
@ -93,7 +91,6 @@ class SessionHistoryInfo {
|
||||
// mCacheKey is handled similar way to mLayoutHistoryState.
|
||||
uint32_t mCacheKey = 0;
|
||||
|
||||
uint64_t mId = 0;
|
||||
bool mLoadReplace = false;
|
||||
bool mURIWasModified = false;
|
||||
bool mIsSrcdocEntry = false;
|
||||
@ -103,10 +100,12 @@ class SessionHistoryInfo {
|
||||
|
||||
struct LoadingSessionHistoryInfo {
|
||||
LoadingSessionHistoryInfo() = default;
|
||||
explicit LoadingSessionHistoryInfo(const SessionHistoryInfo& aInfo);
|
||||
explicit LoadingSessionHistoryInfo(SessionHistoryEntry* aEntry);
|
||||
|
||||
SessionHistoryInfo mInfo;
|
||||
|
||||
uint64_t mLoadId = 0;
|
||||
|
||||
// The following three member variables are used to inform about a load from
|
||||
// the session history. The session-history-in-child approach has just
|
||||
// an nsISHEntry in the nsDocShellLoadState and access to the nsISHistory,
|
||||
@ -148,12 +147,15 @@ class SessionHistoryEntry : public nsISHEntry {
|
||||
// then it returns false.
|
||||
bool ReplaceChild(SessionHistoryEntry* aNewChild);
|
||||
|
||||
// Get an entry based on SessionHistoryInfo's Id. Parent process only.
|
||||
static SessionHistoryEntry* GetByInfoId(uint64_t aId);
|
||||
// Get an entry based on LoadingSessionHistoryInfo's mLoadId. Parent process
|
||||
// only.
|
||||
static SessionHistoryEntry* GetByLoadId(uint64_t aLoadId);
|
||||
static void RemoveLoadId(uint64_t aLoadId);
|
||||
|
||||
static void MaybeSynchronizeSharedStateToInfo(nsISHEntry* aEntry);
|
||||
|
||||
private:
|
||||
friend struct LoadingSessionHistoryInfo;
|
||||
virtual ~SessionHistoryEntry();
|
||||
|
||||
const nsID& DocshellID() const;
|
||||
@ -164,7 +166,7 @@ class SessionHistoryEntry : public nsISHEntry {
|
||||
uint32_t mID;
|
||||
nsTArray<RefPtr<SessionHistoryEntry>> mChildren;
|
||||
|
||||
static nsDataHashtable<nsUint64HashKey, SessionHistoryEntry*>* sInfoIdToEntry;
|
||||
static nsDataHashtable<nsUint64HashKey, SessionHistoryEntry*>* sLoadIdToEntry;
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(SessionHistoryEntry, NS_SESSIONHISTORYENTRY_IID)
|
||||
|
@ -6892,11 +6892,10 @@ mozilla::ipc::IPCResult ContentParent::RecvNotifyOnHistoryReload(
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult ContentParent::RecvHistoryCommit(
|
||||
const MaybeDiscarded<BrowsingContext>& aContext,
|
||||
const uint64_t& aSessionHistoryEntryID, const nsID& aChangeID) {
|
||||
const MaybeDiscarded<BrowsingContext>& aContext, const uint64_t& aLoadID,
|
||||
const nsID& aChangeID) {
|
||||
if (!aContext.IsDiscarded()) {
|
||||
aContext.get_canonical()->SessionHistoryCommit(aSessionHistoryEntryID,
|
||||
aChangeID);
|
||||
aContext.get_canonical()->SessionHistoryCommit(aLoadID, aChangeID);
|
||||
}
|
||||
|
||||
return IPC_OK();
|
||||
|
@ -1329,8 +1329,8 @@ class ContentParent final
|
||||
NotifyOnHistoryReloadResolver&& aResolver);
|
||||
|
||||
mozilla::ipc::IPCResult RecvHistoryCommit(
|
||||
const MaybeDiscarded<BrowsingContext>& aContext,
|
||||
const uint64_t& aSessionHistoryEntryID, const nsID& aChangeID);
|
||||
const MaybeDiscarded<BrowsingContext>& aContext, const uint64_t& aLoadID,
|
||||
const nsID& aChangeID);
|
||||
|
||||
mozilla::ipc::IPCResult RecvHistoryGo(
|
||||
const MaybeDiscarded<BrowsingContext>& aContext, int32_t aOffset,
|
||||
|
@ -1664,8 +1664,7 @@ parent:
|
||||
bool? reloadActiveEntry);
|
||||
|
||||
async HistoryCommit(MaybeDiscardedBrowsingContext aContext,
|
||||
uint64_t aSessionHistoryEntryID,
|
||||
nsID aChangeID);
|
||||
uint64_t aLoadID, nsID aChangeID);
|
||||
|
||||
async HistoryGo(MaybeDiscardedBrowsingContext aContext,
|
||||
int32_t aOffset) returns(int32_t requestedIndex);
|
||||
|
Loading…
Reference in New Issue
Block a user