mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
implement broadcastchannel
This commit is contained in:
parent
145c89a2d4
commit
eb21d5f738
32 changed files with 763 additions and 216 deletions
|
@ -21,7 +21,7 @@ pub mod serializable;
|
|||
pub mod transferable;
|
||||
pub mod webdriver_msg;
|
||||
|
||||
use crate::serializable::BlobImpl;
|
||||
use crate::serializable::{BlobData, BlobImpl};
|
||||
use crate::transferable::MessagePortImpl;
|
||||
use crate::webdriver_msg::{LoadStatus, WebDriverScriptCommand};
|
||||
use bluetooth_traits::BluetoothRequest;
|
||||
|
@ -955,6 +955,48 @@ pub struct StructuredSerializedData {
|
|||
pub ports: Option<HashMap<MessagePortId, MessagePortImpl>>,
|
||||
}
|
||||
|
||||
impl StructuredSerializedData {
|
||||
/// Clone the serialized data for use with broadcast-channels.
|
||||
pub fn clone_for_broadcast(&self) -> StructuredSerializedData {
|
||||
let serialized = self.serialized.clone();
|
||||
|
||||
let blobs = if let Some(blobs) = self.blobs.as_ref() {
|
||||
let mut blob_clones = HashMap::with_capacity(blobs.len());
|
||||
|
||||
for (original_id, blob) in blobs.iter() {
|
||||
let type_string = blob.type_string();
|
||||
|
||||
if let BlobData::Memory(ref bytes) = blob.blob_data() {
|
||||
let blob_clone = BlobImpl::new_from_bytes(bytes.clone(), type_string);
|
||||
|
||||
// Note: we insert the blob at the original id,
|
||||
// otherwise this will not match the storage key as serialized by SM in `serialized`.
|
||||
// The clone has it's own new Id however.
|
||||
blob_clones.insert(original_id.clone(), blob_clone);
|
||||
} else {
|
||||
// Not panicking only because this is called from the constellation.
|
||||
warn!("Serialized blob not in memory format(should never happen).");
|
||||
}
|
||||
}
|
||||
Some(blob_clones)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if self.ports.is_some() {
|
||||
// Not panicking only because this is called from the constellation.
|
||||
warn!("Attempt to broadcast structured serialized data including ports(should never happen).");
|
||||
}
|
||||
|
||||
StructuredSerializedData {
|
||||
serialized,
|
||||
blobs,
|
||||
// Ports cannot be broadcast.
|
||||
ports: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A task on the https://html.spec.whatwg.org/multipage/#port-message-queue
|
||||
#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
|
||||
pub struct PortMessageTask {
|
||||
|
@ -979,6 +1021,27 @@ pub enum MessagePortMsg {
|
|||
NewTask(MessagePortId, PortMessageTask),
|
||||
}
|
||||
|
||||
/// Message for communication between the constellation and a global managing broadcast channels.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct BroadcastMsg {
|
||||
/// The origin of this message.
|
||||
pub origin: ImmutableOrigin,
|
||||
/// The name of the channel.
|
||||
pub channel_name: String,
|
||||
/// A data-holder for serialized data.
|
||||
pub data: StructuredSerializedData,
|
||||
}
|
||||
|
||||
impl Clone for BroadcastMsg {
|
||||
fn clone(&self) -> BroadcastMsg {
|
||||
BroadcastMsg {
|
||||
data: self.data.clone_for_broadcast(),
|
||||
origin: self.origin.clone(),
|
||||
channel_name: self.channel_name.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The type of MediaSession action.
|
||||
/// https://w3c.github.io/mediasession/#enumdef-mediasessionaction
|
||||
#[derive(Clone, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)]
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use crate::AnimationState;
|
||||
use crate::AuxiliaryBrowsingContextLoadInfo;
|
||||
use crate::BroadcastMsg;
|
||||
use crate::DocumentState;
|
||||
use crate::IFrameLoadInfoWithData;
|
||||
use crate::LayoutControlMsg;
|
||||
|
@ -22,7 +23,8 @@ use euclid::Size2D;
|
|||
use gfx_traits::Epoch;
|
||||
use ipc_channel::ipc::{IpcReceiver, IpcSender};
|
||||
use msg::constellation_msg::{
|
||||
BrowsingContextId, MessagePortId, MessagePortRouterId, PipelineId, TopLevelBrowsingContextId,
|
||||
BroadcastChannelRouterId, BrowsingContextId, MessagePortId, MessagePortRouterId, PipelineId,
|
||||
TopLevelBrowsingContextId,
|
||||
};
|
||||
use msg::constellation_msg::{HistoryStateId, TraversalDirection};
|
||||
use net_traits::request::RequestBuilder;
|
||||
|
@ -142,6 +144,21 @@ pub enum ScriptMsg {
|
|||
RemoveMessagePort(MessagePortId),
|
||||
/// Entangle two message-ports.
|
||||
EntanglePorts(MessagePortId, MessagePortId),
|
||||
/// A global has started managing broadcast-channels.
|
||||
NewBroadcastChannelRouter(
|
||||
BroadcastChannelRouterId,
|
||||
IpcSender<BroadcastMsg>,
|
||||
ImmutableOrigin,
|
||||
),
|
||||
/// A global has stopped managing broadcast-channels.
|
||||
RemoveBroadcastChannelRouter(BroadcastChannelRouterId, ImmutableOrigin),
|
||||
/// A global started managing broadcast channels for a given channel-name.
|
||||
NewBroadcastChannelNameInRouter(BroadcastChannelRouterId, String, ImmutableOrigin),
|
||||
/// A global stopped managing broadcast channels for a given channel-name.
|
||||
RemoveBroadcastChannelNameInRouter(BroadcastChannelRouterId, String, ImmutableOrigin),
|
||||
/// Broadcast a message to all same-origin broadcast channels,
|
||||
/// excluding the source of the broadcast.
|
||||
ScheduleBroadcast(BroadcastChannelRouterId, BroadcastMsg),
|
||||
/// Forward a message to the embedder.
|
||||
ForwardToEmbedder(EmbedderMsg),
|
||||
/// Requests are sent to constellation and fetches are checked manually
|
||||
|
@ -280,6 +297,11 @@ impl fmt::Debug for ScriptMsg {
|
|||
RemoveMessagePort(..) => "RemoveMessagePort",
|
||||
MessagePortShipped(..) => "MessagePortShipped",
|
||||
EntanglePorts(..) => "EntanglePorts",
|
||||
NewBroadcastChannelRouter(..) => "NewBroadcastChannelRouter",
|
||||
RemoveBroadcastChannelRouter(..) => "RemoveBroadcastChannelRouter",
|
||||
RemoveBroadcastChannelNameInRouter(..) => "RemoveBroadcastChannelNameInRouter",
|
||||
NewBroadcastChannelNameInRouter(..) => "NewBroadcastChannelNameInRouter",
|
||||
ScheduleBroadcast(..) => "ScheduleBroadcast",
|
||||
ForwardToEmbedder(..) => "ForwardToEmbedder",
|
||||
InitiateNavigateRequest(..) => "InitiateNavigateRequest",
|
||||
BroadcastStorageEvent(..) => "BroadcastStorageEvent",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue