Port ScriptToConstellation channel to generic channel (#38990)

This change was previously part of
fb1c0a4c48, 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 <schwenderjonathan@gmail.com>
This commit is contained in:
Jonathan Schwender 2025-08-29 06:22:48 +02:00 committed by GitHub
parent c4a69abe30
commit 20e955277a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 9 additions and 11 deletions

View file

@ -290,7 +290,7 @@ pub struct Constellation<STF, SWF> {
/// 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");

View file

@ -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<IpcSender<ScriptToDevtoolsControlMsg>>,
/// 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<dyn ImageCache>,
/// Identity manager for WebGPU resources

View file

@ -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

View file

@ -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))
}
}