To update document for history step application given a Document
document, a session history entry entry, a boolean
doNotReactivate, integers scriptHistoryLength and
scriptHistoryIndex, NavigationType-or-null navigationType, an
optional list of session history entries
entriesForNavigationAPI, and an optional session history entry
previousEntryForActivation:
Let documentIsNew be true if document's latest entry is null; otherwise false.
Let documentsEntryChanged be true if document's latest entry is not entry; otherwise false.
Set document's history object's index to scriptHistoryIndex.
Set document's history object's length to scriptHistoryLength.
Let navigation be history's relevant global object's navigation API.
If documentsEntryChanged is true:
Let oldURL be document's latest entry's URL.
Set document's latest entry to entry.
Restore the history object state given document and entry.
If documentIsNew is false:
Assert: navigationType is not null.
Update the navigation API entries for a same-document navigation given navigation, entry, and navigationType.
Fire an event named popstate at document's relevant global
object, using PopStateEvent, with the state attribute initialized to document's
history object's state and hasUAVisualTransition initialized to
true if a visual transition, to display a cached rendered state of the latest
entry, was done by the user agent.
Restore persisted state given entry.
If oldURL's fragment is not
equal to entry's URL's fragment, then queue a global task on the
DOM manipulation task source given document's relevant global
object to fire an event named hashchange at document's relevant global
object, using HashChangeEvent, with the oldURL attribute initialized to the serialization of oldURL and the newURL attribute initialized to the serialization of entry's URL.
Otherwise:
Assert: entriesForNavigationAPI is given.
Restore persisted state given entry.
Initialize the navigation API entries for a new document given navigation, entriesForNavigationAPI, and entry.
If all the following are true:
then:
If navigation's activation is null, then set navigation's
activation to a new
NavigationActivation object in navigation's
relevant realm.
Let previousEntryIndex be the result of getting the navigation API entry index of previousEntryForActivation within navigation.
If previousEntryIndex is non-negative, then set activation's old entry to navigation's entry list[previousEntryIndex].
Otherwise, if all the following are true:
navigationType is "replace";
previousEntryForActivation's document state's origin is same origin with document's origin; and
previousEntryForActivation's document's
is initial about:blank is
false,
then set activation's old entry
to a new NavigationHistoryEntry in navigation's relevant realm, whose session history entry is
previousEntryForActivation.
Set activation's new entry to navigation's current entry.
Set activation's navigation type to navigationType.
If documentIsNew is true:
Assert: document's during-loading navigation ID for WebDriver BiDi is not null.
Invoke WebDriver BiDi navigation committed with navigable and a
new WebDriver BiDi navigation status whose id is document's during-loading navigation ID for WebDriver BiDi,
status is "committed", and url is document's URL.
Try to scroll to the fragment for document.
At this point scripts may run for the newly-created document document.
Otherwise, if documentsEntryChanged is false and doNotReactivate is false:
Assert: entriesForNavigationAPI is given.
Reactivate document given entry and entriesForNavigationAPI.
documentsEntryChanged can be false for one of two reasons: either we are restoring from bfcache, or we are asynchronously finishing up a synchronous navigation which already synchronously set document's latest entry. The doNotReactivate argument distinguishes between these two cases.