Make DOMPoint and DOMPointReadOnly serializable (#35989)

* script: Make DOMPointReadOnly serializable.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Make DOMPoint serializable.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Shrink worker script event.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Update components/script/dom/dompoint.rs

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Signed-off-by: Josh Matthews <josh@joshmatthews.net>

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Josh Matthews 2025-03-26 21:35:02 -04:00 committed by GitHub
parent 1df1ba58d6
commit 53a2e61fec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 224 additions and 45 deletions

View file

@ -21,8 +21,8 @@ use std::sync::Arc;
use background_hang_monitor_api::BackgroundHangMonitorRegister;
use base::cross_process_instant::CrossProcessInstant;
use base::id::{
BlobId, BrowsingContextId, HistoryStateId, MessagePortId, PipelineId, PipelineNamespaceId,
WebViewId,
BlobId, BrowsingContextId, DomPointId, HistoryStateId, MessagePortId, PipelineId,
PipelineNamespaceId, WebViewId,
};
#[cfg(feature = "bluetooth")]
use bluetooth_traits::BluetoothRequest;
@ -64,7 +64,7 @@ pub use crate::script_msg::{
DOMMessage, IFrameSizeMsg, Job, JobError, JobResult, JobResultValue, JobType, SWManagerMsg,
SWManagerSenders, ScopeThings, ScriptMsg, ServiceWorkerMsg, TouchEventResult,
};
use crate::serializable::BlobImpl;
use crate::serializable::{BlobImpl, DomPoint};
use crate::transferable::MessagePortImpl;
/// The origin where a given load was initiated.
@ -648,12 +648,14 @@ impl ScriptToConstellationChan {
/// A data-holder for serialized data and transferred objects.
/// <https://html.spec.whatwg.org/multipage/#structuredserializewithtransfer>
#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
#[derive(Debug, Default, Deserialize, MallocSizeOf, Serialize)]
pub struct StructuredSerializedData {
/// Data serialized by SpiderMonkey.
pub serialized: Vec<u8>,
/// Serialized in a structured callback,
pub blobs: Option<HashMap<BlobId, BlobImpl>>,
/// Serialized point objects.
pub points: Option<HashMap<DomPointId, DomPoint>>,
/// Transferred objects.
pub ports: Option<HashMap<MessagePortId, MessagePortImpl>>,
}
@ -678,12 +680,20 @@ where
pub enum Serializable {
/// The `Blob` interface.
Blob,
/// The `DOMPoint` interface.
DomPoint,
/// The `DOMPointReadOnly` interface.
DomPointReadOnly,
}
impl Serializable {
fn clone_values(&self) -> fn(&StructuredSerializedData, &mut StructuredSerializedData) {
match self {
Serializable::Blob => StructuredSerializedData::clone_all_of_type::<BlobImpl>,
Serializable::DomPointReadOnly => {
StructuredSerializedData::clone_all_of_type::<DomPoint>
},
Serializable::DomPoint => StructuredSerializedData::clone_all_of_type::<DomPoint>,
}
}
}
@ -737,9 +747,7 @@ impl StructuredSerializedData {
let mut cloned = StructuredSerializedData {
serialized,
blobs: None,
// Ports cannot be broadcast.
ports: None,
..Default::default()
};
for serializable in Serializable::iter() {

View file

@ -11,7 +11,7 @@
use std::cell::RefCell;
use std::path::PathBuf;
use base::id::BlobId;
use base::id::{BlobId, DomPointId};
use malloc_size_of_derive::MallocSizeOf;
use net_traits::filemanager_thread::RelativePos;
use serde::{Deserialize, Serialize};
@ -182,3 +182,36 @@ impl BlobImpl {
&mut self.blob_data
}
}
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
/// A serializable version of the DOMPoint/DOMPointReadOnly interface.
pub struct DomPoint {
/// The x coordinate.
pub x: f64,
/// The y coordinate.
pub y: f64,
/// The z coordinate.
pub z: f64,
/// The w coordinate.
pub w: f64,
}
impl crate::BroadcastClone for DomPoint {
type Id = DomPointId;
fn source(
data: &crate::StructuredSerializedData,
) -> &Option<std::collections::HashMap<Self::Id, Self>> {
&data.points
}
fn destination(
data: &mut crate::StructuredSerializedData,
) -> &mut Option<std::collections::HashMap<Self::Id, Self>> {
&mut data.points
}
fn clone_for_broadcast(&self) -> Option<Self> {
Some(self.clone())
}
}