fix(history): restore nested histories across document replacement

Keep child entries and srcdoc resources with their parent Document identity
when top-level and popup Documents are replaced. Restore their original joint
history steps, avoid traversing descendants of a retiring parent, and prune
forward entries when navigation branches from an earlier step.

Preserve parser-created frame identities in navigation projections. Cover
named and unnamed frames, script-created parents, nested Documents, entry
state and identity, and interleaved multi-step traversals through CDP.
This commit is contained in:
ldm0
2026-11-20 22:47:40 +08:00
parent 70d3b80574
commit 33370d8adc
34 changed files with 1070 additions and 13 deletions
@@ -1,5 +1,6 @@
mod browser_target;
mod emulation_input_storage;
mod nested_history;
mod network_fetch;
mod p0_input;
mod p0_network;
@@ -0,0 +1,410 @@
use super::super::tests_cdp_smoke_fixture::SmokeFixtureServer;
use super::super::*;
use super::support::CdpPageHarness;
use anyhow::{Context, Result};
use serde_json::{Value, json};
use tokio::time::Duration;
use url::Url;
struct HistoryPage {
ctx: TestContext,
cdp: CdpPageHarness,
next_id: u64,
}
impl HistoryPage {
async fn evaluate(&mut self, expression: &str) -> Result<Value> {
self.evaluate_with_await(expression, false).await
}
async fn evaluate_await(&mut self, expression: &str) -> Result<Value> {
self.evaluate_with_await(expression, true).await
}
async fn evaluate_with_await(
&mut self,
expression: &str,
await_promise: bool,
) -> Result<Value> {
let id = self.next_id;
self.next_id += 1;
let response = if await_promise {
self.cdp
.evaluate_await_value(&mut self.ctx, id, expression)
.await
} else {
self.cdp.evaluate_value(&mut self.ctx, id, expression).await
};
anyhow::ensure!(
response.get("error").is_none() && response["result"].get("exceptionDetails").is_none(),
"evaluating {expression}: {response}"
);
Ok(response["result"]["result"].clone())
}
}
fn markup_url(server: &SmokeFixtureServer, markup: &str) -> String {
let mut url = Url::parse(&server.url("/history-markup")).unwrap();
url.query_pairs_mut().append_pair(
"markup",
&markup.replace(
"<body>",
"<head><script>onload=()=>document.body.dataset.loaded='yes';</script></head><body>",
),
);
url.into()
}
fn frame(url: &str, name: &str) -> String {
format!(
"<iframe data-static name=\"{name}\" src=\"{}\"></iframe>",
url.replace('&', "&amp;").replace('"', "&quot;")
)
}
async fn value(page: &mut HistoryPage, expression: &str) -> Result<Value> {
let result = page
.evaluate(&format!("JSON.stringify({expression})"))
.await?;
Ok(serde_json::from_str(
result["value"]
.as_str()
.unwrap_or_else(|| panic!("{expression}: {result}")),
)?)
}
async fn wait(page: &mut HistoryPage, expression: &str) -> Result<()> {
let deadline = tokio::time::Instant::now() + Duration::from_secs(5);
loop {
let result = page.evaluate(expression).await;
if result.as_ref().is_ok_and(|value| value["value"] == true) {
return Ok(());
}
anyhow::ensure!(
tokio::time::Instant::now() < deadline,
"timed out waiting for {expression}: {result:?}"
);
page.ctx.complete_one_ready_scheduler_input_for_test().await;
tokio::time::sleep(Duration::from_millis(10)).await;
}
}
async fn navigate(page: &mut HistoryPage, root: &str, action: &str, url: &str) -> Result<()> {
page.evaluate(&format!("({root}).{action}; true")).await?;
wait(
page,
&format!(
"({root}).location.href === {} && ({root}).document.body?.dataset.loaded === 'yes'",
serde_json::to_string(url)?
),
)
.await
.with_context(|| format!("after {root}.{action}"))
}
async fn open_root(
url: &str,
popup: bool,
opener_url: &str,
) -> Result<(HistoryPage, &'static str)> {
let mut ctx = TestContext::new_with_target_discovery(false);
let cdp = CdpPageHarness::attach(&mut ctx, 220_000).await;
let response = cdp
.navigate(&mut ctx, 220_005, if popup { opener_url } else { url })
.await;
anyhow::ensure!(response.get("error").is_none(), "{response}");
let mut page = HistoryPage {
ctx,
cdp,
next_id: 220_010,
};
let root = if popup { "testPopup" } else { "window" };
if popup {
page.evaluate(&format!(
"globalThis.testPopup = open({}); true",
serde_json::to_string(url)?
))
.await?;
}
wait(
&mut page,
&format!(
"({root}).location.href === {} && ({root}).document.body?.dataset.loaded === 'yes'",
serde_json::to_string(url)?
),
)
.await
.with_context(|| format!("opening {root}"))?;
Ok((page, root))
}
fn frames(root: &str) -> String {
format!("Array.from(({root}).document.querySelectorAll('iframe[data-static]'))")
}
async fn snapshot(page: &mut HistoryPage, root: &str) -> Result<Value> {
value(page, &format!("({{length:({root}).history.length, frames:{}.map(f=>({{url:f.contentWindow.location.href, text:f.contentDocument.body.textContent, state:f.contentWindow.history.state, navigationState:f.contentWindow.navigation.currentEntry.getState() ?? null, id:f.contentWindow.navigation.currentEntry.id, keys:f.contentWindow.navigation.entries().map(e=>e.key)}}))}})", frames(root))).await
}
async fn srcdoc(page: &mut HistoryPage, frame: &str, markup: &str) -> Result<()> {
page.evaluate_await(&format!(
"(async()=>{{const f=({frame}); const loaded=new Promise(resolve=>f.addEventListener('load',()=>setTimeout(resolve,0),{{once:true}})); f.srcdoc={}; await loaded; return true;}})()",
serde_json::to_string(markup)?)).await?;
Ok(())
}
#[tokio::test(flavor = "multi_thread")]
async fn nested_history_restores_interleaved_frames_after_parent_document_replacement() -> Result<()>
{
let server = SmokeFixtureServer::start().await;
let initial_url = markup_url(&server, "<!doctype html><body><p>initial</p>");
for popup in [false, true] {
for layout in ["named", "unnamed", "dynamic"] {
let dynamic = if layout == "dynamic" {
format!(
"<script>const f=document.createElement('iframe');f.name='a';f.src={};document.body.prepend(f);</script>",
serde_json::to_string(&initial_url)?
)
} else {
String::new()
};
let names = if layout == "unnamed" {
["", ""]
} else {
["a", "b"]
};
let source = markup_url(
&server,
&format!(
"<!doctype html><body>{dynamic}{}{}",
frame(&initial_url, names[0]),
frame(&initial_url, names[1])
),
);
let away = markup_url(&server, "<!doctype html><body><p>away from parent</p>");
let (mut page, root) = open_root(&source, popup, &server.url("/plain?opener")).await?;
let list = frames(root);
let initial = snapshot(&mut page, root).await?;
let mut stages = vec![initial.clone()];
for (index, text) in [
(0, "first historical source"),
(1, "second historical source"),
] {
srcdoc(
&mut page,
&format!("({list})[{index}]"),
&format!("<p>{text}</p>"),
)
.await?;
wait(
&mut page,
&format!("({list})[{index}].contentDocument.body.textContent === '{text}'"),
)
.await?;
stages.push(snapshot(&mut page, root).await?);
}
page.evaluate(&format!(
"({list})[0].contentWindow.location.hash = 'fragment'; true"
))
.await?;
wait(
&mut page,
&format!("({list})[0].contentWindow.location.hash === '#fragment'"),
)
.await?;
page.evaluate(&format!("({list})[0].contentWindow.history.replaceState({{classic:3}}, ''); ({list})[0].contentWindow.navigation.updateCurrentEntry({{state:{{navigation:3}}}}); true")).await?;
let expected = snapshot(&mut page, root).await?;
assert_eq!(
expected["length"].as_u64(),
initial["length"].as_u64().map(|length| length + 3)
);
navigate(
&mut page,
root,
&format!("location.href = {}", serde_json::to_string(&away)?),
&away,
)
.await?;
navigate(&mut page, root, "history.back()", &source).await?;
let restored = snapshot(&mut page, root).await?;
assert_eq!(
restored["frames"], expected["frames"],
"popup={popup}, {layout}: {restored}"
);
assert_eq!(
restored["length"].as_u64(),
initial["length"].as_u64().map(|length| length + 4)
);
for reference in stages.iter().rev() {
page.evaluate(&format!("({root}).history.back(); true"))
.await?;
let urls = reference["frames"]
.as_array()
.unwrap()
.iter()
.map(|frame| frame["url"].clone())
.collect::<Vec<_>>();
wait(
&mut page,
&format!(
"JSON.stringify(({list}).map(f=>f.contentWindow.location.href)) === {}",
serde_json::to_string(&serde_json::to_string(&urls)?)?
),
)
.await?;
let current = snapshot(&mut page, root).await?;
for index in 0..2 {
assert_eq!(
current["frames"][index]["id"], reference["frames"][index]["id"],
"popup={popup}, {layout}: {current}"
);
}
}
navigate(&mut page, root, "history.go(4)", &away).await?;
navigate(&mut page, root, "history.go(-3)", &source).await?;
let restored = snapshot(&mut page, root).await?;
for index in 0..2 {
assert_eq!(
restored["frames"][index]["id"], stages[1]["frames"][index]["id"],
"popup={popup}, {layout}: {restored}"
);
}
page.evaluate(&format!(
"({list})[1].contentWindow.history.pushState({{fork:true}}, '', '#fork'); true"
))
.await?;
assert_eq!(
value(&mut page, &format!("({root}).history.length")).await?,
json!(initial["length"].as_u64().unwrap() + 2)
);
if layout == "dynamic" {
assert_eq!(value(&mut page, &format!("({root}).document.querySelector('iframe').contentDocument.body.textContent")).await?, json!("initial"));
}
if popup {
page.evaluate("testPopup.close(); true").await?;
}
}
}
Ok(())
}
#[tokio::test(flavor = "multi_thread")]
async fn nested_history_retains_children_of_a_script_created_parent_navigable() -> Result<()> {
let server = SmokeFixtureServer::start().await;
let leaf = markup_url(&server, "<!doctype html><body><p>initial</p>");
let parent = markup_url(
&server,
&format!("<!doctype html><body>{}", frame(&leaf, "grandchild")),
);
let source = markup_url(
&server,
&format!(
"<!doctype html><body><script>const f=document.createElement('iframe');f.src={};document.body.append(f);</script>",
serde_json::to_string(&parent)?
),
);
let away = markup_url(&server, "<!doctype html><body><p>away from child</p>");
for popup in [false, true] {
let (mut page, root) = open_root(&source, popup, &server.url("/plain?opener")).await?;
let container = format!("({root}).document.querySelector('iframe').contentWindow");
let child = format!("({container}).document.querySelector('iframe')");
srcdoc(&mut page, &child, "<p>script parent historical child</p>").await?;
let id = value(
&mut page,
&format!("({child}).contentWindow.navigation.currentEntry.id"),
)
.await?;
navigate(
&mut page,
&container,
&format!("location.href = {}", serde_json::to_string(&away)?),
&away,
)
.await?;
navigate(&mut page, &container, "history.back()", &parent).await?;
assert_eq!(
value(
&mut page,
&format!("({child}).contentWindow.navigation.currentEntry.id")
)
.await?,
id
);
assert_eq!(
value(
&mut page,
&format!("({child}).contentDocument.body.textContent")
)
.await?,
json!("script parent historical child")
);
if popup {
page.evaluate("testPopup.close(); true").await?;
}
}
Ok(())
}
#[tokio::test(flavor = "multi_thread")]
async fn nested_history_restores_grandchildren_with_their_parent_document_identity() -> Result<()> {
let server = SmokeFixtureServer::start().await;
let leaf = markup_url(&server, "<!doctype html><body><p>initial</p>");
let parent = markup_url(
&server,
&format!("<!doctype html><body>{}", frame(&leaf, "grandchild")),
);
let source = markup_url(
&server,
&format!("<!doctype html><body>{}", frame(&parent, "child")),
);
let away = markup_url(&server, "<!doctype html><body><p>away from grandchild</p>");
for popup in [false, true] {
let (mut page, root) = open_root(&source, popup, &server.url("/plain?opener")).await?;
let child = format!(
"({root}).document.querySelector('iframe').contentDocument.querySelector('iframe')"
);
srcdoc(&mut page, &child, "<p>historical grandchild</p>").await?;
wait(
&mut page,
&format!("({child}).contentDocument.body.textContent === 'historical grandchild'"),
)
.await?;
let id = value(
&mut page,
&format!("({child}).contentWindow.navigation.currentEntry.id"),
)
.await?;
navigate(
&mut page,
root,
&format!("location.href = {}", serde_json::to_string(&away)?),
&away,
)
.await?;
navigate(&mut page, root, "history.back()", &source).await?;
assert_eq!(
value(
&mut page,
&format!("({child}).contentWindow.navigation.currentEntry.id")
)
.await?,
id
);
assert_eq!(
value(
&mut page,
&format!("({child}).contentDocument.body.textContent")
)
.await?,
json!("historical grandchild")
);
if popup {
page.evaluate("testPopup.close(); true").await?;
}
}
Ok(())
}
@@ -290,6 +290,7 @@ async fn fixture_handler(
&[],
),
"/plain" => html("<!doctype html><main>plain ok</main>"),
"/history-markup" => html(query.get("markup").map(String::as_str).unwrap_or_default()),
"/iframe" => html(r#"<!doctype html><main>parent</main><iframe src="/child"></iframe>"#),
"/child" => html("<!doctype html><body>child body text</body>"),
"/wait-for-function" => html(
@@ -107,8 +107,10 @@ mod navigation_restore;
mod navigation_result;
mod navigation_seed;
mod navigation_serialize;
pub(crate) use navigation_entry::navigation_entry_public_token;
pub(crate) use navigation_serialize::{
current_document_referrer_policy, document_referrer_policy_for_native_document,
history_document_id_for_holder,
};
mod navigation_surface;
mod navigation_transition_worlds;
@@ -183,7 +183,7 @@ pub(super) fn navigation_entry_referrer_policy_value<'s>(
navigation_entry_stored_string(scope, entry, EntryStringField::ReferrerPolicy)
}
pub(super) fn navigation_entry_public_token(token: &str) -> String {
pub(crate) fn navigation_entry_public_token(token: &str) -> String {
if token.is_empty() || is_uuid_v4_like(token) {
return token.to_owned();
}
@@ -15,7 +15,7 @@ use crate::native_bridge::{
use crate::util::context_host_ptr_for_navigation_owner as context_host_ptr_for_navigation_seed_owner;
use crate::{document_runtime::DomHandle, native_bridge::node_runtime_and_handle_from_object};
fn capture_navigation_entry_seed_for_holder<'s>(
pub(crate) fn capture_navigation_entry_seed_for_holder<'s>(
scope: &mut v8::PinScope<'s, '_>,
owner: v8::Local<'s, v8::Object>,
) -> Option<NavigationHistoryEntrySeed> {
@@ -29,6 +29,14 @@ fn capture_navigation_entry_seed_for_holder<'s>(
})
}
pub(crate) fn history_document_id_for_holder<'s>(
scope: &mut v8::PinScope<'s, '_>,
owner: v8::Local<'s, v8::Object>,
) -> Option<NavigationHistoryDocumentId> {
let entry = navigation_current_entry(scope, owner)?;
navigation_entry_document_id(scope, entry).map(NavigationHistoryDocumentId::from_serialized)
}
pub(super) fn sync_navigation_entry_seed_from_owner<'s>(
scope: &mut v8::PinScope<'s, '_>,
owner: v8::Local<'s, v8::Object>,
@@ -147,6 +147,11 @@ pub(super) fn restore<'s>(
if let Some(update) = update {
publish(scope, owner, update);
}
let root = binding.popup.map_or(
OwnerDispatchScope::Top,
OwnerDispatchScope::LightweightPopup,
);
unsafe { &mut *host_ptr }.remember_nested_histories(root);
}
pub(crate) fn install_session_history_position(
@@ -248,6 +253,11 @@ pub(super) fn commit<'s>(
if let Some(update) = update {
publish(scope, owner, update);
}
let root = binding.popup.map_or(
OwnerDispatchScope::Top,
OwnerDispatchScope::LightweightPopup,
);
unsafe { &mut *host_ptr }.remember_nested_histories(root);
}
/// Capture the next top-level Document's history without committing a pending
+5 -3
View File
@@ -377,13 +377,13 @@ pub(crate) fn parse_browsing_context_document_projection_from_source<'s>(
let source = preserve_decoded_bom_only_browsing_context_body(source, content_type);
let (parsed, kind) =
parse_browsing_context_document_snapshot(document_url, &source, content_type, html_parser);
build_detached_document_from_dom_host_with_content_type(
build_detached_document_object_from_dom_host_with_content_type(
scope,
kind.bridge_kind(),
parsed,
kind,
true,
content_type,
character_set,
true,
)
}
@@ -450,6 +450,7 @@ fn build_detached_document_with_content_type<'s>(
DomHost::from_dom(parsed),
content_type,
None,
false,
)
}
@@ -478,6 +479,7 @@ fn build_detached_document_from_dom_host_with_content_type<'s>(
parsed,
content_type,
character_set,
false,
)
}
@@ -244,6 +244,7 @@ impl PageScriptHost {
{
entry.remember_srcdoc_history_resource(snapshot, origin);
}
self.remember_child_history(handle);
let owner_local_window_id = current_owner.local_window_id;
let owner_document_id = current_owner.document_id;
self.dom_host_mut()
@@ -75,7 +75,11 @@ impl PageScriptHost {
let Some(entry) = self.child_browsing_contexts.get_mut(&handle) else {
return false;
};
entry.set_navigation_entry_seed(entry_seed)
let committed = entry.set_navigation_entry_seed(entry_seed);
if committed {
self.remember_child_history(handle);
}
committed
}
pub(crate) fn pending_child_browsing_context_navigation_position(
@@ -32,6 +32,7 @@ mod classic_scripts;
mod discovery;
mod lookup;
mod module_scripts;
mod nested_history;
mod registry;
mod request_scope;
mod srcdoc_history;
@@ -39,6 +40,8 @@ mod stylesheets;
pub(in crate::native_bridge::context_host) use classic_scripts::ChildParserClassicScriptCandidate;
pub(in crate::native_bridge::context_host) use classic_scripts::PendingChildExternalClassicDocumentScriptLoad;
pub(super) use nested_history::ChildHistoryIdentity;
pub(crate) use nested_history::NestedHistoryStore;
pub(crate) use request_scope::WebStorageScope;
pub(in crate::native_bridge::context_host) use request_scope::{
document_sandbox_policy_from_attribute, sandbox_attribute_forces_opaque_origin,
@@ -50,6 +53,9 @@ pub(super) struct ChildBrowsingContextEntry {
pub(super) pending_download_policy:
Option<super::child_documents::ChildNavigationDownloadPolicy>,
retiring: bool,
history_identity: Option<ChildHistoryIdentity>,
restored_history_positions: Option<nested_history::NavigableHistory>,
restoring_history: bool,
current_document_loader_id: Option<String>,
name: Option<String>,
id: Option<String>,
@@ -0,0 +1,342 @@
use super::*;
use crate::context_bootstrap::navigation_entry_public_token;
use crate::native_bridge::OwnerDispatchScope;
use moli_page_types::{
JointSessionHistory, SessionHistoryContextId, SessionHistoryEntry, SessionHistoryStepId,
};
#[derive(Clone, Debug)]
pub(crate) struct NavigableHistory {
context: SessionHistoryContextId,
entries: Vec<(SessionHistoryStepId, SessionHistoryEntry)>,
}
impl NavigableHistory {
fn contains(&self, key: &str) -> bool {
self.entries
.iter()
.any(|(_, entry)| entry.key.as_str() == key)
}
fn entry_at(&self, step: SessionHistoryStepId) -> Option<&SessionHistoryEntry> {
self.entries
.iter()
.find(|(id, _)| *id == step)
.map(|(_, entry)| entry)
}
fn retain_in(&mut self, history: &JointSessionHistory) {
self.entries
.retain(|(id, _)| history.entries_at(*id).is_some());
}
}
use parking_lot::Mutex;
/// A parser-created frame can be recreated when its parent Document is
/// repopulated. Script-created frames retain their own nested histories, but
/// a new script-created navigable must not claim an old one's history.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub(in crate::native_bridge::context_host) struct ChildHistoryIdentity {
parent: NavigationHistoryDocumentId,
key: ChildHistoryKey,
}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
enum ChildHistoryKey {
Parser { name: String, ordinal: usize },
Script(NavigationHistoryDocumentId),
}
#[derive(Clone, Debug)]
pub(super) struct ChildHistoryRecord {
seed: NavigationHistoryEntrySeed,
resources: HashMap<NavigationHistoryDocumentId, Arc<srcdoc_history::SrcdocHistoryResource>>,
positions: NavigableHistory,
}
/// This store contains no live DOM handles or V8 objects. Retiring a Document
/// can release its entire subtree without discarding its nested histories.
#[derive(Clone, Debug, Default)]
pub(crate) struct NestedHistoryStore {
records: Arc<Mutex<HashMap<ChildHistoryIdentity, ChildHistoryRecord>>>,
}
impl NestedHistoryStore {
pub(crate) fn prune(
&self,
history: &JointSessionHistory,
roots: &[NavigationHistoryDocumentId],
) {
let mut records = self.records.lock();
for record in records.values_mut() {
record.positions.retain_in(history);
record.seed.entries.retain(|entry| {
record
.positions
.contains(&navigation_entry_public_token(entry.key.as_str()))
});
record.resources.retain(|id, _| {
record
.seed
.entries
.iter()
.any(|entry| &entry.document_id == id)
});
}
let mut reachable: HashSet<_> = roots.iter().cloned().collect();
loop {
let count = reachable.len();
for (identity, record) in records.iter() {
if reachable.contains(&identity.parent) {
reachable.extend(
record
.seed
.entries
.iter()
.map(|entry| entry.document_id.clone()),
);
}
}
if reachable.len() == count {
break;
}
}
records.retain(|identity, record| {
reachable.contains(&identity.parent) && !record.seed.entries.is_empty()
});
}
}
impl PageScriptHost {
fn nested_history_root(&self, handle: DomHandle) -> Option<OwnerDispatchScope> {
let mut owner = self.owner_dispatch_scope_for_node(handle)?;
while let OwnerDispatchScope::Child(parent) = owner {
owner = self.owner_dispatch_scope_for_node(parent)?;
}
Some(owner)
}
pub(crate) fn nested_history_store(&mut self, root: OwnerDispatchScope) -> NestedHistoryStore {
if root == OwnerDispatchScope::Top {
return self.top_level_navigation_history.nested_history();
}
self.popup_nested_histories.entry(root).or_default().clone()
}
pub(super) fn child_history_identity(
&self,
scope: &mut v8::PinScope<'_, '_>,
handle: DomHandle,
) -> Option<ChildHistoryIdentity> {
let node = self.dom_host().node(handle)?;
let parser_created = node.flags().parser_created();
let document = node.owner_document()?;
let owner = self.owner_dispatch_scope_for_node(handle)?;
let parent = match owner {
OwnerDispatchScope::Top => self.top_level_navigation_history.current_document_id()?,
OwnerDispatchScope::Child(parent) => {
let seed = &self
.child_browsing_contexts
.get(&parent)?
.committed_navigation_entry_seed;
seed.entries
.iter()
.find(|entry| entry.history_index == seed.current_index)?
.document_id
.clone()
}
OwnerDispatchScope::LightweightPopup(id) => {
let window = self.lightweight_popup_window(scope, id)?;
crate::context_bootstrap::history_document_id_for_holder(scope, window)?
}
};
if !parser_created {
return Some(ChildHistoryIdentity {
parent,
key: ChildHistoryKey::Script(NavigationHistoryDocumentId::allocate()),
});
}
let name = self
.dom_host()
.get_attribute(handle, "name")
.unwrap_or_default();
let mut handles = Vec::new();
self.collect_child_browsing_context_host_handles(document, &mut handles);
let ordinal = handles
.into_iter()
.filter(|candidate| {
self.dom_host()
.node(*candidate)
.is_some_and(|node| node.flags().parser_created())
&& self
.dom_host()
.get_attribute(*candidate, "name")
.unwrap_or_default()
== name
})
.position(|candidate| candidate == handle)?;
Some(ChildHistoryIdentity {
parent,
key: ChildHistoryKey::Parser { name, ordinal },
})
}
pub(super) fn child_history_for_restoration(
&mut self,
handle: DomHandle,
identity: &ChildHistoryIdentity,
) -> Option<ChildHistoryRecord> {
// Consume each parser identity once in this native parent Document.
// Removing/reinserting a frame in a still-live Document is not history traversal.
let document = self.dom_host().node(handle)?.owner_document()?;
if !self
.claimed_child_histories
.entry(document)
.or_default()
.insert(identity.clone())
{
return None;
}
let root = self.nested_history_root(handle)?;
let popup = match root {
OwnerDispatchScope::LightweightPopup(id) => Some(id),
_ => None,
};
let step = self.session_histories.get_mut(popup).current_step();
let store = self.nested_history_store(root);
let mut record = store.records.lock().get(identity)?.clone();
let key = &record.positions.entry_at(step)?.key;
let target = record
.seed
.entries
.iter()
.find(|entry| navigation_entry_public_token(entry.key.as_str()) == key.as_str())?
.clone();
record.seed.current_index = target.history_index;
record.seed.activation = Some(NavigationActivationSeed {
entry: target,
from: None,
navigation_type: Some("traverse".to_owned()),
});
Some(record)
}
pub(super) fn restore_child_history_after_initial_empty(
&mut self,
scope: &mut v8::PinScope<'_, '_>,
handle: DomHandle,
record: ChildHistoryRecord,
) {
let Some(target) = record
.seed
.entries
.iter()
.find(|entry| entry.history_index == record.seed.current_index)
else {
return;
};
let url = target.url.clone();
let root = self
.nested_history_root(handle)
.unwrap_or(OwnerDispatchScope::Top);
let popup = match root {
OwnerDispatchScope::LightweightPopup(id) => Some(id),
_ => None,
};
let parent = self.owner_dispatch_scope_for_node(handle).unwrap_or(root);
let parent = self.session_histories.context(parent);
self.session_histories
.bind_context(OwnerDispatchScope::Child(handle), record.positions.context);
self.session_histories.get_mut(popup).restore_context(
record.positions.context,
parent,
&record.positions.entries,
);
if let Some(entry) = self.child_browsing_contexts.get_mut(&handle) {
entry.srcdoc_history = record.resources;
entry.restored_history_positions = Some(record.positions);
entry.restoring_history = true;
}
self.queue_deferred_child_browsing_context_navigation_from_entry_seed(
scope,
handle,
&url,
record.seed,
None,
);
}
pub(crate) fn remember_child_history(&mut self, handle: DomHandle) {
let Some(root) = self.nested_history_root(handle) else {
return;
};
let store = self.nested_history_store(root);
let context = self
.session_histories
.context(OwnerDispatchScope::Child(handle));
let popup = match root {
OwnerDispatchScope::LightweightPopup(id) => Some(id),
_ => None,
};
let live_positions = self
.session_histories
.get_mut(popup)
.context_entries(context);
let Some(entry) = self.child_browsing_contexts.get(&handle) else {
return;
};
let Some(identity) = entry.history_identity.clone() else {
return;
};
let seed = entry.committed_navigation_entry_seed();
let positions = (!live_positions.is_empty())
.then_some(NavigableHistory {
context,
entries: live_positions,
})
.or_else(|| entry.restored_history_positions.clone())
.or_else(|| {
store
.records
.lock()
.get(&identity)
.map(|record| record.positions.clone())
});
let Some(positions) = positions else {
return;
};
// A new runtime can briefly expose its initial empty Document while
// the historical target is pending. It must not overwrite that target.
if !seed
.entries
.iter()
.find(|entry| entry.history_index == seed.current_index)
.is_some_and(|entry| {
positions.contains(&navigation_entry_public_token(entry.key.as_str()))
})
{
return;
}
let record = ChildHistoryRecord {
seed,
resources: entry.srcdoc_history.clone(),
positions,
};
store.records.lock().insert(identity, record);
}
pub(crate) fn remember_nested_histories(&mut self, root: OwnerDispatchScope) {
let handles: Vec<_> = self
.child_browsing_contexts
.keys()
.copied()
.filter(|handle| self.nested_history_root(*handle) == Some(root))
.collect();
for handle in handles {
self.remember_child_history(handle);
}
if root == OwnerDispatchScope::Top {
self.top_level_navigation_history
.publish_joint_history(Some(self.session_histories.get_mut(None).clone()));
}
}
}
@@ -104,6 +104,7 @@ impl PageScriptHost {
self.retire_web_mcp_document(crate::native_bridge::WindowDocumentOwner::Frame(
retired_owner,
));
self.claimed_child_histories.remove(&document_handle);
let _ = self.retire_document_resource_loader(
crate::native_bridge::WindowDocumentOwner::Frame(retired_owner),
);
@@ -171,6 +172,17 @@ impl PageScriptHost {
self.object_fallback_bootstraps.remove(&handle);
let existing = self.child_browsing_contexts.get(&handle).cloned();
let is_new = existing.is_none();
let history_identity = existing
.as_ref()
.and_then(|entry| entry.history_identity.clone())
.or_else(|| self.child_history_identity(scope, handle));
let restored_history = if is_new {
history_identity
.as_ref()
.and_then(|identity| self.child_history_for_restoration(handle, identity))
} else {
None
};
let attribute_bootstrap_changed = existing
.as_ref()
.is_some_and(|entry| entry.attribute_bootstrap_changed(&attribute_bootstrap));
@@ -375,10 +387,12 @@ impl PageScriptHost {
});
}
let initial_about_blank_document_is_complete = is_new
&& restored_history.is_none()
&& child_browsing_context_bootstrap_is_initial_about_blank(
&attribute_bootstrap,
);
let initial_navigation_uses_initial_empty_load = is_new
&& restored_history.is_none()
&& child_browsing_context_bootstrap_uses_initial_empty_load(
&attribute_bootstrap,
);
@@ -516,6 +530,13 @@ impl PageScriptHost {
.as_ref()
.and_then(|entry| entry.pending_download_policy),
retiring: false,
history_identity,
restoring_history: existing
.as_ref()
.is_some_and(|entry| entry.restoring_history),
restored_history_positions: existing
.as_ref()
.and_then(|entry| entry.restored_history_positions.clone()),
current_document_loader_id: existing.as_ref().and_then(|entry| {
entry.current_document_loader_id().map(ToOwned::to_owned)
}),
@@ -657,6 +678,9 @@ impl PageScriptHost {
{
entry.set_document_permissions_policy(policy);
}
if let Some(restored) = restored_history {
self.restore_child_history_after_initial_empty(scope, handle, restored);
}
if attribute_bootstrap_changed {
self.cancel_child_meta_refresh_navigation(handle);
}
@@ -521,6 +521,8 @@ impl PageScriptHost {
pending_webcrypto_tasks: HashMap::new(),
opfs_owner_state: None,
history_queue: HistoryQueueState::default(),
popup_nested_histories: HashMap::new(),
claimed_child_histories: HashMap::new(),
rendering_updates: super::rendering_updates::RenderingUpdateState::default(),
scroll_observable_effect_batch:
super::interaction_batch::ScrollObservableEffectBatchState::default(),
@@ -211,6 +211,7 @@ pub(crate) use child_frame_snapshots::{
};
use child_frames::ChildBrowsingContextEntry;
pub(in crate::native_bridge::context_host) use child_frames::ChildParserClassicScriptCandidate;
pub(crate) use child_frames::NestedHistoryStore;
pub(crate) use document_execution_context::DocumentExecutionContext;
pub(crate) use event_callbacks::{EventCallbackId, PreparedEventCallback};
pub(crate) use host_loads::ChildFrameAttachmentSnapshot;
@@ -1025,6 +1026,8 @@ pub(crate) struct PageScriptHost {
>,
opfs_owner_state: Option<opfs_tasks::WindowOpfsOwnerState>,
pub(super) history_queue: HistoryQueueState,
popup_nested_histories: HashMap<OwnerDispatchScope, NestedHistoryStore>,
claimed_child_histories: HashMap<DomHandle, HashSet<child_frames::ChildHistoryIdentity>>,
rendering_updates: rendering_updates::RenderingUpdateState,
scroll_observable_effect_batch: interaction_batch::ScrollObservableEffectBatchState,
view_transition_updates: view_transition_updates::ViewTransitionUpdateState,
@@ -122,6 +122,16 @@ impl PageScriptHost {
self.top_level_navigation_history.clone()
}
pub(crate) fn restore_top_level_navigation_history(
&mut self,
source: &crate::runtime::RendererNavigationHistory,
seed: &NavigationHistoryEntrySeed,
) {
self.top_level_navigation_history = source.restore_for(seed);
self.top_level_navigation_history
.install_joint_history(self.session_histories.get_mut(None));
}
pub(in crate::native_bridge::context_host) fn child_frame_attribute_initiator_has_same_origin(
&self,
handle: DomHandle,
@@ -721,6 +721,8 @@ impl PageScriptHost {
.auxiliary_window
.clone();
self.request_auxiliary_window_close(window_handle);
self.popup_nested_histories
.remove(&OwnerDispatchScope::LightweightPopup(popup_id));
let window = self.lightweight_popup_window(scope, popup_id);
self.unregister_service_worker_popup_client(popup_id);
self.cancel_lightweight_popup_document_loads(popup_id);
@@ -3178,6 +3180,7 @@ impl PageScriptHost {
popup_id: u64,
document_handle: DomHandle,
) {
self.claimed_child_histories.remove(&document_handle);
if self
.lightweight_popup_document_handles
.get(&document_handle)
@@ -42,6 +42,21 @@ impl RendererSessionHistories {
}
}
pub(crate) fn bind_context(
&mut self,
owner: OwnerDispatchScope,
context: SessionHistoryContextId,
) {
if let Some(previous) = self.contexts.insert(owner, context)
&& previous != context
{
self.main.detach(previous);
for history in self.popups.values_mut() {
history.detach(previous);
}
}
}
pub(crate) fn context(&mut self, owner: OwnerDispatchScope) -> SessionHistoryContextId {
match owner {
OwnerDispatchScope::Top | OwnerDispatchScope::LightweightPopup(_) => {
@@ -213,7 +213,9 @@ fn import_detached_document_children_from_host<'s>(
document: v8::Local<'s, v8::Object>,
parsed: &DomHost,
) -> Option<()> {
import_detached_document_children_from_host_with_reaction_policy(scope, document, parsed, false)
import_detached_document_children_from_host_with_reaction_policy(
scope, document, parsed, false, false,
)
}
fn import_detached_document_children_from_host_with_reaction_policy<'s>(
@@ -221,6 +223,7 @@ fn import_detached_document_children_from_host_with_reaction_policy<'s>(
document: v8::Local<'s, v8::Object>,
parsed: &DomHost,
append_to_current_reaction_queue: bool,
preserve_parser_frames: bool,
) -> Option<()> {
let runtime_ptr = context_host_ptr_from_global_bridge(scope)?;
let document_handle = detached_native_handle(scope, document)?;
@@ -229,9 +232,34 @@ fn import_detached_document_children_from_host_with_reaction_policy<'s>(
.collect::<Vec<_>>();
let lazy_native_import = parsed.dom().len() > 1_000;
for child in children {
let mut imported_handles = std::collections::HashMap::new();
let imported = unsafe { &mut *runtime_ptr }
.dom_host_mut()
.import_foreign_node_with_shadow_roots(document_handle, parsed, child, true)?;
.import_foreign_node_with_shadow_roots_and_handle_map(
document_handle,
parsed,
child,
true,
&mut imported_handles,
)?;
if preserve_parser_frames {
// This is a navigation Document projection, not author importNode.
// Preserve parser frame identity before insertion can discover its
// child navigables. Other clone/import paths intentionally clear it.
let runtime = unsafe { &mut *runtime_ptr };
for (source, destination) in imported_handles {
if parsed
.node(source)
.is_some_and(|node| node.flags().parser_created())
&& ["iframe", "frame", "object", "embed"]
.iter()
.any(|name| parsed.is_html_element_named(source, name))
&& let Some(node) = runtime.dom_host_mut().node_mut(destination)
{
node.set_parser_created(true);
}
}
}
crate::native_bridge::element::queue_parser_details_toggle_events_in_subtree(
scope,
runtime_ptr,
@@ -272,7 +300,9 @@ pub(crate) fn build_detached_document_object_from_dom_host<'s>(
kind: &str,
parsed: DomHost,
) -> Option<v8::Local<'s, v8::Object>> {
build_detached_document_object_from_dom_host_with_content_type(scope, kind, parsed, None, None)
build_detached_document_object_from_dom_host_with_content_type(
scope, kind, parsed, None, None, false,
)
}
pub(crate) fn build_detached_document_object_from_dom_host_with_content_type<'s>(
@@ -281,6 +311,7 @@ pub(crate) fn build_detached_document_object_from_dom_host_with_content_type<'s>
parsed: DomHost,
content_type: Option<&str>,
character_set: Option<&str>,
preserve_parser_frames: bool,
) -> Option<v8::Local<'s, v8::Object>> {
let url = detached_document_url(&parsed);
let quirks_mode = parsed.dom().document()?.quirks_mode();
@@ -296,7 +327,13 @@ pub(crate) fn build_detached_document_object_from_dom_host_with_content_type<'s>
character_set,
allow_declarative_shadow_roots,
)?;
import_detached_document_children_from_host(scope, document, &parsed)?;
if preserve_parser_frames {
import_detached_document_children_from_host_with_reaction_policy(
scope, document, &parsed, false, true,
)?;
} else {
import_detached_document_children_from_host(scope, document, &parsed)?;
}
Some(document)
}
@@ -1,6 +1,9 @@
use std::sync::Arc;
use anyhow::{Result, anyhow};
use moli_page_types::{
JointSessionHistory, SessionHistoryContextId, SessionHistoryEntry, SessionHistoryStepId,
};
use moli_page_types::{
NavigationHistoryMutation, cross_document_navigation_seed, reload_navigation_seed,
traversal_navigation_seed_candidate,
@@ -8,7 +11,10 @@ use moli_page_types::{
use parking_lot::Mutex;
use url::Url;
use crate::native_bridge::{NavigationHistoryEntrySeed, NavigationHistorySerializedEntry};
use crate::native_bridge::{
NavigationHistoryDocumentId, NavigationHistoryEntrySeed, NavigationHistorySerializedEntry,
NestedHistoryStore,
};
/// The committed history of a renderer's top-level Document. Publishing a
/// snapshot happens at a history mutation, never while capturing Page state.
@@ -17,6 +23,9 @@ use crate::native_bridge::{NavigationHistoryEntrySeed, NavigationHistorySerializ
#[derive(Clone, Debug, Default)]
pub struct RendererNavigationHistory {
snapshot: Arc<Mutex<Option<Arc<NavigationHistoryEntrySeed>>>>,
joint: Arc<Mutex<Option<JointSessionHistory>>>,
nested: NestedHistoryStore,
selected_step: Arc<Mutex<Option<(String, SessionHistoryStepId)>>>,
}
impl PartialEq for RendererNavigationHistory {
@@ -28,6 +37,85 @@ impl PartialEq for RendererNavigationHistory {
impl Eq for RendererNavigationHistory {}
impl RendererNavigationHistory {
pub(crate) fn nested_history(&self) -> NestedHistoryStore {
self.nested.clone()
}
pub(crate) fn current_document_id(&self) -> Option<NavigationHistoryDocumentId> {
Some(
current_entry(self.snapshot()?.as_ref())?
.document_id
.clone(),
)
}
pub(crate) fn publish_joint_history(&self, joint: Option<JointSessionHistory>) {
*self.joint.lock() = joint;
}
pub(crate) fn select_joint_traversal(&self, key: String, step: SessionHistoryStepId) {
*self.selected_step.lock() = Some((key, step));
}
pub(crate) fn restore_for(&self, seed: &NavigationHistoryEntrySeed) -> Self {
if seed
.activation
.as_ref()
.is_some_and(|activation| activation.navigation_type.as_deref() == Some("push"))
&& let Some(joint) = self.joint.lock().as_ref()
{
self.nested.prune(
joint,
&seed
.entries
.iter()
.map(|entry| entry.document_id.clone())
.collect::<Vec<_>>(),
);
}
let current = current_entry(seed);
let target_step = self.selected_step.lock().as_ref().and_then(|(key, step)| {
current
.filter(|entry| entry.key.as_str() == key)
.map(|_| *step)
});
let joint = self.joint.lock().clone().and_then(|mut joint| {
let current = current_entry(seed)?;
let entry = SessionHistoryEntry {
key: moli_page_types::NavigationHistoryEntryKey::from_serialized(
crate::context_bootstrap::navigation_entry_public_token(current.key.as_str()),
),
document: current.document_id.clone(),
};
match seed.session_history.commit {
moli_page_types::SessionHistoryCommit::Push => {
joint.push(SessionHistoryContextId::ROOT, entry)
}
moli_page_types::SessionHistoryCommit::Traverse => {
let step = target_step
.or(seed.session_history.target_step)
.or_else(|| {
joint.step_for_entry(SessionHistoryContextId::ROOT, &entry.key)
})?;
joint.traverse(step)?;
}
_ => joint.replace(SessionHistoryContextId::ROOT, entry),
}
Some(joint)
});
Self {
snapshot: Arc::new(Mutex::new(Some(Arc::new(seed.clone())))),
joint: Arc::new(Mutex::new(joint)),
nested: self.nested.clone(),
selected_step: Arc::default(),
}
}
pub(crate) fn install_joint_history(&self, history: &mut JointSessionHistory) {
if let Some(joint) = self.joint.lock().clone() {
*history = joint;
}
}
pub(crate) fn publish(&self, seed: NavigationHistoryEntrySeed) {
*self.snapshot.lock() = Some(Arc::new(seed));
}
@@ -95,6 +183,7 @@ impl RendererNavigationHistory {
requested: Arc::new(seed),
source_index,
initial_empty_source: false,
selected_step: self.selected_step.lock().clone(),
}
}
}
@@ -109,6 +198,7 @@ pub struct RendererNavigationHistoryRequest {
requested: Arc<NavigationHistoryEntrySeed>,
source_index: Option<u32>,
initial_empty_source: bool,
selected_step: Option<(String, SessionHistoryStepId)>,
}
impl PartialEq for RendererNavigationHistoryRequest {
@@ -122,6 +212,11 @@ impl PartialEq for RendererNavigationHistoryRequest {
impl Eq for RendererNavigationHistoryRequest {}
impl RendererNavigationHistoryRequest {
pub(crate) fn source_history(&self) -> RendererNavigationHistory {
let mut source = self.source.clone();
source.selected_step = Arc::new(Mutex::new(self.selected_step.clone()));
source
}
/// The browser owns the initial-empty Document lifecycle. Its first
/// navigation has no activation source. Same-document URL updates do not
/// change that lifecycle state.
@@ -51,6 +51,7 @@ impl RendererCreateStreamingRawPageRequest {
document_replacement: _document_replacement,
root_frame_id,
main_document_commit,
navigation_history,
final_url,
response_status,
response_headers,
@@ -118,6 +119,9 @@ impl RendererCreateStreamingRawPageRequest {
main_document_commit,
top_level_storage_key: None,
navigation_bootstrap_entry,
navigation_history_source: navigation_history
.as_ref()
.map(|history| history.source_history()),
reserved_service_worker_client_id: reserved_service_worker_client
.map(RendererReservedServiceWorkerClient::release),
};
@@ -936,6 +936,9 @@ impl RendererOwnerHandle {
.as_ref()
.map(|request| request.resolve(&final_url))
.transpose()?,
navigation_history_source: navigation_history
.as_ref()
.map(|request| request.source_history()),
reserved_service_worker_client_id,
};
env.apply_main_document_commit_referrer();
@@ -1445,6 +1445,7 @@ impl PageVm {
root_frame_id: self.vm().root_frame_id().map(str::to_owned),
top_level_storage_key: None,
navigation_bootstrap_entry: None,
navigation_history_source: Some(self.vm().top_level_navigation_history()),
reserved_service_worker_client_id: None,
}
}
+5 -2
View File
@@ -1127,6 +1127,7 @@ pub(crate) struct PageVmEnvConfig {
pub(crate) layout_configuration: moli_page_types::LayoutConfiguration,
pub(crate) wpt_extensions_enabled: bool,
pub(crate) navigation_bootstrap_entry: Option<crate::native_bridge::NavigationHistoryEntrySeed>,
pub(crate) navigation_history_source: Option<crate::runtime::RendererNavigationHistory>,
pub(crate) reserved_service_worker_client_id:
Option<crate::service_worker_runtime::ServiceWorkerClientId>,
}
@@ -4618,8 +4619,10 @@ impl PageVm {
mode,
AuxiliaryEnvironmentApply::Navigation | AuxiliaryEnvironmentApply::InheritedNavigation
) {
self.vm_mut()
.install_navigation_bootstrap_entry(env.navigation_bootstrap_entry.clone());
self.vm_mut().install_navigation_bootstrap_from_history(
env.navigation_bootstrap_entry.clone(),
env.navigation_history_source.clone(),
);
if env.navigation_bootstrap_entry.is_none()
&& let Some(position) = env
.main_document_commit
@@ -708,6 +708,7 @@ fn minimal_test_page_vm_env_config() -> PageVmEnvConfig {
},
wpt_extensions_enabled: false,
navigation_bootstrap_entry: None,
navigation_history_source: None,
reserved_service_worker_client_id: None,
}
}
@@ -39,6 +39,7 @@ fn default_runtime_hooks_reject_direct_no_owner_page_vm_construction() {
},
wpt_extensions_enabled: false,
navigation_bootstrap_entry: None,
navigation_history_source: None,
reserved_service_worker_client_id: None,
},
PageVmRuntimeHooks::default(),
@@ -705,6 +705,7 @@ fn test_page_vm_with_loader_dom_host_hooks_and_response_referrer_policy(
},
wpt_extensions_enabled: false,
navigation_bootstrap_entry: None,
navigation_history_source: None,
reserved_service_worker_client_id: None,
},
runtime_hooks,
@@ -701,6 +701,7 @@ mod tests {
},
wpt_extensions_enabled: false,
navigation_bootstrap_entry: None,
navigation_history_source: None,
reserved_service_worker_client_id: None,
}
}
@@ -1085,6 +1085,7 @@ mod tests {
},
wpt_extensions_enabled: false,
navigation_bootstrap_entry: None,
navigation_history_source: None,
reserved_service_worker_client_id: None,
}
}
@@ -666,6 +666,8 @@ fn parser_owner_boundary_with_live_backend_queues_document_turn_before_runtime_w
wpt_extensions_enabled: false,
navigation_bootstrap_entry: None,
reserved_service_worker_client_id: None,
navigation_history_source: None,
},
PageVmRuntimeHooks::standalone_without_owner_reservation_for_test(),
crate::dom::native::DomHost::from_dom(NativeDom::new(
@@ -954,6 +956,8 @@ fn parser_connected_head_script_does_not_push_later_head_tokens_into_body() {
wpt_extensions_enabled: false,
navigation_bootstrap_entry: None,
reserved_service_worker_client_id: None,
navigation_history_source: None,
},
PageVmRuntimeHooks::standalone_without_owner_reservation_for_test(),
parser_dom_host,
@@ -1130,6 +1134,8 @@ fn parser_connected_external_head_script_with_live_head_and_body_mutation_keeps_
wpt_extensions_enabled: false,
navigation_bootstrap_entry: None,
reserved_service_worker_client_id: None,
navigation_history_source: None,
},
PageVmRuntimeHooks::standalone_without_owner_reservation_for_test(),
parser_dom_host,
@@ -1728,6 +1734,8 @@ fn parser_owner_body_stylesheet_pause_preserves_unconsumed_tail_on_live_page_vm(
wpt_extensions_enabled: false,
navigation_bootstrap_entry: None,
reserved_service_worker_client_id: None,
navigation_history_source: None,
},
PageVmRuntimeHooks::standalone_without_owner_reservation_for_test(),
parser_dom_host,
@@ -361,6 +361,8 @@ fn external_async_handoff_marks_parser_stream_already_started_on_live_backend()
wpt_extensions_enabled: false,
navigation_bootstrap_entry: None,
reserved_service_worker_client_id: None,
navigation_history_source: None,
},
PageVmRuntimeHooks::standalone_without_owner_reservation_for_test(),
parser_dom_host,
@@ -484,6 +486,8 @@ fn blocking_classic_handoff_registers_parser_owned_handle_on_live_backend() {
wpt_extensions_enabled: false,
navigation_bootstrap_entry: None,
reserved_service_worker_client_id: None,
navigation_history_source: None,
},
PageVmRuntimeHooks::standalone_without_owner_reservation_for_test(),
parser_dom_host,
@@ -617,6 +621,8 @@ fn non_async_post_parse_handoff_registers_pending_before_source_and_seals_withou
wpt_extensions_enabled: false,
navigation_bootstrap_entry: None,
reserved_service_worker_client_id: None,
navigation_history_source: None,
},
PageVmRuntimeHooks::standalone_without_owner_reservation_for_test(),
parser_dom_host,
@@ -785,6 +791,8 @@ fn parser_owned_external_module_handoff_starts_pending_script_tree_root_fetch()
wpt_extensions_enabled: false,
navigation_bootstrap_entry: None,
reserved_service_worker_client_id: None,
navigation_history_source: None,
},
PageVmRuntimeHooks::standalone_without_owner_reservation_for_test(),
parser_dom_host,
@@ -1099,6 +1107,8 @@ fn parser_owned_inline_importmap_handoff_registers_parser_owned_handle_on_live_b
wpt_extensions_enabled: false,
navigation_bootstrap_entry: None,
reserved_service_worker_client_id: None,
navigation_history_source: None,
},
PageVmRuntimeHooks::standalone_without_owner_reservation_for_test(),
parser_dom_host,
@@ -1263,6 +1273,8 @@ fn parser_owner_style_import_handoff_is_stylesheet_gated_on_live_page_vm() {
wpt_extensions_enabled: false,
navigation_bootstrap_entry: None,
reserved_service_worker_client_id: None,
navigation_history_source: None,
},
PageVmRuntimeHooks::standalone_without_owner_reservation_for_test(),
parser_dom_host,
@@ -1155,6 +1155,8 @@ fn parser_connected_head_document_write_keeps_later_head_tokens_in_head() {
wpt_extensions_enabled: false,
navigation_bootstrap_entry: None,
reserved_service_worker_client_id: None,
navigation_history_source: None,
},
PageVmRuntimeHooks::standalone_without_owner_reservation_for_test(),
parser_dom_host,
@@ -770,10 +770,24 @@ impl ScriptVm {
});
}
#[cfg(test)]
pub(crate) fn install_navigation_bootstrap_entry(
&mut self,
entry_seed: Option<crate::native_bridge::NavigationHistoryEntrySeed>,
) {
self.install_navigation_bootstrap_from_history(entry_seed, None);
}
pub(super) fn install_navigation_bootstrap_from_history(
&mut self,
entry_seed: Option<super::native_bridge::NavigationHistoryEntrySeed>,
source: Option<crate::runtime::RendererNavigationHistory>,
) {
if let (Some(source), Some(seed)) = (&source, &entry_seed) {
self._context_host
.borrow_mut()
.restore_top_level_navigation_history(source, seed);
}
if let Some(pending) = self.main_world.pending_mut() {
pending.history_entry = entry_seed;
return;
+29
View File
@@ -265,6 +265,35 @@ impl JointSessionHistory {
})
}
pub fn context_entries(
&self,
context: SessionHistoryContextId,
) -> Vec<(SessionHistoryStepId, SessionHistoryEntry)> {
self.steps
.iter()
.filter_map(|step| {
step.entries
.get(&context)
.cloned()
.map(|entry| (step.id, entry))
})
.collect()
}
pub fn restore_context(
&mut self,
context: SessionHistoryContextId,
parent: SessionHistoryContextId,
entries: &[(SessionHistoryStepId, SessionHistoryEntry)],
) {
self.parents.insert(context, parent);
for step in &mut self.steps {
if let Some((_, entry)) = entries.iter().find(|(id, _)| *id == step.id) {
step.entries.insert(context, entry.clone());
}
}
}
pub fn prune_all_but_current(&mut self) {
if self.steps.len() == 1 {
return;