diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index e199efa3e04..745c35f0864 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -4168,7 +4168,7 @@ where source_browsing_context, target_origin: origin, source_origin, - data, + data: Box::new(data), }; let result = match self.pipelines.get(&pipeline_id) { Some(pipeline) => pipeline.event_loop.send(msg), diff --git a/components/script/dom/bindings/structuredclone.rs b/components/script/dom/bindings/structuredclone.rs index 7146e903e4f..cb998a7f808 100644 --- a/components/script/dom/bindings/structuredclone.rs +++ b/components/script/dom/bindings/structuredclone.rs @@ -10,13 +10,14 @@ use std::os::raw; use std::ptr; use base::id::{ - BlobId, DomExceptionId, DomPointId, ImageBitmapId, Index, MessagePortId, NamespaceIndex, - OffscreenCanvasId, PipelineNamespaceId, QuotaExceededErrorId, + BlobId, DomExceptionId, DomMatrixId, DomPointId, DomQuadId, DomRectId, ImageBitmapId, Index, + MessagePortId, NamespaceIndex, OffscreenCanvasId, PipelineNamespaceId, QuotaExceededErrorId, }; use constellation_traits::{ - BlobImpl, DomException, DomPoint, MessagePortImpl, Serializable as SerializableInterface, - SerializableImageBitmap, SerializableQuotaExceededError, StructuredSerializedData, - TransferableOffscreenCanvas, Transferrable as TransferrableInterface, TransformStreamData, + BlobImpl, DomException, DomMatrix, DomPoint, DomQuad, DomRect, MessagePortImpl, + Serializable as SerializableInterface, SerializableImageBitmap, SerializableQuotaExceededError, + StructuredSerializedData, TransferableOffscreenCanvas, Transferrable as TransferrableInterface, + TransformStreamData, }; use js::gc::RootedVec; use js::glue::{ @@ -49,7 +50,10 @@ use crate::dom::imagebitmap::ImageBitmap; use crate::dom::messageport::MessagePort; use crate::dom::offscreencanvas::OffscreenCanvas; use crate::dom::readablestream::ReadableStream; -use crate::dom::types::{DOMException, QuotaExceededError, TransformStream}; +use crate::dom::types::{ + DOMException, DOMMatrix, DOMMatrixReadOnly, DOMQuad, DOMRect, DOMRectReadOnly, + QuotaExceededError, TransformStream, +}; use crate::dom::writablestream::WritableStream; use crate::realms::{AlreadyInRealm, InRealm, enter_realm}; use crate::script_runtime::{CanGc, JSContext as SafeJSContext}; @@ -74,6 +78,11 @@ pub(super) enum StructuredCloneTags { ImageBitmap = 0xFFFF800A, OffscreenCanvas = 0xFFFF800B, QuotaExceededError = 0xFFFF800C, + DomRect = 0xFFFF800D, + DomRectReadOnly = 0xFFFF800E, + DomQuad = 0xFFFF800F, + DomMatrix = 0xFFFF8010, + DomMatrixReadOnly = 0xFFFF8011, Max = 0xFFFFFFFF, } @@ -81,8 +90,13 @@ impl From for StructuredCloneTags { fn from(v: SerializableInterface) -> Self { match v { SerializableInterface::Blob => StructuredCloneTags::DomBlob, - SerializableInterface::DomPointReadOnly => StructuredCloneTags::DomPointReadOnly, SerializableInterface::DomPoint => StructuredCloneTags::DomPoint, + SerializableInterface::DomPointReadOnly => StructuredCloneTags::DomPointReadOnly, + SerializableInterface::DomRect => StructuredCloneTags::DomRect, + SerializableInterface::DomRectReadOnly => StructuredCloneTags::DomRectReadOnly, + SerializableInterface::DomQuad => StructuredCloneTags::DomQuad, + SerializableInterface::DomMatrix => StructuredCloneTags::DomMatrix, + SerializableInterface::DomMatrixReadOnly => StructuredCloneTags::DomMatrixReadOnly, SerializableInterface::DomException => StructuredCloneTags::DomException, SerializableInterface::ImageBitmap => StructuredCloneTags::ImageBitmap, SerializableInterface::QuotaExceededError => StructuredCloneTags::QuotaExceededError, @@ -113,8 +127,13 @@ fn reader_for_type( ) -> *mut JSObject { match val { SerializableInterface::Blob => read_object::, - SerializableInterface::DomPointReadOnly => read_object::, SerializableInterface::DomPoint => read_object::, + SerializableInterface::DomPointReadOnly => read_object::, + SerializableInterface::DomRect => read_object::, + SerializableInterface::DomRectReadOnly => read_object::, + SerializableInterface::DomQuad => read_object::, + SerializableInterface::DomMatrix => read_object::, + SerializableInterface::DomMatrixReadOnly => read_object::, SerializableInterface::DomException => read_object::, SerializableInterface::ImageBitmap => read_object::, SerializableInterface::QuotaExceededError => read_object::, @@ -258,8 +277,13 @@ type SerializeOperation = unsafe fn( fn serialize_for_type(val: SerializableInterface) -> SerializeOperation { match val { SerializableInterface::Blob => try_serialize::, - SerializableInterface::DomPointReadOnly => try_serialize::, SerializableInterface::DomPoint => try_serialize::, + SerializableInterface::DomPointReadOnly => try_serialize::, + SerializableInterface::DomRect => try_serialize::, + SerializableInterface::DomRectReadOnly => try_serialize::, + SerializableInterface::DomQuad => try_serialize::, + SerializableInterface::DomMatrix => try_serialize::, + SerializableInterface::DomMatrixReadOnly => try_serialize::, SerializableInterface::DomException => try_serialize::, SerializableInterface::ImageBitmap => try_serialize::, SerializableInterface::QuotaExceededError => try_serialize::, @@ -572,6 +596,12 @@ pub(crate) struct StructuredDataReader<'a> { pub(crate) blob_impls: Option>, /// A map of serialized points. pub(crate) points: Option>, + /// A map of serialized rects. + pub(crate) rects: Option>, + /// A map of serialized quads. + pub(crate) quads: Option>, + /// A map of serialized matrices. + pub(crate) matrices: Option>, /// A map of serialized exceptions. pub(crate) exceptions: Option>, /// A map of serialized quota exceeded errors. @@ -597,6 +627,12 @@ pub(crate) struct StructuredDataWriter { pub(crate) transform_streams_port: Option>, /// Serialized points. pub(crate) points: Option>, + /// Serialized rects. + pub(crate) rects: Option>, + /// Serialized quads. + pub(crate) quads: Option>, + /// Serialized matrices. + pub(crate) matrices: Option>, /// Serialized exceptions. pub(crate) exceptions: Option>, /// Serialized quota exceeded errors. @@ -665,6 +701,9 @@ pub(crate) fn write( ports: sc_writer.ports.take(), transform_streams: sc_writer.transform_streams_port.take(), points: sc_writer.points.take(), + rects: sc_writer.rects.take(), + quads: sc_writer.quads.take(), + matrices: sc_writer.matrices.take(), exceptions: sc_writer.exceptions.take(), quota_exceeded_errors: sc_writer.quota_exceeded_errors.take(), blobs: sc_writer.blobs.take(), @@ -694,6 +733,9 @@ pub(crate) fn read( transform_streams_port_impls: data.transform_streams.take(), blob_impls: data.blobs.take(), points: data.points.take(), + rects: data.rects.take(), + quads: data.quads.take(), + matrices: data.matrices.take(), exceptions: data.exceptions.take(), quota_exceeded_errors: data.quota_exceeded_errors.take(), image_bitmaps: data.image_bitmaps.take(), diff --git a/components/script/dom/dommatrix.rs b/components/script/dom/dommatrix.rs index bfc6b32aa21..dc4e8bc4c35 100644 --- a/components/script/dom/dommatrix.rs +++ b/components/script/dom/dommatrix.rs @@ -2,6 +2,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +use std::collections::HashMap; + +use base::id::{DomMatrixId, DomMatrixIndex}; +use constellation_traits::DomMatrix; use dom_struct::dom_struct; use euclid::default::Transform3D; use js::rust::{CustomAutoRooterGuard, HandleObject}; @@ -15,6 +19,8 @@ use crate::dom::bindings::error::Fallible; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::reflector::reflect_dom_object_with_proto; use crate::dom::bindings::root::DomRoot; +use crate::dom::bindings::serializable::Serializable; +use crate::dom::bindings::structuredclone::StructuredData; use crate::dom::dommatrixreadonly::{ DOMMatrixReadOnly, dommatrixinit_to_matrix, entries_to_matrix, transform_to_matrix, }; @@ -472,3 +478,86 @@ impl DOMMatrixMethods for DOMMatrix { DomRoot::from_ref(self) } } + +impl Serializable for DOMMatrix { + type Index = DomMatrixIndex; + type Data = DomMatrix; + + fn serialize(&self) -> Result<(DomMatrixId, Self::Data), ()> { + let serialized = if self.parent.is2D() { + DomMatrix { + matrix: Transform3D::new( + self.M11(), + self.M12(), + f64::NAN, + f64::NAN, + self.M21(), + self.M22(), + f64::NAN, + f64::NAN, + f64::NAN, + f64::NAN, + f64::NAN, + f64::NAN, + self.M41(), + self.M42(), + f64::NAN, + f64::NAN, + ), + is_2d: true, + } + } else { + DomMatrix { + matrix: *self.parent.matrix(), + is_2d: false, + } + }; + Ok((DomMatrixId::new(), serialized)) + } + + fn deserialize( + owner: &GlobalScope, + serialized: Self::Data, + can_gc: CanGc, + ) -> Result, ()> + where + Self: Sized, + { + if serialized.is_2d { + Ok(Self::new( + owner, + true, + Transform3D::new( + serialized.matrix.m11, + serialized.matrix.m12, + 0.0, + 0.0, + serialized.matrix.m21, + serialized.matrix.m22, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + serialized.matrix.m41, + serialized.matrix.m42, + 0.0, + 1.0, + ), + can_gc, + )) + } else { + Ok(Self::new(owner, false, serialized.matrix, can_gc)) + } + } + + fn serialized_storage<'a>( + data: StructuredData<'a, '_>, + ) -> &'a mut Option> { + match data { + StructuredData::Reader(reader) => &mut reader.matrices, + StructuredData::Writer(writer) => &mut writer.matrices, + } + } +} diff --git a/components/script/dom/dommatrixreadonly.rs b/components/script/dom/dommatrixreadonly.rs index 8954e8cab57..e0862276d0d 100644 --- a/components/script/dom/dommatrixreadonly.rs +++ b/components/script/dom/dommatrixreadonly.rs @@ -3,8 +3,11 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use std::cell::Cell; +use std::collections::HashMap; use std::{f64, ptr}; +use base::id::{DomMatrixId, DomMatrixIndex}; +use constellation_traits::DomMatrix; use cssparser::{Parser, ParserInput}; use dom_struct::dom_struct; use euclid::Angle; @@ -30,7 +33,9 @@ use crate::dom::bindings::error::Fallible; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto}; use crate::dom::bindings::root::DomRoot; +use crate::dom::bindings::serializable::Serializable; use crate::dom::bindings::str::DOMString; +use crate::dom::bindings::structuredclone::StructuredData; use crate::dom::dommatrix::DOMMatrix; use crate::dom::dompoint::DOMPoint; use crate::dom::globalscope::GlobalScope; @@ -924,6 +929,89 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly { } } +impl Serializable for DOMMatrixReadOnly { + type Index = DomMatrixIndex; + type Data = DomMatrix; + + fn serialize(&self) -> Result<(DomMatrixId, Self::Data), ()> { + let serialized = if self.is2D() { + DomMatrix { + matrix: Transform3D::new( + self.M11(), + self.M12(), + f64::NAN, + f64::NAN, + self.M21(), + self.M22(), + f64::NAN, + f64::NAN, + f64::NAN, + f64::NAN, + f64::NAN, + f64::NAN, + self.M41(), + self.M42(), + f64::NAN, + f64::NAN, + ), + is_2d: true, + } + } else { + DomMatrix { + matrix: *self.matrix(), + is_2d: false, + } + }; + Ok((DomMatrixId::new(), serialized)) + } + + fn deserialize( + owner: &GlobalScope, + serialized: Self::Data, + can_gc: CanGc, + ) -> Result, ()> + where + Self: Sized, + { + if serialized.is_2d { + Ok(Self::new( + owner, + true, + Transform3D::new( + serialized.matrix.m11, + serialized.matrix.m12, + 0.0, + 0.0, + serialized.matrix.m21, + serialized.matrix.m22, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + serialized.matrix.m41, + serialized.matrix.m42, + 0.0, + 1.0, + ), + can_gc, + )) + } else { + Ok(Self::new(owner, false, serialized.matrix, can_gc)) + } + } + + fn serialized_storage<'a>( + data: StructuredData<'a, '_>, + ) -> &'a mut Option> { + match data { + StructuredData::Reader(reader) => &mut reader.matrices, + StructuredData::Writer(writer) => &mut writer.matrices, + } + } +} + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-dommatrixreadonly-numbersequence pub(crate) fn entries_to_matrix(entries: &[f64]) -> Fallible<(bool, Transform3D)> { if let Ok(array) = entries.try_into() { diff --git a/components/script/dom/domquad.rs b/components/script/dom/domquad.rs index ac5df6fd36b..44b21d9f4cc 100644 --- a/components/script/dom/domquad.rs +++ b/components/script/dom/domquad.rs @@ -2,6 +2,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +use std::collections::HashMap; + +use base::id::{DomQuadId, DomQuadIndex}; +use constellation_traits::{DomPoint, DomQuad}; use dom_struct::dom_struct; use js::rust::HandleObject; @@ -11,6 +15,8 @@ use crate::dom::bindings::codegen::Bindings::DOMRectReadOnlyBinding::DOMRectInit use crate::dom::bindings::error::Fallible; use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto}; use crate::dom::bindings::root::{Dom, DomRoot}; +use crate::dom::bindings::serializable::Serializable; +use crate::dom::bindings::structuredclone::StructuredData; use crate::dom::dompoint::DOMPoint; use crate::dom::domrect::DOMRect; use crate::dom::globalscope::GlobalScope; @@ -203,3 +209,56 @@ impl DOMQuadMethods for DOMQuad { ) } } + +impl Serializable for DOMQuad { + type Index = DomQuadIndex; + type Data = DomQuad; + + fn serialize(&self) -> Result<(DomQuadId, Self::Data), ()> { + let make_point = |src: DomRoot| -> DomPoint { + DomPoint { + x: src.X(), + y: src.Y(), + z: src.Z(), + w: src.W(), + } + }; + let serialized = DomQuad { + p1: make_point(self.P1()), + p2: make_point(self.P2()), + p3: make_point(self.P3()), + p4: make_point(self.P4()), + }; + Ok((DomQuadId::new(), serialized)) + } + + fn deserialize( + owner: &GlobalScope, + serialized: Self::Data, + can_gc: CanGc, + ) -> Result, ()> + where + Self: Sized, + { + let make_point = |src: DomPoint| -> DomRoot { + DOMPoint::new(owner, src.x, src.y, src.z, src.w, can_gc) + }; + Ok(Self::new( + owner, + &make_point(serialized.p1), + &make_point(serialized.p2), + &make_point(serialized.p3), + &make_point(serialized.p4), + can_gc, + )) + } + + fn serialized_storage<'a>( + data: StructuredData<'a, '_>, + ) -> &'a mut Option> { + match data { + StructuredData::Reader(reader) => &mut reader.quads, + StructuredData::Writer(writer) => &mut writer.quads, + } + } +} diff --git a/components/script/dom/domrect.rs b/components/script/dom/domrect.rs index 632d2846e1c..705e40d448b 100644 --- a/components/script/dom/domrect.rs +++ b/components/script/dom/domrect.rs @@ -2,6 +2,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +use std::collections::HashMap; + +use base::id::{DomRectId, DomRectIndex}; +use constellation_traits::DomRect; use dom_struct::dom_struct; use js::rust::HandleObject; @@ -12,6 +16,8 @@ use crate::dom::bindings::codegen::Bindings::DOMRectReadOnlyBinding::{ use crate::dom::bindings::error::Fallible; use crate::dom::bindings::reflector::{reflect_dom_object, reflect_dom_object_with_proto}; use crate::dom::bindings::root::DomRoot; +use crate::dom::bindings::serializable::Serializable; +use crate::dom::bindings::structuredclone::StructuredData; use crate::dom::domrectreadonly::{DOMRectReadOnly, create_a_domrectreadonly_from_the_dictionary}; use crate::dom::globalscope::GlobalScope; use crate::script_runtime::CanGc; @@ -121,3 +127,45 @@ impl DOMRectMethods for DOMRect { self.rect.set_height(value); } } + +impl Serializable for DOMRect { + type Index = DomRectIndex; + type Data = DomRect; + + fn serialize(&self) -> Result<(DomRectId, Self::Data), ()> { + let serialized = DomRect { + x: self.X(), + y: self.Y(), + width: self.Width(), + height: self.Height(), + }; + Ok((DomRectId::new(), serialized)) + } + + fn deserialize( + owner: &GlobalScope, + serialized: Self::Data, + can_gc: CanGc, + ) -> Result, ()> + where + Self: Sized, + { + Ok(Self::new( + owner, + serialized.x, + serialized.y, + serialized.width, + serialized.height, + can_gc, + )) + } + + fn serialized_storage<'a>( + data: StructuredData<'a, '_>, + ) -> &'a mut Option> { + match data { + StructuredData::Reader(reader) => &mut reader.rects, + StructuredData::Writer(writer) => &mut writer.rects, + } + } +} diff --git a/components/script/dom/domrectreadonly.rs b/components/script/dom/domrectreadonly.rs index a7efa5725bb..df7fab4faf4 100644 --- a/components/script/dom/domrectreadonly.rs +++ b/components/script/dom/domrectreadonly.rs @@ -3,7 +3,10 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use std::cell::Cell; +use std::collections::HashMap; +use base::id::{DomRectId, DomRectIndex}; +use constellation_traits::DomRect; use dom_struct::dom_struct; use js::rust::HandleObject; @@ -15,6 +18,8 @@ use crate::dom::bindings::reflector::{ Reflector, reflect_dom_object, reflect_dom_object_with_proto, }; use crate::dom::bindings::root::DomRoot; +use crate::dom::bindings::serializable::Serializable; +use crate::dom::bindings::structuredclone::StructuredData; use crate::dom::globalscope::GlobalScope; use crate::script_runtime::CanGc; @@ -196,3 +201,48 @@ pub(super) fn create_a_domrectreadonly_from_the_dictionary(other: &DOMRectInit) height: Cell::new(other.height), } } + +type Type = DomRectId; + +impl Serializable for DOMRectReadOnly { + type Index = DomRectIndex; + type Data = DomRect; + + fn serialize(&self) -> Result<(DomRectId, Self::Data), ()> { + let serialized = DomRect { + x: self.X(), + y: self.Y(), + width: self.Width(), + height: self.Height(), + }; + Ok((DomRectId::new(), serialized)) + } + + fn deserialize( + owner: &GlobalScope, + serialized: Self::Data, + can_gc: CanGc, + ) -> Result, ()> + where + Self: Sized, + { + Ok(Self::new( + owner, + None, + serialized.x, + serialized.y, + serialized.width, + serialized.height, + can_gc, + )) + } + + fn serialized_storage<'a>( + data: StructuredData<'a, '_>, + ) -> &'a mut Option> { + match data { + StructuredData::Reader(reader) => &mut reader.rects, + StructuredData::Writer(writer) => &mut writer.rects, + } + } +} diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 86571029bef..9713e491bce 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -1773,7 +1773,7 @@ impl ScriptThread { source_browsing_context, origin, source_origin, - data, + *data, ), ScriptThreadMessage::UpdatePipelineId( parent_pipeline_id, diff --git a/components/script_bindings/webidls/DOMMatrix.webidl b/components/script_bindings/webidls/DOMMatrix.webidl index a6e4408994e..0feaec567ce 100644 --- a/components/script_bindings/webidls/DOMMatrix.webidl +++ b/components/script_bindings/webidls/DOMMatrix.webidl @@ -5,7 +5,8 @@ // https://drafts.fxtf.org/geometry/#dommatrix [Exposed=(Window,Worker,PaintWorklet), - LegacyWindowAlias=(SVGMatrix,WebKitCSSMatrix)] + LegacyWindowAlias=(SVGMatrix,WebKitCSSMatrix), + Serializable] interface DOMMatrix : DOMMatrixReadOnly { [Throws] constructor(optional (DOMString or sequence) init); diff --git a/components/script_bindings/webidls/DOMMatrixReadOnly.webidl b/components/script_bindings/webidls/DOMMatrixReadOnly.webidl index 92993905db4..123541c4a09 100644 --- a/components/script_bindings/webidls/DOMMatrixReadOnly.webidl +++ b/components/script_bindings/webidls/DOMMatrixReadOnly.webidl @@ -10,7 +10,8 @@ * related or neighboring rights to this work. */ -[Exposed=(Window,Worker,PaintWorklet)] +[Exposed=(Window,Worker,PaintWorklet), + Serializable] interface DOMMatrixReadOnly { [Throws] constructor(optional (DOMString or sequence) init); diff --git a/components/script_bindings/webidls/DOMQuad.webidl b/components/script_bindings/webidls/DOMQuad.webidl index ba58ccffc48..e64f6368cbf 100644 --- a/components/script_bindings/webidls/DOMQuad.webidl +++ b/components/script_bindings/webidls/DOMQuad.webidl @@ -10,7 +10,8 @@ * related or neighboring rights to this work. */ -[Exposed=(Window,Worker)] +[Exposed=(Window,Worker), + Serializable] interface DOMQuad { [Throws] constructor(optional DOMPointInit p1 = {}, optional DOMPointInit p2 = {}, optional DOMPointInit p3 = {}, optional DOMPointInit p4 = {}); diff --git a/components/script_bindings/webidls/DOMRect.webidl b/components/script_bindings/webidls/DOMRect.webidl index 1f987943e6d..aee406502fc 100644 --- a/components/script_bindings/webidls/DOMRect.webidl +++ b/components/script_bindings/webidls/DOMRect.webidl @@ -5,7 +5,7 @@ // https://drafts.fxtf.org/geometry/#domrect [Exposed=(Window,Worker), - /*Serializable,*/ + Serializable, LegacyWindowAlias=SVGRect] interface DOMRect : DOMRectReadOnly { [Throws] constructor(optional unrestricted double x = 0, optional unrestricted double y = 0, diff --git a/components/script_bindings/webidls/DOMRectReadOnly.webidl b/components/script_bindings/webidls/DOMRectReadOnly.webidl index 5ff06230f59..b8bc3057675 100644 --- a/components/script_bindings/webidls/DOMRectReadOnly.webidl +++ b/components/script_bindings/webidls/DOMRectReadOnly.webidl @@ -5,7 +5,7 @@ // https://drafts.fxtf.org/geometry/#domrect [Exposed=(Window,Worker), - /*Serializable*/] + Serializable] interface DOMRectReadOnly { [Throws] constructor(optional unrestricted double x = 0, optional unrestricted double y = 0, optional unrestricted double width = 0, optional unrestricted double height = 0); diff --git a/components/shared/base/id.rs b/components/shared/base/id.rs index ebd084f596c..a24e355a2d0 100644 --- a/components/shared/base/id.rs +++ b/components/shared/base/id.rs @@ -366,6 +366,12 @@ namespace_id! {BlobId, BlobIndex, "Blob"} namespace_id! {DomPointId, DomPointIndex, "DomPoint"} +namespace_id! {DomRectId, DomRectIndex, "DomRect"} + +namespace_id! {DomQuadId, DomQuadIndex, "DomQuad"} + +namespace_id! {DomMatrixId, DomMatrixIndex, "DomMatrix"} + namespace_id! {DomExceptionId, DomExceptionIndex, "DomException"} namespace_id! {QuotaExceededErrorId, QuotaExceededErrorIndex, "QuotaExceededError"} diff --git a/components/shared/constellation/structured_data/mod.rs b/components/shared/constellation/structured_data/mod.rs index 0424cc60f94..2531e405a22 100644 --- a/components/shared/constellation/structured_data/mod.rs +++ b/components/shared/constellation/structured_data/mod.rs @@ -11,8 +11,8 @@ mod transferable; use std::collections::HashMap; use base::id::{ - BlobId, DomExceptionId, DomPointId, ImageBitmapId, MessagePortId, OffscreenCanvasId, - QuotaExceededErrorId, + BlobId, DomExceptionId, DomMatrixId, DomPointId, DomQuadId, DomRectId, ImageBitmapId, + MessagePortId, OffscreenCanvasId, QuotaExceededErrorId, }; use log::warn; use malloc_size_of_derive::MallocSizeOf; @@ -31,6 +31,12 @@ pub struct StructuredSerializedData { pub blobs: Option>, /// Serialized point objects. pub points: Option>, + /// Serialized rect objects. + pub rects: Option>, + /// Serialized quad objects. + pub quads: Option>, + /// Serialized matrix objects. + pub matrices: Option>, /// Serialized exception objects. pub exceptions: Option>, /// Serialized quota exceeded errors. diff --git a/components/shared/constellation/structured_data/serializable.rs b/components/shared/constellation/structured_data/serializable.rs index db442d981b6..62cc158421b 100644 --- a/components/shared/constellation/structured_data/serializable.rs +++ b/components/shared/constellation/structured_data/serializable.rs @@ -11,7 +11,11 @@ use std::cell::RefCell; use std::collections::HashMap; use std::path::PathBuf; -use base::id::{BlobId, DomExceptionId, DomPointId, ImageBitmapId, QuotaExceededErrorId}; +use base::id::{ + BlobId, DomExceptionId, DomMatrixId, DomPointId, DomQuadId, DomRectId, ImageBitmapId, + QuotaExceededErrorId, +}; +use euclid::default::Transform3D; use malloc_size_of_derive::MallocSizeOf; use net_traits::filemanager_thread::RelativePos; use pixels::Snapshot; @@ -49,6 +53,16 @@ pub enum Serializable { DomPoint, /// The `DOMPointReadOnly` interface. DomPointReadOnly, + /// The `DOMRect` interface. + DomRect, + /// The `DOMRectReadOnly` interface. + DomRectReadOnly, + /// The `DOMQuad` interface. + DomQuad, + /// The `DOMMatrix` interface. + DomMatrix, + /// The `DOMMatrixReadOnly` interface. + DomMatrixReadOnly, /// The `QuotaExceededError` interface. QuotaExceededError, /// The `DOMException` interface. @@ -63,10 +77,17 @@ impl Serializable { ) -> fn(&StructuredSerializedData, &mut StructuredSerializedData) { match self { Serializable::Blob => StructuredSerializedData::clone_all_of_type::, + Serializable::DomPoint => StructuredSerializedData::clone_all_of_type::, Serializable::DomPointReadOnly => { StructuredSerializedData::clone_all_of_type:: }, - Serializable::DomPoint => StructuredSerializedData::clone_all_of_type::, + Serializable::DomRect => StructuredSerializedData::clone_all_of_type::, + Serializable::DomRectReadOnly => StructuredSerializedData::clone_all_of_type::, + Serializable::DomQuad => StructuredSerializedData::clone_all_of_type::, + Serializable::DomMatrix => StructuredSerializedData::clone_all_of_type::, + Serializable::DomMatrixReadOnly => { + StructuredSerializedData::clone_all_of_type:: + }, Serializable::DomException => { StructuredSerializedData::clone_all_of_type:: }, @@ -300,6 +321,101 @@ impl BroadcastClone for DomPoint { } } +#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)] +/// A serializable version of the DOMRect/DOMRectReadOnly interface. +pub struct DomRect { + /// The x coordinate. + pub x: f64, + /// The y coordinate. + pub y: f64, + /// The width. + pub width: f64, + /// The height. + pub height: f64, +} + +impl BroadcastClone for DomRect { + type Id = DomRectId; + + fn source( + data: &StructuredSerializedData, + ) -> &Option> { + &data.rects + } + + fn destination( + data: &mut StructuredSerializedData, + ) -> &mut Option> { + &mut data.rects + } + + fn clone_for_broadcast(&self) -> Option { + Some(self.clone()) + } +} + +#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)] +/// A serializable version of the DOMQuad interface. +pub struct DomQuad { + /// The first point. + pub p1: DomPoint, + /// The second point. + pub p2: DomPoint, + /// The third point. + pub p3: DomPoint, + /// The fourth point. + pub p4: DomPoint, +} + +impl BroadcastClone for DomQuad { + type Id = DomQuadId; + + fn source( + data: &StructuredSerializedData, + ) -> &Option> { + &data.quads + } + + fn destination( + data: &mut StructuredSerializedData, + ) -> &mut Option> { + &mut data.quads + } + + fn clone_for_broadcast(&self) -> Option { + Some(self.clone()) + } +} + +#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)] +/// A serializable version of the DOMMatrix/DOMMatrixReadOnly interface. +pub struct DomMatrix { + /// The matrix. + pub matrix: Transform3D, + /// Whether this matrix represents a 2D transformation. + pub is_2d: bool, +} + +impl BroadcastClone for DomMatrix { + type Id = DomMatrixId; + + fn source( + data: &StructuredSerializedData, + ) -> &Option> { + &data.matrices + } + + fn destination( + data: &mut StructuredSerializedData, + ) -> &mut Option> { + &mut data.matrices + } + + fn clone_for_broadcast(&self) -> Option { + Some(self.clone()) + } +} + #[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)] /// A serializable version of the DOMException interface. pub struct DomException { diff --git a/components/shared/script/lib.rs b/components/shared/script/lib.rs index 7028d202aaf..a5b725b7e31 100644 --- a/components/shared/script/lib.rs +++ b/components/shared/script/lib.rs @@ -182,7 +182,7 @@ pub enum ScriptThreadMessage { /// source_origin: ImmutableOrigin, /// The data to be posted. - data: StructuredSerializedData, + data: Box, }, /// Updates the current pipeline ID of a given iframe. /// First PipelineId is for the parent, second is the new PipelineId for the frame. diff --git a/tests/wpt/meta/css/geometry/structured-serialization.html.ini b/tests/wpt/meta/css/geometry/structured-serialization.html.ini deleted file mode 100644 index 2b817e6c20b..00000000000 --- a/tests/wpt/meta/css/geometry/structured-serialization.html.ini +++ /dev/null @@ -1,66 +0,0 @@ -[structured-serialization.html] - [DOMRectReadOnly clone: basic] - expected: FAIL - - [DOMRectReadOnly clone: custom property] - expected: FAIL - - [DOMRectReadOnly clone: throwing getters] - expected: FAIL - - [DOMRectReadOnly clone: non-initial values] - expected: FAIL - - [DOMRect clone: basic] - expected: FAIL - - [DOMRect clone: custom property] - expected: FAIL - - [DOMRect clone: throwing getters] - expected: FAIL - - [DOMRect clone: non-initial values] - expected: FAIL - - [DOMQuad clone: basic] - expected: FAIL - - [DOMQuad clone: custom property] - expected: FAIL - - [DOMQuad clone: throwing getters] - expected: FAIL - - [DOMQuad clone: non-initial values] - expected: FAIL - - [DOMMatrixReadOnly clone: basic] - expected: FAIL - - [DOMMatrixReadOnly clone: custom property] - expected: FAIL - - [DOMMatrixReadOnly clone: throwing getters] - expected: FAIL - - [DOMMatrixReadOnly clone: non-initial values (2d)] - expected: FAIL - - [DOMMatrixReadOnly clone: non-initial values (3d)] - expected: FAIL - - [DOMMatrix clone: basic] - expected: FAIL - - [DOMMatrix clone: custom property] - expected: FAIL - - [DOMMatrix clone: throwing getters] - expected: FAIL - - [DOMMatrix clone: non-initial values (2d)] - expected: FAIL - - [DOMMatrix clone: non-initial values (3d)] - expected: FAIL diff --git a/tests/wpt/meta/intersection-observer/same-origin-grand-child-iframe.sub.html.ini b/tests/wpt/meta/intersection-observer/same-origin-grand-child-iframe.sub.html.ini index b0c66eef5a4..8cc9dfe7b58 100644 --- a/tests/wpt/meta/intersection-observer/same-origin-grand-child-iframe.sub.html.ini +++ b/tests/wpt/meta/intersection-observer/same-origin-grand-child-iframe.sub.html.ini @@ -1,4 +1,3 @@ [same-origin-grand-child-iframe.sub.html] - expected: TIMEOUT [rootBounds in a same-origin iframe in the case where there is a cross-origin iframe in between the top document and the same origin iframe] - expected: TIMEOUT + expected: FAIL