Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

refactor(cdp): freeze navigation command owners

ldm0fa122fd517d5
diff --git a/moli-protocol/src/conn.rs b/moli-protocol/src/conn.rs
index 140f21a6d..0fdc60d4c 100644
--- a/moli-protocol/src/conn.rs
+++ b/moli-protocol/src/conn.rs
@@ -1775,13 +1775,14 @@ impl CdpConnection {
.is_ok_and(TargetRuntimeSlot::renderer_document_navigation_is_suspended)
}
- pub(crate) fn accepts_pending_document_navigation_for_session_owner(
+ pub(crate) fn accepts_pending_document_navigation_for_route(
&self,
session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
token: &DocumentNavigationToken,
) -> bool {
let Some((browser_context_id, target_id)) =
- self.target_owner_identity_for_session(session_id)
+ self.target_owner_identity_for_route(session_id, owner_route)
else {
return false;
};
@@ -1817,7 +1818,15 @@ impl CdpConnection {
&self,
session_id: Option<&str>,
) -> Option<String> {
- self.runtime_session_owner_slot(session_id)
+ self.current_document_loader_id_for_route(session_id, None)
+ }
+
+ pub(crate) fn current_document_loader_id_for_route(
+ &self,
+ session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
+ ) -> Option<String> {
+ self.runtime_session_owner_slot_for_route(session_id, owner_route)
.ok()
.and_then(|slot| slot.current_document_loader_id().map(str::to_owned))
}
@@ -1948,7 +1957,17 @@ impl CdpConnection {
session_id: Option<&str>,
loader_id: String,
) -> Option<DocumentNavigationToken> {
- let (browser_context_id, target_id) = self.target_owner_identity_for_session(session_id)?;
+ self.start_document_navigation_for_route(session_id, None, loader_id)
+ }
+
+ pub(crate) fn start_document_navigation_for_route(
+ &mut self,
+ session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
+ loader_id: String,
+ ) -> Option<DocumentNavigationToken> {
+ let (browser_context_id, target_id) =
+ self.target_owner_identity_for_route(session_id, owner_route)?;
let target_id = target_id?;
self.browser_context_by_id_mut(&browser_context_id)?
.start_document_navigation_for_target(&target_id, loader_id)
@@ -2288,10 +2307,7 @@ impl CdpConnection {
let route = self
.target_session_route_for_target_id(target_id.as_str())
.or_else(|| self.target_session_route_for_child_frame_id(target_id.as_str()))?;
- return Some(CommandOwnerScope::from_session_and_owner_route(
- None,
- Some(route),
- ));
+ return Some(CommandOwnerScope::for_implicit_route(Some(route)));
}
Some(CommandOwnerScope::capture(
self,
@@ -2384,13 +2400,14 @@ impl CdpConnection {
})
}
- pub(crate) fn accepts_document_body_completion_for_session_owner(
+ pub(crate) fn accepts_document_body_completion_for_route(
&self,
session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
token: &DocumentNavigationToken,
) -> bool {
let Some((browser_context_id, target_id)) =
- self.target_owner_identity_for_session(session_id)
+ self.target_owner_identity_for_route(session_id, owner_route)
else {
return false;
};
@@ -2485,21 +2502,35 @@ impl CdpConnection {
) -> Option<
tokio::sync::mpsc::UnboundedSender<crate::domains::page::BackgroundNavigationCompletion>,
> {
- if !self.can_run_background_navigation_for_session_owner(session_id) {
+ self.background_navigation_completion_sender_for_route(session_id, None)
+ }
+
+ pub(crate) fn background_navigation_completion_sender_for_route(
+ &self,
+ session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
+ ) -> Option<
+ tokio::sync::mpsc::UnboundedSender<crate::domains::page::BackgroundNavigationCompletion>,
+ > {
+ if !self.can_run_background_navigation_for_route(session_id, owner_route) {
return None;
}
self.scheduler_hooks
.background_navigation_completion_sender()
}
- fn can_run_background_navigation_for_session_owner(&self, session_id: Option<&str>) -> bool {
+ fn can_run_background_navigation_for_route(
+ &self,
+ session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
+ ) -> bool {
if !self
.scheduler_hooks
.has_background_navigation_completion_sender()
{
return false;
}
- self.target_owner_identity_for_session(session_id)
+ self.target_owner_identity_for_route(session_id, owner_route)
.is_some_and(|(_, target_id)| target_id.is_some())
}
@@ -2561,25 +2592,10 @@ impl CdpConnection {
completion
}
crate::domains::page::BackgroundNavigationCompletion::MainDocumentBody(completion) => {
- let previous_none_session_owner_route =
- completion.navigate_session_id().is_none().then(|| {
- self.replace_none_session_owner_route_override(
- completion.none_session_owner_route(),
- )
- });
completion.record_if_current(self);
- if let Some(previous) = previous_none_session_owner_route {
- self.replace_none_session_owner_route_override(previous);
- }
return command_context.take_protocol_events();
}
};
- let previous_none_session_owner_route =
- completion.navigate_session_id().is_none().then(|| {
- self.replace_none_session_owner_route_override(
- completion.none_session_owner_route(),
- )
- });
let timing_started = moli_trace::cdp_nav_timing_enabled().then(std::time::Instant::now);
if timing_started.is_some() {
tracing::info!(
@@ -2606,9 +2622,6 @@ impl CdpConnection {
let protocol_events = self
.drain_materialized_navigation_completion_background_events(completion, command_context)
.await;
- if let Some(previous) = previous_none_session_owner_route {
- self.replace_none_session_owner_route_override(previous);
- }
protocol_events
}
@@ -2968,7 +2981,7 @@ impl CdpConnection {
crate::domains::page::push_superseded_navigation_result(out, &state);
return;
}
- let navigation_session_id = state.navigate_session_id.clone();
+ let navigation_session_id = state.owner.session_id().map(str::to_owned);
crate::domains::page::complete_materialized_navigation_into_buffer_async(
self,
out,
diff --git a/moli-protocol/src/conn/activity_source.rs b/moli-protocol/src/conn/activity_source.rs
index 9f951bccf..b3d1f28d6 100644
--- a/moli-protocol/src/conn/activity_source.rs
+++ b/moli-protocol/src/conn/activity_source.rs
@@ -4,15 +4,15 @@ use moli_core::{
};
use std::time::Instant;
-use super::{CdpConnection, CdpSessionRoute, TargetRuntimeSlot};
+use super::{CdpConnection, CdpSessionRoute, CommandOwnerScope, TargetRuntimeSlot};
pub(crate) struct PendingChildFrameLifecycleWork {
- session_id: Option<String>,
+ owner: CommandOwnerScope,
pending: PendingPageCommand,
}
pub(crate) struct CompletedChildFrameLifecycleWork {
- session_id: Option<String>,
+ owner: CommandOwnerScope,
completion: CompletedPageCommand,
}
@@ -24,7 +24,7 @@ impl PendingChildFrameLifecycleWork {
.await
.map_err(|error| error.to_string())?;
Ok(CompletedChildFrameLifecycleWork {
- session_id: self.session_id,
+ owner: self.owner,
completion,
})
}
@@ -34,12 +34,18 @@ impl CdpConnection {
fn activity_source_engine_and_runtime_slot_mut(
&mut self,
session_id: Option<&str>,
+ ) -> Option<(&mut NavigationEngine, &mut TargetRuntimeSlot)> {
+ self.activity_source_engine_and_runtime_slot_mut_for_route(session_id, None)
+ }
+
+ fn activity_source_engine_and_runtime_slot_mut_for_route(
+ &mut self,
+ session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
) -> Option<(&mut NavigationEngine, &mut TargetRuntimeSlot)> {
let route = match session_id {
Some(_) => self.session_route(session_id)?,
- None => self
- .none_session_owner_route_override()
- .unwrap_or(CdpSessionRoute::Browser),
+ None => owner_route.cloned().unwrap_or(CdpSessionRoute::Browser),
};
let (browser_context_id, target_id) = match &route {
CdpSessionRoute::PageTarget {
@@ -68,15 +74,35 @@ impl CdpConnection {
.navigation_engine_and_runtime_slot_mut()
}
+ fn activity_source_engine_and_runtime_slot_mut_for_owner(
+ &mut self,
+ owner: &CommandOwnerScope,
+ ) -> Option<(&mut NavigationEngine, &mut TargetRuntimeSlot)> {
+ self.activity_source_engine_and_runtime_slot_mut_for_route(
+ owner.session_id(),
+ owner.session_owner_route(),
+ )
+ }
+
pub(crate) fn start_child_frame_lifecycle_work_for_session_owner(
&mut self,
session_id: Option<&str>,
timeout: std::time::Duration,
+ ) -> Result<PendingChildFrameLifecycleWork, String> {
+ let owner = CommandOwnerScope::capture(self, session_id);
+ self.start_child_frame_lifecycle_work_for_owner(owner, timeout)
+ }
+
+ pub(crate) fn start_child_frame_lifecycle_work_for_owner(
+ &mut self,
+ owner: CommandOwnerScope,
+ timeout: std::time::Duration,
) -> Result<PendingChildFrameLifecycleWork, String> {
let storage = self
- .navigation_load_inputs_for_session_owner(session_id)
+ .navigation_load_inputs_for_route(owner.session_id(), owner.session_owner_route())
.resource_storage_handles();
- let Some((engine, slot)) = self.activity_source_engine_and_runtime_slot_mut(session_id)
+ let Some((engine, slot)) =
+ self.activity_source_engine_and_runtime_slot_mut_for_owner(&owner)
else {
return Err("NoDocumentLoaded".to_owned());
};
@@ -90,18 +116,15 @@ impl CdpConnection {
timeout,
)
.map_err(|error| error.to_string())?;
- Ok(PendingChildFrameLifecycleWork {
- session_id: session_id.map(str::to_owned),
- pending,
- })
+ Ok(PendingChildFrameLifecycleWork { owner, pending })
}
pub(crate) fn complete_child_frame_lifecycle_work_command_turn_for_session_owner(
&mut self,
pending: CompletedChildFrameLifecycleWork,
) -> Result<(bool, moli_core::page::RendererCommandTurnOutput), String> {
- let session_id = pending.session_id.as_deref();
- let Some((engine, slot)) = self.activity_source_engine_and_runtime_slot_mut(session_id)
+ let Some((engine, slot)) =
+ self.activity_source_engine_and_runtime_slot_mut_for_owner(&pending.owner)
else {
return Err("NoDocumentLoaded".to_owned());
};
diff --git a/moli-protocol/src/conn/browser_context/page_owner.rs b/moli-protocol/src/conn/browser_context/page_owner.rs
index 2c1153637..1cb68abfe 100644
--- a/moli-protocol/src/conn/browser_context/page_owner.rs
+++ b/moli-protocol/src/conn/browser_context/page_owner.rs
@@ -582,9 +582,10 @@ impl CdpConnection {
})
}
- pub(crate) fn record_main_document_resource_body_for_session_owner(
+ pub(crate) fn record_main_document_resource_body_for_route(
&mut self,
session_id: Option<&str>,
+ owner_route: Option<&crate::conn::CdpSessionRoute>,
frame_id: String,
loader_id: String,
url: url::Url,
@@ -592,7 +593,7 @@ impl CdpConnection {
from_cache: bool,
body: crate::conn::CapturedBody,
) -> bool {
- self.with_target_owner_state_for_session_mut(session_id, |owner_state| {
+ self.with_target_owner_state_for_route_mut(session_id, owner_route, |owner_state| {
owner_state.page_resource_store.record_main_document_body(
frame_id,
loader_id,
diff --git a/moli-protocol/src/conn/browser_context/target_session_owner.rs b/moli-protocol/src/conn/browser_context/target_session_owner.rs
index 4a989ae03..4cf72fcec 100644
--- a/moli-protocol/src/conn/browser_context/target_session_owner.rs
+++ b/moli-protocol/src/conn/browser_context/target_session_owner.rs
@@ -1349,11 +1349,12 @@ impl CdpConnection {
inputs
}
- pub(crate) fn navigation_initiator_url_for_session_owner(
+ pub(crate) fn navigation_initiator_url_for_route(
&self,
session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
) -> Option<Url> {
- self.target_session_owner_ref(session_id)
+ self.target_session_owner_ref_for_route(session_id, owner_route)
.and_then(|owner| owner.navigation_initiator_url())
}
@@ -1363,6 +1364,23 @@ impl CdpConnection {
requested_url: &Url,
referrer: Option<&str>,
is_data_url: bool,
+ ) -> Option<TargetNavigationRequestPreflight> {
+ self.prepare_navigation_request_for_route(
+ session_id,
+ None,
+ requested_url,
+ referrer,
+ is_data_url,
+ )
+ }
+
+ pub(crate) fn prepare_navigation_request_for_route(
+ &mut self,
+ session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
+ requested_url: &Url,
+ referrer: Option<&str>,
+ is_data_url: bool,
) -> Option<TargetNavigationRequestPreflight> {
let fallback_browser_identity = self
.global_browser_identity_override
@@ -1371,7 +1389,7 @@ impl CdpConnection {
let mut network_request_id_allocator =
std::mem::take(&mut self.network_request_id_allocator);
let result = self
- .target_session_owner_mut(session_id)
+ .target_session_owner_mut_for_route(session_id, owner_route)
.and_then(|mut owner| {
owner.prepare_navigation_request(
requested_url,
@@ -1390,7 +1408,16 @@ impl CdpConnection {
session_id: Option<&str>,
pending: PendingFetchNavigation,
) -> Option<()> {
- self.target_session_owner_mut(session_id)?
+ self.register_pending_fetch_navigation_request_for_route(session_id, None, pending)
+ }
+
+ pub(crate) fn register_pending_fetch_navigation_request_for_route(
+ &mut self,
+ session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
+ pending: PendingFetchNavigation,
+ ) -> Option<()> {
+ self.target_session_owner_mut_for_route(session_id, owner_route)?
.register_pending_fetch_navigation_request(pending)
}
@@ -1800,7 +1827,15 @@ impl CdpConnection {
&self,
session_id: Option<&str>,
) -> Option<&TargetOwnerState> {
- self.target_session_owner_ref(session_id)?
+ self.target_owner_state_for_route(session_id, None)
+ }
+
+ pub(crate) fn target_owner_state_for_route(
+ &self,
+ session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
+ ) -> Option<&TargetOwnerState> {
+ self.target_session_owner_ref_for_route(session_id, owner_route)?
.target_owner_state()
}
@@ -1971,22 +2006,21 @@ impl CdpConnection {
))
}
- /// Binds a renderer Page reservation to its explicit future target Page
- /// attachment and returns that exact residence identity.
- pub(crate) fn reserve_target_page_residence_identity_for_session(
+ pub(crate) fn reserve_target_page_residence_identity_for_route(
&mut self,
session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
renderer_page: crate::conn::RendererPageResidenceIdentity,
) -> Option<TargetPageResidenceIdentity> {
let (browser_context_id, routed_target_id) =
- self.target_owner_identity_for_session(session_id)?;
+ self.target_owner_identity_for_route(session_id, owner_route)?;
let target_id = routed_target_id.or_else(|| {
self.browser_context_by_id(&browser_context_id)
.and_then(|browser_context| browser_context.active_target_id())
.map(str::to_owned)
});
let page_attachment_id = self
- .runtime_session_owner_slot_mut(session_id)
+ .runtime_session_owner_slot_mut_for_route(session_id, owner_route)
.ok()?
.reserve_renderer_page_attachment(renderer_page);
Some(TargetPageResidenceIdentity::new(
@@ -2000,12 +2034,13 @@ impl CdpConnection {
/// Page-slot residence from which it was captured.
pub(crate) fn target_page_residence_identity_is_current_for_session(
&self,
- session_id: Option<&str>,
+ _session_id: Option<&str>,
expected: &TargetPageResidenceIdentity,
) -> bool {
- self.target_page_residence_identity_for_session(session_id)
- .as_ref()
- == Some(expected)
+ self.browser_context_by_id(expected.browser_context_id())
+ .is_some_and(|browser_context| {
+ browser_context.target_page_residence_is_current(expected)
+ })
}
/// Captures the lifetime of the concrete Page attachment currently
@@ -2028,9 +2063,17 @@ impl CdpConnection {
pub(crate) fn target_page_protocol_attachment_identity_for_session(
&self,
session_id: Option<&str>,
+ ) -> Option<crate::conn::TargetPageProtocolAttachmentIdentity> {
+ self.target_page_protocol_attachment_identity_for_route(session_id, None)
+ }
+
+ pub(crate) fn target_page_protocol_attachment_identity_for_route(
+ &self,
+ session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
) -> Option<crate::conn::TargetPageProtocolAttachmentIdentity> {
Some(crate::conn::TargetPageProtocolAttachmentIdentity::new(
- self.target_page_residence_identity_for_session(session_id)?,
+ self.target_page_residence_identity_for_route(session_id, owner_route)?,
session_id.map(str::to_owned),
))
}
@@ -2105,9 +2148,22 @@ impl CdpConnection {
&self,
session_id: Option<&str>,
root_document: moli_core::RendererDocumentLifecycleIdentity,
+ ) -> Option<crate::conn::TargetRootDocumentProtocolAttachmentIdentity> {
+ self.target_root_document_protocol_attachment_identity_for_route(
+ session_id,
+ None,
+ root_document,
+ )
+ }
+
+ pub(crate) fn target_root_document_protocol_attachment_identity_for_route(
+ &self,
+ session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
+ root_document: moli_core::RendererDocumentLifecycleIdentity,
) -> Option<crate::conn::TargetRootDocumentProtocolAttachmentIdentity> {
let binding = crate::conn::TargetRootDocumentProtocolAttachmentIdentity::new(
- self.target_page_protocol_attachment_identity_for_session(session_id)?,
+ self.target_page_protocol_attachment_identity_for_route(session_id, owner_route)?,
root_document,
);
self.target_root_document_protocol_attachment_identity_is_current(&binding)
@@ -2134,7 +2190,15 @@ impl CdpConnection {
&self,
session_id: Option<&str>,
) -> Option<moli_core::RendererDocumentLifecycleIdentity> {
- self.runtime_session_owner_slot(session_id)
+ self.target_root_document_lifecycle_identity_for_route(session_id, None)
+ }
+
+ pub(crate) fn target_root_document_lifecycle_identity_for_route(
+ &self,
+ session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
+ ) -> Option<moli_core::RendererDocumentLifecycleIdentity> {
+ self.runtime_session_owner_slot_for_route(session_id, owner_route)
.ok()?
.page_slot()
.renderer_document_lifecycle_binding()
@@ -2322,7 +2386,15 @@ impl CdpConnection {
&self,
session_id: Option<&str>,
) -> Vec<Option<String>> {
- self.page_event_session_ids_for_session_owner(session_id)
+ self.subscribed_page_event_session_ids_for_route(session_id, None)
+ }
+
+ pub(crate) fn subscribed_page_event_session_ids_for_route(
+ &self,
+ session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
+ ) -> Vec<Option<String>> {
+ self.page_event_session_ids_for_route(session_id, owner_route)
.into_iter()
.filter(|event_session_id| {
self.target_page_session_state_for_session(event_session_id.as_deref())
@@ -2495,7 +2567,15 @@ impl CdpConnection {
&mut self,
session_id: Option<&str>,
) -> Option<(usize, Vec<PageNavigationHistoryEntry>)> {
- self.target_session_owner_mut(session_id)?
+ self.target_session_owner_navigation_history_snapshot_for_route(session_id, None)
+ }
+
+ pub(crate) fn target_session_owner_navigation_history_snapshot_for_route(
+ &mut self,
+ session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
+ ) -> Option<(usize, Vec<PageNavigationHistoryEntry>)> {
+ self.target_session_owner_mut_for_route(session_id, owner_route)?
.navigation_history_snapshot()
}
@@ -2521,11 +2601,12 @@ impl CdpConnection {
.navigation_history_entry_url(entry_id)
}
- pub(crate) fn reset_navigation_history_for_session_owner(
+ pub(crate) fn reset_navigation_history_for_route(
&mut self,
session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
) -> Option<bool> {
- self.target_session_owner_mut(session_id)?
+ self.target_session_owner_mut_for_route(session_id, owner_route)?
.reset_navigation_history()
}
@@ -2537,20 +2618,22 @@ impl CdpConnection {
.can_reset_navigation_history()
}
- pub(crate) fn mark_next_navigation_history_replace_current_for_session_owner(
+ pub(crate) fn mark_next_navigation_history_replace_current_for_route(
&mut self,
session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
) -> Option<()> {
- self.target_session_owner_mut(session_id)?
+ self.target_session_owner_mut_for_route(session_id, owner_route)?
.mark_next_navigation_history_replace_current()
}
- pub(crate) fn mark_next_navigation_history_traverse_to_entry_for_session_owner(
+ pub(crate) fn mark_next_navigation_history_traverse_to_entry_for_route(
&mut self,
session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
entry_id: i32,
) -> Option<()> {
- self.target_session_owner_mut(session_id)?
+ self.target_session_owner_mut_for_route(session_id, owner_route)?
.mark_next_navigation_history_traverse_to_entry(entry_id)
}
diff --git a/moli-protocol/src/conn/command_owner_scope.rs b/moli-protocol/src/conn/command_owner_scope.rs
index e99cacbb6..a0aaa1df0 100644
--- a/moli-protocol/src/conn/command_owner_scope.rs
+++ b/moli-protocol/src/conn/command_owner_scope.rs
@@ -2,8 +2,14 @@ use super::{CdpConnection, CdpSessionRoute, NoneSessionOwnerRouteOverrideScope};
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct CommandOwnerScope {
- session_id: Option<String>,
- session_owner_route: Option<CdpSessionRoute>,
+ identity: CommandOwnerIdentity,
+}
+
+#[derive(Clone, Debug, PartialEq, Eq)]
+enum CommandOwnerIdentity {
+ Session(String),
+ ImplicitRoute(CdpSessionRoute),
+ Implicit,
}
impl CommandOwnerScope {
@@ -22,24 +28,32 @@ impl CommandOwnerScope {
})
})
.flatten();
+ match session_id {
+ Some(session_id) => Self::for_session(session_id),
+ None => Self::for_implicit_route(none_session_owner_route),
+ }
+ }
+
+ pub(crate) fn for_session(session_id: &str) -> Self {
Self {
- session_id: session_id.map(str::to_owned),
- session_owner_route: none_session_owner_route,
+ identity: CommandOwnerIdentity::Session(session_id.to_owned()),
}
}
- pub(crate) fn from_session_and_owner_route(
- session_id: Option<&str>,
- session_owner_route: Option<CdpSessionRoute>,
- ) -> Self {
+ pub(crate) fn for_implicit_route(session_owner_route: Option<CdpSessionRoute>) -> Self {
Self {
- session_id: session_id.map(str::to_owned),
- session_owner_route,
+ identity: match session_owner_route {
+ Some(route) => CommandOwnerIdentity::ImplicitRoute(route),
+ None => CommandOwnerIdentity::Implicit,
+ },
}
}
pub(crate) fn session_id(&self) -> Option<&str> {
- self.session_id.as_deref()
+ match &self.identity {
+ CommandOwnerIdentity::Session(session_id) => Some(session_id),
+ CommandOwnerIdentity::ImplicitRoute(_) | CommandOwnerIdentity::Implicit => None,
+ }
}
/// Returns the exact route captured for an implicit-session command.
@@ -49,14 +63,17 @@ impl CommandOwnerScope {
/// admission, so deferred completion cannot follow a later foreground
/// selection.
pub(crate) fn session_owner_route(&self) -> Option<&CdpSessionRoute> {
- self.session_owner_route.as_ref()
+ match &self.identity {
+ CommandOwnerIdentity::ImplicitRoute(route) => Some(route),
+ CommandOwnerIdentity::Session(_) | CommandOwnerIdentity::Implicit => None,
+ }
}
pub(crate) fn enter<'a>(
&self,
conn: &'a mut CdpConnection,
) -> NoneSessionOwnerRouteOverrideScope<'a> {
- conn.scoped_optional_none_session_owner_route_override(self.session_owner_route.clone())
+ conn.scoped_optional_none_session_owner_route_override(self.session_owner_route().cloned())
}
}
diff --git a/moli-protocol/src/conn/dispatch_tests.rs b/moli-protocol/src/conn/dispatch_tests.rs
index fb5db48f0..3e81f54f8 100644
--- a/moli-protocol/src/conn/dispatch_tests.rs
+++ b/moli-protocol/src/conn/dispatch_tests.rs
@@ -705,7 +705,7 @@ async fn bidi_fetch_control_resolves_background_request_owner() {
document_navigation_token: None,
navigation: NavigationDispatchState {
navigate_id: None,
- navigate_session_id: Some("SID-background".to_owned()),
+ owner: CommandOwnerScope::for_session("SID-background"),
result_projection: NavigationResultProjection::WebDriverBidi(json!({})),
frame_id: "TID-background".to_owned(),
session_id: Some("SID-background".to_owned()),
diff --git a/moli-protocol/src/conn/page_state/fetch_state.rs b/moli-protocol/src/conn/page_state/fetch_state.rs
index 99adc479d..826666729 100644
--- a/moli-protocol/src/conn/page_state/fetch_state.rs
+++ b/moli-protocol/src/conn/page_state/fetch_state.rs
@@ -370,7 +370,7 @@ mod tests {
fn navigation_state(url: &Url) -> NavigationDispatchState {
NavigationDispatchState {
navigate_id: Some(1),
- navigate_session_id: Some("SID-1".to_owned()),
+ owner: crate::conn::CommandOwnerScope::for_session("SID-1"),
result_projection: NavigationResultProjection::Cdp(
json!({"frameId": "TID-1", "loaderId": "LID-0000000001"}),
),
diff --git a/moli-protocol/src/conn/popup_activation_work.rs b/moli-protocol/src/conn/popup_activation_work.rs
index 6961e8e45..2652ab4bc 100644
--- a/moli-protocol/src/conn/popup_activation_work.rs
+++ b/moli-protocol/src/conn/popup_activation_work.rs
@@ -22,14 +22,11 @@ impl PopupTargetActivationAction {
) -> Option<Self> {
let route = conn.target_session_route_for_target_id(target_id)?;
(route.browser_context_id() == Some(browser_context_id)).then(|| Self {
- owner_scope: CommandOwnerScope::from_session_and_owner_route(
- None,
- Some(CdpSessionRoute::PageTarget {
- browser_context_id: browser_context_id.to_owned(),
- target_id: target_id.to_owned(),
- is_attached_session: false,
- }),
- ),
+ owner_scope: CommandOwnerScope::for_implicit_route(Some(CdpSessionRoute::PageTarget {
+ browser_context_id: browser_context_id.to_owned(),
+ target_id: target_id.to_owned(),
+ is_attached_session: false,
+ })),
browser_context_id: browser_context_id.to_owned(),
target_id: target_id.to_owned(),
})
diff --git a/moli-protocol/src/conn/popup_navigation_work.rs b/moli-protocol/src/conn/popup_navigation_work.rs
index 3679d39b6..1ded2b78f 100644
--- a/moli-protocol/src/conn/popup_navigation_work.rs
+++ b/moli-protocol/src/conn/popup_navigation_work.rs
@@ -41,14 +41,11 @@ impl PopupTargetNavigationOwnerAction {
// Activation has an independent owner action. Unlike a frozen
// Stable PageTarget route keeps this exact target addressable if
// the independent activation action changes its residence first.
- owner_scope: CommandOwnerScope::from_session_and_owner_route(
- None,
- Some(CdpSessionRoute::PageTarget {
- browser_context_id: browser_context_id.to_owned(),
- target_id: target_id.to_owned(),
- is_attached_session: false,
- }),
- ),
+ owner_scope: CommandOwnerScope::for_implicit_route(Some(CdpSessionRoute::PageTarget {
+ browser_context_id: browser_context_id.to_owned(),
+ target_id: target_id.to_owned(),
+ is_attached_session: false,
+ })),
browser_context_id: browser_context_id.to_owned(),
target_id: target_id.to_owned(),
url,
diff --git a/moli-protocol/src/conn/runtime_eval.rs b/moli-protocol/src/conn/runtime_eval.rs
index 0ab482900..5c64de354 100644
--- a/moli-protocol/src/conn/runtime_eval.rs
+++ b/moli-protocol/src/conn/runtime_eval.rs
@@ -4216,7 +4216,15 @@ impl CdpConnection {
}
pub(crate) fn ingest_runtime_session_owner_output_updates(&mut self, session_id: Option<&str>) {
- if let Ok(slot) = self.runtime_session_owner_slot_mut(session_id) {
+ self.ingest_runtime_session_owner_output_updates_for_route(session_id, None)
+ }
+
+ pub(crate) fn ingest_runtime_session_owner_output_updates_for_route(
+ &mut self,
+ session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
+ ) {
+ if let Ok(slot) = self.runtime_session_owner_slot_mut_for_route(session_id, owner_route) {
let _ = slot.ingest_owner_page_observable_output_updates();
}
}
@@ -4225,6 +4233,19 @@ impl CdpConnection {
&self,
session_id: Option<&str>,
) -> Option<String> {
+ self.runtime_session_owner_frame_id_for_route(session_id, None)
+ }
+
+ pub(crate) fn runtime_session_owner_frame_id_for_route(
+ &self,
+ session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
+ ) -> Option<String> {
+ if let Some((_, target_id)) = self.target_owner_identity_for_route(session_id, owner_route)
+ && target_id.is_some()
+ {
+ return target_id;
+ }
match session_id {
None => self
.browser_context
diff --git a/moli-protocol/src/conn/runtime_load.rs b/moli-protocol/src/conn/runtime_load.rs
index d4559e6db..2a9606ab6 100644
--- a/moli-protocol/src/conn/runtime_load.rs
+++ b/moli-protocol/src/conn/runtime_load.rs
@@ -736,7 +736,6 @@ pub(crate) struct BackgroundNavigationBodyCompletionSink {
tokio::sync::mpsc::UnboundedSender<crate::domains::page::BackgroundNavigationCompletion>,
token: DocumentNavigationToken,
state: NavigationDispatchState,
- none_session_owner_route: Option<CdpSessionRoute>,
}
impl BackgroundNavigationBodyCompletionSink {
@@ -746,13 +745,11 @@ impl BackgroundNavigationBodyCompletionSink {
>,
token: DocumentNavigationToken,
state: NavigationDispatchState,
- none_session_owner_route: Option<CdpSessionRoute>,
) -> Self {
Self {
sender,
token,
state,
- none_session_owner_route,
}
}
@@ -768,7 +765,6 @@ impl BackgroundNavigationBodyCompletionSink {
crate::domains::page::BackgroundNavigationCompletion::main_document_body(
self.token,
self.state,
- self.none_session_owner_route,
body,
false,
body_progress_source,
@@ -1548,8 +1544,9 @@ impl CdpConnection {
navigation: &NavigationDispatchState,
) -> TargetNavigationLoadInputs {
apply_navigation_request_load_policy(
- self.navigation_load_inputs_for_session_owner(
- navigation.navigate_session_id.as_deref(),
+ self.navigation_load_inputs_for_route(
+ navigation.owner.session_id(),
+ navigation.owner.session_owner_route(),
),
navigation.request_load_policy,
)
@@ -1695,8 +1692,9 @@ impl CdpConnection {
let main_document_commit = load_inputs
.main_document_commit_for_final_url(&final_url, None)
.map(Arc::new);
- let page_reservation = self.reserve_renderer_page_for_session_owner(
- navigation.navigate_session_id.as_deref(),
+ let page_reservation = self.reserve_renderer_page_for_route(
+ navigation.owner.session_id(),
+ navigation.owner.session_owner_route(),
&load_inputs,
&engine,
);
@@ -2286,7 +2284,7 @@ impl CdpConnection {
body_progress_source: MainDocumentBodyProgressSource,
) -> Result<NavigationLoadOutcome, String> {
self.load_navigation_request_via_runtime_with_network_events_and_load_inputs_async(
- navigation.navigate_session_id.as_deref(),
+ navigation.owner.session_id(),
self.navigation_load_inputs_for_navigation(navigation),
&navigation.request_method,
navigation.requested_url.as_str(),
@@ -2422,8 +2420,9 @@ impl CdpConnection {
let shared_resource_runtime =
self.shared_resource_runtime_for_navigation_load_inputs(&load_inputs);
let engine = self.background_navigation_engine_for_load_inputs(&load_inputs);
- let page_reservation = self.reserve_renderer_page_for_session_owner(
- navigation.navigate_session_id.as_deref(),
+ let page_reservation = self.reserve_renderer_page_for_route(
+ navigation.owner.session_id(),
+ navigation.owner.session_owner_route(),
&load_inputs,
&engine,
);
@@ -2472,8 +2471,9 @@ impl CdpConnection {
let shared_resource_runtime =
self.shared_resource_runtime_for_navigation_load_inputs(&load_inputs);
let engine = self.background_navigation_engine_for_load_inputs(&load_inputs);
- let page_reservation = self.reserve_renderer_page_for_session_owner(
- navigation.navigate_session_id.as_deref(),
+ let page_reservation = self.reserve_renderer_page_for_route(
+ navigation.owner.session_id(),
+ navigation.owner.session_owner_route(),
&load_inputs,
&engine,
);
@@ -2505,19 +2505,31 @@ impl CdpConnection {
session_id: Option<&str>,
load_inputs: &TargetNavigationLoadInputs,
engine: &NavigationEngine,
+ ) -> RendererPageReservationToken {
+ self.reserve_renderer_page_for_route(session_id, None, load_inputs, engine)
+ }
+
+ fn reserve_renderer_page_for_route(
+ &mut self,
+ session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
+ load_inputs: &TargetNavigationLoadInputs,
+ engine: &NavigationEngine,
) -> RendererPageReservationToken {
let page_reservation = engine.reserve_page_for_creation();
- self.bind_renderer_page_reservation_for_session_owner(
+ self.bind_renderer_page_reservation_for_route(
session_id,
+ owner_route,
load_inputs,
page_reservation,
);
page_reservation
}
- fn bind_renderer_page_reservation_for_session_owner(
+ fn bind_renderer_page_reservation_for_route(
&mut self,
session_id: Option<&str>,
+ owner_route: Option<&CdpSessionRoute>,
load_inputs: &TargetNavigationLoadInputs,
page_reservation: RendererPageReservationToken,
) {
@@ -2529,7 +2541,7 @@ impl CdpConnection {
// reservation; recording `target_id: None` here would conflict with
// that exact owner when the stream-open control is later consumed.
if let Some((browser_context_id, Some(_target_id))) =
- self.target_owner_identity_for_session(session_id)
+ self.target_owner_identity_for_route(session_id, owner_route)
{
assert_eq!(
load_inputs.browser_context_id.as_deref(),
@@ -2541,7 +2553,11 @@ impl CdpConnection {
page_reservation.page_id(),
);
let page_owner = self
- .reserve_target_page_residence_identity_for_session(session_id, renderer_page)
+ .reserve_target_page_residence_identity_for_route(
+ session_id,
+ owner_route,
+ renderer_page,
+ )
.expect("navigation Page reservation must retain its target owner");
self.bind_renderer_page_output_owner(renderer_page, page_owner);
}
@@ -2896,7 +2912,7 @@ impl CdpConnection {
) -> Result<NavigationLoadOutcome, String> {
let load_inputs = self.navigation_load_inputs_for_navigation(navigation);
self.build_navigation_from_buffered_body_source_with_load_inputs_async(
- navigation.navigate_session_id.as_deref(),
+ navigation.owner.session_id(),
&load_inputs,
navigation.requested_url.clone(),
final_url,
@@ -3407,7 +3423,7 @@ impl CdpConnection {
) -> Result<NavigationLoadOutcome, String> {
let load_inputs = self.navigation_load_inputs_for_navigation(navigation);
self.build_navigation_from_buffered_raw_response_with_load_inputs_async(
- navigation.navigate_session_id.as_deref(),
+ navigation.owner.session_id(),
&load_inputs,
navigation.requested_url.clone(),
navigation.request_method.clone(),
@@ -3465,7 +3481,7 @@ impl CdpConnection {
) -> Result<NavigationLoadOutcome, String> {
let load_inputs = self.navigation_load_inputs_for_navigation(navigation);
self.build_navigation_from_captured_raw_response_with_load_inputs_async(
- navigation.navigate_session_id.as_deref(),
+ navigation.owner.session_id(),
&load_inputs,
navigation.requested_url.clone(),
navigation.request_method.clone(),
@@ -3604,7 +3620,7 @@ impl CdpConnection {
) -> Result<NavigationLoadOutcome, String> {
let load_inputs = self.navigation_load_inputs_for_navigation(navigation);
self.build_navigation_from_streaming_raw_response_with_load_inputs_async(
- navigation.navigate_session_id.as_deref(),
+ navigation.owner.session_id(),
&load_inputs,
navigation.requested_url.clone(),
navigation.request_method.clone(),
@@ -3627,7 +3643,7 @@ impl CdpConnection {
) -> Result<NavigationLoadOutcome, String> {
let load_inputs = self.navigation_load_inputs_for_navigation(navigation);
self.build_navigation_from_streaming_raw_response_with_load_inputs_async(
- navigation.navigate_session_id.as_deref(),
+ navigation.owner.session_id(),
&load_inputs,
navigation.requested_url.clone(),
navigation.request_method.clone(),
diff --git a/moli-protocol/src/conn/state/fetch.rs b/moli-protocol/src/conn/state/fetch.rs
index 039622f0b..5611af758 100644
--- a/moli-protocol/src/conn/state/fetch.rs
+++ b/moli-protocol/src/conn/state/fetch.rs
@@ -2373,7 +2373,9 @@ mod tests {
document_navigation_token: None,
navigation: NavigationDispatchState {
navigate_id: Some(1),
- navigate_session_id: owner_session_id.map(str::to_owned),
+ owner: owner_session_id
+ .map(crate::conn::CommandOwnerScope::for_session)
+ .unwrap_or_else(|| crate::conn::CommandOwnerScope::for_implicit_route(None)),
result_projection: NavigationResultProjection::Cdp(
json!({"frameId": "FRAME-1", "loaderId": "LOADER-1"}),
),
diff --git a/moli-protocol/src/conn/state/navigation_outcome.rs b/moli-protocol/src/conn/state/navigation_outcome.rs
index 2ef79e545..840c4383a 100644
--- a/moli-protocol/src/conn/state/navigation_outcome.rs
+++ b/moli-protocol/src/conn/state/navigation_outcome.rs
@@ -9,7 +9,7 @@ use serde_json::Value;
use std::sync::Arc;
use url::Url;
-use crate::conn::ResponseCommitReady;
+use crate::conn::{CommandOwnerScope, ResponseCommitReady};
use crate::devtools_runtime::DevToolsProtocol;
use crate::domains::network::{
CompletedDocumentProgressTransfer, CompletedDownloadProgressTransfer,
@@ -317,7 +317,7 @@ impl NavigationResultProjection {
#[derive(Debug, Clone)]
pub struct NavigationDispatchState {
pub navigate_id: Option<u64>,
- pub navigate_session_id: Option<String>,
+ pub(crate) owner: CommandOwnerScope,
pub(crate) result_projection: NavigationResultProjection,
pub frame_id: String,
pub session_id: Option<String>,
diff --git a/moli-protocol/src/conn/state/tests.rs b/moli-protocol/src/conn/state/tests.rs
index d09136df3..66796717c 100644
--- a/moli-protocol/src/conn/state/tests.rs
+++ b/moli-protocol/src/conn/state/tests.rs
@@ -29,7 +29,7 @@ use url::Url;
fn test_navigation_dispatch_state(fetch_request_id: &str) -> NavigationDispatchState {
NavigationDispatchState {
navigate_id: Some(1),
- navigate_session_id: Some("SID-1".to_owned()),
+ owner: crate::conn::CommandOwnerScope::for_session("SID-1"),
result_projection: NavigationResultProjection::Cdp(
json!({"frameId": "TID-1", "loaderId": "LID-0000000001"}),
),
diff --git a/moli-protocol/src/conn/tests/mod.rs b/moli-protocol/src/conn/tests/mod.rs
index 0b9a580c2..5f4e9f852 100644
--- a/moli-protocol/src/conn/tests/mod.rs
+++ b/moli-protocol/src/conn/tests/mod.rs
@@ -1681,7 +1681,7 @@ fn materialized_navigation_test_state(
) -> NavigationDispatchState {
NavigationDispatchState {
navigate_id,
- navigate_session_id: None,
+ owner: crate::conn::CommandOwnerScope::for_implicit_route(None),
result_projection: NavigationResultProjection::Cdp(
json!({ "frameId": "TID-nav", "loaderId": loader_id }),
),
diff --git a/moli-protocol/src/conn/tests/resource_runtime.rs b/moli-protocol/src/conn/tests/resource_runtime.rs
index 0664e71a3..b30012cde 100644
--- a/moli-protocol/src/conn/tests/resource_runtime.rs
+++ b/moli-protocol/src/conn/tests/resource_runtime.rs
@@ -96,7 +96,7 @@ async fn buffered_navigation_for_inactive_session_carries_its_target_engine() {
let requested_url = Url::parse("https://target.example/fulfilled").unwrap();
let navigation = NavigationDispatchState {
navigate_id: Some(1),
- navigate_session_id: Some("SID-target".to_owned()),
+ owner: crate::conn::CommandOwnerScope::for_session("SID-target"),
result_projection: NavigationResultProjection::Cdp(json!({
"frameId": "TID-target",
"loaderId": "LOADER-target",
diff --git a/moli-protocol/src/domains/activity/main_document.rs b/moli-protocol/src/domains/activity/main_document.rs
index b7ce09a20..b8be4bcf1 100644
--- a/moli-protocol/src/domains/activity/main_document.rs
+++ b/moli-protocol/src/domains/activity/main_document.rs
@@ -151,7 +151,7 @@ impl MainDocumentNavigationActivity {
crate::domains::target::emit_target_info_changed_for_session_owner_background_event(
conn,
&mut target_info_events,
- self.state.navigate_session_id.as_deref(),
+ self.state.owner.session_id(),
);
out.extend_background_events_after_messages(target_info_events);
if timing_enabled {
@@ -227,7 +227,7 @@ impl MainDocumentNavigationActivity {
page::emit_bound_renderer_document_lifecycle_background_events(
conn,
&mut renderer_lifecycle_events,
- self.state.navigate_session_id.as_deref(),
+ self.state.owner.session_id(),
binding,
&initial_renderer_document_lifecycle_events,
);
@@ -236,14 +236,14 @@ impl MainDocumentNavigationActivity {
if terminated_before_domcontentloaded {
conn.cancel_renderer_document_load_visibility_barrier_for_session_owner(
- self.state.navigate_session_id.as_deref(),
+ self.state.owner.session_id(),
&self.state.loader_id,
);
return;
}
if !reached_domcontentloaded {
tracing::debug!(
- session_id = self.state.navigate_session_id.as_deref(),
+ session_id = self.state.owner.session_id(),
"renderer page creation reached commit without DOMContentLoaded or termination"
);
}
@@ -255,8 +255,7 @@ impl MainDocumentNavigationActivity {
elapsed_ms = timing_started.elapsed().as_millis(),
);
}
- let owner_scope =
- CommandOwnerScope::capture(conn, self.state.navigate_session_id.as_deref());
+ let owner_scope = CommandOwnerScope::capture(conn, self.state.owner.session_id());
conn.enqueue_deferred_main_document_load_completion(
DeferredMainDocumentLoadCompletionAdmission::new(self, pending_download)
.with_renderer_document_binding(renderer_document_binding)
@@ -275,7 +274,7 @@ impl MainDocumentNavigationActivity {
let timing_started = std::time::Instant::now();
if !self.is_still_current(conn) {
conn.cancel_renderer_document_load_visibility_barrier_for_session_owner(
- self.state.navigate_session_id.as_deref(),
+ self.state.owner.session_id(),
&self.state.loader_id,
);
if timing_enabled {
@@ -293,7 +292,7 @@ impl MainDocumentNavigationActivity {
.await;
if post_load_observation_armed {
conn.settle_root_frame_stopped_loading_observation(
- self.state.navigate_session_id.as_deref(),
+ self.state.owner.session_id(),
)
.expect(
"an armed root post-load observation must settle its exact stopped-loading fact",
@@ -319,12 +318,13 @@ impl MainDocumentNavigationActivity {
// The document token is the document identity. A same-document
// navigation may update the target URL between DCL and load, but
// it must not make the current document's load completion stale.
- return conn.accepts_document_body_completion_for_session_owner(
- self.state.navigate_session_id.as_deref(),
+ return conn.accepts_document_body_completion_for_route(
+ self.state.owner.session_id(),
+ self.state.owner.session_owner_route(),
token,
);
}
- conn.runtime_session_owner_target_url(self.state.navigate_session_id.as_deref())
+ conn.runtime_session_owner_target_url(self.state.owner.session_id())
.is_some_and(|url| url == self.final_url.as_str())
}
@@ -431,7 +431,7 @@ impl MainDocumentNavigationActivity {
pub(crate) fn navigation_error_messages_for_test(&mut self, message: &str) -> Vec<Value> {
let state = self.state();
let navigate_id = state.navigate_id;
- let navigate_session_id = state.navigate_session_id.clone();
+ let navigate_session_id = state.owner.session_id().map(str::to_owned);
let mut background_events = Vec::new();
let mut output = MainDocumentProgressBackgroundEventBarrier::background_events(
&mut background_events,
@@ -478,13 +478,13 @@ impl MainDocumentNavigationActivity {
) -> bool {
self.emit_renderer_load_boundary_facts(conn, out);
let armed = conn.arm_root_post_load_observation_for_session_owner(
- self.state.navigate_session_id.as_deref(),
+ self.state.owner.session_id(),
&self.state.loader_id,
);
if armed {
let mut network_idle_events = Vec::new();
conn.emit_root_network_idle_for_session_owner(
- self.state.navigate_session_id.as_deref(),
+ self.state.owner.session_id(),
&mut network_idle_events,
);
out.extend_background_events(network_idle_events);
@@ -510,12 +510,12 @@ impl MainDocumentNavigationActivity {
std::mem::take(&mut self.deferred_initial_renderer_document_lifecycle_events);
let (binding, mut accepted_events) = conn
.ingest_renderer_document_lifecycle_events_for_session_owner(
- self.state.navigate_session_id.as_deref(),
+ self.state.owner.session_id(),
renderer_events,
);
accepted_events.extend(
conn.release_renderer_document_load_visibility_barrier_for_session_owner(
- self.state.navigate_session_id.as_deref(),
+ self.state.owner.session_id(),
&self.state.loader_id,
)
.unwrap_or_default(),
@@ -525,7 +525,7 @@ impl MainDocumentNavigationActivity {
page::emit_bound_renderer_document_lifecycle_background_events(
conn,
&mut renderer_lifecycle_events,
- self.state.navigate_session_id.as_deref(),
+ self.state.owner.session_id(),
binding,
&accepted_events,
);
@@ -588,7 +588,7 @@ impl MainDocumentNavigationActivity {
let error = conn
.handle_pending_download_activation_inline_async(
&mut download_events,
- self.state.navigate_session_id.as_deref(),
+ self.state.owner.session_id(),
download,
&mut command_context,
)
@@ -601,7 +601,7 @@ impl MainDocumentNavigationActivity {
};
if let Some(message) = error {
let navigate_id = self.state.navigate_id;
- let navigate_session_id = self.state.navigate_session_id.clone();
+ let navigate_session_id = self.state.owner.session_id().map(str::to_owned);
let mut command_output = CommandOutputBuffer::default();
self.emit_navigation_error_into_buffer(&mut command_output, &message);
out.extend_background_events(
@@ -624,9 +624,7 @@ impl MainDocumentNavigationActivity {
network::emit_pending_network_backlog_activity_background_events(
conn,
out,
- network::NetworkBacklogProjectionContext::new(
- self.state.navigate_session_id.as_deref(),
- ),
+ network::NetworkBacklogProjectionContext::new(self.state.owner.session_id()),
);
if timing_enabled {
tracing::info!(
@@ -645,10 +643,7 @@ impl DeferredMainDocumentLoadCompletionAdmission {
navigation_activity: MainDocumentNavigationActivity,
pending_download: Option<RendererPendingDownloadActivation>,
) -> Self {
- let owner_scope = CommandOwnerScope::from_session_and_owner_route(
- navigation_activity.state.navigate_session_id.as_deref(),
- None,
- );
+ let owner_scope = navigation_activity.state.owner.clone();
Self {
state: DeferredMainDocumentLoadCompletionState {
navigation_activity,
@@ -960,7 +955,7 @@ mod tests {
fn navigation_state() -> NavigationDispatchState {
NavigationDispatchState {
navigate_id: Some(77),
- navigate_session_id: Some("SID-nav".to_owned()),
+ owner: CommandOwnerScope::for_session("SID-nav"),
result_projection: NavigationResultProjection::Cdp(
json!({ "frameId": "FRAME-1", "loaderId": "LID-1" }),
),
@@ -1389,11 +1384,9 @@ mod tests {
.await;
let mut out = Vec::new();
- output.into_plan().emit_into(
- &mut out,
- state.navigate_id,
- state.navigate_session_id.as_deref(),
- );
+ output
+ .into_plan()
+ .emit_into(&mut out, state.navigate_id, state.owner.session_id());
let dcl_index = out
.iter()
.position(|message| message["method"] == json!("Page.domContentEventFired"))
diff --git a/moli-protocol/src/domains/emulation.rs b/moli-protocol/src/domains/emulation.rs
index c81bb3d6c..a8750225e 100644
--- a/moli-protocol/src/domains/emulation.rs
+++ b/moli-protocol/src/domains/emulation.rs
@@ -961,8 +961,9 @@ fn start_devtools_set_viewport_command(
"BrowserContextNotLoaded",
));
}
- let owner_scope =
- CommandOwnerScope::from_session_and_owner_route(session_id, owner_route.cloned());
+ let owner_scope = session_id
+ .map(CommandOwnerScope::for_session)
+ .unwrap_or_else(|| CommandOwnerScope::for_implicit_route(owner_route.cloned()));
let runtime_call_id = conn.next_internal_runtime_command_id();
let Some(page) = conn
.loaded_page_mut_for_target_configuration_for_route(session_id, owner_route)
@@ -2790,8 +2791,9 @@ fn start_session_surface_override_page_command_for_route(
let Some(script) = script else {
return Ok(Vec::new());
};
- let owner_scope =
- CommandOwnerScope::from_session_and_owner_route(session_id, owner_route.cloned());
+ let owner_scope = session_id
+ .map(CommandOwnerScope::for_session)
+ .unwrap_or_else(|| CommandOwnerScope::for_implicit_route(owner_route.cloned()));
let runtime_call_id = conn.next_internal_runtime_command_id();
let Some(page) = conn
.loaded_page_mut_for_target_configuration_for_route(session_id, owner_route)
diff --git a/moli-protocol/src/domains/fetch.rs b/moli-protocol/src/domains/fetch.rs
index 84ba2c953..1b33eab78 100644
--- a/moli-protocol/src/domains/fetch.rs
+++ b/moli-protocol/src/domains/fetch.rs
@@ -253,10 +253,9 @@ impl PendingFetchCommandDispatch {
Self {
command_id,
session_id: session_id.map(str::to_owned),
- owner_scope: CommandOwnerScope::from_session_and_owner_route(
- session_id,
- session_owner_route,
- ),
+ owner_scope: session_id
+ .map(CommandOwnerScope::for_session)
+ .unwrap_or_else(|| CommandOwnerScope::for_implicit_route(session_owner_route)),
kind,
pending,
}
diff --git a/moli-protocol/src/domains/fetch/commands.rs b/moli-protocol/src/domains/fetch/commands.rs
index 3645a8d06..c1a3440e9 100644
--- a/moli-protocol/src/domains/fetch/commands.rs
+++ b/moli-protocol/src/domains/fetch/commands.rs
@@ -1891,11 +1891,6 @@ fn continue_streaming_document_response_in_background(
body_progress_source,
prepared_document,
} = pending;
- let session_id = navigation.navigate_session_id.clone();
- let none_session_owner_route =
- crate::conn::CommandOwnerScope::capture(conn, session_id.as_deref())
- .session_owner_route()
- .cloned();
let cancellation = response.cancellation_handle();
if response_code.is_none()
&& response_headers.is_empty()
@@ -1907,14 +1902,12 @@ fn continue_streaming_document_response_in_background(
sender.clone(),
document_navigation_token.clone(),
navigation.clone(),
- none_session_owner_route.clone(),
);
let (engine, navigation_result) =
prepared_document.resume_streaming(response, Some(body_completion_sink));
let _ = sender.send(page::BackgroundNavigationCompletion::new(
document_navigation_token,
navigation,
- none_session_owner_route,
engine,
Ok(navigation_result),
));
@@ -1935,13 +1928,11 @@ fn continue_streaming_document_response_in_background(
sender.clone(),
document_navigation_token.clone(),
navigation.clone(),
- none_session_owner_route.clone(),
);
let (engine, navigation_result) = job.run(Some(body_completion_sink)).await;
let _ = sender.send(page::BackgroundNavigationCompletion::new(
document_navigation_token,
navigation,
- none_session_owner_route,
engine,
navigation_result,
));
diff --git a/moli-protocol/src/domains/fetch/navigation.rs b/moli-protocol/src/domains/fetch/navigation.rs
index 781ebb3e4..3df74e47b 100644
--- a/moli-protocol/src/domains/fetch/navigation.rs
+++ b/moli-protocol/src/domains/fetch/navigation.rs
@@ -38,12 +38,12 @@ fn prepare_navigation_response_stage(
}
let Some(response_stage) = conn
.target_fetch_subresource_interception_snapshot_for_session_owner(
- pending.navigation.navigate_session_id.as_deref(),
+ pending.navigation.owner.session_id(),
)
.and_then(|snapshot| {
snapshot
.matching_response_stage_pause_sessions(
- pending.navigation.navigate_session_id.as_deref(),
+ pending.navigation.owner.session_id(),
DevToolsNetworkResourceType::Document,
final_url,
)
@@ -64,7 +64,7 @@ pub(crate) async fn load_or_pause_navigation_for_auth_into_buffer_async(
auth: Option<SubresourceAuthCredentials>,
prior_network_observation_journal: Option<NetworkObservationJournal>,
) {
- let navigate_session_id = pending.navigation.navigate_session_id.clone();
+ let navigate_session_id = pending.navigation.owner.session_id().map(str::to_owned);
network::record_main_document_request_body(conn, &pending.navigation);
let should_handle_auth = conn.target_fetch_matches_auth_required_for_session_owner(
navigate_session_id.as_deref(),
@@ -173,7 +173,7 @@ pub(crate) async fn load_or_pause_navigation_for_auth_into_buffer_async(
{
populate_auth_challenge_origin(
conn,
- pending.navigation.navigate_session_id.as_deref(),
+ pending.navigation.owner.session_id(),
&response_head.final_url,
&mut challenge,
);
@@ -271,7 +271,7 @@ pub(super) async fn load_or_pause_navigation_for_auth_as_background_events_async
prior_network_observation_journal: Option<NetworkObservationJournal>,
) {
let command_id = pending.navigation.navigate_id;
- let command_session_id = pending.navigation.navigate_session_id.clone();
+ let command_session_id = pending.navigation.owner.session_id().map(str::to_owned);
let mut output = CommandOutputBuffer::default();
Box::pin(load_or_pause_navigation_for_auth_into_buffer_async(
conn,
@@ -308,7 +308,7 @@ pub(super) async fn cancel_navigation_auth_as_background_events_async(
auth_required_blocked_intercepts: Vec::new(),
};
let command_id = pending.navigation.navigate_id;
- let command_session_id = pending.navigation.navigate_session_id.clone();
+ let command_session_id = pending.navigation.owner.session_id().map(str::to_owned);
let mut output = CommandOutputBuffer::default();
if response
.observation_journal()
@@ -378,7 +378,7 @@ pub(super) async fn complete_tokened_materialized_navigation_as_background_event
navigation: network::MaterializedNavigationLoadOutcome,
) {
let command_id = navigation_state.navigate_id;
- let command_session_id = navigation_state.navigate_session_id.clone();
+ let command_session_id = navigation_state.owner.session_id().map(str::to_owned);
let mut output = CommandOutputBuffer::default();
complete_tokened_materialized_navigation_into_buffer_async(
conn,
@@ -407,7 +407,7 @@ pub(super) async fn complete_tokened_materialized_navigation_into_buffer_async(
page::push_superseded_navigation_result(out, &navigation_state);
} else {
tracing::warn!(
- session_id = navigation_state.navigate_session_id.as_deref(),
+ session_id = navigation_state.owner.session_id(),
"direct navigation aborted after command result was handled"
);
}
@@ -472,7 +472,7 @@ async fn handle_streaming_response_head_for_navigation_into_buffer_async(
{
populate_auth_challenge_origin(
conn,
- pending.navigation.navigate_session_id.as_deref(),
+ pending.navigation.owner.session_id(),
&response_head.final_url,
&mut challenge,
);
@@ -575,7 +575,7 @@ async fn handle_streaming_response_head_for_navigation_into_buffer_async(
};
let (response, network_observation_journal) = response.into_parts_with_observation_journal();
conn.register_pending_fetch_response_navigation_for_session_owner(
- pending.navigation.navigate_session_id.as_deref(),
+ pending.navigation.owner.session_id(),
pending.fetch_request_id.clone(),
pending.document_navigation_token.clone(),
pending.navigation.clone(),
@@ -684,7 +684,7 @@ fn pause_buffered_raw_response_stage_navigation_into_buffer(
let request_cookie_report = response.response().request_cookie_report.clone();
let (response, network_observation_journal) = response.into_parts_with_observation_journal();
conn.register_pending_fetch_response_navigation_for_session_owner(
- pending.navigation.navigate_session_id.as_deref(),
+ pending.navigation.owner.session_id(),
pending.fetch_request_id.clone(),
pending.document_navigation_token.clone(),
pending.navigation.clone(),
@@ -794,7 +794,7 @@ fn navigation_auth_required_blocked_intercepts(
return pending.auth_required_blocked_intercepts.clone();
}
let intercepts = conn.target_fetch_matching_auth_required_network_intercepts_for_session_owner(
- pending.navigation.navigate_session_id.as_deref(),
+ pending.navigation.owner.session_id(),
&pending.navigation.requested_url,
);
if !intercepts.is_empty() {
@@ -842,7 +842,7 @@ fn register_navigation_auth_required_event(
) -> crate::conn::BackgroundProtocolEvent {
let blocked_intercepts = navigation_auth_required_blocked_intercepts(conn, pending);
let mut pending_auth = crate::conn::PendingFetchAuthNavigation {
- owner_session_id: pending.navigation.navigate_session_id.clone(),
+ owner_session_id: pending.navigation.owner.session_id().map(str::to_owned),
action_session_id: pending.interception_session_id.clone(),
interception_session_id: pending.interception_session_id.clone(),
owner_kind: PendingSubresourceFetchOwnerKind::Fetch,
@@ -863,12 +863,12 @@ fn register_navigation_auth_required_event(
.target_fetch_subresource_interception_snapshot_for_target(&pending.navigation.frame_id)
.or_else(|| {
conn.target_fetch_subresource_interception_snapshot_for_session_owner(
- pending.navigation.navigate_session_id.as_deref(),
+ pending.navigation.owner.session_id(),
)
})
.map(|snapshot| {
snapshot.matching_auth_required_pause_sessions(
- pending.navigation.navigate_session_id.as_deref(),
+ pending.navigation.owner.session_id(),
&pending.navigation.requested_url,
)
})
@@ -876,7 +876,7 @@ fn register_navigation_auth_required_event(
if let Some(first_pause_session) = auth_sessions.first().cloned() {
pending_auth.owner_session_id = routable_stage_owner_session_id(
conn,
- pending.navigation.navigate_session_id.as_deref(),
+ pending.navigation.owner.session_id(),
first_pause_session.session_id.as_deref(),
);
pending_auth.owner_kind = first_pause_session.owner_kind;
@@ -889,7 +889,7 @@ fn register_navigation_auth_required_event(
let mut remaining_sessions = Vec::new();
for session in auth_sessions.into_iter().skip(1) {
let Ok(next_request_id) = conn.allocate_fetch_navigation_request_id_for_session_owner(
- pending.navigation.navigate_session_id.as_deref(),
+ pending.navigation.owner.session_id(),
) else {
break;
};
@@ -914,7 +914,7 @@ fn register_navigation_auth_required_event(
let pending_owner_session_id = pending_auth
.owner_session_id
.as_deref()
- .or(pending.navigation.navigate_session_id.as_deref());
+ .or(pending.navigation.owner.session_id());
conn.register_pending_fetch_auth_navigation_for_session_owner(
pending_owner_session_id,
pending.fetch_request_id.clone(),
diff --git a/moli-protocol/src/domains/fetch/tests/basics.rs b/moli-protocol/src/domains/fetch/tests/basics.rs
index 721b94d94..07034dd6a 100644
--- a/moli-protocol/src/domains/fetch/tests/basics.rs
+++ b/moli-protocol/src/domains/fetch/tests/basics.rs
@@ -1073,7 +1073,7 @@ async fn disable_clears_fetch_state() {
document_navigation_token: None,
navigation: crate::conn::NavigationDispatchState {
navigate_id: Some(1),
- navigate_session_id: None,
+ owner: crate::conn::CommandOwnerScope::for_implicit_route(None),
result_projection: crate::conn::NavigationResultProjection::Cdp(
json!({"frameId": "TID-1", "loaderId": "LID-0000000001"}),
),
@@ -1111,7 +1111,7 @@ async fn disable_clears_fetch_state() {
document_navigation_token: None,
navigation: crate::conn::NavigationDispatchState {
navigate_id: Some(1),
- navigate_session_id: None,
+ owner: crate::conn::CommandOwnerScope::for_implicit_route(None),
result_projection: crate::conn::NavigationResultProjection::Cdp(
json!({"frameId": "TID-1", "loaderId": "LID-0000000001"}),
),
@@ -1335,7 +1335,7 @@ async fn continue_with_auth_rejects_invalid_response_without_consuming_pending_a
document_navigation_token: None,
navigation: crate::conn::NavigationDispatchState {
navigate_id: Some(1),
- navigate_session_id: Some("SID-1".to_owned()),
+ owner: crate::conn::CommandOwnerScope::for_session("SID-1"),
result_projection: crate::conn::NavigationResultProjection::Cdp(
json!({"frameId": "TID-1", "loaderId": "LID-0000000001"}),
),
@@ -1410,7 +1410,7 @@ async fn continue_with_auth_unsupported_challenge_preserves_pending_auth_navigat
document_navigation_token: None,
navigation: crate::conn::NavigationDispatchState {
navigate_id: Some(1),
- navigate_session_id: Some("SID-1".to_owned()),
+ owner: crate::conn::CommandOwnerScope::for_session("SID-1"),
result_projection: crate::conn::NavigationResultProjection::Cdp(
json!({"frameId": "TID-1", "loaderId": "LID-0000000001"}),
),
@@ -1582,7 +1582,7 @@ fn emit_auth_required_preserves_request_headers_and_post_data_shape() {
document_navigation_token: None,
navigation: crate::conn::NavigationDispatchState {
navigate_id: Some(1),
- navigate_session_id: Some("SID-1".to_owned()),
+ owner: crate::conn::CommandOwnerScope::for_session("SID-1"),
result_projection: crate::conn::NavigationResultProjection::Cdp(
json!({"frameId": "TID-1", "loaderId": "LID-0000000001"}),
),
diff --git a/moli-protocol/src/domains/network/tests/cache.rs b/moli-protocol/src/domains/network/tests/cache.rs
index 2a2e1a841..8351da9a0 100644
--- a/moli-protocol/src/domains/network/tests/cache.rs
+++ b/moli-protocol/src/domains/network/tests/cache.rs
@@ -644,7 +644,7 @@ async fn clear_browser_cache_keeps_pending_response_navigation_transfer() {
None,
NavigationDispatchState {
navigate_id: Some(1),
- navigate_session_id: Some("SID-1".to_owned()),
+ owner: crate::conn::CommandOwnerScope::for_session("SID-1"),
result_projection: crate::conn::NavigationResultProjection::Cdp(
json!({"frameId": "TID-1", "loaderId": LOADER_ID}),
),
diff --git a/moli-protocol/src/domains/network/tests/response_body.rs b/moli-protocol/src/domains/network/tests/response_body.rs
index 03fb5d749..0f6f5d51d 100644
--- a/moli-protocol/src/domains/network/tests/response_body.rs
+++ b/moli-protocol/src/domains/network/tests/response_body.rs
@@ -504,7 +504,7 @@ async fn get_request_post_data_returns_main_document_navigation_post_body() {
let requested_url = Url::parse("http://127.0.0.1:1/post").unwrap();
let navigation_state = NavigationDispatchState {
navigate_id: Some(1),
- navigate_session_id: Some("SID-1".to_owned()),
+ owner: crate::conn::CommandOwnerScope::for_session("SID-1"),
result_projection: crate::conn::NavigationResultProjection::Cdp(
json!({"frameId": "TID-1", "loaderId": LOADER_ID}),
),
@@ -593,7 +593,7 @@ async fn get_request_post_data_uses_text_projection_while_bidi_collector_keeps_t
let requested_url = Url::parse("http://127.0.0.1:1/upload").unwrap();
let navigation_state = NavigationDispatchState {
navigate_id: Some(1),
- navigate_session_id: Some("SID-1".to_owned()),
+ owner: crate::conn::CommandOwnerScope::for_session("SID-1"),
result_projection: crate::conn::NavigationResultProjection::Cdp(
json!({"frameId": "TID-1", "loaderId": LOADER_ID}),
),
diff --git a/moli-protocol/src/domains/page.rs b/moli-protocol/src/domains/page.rs
index c97ab405a..b9bcba034 100644
--- a/moli-protocol/src/domains/page.rs
+++ b/moli-protocol/src/domains/page.rs
@@ -2388,9 +2388,10 @@ async fn navigate_session_owner_from_renderer_request_background_events_async(
request_headers: &[(String, String)],
browser_navigation_kind: moli_fetch::BrowserNavigationRequestKind,
) {
+ let owner = CommandOwnerScope::capture(conn, session_id);
let start = navigation::start_session_owner_navigation_from_renderer(
conn,
- session_id,
+ &owner,
url,
request_method,
request_body,
@@ -2398,7 +2399,7 @@ async fn navigate_session_owner_from_renderer_request_background_events_async(
browser_navigation_kind,
);
let step =
- navigation::finish_started_navigation_command_for_parts(conn, None, session_id, start, &[]);
+ navigation::finish_started_navigation_command_for_parts(conn, None, owner, start, &[]);
complete_renderer_navigation_step_background_events_async(conn, out, step).await;
}
@@ -6525,10 +6526,11 @@ fn try_start_page_enable_command(
cmd.session_id,
) =>
{
+ let owner = CommandOwnerScope::capture(conn, cmd.session_id);
let start = match navigation::start_initial_document_navigation_for_session_owner(
conn,
cmd.id,
- cmd.session_id,
+ &owner,
json!({}),
) {
Ok(start) => start,
@@ -6537,7 +6539,7 @@ fn try_start_page_enable_command(
Some(navigation::finish_started_navigation_command_for_parts(
conn,
cmd.id,
- cmd.session_id,
+ owner,
start,
&[],
))
@@ -6546,10 +6548,11 @@ fn try_start_page_enable_command(
Some(PageCommandTaskStep::Complete(CommandOutputPlan::success()))
}
Ok(_) if !conn.runtime_session_owner_target_is_initial_about_blank(cmd.session_id) => {
+ let owner = CommandOwnerScope::capture(conn, cmd.session_id);
let start = match navigation::start_initial_document_navigation_for_session_owner(
conn,
cmd.id,
- cmd.session_id,
+ &owner,
json!({}),
) {
Ok(start) => start,
@@ -6558,7 +6561,7 @@ fn try_start_page_enable_command(
Some(navigation::finish_started_navigation_command_for_parts(
conn,
cmd.id,
- cmd.session_id,
+ owner,
start,
&[],
))
@@ -7484,7 +7487,9 @@ async fn complete_pending_page_command_inner(
command_context: &mut CommandDispatchContext,
) -> PageCommandTaskStep {
let command_id = completed.command_id;
+ let owner_scope = completed.owner_scope.clone();
let session_id = completed.owner_scope.session_id().map(str::to_owned);
+ let owner_route = completed.owner_scope.session_owner_route().cloned();
if let Some(predecessor) = completed.kind.renderer_output_predecessor() {
command_context.set_renderer_output_predecessor(predecessor);
}
@@ -7520,7 +7525,10 @@ async fn complete_pending_page_command_inner(
};
let completed_script = {
let Some(page) = conn
- .runtime_session_owner_slot_mut(session_id.as_deref())
+ .runtime_session_owner_slot_mut_for_route(
+ session_id.as_deref(),
+ owner_route.as_ref(),
+ )
.ok()
.and_then(|slot| slot.loaded_page_mut())
else {
@@ -7553,7 +7561,10 @@ async fn complete_pending_page_command_inner(
}
};
let Some(page) = conn
- .runtime_session_owner_slot_mut(session_id.as_deref())
+ .runtime_session_owner_slot_mut_for_route(
+ session_id.as_deref(),
+ owner_route.as_ref(),
+ )
.ok()
.and_then(|slot| slot.loaded_page_mut())
else {
@@ -7576,7 +7587,7 @@ async fn complete_pending_page_command_inner(
return resource_search::complete_search_in_resource_command(
conn,
command_id,
- session_id.as_deref(),
+ &owner_scope,
*completed,
);
}
@@ -7584,7 +7595,7 @@ async fn complete_pending_page_command_inner(
return app_manifest::complete_get_app_manifest_command(
conn,
command_id,
- session_id.as_deref(),
+ &owner_scope,
*completed,
command_context,
);
@@ -7592,7 +7603,7 @@ async fn complete_pending_page_command_inner(
CompletedPageCommandKind::ResetNavigationHistory { completed } => {
return navigation::complete_reset_navigation_history_command(
conn,
- session_id.as_deref(),
+ &owner_scope,
*completed,
);
}
@@ -7616,7 +7627,10 @@ async fn complete_pending_page_command_inner(
}
};
let Some(page) = conn
- .runtime_session_owner_slot_mut(session_id.as_deref())
+ .runtime_session_owner_slot_mut_for_route(
+ session_id.as_deref(),
+ owner_route.as_ref(),
+ )
.ok()
.and_then(|slot| slot.loaded_page_mut())
else {
@@ -7644,7 +7658,10 @@ async fn complete_pending_page_command_inner(
};
let (result, output) = {
let Some(page) = conn
- .runtime_session_owner_slot_mut(session_id.as_deref())
+ .runtime_session_owner_slot_mut_for_route(
+ session_id.as_deref(),
+ owner_route.as_ref(),
+ )
.ok()
.and_then(|slot| slot.loaded_page_mut())
else {
@@ -7679,7 +7696,7 @@ async fn complete_pending_page_command_inner(
CompletedPageCommandKind::SameDocumentNavigate(completed) => {
return navigation::complete_pending_same_document_navigate_command(
conn,
- session_id.as_deref(),
+ &owner_scope,
*completed,
command_context,
)
@@ -7697,7 +7714,7 @@ async fn complete_pending_page_command_inner(
completed,
} => {
if conn
- .ensure_document_accessible_for_session_owner(session_id.as_deref())
+ .ensure_document_accessible_for_route(session_id.as_deref(), owner_route.as_ref())
.is_err()
{
return PageCommandTaskStep::Complete(get_frame_tree_command_output_plan(
@@ -7714,7 +7731,10 @@ async fn complete_pending_page_command_inner(
));
}
let Some(page) = conn
- .runtime_session_owner_slot_mut(session_id.as_deref())
+ .runtime_session_owner_slot_mut_for_route(
+ session_id.as_deref(),
+ owner_route.as_ref(),
+ )
.ok()
.and_then(|slot| slot.loaded_page_mut())
else {
@@ -7772,7 +7792,10 @@ async fn complete_pending_page_command_inner(
}
};
let Some(page) = conn
- .runtime_session_owner_slot_mut(session_id.as_deref())
+ .runtime_session_owner_slot_mut_for_route(
+ session_id.as_deref(),
+ owner_route.as_ref(),
+ )
.ok()
.and_then(|slot| slot.loaded_page_mut())
else {
@@ -7803,7 +7826,10 @@ async fn complete_pending_page_command_inner(
));
}
};
- let page = match conn.loaded_page_mut_for_protocol_access(session_id.as_deref()) {
+ let page = match conn.loaded_page_mut_for_protocol_access_for_route(
+ session_id.as_deref(),
+ owner_route.as_ref(),
+ ) {
Ok(page) => page,
Err(message) => {
return PageCommandTaskStep::Complete(CommandOutputPlan::error(
@@ -7833,7 +7859,10 @@ async fn complete_pending_page_command_inner(
));
}
};
- let page = match conn.loaded_page_mut_for_protocol_access(session_id.as_deref()) {
+ let page = match conn.loaded_page_mut_for_protocol_access_for_route(
+ session_id.as_deref(),
+ owner_route.as_ref(),
+ ) {
Ok(page) => page,
Err(message) => {
return PageCommandTaskStep::Complete(CommandOutputPlan::error(
@@ -7878,7 +7907,10 @@ async fn complete_pending_page_command_inner(
));
}
};
- let page = match conn.loaded_page_mut_for_protocol_access(session_id.as_deref()) {
+ let page = match conn.loaded_page_mut_for_protocol_access_for_route(
+ session_id.as_deref(),
+ owner_route.as_ref(),
+ ) {
Ok(page) => page,
Err(message) => {
return PageCommandTaskStep::Complete(CommandOutputPlan::error(
@@ -7934,8 +7966,9 @@ async fn complete_pending_page_command_inner(
}))
}
DevToolsPrintToPdfTransferMode::ReturnAsStream => {
- let stream = match conn.open_io_stream_body_source_for_session_owner(
+ let stream = match conn.open_io_stream_body_source_for_route(
session_id.as_deref(),
+ owner_route.as_ref(),
CapturedBody::from_bytes_spooled(pdf),
) {
Ok(stream) => stream,
@@ -7965,7 +7998,7 @@ async fn complete_pending_page_command_inner(
CompletedPageCommandKind::ChildFrameNavigate(completed) => {
return navigation::complete_pending_child_frame_navigate_command(
conn,
- session_id.as_deref(),
+ &owner_scope,
*completed,
command_context,
)
@@ -7981,10 +8014,7 @@ async fn complete_pending_page_command_inner(
}
CompletedPageCommandKind::TraverseSameDocumentHistory(completed) => {
return navigation::complete_pending_same_document_history_traversal_command(
- conn,
- command_id,
- session_id.as_deref(),
- *completed,
+ conn, command_id, *completed,
);
}
CompletedPageCommandKind::ContinueNavigationWithoutRequestPause(completed) => {
diff --git a/moli-protocol/src/domains/page/app_manifest.rs b/moli-protocol/src/domains/page/app_manifest.rs
index 7c73c1829..86b6a676c 100644
--- a/moli-protocol/src/domains/page/app_manifest.rs
+++ b/moli-protocol/src/domains/page/app_manifest.rs
@@ -107,9 +107,8 @@ pub(super) fn try_start_get_app_manifest_command(
};
match pending {
Ok(pending) => pending_step(
- conn,
cmd.id,
- cmd.session_id,
+ CommandOwnerScope::capture(conn, cmd.session_id),
PendingGetAppManifestCommand {
manifest_id: params.manifest_id,
work: PendingGetAppManifestWork::Prepare(pending),
@@ -125,10 +124,12 @@ pub(super) fn try_start_get_app_manifest_command(
pub(super) fn complete_get_app_manifest_command(
conn: &mut CdpConnection,
command_id: Option<u64>,
- session_id: Option<&str>,
+ owner: &CommandOwnerScope,
completed: CompletedGetAppManifestCommand,
command_context: &mut CommandDispatchContext,
) -> PageCommandTaskStep {
+ let session_id = owner.session_id();
+ let owner_route = owner.session_owner_route();
match completed.work {
CompletedGetAppManifestWork::Prepare(completion) => {
let completion = match completion {
@@ -141,7 +142,7 @@ pub(super) fn complete_get_app_manifest_command(
}
};
let preparation = match conn
- .loaded_page_mut_for_protocol_access(session_id)
+ .loaded_page_mut_for_protocol_access_for_route(session_id, owner_route)
.and_then(|page| {
page.finish_prepare_app_manifest_load(completion)
.map_err(|error| error.to_string())
@@ -162,9 +163,8 @@ pub(super) fn complete_get_app_manifest_command(
))
}
RendererAppManifestLoadPreparation::Ready(pending) => pending_step(
- conn,
command_id,
- session_id,
+ owner.clone(),
PendingGetAppManifestCommand {
manifest_id: completed.manifest_id,
work: PendingGetAppManifestWork::Fetch(pending),
@@ -174,19 +174,19 @@ pub(super) fn complete_get_app_manifest_command(
}
CompletedGetAppManifestWork::Fetch(outcome) => {
let (result, publication) = (*outcome).into_parts();
- let pending = match conn.loaded_page_mut_for_protocol_access(session_id) {
- Ok(page) => page.start_publish_app_manifest_load(publication),
- Err(message) => {
- return PageCommandTaskStep::Complete(CommandOutputPlan::error(
- -32000, message,
- ));
- }
- };
+ let pending =
+ match conn.loaded_page_mut_for_protocol_access_for_route(session_id, owner_route) {
+ Ok(page) => page.start_publish_app_manifest_load(publication),
+ Err(message) => {
+ return PageCommandTaskStep::Complete(CommandOutputPlan::error(
+ -32000, message,
+ ));
+ }
+ };
match pending {
Ok(pending) => pending_step(
- conn,
command_id,
- session_id,
+ owner.clone(),
PendingGetAppManifestCommand {
manifest_id: completed.manifest_id,
work: PendingGetAppManifestWork::Publish {
@@ -212,7 +212,7 @@ pub(super) fn complete_get_app_manifest_command(
}
};
let output = match conn
- .loaded_page_mut_for_protocol_access(session_id)
+ .loaded_page_mut_for_protocol_access_for_route(session_id, owner_route)
.and_then(|page| {
page.finish_publish_app_manifest_load(completion)
.map_err(|error| error.to_string())
@@ -226,7 +226,7 @@ pub(super) fn complete_get_app_manifest_command(
};
let mut ordered_events = Vec::new();
command_context.consume_renderer_command_turn_output(output);
- conn.ingest_runtime_session_owner_output_updates(session_id);
+ conn.ingest_runtime_session_owner_output_updates_for_route(session_id, owner_route);
emit_pending_network_backlog_activity_background_events(
conn,
&mut ordered_events,
@@ -241,14 +241,13 @@ pub(super) fn complete_get_app_manifest_command(
}
fn pending_step(
- conn: &CdpConnection,
command_id: Option<u64>,
- session_id: Option<&str>,
+ owner_scope: CommandOwnerScope,
pending: PendingGetAppManifestCommand,
) -> PageCommandTaskStep {
PageCommandTaskStep::Pending(PendingPageCommandDispatch {
command_id,
- owner_scope: CommandOwnerScope::capture(conn, session_id),
+ owner_scope,
kind: Box::new(PendingPageCommandKind::GetAppManifest(pending)),
})
}
diff --git a/moli-protocol/src/domains/page/navigation.rs b/moli-protocol/src/domains/page/navigation.rs
index d58fc4d95..a48f62f61 100644
--- a/moli-protocol/src/domains/page/navigation.rs
+++ b/moli-protocol/src/domains/page/navigation.rs
@@ -22,8 +22,8 @@ use url::Url;
use crate::conn::{
BackgroundNavigationLoadJob, BackgroundProtocolEvent, CapturedBody, CdpConnection,
- CdpSessionRoute, Cmd, CommandDispatchContext, DocumentNavigationToken, FetchRequestStage,
- NavigationDispatchState, NavigationLoadOutcome, NavigationRequestLoadPolicy,
+ CdpSessionRoute, Cmd, CommandDispatchContext, CommandOwnerScope, DocumentNavigationToken,
+ FetchRequestStage, NavigationDispatchState, NavigationLoadOutcome, NavigationRequestLoadPolicy,
NavigationResultProjection, NavigationSourceDocumentSecurityContext, PendingFetchNavigation,
ResponseStageUrlMatchPolicy, monotonic_timestamp_seconds,
};
@@ -106,6 +106,7 @@ pub(super) struct CompletedContinueNavigationWithoutRequestPauseCommand {
struct HistoryTraversalUrlFallback {
entry_id: i32,
url: String,
+ owner: CommandOwnerScope,
result_projection: NavigationResultProjection,
reloaded_after_crash_session_ids: Vec<Option<String>>,
allow_background_navigation: bool,
@@ -346,13 +347,15 @@ impl DirectNavigationResult {
fn send_background_navigation_started(
conn: &mut CdpConnection,
token: DocumentNavigationToken,
- owner_session_id: Option<&str>,
+ owner: &CommandOwnerScope,
frame_id: &str,
loader_id: &str,
url: &str,
initiator: NavigationStartInitiator,
) {
- for session_id in conn.page_event_session_ids_for_session_owner(owner_session_id) {
+ for session_id in
+ conn.page_event_session_ids_for_route(owner.session_id(), owner.session_owner_route())
+ {
let mut events = Vec::new();
emit_navigation_started_background_events(
&mut events,
@@ -371,13 +374,15 @@ fn send_background_navigation_started(
fn emit_navigation_started_for_session_owner(
conn: &CdpConnection,
out: &mut Vec<BackgroundProtocolEvent>,
- owner_session_id: Option<&str>,
+ owner: &CommandOwnerScope,
frame_id: &str,
loader_id: &str,
url: &str,
initiator: NavigationStartInitiator,
) {
- for session_id in conn.page_event_session_ids_for_session_owner(owner_session_id) {
+ for session_id in
+ conn.page_event_session_ids_for_route(owner.session_id(), owner.session_owner_route())
+ {
emit_navigation_started_background_events(
out,
session_id.as_deref(),
@@ -416,8 +421,9 @@ impl MaterializedNavigationCompletion {
}
pub(crate) fn is_current_for_connection(&self, conn: &CdpConnection) -> bool {
- conn.accepts_pending_document_navigation_for_session_owner(
- self.state.navigate_session_id.as_deref(),
+ conn.accepts_pending_document_navigation_for_route(
+ self.state.owner.session_id(),
+ self.state.owner.session_owner_route(),
&self.token,
)
}
@@ -431,7 +437,7 @@ impl MaterializedNavigationCompletion {
}
pub(crate) fn navigate_session_id(&self) -> Option<&str> {
- self.state.navigate_session_id.as_deref()
+ self.state.owner.session_id()
}
pub(crate) fn into_parts(
@@ -449,7 +455,6 @@ impl MaterializedNavigationCompletion {
pub struct BackgroundMainDocumentBodyCompletion {
token: DocumentNavigationToken,
state: NavigationDispatchState,
- none_session_owner_route: Option<CdpSessionRoute>,
body: Result<CapturedBody, String>,
synthetic: bool,
body_progress_source: network::MainDocumentBodyProgressSource,
@@ -462,7 +467,6 @@ impl BackgroundMainDocumentBodyCompletion {
pub(crate) fn new(
token: DocumentNavigationToken,
state: NavigationDispatchState,
- none_session_owner_route: Option<CdpSessionRoute>,
body: Result<CapturedBody, String>,
synthetic: bool,
body_progress_source: network::MainDocumentBodyProgressSource,
@@ -473,7 +477,6 @@ impl BackgroundMainDocumentBodyCompletion {
Self {
token,
state,
- none_session_owner_route,
body,
synthetic,
body_progress_source,
@@ -483,17 +486,10 @@ impl BackgroundMainDocumentBodyCompletion {
}
}
- pub(crate) fn navigate_session_id(&self) -> Option<&str> {
- self.state.navigate_session_id.as_deref()
- }
-
- pub(crate) fn none_session_owner_route(&self) -> Option<CdpSessionRoute> {
- self.none_session_owner_route.clone()
- }
-
pub(crate) fn is_current_for_connection(&self, conn: &CdpConnection) -> bool {
- conn.accepts_document_body_completion_for_session_owner(
- self.state.navigate_session_id.as_deref(),
+ conn.accepts_document_body_completion_for_route(
+ self.state.owner.session_id(),
+ self.state.owner.session_owner_route(),
&self.token,
)
}
@@ -504,8 +500,9 @@ impl BackgroundMainDocumentBodyCompletion {
}
match self.body {
Ok(body) => {
- let _ = conn.record_main_document_resource_body_for_session_owner(
- self.state.navigate_session_id.as_deref(),
+ let _ = conn.record_main_document_resource_body_for_route(
+ self.state.owner.session_id(),
+ self.state.owner.session_owner_route(),
self.state.frame_id.clone(),
self.state.loader_id.clone(),
self.final_url,
@@ -558,7 +555,6 @@ impl BackgroundNavigationCompletion {
pub struct BackgroundNavigationLifecycleCompletion {
token: DocumentNavigationToken,
state: NavigationDispatchState,
- none_session_owner_route: Option<CdpSessionRoute>,
engine: NavigationEngine,
navigation: Result<NavigationLoadOutcome, String>,
ready_at: std::time::Instant,
@@ -568,35 +564,26 @@ impl BackgroundNavigationLifecycleCompletion {
pub(crate) fn new(
token: DocumentNavigationToken,
state: NavigationDispatchState,
- none_session_owner_route: Option<CdpSessionRoute>,
engine: NavigationEngine,
navigation: Result<NavigationLoadOutcome, String>,
) -> Self {
Self {
token,
state,
- none_session_owner_route,
engine,
navigation,
ready_at: std::time::Instant::now(),
}
}
- pub(crate) fn navigate_session_id(&self) -> Option<&str> {
- self.state.navigate_session_id.as_deref()
- }
-
pub(crate) fn navigation_token(&self) -> &DocumentNavigationToken {
&self.token
}
- pub(crate) fn none_session_owner_route(&self) -> Option<CdpSessionRoute> {
- self.none_session_owner_route.clone()
- }
-
pub(crate) fn is_current_for_connection(&self, conn: &CdpConnection) -> bool {
- conn.accepts_pending_document_navigation_for_session_owner(
- self.state.navigate_session_id.as_deref(),
+ conn.accepts_pending_document_navigation_for_route(
+ self.state.owner.session_id(),
+ self.state.owner.session_owner_route(),
&self.token,
)
}
@@ -623,7 +610,6 @@ impl BackgroundNavigationLifecycleCompletion {
let Self {
token,
state,
- none_session_owner_route: _,
engine,
navigation,
ready_at: _,
@@ -648,23 +634,17 @@ impl BackgroundNavigationCompletion {
pub(crate) fn new(
token: DocumentNavigationToken,
state: NavigationDispatchState,
- none_session_owner_route: Option<CdpSessionRoute>,
engine: NavigationEngine,
navigation: Result<NavigationLoadOutcome, String>,
) -> Self {
Self::Lifecycle(Box::new(BackgroundNavigationLifecycleCompletion::new(
- token,
- state,
- none_session_owner_route,
- engine,
- navigation,
+ token, state, engine, navigation,
)))
}
pub(crate) fn main_document_body(
token: DocumentNavigationToken,
state: NavigationDispatchState,
- none_session_owner_route: Option<CdpSessionRoute>,
body: Result<CapturedBody, String>,
synthetic: bool,
body_progress_source: network::MainDocumentBodyProgressSource,
@@ -675,7 +655,6 @@ impl BackgroundNavigationCompletion {
Self::MainDocumentBody(Box::new(BackgroundMainDocumentBodyCompletion::new(
token,
state,
- none_session_owner_route,
body,
synthetic,
body_progress_source,
@@ -694,14 +673,36 @@ pub(crate) fn navigation_cookie_access_report(
previous_request_url: Option<&Url>,
_request_load_policy: NavigationRequestLoadPolicy,
initiator_url_override: Option<&Url>,
+) -> Option<StoredCookieQueryReport> {
+ let owner = CommandOwnerScope::capture(conn, owner_session_id);
+ navigation_cookie_access_report_for_owner(
+ conn,
+ &owner,
+ request_url,
+ method,
+ previous_request_url,
+ _request_load_policy,
+ initiator_url_override,
+ )
+}
+
+#[allow(clippy::too_many_arguments)]
+fn navigation_cookie_access_report_for_owner(
+ conn: &CdpConnection,
+ owner: &CommandOwnerScope,
+ request_url: &Url,
+ method: &str,
+ previous_request_url: Option<&Url>,
+ _request_load_policy: NavigationRequestLoadPolicy,
+ initiator_url_override: Option<&Url>,
) -> Option<StoredCookieQueryReport> {
// Once a navigation commits, the target identity and loaded page already point
// at the destination document. Redirect diagnostics still need the
// pre-commit initiator, so callers may override it with a snapshot taken
// before mutating browser context state.
- let initiator_url = initiator_url_override
- .cloned()
- .or_else(|| conn.navigation_initiator_url_for_session_owner(owner_session_id));
+ let initiator_url = initiator_url_override.cloned().or_else(|| {
+ conn.navigation_initiator_url_for_route(owner.session_id(), owner.session_owner_route())
+ });
let request_context = network::navigation_cookie_request_context(
request_url,
method,
@@ -733,8 +734,8 @@ pub(super) fn try_start_navigate_command_dispatch(
));
}
};
- let reloaded_after_crash_session_ids =
- reloaded_after_crash_session_ids_for_session_owner(conn, cmd.session_id);
+ let owner = CommandOwnerScope::capture(conn, cmd.session_id);
+ let reloaded_after_crash_session_ids = reloaded_after_crash_session_ids(conn, &owner);
let frame_id = params
.frame_id
.as_ref()
@@ -761,9 +762,9 @@ pub(super) fn try_start_navigate_command_dispatch(
start_devtools_page_command(
conn,
cmd.id,
- cmd.session_id,
DevToolsCommand::Navigate(shared_command),
DevToolsNavigationStartOptions {
+ owner,
result_projection,
reloaded_after_crash_session_ids,
allow_background_navigation: true,
@@ -854,6 +855,7 @@ fn update_navigation_result_payload_identity(
}
struct DevToolsNavigationStartOptions {
+ owner: CommandOwnerScope,
result_projection: NavigationResultProjection,
reloaded_after_crash_session_ids: Vec<Option<String>>,
allow_background_navigation: bool,
@@ -862,7 +864,6 @@ struct DevToolsNavigationStartOptions {
fn start_devtools_page_command(
conn: &mut CdpConnection,
command_id: Option<u64>,
- command_session_id: Option<&str>,
command: DevToolsCommand,
options: DevToolsNavigationStartOptions,
) -> PageCommandTaskStep {
@@ -871,7 +872,7 @@ fn start_devtools_page_command(
let start = start_devtools_navigate_command(
conn,
command_id,
- command_session_id,
+ &options.owner,
&command,
options.result_projection,
options.allow_background_navigation,
@@ -879,21 +880,17 @@ fn start_devtools_page_command(
finish_started_navigation_command_for_parts(
conn,
command_id,
- command_session_id,
+ options.owner,
start,
&options.reloaded_after_crash_session_ids,
)
}
DevToolsCommand::Reload(command) => {
- start_devtools_reload_command(conn, command_id, command_session_id, &command, options)
+ start_devtools_reload_command(conn, command_id, &command, options)
+ }
+ DevToolsCommand::TraverseHistory(command) => {
+ start_devtools_traverse_history_command(conn, command_id, &command, options)
}
- DevToolsCommand::TraverseHistory(command) => start_devtools_traverse_history_command(
- conn,
- command_id,
- command_session_id,
- &command,
- options,
- ),
_ => PageCommandTaskStep::Complete(CommandOutputPlan::error(
-32000,
"UnsupportedDevToolsCommand",
@@ -944,22 +941,14 @@ pub(crate) async fn execute_devtools_navigation_command_async_with_protocol_even
}
PageCommandTaskStep::Pending(pending) => {
let completed = pending.wait().await;
- let mut route_scope = conn.scoped_none_session_owner_route_override(route.clone());
if let Ok(result) = direct_result.as_mut()
- && let Err(error) = direct_navigation_result_from_completed(
- route_scope.conn_mut(),
- &completed,
- result,
- )
+ && let Err(error) =
+ direct_navigation_result_from_completed(conn, &completed, result)
{
direct_result = Err(error);
}
- step = super::complete_pending_page_command(
- route_scope.conn_mut(),
- completed,
- &mut command_context,
- )
- .await;
+ step = super::complete_pending_page_command(conn, completed, &mut command_context)
+ .await;
}
}
}
@@ -977,12 +966,8 @@ pub(crate) fn execute_devtools_get_navigation_history_command(
let route = conn
.target_session_route_for_target_id(target_id.as_str())
.ok_or_else(|| DevToolsError::new(DevToolsErrorKind::NoSuchTarget, "NoSuchTarget"))?;
- let snapshot = {
- let mut route_scope = conn.scoped_none_session_owner_route_override(route);
- route_scope
- .conn_mut()
- .target_session_owner_navigation_history_snapshot(None)
- };
+ let snapshot =
+ conn.target_session_owner_navigation_history_snapshot_for_route(None, Some(&route));
let Some((current_index, entries)) = snapshot else {
return Err(DevToolsError::new(
DevToolsErrorKind::NoSuchTarget,
@@ -1048,12 +1033,12 @@ fn start_protocol_neutral_navigation_command(
PageCommandTaskStep,
Result<DirectNavigationResult, DevToolsError>,
) {
- let mut route_scope = conn.scoped_none_session_owner_route_override(route);
- let conn = route_scope.conn_mut();
let wait = devtools_navigation_wait(&command);
let result_url = match &command {
DevToolsCommand::Navigate(command) => command.url.clone(),
- DevToolsCommand::Reload(_) => match conn.runtime_session_owner_target_url(None) {
+ DevToolsCommand::Reload(_) => match conn
+ .runtime_session_owner_target_url_for_route(None, Some(&route))
+ {
Some(url) => url,
None => {
let error = DevToolsError::new(DevToolsErrorKind::NoSuchTarget, "TargetNotLoaded");
@@ -1107,8 +1092,8 @@ fn start_protocol_neutral_navigation_command(
is_download: None,
},
};
- let reloaded_after_crash_session_ids =
- reloaded_after_crash_session_ids_for_session_owner(conn, None);
+ let command_owner = CommandOwnerScope::for_implicit_route(Some(route.clone()));
+ let reloaded_after_crash_session_ids = reloaded_after_crash_session_ids(conn, &command_owner);
let step = match command {
DevToolsCommand::Navigate(command) => {
if Url::parse(&command.url).is_err() {
@@ -1137,9 +1122,9 @@ fn start_protocol_neutral_navigation_command(
start_devtools_page_command(
conn,
background_command_id,
- None,
DevToolsCommand::Navigate(command),
DevToolsNavigationStartOptions {
+ owner: command_owner.clone(),
result_projection,
reloaded_after_crash_session_ids,
allow_background_navigation: wait == DevToolsNavigationWait::None,
@@ -1159,9 +1144,9 @@ fn start_protocol_neutral_navigation_command(
start_devtools_page_command(
conn,
background_command_id,
- None,
DevToolsCommand::Reload(command),
DevToolsNavigationStartOptions {
+ owner: command_owner.clone(),
result_projection,
reloaded_after_crash_session_ids,
allow_background_navigation: wait == DevToolsNavigationWait::None,
@@ -1171,7 +1156,11 @@ fn start_protocol_neutral_navigation_command(
DevToolsCommand::TraverseHistory(mut command) => {
let result_protocol = command.context.protocol;
command.context.session_id = None;
- match resolve_devtools_history_traversal_destination(conn, None, &command.destination) {
+ match resolve_devtools_history_traversal_destination(
+ conn,
+ &command_owner,
+ &command.destination,
+ ) {
Ok(ResolvedDevToolsHistoryTraversal::Noop) => {
return (
PageCommandTaskStep::Complete(CommandOutputPlan::from_devtools_result(
@@ -1203,9 +1192,9 @@ fn start_protocol_neutral_navigation_command(
start_devtools_page_command(
conn,
background_command_id,
- None,
DevToolsCommand::TraverseHistory(command),
DevToolsNavigationStartOptions {
+ owner: command_owner,
result_projection: NavigationResultProjection::new(result_protocol, json!({})),
reloaded_after_crash_session_ids,
allow_background_navigation: wait == DevToolsNavigationWait::None,
@@ -1305,8 +1294,9 @@ fn direct_navigation_result_from_completed_load(
completed: &CompletedNavigateLoadCommand,
result: &mut DirectNavigationResult,
) -> Result<(), DevToolsError> {
- if !conn.accepts_pending_document_navigation_for_session_owner(
- completed.state.navigate_session_id.as_deref(),
+ if !conn.accepts_pending_document_navigation_for_route(
+ completed.state.owner.session_id(),
+ completed.state.owner.session_owner_route(),
&completed.token,
) {
if superseded_cdp_page_navigate_payload(&completed.state).is_some() {
@@ -1408,19 +1398,14 @@ fn fill_navigation_id_from_current_loader_for_route(
if result.navigation_id.is_some() {
return;
}
- let loader_id = {
- let mut route_scope = conn.scoped_none_session_owner_route_override(route.clone());
- route_scope
- .conn_mut()
- .current_document_loader_id_for_session_owner(None)
- };
+ let loader_id = conn.current_document_loader_id_for_route(None, Some(route));
result.ensure_navigation_id_from_loader(loader_id);
}
fn start_devtools_navigate_command(
conn: &mut CdpConnection,
command_id: Option<u64>,
- command_session_id: Option<&str>,
+ owner: &CommandOwnerScope,
command: &DevToolsNavigateCommand,
result_projection: NavigationResultProjection,
allow_background_navigation: bool,
@@ -1429,7 +1414,7 @@ fn start_devtools_navigate_command(
return start_child_frame_navigate_command(
conn,
command_id,
- command_session_id,
+ owner,
frame_id,
command.url.as_str(),
command.wait,
@@ -1441,17 +1426,13 @@ fn start_devtools_navigate_command(
),
);
}
- if session_owner_navigation_is_same_document_fragment(
- conn,
- command_session_id,
- command.url.as_str(),
- ) {
- return start_top_level_same_document_navigate_command(conn, command_session_id, command);
+ if session_owner_navigation_is_same_document_fragment(conn, owner, command.url.as_str()) {
+ return start_top_level_same_document_navigate_command(conn, owner, command);
}
start_navigate_to_url_command_with_background_policy(
conn,
command_id,
- command_session_id,
+ owner,
&command.url,
command.referrer.as_deref(),
result_projection,
@@ -1463,10 +1444,13 @@ fn start_devtools_navigate_command(
fn session_owner_navigation_is_same_document_fragment(
conn: &CdpConnection,
- session_id: Option<&str>,
+ owner: &CommandOwnerScope,
target: &str,
) -> bool {
- let Some(current) = conn.runtime_session_owner_target_url(session_id) else {
+ let Some(current) = conn.runtime_session_owner_target_url_for_route(
+ owner.session_id(),
+ owner.session_owner_route(),
+ ) else {
return false;
};
let (Ok(mut current), Ok(mut target)) = (Url::parse(&current), Url::parse(target)) else {
@@ -1485,7 +1469,7 @@ fn session_owner_navigation_is_same_document_fragment(
fn start_top_level_same_document_navigate_command(
conn: &mut CdpConnection,
- command_session_id: Option<&str>,
+ owner: &CommandOwnerScope,
command: &DevToolsNavigateCommand,
) -> NavigateCommandStart {
let result_payload = protocol_neutral_navigate_result_payload(
@@ -1498,22 +1482,17 @@ fn start_top_level_same_document_navigate_command(
None,
&command.url,
);
- start_top_level_same_document_navigate(
- conn,
- command_session_id,
- command.url.clone(),
- result_payload,
- )
+ start_top_level_same_document_navigate(conn, owner, command.url.clone(), result_payload)
}
fn start_top_level_same_document_navigate(
conn: &mut CdpConnection,
- command_session_id: Option<&str>,
+ owner: &CommandOwnerScope,
url: String,
result_payload: Value,
) -> NavigateCommandStart {
let Some(page) = conn
- .runtime_session_owner_slot_mut(command_session_id)
+ .runtime_session_owner_slot_mut_for_route(owner.session_id(), owner.session_owner_route())
.ok()
.and_then(|slot| slot.loaded_page_mut())
else {
@@ -1550,33 +1529,33 @@ fn child_frame_navigation_target_id<'a>(
fn start_child_frame_navigate_command(
conn: &mut CdpConnection,
_command_id: Option<u64>,
- command_session_id: Option<&str>,
+ owner: &CommandOwnerScope,
frame_id: &str,
url: &str,
wait: DevToolsNavigationWait,
result_payload: Value,
) -> NavigateCommandStart {
- let Some(source_document) =
- conn.target_root_document_lifecycle_identity_for_session(command_session_id)
- else {
+ let Some(source_document) = conn.target_root_document_lifecycle_identity_for_route(
+ owner.session_id(),
+ owner.session_owner_route(),
+ ) else {
return NavigateCommandStart::CompletePlan(CommandOutputPlan::error(
-32000,
"NoDocumentLoaded",
));
};
- let Some(activity_binding) = conn
- .target_root_document_protocol_attachment_identity_for_session(
- command_session_id,
- source_document,
- )
- else {
+ let Some(activity_binding) = conn.target_root_document_protocol_attachment_identity_for_route(
+ owner.session_id(),
+ owner.session_owner_route(),
+ source_document,
+ ) else {
return NavigateCommandStart::CompletePlan(CommandOutputPlan::error(
-32000,
"NoDocumentLoaded",
));
};
let Some(page) = conn
- .runtime_session_owner_slot_mut(command_session_id)
+ .runtime_session_owner_slot_mut_for_route(owner.session_id(), owner.session_owner_route())
.ok()
.and_then(|slot| slot.loaded_page_mut())
else {
@@ -1626,17 +1605,17 @@ pub(super) fn try_start_reload_command_dispatch(
let Some(target_id) = target_id else {
return PageCommandTaskStep::Complete(CommandOutputPlan::error(-31998, "TargetNotLoaded"));
};
- let reloaded_after_crash_session_ids =
- reloaded_after_crash_session_ids_for_session_owner(conn, cmd.session_id);
+ let owner = CommandOwnerScope::capture(conn, cmd.session_id);
+ let reloaded_after_crash_session_ids = reloaded_after_crash_session_ids(conn, &owner);
let shared_command = build_cdp_reload_command(cmd, Some(target_id.as_str()), params);
let result_projection =
NavigationResultProjection::new(shared_command.context.protocol, json!({}));
start_devtools_page_command(
conn,
cmd.id,
- cmd.session_id,
DevToolsCommand::Reload(shared_command),
DevToolsNavigationStartOptions {
+ owner,
result_projection,
reloaded_after_crash_session_ids,
allow_background_navigation: true,
@@ -1660,17 +1639,29 @@ fn build_cdp_reload_command(
fn start_devtools_reload_command(
conn: &mut CdpConnection,
command_id: Option<u64>,
- command_session_id: Option<&str>,
command: &DevToolsReloadCommand,
options: DevToolsNavigationStartOptions,
) -> PageCommandTaskStep {
let context_session_id = command.context.session_id.as_ref().map(|id| id.as_str());
- let command_session_id = command_session_id.or(context_session_id);
- let Some(url) = conn.runtime_session_owner_target_url(command_session_id) else {
+ let owner = if options.owner.session_id().is_none()
+ && options.owner.session_owner_route().is_none()
+ && context_session_id.is_some()
+ {
+ CommandOwnerScope::capture(conn, context_session_id)
+ } else {
+ options.owner
+ };
+ let Some(url) = conn.runtime_session_owner_target_url_for_route(
+ owner.session_id(),
+ owner.session_owner_route(),
+ ) else {
return PageCommandTaskStep::Complete(CommandOutputPlan::error(-31998, "TargetNotLoaded"));
};
if conn
- .mark_next_navigation_history_replace_current_for_session_owner(command_session_id)
+ .mark_next_navigation_history_replace_current_for_route(
+ owner.session_id(),
+ owner.session_owner_route(),
+ )
.is_none()
{
return PageCommandTaskStep::Complete(CommandOutputPlan::error(-31998, "TargetNotLoaded"));
@@ -1678,7 +1669,7 @@ fn start_devtools_reload_command(
let start = start_navigate_to_url_command_with_background_policy(
conn,
command_id,
- command_session_id,
+ &owner,
url.as_str(),
None,
options.result_projection,
@@ -1689,7 +1680,7 @@ fn start_devtools_reload_command(
finish_started_navigation_command_for_parts(
conn,
command_id,
- command_session_id,
+ owner,
start,
&options.reloaded_after_crash_session_ids,
)
@@ -1722,17 +1713,16 @@ pub(super) fn try_start_navigate_to_history_entry_command_dispatch(
let shared_command = build_cdp_traverse_history_command(cmd, None, entry_id, url);
let result_projection =
NavigationResultProjection::new(shared_command.context.protocol, json!({}));
+ let owner = CommandOwnerScope::capture(conn, cmd.session_id);
+ let reloaded_after_crash_session_ids = reloaded_after_crash_session_ids(conn, &owner);
start_devtools_page_command(
conn,
cmd.id,
- cmd.session_id,
DevToolsCommand::TraverseHistory(shared_command),
DevToolsNavigationStartOptions {
+ owner,
result_projection,
- reloaded_after_crash_session_ids: reloaded_after_crash_session_ids_for_session_owner(
- conn,
- cmd.session_id,
- ),
+ reloaded_after_crash_session_ids,
allow_background_navigation: true,
},
)
@@ -1762,11 +1752,14 @@ enum ResolvedDevToolsHistoryTraversal {
fn resolve_devtools_history_traversal_destination(
conn: &mut CdpConnection,
- session_id: Option<&str>,
+ owner: &CommandOwnerScope,
destination: &DevToolsHistoryTraversalDestination,
) -> Result<ResolvedDevToolsHistoryTraversal, DevToolsError> {
- let Some((current_index, entries)) =
- conn.target_session_owner_navigation_history_snapshot(session_id)
+ let Some((current_index, entries)) = conn
+ .target_session_owner_navigation_history_snapshot_for_route(
+ owner.session_id(),
+ owner.session_owner_route(),
+ )
else {
return Err(DevToolsError::new(
DevToolsErrorKind::NoSuchTarget,
@@ -1824,12 +1817,14 @@ fn resolve_devtools_history_traversal_destination(
fn start_same_document_history_traversal_command(
conn: &mut CdpConnection,
command_id: Option<u64>,
- command_session_id: Option<&str>,
delta: i64,
fallback: HistoryTraversalUrlFallback,
) -> PageCommandTaskStep {
let page = conn
- .runtime_session_owner_slot_mut(command_session_id)
+ .runtime_session_owner_slot_mut_for_route(
+ fallback.owner.session_id(),
+ fallback.owner.session_owner_route(),
+ )
.ok()
.and_then(|slot| slot.loaded_page())
.ok_or_else(|| anyhow::anyhow!("TargetNotLoaded"));
@@ -1853,7 +1848,7 @@ fn start_same_document_history_traversal_command(
};
PageCommandTaskStep::Pending(super::PendingPageCommandDispatch {
command_id,
- owner_scope: crate::conn::CommandOwnerScope::capture(conn, command_session_id),
+ owner_scope: fallback.owner.clone(),
kind: Box::new(super::PendingPageCommandKind::TraverseSameDocumentHistory(
Box::new(PendingSameDocumentHistoryTraversalCommand { pending, fallback }),
)),
@@ -1863,7 +1858,6 @@ fn start_same_document_history_traversal_command(
pub(super) fn complete_pending_same_document_history_traversal_command(
conn: &mut CdpConnection,
command_id: Option<u64>,
- session_id: Option<&str>,
completed: CompletedSameDocumentHistoryTraversalCommand,
) -> PageCommandTaskStep {
let CompletedSameDocumentHistoryTraversalCommand {
@@ -1877,7 +1871,10 @@ pub(super) fn complete_pending_same_document_history_traversal_command(
}
};
let result = conn
- .runtime_session_owner_slot_mut(session_id)
+ .runtime_session_owner_slot_mut_for_route(
+ fallback.owner.session_id(),
+ fallback.owner.session_owner_route(),
+ )
.ok()
.and_then(|slot| slot.loaded_page_mut())
.ok_or_else(|| anyhow::anyhow!("TargetNotLoaded"))
@@ -1886,7 +1883,7 @@ pub(super) fn complete_pending_same_document_history_traversal_command(
Ok(true) => PageCommandTaskStep::Complete(CommandOutputPlan::from_devtools_result(
DevToolsCommandResult::Empty,
)),
- Ok(false) => start_history_traversal_url_fallback(conn, command_id, session_id, fallback),
+ Ok(false) => start_history_traversal_url_fallback(conn, command_id, fallback),
Err(error) => {
PageCommandTaskStep::Complete(CommandOutputPlan::error(-32000, error.to_string()))
}
@@ -1896,12 +1893,12 @@ pub(super) fn complete_pending_same_document_history_traversal_command(
fn start_history_traversal_url_fallback(
conn: &mut CdpConnection,
command_id: Option<u64>,
- command_session_id: Option<&str>,
fallback: HistoryTraversalUrlFallback,
) -> PageCommandTaskStep {
let HistoryTraversalUrlFallback {
entry_id,
url,
+ owner,
result_projection,
reloaded_after_crash_session_ids,
allow_background_navigation,
@@ -1909,10 +1906,10 @@ fn start_history_traversal_url_fallback(
start_resolved_history_traversal_command(
conn,
command_id,
- command_session_id,
entry_id,
&url,
DevToolsNavigationStartOptions {
+ owner,
result_projection,
reloaded_after_crash_session_ids,
allow_background_navigation,
@@ -1926,11 +1923,11 @@ pub(super) fn start_session_owner_history_traversal_from_renderer(
session_id: Option<&str>,
delta: i64,
) -> PageCommandTaskStep {
- let reloaded_after_crash_session_ids =
- reloaded_after_crash_session_ids_for_session_owner(conn, session_id);
+ let owner = CommandOwnerScope::capture(conn, session_id);
+ let reloaded_after_crash_session_ids = reloaded_after_crash_session_ids(conn, &owner);
let destination = DevToolsHistoryTraversalDestination::Delta(delta);
let (entry_id, url) =
- match resolve_devtools_history_traversal_destination(conn, session_id, &destination) {
+ match resolve_devtools_history_traversal_destination(conn, &owner, &destination) {
Ok(ResolvedDevToolsHistoryTraversal::Entry { entry_id, url, .. }) => (entry_id, url),
Ok(ResolvedDevToolsHistoryTraversal::Noop) => {
return PageCommandTaskStep::Complete(CommandOutputPlan::success());
@@ -1948,10 +1945,10 @@ pub(super) fn start_session_owner_history_traversal_from_renderer(
start_resolved_history_traversal_command(
conn,
None,
- session_id,
entry_id,
&url,
DevToolsNavigationStartOptions {
+ owner,
result_projection: NavigationResultProjection::Cdp(json!({})),
reloaded_after_crash_session_ids,
allow_background_navigation: false,
@@ -1969,15 +1966,15 @@ enum HistoryTraversalStartSource {
fn start_resolved_history_traversal_command(
conn: &mut CdpConnection,
command_id: Option<u64>,
- command_session_id: Option<&str>,
entry_id: i32,
url: &str,
options: DevToolsNavigationStartOptions,
source: HistoryTraversalStartSource,
) -> PageCommandTaskStep {
if conn
- .mark_next_navigation_history_traverse_to_entry_for_session_owner(
- command_session_id,
+ .mark_next_navigation_history_traverse_to_entry_for_route(
+ options.owner.session_id(),
+ options.owner.session_owner_route(),
entry_id,
)
.is_none()
@@ -1989,6 +1986,7 @@ fn start_resolved_history_traversal_command(
HistoryTraversalStartSource::Renderer => NavigationStartInitiator::Renderer,
};
let DevToolsNavigationStartOptions {
+ owner,
result_projection,
reloaded_after_crash_session_ids,
allow_background_navigation,
@@ -1996,7 +1994,7 @@ fn start_resolved_history_traversal_command(
let start = start_navigate_to_url_command_with_background_policy(
conn,
command_id,
- command_session_id,
+ &owner,
url,
None,
result_projection,
@@ -2007,7 +2005,7 @@ fn start_resolved_history_traversal_command(
finish_started_navigation_command_for_parts(
conn,
command_id,
- command_session_id,
+ owner,
start,
&reloaded_after_crash_session_ids,
)
@@ -2016,15 +2014,19 @@ fn start_resolved_history_traversal_command(
fn start_devtools_traverse_history_command(
conn: &mut CdpConnection,
command_id: Option<u64>,
- command_session_id: Option<&str>,
command: &DevToolsTraverseHistoryCommand,
- options: DevToolsNavigationStartOptions,
+ mut options: DevToolsNavigationStartOptions,
) -> PageCommandTaskStep {
let context_session_id = command.context.session_id.as_ref().map(|id| id.as_str());
- let command_session_id = command_session_id.or(context_session_id);
+ if options.owner.session_id().is_none()
+ && options.owner.session_owner_route().is_none()
+ && context_session_id.is_some()
+ {
+ options.owner = CommandOwnerScope::capture(conn, context_session_id);
+ }
let (entry_id, url, same_document_delta) = match resolve_devtools_history_traversal_destination(
conn,
- command_session_id,
+ &options.owner,
&command.destination,
) {
Ok(ResolvedDevToolsHistoryTraversal::Noop) => {
@@ -2045,25 +2047,20 @@ fn start_devtools_traverse_history_command(
let fallback = HistoryTraversalUrlFallback {
entry_id,
url,
+ owner: options.owner,
result_projection: options.result_projection,
reloaded_after_crash_session_ids: options.reloaded_after_crash_session_ids,
allow_background_navigation: options.allow_background_navigation,
};
- return start_same_document_history_traversal_command(
- conn,
- command_id,
- command_session_id,
- delta,
- fallback,
- );
+ return start_same_document_history_traversal_command(conn, command_id, delta, fallback);
}
start_history_traversal_url_fallback(
conn,
command_id,
- command_session_id,
HistoryTraversalUrlFallback {
entry_id,
url,
+ owner: options.owner,
result_projection: options.result_projection,
reloaded_after_crash_session_ids: options.reloaded_after_crash_session_ids,
allow_background_navigation: options.allow_background_navigation,
@@ -2074,7 +2071,7 @@ fn start_devtools_traverse_history_command(
pub(super) fn finish_started_navigation_command_for_parts(
conn: &mut CdpConnection,
command_id: Option<u64>,
- command_session_id: Option<&str>,
+ owner: CommandOwnerScope,
mut start: NavigateCommandStart,
reloaded_after_crash_session_ids: &[Option<String>],
) -> PageCommandTaskStep {
@@ -2084,14 +2081,14 @@ pub(super) fn finish_started_navigation_command_for_parts(
clear_crash_state_after_navigation_into_plan(
conn,
plan,
- command_session_id,
+ &owner,
reloaded_after_crash_session_ids,
)
}
NavigateCommandStart::PendingLoad(pending) => clear_crash_state_after_navigation(
conn,
&mut pending.prefix_events,
- command_session_id,
+ &owner,
reloaded_after_crash_session_ids,
),
NavigateCommandStart::PendingChildFrame(_) => {}
@@ -2100,7 +2097,7 @@ pub(super) fn finish_started_navigation_command_for_parts(
clear_crash_state_after_navigation(
conn,
&mut pending.prefix_events,
- command_session_id,
+ &owner,
reloaded_after_crash_session_ids,
)
}
@@ -2111,28 +2108,28 @@ pub(super) fn finish_started_navigation_command_for_parts(
NavigateCommandStart::PendingLoad(pending) => {
PageCommandTaskStep::Pending(super::PendingPageCommandDispatch {
command_id,
- owner_scope: crate::conn::CommandOwnerScope::capture(conn, command_session_id),
+ owner_scope: owner.clone(),
kind: Box::new(super::PendingPageCommandKind::Navigate(pending)),
})
}
NavigateCommandStart::PendingChildFrame(pending) => {
PageCommandTaskStep::Pending(super::PendingPageCommandDispatch {
command_id,
- owner_scope: crate::conn::CommandOwnerScope::capture(conn, command_session_id),
+ owner_scope: owner.clone(),
kind: Box::new(super::PendingPageCommandKind::ChildFrameNavigate(pending)),
})
}
NavigateCommandStart::PendingSameDocument(pending) => {
PageCommandTaskStep::Pending(super::PendingPageCommandDispatch {
command_id,
- owner_scope: crate::conn::CommandOwnerScope::capture(conn, command_session_id),
+ owner_scope: owner.clone(),
kind: Box::new(super::PendingPageCommandKind::SameDocumentNavigate(pending)),
})
}
NavigateCommandStart::PendingContinueWithoutRequestPause(pending) => {
PageCommandTaskStep::Pending(super::PendingPageCommandDispatch {
command_id,
- owner_scope: crate::conn::CommandOwnerScope::capture(conn, command_session_id),
+ owner_scope: owner,
kind: Box::new(
super::PendingPageCommandKind::ContinueNavigationWithoutRequestPause(pending),
),
@@ -2143,15 +2140,15 @@ pub(super) fn finish_started_navigation_command_for_parts(
pub(super) fn start_session_owner_navigation_from_renderer(
conn: &mut CdpConnection,
- session_id: Option<&str>,
+ owner: &CommandOwnerScope,
url: &str,
request_method: &str,
request_body: Option<&[u8]>,
request_headers: &[(String, String)],
browser_navigation_kind: moli_fetch::BrowserNavigationRequestKind,
) -> NavigateCommandStart {
- let reloaded_after_crash_session_ids =
- reloaded_after_crash_session_ids_for_session_owner(conn, session_id);
+ let session_id = owner.session_id();
+ let reloaded_after_crash_session_ids = reloaded_after_crash_session_ids(conn, owner);
let result_payload = cdp_navigate_result_payload(
None,
conn.runtime_session_owner_frame_id(session_id).as_deref(),
@@ -2159,19 +2156,19 @@ pub(super) fn start_session_owner_navigation_from_renderer(
url,
);
let start = if request_method.eq_ignore_ascii_case("GET")
- && session_owner_navigation_is_same_document_fragment(conn, session_id, url)
+ && session_owner_navigation_is_same_document_fragment(conn, owner, url)
{
// A renderer-owned top-level navigation follows the same fragment
// classification as Page.navigate. In particular, a freshly created
// popup's `about:blank#fragment` target must not discard its initial
// Document by trying to fetch the non-fetchable about: URL.
- start_top_level_same_document_navigate(conn, session_id, url.to_owned(), result_payload)
+ start_top_level_same_document_navigate(conn, owner, url.to_owned(), result_payload)
} else {
let result_projection = NavigationResultProjection::Cdp(result_payload);
start_navigate_to_url_command_with_background_policy_and_request(
conn,
None,
- session_id,
+ owner,
url,
None,
result_projection,
@@ -2202,12 +2199,7 @@ pub(super) fn start_session_owner_navigation_from_renderer(
NavigationStartInitiator::Renderer,
)
};
- clear_crash_state_for_renderer_navigation(
- conn,
- start,
- session_id,
- &reloaded_after_crash_session_ids,
- )
+ clear_crash_state_for_renderer_navigation(conn, start, owner, &reloaded_after_crash_session_ids)
}
#[cfg(test)]
@@ -2596,7 +2588,7 @@ pub(super) fn try_start_reset_navigation_history_command(
pub(super) fn complete_reset_navigation_history_command(
conn: &mut CdpConnection,
- session_id: Option<&str>,
+ owner: &CommandOwnerScope,
completed: Result<CompletedPageCommand, String>,
) -> PageCommandTaskStep {
let completion = match completed {
@@ -2606,7 +2598,7 @@ pub(super) fn complete_reset_navigation_history_command(
}
};
let Some(page) = conn
- .runtime_session_owner_slot_mut(session_id)
+ .runtime_session_owner_slot_mut_for_route(owner.session_id(), owner.session_owner_route())
.ok()
.and_then(|slot| slot.loaded_page_mut())
else {
@@ -2627,7 +2619,7 @@ pub(super) fn complete_reset_navigation_history_command(
));
}
}
- match conn.reset_navigation_history_for_session_owner(session_id) {
+ match conn.reset_navigation_history_for_route(owner.session_id(), owner.session_owner_route()) {
Some(true) => PageCommandTaskStep::Complete(CommandOutputPlan::success()),
Some(false) => PageCommandTaskStep::Complete(CommandOutputPlan::error(
-32000,
@@ -2637,17 +2629,17 @@ pub(super) fn complete_reset_navigation_history_command(
}
}
-fn reloaded_after_crash_session_ids_for_session_owner(
+fn reloaded_after_crash_session_ids(
conn: &CdpConnection,
- session_id: Option<&str>,
+ owner: &CommandOwnerScope,
) -> Vec<Option<String>> {
if !conn
- .target_owner_state_for_session(session_id)
+ .target_owner_state_for_route(owner.session_id(), owner.session_owner_route())
.is_some_and(|owner_state| owner_state.target_crash_state.is_crashed())
{
return Vec::new();
}
- conn.page_event_session_ids_for_session_owner(session_id)
+ conn.page_event_session_ids_for_route(owner.session_id(), owner.session_owner_route())
.into_iter()
.filter(|event_session_id| {
conn.target_runtime_session_state_for_session(event_session_id.as_deref())
@@ -2659,12 +2651,16 @@ fn reloaded_after_crash_session_ids_for_session_owner(
fn clear_crash_state_after_navigation(
conn: &mut CdpConnection,
out: &mut Vec<BackgroundProtocolEvent>,
- owner_session_id: Option<&str>,
+ owner: &CommandOwnerScope,
reloaded_after_crash_session_ids: &[Option<String>],
) {
- let _ = conn.with_target_owner_state_for_session_mut(owner_session_id, |owner_state| {
- owner_state.target_crash_state.clear();
- });
+ let _ = conn.with_target_owner_state_for_route_mut(
+ owner.session_id(),
+ owner.session_owner_route(),
+ |owner_state| {
+ owner_state.target_crash_state.clear();
+ },
+ );
for session_id in reloaded_after_crash_session_ids {
out.push(inspector_target_reloaded_after_crash_event(
session_id.as_deref(),
@@ -2675,12 +2671,16 @@ fn clear_crash_state_after_navigation(
fn clear_crash_state_after_navigation_into_plan(
conn: &mut CdpConnection,
plan: &mut CommandOutputPlan,
- owner_session_id: Option<&str>,
+ owner: &CommandOwnerScope,
reloaded_after_crash_session_ids: &[Option<String>],
) {
- let _ = conn.with_target_owner_state_for_session_mut(owner_session_id, |owner_state| {
- owner_state.target_crash_state.clear();
- });
+ let _ = conn.with_target_owner_state_for_route_mut(
+ owner.session_id(),
+ owner.session_owner_route(),
+ |owner_state| {
+ owner_state.target_crash_state.clear();
+ },
+ );
for session_id in reloaded_after_crash_session_ids {
plan.push_background_event(inspector_target_reloaded_after_crash_event(
session_id.as_deref(),
@@ -2697,7 +2697,7 @@ fn inspector_target_reloaded_after_crash_event(
fn clear_crash_state_for_renderer_navigation(
conn: &mut CdpConnection,
mut start: NavigateCommandStart,
- owner_session_id: Option<&str>,
+ owner: &CommandOwnerScope,
reloaded_after_crash_session_ids: &[Option<String>],
) -> NavigateCommandStart {
match &mut start {
@@ -2706,14 +2706,14 @@ fn clear_crash_state_for_renderer_navigation(
clear_crash_state_after_navigation_into_plan(
conn,
plan,
- owner_session_id,
+ owner,
reloaded_after_crash_session_ids,
)
}
NavigateCommandStart::PendingLoad(pending) => clear_crash_state_after_navigation(
conn,
&mut pending.prefix_events,
- owner_session_id,
+ owner,
reloaded_after_crash_session_ids,
),
NavigateCommandStart::PendingChildFrame(_) => {}
@@ -2722,7 +2722,7 @@ fn clear_crash_state_for_renderer_navigation(
clear_crash_state_after_navigation(
conn,
&mut pending.prefix_events,
- owner_session_id,
+ owner,
reloaded_after_crash_session_ids,
)
}
@@ -2730,31 +2730,10 @@ fn clear_crash_state_for_renderer_navigation(
start
}
-pub(super) fn start_navigate_to_url_command(
- conn: &mut CdpConnection,
- command_id: Option<u64>,
- command_session_id: Option<&str>,
- url: &str,
- referrer: Option<&str>,
- result_payload: Value,
-) -> NavigateCommandStart {
- start_navigate_to_url_command_with_background_policy(
- conn,
- command_id,
- command_session_id,
- url,
- referrer,
- NavigationResultProjection::Cdp(result_payload),
- true,
- NavigationRequestLoadPolicy::BrowserInitiated,
- NavigationStartInitiator::Browser,
- )
-}
-
fn start_navigate_to_url_command_with_background_policy(
conn: &mut CdpConnection,
command_id: Option<u64>,
- command_session_id: Option<&str>,
+ owner: &CommandOwnerScope,
url: &str,
referrer: Option<&str>,
result_projection: NavigationResultProjection,
@@ -2765,7 +2744,7 @@ fn start_navigate_to_url_command_with_background_policy(
start_navigate_to_url_command_with_background_policy_and_request(
conn,
command_id,
- command_session_id,
+ owner,
url,
referrer,
result_projection,
@@ -2792,7 +2771,7 @@ fn overlay_navigation_request_headers(
fn start_navigate_to_url_command_with_background_policy_and_request(
conn: &mut CdpConnection,
command_id: Option<u64>,
- command_session_id: Option<&str>,
+ owner: &CommandOwnerScope,
url: &str,
referrer: Option<&str>,
result_projection: NavigationResultProjection,
@@ -2803,6 +2782,8 @@ fn start_navigate_to_url_command_with_background_policy_and_request(
request_load_policy: NavigationRequestLoadPolicy,
initiator: NavigationStartInitiator,
) -> NavigateCommandStart {
+ let command_session_id = owner.session_id();
+ let owner_route = owner.session_owner_route();
let mut out = Vec::new();
let timestamp = monotonic_timestamp_seconds();
let mut fetch_request_stage = FetchRequestStage::Request;
@@ -2818,8 +2799,9 @@ fn start_navigate_to_url_command_with_background_policy_and_request(
error.to_string(),
));
}
- let mut navigation_preflight = conn.prepare_navigation_request_for_session_owner(
+ let mut navigation_preflight = conn.prepare_navigation_request_for_route(
command_session_id,
+ owner_route,
&requested_url,
referrer,
url.starts_with("data:"),
@@ -2828,10 +2810,8 @@ fn start_navigate_to_url_command_with_background_policy_and_request(
.as_ref()
.map(|preflight| preflight.frame_id.clone())
.or_else(|| {
- conn.browser_context
- .as_ref()
- .and_then(|bc| bc.active_target_id())
- .map(str::to_owned)
+ conn.target_owner_identity_for_route(command_session_id, owner_route)
+ .and_then(|(_, target_id)| target_id)
})
.unwrap_or_else(|| "FRAME-0".to_owned());
let session_id = command_session_id.map(str::to_owned).or_else(|| {
@@ -2853,7 +2833,7 @@ fn start_navigate_to_url_command_with_background_policy_and_request(
.unwrap_or_else(|| "Secure".to_owned());
let mut navigation_state = NavigationDispatchState {
navigate_id: command_id,
- navigate_session_id: command_session_id.map(str::to_owned),
+ owner: owner.clone(),
result_projection,
frame_id: frame_id.clone(),
session_id: None,
@@ -2928,8 +2908,9 @@ fn start_navigate_to_url_command_with_background_policy_and_request(
}
let navigation_loader_id = navigation_state.loader_id.as_str();
- let document_navigation_token = conn.start_document_navigation_for_session_owner(
+ let document_navigation_token = conn.start_document_navigation_for_route(
command_session_id,
+ owner_route,
navigation_loader_id.to_owned(),
);
let Some(document_navigation_token) = document_navigation_token else {
@@ -2945,7 +2926,7 @@ fn start_navigate_to_url_command_with_background_policy_and_request(
emit_navigation_started_for_session_owner(
conn,
&mut out,
- command_session_id,
+ owner,
&frame_id,
navigation_loader_id,
url,
@@ -2955,7 +2936,7 @@ fn start_navigate_to_url_command_with_background_policy_and_request(
send_background_navigation_started(
conn,
document_navigation_token.clone(),
- session_id.as_deref(),
+ owner,
&frame_id,
navigation_loader_id,
url,
@@ -2965,7 +2946,7 @@ fn start_navigate_to_url_command_with_background_policy_and_request(
emit_navigation_started_for_session_owner(
conn,
&mut out,
- command_session_id,
+ owner,
&frame_id,
navigation_loader_id,
url,
@@ -2975,9 +2956,9 @@ fn start_navigate_to_url_command_with_background_policy_and_request(
if let Some(mut pending) = pending_fetch_navigation {
if fetch_request_stage == FetchRequestStage::Request {
- pending.request_cookie_report = navigation_cookie_access_report(
+ pending.request_cookie_report = navigation_cookie_access_report_for_owner(
conn,
- pending.navigation.navigate_session_id.as_deref(),
+ &pending.navigation.owner,
&pending.navigation.requested_url,
&pending.navigation.request_method,
None,
@@ -2993,8 +2974,9 @@ fn start_navigate_to_url_command_with_background_policy_and_request(
);
}
pending.navigation.request_announced = pending.navigation.request_id.is_some();
- let _ = conn.register_pending_fetch_navigation_request_for_session_owner(
- pending.navigation.navigate_session_id.as_deref(),
+ let _ = conn.register_pending_fetch_navigation_request_for_route(
+ pending.navigation.owner.session_id(),
+ pending.navigation.owner.session_owner_route(),
pending.clone(),
);
out.push(fetch::request_paused_background_event(
@@ -3006,9 +2988,9 @@ fn start_navigate_to_url_command_with_background_policy_and_request(
return NavigateCommandStart::CompleteImmediate(output.into_plan());
}
if pending.navigation.request_id.is_some() {
- pending.request_cookie_report = navigation_cookie_access_report(
+ pending.request_cookie_report = navigation_cookie_access_report_for_owner(
conn,
- pending.navigation.navigate_session_id.as_deref(),
+ &pending.navigation.owner,
&pending.navigation.requested_url,
&pending.navigation.request_method,
None,
@@ -3033,12 +3015,12 @@ fn start_navigate_to_url_command_with_background_policy_and_request(
if allow_background_navigation
&& let Some(sender) =
- conn.background_navigation_completion_sender_for_session_owner(command_session_id)
+ conn.background_navigation_completion_sender_for_route(command_session_id, owner_route)
{
let body_progress_source = if navigation_state.request_id.is_some() {
- let request_cookie_report = navigation_cookie_access_report(
+ let request_cookie_report = navigation_cookie_access_report_for_owner(
conn,
- navigation_state.navigate_session_id.as_deref(),
+ &navigation_state.owner,
&navigation_state.requested_url,
&navigation_state.request_method,
None,
@@ -3061,7 +3043,7 @@ fn start_navigate_to_url_command_with_background_policy_and_request(
crate::conn::BackgroundNavigationEarlyResult::new(
sender,
navigate_id,
- completion_state.navigate_session_id.clone(),
+ completion_state.owner.session_id().map(str::to_owned),
completion_state.result_projection.payload().clone(),
)
})
@@ -3077,18 +3059,11 @@ fn start_navigate_to_url_command_with_background_policy_and_request(
"NavigationRequestNotCurrent",
));
};
- let none_session_owner_route = crate::conn::CommandOwnerScope::capture(
- conn,
- completion_state.navigate_session_id.as_deref(),
- )
- .session_owner_route()
- .cloned();
tokio::task::spawn_local(async move {
let body_completion_sink = crate::conn::BackgroundNavigationBodyCompletionSink::new(
sender.clone(),
document_navigation_token.clone(),
completion_state.clone(),
- none_session_owner_route.clone(),
);
let (engine, navigation, early_result_sent) = job.run(Some(body_completion_sink)).await;
if early_result_sent {
@@ -3104,7 +3079,6 @@ fn start_navigate_to_url_command_with_background_policy_and_request(
let _ = sender.send(BackgroundNavigationCompletion::new(
document_navigation_token,
completion_state,
- none_session_owner_route,
engine,
navigation,
));
@@ -3115,9 +3089,9 @@ fn start_navigate_to_url_command_with_background_policy_and_request(
}
let body_progress_source = if navigation_state.request_id.is_some() {
- let request_cookie_report = navigation_cookie_access_report(
+ let request_cookie_report = navigation_cookie_access_report_for_owner(
conn,
- navigation_state.navigate_session_id.as_deref(),
+ &navigation_state.owner,
&navigation_state.requested_url,
&navigation_state.request_method,
None,
@@ -3156,22 +3130,28 @@ fn start_navigate_to_url_command_with_background_policy_and_request(
pub(super) fn start_initial_document_navigation_for_session_owner(
conn: &mut CdpConnection,
command_id: Option<u64>,
- command_session_id: Option<&str>,
+ owner: &CommandOwnerScope,
result_payload: Value,
) -> Result<NavigateCommandStart, CommandOutputPlan> {
- let Some(url) = conn.runtime_session_owner_target_url(command_session_id) else {
+ let Some(url) = conn.runtime_session_owner_target_url_for_route(
+ owner.session_id(),
+ owner.session_owner_route(),
+ ) else {
if conn.browser_context.is_none() {
return Err(CommandOutputPlan::error(-31998, "BrowserContextNotLoaded"));
}
return Err(CommandOutputPlan::error(-31998, "TargetNotLoaded"));
};
- Ok(start_navigate_to_url_command(
+ Ok(start_navigate_to_url_command_with_background_policy(
conn,
command_id,
- command_session_id,
+ owner,
url.as_str(),
None,
- result_payload,
+ NavigationResultProjection::Cdp(result_payload),
+ true,
+ NavigationRequestLoadPolicy::BrowserInitiated,
+ NavigationStartInitiator::Browser,
))
}
@@ -3187,8 +3167,9 @@ pub(super) async fn complete_pending_navigate_load_command(
engine,
navigation,
} = completed;
- let is_current = conn.accepts_pending_document_navigation_for_session_owner(
- state.navigate_session_id.as_deref(),
+ let is_current = conn.accepts_pending_document_navigation_for_route(
+ state.owner.session_id(),
+ state.owner.session_owner_route(),
&token,
);
let should_retain_engine = is_current
@@ -3216,7 +3197,7 @@ pub(super) async fn complete_pending_navigate_load_command(
pub(super) async fn complete_pending_child_frame_navigate_command(
conn: &mut CdpConnection,
- command_session_id: Option<&str>,
+ owner: &CommandOwnerScope,
completed: CompletedChildFrameNavigateCommand,
command_context: &mut CommandDispatchContext,
) -> PageCommandTaskStep {
@@ -3239,7 +3220,10 @@ pub(super) async fn complete_pending_child_frame_navigate_command(
};
let (navigated, renderer_output) = {
let Some(page) = conn
- .runtime_session_owner_slot_mut(command_session_id)
+ .runtime_session_owner_slot_mut_for_route(
+ owner.session_id(),
+ owner.session_owner_route(),
+ )
.ok()
.and_then(|slot| slot.loaded_page_mut())
else {
@@ -3261,8 +3245,8 @@ pub(super) async fn complete_pending_child_frame_navigate_command(
}
if wait != DevToolsNavigationWait::None {
- let child_gate = match conn.start_child_frame_lifecycle_work_for_session_owner(
- command_session_id,
+ let child_gate = match conn.start_child_frame_lifecycle_work_for_owner(
+ owner.clone(),
CHILD_FRAME_NAVIGATION_LOAD_GATE_TIMEOUT,
) {
Ok(pending) => pending,
@@ -3310,7 +3294,7 @@ pub(super) async fn complete_pending_child_frame_navigate_command(
pub(super) async fn complete_pending_same_document_navigate_command(
conn: &mut CdpConnection,
- command_session_id: Option<&str>,
+ owner: &CommandOwnerScope,
completed: CompletedSameDocumentNavigateCommand,
command_context: &mut CommandDispatchContext,
) -> PageCommandTaskStep {
@@ -3326,7 +3310,10 @@ pub(super) async fn complete_pending_same_document_navigate_command(
};
let (navigated, output) = {
let Some(page) = conn
- .runtime_session_owner_slot_mut(command_session_id)
+ .runtime_session_owner_slot_mut_for_route(
+ owner.session_id(),
+ owner.session_owner_route(),
+ )
.ok()
.and_then(|slot| slot.loaded_page_mut())
else {
@@ -3378,13 +3365,34 @@ pub(crate) async fn complete_materialized_navigation_into_buffer_async(
navigation: network::MaterializedNavigationLoadOutcome,
command_context: &mut crate::conn::CommandDispatchContext,
) {
- let navigation_session_id = state.navigate_session_id.clone();
+ let owner = state.owner.clone();
+ let mut route_scope = owner.enter(conn);
+ complete_materialized_navigation_into_buffer_inner_async(
+ route_scope.conn_mut(),
+ out,
+ token,
+ state,
+ navigation,
+ command_context,
+ )
+ .await;
+}
+
+async fn complete_materialized_navigation_into_buffer_inner_async(
+ conn: &mut CdpConnection,
+ out: &mut CommandOutputBuffer,
+ token: DocumentNavigationToken,
+ state: NavigationDispatchState,
+ navigation: network::MaterializedNavigationLoadOutcome,
+ command_context: &mut crate::conn::CommandDispatchContext,
+) {
+ let navigation_session_id = state.owner.session_id().map(str::to_owned);
let navigation_loader_id = state.loader_id.clone();
match navigation {
network::MaterializedNavigationLoadOutcome::ResponseCommitReady(navigation) => {
let navigation = *navigation;
let update_result = match conn.prepared_document_commit_configuration_for_session_owner(
- state.navigate_session_id.as_deref(),
+ state.owner.session_id(),
navigation.final_url(),
) {
Ok(configuration) => navigation.update_commit_configuration(configuration).await,
@@ -3395,13 +3403,13 @@ pub(crate) async fn complete_materialized_navigation_into_buffer_async(
} else {
let renderer_page = navigation.renderer_page_residence_identity();
let candidate = conn.prepare_renderer_agent_candidate_token_for_session_owner(
- state.navigate_session_id.as_deref(),
+ state.owner.session_id(),
&token,
navigation.renderer_devtools_agent_token(),
);
match candidate.and_then(|candidate| {
conn.commit_renderer_agent_candidate_for_session_owner(
- state.navigate_session_id.as_deref(),
+ state.owner.session_id(),
candidate,
renderer_page,
)
@@ -3427,13 +3435,13 @@ pub(crate) async fn complete_materialized_navigation_into_buffer_async(
Err(error) => {
if let Err(rollback_error) = conn
.rollback_committed_renderer_agent_candidate_for_session_owner(
- state.navigate_session_id.as_deref(),
+ state.owner.session_id(),
transaction,
)
{
tracing::warn!(
%rollback_error,
- session_id = state.navigate_session_id.as_deref(),
+ session_id = state.owner.session_id(),
"failed to roll back renderer channel after prepared document commit failure"
);
}
@@ -3444,7 +3452,7 @@ pub(crate) async fn complete_materialized_navigation_into_buffer_async(
Err(error) => {
tracing::debug!(
%error,
- session_id = state.navigate_session_id.as_deref(),
+ session_id = state.owner.session_id(),
loader_id = token.loader_id,
"dropping superseded response commit-ready navigation"
);
@@ -3467,13 +3475,13 @@ pub(crate) async fn complete_materialized_navigation_into_buffer_async(
}
network::MaterializedNavigationLoadOutcome::Download(navigation) => {
let _ = conn.clear_pending_navigation_history_update_for_session_owner(
- state.navigate_session_id.as_deref(),
+ state.owner.session_id(),
);
commit_download_navigation_async(conn, out, state, navigation, command_context).await;
}
network::MaterializedNavigationLoadOutcome::Failed(navigation) => {
let _ = conn.clear_pending_navigation_history_update_for_session_owner(
- state.navigate_session_id.as_deref(),
+ state.owner.session_id(),
);
let network::MaterializedFailedDocumentProgress {
error_text,
@@ -3484,7 +3492,7 @@ pub(crate) async fn complete_materialized_navigation_into_buffer_async(
if document_policy.invalidates_committed_document() {
let _ = conn
.discard_loaded_page_after_failed_navigation_for_session_owner_async(
- state.navigate_session_id.as_deref(),
+ state.owner.session_id(),
&state.requested_url,
)
.await;
@@ -3553,7 +3561,7 @@ fn push_navigation_commit_error(
} else {
tracing::warn!(
%error,
- session_id = state.navigate_session_id.as_deref(),
+ session_id = state.owner.session_id(),
"navigation commit failed after early Page.navigate result"
);
}
@@ -3727,13 +3735,14 @@ mod child_frame_attachment_tests {
);
let command =
build_cdp_navigate_command(&cmd, Some("TID-2"), "not a valid navigation url", None);
+ let owner = crate::conn::CommandOwnerScope::capture(&conn, cmd.session_id);
let step = start_devtools_page_command(
&mut conn,
cmd.id,
- cmd.session_id,
DevToolsCommand::Navigate(command),
DevToolsNavigationStartOptions {
+ owner,
result_projection: NavigationResultProjection::Cdp(json!({})),
reloaded_after_crash_session_ids: Vec::new(),
allow_background_navigation: true,
@@ -3798,13 +3807,14 @@ mod child_frame_attachment_tests {
r#"{"id":14,"method":"Page.reload"}"#,
);
let command = build_cdp_reload_command(&cmd, Some("TID-4"), Default::default());
+ let owner = crate::conn::CommandOwnerScope::capture(&conn, cmd.session_id);
let step = start_devtools_page_command(
&mut conn,
cmd.id,
- cmd.session_id,
DevToolsCommand::Reload(command),
DevToolsNavigationStartOptions {
+ owner,
result_projection: NavigationResultProjection::Cdp(json!({})),
reloaded_after_crash_session_ids: Vec::new(),
allow_background_navigation: true,
@@ -3874,13 +3884,14 @@ mod child_frame_attachment_tests {
9,
"https://example.test/history".to_owned(),
);
+ let owner = crate::conn::CommandOwnerScope::capture(&conn, cmd.session_id);
let step = start_devtools_page_command(
&mut conn,
cmd.id,
- cmd.session_id,
DevToolsCommand::TraverseHistory(command),
DevToolsNavigationStartOptions {
+ owner,
result_projection: NavigationResultProjection::Cdp(json!({})),
reloaded_after_crash_session_ids: Vec::new(),
allow_background_navigation: true,
diff --git a/moli-protocol/src/domains/page/navigation_commit.rs b/moli-protocol/src/domains/page/navigation_commit.rs
index 8c8f56269..98903553f 100644
--- a/moli-protocol/src/domains/page/navigation_commit.rs
+++ b/moli-protocol/src/domains/page/navigation_commit.rs
@@ -55,7 +55,7 @@ pub(super) async fn commit_loaded_navigation_async(
out.push_error_after_messages(-32000, error);
} else {
tracing::warn!(
- session_id = state.navigate_session_id.as_deref(),
+ session_id = state.owner.session_id(),
loader_id = state.loader_id,
"{error} after early Page.navigate result"
);
@@ -63,7 +63,7 @@ pub(super) async fn commit_loaded_navigation_async(
return;
};
let is_network_error_page = network_error_page.is_some();
- let navigation_session_id = state.navigate_session_id.clone();
+ let navigation_session_id = state.owner.session_id().map(str::to_owned);
let (page_creation_artifacts, mut deferred_initial_renderer_document_lifecycle_events) =
split_renderer_page_creation_lifecycle_at_load_boundary(page_creation_artifacts);
let mut navigation_activity = MainDocumentNavigationActivity::new(
@@ -110,7 +110,7 @@ pub(super) async fn commit_loaded_navigation_async(
} = commit;
let (renderer_document_binding, mut initial_renderer_document_lifecycle_events) = conn
.bind_renderer_document_lifecycle_for_session_owner(
- navigation_activity.state().navigate_session_id.as_deref(),
+ navigation_activity.state().owner.session_id(),
page_creation_artifacts,
token.cloned(),
navigation_activity.state().frame_id.clone(),
@@ -118,7 +118,7 @@ pub(super) async fn commit_loaded_navigation_async(
);
let load_visibility_barrier_armed = renderer_document_binding.is_some()
&& conn.begin_renderer_document_load_visibility_barrier_for_session_owner(
- navigation_activity.state().navigate_session_id.as_deref(),
+ navigation_activity.state().owner.session_id(),
&navigation_activity.state().loader_id,
);
if load_visibility_barrier_armed {
@@ -128,7 +128,7 @@ pub(super) async fn commit_loaded_navigation_async(
// finishes installing this binding. Never read the Page back here:
// ordered ingress and the commit cursor preserve that handoff.
let (_, visible_events) = conn.ingest_renderer_document_lifecycle_events_for_session_owner(
- navigation_activity.state().navigate_session_id.as_deref(),
+ navigation_activity.state().owner.session_id(),
std::mem::take(&mut deferred_initial_renderer_document_lifecycle_events),
);
initial_renderer_document_lifecycle_events.extend(visible_events);
@@ -266,12 +266,11 @@ async fn restore_and_commit_loaded_navigation_page_async(
if let Some(transaction) = committed_renderer_attachment.as_ref() {
if token != Some(transaction.navigation())
|| transaction.current().agent_token() != page_agent_token
- || conn.current_renderer_agent_attachment_id_for_session_owner(
- state.navigate_session_id.as_deref(),
- ) != Some(transaction.current().id())
+ || conn.current_renderer_agent_attachment_id_for_session_owner(state.owner.session_id())
+ != Some(transaction.current().id())
{
tracing::warn!(
- session_id = state.navigate_session_id.as_deref(),
+ session_id = state.owner.session_id(),
"prepared navigation Page does not match its committed renderer attachment"
);
return None;
@@ -281,7 +280,7 @@ async fn restore_and_commit_loaded_navigation_page_async(
let renderer_agent_candidate = match (token, committed_renderer_attachment.as_ref()) {
(Some(token), None) => {
match conn.prepare_renderer_agent_candidate_for_session_owner(
- state.navigate_session_id.as_deref(),
+ state.owner.session_id(),
token,
&mut page,
) {
@@ -289,7 +288,7 @@ async fn restore_and_commit_loaded_navigation_page_async(
Err(error) => {
tracing::debug!(
%error,
- session_id = state.navigate_session_id.as_deref(),
+ session_id = state.owner.session_id(),
loader_id = token.loader_id,
"dropping superseded renderer navigation candidate before commit"
);
@@ -299,8 +298,8 @@ async fn restore_and_commit_loaded_navigation_page_async(
}
_ => None,
};
- let Some(commit_state) = conn
- .prepare_loaded_navigation_commit_for_session_owner(state.navigate_session_id.as_deref())
+ let Some(commit_state) =
+ conn.prepare_loaded_navigation_commit_for_session_owner(state.owner.session_id())
else {
return Some(outcome);
};
@@ -353,7 +352,7 @@ async fn restore_and_commit_loaded_navigation_page_async(
// lifecycle events that will never arrive.
tracing::warn!(
%error,
- session_id = state.navigate_session_id.as_deref(),
+ session_id = state.owner.session_id(),
"navigation commit failed after early Page.navigate result: runtime protocol state restore"
);
}
@@ -393,7 +392,7 @@ async fn restore_and_commit_loaded_navigation_page_async(
} else {
tracing::warn!(
%error,
- session_id = state.navigate_session_id.as_deref(),
+ session_id = state.owner.session_id(),
"navigation commit failed after early Page.navigate result: fetch interception state restore"
);
}
@@ -427,7 +426,7 @@ async fn restore_and_commit_loaded_navigation_page_async(
} else {
tracing::warn!(
%error,
- session_id = state.navigate_session_id.as_deref(),
+ session_id = state.owner.session_id(),
"navigation commit failed after early Page.navigate result: permission overrides apply"
);
}
@@ -449,7 +448,7 @@ async fn restore_and_commit_loaded_navigation_page_async(
let page_commit_started = timing_enabled.then(std::time::Instant::now);
let page_commit = match conn
.commit_loaded_navigation_page_for_session_owner_async(
- state.navigate_session_id.as_deref(),
+ state.owner.session_id(),
page,
match committed_renderer_attachment {
Some(transaction) => {
@@ -471,7 +470,7 @@ async fn restore_and_commit_loaded_navigation_page_async(
} else {
tracing::warn!(
%error,
- session_id = state.navigate_session_id.as_deref(),
+ session_id = state.owner.session_id(),
"navigation commit failed after early Page.navigate result: Inspector output collection"
);
}
@@ -494,19 +493,19 @@ async fn restore_and_commit_loaded_navigation_page_async(
.defer_until_response_flush(move || continuation.release());
}
let _ = conn.commit_loaded_navigation_target_identity_for_session_owner(
- state.navigate_session_id.as_deref(),
+ state.owner.session_id(),
main_document_commit,
target_url,
);
if commit_state.runtime_frontend_enabled {
let _ = conn.set_renderer_runtime_agent_owns_page_console_api_events_for_session_owner(
- state.navigate_session_id.as_deref(),
+ state.owner.session_id(),
true,
);
}
if let Some(token) = token {
conn.commit_document_navigation_for_session_owner_if_matches(
- state.navigate_session_id.as_deref(),
+ state.owner.session_id(),
token,
);
}
@@ -524,9 +523,8 @@ async fn restore_and_commit_loaded_navigation_page_async(
);
}
let preload_channel_execution_context_ids = if conn
- .target_owner_has_bidi_channel_preload_script_for_session(
- state.navigate_session_id.as_deref(),
- ) {
+ .target_owner_has_bidi_channel_preload_script_for_session(state.owner.session_id())
+ {
dedupe_preload_channel_execution_context_ids(std::mem::take(
&mut outcome.preload_channel_execution_context_ids,
))
@@ -538,7 +536,7 @@ async fn restore_and_commit_loaded_navigation_page_async(
Box::pin(
crate::domains::runtime::start_bidi_preload_channel_listeners_for_execution_context_background_events_async(
conn,
- state.navigate_session_id.as_deref(),
+ state.owner.session_id(),
execution_context_id,
&mut preload_channel_listener_events,
),
diff --git a/moli-protocol/src/domains/page/preload.rs b/moli-protocol/src/domains/page/preload.rs
index 4551ef35c..a94c3f1bf 100644
--- a/moli-protocol/src/domains/page/preload.rs
+++ b/moli-protocol/src/domains/page/preload.rs
@@ -1263,15 +1263,14 @@ fn prepare_create_isolated_world_task(
}
fn pending_create_isolated_world_command_for_session(
- conn: &CdpConnection,
command_id: Option<u64>,
- session_id: Option<&str>,
+ owner_scope: crate::conn::CommandOwnerScope,
task: CreateIsolatedWorldCommandTask,
pending: PendingCreateIsolatedWorldPhase,
) -> PageCommandTaskStep {
PageCommandTaskStep::Pending(PendingPageCommandDispatch {
command_id,
- owner_scope: crate::conn::CommandOwnerScope::capture(conn, session_id),
+ owner_scope,
kind: Box::new(PendingPageCommandKind::CreateIsolatedWorld(
PendingCreateIsolatedWorldCommand { task, pending },
)),
@@ -1292,10 +1291,11 @@ fn start_create_isolated_world_initial_navigation_or_renderer_phase(
);
}
+ let owner = crate::conn::CommandOwnerScope::capture(conn, session_id);
let start = match super::navigation::start_initial_document_navigation_for_session_owner(
conn,
None,
- session_id,
+ &owner,
json!({}),
) {
Ok(start) => start,
@@ -1317,9 +1317,8 @@ fn start_create_isolated_world_initial_navigation_or_renderer_phase(
super::navigation::NavigateCommandStart::PendingLoad(pending) => {
task.phase = CreateIsolatedWorldPhase::InitialDocumentNavigation;
pending_create_isolated_world_command_for_session(
- conn,
command_id,
- session_id,
+ owner.clone(),
task,
PendingCreateIsolatedWorldPhase::InitialDocumentNavigation(pending),
)
@@ -1339,9 +1338,8 @@ fn start_create_isolated_world_initial_navigation_or_renderer_phase(
super::navigation::NavigateCommandStart::PendingContinueWithoutRequestPause(pending) => {
task.phase = CreateIsolatedWorldPhase::InitialDocumentNavigation;
pending_create_isolated_world_command_for_session(
- conn,
command_id,
- session_id,
+ owner,
task,
PendingCreateIsolatedWorldPhase::InitialDocumentNavigationContinue(pending),
)
@@ -1355,6 +1353,7 @@ fn start_create_isolated_world_frame_or_world_phase(
session_id: Option<&str>,
mut task: CreateIsolatedWorldCommandTask,
) -> PageCommandTaskStep {
+ let owner = crate::conn::CommandOwnerScope::capture(conn, session_id);
task.phase = CreateIsolatedWorldPhase::RuntimeActivity;
let frame_id = (task.params.frame_id != task.target_id).then(|| task.params.frame_id.clone());
let world_name = task.params.world_name.clone();
@@ -1374,9 +1373,8 @@ fn start_create_isolated_world_frame_or_world_phase(
grant_universal_access,
) {
Ok(pending) => pending_create_isolated_world_command_for_session(
- conn,
command_id,
- session_id,
+ owner,
task,
PendingCreateIsolatedWorldPhase::RendererPageCommand(pending),
),
diff --git a/moli-protocol/src/domains/page/resource_search.rs b/moli-protocol/src/domains/page/resource_search.rs
index 1ec7fb612..66474b799 100644
--- a/moli-protocol/src/domains/page/resource_search.rs
+++ b/moli-protocol/src/domains/page/resource_search.rs
@@ -125,6 +125,7 @@ pub(super) fn try_start_search_in_resource_command(
return complete_error(FRAME_NOT_FOUND);
}
let materialize_limit = conn.response_body_materialize_limit();
+ let owner = CommandOwnerScope::capture(conn, cmd.session_id);
if is_root_frame {
let main_document = conn.current_main_document_resource_for_session_owner(cmd.session_id);
@@ -153,15 +154,15 @@ pub(super) fn try_start_search_in_resource_command(
None => SelectedResource::Unavailable,
}
} else {
- let Some(page) = loaded_page(conn, cmd.session_id) else {
+ let Some(page) = loaded_page(conn, &owner) else {
return complete_error(CONTENT_UNAVAILABLE);
};
select_subresource(page, &root_frame_id, true, &params.url, materialize_limit)
};
- return start_selected_resource_search(conn, cmd.id, cmd.session_id, params, selected);
+ return start_selected_resource_search(conn, cmd.id, owner, params, selected);
}
- let Some(page) = loaded_page(conn, cmd.session_id) else {
+ let Some(page) = loaded_page(conn, &owner) else {
return complete_error(CONTENT_UNAVAILABLE);
};
match page.start_child_frame_resource_search_by_lines(
@@ -172,9 +173,8 @@ pub(super) fn try_start_search_in_resource_command(
params.is_regex,
) {
Ok(pending) => pending_step(
- conn,
cmd.id,
- cmd.session_id,
+ owner,
PendingSearchInResourceCommand {
params,
source: ResourceSearchSource::ChildDocument,
@@ -188,11 +188,11 @@ pub(super) fn try_start_search_in_resource_command(
pub(super) fn complete_search_in_resource_command(
conn: &mut CdpConnection,
command_id: Option<u64>,
- session_id: Option<&str>,
+ owner: &CommandOwnerScope,
completed: CompletedSearchInResourceCommand,
) -> PageCommandTaskStep {
let materialize_limit = conn.response_body_materialize_limit();
- let Some(page) = loaded_page(conn, session_id) else {
+ let Some(page) = loaded_page(conn, owner) else {
return complete_error(CONTENT_UNAVAILABLE);
};
let completion = match completed.completed {
@@ -225,7 +225,13 @@ pub(super) fn complete_search_in_resource_command(
&completed.params.url,
materialize_limit,
);
- start_selected_resource_search(conn, command_id, session_id, completed.params, selected)
+ start_selected_resource_search(
+ conn,
+ command_id,
+ owner.clone(),
+ completed.params,
+ selected,
+ )
}
}
}
@@ -233,7 +239,7 @@ pub(super) fn complete_search_in_resource_command(
fn start_selected_resource_search(
conn: &mut CdpConnection,
command_id: Option<u64>,
- session_id: Option<&str>,
+ owner: CommandOwnerScope,
params: SearchInResourceParams,
selected: SelectedResource,
) -> PageCommandTaskStep {
@@ -242,7 +248,7 @@ fn start_selected_resource_search(
SelectedResource::Unavailable => return complete_error(CONTENT_UNAVAILABLE),
SelectedResource::Missing => return complete_error(RESOURCE_NOT_FOUND),
};
- let Some(page) = loaded_page(conn, session_id) else {
+ let Some(page) = loaded_page(conn, &owner) else {
return complete_error(CONTENT_UNAVAILABLE);
};
match page.start_text_search_by_lines(
@@ -252,9 +258,8 @@ fn start_selected_resource_search(
params.is_regex,
) {
Ok(pending) => pending_step(
- conn,
command_id,
- session_id,
+ owner,
PendingSearchInResourceCommand {
params,
source: ResourceSearchSource::SelectedText,
@@ -266,14 +271,13 @@ fn start_selected_resource_search(
}
fn pending_step(
- conn: &CdpConnection,
command_id: Option<u64>,
- session_id: Option<&str>,
+ owner_scope: CommandOwnerScope,
pending: PendingSearchInResourceCommand,
) -> PageCommandTaskStep {
PageCommandTaskStep::Pending(PendingPageCommandDispatch {
command_id,
- owner_scope: CommandOwnerScope::capture(conn, session_id),
+ owner_scope,
kind: Box::new(PendingPageCommandKind::SearchInResource(pending)),
})
}
@@ -294,8 +298,8 @@ fn complete_error(message: impl Into<String>) -> PageCommandTaskStep {
PageCommandTaskStep::Complete(CommandOutputPlan::error(-32000, message))
}
-fn loaded_page<'a>(conn: &'a mut CdpConnection, session_id: Option<&str>) -> Option<&'a mut Page> {
- conn.runtime_session_owner_slot_mut(session_id)
+fn loaded_page<'a>(conn: &'a mut CdpConnection, owner: &CommandOwnerScope) -> Option<&'a mut Page> {
+ conn.runtime_session_owner_slot_mut_for_route(owner.session_id(), owner.session_owner_route())
.ok()?
.loaded_page_mut()
}
diff --git a/moli-protocol/src/domains/page/termination.rs b/moli-protocol/src/domains/page/termination.rs
index 482a3ecfb..20ab7ef39 100644
--- a/moli-protocol/src/domains/page/termination.rs
+++ b/moli-protocol/src/domains/page/termination.rs
@@ -71,7 +71,7 @@ async fn complete_tokened_materialized_navigation_background_events_async(
navigation: network::MaterializedNavigationLoadOutcome,
) -> Option<RendererOutputFence> {
let command_id = navigation_state.navigate_id;
- let command_session_id = navigation_state.navigate_session_id.clone();
+ let command_session_id = navigation_state.owner.session_id().map(str::to_owned);
let Some(token) = token else {
out.extend(
CommandOutputPlan::error(-32000, "Navigation aborted")
diff --git a/moli-protocol/src/domains/runtime/dispatcher.rs b/moli-protocol/src/domains/runtime/dispatcher.rs
index af3e685fc..816c30625 100644
--- a/moli-protocol/src/domains/runtime/dispatcher.rs
+++ b/moli-protocol/src/domains/runtime/dispatcher.rs
@@ -4686,10 +4686,9 @@ async fn start_protocol_neutral_runtime_command(
)),
};
drop(route_scope);
- step.with_owner_scope(CommandOwnerScope::from_session_and_owner_route(
- None,
- Some(session_owner_route),
- ))
+ step.with_owner_scope(CommandOwnerScope::for_implicit_route(Some(
+ session_owner_route,
+ )))
}
fn runtime_inspector_command_json(command_id: u64, method: &str, params: &Value) -> String {
@@ -9198,10 +9197,10 @@ fn start_pending_shared_worker_runtime_inspector_command(
PendingRuntimeCommandDispatch {
command_id: cmd.id,
action: action.label(),
- owner_scope: CommandOwnerScope::from_session_and_owner_route(
- cmd.session_id,
- session_owner_route,
- ),
+ owner_scope: cmd
+ .session_id
+ .map(CommandOwnerScope::for_session)
+ .unwrap_or_else(|| CommandOwnerScope::for_implicit_route(session_owner_route)),
object_group,
release_object_ids,
release_object_group,
@@ -9263,10 +9262,10 @@ fn start_pending_service_worker_runtime_inspector_command(
PendingRuntimeCommandDispatch {
command_id: cmd.id,
action: action.label(),
- owner_scope: CommandOwnerScope::from_session_and_owner_route(
- cmd.session_id,
- session_owner_route,
- ),
+ owner_scope: cmd
+ .session_id
+ .map(CommandOwnerScope::for_session)
+ .unwrap_or_else(|| CommandOwnerScope::for_implicit_route(session_owner_route)),
object_group,
release_object_ids,
release_object_group,
diff --git a/moli-protocol/src/domains/runtime/tests/evaluate.rs b/moli-protocol/src/domains/runtime/tests/evaluate.rs
index 575727294..5b6ad2523 100644
--- a/moli-protocol/src/domains/runtime/tests/evaluate.rs
+++ b/moli-protocol/src/domains/runtime/tests/evaluate.rs
@@ -2452,7 +2452,7 @@ async fn page_navigate_network_failure_commits_error_document() {
old_document_token.clone(),
crate::conn::NavigationDispatchState {
navigate_id: None,
- navigate_session_id: Some("SID-1".to_owned()),
+ owner: crate::conn::CommandOwnerScope::for_session("SID-1"),
result_projection: crate::conn::NavigationResultProjection::Cdp(json!({})),
frame_id: "TID-1".to_owned(),
session_id: Some("SID-1".to_owned()),
@@ -2471,7 +2471,6 @@ async fn page_navigate_network_failure_commits_error_document() {
"InsecureScheme".to_owned(),
),
},
- None,
Ok(crate::conn::CapturedBody::from_string(
"stale body".to_owned(),
)),
diff --git a/moli-protocol/src/domains/target/closing.rs b/moli-protocol/src/domains/target/closing.rs
index 9aac92244..ea49d9eaa 100644
--- a/moli-protocol/src/domains/target/closing.rs
+++ b/moli-protocol/src/domains/target/closing.rs
@@ -172,10 +172,12 @@ async fn close_target_inner_async(
.as_ref()
.and_then(|browser_context| browser_context.background_target(&target_id))
.and_then(|target| target.session_id().map(str::to_owned));
- let owner_scope = crate::conn::CommandOwnerScope::from_session_and_owner_route(
- session_id.as_deref(),
- session_id.is_none().then_some(target_route),
- );
+ let owner_scope = session_id
+ .as_deref()
+ .map(crate::conn::CommandOwnerScope::for_session)
+ .unwrap_or_else(|| {
+ crate::conn::CommandOwnerScope::for_implicit_route(Some(target_route))
+ });
let renderer_output_predecessor =
events::fail_pending_fetch_state_for_target_background_events_async(
conn,