mirror of
https://github.com/servo/servo.git
synced 2025-06-11 01:50:10 +00: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)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue