Skip to main content

EventSubscriber

Struct EventSubscriber 

Source
pub struct EventSubscriber { /* private fields */ }
Expand description

事件订阅者 — servo delegate 在 servo 线程调用 on_* 方法,push 事件到 channel。

用法:

use bao_cdp_client::bridge::{ConsoleLevel, EventSubscriber};
use std::time::Duration;

let (subscriber, rx) = EventSubscriber::new();
// servo delegate 在 servo 线程调用 on_console_message 时,事件进入 channel
subscriber.on_console_message("target-1", ConsoleLevel::Info, "hello", None, None, None);
// 主线程在 InMemoryTransport 内 recv_event 时,从 rx 取出并 translate 为 CdpEvent
let servo_event = rx.recv_timeout(Duration::from_millis(100)).expect("event delivered");
assert!(matches!(servo_event,
    bao_cdp_client::bridge::ServoEvent::Console { ref text, .. } if text == "hello"));

§关闭语义

EventSubscriber drop 时,Sender 被丢弃,接收端 recv 会收到 RecvTimeoutError::Disconnected

§线程安全

mpsc::SenderSend + Sync,可被 servo delegate 在 servo 线程持有。 但注意 EventSubscriberClone(避免多 sender 混淆事件源); 如需多 sender,显式调 EventSubscriber::sender 拿到 Sender<ServoEvent>

@trace REQ-BAO-API-003 [level:library]

Implementations§

Source§

impl EventSubscriber

Source

pub fn new() -> (EventSubscriber, Receiver<ServoEvent>)

构造 EventSubscriber 与对应的 Receiver。

bounded(1024):channel 缓冲 1024 个事件。servo 端 push 时若 channel 满,事件被丢弃(避免阻塞 servo ScriptThread)并记录日志。

@trace REQ-BAO-API-003 [level:library]

Source

pub fn with_capacity(capacity: usize) -> (EventSubscriber, Receiver<ServoEvent>)

指定 channel 容量构造。

@trace REQ-BAO-API-003 [level:library]

Source

pub fn sender(&self) -> Sender<ServoEvent>

获取底层 sender(供复杂场景使用,如多 sender 模式)。

@trace REQ-BAO-API-003 [level:library]

Source

pub fn on_console_message( &self, target_id: impl Into<String>, level: ConsoleLevel, text: impl Into<String>, url: Option<String>, line: Option<u32>, column: Option<u32>, )

servo console 消息回调。

@trace REQ-BAO-API-003 [event:Console]

Source

pub fn on_page_error( &self, target_id: impl Into<String>, text: impl Into<String>, url: Option<String>, line: Option<u32>, column: Option<u32>, stack: Option<String>, )

servo 页面错误(JS 异常/CSS 错误)回调。

@trace REQ-BAO-API-003 [event:PageError]

Source

pub fn on_network_request( &self, target_id: impl Into<String>, request_id: impl Into<String>, url: impl Into<String>, method: impl Into<String>, headers: HashMap<String, String>, post_data: Option<Vec<u8>>, resource_type: impl Into<String>, frame_id: impl Into<String>, )

servo 网络请求开始回调。

@trace REQ-BAO-API-003 [event:NetworkEvent]

Source

pub fn on_network_response( &self, target_id: impl Into<String>, request_id: impl Into<String>, url: impl Into<String>, status: u16, status_text: impl Into<String>, headers: HashMap<String, String>, mime_type: impl Into<String>, remote_ip: Option<String>, )

servo 网络响应到达回调。

@trace REQ-BAO-API-003 [event:NetworkEvent]

Source

pub fn on_network_loading_finish( &self, target_id: impl Into<String>, request_id: impl Into<String>, encoded_data_length: u64, )

servo 网络请求成功结束回调。

@trace REQ-BAO-API-003 [event:NetworkEvent]

Source

pub fn on_network_loading_fail( &self, target_id: impl Into<String>, request_id: impl Into<String>, error_text: impl Into<String>, canceled: bool, )

servo 网络请求失败回调。

@trace REQ-BAO-API-003 [event:NetworkEvent]

Source

pub fn on_dom_attribute_modified( &self, target_id: impl Into<String>, node_id: i64, name: impl Into<String>, value: impl Into<String>, )

servo DOM 属性变更回调。

@trace REQ-BAO-API-003 [event:DomMutation]

Source

pub fn on_dom_character_data_modified( &self, target_id: impl Into<String>, node_id: i64, old_value: impl Into<String>, new_value: impl Into<String>, )

servo DOM character data 变更回调。

@trace REQ-BAO-API-003 [event:DomMutation]

Source

pub fn on_script_parsed( &self, target_id: impl Into<String>, script_id: impl Into<String>, url: impl Into<String>, start_line: u32, start_column: u32, end_line: u32, end_column: u32, source_map_url: Option<String>, )

servo 脚本编译完成回调。

@trace REQ-BAO-API-003 [event:SourceInfo]

Source

pub fn on_frame_navigated( &self, target_id: impl Into<String>, frame_id: impl Into<String>, url: impl Into<String>, name: Option<String>, )

servo frame 导航完成回调。

@trace REQ-BAO-API-003 [event:FrameInfo]

Source

pub fn on_frame_started_loading( &self, target_id: impl Into<String>, frame_id: impl Into<String>, )

servo frame 开始加载回调。

@trace REQ-BAO-API-003 [event:FrameInfo]

Source

pub fn on_frame_stopped_loading( &self, target_id: impl Into<String>, frame_id: impl Into<String>, )

servo frame 停止加载回调。

@trace REQ-BAO-API-003 [event:FrameInfo]

Source

pub fn on_timeline_marker( &self, target_id: impl Into<String>, name: impl Into<String>, start_time: f64, end_time: f64, )

servo 性能 timeline 标记回调。

@trace REQ-BAO-API-003 [event:TimelineMarker]

Trait Implementations§

Source§

impl Debug for EventSubscriber

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for EventSubscriber

Source§

fn default() -> EventSubscriber

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> AsCtxPtr for T
where T: ?Sized,

Source§

fn as_ctx_ptr(&self) -> *mut Self
where Self: Sized,

self’s address as *mut Self for deferred-task / scopeguard / ref_guard ctx slots. The closures/trampolines deref it as shared (&*p) — every method they reach is &self post-R-2, so no write provenance is required; the *mut spelling is purely to match the existing DerefOnDrop / HasAutoFlush / RefCount ABI.
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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> Filterable for T

Source§

fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>

Creates a filterable data provider with the given name for debugging. Read more
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> MaybeBoxed<Box<T>> for T

Source§

fn maybe_boxed(self) -> Box<T>

Convert
Source§

impl<T> MaybeBoxed<T> for T

Source§

fn maybe_boxed(self) -> T

Convert
Source§

impl<T> MaybeSendSync for T

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> 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> Send for T
where T: ?Sized,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

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

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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