aboutsummaryrefslogtreecommitdiffstats
path: root/components/script_traits/lib.rs
diff options
context:
space:
mode:
authorGregory Terzian <gterzian@users.noreply.github.com>2020-02-19 00:48:17 +0800
committerGregory Terzian <gterzian@users.noreply.github.com>2020-02-25 14:17:48 +0800
commiteb21d5f738f6ecac4bad7ad23f1d08b5eede8802 (patch)
tree5bb6e43322739c204d982bdd0d03db38f24ff722 /components/script_traits/lib.rs
parent145c89a2d49b7a0c2842e99dff65da4d8164bf7d (diff)
downloadservo-eb21d5f738f6ecac4bad7ad23f1d08b5eede8802.tar.gz
servo-eb21d5f738f6ecac4bad7ad23f1d08b5eede8802.zip
implement broadcastchannel
Diffstat (limited to 'components/script_traits/lib.rs')
-rw-r--r--components/script_traits/lib.rs65
1 files changed, 64 insertions, 1 deletions
diff --git a/components/script_traits/lib.rs b/components/script_traits/lib.rs
index d928335f8e3..9b4588a3cb0 100644
--- a/components/script_traits/lib.rs
+++ b/components/script_traits/lib.rs
@@ -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)]