pub struct ChannelOwnerImpl { /* private fields */ }Expand description
Base implementation of ChannelOwner that can be embedded in protocol objects.
This struct provides the common functionality for all ChannelOwner implementations. Protocol objects (Browser, Page, etc.) should contain this as a field and delegate trait methods to it.
§Example
use playwright_core::channel_owner::{ChannelOwner, ChannelOwnerImpl, ParentOrConnection, DisposeReason};
use playwright_core::channel::Channel;
use playwright_core::connection::ConnectionLike;
use std::sync::Arc;
use std::any::Any;
use serde_json::Value;
pub struct Browser {
base: ChannelOwnerImpl,
// ... browser-specific fields
}
impl Browser {
pub fn new(
parent: Arc<dyn ChannelOwner>,
type_name: String,
guid: Arc<str>,
initializer: Value,
) -> Self {
let base = ChannelOwnerImpl::new(
ParentOrConnection::Parent(parent),
type_name,
guid,
initializer,
);
Self { base }
}
}
impl ChannelOwner for Browser {
fn guid(&self) -> &str { self.base.guid() }
fn type_name(&self) -> &str { self.base.type_name() }
fn parent(&self) -> Option<Arc<dyn ChannelOwner>> { self.base.parent() }
fn connection(&self) -> Arc<dyn ConnectionLike> { self.base.connection() }
fn initializer(&self) -> &Value { self.base.initializer() }
fn channel(&self) -> &Channel { self.base.channel() }
fn dispose(&self, reason: DisposeReason) { self.base.dispose(reason) }
fn adopt(&self, child: Arc<dyn ChannelOwner>) { self.base.adopt(child) }
fn add_child(&self, guid: Arc<str>, child: Arc<dyn ChannelOwner>) {
self.base.add_child(guid, child)
}
fn remove_child(&self, guid: &str) { self.base.remove_child(guid) }
fn on_event(&self, method: &str, params: Value) { self.base.on_event(method, params) }
fn was_collected(&self) -> bool { self.base.was_collected() }
fn as_any(&self) -> &dyn Any { self }
}Implementations§
Source§impl ChannelOwnerImpl
impl ChannelOwnerImpl
Sourcepub fn new(
parent: ParentOrConnection,
type_name: String,
guid: Arc<str>,
initializer: Value,
) -> Self
pub fn new( parent: ParentOrConnection, type_name: String, guid: Arc<str>, initializer: Value, ) -> Self
Creates a new ChannelOwner base implementation.
This constructor:
- Extracts the connection from parent or uses provided connection
- Creates the channel for RPC communication
- Stores the initializer data
- Registers itself in the connection (done by caller via Connection::register_object)
- Registers itself in parent (done by caller via parent.add_child)
§Arguments
parent- Either a parent ChannelOwner or the root Connectiontype_name- Protocol type name (e.g., “Browser”)guid- Unique GUID from serverinitializer- Initial state from__create__message
Sourcepub fn parent(&self) -> Option<Arc<dyn ChannelOwner>>
pub fn parent(&self) -> Option<Arc<dyn ChannelOwner>>
Returns the parent object, if any.
Sourcepub fn connection(&self) -> Arc<dyn ConnectionLike>
pub fn connection(&self) -> Arc<dyn ConnectionLike>
Returns the connection.
Sourcepub fn initializer(&self) -> &Value
pub fn initializer(&self) -> &Value
Returns the initializer JSON.
Sourcepub fn dispose(&self, reason: DisposeReason)
pub fn dispose(&self, reason: DisposeReason)
Disposes this object and all children recursively.
§Arguments
reason- Why the object is being disposed
Sourcepub fn adopt(&self, child: Arc<dyn ChannelOwner>)
pub fn adopt(&self, child: Arc<dyn ChannelOwner>)
Adopts a child object (moves from old parent to this parent).
Sourcepub fn add_child(&self, guid: Arc<str>, child: Arc<dyn ChannelOwner>)
pub fn add_child(&self, guid: Arc<str>, child: Arc<dyn ChannelOwner>)
Adds a child to this parent’s registry.
Sourcepub fn remove_child(&self, guid: &str)
pub fn remove_child(&self, guid: &str)
Removes a child from this parent’s registry.
Sourcepub fn on_event(&self, method: &str, params: Value)
pub fn on_event(&self, method: &str, params: Value)
Handles a protocol event (default implementation logs it).
Subclasses should override this to handle specific events.
Sourcepub fn was_collected(&self) -> bool
pub fn was_collected(&self) -> bool
Returns true if object was garbage collected.