aboutsummaryrefslogtreecommitdiffstats
path: root/components/shared/script/serializable.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/shared/script/serializable.rs')
-rw-r--r--components/shared/script/serializable.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/components/shared/script/serializable.rs b/components/shared/script/serializable.rs
index d168736f961..8e9f9f5b3da 100644
--- a/components/shared/script/serializable.rs
+++ b/components/shared/script/serializable.rs
@@ -60,6 +60,39 @@ impl FileBlob {
}
}
+impl crate::BroadcastClone for BlobImpl {
+ type Id = BlobId;
+
+ fn source(
+ data: &crate::StructuredSerializedData,
+ ) -> &Option<std::collections::HashMap<Self::Id, Self>> {
+ &data.blobs
+ }
+
+ fn destination(
+ data: &mut crate::StructuredSerializedData,
+ ) -> &mut Option<std::collections::HashMap<Self::Id, Self>> {
+ &mut data.blobs
+ }
+
+ fn clone_for_broadcast(&self) -> Option<Self> {
+ let type_string = self.type_string();
+
+ if let BlobData::Memory(bytes) = self.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.
+ return Some(blob_clone);
+ } else {
+ // Not panicking only because this is called from the constellation.
+ log::warn!("Serialized blob not in memory format(should never happen).");
+ }
+ None
+ }
+}
+
/// The data backing a DOM Blob.
#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
pub struct BlobImpl {