Skip to main content

TabRegistry

Struct TabRegistry 

Source
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>

Source

pub fn new() -> (Self, Receiver<TabsSnapshot>)

A registry with no tabs open and no active tab — the well-defined empty state.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn active_id(&self) -> Option<TabId>

The active tab’s id, if any (None in the empty state).

Source

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.

Source

pub fn active_page(&self) -> Option<P>

The active tab’s page handle, if any.

Source

pub fn page(&self, id: TabId) -> Option<P>

id’s page handle, if it’s an open tab.

Source

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.

Source

pub fn list(&self) -> Vec<TabInfo>

Current tab list in strip order, each flagged with whether it’s the active one.

Source

pub fn update_nav_state( &mut self, id: TabId, url: impl Into<String>, title: impl Into<String>, can_go_back: bool, can_go_forward: bool, )

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>
where Vec<TabEntry<P>>: Freeze,

§

impl<P> Send for TabRegistry<P>
where Vec<TabEntry<P>>: Send,

§

impl<P> Sync for TabRegistry<P>
where Vec<TabEntry<P>>: Sync,

§

impl<P> Unpin for TabRegistry<P>
where Vec<TabEntry<P>>: Unpin,

§

impl<P> UnsafeUnpin for TabRegistry<P>
where Vec<TabEntry<P>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more