mirror of
https://github.com/lexmount/moli.git
synced 2026-11-22 00:02:21 +00:00
fix(navigation): dispatch popup cross-document history events
Route popup history traversal through the Window-owned task queue and retain its Navigation API signal and method results until commit or cancellation. Window.stop() aborts those API results while the physical traversal continues. Deliver popup pageshow and traversal unload events, preserve nested unload guards, and handle close() from navigate and pagehide callbacks. Add gated HTTP regression coverage for traversal metadata, cancellation, ignored responses, and opener history isolation.
This commit is contained in:
@@ -5,6 +5,8 @@ use std::sync::{
|
||||
};
|
||||
use std::time::Duration;
|
||||
|
||||
mod history_traversal;
|
||||
|
||||
struct ResponseGate {
|
||||
requests: AtomicUsize,
|
||||
responses: AtomicUsize,
|
||||
|
||||
+362
@@ -0,0 +1,362 @@
|
||||
use super::*;
|
||||
|
||||
async fn traversal_page(response: &'static str) -> (SameDocumentPage, Arc<ResponseGate>) {
|
||||
let gate = Arc::new(ResponseGate {
|
||||
requests: AtomicUsize::new(0),
|
||||
responses: AtomicUsize::new(0),
|
||||
release: tokio::sync::Semaphore::new(0),
|
||||
});
|
||||
let observed = gate.clone();
|
||||
let routes = axum::Router::new().route(
|
||||
"/traversal.html",
|
||||
axum::routing::get(move || {
|
||||
let gate = observed.clone();
|
||||
async move {
|
||||
use axum::response::IntoResponse;
|
||||
let visit = gate.requests.fetch_add(1, Ordering::SeqCst) + 1;
|
||||
if visit > 1 {
|
||||
gate.release.acquire().await.unwrap().forget();
|
||||
}
|
||||
gate.responses.fetch_add(1, Ordering::SeqCst);
|
||||
if visit > 1 {
|
||||
match response {
|
||||
"204" => return axum::http::StatusCode::NO_CONTENT.into_response(),
|
||||
"205" => return axum::http::StatusCode::RESET_CONTENT.into_response(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let mut result = (
|
||||
[(axum::http::header::CONTENT_TYPE, "text/html")],
|
||||
r#"<!doctype html><title>Traversal target</title><script>
|
||||
onpageshow = event => opener.traversalPageShown(event.persisted);
|
||||
</script>"#,
|
||||
)
|
||||
.into_response();
|
||||
if visit > 1 && response == "attachment" {
|
||||
result.headers_mut().insert(
|
||||
axum::http::header::CONTENT_DISPOSITION,
|
||||
axum::http::HeaderValue::from_static("attachment; filename=traversal.txt"),
|
||||
);
|
||||
}
|
||||
result
|
||||
}
|
||||
}),
|
||||
);
|
||||
(SameDocumentPage::with_routes(routes).await, gate)
|
||||
}
|
||||
|
||||
const SETUP_TRAVERSAL: &str = r#"(async () => {
|
||||
globalThis.shown = [];
|
||||
globalThis.traversalPageShown = persisted => shown.push(persisted);
|
||||
globalThis.popup = open('traversal.html', 'history-traversal');
|
||||
await new Promise(resolve => popup.addEventListener('load', resolve, {once:true}));
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
if (shown.length !== 1 || shown[0] !== false) throw new Error('missing initial pageshow');
|
||||
popup.navigation.updateCurrentEntry({state: {original: true}});
|
||||
const entry = popup.navigation.currentEntry;
|
||||
globalThis.destination = {url: entry.url, key: entry.key, id: entry.id};
|
||||
const firstDocument = popup.document;
|
||||
popup.addEventListener('unload', () => {});
|
||||
popup.location.href = 'history.html?second-popup';
|
||||
for (let i = 0; popup.document === firstDocument && i < 500; ++i)
|
||||
await new Promise(resolve => setTimeout(resolve, 10));
|
||||
if (popup.document === firstDocument) throw new Error('second Document never committed');
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
globalThis.popupDocument = popup.document;
|
||||
globalThis.popupNavigation = popup.navigation;
|
||||
globalThis.PopupDOMException = popup.DOMException;
|
||||
globalThis.events = [];
|
||||
globalThis.signals = [];
|
||||
globalThis.reasons = [];
|
||||
globalThis.states = {};
|
||||
globalThis.details = [];
|
||||
globalThis.info = {token: 42};
|
||||
for (const type of ['beforeunload', 'pagehide', 'unload'])
|
||||
popup.addEventListener(type, () => {
|
||||
events.push(type);
|
||||
if (type === 'pagehide' && ACTION === 'close-pagehide') popup.close();
|
||||
});
|
||||
popupNavigation.addEventListener('navigate', event => {
|
||||
events.push('navigate');
|
||||
signals.push(event.signal);
|
||||
event.signal.addEventListener('abort', () => events.push('abort'));
|
||||
const detail = {
|
||||
type: event.navigationType, cancelable: event.cancelable,
|
||||
canIntercept: event.canIntercept, userInitiated: event.userInitiated,
|
||||
hashChange: event.hashChange, sameDocument: event.destination.sameDocument,
|
||||
urlMatches: event.destination.url === destination.url,
|
||||
keyMatches: event.destination.key === destination.key,
|
||||
idMatches: event.destination.id === destination.id,
|
||||
index: event.destination.index, state: event.destination.getState(),
|
||||
infoMatches: event.info === (METHOD === 'history-back' ? undefined : info),
|
||||
formData: event.formData, downloadRequest: event.downloadRequest,
|
||||
sourceElement: event.sourceElement,
|
||||
};
|
||||
details.push(detail);
|
||||
if (ACTION === 'prevent') {
|
||||
event.preventDefault();
|
||||
detail.prevented = event.defaultPrevented;
|
||||
}
|
||||
if (ACTION === 'intercept') {
|
||||
try { event.intercept(); detail.intercept = 'allowed'; }
|
||||
catch (error) { detail.intercept = error.name; }
|
||||
}
|
||||
if (ACTION === 'stop-dispatch') popup.stop();
|
||||
if (ACTION === 'close-dispatch') popup.close();
|
||||
});
|
||||
popupNavigation.addEventListener('navigateerror', event => {
|
||||
events.push('error:' + event.error.name); reasons.push(event.error);
|
||||
});
|
||||
popupNavigation.addEventListener('navigatesuccess', () => events.push('success'));
|
||||
globalThis.traversalSnapshot = () => ({
|
||||
closed: popup.closed, sameDocument: popup.document === popupDocument,
|
||||
href: popup.location.href, events: [...events], details: [...details],
|
||||
index: popup.closed ? null : popup.navigation.currentEntry.index,
|
||||
length: popup.closed ? null : popup.history.length,
|
||||
states: {...states}, aborted: signals.map(signal => signal.aborted),
|
||||
errorIdentity: reasons.every(error => error === signals[0].reason && error instanceof PopupDOMException),
|
||||
reasons: reasons.length, shown: [...shown],
|
||||
});
|
||||
globalThis.beginTraversal = () => {
|
||||
let result;
|
||||
if (METHOD === 'history-back') popup.history.back();
|
||||
else if (METHOD === 'back') result = popupNavigation.back({info});
|
||||
else result = popupNavigation.traverseTo(destination.key, {info});
|
||||
if (result) for (const key of ['committed', 'finished']) result[key].then(
|
||||
() => states[key] = 'fulfilled',
|
||||
error => { states[key] = error.name; reasons.push(error); }
|
||||
);
|
||||
return traversalSnapshot();
|
||||
};
|
||||
return traversalSnapshot();
|
||||
})()"#;
|
||||
|
||||
async fn setup_traversal(
|
||||
page: &mut SameDocumentPage,
|
||||
method: &str,
|
||||
action: &str,
|
||||
) -> serde_json::Value {
|
||||
page.evaluate(
|
||||
&SETUP_TRAVERSAL
|
||||
.replace("METHOD", &json!(method).to_string())
|
||||
.replace("ACTION", &json!(action).to_string()),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
fn assert_traverse_event(snapshot: &serde_json::Value, action: &str) {
|
||||
let mut expected = json!({
|
||||
"type": "traverse", "cancelable": false, "canIntercept": false,
|
||||
"userInitiated": false, "hashChange": false, "sameDocument": false,
|
||||
"urlMatches": true, "keyMatches": true, "idMatches": true,
|
||||
"index": 0, "state": {"original": true}, "infoMatches": true,
|
||||
"formData": null, "downloadRequest": null, "sourceElement": null,
|
||||
});
|
||||
if action == "prevent" {
|
||||
expected["prevented"] = json!(false);
|
||||
}
|
||||
if action == "intercept" {
|
||||
expected["intercept"] = json!("SecurityError");
|
||||
}
|
||||
assert_eq!(snapshot["details"], json!([expected]), "{snapshot}");
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn popup_cross_document_history_traversal_events_and_cancellation() {
|
||||
for method in ["back", "traverseTo", "history-back"] {
|
||||
for action in [
|
||||
"none",
|
||||
"prevent",
|
||||
"intercept",
|
||||
"stop-dispatch",
|
||||
"stop-pending",
|
||||
"close-pending",
|
||||
] {
|
||||
let (mut page, gate) = traversal_page("html").await;
|
||||
let initial = setup_traversal(&mut page, method, action).await;
|
||||
let started = page.evaluate("beginTraversal()").await;
|
||||
assert_eq!(started["events"], json!([]), "{method}/{action}: {started}");
|
||||
assert_eq!(started["index"], 1);
|
||||
ResponseGate::wait_for(&gate.requests, 2).await;
|
||||
let pending = page.evaluate("traversalSnapshot()").await;
|
||||
assert_traverse_event(&pending, action);
|
||||
assert_eq!(pending["sameDocument"], true, "{pending}");
|
||||
assert_eq!(pending["href"], initial["href"]);
|
||||
assert_eq!(pending["index"], 1);
|
||||
assert_eq!(pending["length"], 2);
|
||||
if action != "stop-dispatch" {
|
||||
assert_eq!(pending["events"], json!(["beforeunload", "navigate"]));
|
||||
assert_eq!(pending["states"], json!({}));
|
||||
assert_eq!(pending["aborted"], json!([false]));
|
||||
}
|
||||
match action {
|
||||
"stop-pending" => {
|
||||
page.evaluate("popup.stop(); void 0").await;
|
||||
}
|
||||
"close-pending" => {
|
||||
page.evaluate("popup.close(); void 0").await;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
gate.release.add_permits(1);
|
||||
ResponseGate::wait_for(&gate.responses, 2).await;
|
||||
let snapshot = if action == "close-pending" {
|
||||
page.evaluate(
|
||||
"new Promise(r => setTimeout(r, 100)).then(() => traversalSnapshot())",
|
||||
)
|
||||
.await
|
||||
} else {
|
||||
page.evaluate(
|
||||
r#"(async () => {
|
||||
for (let i = 0; shown.length < 2 && i < 500; ++i)
|
||||
await new Promise(resolve => setTimeout(resolve, 10));
|
||||
return traversalSnapshot();
|
||||
})()"#,
|
||||
)
|
||||
.await
|
||||
};
|
||||
let aborted = action.starts_with("stop") || action.starts_with("close");
|
||||
let mut events = vec!["beforeunload", "navigate"];
|
||||
if action == "close-pending" {
|
||||
events.push("beforeunload");
|
||||
}
|
||||
if aborted {
|
||||
events.extend(["abort", "error:AbortError"]);
|
||||
}
|
||||
events.extend(["pagehide", "unload"]);
|
||||
assert_eq!(
|
||||
snapshot["events"],
|
||||
json!(events),
|
||||
"{method}/{action}: {snapshot}"
|
||||
);
|
||||
assert_eq!(snapshot["aborted"], json!([aborted]), "{snapshot}");
|
||||
assert_eq!(snapshot["errorIdentity"], true, "{snapshot}");
|
||||
let states = if aborted && method != "history-back" {
|
||||
json!({"committed": "AbortError", "finished": "AbortError"})
|
||||
} else {
|
||||
json!({})
|
||||
};
|
||||
assert_eq!(snapshot["states"], states, "{snapshot}");
|
||||
assert_eq!(
|
||||
snapshot["reasons"],
|
||||
if aborted {
|
||||
if method == "history-back" { 1 } else { 3 }
|
||||
} else {
|
||||
0
|
||||
}
|
||||
);
|
||||
if action == "close-pending" {
|
||||
assert_eq!(snapshot["closed"], true);
|
||||
assert_eq!(snapshot["shown"], json!([false]), "{snapshot}");
|
||||
} else {
|
||||
assert_eq!(snapshot["closed"], false);
|
||||
assert_eq!(snapshot["sameDocument"], false, "{snapshot}");
|
||||
assert_eq!(snapshot["index"], 0);
|
||||
assert_eq!(snapshot["length"], 2);
|
||||
assert_eq!(snapshot["shown"], json!([false, false]));
|
||||
let entry = page.evaluate("({key: popup.navigation.currentEntry.key === destination.key, state: popup.navigation.currentEntry.getState()})").await;
|
||||
assert_eq!(entry, json!({"key": true, "state": {"original": true}}));
|
||||
page.evaluate("popup.close(); void 0").await;
|
||||
}
|
||||
page.assert_history(&[""], 0).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn popup_cross_document_history_traversal_ignored_responses_remain_pending() {
|
||||
for response in ["204", "205", "attachment"] {
|
||||
let (mut page, gate) = traversal_page(response).await;
|
||||
page.allow_downloads().await;
|
||||
let initial = setup_traversal(&mut page, "back", "none").await;
|
||||
page.evaluate("beginTraversal()").await;
|
||||
ResponseGate::wait_for(&gate.requests, 2).await;
|
||||
gate.release.add_permits(1);
|
||||
ResponseGate::wait_for(&gate.responses, 2).await;
|
||||
let pending = page
|
||||
.evaluate("new Promise(r => setTimeout(r, 100)).then(() => traversalSnapshot())")
|
||||
.await;
|
||||
assert_traverse_event(&pending, "none");
|
||||
assert_eq!(
|
||||
pending["events"],
|
||||
json!(["beforeunload", "navigate"]),
|
||||
"{response}: {pending}"
|
||||
);
|
||||
assert_eq!(pending["states"], json!({}));
|
||||
assert_eq!(pending["aborted"], json!([false]));
|
||||
assert_eq!(pending["sameDocument"], true);
|
||||
assert_eq!(pending["href"], initial["href"]);
|
||||
assert_eq!(pending["index"], 1);
|
||||
assert_eq!(pending["shown"], json!([false]));
|
||||
let stopped = page
|
||||
.evaluate("popup.stop(); Promise.resolve().then(() => traversalSnapshot())")
|
||||
.await;
|
||||
assert_eq!(
|
||||
stopped["states"],
|
||||
json!({"committed": "AbortError", "finished": "AbortError"}),
|
||||
"{stopped}"
|
||||
);
|
||||
assert_eq!(stopped["aborted"], json!([true]));
|
||||
assert_eq!(stopped["errorIdentity"], true);
|
||||
page.evaluate("popup.close(); void 0").await;
|
||||
page.assert_history(&[""], 0).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn popup_cross_document_history_traversal_close_during_callbacks() {
|
||||
for action in ["close-dispatch", "close-pagehide"] {
|
||||
let (mut page, gate) = traversal_page("html").await;
|
||||
setup_traversal(&mut page, "back", action).await;
|
||||
page.evaluate("beginTraversal()").await;
|
||||
if action == "close-pagehide" {
|
||||
ResponseGate::wait_for(&gate.requests, 2).await;
|
||||
gate.release.add_permits(1);
|
||||
ResponseGate::wait_for(&gate.responses, 2).await;
|
||||
}
|
||||
let snapshot = page
|
||||
.evaluate("new Promise(r => setTimeout(r, 100)).then(() => traversalSnapshot())")
|
||||
.await;
|
||||
assert_eq!(snapshot["closed"], true, "{action}: {snapshot}");
|
||||
assert_traverse_event(&snapshot, action);
|
||||
if action == "close-dispatch" {
|
||||
assert_eq!(
|
||||
snapshot["events"],
|
||||
json!([
|
||||
"beforeunload",
|
||||
"navigate",
|
||||
"beforeunload",
|
||||
"abort",
|
||||
"error:AbortError",
|
||||
"pagehide",
|
||||
"unload"
|
||||
]),
|
||||
"{snapshot}"
|
||||
);
|
||||
assert_eq!(snapshot["aborted"], json!([true]));
|
||||
assert_eq!(
|
||||
snapshot["states"],
|
||||
json!({"committed": "AbortError", "finished": "AbortError"})
|
||||
);
|
||||
assert_eq!(snapshot["errorIdentity"], true);
|
||||
assert_eq!(snapshot["reasons"], 3);
|
||||
assert_eq!(gate.requests.load(Ordering::SeqCst), 1);
|
||||
} else {
|
||||
assert_eq!(
|
||||
snapshot["events"],
|
||||
json!([
|
||||
"beforeunload",
|
||||
"navigate",
|
||||
"pagehide",
|
||||
"beforeunload",
|
||||
"unload"
|
||||
]),
|
||||
"{snapshot}"
|
||||
);
|
||||
assert_eq!(snapshot["aborted"], json!([false]));
|
||||
assert_eq!(snapshot["states"], json!({}));
|
||||
assert_eq!(snapshot["reasons"], 0);
|
||||
}
|
||||
page.assert_history(&[""], 0).await;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,8 @@ pub(super) mod traversal;
|
||||
pub(super) use self::admission::require_fully_active_history_owner;
|
||||
pub(super) use self::traversal::{
|
||||
apply_pending_history_traversal, cancel_active_history_traversal_intercept_settlement,
|
||||
pending_history_traversal_target_index, route_history_traversal_task,
|
||||
history_traversal_target_window, pending_history_traversal_target_index,
|
||||
route_history_traversal_task,
|
||||
};
|
||||
|
||||
pub(super) use super::navigation_traversal_coordinator::cancel_pending as cancel_pending_precommit_history_traversal;
|
||||
|
||||
@@ -140,7 +140,7 @@ pub(in crate::context_bootstrap) fn route_history_traversal_task(
|
||||
crate::native_bridge::PendingHistoryTraversalAction::SameDocument(traversal) => {
|
||||
traversal.results.as_slice()
|
||||
}
|
||||
crate::native_bridge::PendingHistoryTraversalAction::ChildCrossDocument(traversal) => {
|
||||
crate::native_bridge::PendingHistoryTraversalAction::CrossDocument(traversal) => {
|
||||
traversal.results.as_slice()
|
||||
}
|
||||
};
|
||||
@@ -305,7 +305,7 @@ pub(in crate::context_bootstrap) fn finish_history_participant<'s>(
|
||||
}
|
||||
}
|
||||
|
||||
fn history_traversal_target_window<'s>(
|
||||
pub(in crate::context_bootstrap) fn history_traversal_target_window<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
host: &mut PageScriptHost,
|
||||
target: crate::native_bridge::WindowTaskTarget,
|
||||
|
||||
@@ -168,13 +168,6 @@ fn stop_navigation_for_window<'s>(
|
||||
if navigation_unload_event_active(scope, window) {
|
||||
return;
|
||||
}
|
||||
if let Some(OwnerDispatchScope::LightweightPopup(popup_id)) =
|
||||
runtime_window_dispatch_scope(scope, window)
|
||||
&& let Some(host_ptr) = context_host_ptr_from_global_bridge(scope)
|
||||
&& unsafe { &*host_ptr }.lightweight_popup_has_pending_history_traversal(popup_id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
inform_about_canceled_navigation_for_window(
|
||||
scope,
|
||||
window,
|
||||
@@ -216,7 +209,23 @@ pub(super) fn clear_pending_cross_document_navigation_for_window<'s>(
|
||||
return;
|
||||
};
|
||||
let host = unsafe { &mut *host_ptr };
|
||||
match runtime_window_dispatch_scope(scope, window) {
|
||||
let dispatch_scope = runtime_window_dispatch_scope(scope, window);
|
||||
if window_navigation_is_stopping(scope, window)
|
||||
&& match dispatch_scope {
|
||||
Some(OwnerDispatchScope::Child(handle)) => {
|
||||
host.child_browsing_context_has_pending_cross_document_traversal(handle)
|
||||
}
|
||||
Some(OwnerDispatchScope::LightweightPopup(popup_id)) => {
|
||||
host.lightweight_popup_has_pending_cross_document_traversal(popup_id)
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
{
|
||||
// stop() still aborts the Navigation API signal and method promises,
|
||||
// but cannot cancel the physical cross-document history traversal.
|
||||
return;
|
||||
}
|
||||
match dispatch_scope {
|
||||
Some(crate::native_bridge::OwnerDispatchScope::Top) => {
|
||||
host.clear_pending_location_navigation();
|
||||
}
|
||||
|
||||
@@ -582,6 +582,7 @@ fn dispatch_unload_lifecycle_event_for_runtime_owner<'s>(
|
||||
event_type: &str,
|
||||
event: v8::Local<'s, v8::Object>,
|
||||
) {
|
||||
let previous_unload = super::navigation_window::navigation_unload_event_active(scope, owner);
|
||||
let _document_unload = context_host_ptr_from_global_bridge(scope).and_then(|host_ptr| {
|
||||
let host = unsafe { &*host_ptr };
|
||||
super::window_accessors::window_document_handle(scope, owner, host)
|
||||
@@ -609,8 +610,14 @@ fn dispatch_unload_lifecycle_event_for_runtime_owner<'s>(
|
||||
event,
|
||||
matches!(event_type, "pagehide" | "unload"),
|
||||
);
|
||||
} else if let Some(popup_id) =
|
||||
crate::native_bridge::lightweight_popup_id_from_window(scope, owner)
|
||||
&& let Some(host_ptr) = context_host_ptr_from_global_bridge(scope)
|
||||
{
|
||||
unsafe { &mut *host_ptr }
|
||||
.dispatch_lightweight_popup_window_event(scope, popup_id, event_type, event);
|
||||
}
|
||||
set_navigation_unload_event_active(scope, owner, false);
|
||||
set_navigation_unload_event_active(scope, owner, previous_unload);
|
||||
}
|
||||
|
||||
pub(super) fn queue_hash_change_for_runtime_owner<'s>(
|
||||
@@ -1105,12 +1112,14 @@ pub(super) fn dispatch_navigation_traverse_event_with_outcome<'s>(
|
||||
let current_href = window_location_for_holder(scope, owner)
|
||||
.and_then(|location| location_href_slot(scope, location))
|
||||
.unwrap_or_default();
|
||||
let hash_change = should_dispatch_hash_change(¤t_href, &target_href);
|
||||
let destination_same_document = navigation_destination_same_document_value(scope, destination);
|
||||
let hash_change =
|
||||
destination_same_document && should_dispatch_hash_change(¤t_href, &target_href);
|
||||
let Some(signal) = create_navigation_abort_signal(scope) else {
|
||||
return NavigationDispatchOutcome::proceed();
|
||||
};
|
||||
let cancelable = runtime_window_is_global(scope, owner);
|
||||
let cancelable = destination_same_document
|
||||
&& child_browsing_context_handle_for_runtime_owner(scope, owner).is_none();
|
||||
let Some(event) = construct_native_navigate_event(
|
||||
scope,
|
||||
"traverse",
|
||||
|
||||
@@ -22,6 +22,8 @@ const CROSS_DOCUMENT_PENDING_COMMITTED_REJECT_SLOT: &str =
|
||||
"__lmCrossDocumentPendingCommittedReject";
|
||||
const CROSS_DOCUMENT_PENDING_FINISHED_REJECT_SLOT: &str = "__lmCrossDocumentPendingFinishedReject";
|
||||
const CROSS_DOCUMENT_PENDING_HREF_SLOT: &str = "__lmCrossDocumentPendingHref";
|
||||
const CROSS_DOCUMENT_PENDING_TRAVERSAL_RESULTS_SLOT: &str =
|
||||
"__lmCrossDocumentPendingTraversalResults";
|
||||
const NAVIGATION_ACTIVE_CROSS_DOCUMENT_PENDING_SLOT: &str =
|
||||
"__lmNavigationActiveCrossDocumentPending";
|
||||
|
||||
@@ -185,6 +187,33 @@ pub(super) fn track_cross_document_location_navigation<'s>(
|
||||
set_navigation_active_cross_document_pending(scope, navigation, data);
|
||||
}
|
||||
|
||||
pub(super) fn track_cross_document_traversal_navigation<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
navigation: v8::Local<'s, v8::Object>,
|
||||
signal: Option<v8::Local<'s, v8::Object>>,
|
||||
href: &str,
|
||||
results: &[crate::native_bridge::PendingNavigationResult],
|
||||
) {
|
||||
track_cross_document_location_navigation(scope, navigation, signal, href);
|
||||
let data = navigation_active_cross_document_pending(scope, navigation)
|
||||
.expect("new traversal must retain its pending navigation");
|
||||
let mut resolvers = Vec::with_capacity(results.len() * 2);
|
||||
for result in results {
|
||||
let committed = v8::Local::new(scope, &result.committed_resolver);
|
||||
let finished = v8::Local::new(scope, &result.finished_resolver);
|
||||
resolvers.push(committed.into());
|
||||
resolvers.push(finished.into());
|
||||
suppress_unhandled_rejection(scope, finished.get_promise(scope));
|
||||
}
|
||||
let resolvers = v8::Array::new_with_elements(scope, &resolvers);
|
||||
set_private_value(
|
||||
scope,
|
||||
data,
|
||||
CROSS_DOCUMENT_PENDING_TRAVERSAL_RESULTS_SLOT,
|
||||
resolvers.into(),
|
||||
);
|
||||
}
|
||||
|
||||
pub(super) fn navigation_immediate_current_entry_result<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
owner: v8::Local<'s, v8::Object>,
|
||||
@@ -387,6 +416,21 @@ pub(super) fn cancel_active_cross_document_navigation<'s>(
|
||||
{
|
||||
let _ = reject.call(scope, receiver, &[error]);
|
||||
}
|
||||
if let Some(resolvers) =
|
||||
get_private_value(scope, data, CROSS_DOCUMENT_PENDING_TRAVERSAL_RESULTS_SLOT)
|
||||
.and_then(|value| v8::Local::<v8::Array>::try_from(value).ok())
|
||||
{
|
||||
for index in 0..resolvers.length() {
|
||||
if let Some(resolver) = resolvers
|
||||
.get_index(scope, index)
|
||||
.and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())
|
||||
// Only native PromiseResolvers are stored in this private array.
|
||||
.map(|object| unsafe { v8::Local::<v8::PromiseResolver>::cast_unchecked(object) })
|
||||
{
|
||||
let _ = resolver.reject(scope, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
|
||||
@@ -551,6 +551,7 @@ fn commit(scope: &mut v8::PinScope<'_, '_>, admission: &PendingHistoryTraversalA
|
||||
participant.handle,
|
||||
participant.url.as_str(),
|
||||
participant.seed.clone(),
|
||||
None,
|
||||
) {
|
||||
for queued in &cross_document {
|
||||
host.cancel_joint_child_history_navigation(queued.handle, step);
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
use super::history_runtime::route_history_traversal_task;
|
||||
use super::history_runtime::{
|
||||
history_traversal_target_window, reject_pending_navigation_results,
|
||||
route_history_traversal_task,
|
||||
};
|
||||
use super::navigation_entry::history_entries;
|
||||
use super::navigation_events::{
|
||||
NavigationDispatchOutcome, dispatch_beforeunload_for_runtime_owner,
|
||||
dispatch_navigation_traverse_event_with_outcome,
|
||||
};
|
||||
use super::navigation_result::{
|
||||
navigation_pending_result, navigation_rejected_dom_exception_result,
|
||||
cancel_active_cross_document_navigation, navigation_dom_exception, navigation_pending_result,
|
||||
navigation_rejected_dom_exception_result, track_cross_document_traversal_navigation,
|
||||
};
|
||||
use super::navigation_seed::history_entry_seed_for_traversal;
|
||||
use super::navigation_window::{navigation_document_is_active, window_navigation_for_holder};
|
||||
use super::navigation_window::{
|
||||
child_browsing_context_handle_for_runtime_owner, runtime_window_is_global,
|
||||
window_task_target_for_runtime_owner,
|
||||
runtime_window_is_global, window_history_for_holder, window_task_target_for_runtime_owner,
|
||||
};
|
||||
use super::*;
|
||||
use crate::document_runtime::DomHandle;
|
||||
use crate::native_bridge::PendingHistoryTraversalAction;
|
||||
use crate::native_bridge::{PendingCrossDocumentTraversal, PendingHistoryTraversalAction};
|
||||
use moli_history::HistoryEntryRef;
|
||||
|
||||
pub(super) struct TraversalTarget<'s> {
|
||||
@@ -30,7 +37,6 @@ pub(super) fn queue_navigation_traversal_with_result<'s>(
|
||||
traversal_target_entry(scope, &target)
|
||||
.and_then(|entry| super::session_history::step_for_entry(scope, target.owner, &entry))
|
||||
});
|
||||
let child_handle = child_browsing_context_handle_for_traversal(scope, target.owner);
|
||||
let Some(host_ptr) = context_host_ptr_from_global_bridge(scope) else {
|
||||
return Some(navigation_rejected_dom_exception_result(
|
||||
scope,
|
||||
@@ -58,20 +64,6 @@ pub(super) fn queue_navigation_traversal_with_result<'s>(
|
||||
host.record_pending_location_navigation(target_url, Some(seed.clone()));
|
||||
return Some(navigation_pending_result(scope));
|
||||
}
|
||||
if let Some(popup_id) =
|
||||
crate::native_bridge::lightweight_popup_id_from_window(scope, target.owner)
|
||||
{
|
||||
host.queue_lightweight_popup_cross_document_traversal(
|
||||
scope,
|
||||
popup_id,
|
||||
target_url.as_str(),
|
||||
seed,
|
||||
);
|
||||
return Some(navigation_pending_result(scope));
|
||||
}
|
||||
if child_handle.is_none() {
|
||||
return Some(navigation_pending_result(scope));
|
||||
};
|
||||
let target_key = traversal_target_entry(scope, &target)
|
||||
.map(|entry| entry.borrow().key.as_str().to_owned());
|
||||
let receiver_context = target
|
||||
@@ -79,7 +71,7 @@ pub(super) fn queue_navigation_traversal_with_result<'s>(
|
||||
.get_creation_context(scope)
|
||||
.unwrap_or_else(|| scope.get_current_context());
|
||||
let receiver_scope = &mut v8::ContextScope::new(scope, receiver_context);
|
||||
let (result, producer) = host.queue_child_cross_document_traversal_with_result(
|
||||
let (result, producer) = host.queue_cross_document_history_traversal_with_result(
|
||||
receiver_scope,
|
||||
exact_target,
|
||||
target.target_index,
|
||||
@@ -126,7 +118,6 @@ pub(super) fn queue_history_traversal_without_result<'s>(
|
||||
traversal_target_entry(scope, &target)
|
||||
.and_then(|entry| super::session_history::step_for_entry(scope, target.owner, &entry))
|
||||
});
|
||||
let child_handle = child_browsing_context_handle_for_traversal(scope, target.owner);
|
||||
let Some(host_ptr) = context_host_ptr_from_global_bridge(scope) else {
|
||||
return;
|
||||
};
|
||||
@@ -134,7 +125,7 @@ pub(super) fn queue_history_traversal_without_result<'s>(
|
||||
let Some(exact_target) = window_task_target_for_runtime_owner(scope, host, target.owner) else {
|
||||
return;
|
||||
};
|
||||
if let Some((target_url, mut seed)) = history_entry_seed_for_traversal(
|
||||
if let Some((_target_url, mut seed)) = history_entry_seed_for_traversal(
|
||||
scope,
|
||||
target.owner,
|
||||
target.current_index,
|
||||
@@ -153,34 +144,21 @@ pub(super) fn queue_history_traversal_without_result<'s>(
|
||||
host.record_pending_top_level_history_traversal(delta);
|
||||
return;
|
||||
}
|
||||
if let Some(popup_id) =
|
||||
crate::native_bridge::lightweight_popup_id_from_window(scope, target.owner)
|
||||
{
|
||||
host.queue_lightweight_popup_cross_document_traversal(
|
||||
scope,
|
||||
popup_id,
|
||||
target_url.as_str(),
|
||||
seed,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if child_handle.is_some() {
|
||||
let target_key = traversal_target_entry(scope, &target)
|
||||
.map(|entry| entry.borrow().key.as_str().to_owned());
|
||||
let receiver_context = target
|
||||
.history
|
||||
.get_creation_context(scope)
|
||||
.unwrap_or_else(|| scope.get_current_context());
|
||||
let receiver_scope = &mut v8::ContextScope::new(scope, receiver_context);
|
||||
if let Some(producer) = host.queue_child_cross_document_traversal(
|
||||
receiver_scope,
|
||||
exact_target,
|
||||
target.target_index,
|
||||
target_key,
|
||||
seed,
|
||||
) {
|
||||
route_history_traversal_task(receiver_scope, host, producer);
|
||||
}
|
||||
let target_key = traversal_target_entry(scope, &target)
|
||||
.map(|entry| entry.borrow().key.as_str().to_owned());
|
||||
let receiver_context = target
|
||||
.history
|
||||
.get_creation_context(scope)
|
||||
.unwrap_or_else(|| scope.get_current_context());
|
||||
let receiver_scope = &mut v8::ContextScope::new(scope, receiver_context);
|
||||
if let Some(producer) = host.queue_cross_document_history_traversal(
|
||||
receiver_scope,
|
||||
exact_target,
|
||||
target.target_index,
|
||||
target_key,
|
||||
seed,
|
||||
) {
|
||||
route_history_traversal_task(receiver_scope, host, producer);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -226,6 +204,160 @@ fn traversal_target_entry_still_available<'s>(
|
||||
.is_some_and(|entry| std::rc::Rc::ptr_eq(&entry, expected_entry))
|
||||
}
|
||||
|
||||
fn traversal_target_key_still_available<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
history: v8::Local<'s, v8::Object>,
|
||||
target_index: u32,
|
||||
expected_key: Option<&str>,
|
||||
) -> bool {
|
||||
let Some(expected_key) = expected_key else {
|
||||
return true;
|
||||
};
|
||||
history_entries(scope, history).is_some_and(|entries| {
|
||||
entries
|
||||
.get(target_index as usize)
|
||||
.is_some_and(|entry| entry.borrow().key.as_str() == expected_key)
|
||||
})
|
||||
}
|
||||
|
||||
pub(in crate::context_bootstrap) fn apply_pending_cross_document_traversal<'s, 'i>(
|
||||
scope: &mut v8::PinScope<'s, 'i>,
|
||||
host: &mut PageScriptHost,
|
||||
traversal: PendingCrossDocumentTraversal,
|
||||
) {
|
||||
if matches!(
|
||||
traversal.target.dispatch_scope(),
|
||||
crate::native_bridge::OwnerDispatchScope::Child(_)
|
||||
) {
|
||||
super::history_runtime::apply_pending_history_traversal(
|
||||
scope,
|
||||
host,
|
||||
crate::native_bridge::PendingHistoryTraversal {
|
||||
joint_step: traversal.seed.session_history.target_step,
|
||||
target: traversal.target,
|
||||
target_index: traversal.target_index,
|
||||
target_key: traversal.target_key,
|
||||
info: traversal.info,
|
||||
results: traversal.results,
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
let Some(target_url) = traversal
|
||||
.seed
|
||||
.entries
|
||||
.iter()
|
||||
.find(|entry| entry.history_index == traversal.seed.current_index)
|
||||
.map(|entry| entry.url.clone())
|
||||
else {
|
||||
reject_cross_document_traversal(scope, &traversal);
|
||||
return;
|
||||
};
|
||||
let Some(owner) = history_traversal_target_window(scope, host, traversal.target) else {
|
||||
reject_cross_document_traversal(scope, &traversal);
|
||||
return;
|
||||
};
|
||||
let Some(history) = window_history_for_holder(scope, owner) else {
|
||||
reject_cross_document_traversal(scope, &traversal);
|
||||
return;
|
||||
};
|
||||
if !traversal_target_key_still_available(
|
||||
scope,
|
||||
history,
|
||||
traversal.target_index,
|
||||
traversal.target_key.as_deref(),
|
||||
) {
|
||||
reject_cross_document_traversal(scope, &traversal);
|
||||
return;
|
||||
}
|
||||
let info = traversal
|
||||
.info
|
||||
.as_ref()
|
||||
.map(|info| v8::Local::new(scope, info));
|
||||
let dispatch_scope = traversal.target.dispatch_scope();
|
||||
let retiring_document =
|
||||
host.current_window_document_task_target_for_dispatch_scope(dispatch_scope);
|
||||
let is_current = |scope: &mut v8::PinScope<'s, 'i>, host: &PageScriptHost| {
|
||||
retiring_document.is_some()
|
||||
&& host.current_window_document_task_target_for_dispatch_scope(dispatch_scope)
|
||||
== retiring_document
|
||||
&& window_task_target_for_runtime_owner(scope, host, owner) == Some(traversal.target)
|
||||
&& navigation_document_is_active(scope, owner)
|
||||
};
|
||||
dispatch_beforeunload_for_runtime_owner(scope, owner);
|
||||
if !is_current(scope, host) {
|
||||
reject_cross_document_traversal(scope, &traversal);
|
||||
return;
|
||||
}
|
||||
let navigation = window_navigation_for_holder(scope, owner);
|
||||
if let Some(navigation) = navigation {
|
||||
cancel_active_cross_document_navigation(scope, navigation, None);
|
||||
}
|
||||
if !is_current(scope, host) {
|
||||
reject_cross_document_traversal(scope, &traversal);
|
||||
return;
|
||||
}
|
||||
let outcome = navigation.map_or_else(NavigationDispatchOutcome::proceed, |navigation| {
|
||||
dispatch_navigation_traverse_event_with_outcome(
|
||||
scope,
|
||||
navigation,
|
||||
history,
|
||||
traversal.target_index,
|
||||
info,
|
||||
)
|
||||
});
|
||||
if let Some(error) = outcome.abort_error {
|
||||
// stop() aborts the API method and signal even though a cross-document
|
||||
// history traversal itself cannot be canceled by script.
|
||||
reject_pending_navigation_results(scope, &traversal.results, error);
|
||||
}
|
||||
// close() queues retirement of this exact Window. Keep its dispatched
|
||||
// event and API results alive until the close task aborts them together.
|
||||
let closing_popup = matches!(dispatch_scope,
|
||||
crate::native_bridge::OwnerDispatchScope::LightweightPopup(popup_id)
|
||||
if host.lightweight_popup_is_closing(popup_id))
|
||||
&& host.current_window_document_task_target_for_dispatch_scope(dispatch_scope)
|
||||
== retiring_document;
|
||||
if outcome.proceed
|
||||
&& outcome.abort_error.is_none()
|
||||
&& (is_current(scope, host) || closing_popup)
|
||||
&& let Some(navigation) = navigation
|
||||
{
|
||||
track_cross_document_traversal_navigation(
|
||||
scope,
|
||||
navigation,
|
||||
outcome.signal,
|
||||
&target_url,
|
||||
&traversal.results,
|
||||
);
|
||||
}
|
||||
if !outcome.proceed || !is_current(scope, host) {
|
||||
if !closing_popup {
|
||||
reject_cross_document_traversal(scope, &traversal);
|
||||
}
|
||||
return;
|
||||
}
|
||||
match dispatch_scope {
|
||||
crate::native_bridge::OwnerDispatchScope::Child(_) => {
|
||||
unreachable!("child traversal uses the coordinator")
|
||||
}
|
||||
crate::native_bridge::OwnerDispatchScope::LightweightPopup(popup_id) => {
|
||||
if !host.queue_lightweight_popup_cross_document_traversal(
|
||||
scope,
|
||||
popup_id,
|
||||
&target_url,
|
||||
traversal.seed,
|
||||
) && let Some(navigation) = navigation
|
||||
{
|
||||
cancel_active_cross_document_navigation(scope, navigation, None);
|
||||
}
|
||||
}
|
||||
crate::native_bridge::OwnerDispatchScope::Top => {
|
||||
unreachable!("top-level traversals are handed off to the browser")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn apply_authorized_history_traversal_task(
|
||||
scope: &mut v8::PinScope<'_, '_>,
|
||||
host: &mut PageScriptHost,
|
||||
@@ -235,30 +367,19 @@ pub(crate) fn apply_authorized_history_traversal_task(
|
||||
PendingHistoryTraversalAction::SameDocument(traversal) => {
|
||||
super::history_runtime::apply_pending_history_traversal(scope, host, traversal);
|
||||
}
|
||||
PendingHistoryTraversalAction::ChildCrossDocument(traversal) => {
|
||||
super::history_runtime::apply_pending_history_traversal(
|
||||
scope,
|
||||
host,
|
||||
crate::native_bridge::PendingHistoryTraversal {
|
||||
joint_step: traversal.seed.session_history.target_step,
|
||||
target: traversal.target,
|
||||
target_index: traversal.target_index,
|
||||
target_key: traversal.target_key,
|
||||
info: traversal.info,
|
||||
results: traversal.results,
|
||||
},
|
||||
);
|
||||
PendingHistoryTraversalAction::CrossDocument(traversal) => {
|
||||
apply_pending_cross_document_traversal(scope, host, *traversal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn child_browsing_context_handle_for_traversal<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
owner: v8::Local<'s, v8::Object>,
|
||||
) -> Option<DomHandle> {
|
||||
if runtime_window_is_global(scope, owner) {
|
||||
None
|
||||
} else {
|
||||
child_browsing_context_handle_for_runtime_owner(scope, owner)
|
||||
fn reject_cross_document_traversal(
|
||||
scope: &mut v8::PinScope<'_, '_>,
|
||||
traversal: &PendingCrossDocumentTraversal,
|
||||
) {
|
||||
if traversal.results.is_empty() {
|
||||
return;
|
||||
}
|
||||
let error = navigation_dom_exception(scope, "Navigation was canceled", "AbortError");
|
||||
reject_pending_navigation_results(scope, &traversal.results, error);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@ use crate::{
|
||||
context_bootstrap::{
|
||||
SIMPLE_EVENT_TARGET_LISTENERS_SLOT, SharedWebStorageStore, WINDOW_NAME_SLOT,
|
||||
apply_local_window_location_navigation, clear_simple_window_event_handler_values,
|
||||
deep_clone_shared_web_storage_store, dispatch_simple_event_target_event,
|
||||
construct_original_page_transition_event, deep_clone_shared_web_storage_store,
|
||||
dispatch_beforeunload_for_runtime_owner, dispatch_pagehide_for_runtime_owner,
|
||||
dispatch_simple_event_target_event, dispatch_unload_for_runtime_owner,
|
||||
finish_cross_document_navigation_for_window,
|
||||
history_entry_seed_for_cross_document_location, initialize_simple_event_target,
|
||||
install_navigation_bootstrap_entry_for_holder, install_simple_window_event_handlers,
|
||||
@@ -424,6 +426,7 @@ struct LightweightPopupDocumentRecord {
|
||||
pending_load_event: Option<LightweightPopupNavigationTaskToken>,
|
||||
queued_load_event: Option<LightweightPopupNavigationTaskToken>,
|
||||
load_event_dispatched: bool,
|
||||
unload_events_dispatched: bool,
|
||||
// Location replacement remains in effect while load callbacks run, and
|
||||
// document.open() does not make a previously loaded Document incomplete.
|
||||
completely_loaded: bool,
|
||||
@@ -1087,6 +1090,7 @@ impl PageScriptHost {
|
||||
pending_load_event: None,
|
||||
queued_load_event: None,
|
||||
load_event_dispatched: false,
|
||||
unload_events_dispatched: false,
|
||||
completely_loaded: true,
|
||||
},
|
||||
session_storage_store,
|
||||
@@ -2047,6 +2051,13 @@ impl PageScriptHost {
|
||||
.unwrap_or_else(|| target_url.clone());
|
||||
let document_referrer = navigation_state.policy_container.document_referrer.clone();
|
||||
if moli_url::is_about_blank(&target_url) {
|
||||
if matches!(history, PendingLightweightPopupHistory::Traversal(_)) {
|
||||
finish_cross_document_navigation_for_window(scope, window, target_url.as_str());
|
||||
self.dispatch_lightweight_popup_document_unload(scope, popup_id);
|
||||
if !self.lightweight_popup_navigation_attempt_is_current(navigation_task) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
navigation_state.reset_for_empty_document(target_url.clone());
|
||||
if !self.commit_lightweight_popup_document(
|
||||
scope,
|
||||
@@ -2271,6 +2282,7 @@ impl PageScriptHost {
|
||||
pending_load_event: None,
|
||||
queued_load_event: None,
|
||||
load_event_dispatched: false,
|
||||
unload_events_dispatched: false,
|
||||
completely_loaded: false,
|
||||
},
|
||||
);
|
||||
@@ -2874,6 +2886,20 @@ impl PageScriptHost {
|
||||
return PopupDocumentLoadApplication::Applied { body_activity };
|
||||
}
|
||||
Ok(PopupDocumentLoadOutcome::Loaded(loaded)) => {
|
||||
if matches!(
|
||||
pending.history,
|
||||
PendingLightweightPopupHistory::Traversal(_)
|
||||
) {
|
||||
finish_cross_document_navigation_for_window(
|
||||
scope,
|
||||
window,
|
||||
pending.target_url.as_str(),
|
||||
);
|
||||
self.dispatch_lightweight_popup_document_unload(scope, popup_id);
|
||||
if !self.lightweight_popup_navigation_attempt_is_current(task) {
|
||||
return PopupDocumentLoadApplication::NotApplied;
|
||||
}
|
||||
}
|
||||
let mut loaded = *loaded;
|
||||
let opener_sandbox = self
|
||||
.lightweight_popup_record(popup_id)
|
||||
@@ -3282,6 +3308,30 @@ impl PageScriptHost {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn dispatch_lightweight_popup_document_unload(
|
||||
&mut self,
|
||||
scope: &mut v8::PinScope<'_, '_>,
|
||||
popup_id: u64,
|
||||
) {
|
||||
let Some(document) = self.lightweight_popup_document_record_mut(popup_id) else {
|
||||
return;
|
||||
};
|
||||
if document.unload_events_dispatched {
|
||||
return;
|
||||
}
|
||||
// Mark before entering author callbacks: pagehide can call close(),
|
||||
// whose queued destruction must not unload this Document a second time.
|
||||
document.unload_events_dispatched = true;
|
||||
let owner = document.owner;
|
||||
let Some(window) = self.lightweight_popup_window(scope, popup_id) else {
|
||||
return;
|
||||
};
|
||||
dispatch_pagehide_for_runtime_owner(scope, window);
|
||||
if self.lightweight_popup_document_owner_is_current(owner) {
|
||||
dispatch_unload_for_runtime_owner(scope, window);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn dispatch_lightweight_popup_load_event(
|
||||
&mut self,
|
||||
scope: &mut v8::PinScope<'_, '_>,
|
||||
@@ -3290,9 +3340,22 @@ impl PageScriptHost {
|
||||
let window = self
|
||||
.lightweight_popup_window(scope, popup_id)
|
||||
.expect("authorized popup load event must retain its WindowProxy");
|
||||
let document_owner = self.current_lightweight_popup_document_owner(popup_id);
|
||||
let event = lightweight_popup_event(scope, window, "load")
|
||||
.expect("authorized popup load event must materialize its Event");
|
||||
self.dispatch_lightweight_popup_window_event(scope, popup_id, "load", event);
|
||||
if !self.lightweight_popup_is_open(popup_id)
|
||||
|| self.current_lightweight_popup_document_owner(popup_id) != document_owner
|
||||
{
|
||||
return;
|
||||
}
|
||||
let context = window
|
||||
.get_creation_context(scope)
|
||||
.unwrap_or_else(|| scope.get_current_context());
|
||||
let scope = &mut v8::ContextScope::new(scope, context);
|
||||
if let Some(event) = construct_original_page_transition_event(scope, "pageshow", false) {
|
||||
self.dispatch_lightweight_popup_window_event(scope, popup_id, "pageshow", event);
|
||||
}
|
||||
}
|
||||
|
||||
fn install_lightweight_popup_document_projection<'s>(
|
||||
@@ -4933,6 +4996,7 @@ fn lightweight_popup_close_callback<'s>(
|
||||
if !host.begin_lightweight_popup_close(popup_id) {
|
||||
return;
|
||||
}
|
||||
dispatch_beforeunload_for_runtime_owner(scope, window);
|
||||
set_object_slot(
|
||||
scope,
|
||||
window,
|
||||
|
||||
@@ -62,7 +62,7 @@ pub(crate) struct PendingHistoryTraversal {
|
||||
pub(crate) results: Vec<PendingNavigationResult>,
|
||||
}
|
||||
|
||||
pub(crate) struct PendingChildCrossDocumentTraversal {
|
||||
pub(crate) struct PendingCrossDocumentTraversal {
|
||||
pub(crate) target: WindowTaskTarget,
|
||||
pub(crate) target_index: u32,
|
||||
pub(crate) target_key: Option<String>,
|
||||
@@ -73,7 +73,7 @@ pub(crate) struct PendingChildCrossDocumentTraversal {
|
||||
|
||||
pub(crate) enum PendingHistoryTraversalAction {
|
||||
SameDocument(PendingHistoryTraversal),
|
||||
ChildCrossDocument(Box<PendingChildCrossDocumentTraversal>),
|
||||
CrossDocument(Box<PendingCrossDocumentTraversal>),
|
||||
}
|
||||
|
||||
pub(crate) struct QueuedHistoryTraversalTask {
|
||||
@@ -117,7 +117,7 @@ impl HistoryQueueState {
|
||||
Some(pending.target_index)
|
||||
}
|
||||
PendingHistoryTraversalAction::SameDocument(_)
|
||||
| PendingHistoryTraversalAction::ChildCrossDocument(_) => None,
|
||||
| PendingHistoryTraversalAction::CrossDocument(_) => None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ impl HistoryQueueState {
|
||||
Some(pending)
|
||||
}
|
||||
PendingHistoryTraversalAction::SameDocument(_)
|
||||
| PendingHistoryTraversalAction::ChildCrossDocument(_) => None,
|
||||
| PendingHistoryTraversalAction::CrossDocument(_) => None,
|
||||
})
|
||||
{
|
||||
if let Some(result) = result {
|
||||
@@ -180,11 +180,11 @@ impl HistoryQueueState {
|
||||
Some(task_id)
|
||||
}
|
||||
|
||||
fn queue_child_cross_document_traversal(
|
||||
fn queue_cross_document_history_traversal(
|
||||
&mut self,
|
||||
execution_context: WindowExecutionContextIdentity,
|
||||
relevant_context: WindowExecutionContextBinding,
|
||||
traversal: PendingChildCrossDocumentTraversal,
|
||||
traversal: PendingCrossDocumentTraversal,
|
||||
) -> RendererPageHistoryTraversalTaskId {
|
||||
let task_id = self.next_history_traversal_task_id;
|
||||
self.next_history_traversal_task_id = task_id
|
||||
@@ -195,7 +195,7 @@ impl HistoryQueueState {
|
||||
task_id,
|
||||
execution_context,
|
||||
relevant_context,
|
||||
action: PendingHistoryTraversalAction::ChildCrossDocument(Box::new(traversal)),
|
||||
action: PendingHistoryTraversalAction::CrossDocument(Box::new(traversal)),
|
||||
});
|
||||
task_id
|
||||
}
|
||||
@@ -398,7 +398,7 @@ impl PageScriptHost {
|
||||
.find_map(|queued| {
|
||||
let step = match &queued.action {
|
||||
PendingHistoryTraversalAction::SameDocument(pending) => pending.joint_step,
|
||||
PendingHistoryTraversalAction::ChildCrossDocument(pending) => {
|
||||
PendingHistoryTraversalAction::CrossDocument(pending) => {
|
||||
pending.seed.session_history.target_step
|
||||
}
|
||||
}?;
|
||||
@@ -541,7 +541,7 @@ impl PageScriptHost {
|
||||
pending.results.first()
|
||||
}
|
||||
PendingHistoryTraversalAction::SameDocument(_)
|
||||
| PendingHistoryTraversalAction::ChildCrossDocument(_) => None,
|
||||
| PendingHistoryTraversalAction::CrossDocument(_) => None,
|
||||
})
|
||||
{
|
||||
// Repeated requests share the original tracker, including its
|
||||
@@ -591,7 +591,7 @@ impl PageScriptHost {
|
||||
Some((result, producer))
|
||||
}
|
||||
|
||||
pub(crate) fn queue_child_cross_document_traversal<'s>(
|
||||
pub(crate) fn queue_cross_document_history_traversal<'s>(
|
||||
&mut self,
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
target: WindowTaskTarget,
|
||||
@@ -602,10 +602,10 @@ impl PageScriptHost {
|
||||
let execution_context = self.current_runtime_window_execution_context_identity(scope)?;
|
||||
let relevant_context = self.current_runtime_window_execution_context_binding(scope)?;
|
||||
let sender = self.page_history_traversal_sender();
|
||||
let task_id = self.history_queue.queue_child_cross_document_traversal(
|
||||
let task_id = self.history_queue.queue_cross_document_history_traversal(
|
||||
execution_context,
|
||||
relevant_context,
|
||||
PendingChildCrossDocumentTraversal {
|
||||
PendingCrossDocumentTraversal {
|
||||
target,
|
||||
target_index,
|
||||
target_key,
|
||||
@@ -618,12 +618,12 @@ impl PageScriptHost {
|
||||
execution_context,
|
||||
target,
|
||||
task_id,
|
||||
RendererPageHistoryTraversalTaskKind::ChildCrossDocument,
|
||||
RendererPageHistoryTraversalTaskKind::CrossDocument,
|
||||
))
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn queue_child_cross_document_traversal_with_result<'s>(
|
||||
pub(crate) fn queue_cross_document_history_traversal_with_result<'s>(
|
||||
&mut self,
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
target: WindowTaskTarget,
|
||||
@@ -644,10 +644,10 @@ impl PageScriptHost {
|
||||
let execution_context = self.current_runtime_window_execution_context_identity(scope)?;
|
||||
let relevant_context = self.current_runtime_window_execution_context_binding(scope)?;
|
||||
let sender = self.page_history_traversal_sender();
|
||||
let task_id = self.history_queue.queue_child_cross_document_traversal(
|
||||
let task_id = self.history_queue.queue_cross_document_history_traversal(
|
||||
execution_context,
|
||||
relevant_context,
|
||||
PendingChildCrossDocumentTraversal {
|
||||
PendingCrossDocumentTraversal {
|
||||
target,
|
||||
target_index,
|
||||
target_key,
|
||||
@@ -665,7 +665,7 @@ impl PageScriptHost {
|
||||
execution_context,
|
||||
target,
|
||||
task_id,
|
||||
RendererPageHistoryTraversalTaskKind::ChildCrossDocument,
|
||||
RendererPageHistoryTraversalTaskKind::CrossDocument,
|
||||
),
|
||||
))
|
||||
}
|
||||
@@ -687,9 +687,9 @@ impl PageScriptHost {
|
||||
pending.target,
|
||||
RendererPageHistoryTraversalTaskKind::SameDocument,
|
||||
),
|
||||
PendingHistoryTraversalAction::ChildCrossDocument(pending) => (
|
||||
PendingHistoryTraversalAction::CrossDocument(pending) => (
|
||||
pending.target,
|
||||
RendererPageHistoryTraversalTaskKind::ChildCrossDocument,
|
||||
RendererPageHistoryTraversalTaskKind::CrossDocument,
|
||||
),
|
||||
};
|
||||
if self.current_window_execution_context_owner(target.dispatch_scope())
|
||||
@@ -713,9 +713,9 @@ impl PageScriptHost {
|
||||
pending.target,
|
||||
RendererPageHistoryTraversalTaskKind::SameDocument,
|
||||
),
|
||||
PendingHistoryTraversalAction::ChildCrossDocument(pending) => (
|
||||
PendingHistoryTraversalAction::CrossDocument(pending) => (
|
||||
pending.target,
|
||||
RendererPageHistoryTraversalTaskKind::ChildCrossDocument,
|
||||
RendererPageHistoryTraversalTaskKind::CrossDocument,
|
||||
),
|
||||
};
|
||||
if queued.execution_context != execution_context
|
||||
|
||||
@@ -40,8 +40,9 @@ use super::{
|
||||
|
||||
use bindings::NativeBridgeBindings;
|
||||
pub(crate) use history_queue::{
|
||||
NavigationAttemptId, PendingHistoryTraversal, PendingHistoryTraversalAction,
|
||||
PendingNavigationApiTaskAction, PendingNavigationFinishedResult, PendingNavigationResult,
|
||||
NavigationAttemptId, PendingCrossDocumentTraversal, PendingHistoryTraversal,
|
||||
PendingHistoryTraversalAction, PendingNavigationApiTaskAction, PendingNavigationFinishedResult,
|
||||
PendingNavigationResult,
|
||||
};
|
||||
use identity::{BridgeHandle, BridgeIdentityStore, DomTokenListKind, ReflectorId};
|
||||
use identity::{CollectionKind, LiveCollectionDescriptor, LiveCollectionQueryKind};
|
||||
|
||||
@@ -40,7 +40,7 @@ impl RendererPageHistoryTraversalTaskId {
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub(crate) enum RendererPageHistoryTraversalTaskKind {
|
||||
SameDocument,
|
||||
ChildCrossDocument,
|
||||
CrossDocument,
|
||||
}
|
||||
|
||||
/// Exact authority captured when a history traversal becomes pending.
|
||||
|
||||
@@ -1072,7 +1072,7 @@ impl HistoryTraversalLane {
|
||||
sequence: u64,
|
||||
) -> bool {
|
||||
let kind = if sequence.is_multiple_of(2) {
|
||||
RendererPageHistoryTraversalTaskKind::ChildCrossDocument
|
||||
RendererPageHistoryTraversalTaskKind::CrossDocument
|
||||
} else {
|
||||
RendererPageHistoryTraversalTaskKind::SameDocument
|
||||
};
|
||||
@@ -1911,7 +1911,7 @@ fn navigation_and_traversal_source_preserves_cross_kind_fifo_and_one_readiness_e
|
||||
execution_context,
|
||||
target,
|
||||
RendererPageHistoryTraversalTaskId::from_raw(3),
|
||||
RendererPageHistoryTraversalTaskKind::ChildCrossDocument,
|
||||
RendererPageHistoryTraversalTaskKind::CrossDocument,
|
||||
)
|
||||
.send()
|
||||
.expect("second traversal should enqueue third");
|
||||
|
||||
@@ -46,6 +46,8 @@ impl ScriptVm {
|
||||
binding.with_current_scope(scope, host_ptr, |scope, _| {
|
||||
let window = v8::Local::new(scope, &window);
|
||||
inform_about_canceled_navigation_for_window(scope, window);
|
||||
unsafe { &mut *host_ptr }
|
||||
.dispatch_lightweight_popup_document_unload(scope, popup_id);
|
||||
});
|
||||
}
|
||||
assert!(
|
||||
|
||||
Reference in New Issue
Block a user