pub struct TabRegistry<P> { /* private fields */ }Expand description
Ordered collection of open tabs plus which one is active. Generic over the
page handle type P so the state machine is unit testable without a live
CDP connection — the tests module below drives it with a plain &str
standing in for chromiumoxide::Page.
Implementations§
Source§impl<P: Clone> TabRegistry<P>
impl<P: Clone> TabRegistry<P>
Sourcepub fn new() -> (Self, Receiver<TabsSnapshot>)
pub fn new() -> (Self, Receiver<TabsSnapshot>)
A registry with no tabs open and no active tab — the well-defined empty state.
Sourcepub fn subscribe(&self) -> Receiver<TabsSnapshot>
pub fn subscribe(&self) -> Receiver<TabsSnapshot>
A new receiver tuned to the current state — borrow() sees the
latest snapshot immediately; changed() waits for the next one.
Sourcepub fn open(
&mut self,
page: P,
url: impl Into<String>,
title: impl Into<String>,
) -> TabId
pub fn open( &mut self, page: P, url: impl Into<String>, title: impl Into<String>, ) -> TabId
Open a new tab wrapping page, and make it active. Returns the new
tab’s id.
Sourcepub fn close(&mut self, id: TabId) -> Option<P>
pub fn close(&mut self, id: TabId) -> Option<P>
Close id. Returns its page handle (so the caller can drive the
CDP-level close) if it existed — None if there was no such tab, a
safe no-op rather than an error.
Closing the active tab activates a neighbor: prefer the tab that
slides into the closed one’s position (the tab that was to its
right), falling back to the tab now at the end (previously to its
left) if it was the rightmost tab, falling back to None if it was
the last tab open — the well-defined empty state.
Sourcepub fn close_all(&mut self) -> Vec<P>
pub fn close_all(&mut self) -> Vec<P>
Close every open tab. Returns their page handles in closing order, so
the caller can drive a CDP-level close for each. Equivalent to
calling Self::close on every currently-open id.
Sourcepub fn switch(&mut self, id: TabId) -> Result<(), TabError>
pub fn switch(&mut self, id: TabId) -> Result<(), TabError>
Make id the active tab. Errors if no tab has that id. A no-op
(still Ok, no event published) if id is already active.
Sourcepub fn active_id(&self) -> Option<TabId>
pub fn active_id(&self) -> Option<TabId>
The active tab’s id, if any (None in the empty state).
Sourcepub fn active_url(&self) -> Option<String>
pub fn active_url(&self) -> Option<String>
The active tab’s cached URL, if any. Used to keep a scalar “last known URL” cache in sync with whichever tab is active, without a live CDP round trip.
Sourcepub fn active_page(&self) -> Option<P>
pub fn active_page(&self) -> Option<P>
The active tab’s page handle, if any.
Sourcepub fn pages(&self) -> Vec<(TabId, P)>
pub fn pages(&self) -> Vec<(TabId, P)>
Every open tab’s id + page handle, in tab-strip order. Used to drive
a live nav-state refresh across ALL tabs, not just the active one — a
background tab can navigate on its own (a clicked link, a JS
redirect) without ever going through ChromiumBackend::navigate.
Sourcepub fn list(&self) -> Vec<TabInfo>
pub fn list(&self) -> Vec<TabInfo>
Current tab list in strip order, each flagged with whether it’s the active one.
Update id’s cached nav state. A no-op (including no published
event) if none of the fields actually changed, or if id doesn’t
exist — keeps the watch channel free of churn from a caller that
refreshes on every poll regardless of whether anything actually
moved (see ChromiumBackend::list_tabs).
Auto Trait Implementations§
impl<P> !RefUnwindSafe for TabRegistry<P>
impl<P> !UnwindSafe for TabRegistry<P>
impl<P> Freeze for TabRegistry<P>
impl<P> Send for TabRegistry<P>
impl<P> Sync for TabRegistry<P>
impl<P> Unpin for TabRegistry<P>
impl<P> UnsafeUnpin for TabRegistry<P>where
Vec<TabEntry<P>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more