Bug 1658649 - Make session-history-in-parent nsISHEntry setters to rely on active entry, r=peterv

Differential Revision: https://phabricator.services.mozilla.com/D86770
This commit is contained in:
Olli Pettay 2020-08-13 22:51:47 +00:00
Родитель 0806eb1e4e
Коммит 9c7b1aa59d
9 изменённых файлов: 80 добавлений и 74 удалений

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

@ -281,6 +281,10 @@ nsISHistory* CanonicalBrowsingContext::GetSessionHistory() {
return mSessionHistory;
}
SessionHistoryEntry* CanonicalBrowsingContext::GetActiveSessionHistoryEntry() {
return mActiveEntry;
}
UniquePtr<LoadingSessionHistoryInfo>
CanonicalBrowsingContext::CreateLoadingSessionHistoryEntryForLoad(
nsDocShellLoadState* aLoadState, nsIChannel* aChannel) {

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

@ -96,6 +96,8 @@ class CanonicalBrowsingContext final : public BrowsingContext {
Nullable<WindowProxyHolder> GetTopChromeWindow();
nsISHistory* GetSessionHistory();
SessionHistoryEntry* GetActiveSessionHistoryEntry();
UniquePtr<LoadingSessionHistoryInfo> CreateLoadingSessionHistoryEntryForLoad(
nsDocShellLoadState* aLoadState, nsIChannel* aChannel);
void SessionHistoryCommit(uint64_t aSessionHistoryEntryId,

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

@ -2961,16 +2961,20 @@ nsDocShell::GetCurrentSHEntry(nsISHEntry** aEntry, bool* aOSHE) {
}
NS_IMETHODIMP nsDocShell::SynchronizeLayoutHistoryState() {
if (mActiveEntry && mActiveEntry->GetLayoutHistoryState()) {
if (mActiveEntry && mActiveEntry->GetLayoutHistoryState() &&
mBrowsingContext) {
if (XRE_IsContentProcess()) {
dom::ContentChild* contentChild = dom::ContentChild::GetSingleton();
if (contentChild) {
contentChild->SendSynchronizeLayoutHistoryState(
mActiveEntry->Id(), mActiveEntry->GetLayoutHistoryState());
mBrowsingContext, mActiveEntry->GetLayoutHistoryState());
}
} else {
SessionHistoryEntry::UpdateLayoutHistoryState(
mActiveEntry->Id(), mActiveEntry->GetLayoutHistoryState());
SessionHistoryEntry* entry =
mBrowsingContext->Canonical()->GetActiveSessionHistoryEntry();
if (entry) {
entry->SetLayoutHistoryState(mActiveEntry->GetLayoutHistoryState());
}
}
}
@ -4751,18 +4755,18 @@ void nsDocShell::SetTitleOnHistoryEntry() {
mOSHE->SetTitle(mTitle);
}
if (mActiveEntry) {
if (mActiveEntry && mBrowsingContext) {
mActiveEntry->SetTitle(mTitle);
if (XRE_IsParentProcess()) {
SessionHistoryEntry* entry =
SessionHistoryEntry::GetByInfoId(mActiveEntry->Id());
mBrowsingContext->Canonical()->GetActiveSessionHistoryEntry();
if (entry) {
entry->SetTitle(mTitle);
}
} else {
mozilla::Unused
<< ContentChild::GetSingleton()->SendSessionHistoryEntryTitle(
mActiveEntry->Id(), mTitle);
mBrowsingContext, mTitle);
}
}
}
@ -8511,14 +8515,16 @@ nsresult nsDocShell::HandleSameDocumentNavigation(
if (mLoadingEntry && !mLoadingEntry->mIsLoadFromSessionHistory) {
// If we're not doing a history load, scroll restoration
// should be inherited from the previous session history entry.
SetScrollRestorationIsManualOnHistoryEntry(
nullptr, &mLoadingEntry->mInfo, scrollRestorationIsManual);
// XXX This needs most probably tweaks once fragment navigation is fixed
// to work with session-history-in-parent.
SetScrollRestorationIsManualOnHistoryEntry(nullptr,
scrollRestorationIsManual);
}
if (mLSHE) {
if (!aLoadState->SHEntry()) {
// If we're not doing a history load, scroll restoration
// should be inherited from the previous session history entry.
SetScrollRestorationIsManualOnHistoryEntry(mLSHE, nullptr,
SetScrollRestorationIsManualOnHistoryEntry(mLSHE,
scrollRestorationIsManual);
}
mLSHE->AdoptBFCacheEntry(mOSHE);
@ -8551,10 +8557,9 @@ nsresult nsDocShell::HandleSameDocumentNavigation(
// Make sure we won't just repost without hitting the
// cache first
if (cacheKey != 0) {
// XXX Update this call to deal with mLoadingEntry or mActiveEntry once
// the whole HandleSameDocumentNavigation is updated to work with
// SessionHistoryInfo objects!
SetCacheKeyOnHistoryEntry(mOSHE, nullptr, cacheKey);
// XXX Ensure this method is still called when fragment navigation is
// fixed to work with session history in parent.
SetCacheKeyOnHistoryEntry(mOSHE, cacheKey);
}
}
@ -10327,17 +10332,7 @@ bool nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel,
// in it. Otherwise, since we're doing a reload and won't be updating
// our history entry, store the cache key in our current history entry.
if (mLoadingEntry) {
SetCacheKeyOnHistoryEntry(nullptr, &mLoadingEntry->mInfo, cacheKey);
} else if (mActiveEntry) {
SetCacheKeyOnHistoryEntry(nullptr, mActiveEntry.get(), cacheKey);
}
if (mLSHE) {
SetCacheKeyOnHistoryEntry(mLSHE, nullptr, cacheKey);
} else if (mOSHE) {
SetCacheKeyOnHistoryEntry(mOSHE, nullptr, cacheKey);
}
SetCacheKeyOnHistoryEntry(mLSHE ? mLSHE : mOSHE, cacheKey);
// Since we're force-reloading, clear all the sub frame history.
ClearFrameHistory(mLSHE);
@ -10804,54 +10799,50 @@ nsDocShell::GetCurrentScrollRestorationIsManual(bool* aIsManual) {
NS_IMETHODIMP
nsDocShell::SetCurrentScrollRestorationIsManual(bool aIsManual) {
SetScrollRestorationIsManualOnHistoryEntry(mOSHE, mActiveEntry.get(),
aIsManual);
SetScrollRestorationIsManualOnHistoryEntry(mOSHE, aIsManual);
return NS_OK;
}
void nsDocShell::SetScrollRestorationIsManualOnHistoryEntry(
nsISHEntry* aSHEntry, mozilla::dom::SessionHistoryInfo* aInfo,
bool aIsManual) {
nsISHEntry* aSHEntry, bool aIsManual) {
if (aSHEntry) {
aSHEntry->SetScrollRestorationIsManual(aIsManual);
}
if (aInfo) {
aInfo->SetScrollRestorationIsManual(aIsManual);
if (mActiveEntry && mBrowsingContext) {
mActiveEntry->SetScrollRestorationIsManual(aIsManual);
if (XRE_IsParentProcess()) {
SessionHistoryEntry* entry =
SessionHistoryEntry::GetByInfoId(aInfo->Id());
mBrowsingContext->Canonical()->GetActiveSessionHistoryEntry();
if (entry) {
entry->SetScrollRestorationIsManual(aIsManual);
}
} else {
mozilla::Unused << ContentChild::GetSingleton()
->SendSessionHistoryEntryScrollRestorationIsManual(
aInfo->Id(), aIsManual);
mBrowsingContext, aIsManual);
}
}
}
void nsDocShell::SetCacheKeyOnHistoryEntry(
nsISHEntry* aSHEntry, mozilla::dom::SessionHistoryInfo* aInfo,
uint32_t aCacheKey) {
void nsDocShell::SetCacheKeyOnHistoryEntry(nsISHEntry* aSHEntry,
uint32_t aCacheKey) {
if (aSHEntry) {
aSHEntry->SetCacheKey(aCacheKey);
}
if (aInfo) {
aInfo->SetCacheKey(aCacheKey);
if (mActiveEntry && mBrowsingContext) {
if (XRE_IsParentProcess()) {
SessionHistoryEntry* entry =
SessionHistoryEntry::GetByInfoId(aInfo->Id());
mBrowsingContext->Canonical()->GetActiveSessionHistoryEntry();
if (entry) {
entry->SetCacheKey(aCacheKey);
}
} else {
mozilla::Unused
<< ContentChild::GetSingleton()->SendSessionHistoryEntryCacheKey(
aInfo->Id(), aCacheKey);
mBrowsingContext, aCacheKey);
}
}
}

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

@ -1050,13 +1050,10 @@ class nsDocShell final : public nsDocLoader,
void SetTitleOnHistoryEntry();
void SetScrollRestorationIsManualOnHistoryEntry(
nsISHEntry* aSHEntry, mozilla::dom::SessionHistoryInfo* aInfo,
bool aIsManual);
void SetScrollRestorationIsManualOnHistoryEntry(nsISHEntry* aSHEntry,
bool aIsManual);
void SetCacheKeyOnHistoryEntry(nsISHEntry* aSHEntry,
mozilla::dom::SessionHistoryInfo* aInfo,
uint32_t aCacheKey);
void SetCacheKeyOnHistoryEntry(nsISHEntry* aSHEntry, uint32_t aCacheKey);
private: // data members
nsID mHistoryID;

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

@ -952,15 +952,6 @@ SessionHistoryEntry::SyncTreesForSubframeNavigation(
NS_WARNING("Need to implement this");
}
void SessionHistoryEntry::UpdateLayoutHistoryState(
uint64_t aSessionHistoryEntryID, nsILayoutHistoryState* aState) {
SessionHistoryEntry* entry =
SessionHistoryEntry::GetByInfoId(aSessionHistoryEntryID);
if (entry) {
entry->SetLayoutHistoryState(aState);
}
}
void SessionHistoryEntry::MaybeSynchronizeSharedStateToInfo(
nsISHEntry* aEntry) {
nsCOMPtr<SessionHistoryEntry> entry = do_QueryInterface(aEntry);

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

@ -151,9 +151,6 @@ class SessionHistoryEntry : public nsISHEntry {
// Get an entry based on SessionHistoryInfo's Id. Parent process only.
static SessionHistoryEntry* GetByInfoId(uint64_t aId);
static void UpdateLayoutHistoryState(uint64_t aSessionHistoryEntryID,
nsILayoutHistoryState* aState);
static void MaybeSynchronizeSharedStateToInfo(nsISHEntry* aEntry);
private:

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

@ -6962,15 +6962,28 @@ mozilla::ipc::IPCResult ContentParent::RecvSessionHistoryUpdate(
}
mozilla::ipc::IPCResult ContentParent::RecvSynchronizeLayoutHistoryState(
const uint64_t& aSessionHistoryEntryID, nsILayoutHistoryState* aState) {
SessionHistoryEntry::UpdateLayoutHistoryState(aSessionHistoryEntryID, aState);
const MaybeDiscarded<BrowsingContext>& aContext,
nsILayoutHistoryState* aState) {
if (aContext.IsNullOrDiscarded()) {
return IPC_OK();
}
SessionHistoryEntry* entry =
aContext.get_canonical()->GetActiveSessionHistoryEntry();
if (entry) {
entry->SetLayoutHistoryState(aState);
}
return IPC_OK();
}
mozilla::ipc::IPCResult ContentParent::RecvSessionHistoryEntryTitle(
const uint64_t& aSessionHistoryEntryID, const nsString& aTitle) {
const MaybeDiscarded<BrowsingContext>& aContext, const nsString& aTitle) {
if (aContext.IsNullOrDiscarded()) {
return IPC_OK();
}
SessionHistoryEntry* entry =
SessionHistoryEntry::GetByInfoId(aSessionHistoryEntryID);
aContext.get_canonical()->GetActiveSessionHistoryEntry();
if (entry) {
entry->SetTitle(aTitle);
}
@ -6979,9 +6992,13 @@ mozilla::ipc::IPCResult ContentParent::RecvSessionHistoryEntryTitle(
mozilla::ipc::IPCResult
ContentParent::RecvSessionHistoryEntryScrollRestorationIsManual(
const uint64_t& aSessionHistoryEntryID, const bool& aIsManual) {
const MaybeDiscarded<BrowsingContext>& aContext, const bool& aIsManual) {
if (aContext.IsNullOrDiscarded()) {
return IPC_OK();
}
SessionHistoryEntry* entry =
SessionHistoryEntry::GetByInfoId(aSessionHistoryEntryID);
aContext.get_canonical()->GetActiveSessionHistoryEntry();
if (entry) {
entry->SetScrollRestorationIsManual(aIsManual);
}
@ -6989,9 +7006,14 @@ ContentParent::RecvSessionHistoryEntryScrollRestorationIsManual(
}
mozilla::ipc::IPCResult ContentParent::RecvSessionHistoryEntryCacheKey(
const uint64_t& aSessionHistoryEntryID, const uint32_t& aCacheKey) {
const MaybeDiscarded<BrowsingContext>& aContext,
const uint32_t& aCacheKey) {
if (aContext.IsNullOrDiscarded()) {
return IPC_OK();
}
SessionHistoryEntry* entry =
SessionHistoryEntry::GetByInfoId(aSessionHistoryEntryID);
aContext.get_canonical()->GetActiveSessionHistoryEntry();
if (entry) {
entry->SetCacheKey(aCacheKey);
}

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

@ -1338,16 +1338,18 @@ class ContentParent final
const int32_t& aLength, const nsID& aChangeID);
mozilla::ipc::IPCResult RecvSynchronizeLayoutHistoryState(
const uint64_t& aSessionHistoryEntryID, nsILayoutHistoryState* aState);
const MaybeDiscarded<BrowsingContext>& aContext,
nsILayoutHistoryState* aState);
mozilla::ipc::IPCResult RecvSessionHistoryEntryTitle(
const uint64_t& aSessionHistoryEntryID, const nsString& aTitle);
const MaybeDiscarded<BrowsingContext>& aContext, const nsString& aTitle);
mozilla::ipc::IPCResult RecvSessionHistoryEntryScrollRestorationIsManual(
const uint64_t& aSessionHistoryEntryID, const bool& aIsManual);
const MaybeDiscarded<BrowsingContext>& aContext, const bool& aIsManual);
mozilla::ipc::IPCResult RecvSessionHistoryEntryCacheKey(
const uint64_t& aSessionHistoryEntryID, const uint32_t& aCacheKey);
const MaybeDiscarded<BrowsingContext>& aContext,
const uint32_t& aCacheKey);
// Notify the ContentChild to enable the input event prioritization when
// initializing.

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

@ -922,16 +922,16 @@ parent:
async SessionHistoryUpdate(MaybeDiscardedBrowsingContext aTopContext,
int32_t aIndex, int32_t aLength, nsID aChangeID);
async SynchronizeLayoutHistoryState(uint64_t aSessionHistoryEntryID,
async SynchronizeLayoutHistoryState(MaybeDiscardedBrowsingContext aContext,
nsILayoutHistoryState aState);
async SessionHistoryEntryTitle(uint64_t aSessionHistoryEntryID,
async SessionHistoryEntryTitle(MaybeDiscardedBrowsingContext aContext,
nsString aTitle);
async SessionHistoryEntryScrollRestorationIsManual(uint64_t aSessionHistoryEntryID,
async SessionHistoryEntryScrollRestorationIsManual(MaybeDiscardedBrowsingContext aContext,
bool aIsManual);
async SessionHistoryEntryCacheKey(uint64_t aSessionHistoryEntryID,
async SessionHistoryEntryCacheKey(MaybeDiscardedBrowsingContext aContext,
uint32_t aCacheKey);
async InitBackground(Endpoint<PBackgroundParent> aEndpoint);