Skip to content

Commit

Permalink
Bug 1621643: Ensure replaceState updates all listeners about the modi…
Browse files Browse the repository at this point in the history
…fied state r=peterv

Differential Revision: https://phabricator.services.mozilla.com/D91433
  • Loading branch information
Randell Jesup committed Sep 28, 2020
1 parent b9deebe commit 95e052d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docshell/base/CanonicalBrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,11 @@ void CanonicalBrowsingContext::SetActiveSessionHistoryEntryForFrame(

void CanonicalBrowsingContext::ReplaceActiveSessionHistoryEntry(
SessionHistoryInfo* aInfo) {
nsSHistory* shistory = static_cast<nsSHistory*>(GetSessionHistory());
mActiveEntry->SetInfo(aInfo);
// Notify children of the update
shistory->NotifyOnHistoryReplaceEntry();
shistory->UpdateRootBrowsingContextState();
// FIXME Need to do the equivalent of EvictContentViewersOrReplaceEntry.
}

Expand Down
4 changes: 4 additions & 0 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10776,6 +10776,10 @@ void nsDocShell::SetReferrerInfo(nsIReferrerInfo* aReferrerInfo) {
NS_IMETHODIMP
nsDocShell::AddState(JS::Handle<JS::Value> aData, const nsAString& aTitle,
const nsAString& aURL, bool aReplace, JSContext* aCx) {
MOZ_LOG(gSHLog, LogLevel::Debug,
("nsDocShell[%p]: AddState(..., %s, %s, %d)", this,
NS_ConvertUTF16toUTF8(aTitle).get(),
NS_ConvertUTF16toUTF8(aURL).get(), aReplace));
// Implements History.pushState and History.replaceState

// Here's what we do, roughly in the order specified by HTML5. The specific
Expand Down
5 changes: 5 additions & 0 deletions docshell/shistory/nsSHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,11 @@ nsSHistory::AddEntry(nsISHEntry* aSHEntry, bool aPersist) {
return NS_OK;
}

void
nsSHistory::NotifyOnHistoryReplaceEntry() {
NOTIFY_LISTENERS(OnHistoryReplaceEntry, ());
}

/* Get size of the history list */
NS_IMETHODIMP
nsSHistory::GetCount(int32_t* aResult) {
Expand Down
10 changes: 6 additions & 4 deletions docshell/shistory/nsSHistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class nsSHistory : public mozilla::LinkedListElement<nsSHistory>,

nsTArray<nsCOMPtr<nsISHEntry>>& Entries() { return mEntries; }

void NotifyOnHistoryReplaceEntry();

void RemoveEntries(nsTArray<nsID>& aIDs, int32_t aStartIndex,
bool* aDidRemove);

Expand Down Expand Up @@ -181,6 +183,10 @@ class nsSHistory : public mozilla::LinkedListElement<nsSHistory>,
return mRequestedIndex == -1 ? mIndex : mRequestedIndex;
}

// Update the root browsing context state when adding, removing or
// replacing entries.
void UpdateRootBrowsingContextState();

protected:
virtual ~nsSHistory();

Expand Down Expand Up @@ -243,10 +249,6 @@ class nsSHistory : public mozilla::LinkedListElement<nsSHistory>,
nsISHEntry* aOldEntry,
nsISHEntry* aNewEntry);

// Update the root browsing context state when adding, removing or
// replacing entries.
void UpdateRootBrowsingContextState();

protected:
bool mHasOngoingUpdate;
bool mIsRemote;
Expand Down

0 comments on commit 95e052d

Please sign in to comment.