Bug 1664656 - Decide whether to add a new entry based on the load type. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D90028
This commit is contained in:
Peter Van der Beken 2020-09-20 12:40:10 +00:00
Родитель f040f9c556
Коммит aa030970db
8 изменённых файлов: 47 добавлений и 31 удалений

Просмотреть файл

@ -2745,6 +2745,14 @@ void BrowsingContext::SetChildSHistory(ChildSHistory* aChildSHistory) {
mFields.SetWithoutSyncing<IDX_HasSessionHistory>(true); mFields.SetWithoutSyncing<IDX_HasSessionHistory>(true);
} }
bool BrowsingContext::ShouldUpdateSessionHistory(uint32_t aLoadType) {
// We don't update session history on reload unless we're loading
// an iframe in shift-reload case.
return nsDocShell::ShouldUpdateGlobalHistory(aLoadType) &&
(!(aLoadType & nsIDocShell::LOAD_CMD_RELOAD) ||
(IsForceReloadType(aLoadType) && IsFrame()));
}
} // namespace dom } // namespace dom
namespace ipc { namespace ipc {

Просмотреть файл

@ -688,6 +688,8 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
void HistoryGo(int32_t aIndex, std::function<void(int32_t&&)>&& aResolver); void HistoryGo(int32_t aIndex, std::function<void(int32_t&&)>&& aResolver);
bool ShouldUpdateSessionHistory(uint32_t aLoadType);
protected: protected:
virtual ~BrowsingContext(); virtual ~BrowsingContext();
BrowsingContext(WindowContext* aParentWindow, BrowsingContextGroup* aGroup, BrowsingContext(WindowContext* aParentWindow, BrowsingContextGroup* aGroup,

Просмотреть файл

@ -376,7 +376,8 @@ CanonicalBrowsingContext::CreateLoadingSessionHistoryEntryForLoad(
} }
void CanonicalBrowsingContext::SessionHistoryCommit(uint64_t aLoadId, void CanonicalBrowsingContext::SessionHistoryCommit(uint64_t aLoadId,
const nsID& aChangeID) { const nsID& aChangeID,
uint32_t aLoadType) {
for (size_t i = 0; i < mLoadingEntries.Length(); ++i) { for (size_t i = 0; i < mLoadingEntries.Length(); ++i) {
if (mLoadingEntries[i].mLoadId == aLoadId) { if (mLoadingEntries[i].mLoadId == aLoadId) {
nsISHistory* shistory = GetSessionHistory(); nsISHistory* shistory = GetSessionHistory();
@ -405,12 +406,13 @@ void CanonicalBrowsingContext::SessionHistoryCommit(uint64_t aLoadId,
[](nsISHEntry* aEntry) { aEntry->SetName(EmptyString()); }); [](nsISHEntry* aEntry) { aEntry->SetName(EmptyString()); });
} }
bool addEntry = ShouldUpdateSessionHistory(aLoadType);
if (IsTop()) { if (IsTop()) {
mActiveEntry = newActiveEntry; mActiveEntry = newActiveEntry;
if (loadFromSessionHistory) { if (loadFromSessionHistory) {
// XXX Synchronize browsing context tree and session history tree? // XXX Synchronize browsing context tree and session history tree?
shistory->UpdateIndex(); shistory->UpdateIndex();
} else { } else if (addEntry) {
shistory->AddEntry(mActiveEntry, shistory->AddEntry(mActiveEntry,
/* FIXME aPersist = */ true); /* FIXME aPersist = */ true);
} }
@ -431,24 +433,28 @@ void CanonicalBrowsingContext::SessionHistoryCommit(uint64_t aLoadId,
// FIXME UpdateIndex() here may update index too early (but even the // FIXME UpdateIndex() here may update index too early (but even the
// old implementation seems to have similar issues). // old implementation seems to have similar issues).
shistory->UpdateIndex(); shistory->UpdateIndex();
} else if (oldActiveEntry) { } else if (addEntry) {
// AddChildSHEntryHelper does update the index of the session history! if (oldActiveEntry) {
// FIXME Need to figure out the right value for aCloneChildren. // AddChildSHEntryHelper does update the index of the session
shistory->AddChildSHEntryHelper(oldActiveEntry, newActiveEntry, Top(), // history!
true); // FIXME Need to figure out the right value for aCloneChildren.
mActiveEntry = newActiveEntry; shistory->AddChildSHEntryHelper(oldActiveEntry, newActiveEntry,
} else { Top(), true);
SessionHistoryEntry* parentEntry =
static_cast<CanonicalBrowsingContext*>(GetParent())->mActiveEntry;
// XXX What should happen if parent doesn't have mActiveEntry?
// Or can that even happen ever?
if (parentEntry) {
mActiveEntry = newActiveEntry; mActiveEntry = newActiveEntry;
// FIXME The docshell code sometime uses -1 for aChildOffset! } else {
// FIXME Using IsInProcess for aUseRemoteSubframes isn't quite SessionHistoryEntry* parentEntry =
// right, but aUseRemoteSubframes should be going away. static_cast<CanonicalBrowsingContext*>(GetParent())
parentEntry->AddChild(mActiveEntry, Children().Length() - 1, ->mActiveEntry;
IsInProcess()); // XXX What should happen if parent doesn't have mActiveEntry?
// Or can that even happen ever?
if (parentEntry) {
mActiveEntry = newActiveEntry;
// FIXME The docshell code sometime uses -1 for aChildOffset!
// FIXME Using IsInProcess for aUseRemoteSubframes isn't quite
// right, but aUseRemoteSubframes should be going away.
parentEntry->AddChild(mActiveEntry, Children().Length() - 1,
IsInProcess());
}
} }
} }
} }

Просмотреть файл

@ -100,7 +100,8 @@ class CanonicalBrowsingContext final : public BrowsingContext {
UniquePtr<LoadingSessionHistoryInfo> CreateLoadingSessionHistoryEntryForLoad( UniquePtr<LoadingSessionHistoryInfo> CreateLoadingSessionHistoryEntryForLoad(
nsDocShellLoadState* aLoadState, nsIChannel* aChannel); nsDocShellLoadState* aLoadState, nsIChannel* aChannel);
void SessionHistoryCommit(uint64_t aLoadId, const nsID& aChangeID); void SessionHistoryCommit(uint64_t aLoadId, const nsID& aChangeID,
uint32_t aLoadType);
// Calls the session history listeners' OnHistoryReload, storing the result in // 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 // aCanReload. If aCanReload is set to true and we have an active or a loading

Просмотреть файл

@ -5713,7 +5713,7 @@ nsresult nsDocShell::Embed(nsIContentViewer* aContentViewer,
nsID changeID = {}; nsID changeID = {};
if (XRE_IsParentProcess()) { if (XRE_IsParentProcess()) {
mBrowsingContext->Canonical()->SessionHistoryCommit( mBrowsingContext->Canonical()->SessionHistoryCommit(
loadingEntry->mLoadId, changeID); loadingEntry->mLoadId, changeID, mLoadType);
} else { } else {
RefPtr<ChildSHistory> rootSH = GetRootSessionHistory(); RefPtr<ChildSHistory> rootSH = GetRootSessionHistory();
if (rootSH) { if (rootSH) {
@ -5729,7 +5729,7 @@ nsresult nsDocShell::Embed(nsIContentViewer* aContentViewer,
} }
ContentChild* cc = ContentChild::GetSingleton(); ContentChild* cc = ContentChild::GetSingleton();
mozilla::Unused << cc->SendHistoryCommit( mozilla::Unused << cc->SendHistoryCommit(
mBrowsingContext, loadingEntry->mLoadId, changeID); mBrowsingContext, loadingEntry->mLoadId, changeID, mLoadType);
} }
} }
} }
@ -8895,7 +8895,7 @@ nsresult nsDocShell::HandleSameDocumentNavigation(
nsID changeID = {}; nsID changeID = {};
if (XRE_IsParentProcess()) { if (XRE_IsParentProcess()) {
mBrowsingContext->Canonical()->SessionHistoryCommit( mBrowsingContext->Canonical()->SessionHistoryCommit(
mLoadingEntry->mLoadId, changeID); mLoadingEntry->mLoadId, changeID, mLoadType);
} else { } else {
RefPtr<ChildSHistory> rootSH = GetRootSessionHistory(); RefPtr<ChildSHistory> rootSH = GetRootSessionHistory();
if (rootSH) { if (rootSH) {
@ -8907,7 +8907,7 @@ nsresult nsDocShell::HandleSameDocumentNavigation(
} }
ContentChild* cc = ContentChild::GetSingleton(); ContentChild* cc = ContentChild::GetSingleton();
mozilla::Unused << cc->SendHistoryCommit( mozilla::Unused << cc->SendHistoryCommit(
mBrowsingContext, mLoadingEntry->mLoadId, changeID); mBrowsingContext, mLoadingEntry->mLoadId, changeID, mLoadType);
} }
} }
@ -10630,9 +10630,7 @@ bool nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel,
// We don't update session history on reload unless we're loading // We don't update session history on reload unless we're loading
// an iframe in shift-reload case. // an iframe in shift-reload case.
bool updateSHistory = bool updateSHistory = mBrowsingContext->ShouldUpdateSessionHistory(aLoadType);
updateGHistory && (!(aLoadType & LOAD_CMD_RELOAD) ||
(IsForceReloadType(aLoadType) && IsFrame()));
// Create SH Entry (mLSHE) only if there is a SessionHistory object in the // Create SH Entry (mLSHE) only if there is a SessionHistory object in the
// root browsing context. // root browsing context.

Просмотреть файл

@ -6836,9 +6836,10 @@ mozilla::ipc::IPCResult ContentParent::RecvNotifyOnHistoryReload(
mozilla::ipc::IPCResult ContentParent::RecvHistoryCommit( mozilla::ipc::IPCResult ContentParent::RecvHistoryCommit(
const MaybeDiscarded<BrowsingContext>& aContext, const uint64_t& aLoadID, const MaybeDiscarded<BrowsingContext>& aContext, const uint64_t& aLoadID,
const nsID& aChangeID) { const nsID& aChangeID, const uint32_t& aLoadType) {
if (!aContext.IsDiscarded()) { if (!aContext.IsDiscarded()) {
aContext.get_canonical()->SessionHistoryCommit(aLoadID, aChangeID); aContext.get_canonical()->SessionHistoryCommit(aLoadID, aChangeID,
aLoadType);
} }
return IPC_OK(); return IPC_OK();

Просмотреть файл

@ -1314,7 +1314,7 @@ class ContentParent final
mozilla::ipc::IPCResult RecvHistoryCommit( mozilla::ipc::IPCResult RecvHistoryCommit(
const MaybeDiscarded<BrowsingContext>& aContext, const uint64_t& aLoadID, const MaybeDiscarded<BrowsingContext>& aContext, const uint64_t& aLoadID,
const nsID& aChangeID); const nsID& aChangeID, const uint32_t& aLoadType);
mozilla::ipc::IPCResult RecvHistoryGo( mozilla::ipc::IPCResult RecvHistoryGo(
const MaybeDiscarded<BrowsingContext>& aContext, int32_t aOffset, const MaybeDiscarded<BrowsingContext>& aContext, int32_t aOffset,

Просмотреть файл

@ -1671,7 +1671,7 @@ parent:
bool? reloadActiveEntry); bool? reloadActiveEntry);
async HistoryCommit(MaybeDiscardedBrowsingContext aContext, async HistoryCommit(MaybeDiscardedBrowsingContext aContext,
uint64_t aLoadID, nsID aChangeID); uint64_t aLoadID, nsID aChangeID, uint32_t aLoadType);
async HistoryGo(MaybeDiscardedBrowsingContext aContext, async HistoryGo(MaybeDiscardedBrowsingContext aContext,
int32_t aOffset) returns(int32_t requestedIndex); int32_t aOffset) returns(int32_t requestedIndex);