From 20e955277a64e98515d17b92369ed01ba2ca36de Mon Sep 17 00:00:00 2001 From: Jonathan Schwender <55576758+jschwe@users.noreply.github.com> Date: Fri, 29 Aug 2025 06:22:48 +0200 Subject: [PATCH] Port ScriptToConstellation channel to generic channel (#38990) This change was previously part of fb1c0a4c48dee5791b8785e5d5d4906b935bdb76, which got reverted due to an issue with the compositor channel. Split this change out into a separate PR, as it probably should have been in the first place. Presumably it was one change before, since serialization of crossbeam generic channels in single-process mode was not implemented yet at the time. Testing: Covered by existing tests. No custom callbacks involved. Part of #38912 Signed-off-by: Jonathan Schwender --- components/constellation/constellation.rs | 9 +++------ components/script/dom/workletglobalscope.rs | 3 ++- components/script/messaging.rs | 2 +- components/shared/constellation/from_script_message.rs | 6 +++--- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 8f77500083c..612f60b87bc 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -290,7 +290,7 @@ pub struct Constellation { /// An IPC channel for script threads to send messages to the constellation. /// This is the script threads' view of `script_receiver`. - script_sender: IpcSender<(PipelineId, ScriptToConstellationMessage)>, + script_sender: GenericSender<(PipelineId, ScriptToConstellationMessage)>, /// A channel for the constellation to receive messages from script threads. /// This is the constellation's view of `script_sender`. @@ -607,11 +607,8 @@ where .name("Constellation".to_owned()) .spawn(move || { let (script_ipc_sender, script_ipc_receiver) = - ipc::channel().expect("ipc channel failure"); - let script_receiver = - route_ipc_receiver_to_new_crossbeam_receiver_preserving_errors( - script_ipc_receiver, - ); + generic_channel::channel().expect("ipc channel failure"); + let script_receiver = script_ipc_receiver.route_preserving_errors(); let (namespace_ipc_sender, namespace_ipc_receiver) = generic_channel::channel().expect("ipc channel failure"); diff --git a/components/script/dom/workletglobalscope.rs b/components/script/dom/workletglobalscope.rs index e4d35b2f17d..b095de4b6f4 100644 --- a/components/script/dom/workletglobalscope.rs +++ b/components/script/dom/workletglobalscope.rs @@ -4,6 +4,7 @@ use std::sync::Arc; +use base::generic_channel::GenericSender; use base::id::PipelineId; use constellation_traits::{ScriptToConstellationChan, ScriptToConstellationMessage}; use crossbeam_channel::Sender; @@ -196,7 +197,7 @@ pub(crate) struct WorkletGlobalScopeInit { /// Channel to devtools pub(crate) devtools_chan: Option>, /// Messages to send to constellation - pub(crate) to_constellation_sender: IpcSender<(PipelineId, ScriptToConstellationMessage)>, + pub(crate) to_constellation_sender: GenericSender<(PipelineId, ScriptToConstellationMessage)>, /// The image cache pub(crate) image_cache: Arc, /// Identity manager for WebGPU resources diff --git a/components/script/messaging.rs b/components/script/messaging.rs index fb295a0f0d3..6104cdfaecc 100644 --- a/components/script/messaging.rs +++ b/components/script/messaging.rs @@ -340,7 +340,7 @@ pub(crate) struct ScriptThreadSenders { /// particular pipelines. #[no_trace] pub(crate) pipeline_to_constellation_sender: - IpcSender<(PipelineId, ScriptToConstellationMessage)>, + GenericSender<(PipelineId, ScriptToConstellationMessage)>, /// The shared [`IpcSender`] which is sent to the `ImageCache` when requesting an image. The /// messages on this channel are routed to crossbeam [`Sender`] on the router thread, which diff --git a/components/shared/constellation/from_script_message.rs b/components/shared/constellation/from_script_message.rs index b71a23e2561..8f2d7b464aa 100644 --- a/components/shared/constellation/from_script_message.rs +++ b/components/shared/constellation/from_script_message.rs @@ -8,6 +8,7 @@ use std::collections::HashMap; use std::fmt; use base::Epoch; +use base::generic_channel::{GenericSender, SendResult}; use base::id::{ BroadcastChannelRouterId, BrowsingContextId, HistoryStateId, MessagePortId, MessagePortRouterId, PipelineId, ServiceWorkerId, ServiceWorkerRegistrationId, WebViewId, @@ -23,7 +24,6 @@ use embedder_traits::{ use euclid::default::Size2D as UntypedSize2D; use fonts_traits::SystemFontServiceProxySender; use http::{HeaderMap, Method}; -use ipc_channel::Error as IpcError; use ipc_channel::ipc::{IpcReceiver, IpcSender}; use malloc_size_of_derive::MallocSizeOf; use net_traits::policy_container::PolicyContainer; @@ -48,14 +48,14 @@ use crate::{ #[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)] pub struct ScriptToConstellationChan { /// Sender for communicating with constellation thread. - pub sender: IpcSender<(PipelineId, ScriptToConstellationMessage)>, + pub sender: GenericSender<(PipelineId, ScriptToConstellationMessage)>, /// Used to identify the origin of the message. pub pipeline_id: PipelineId, } impl ScriptToConstellationChan { /// Send ScriptMsg and attach the pipeline_id to the message. - pub fn send(&self, msg: ScriptToConstellationMessage) -> Result<(), IpcError> { + pub fn send(&self, msg: ScriptToConstellationMessage) -> SendResult { self.sender.send((self.pipeline_id, msg)) } }