Include WebViewId into EmbedderMsg variants where possible (#35211)

`EmbedderMsg` was previously paired with an implicit
`Option<WebViewId>`, even though almost all variants were either always
`Some` or always `None`, depending on whether there was a `WebView
involved.

This patch adds the `WebViewId` to as many `EmbedderMsg` variants as
possible, so we can call their associated `WebView` delegate methods
without needing to check and unwrap the `Option`. In many cases, this
required more changes to plumb through the `WebViewId`.

Notably, all `Request`s now explicitly need a `WebView` or not, in order
to ensure that it is passed when appropriate.

Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Delan Azabani 2025-01-30 19:15:35 +08:00 committed by GitHub
parent 9eeb602f7a
commit 5e9de2cb61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
70 changed files with 809 additions and 753 deletions

View file

@ -16,7 +16,7 @@ use std::sync::{Arc, LazyLock};
use app_units::Au;
use base::cross_process_instant::CrossProcessInstant;
use base::id::PipelineId;
use base::id::{PipelineId, WebViewId};
use base::Epoch;
use embedder_traits::resources::{self, Resource};
use euclid::default::{Point2D as UntypedPoint2D, Rect as UntypedRect, Size2D as UntypedSize2D};
@ -105,6 +105,9 @@ pub struct LayoutThread {
/// The ID of the pipeline that we belong to.
id: PipelineId,
/// The webview that contains the pipeline we belong to.
webview_id: WebViewId,
/// The URL of the pipeline that we belong to.
url: ServoUrl,
@ -169,18 +172,7 @@ pub struct LayoutFactoryImpl();
impl LayoutFactory for LayoutFactoryImpl {
fn create(&self, config: LayoutConfig) -> Box<dyn Layout> {
Box::new(LayoutThread::new(
config.id,
config.url,
config.is_iframe,
config.script_chan,
config.image_cache,
config.font_context,
config.time_profiler_chan,
config.compositor_api,
config.paint_time_metrics,
config.window_size,
))
Box::new(LayoutThread::new(config))
}
}
@ -476,23 +468,12 @@ impl Layout for LayoutThread {
}
}
#[allow(clippy::too_many_arguments)]
impl LayoutThread {
#[allow(clippy::too_many_arguments)]
fn new(
id: PipelineId,
url: ServoUrl,
is_iframe: bool,
script_chan: IpcSender<ConstellationControlMsg>,
image_cache: Arc<dyn ImageCache>,
font_context: Arc<FontContext>,
time_profiler_chan: profile_time::ProfilerChan,
compositor_api: CrossProcessCompositorApi,
paint_time_metrics: PaintTimeMetrics,
window_size: WindowSizeData,
) -> LayoutThread {
fn new(config: LayoutConfig) -> LayoutThread {
// Let webrender know about this pipeline by sending an empty display list.
compositor_api.send_initial_transaction(id.into());
config
.compositor_api
.send_initial_transaction(config.id.into());
let mut font = Font::initial_values();
let default_font_size = pref!(fonts_default_size);
@ -507,23 +488,24 @@ impl LayoutThread {
let device = Device::new(
MediaType::screen(),
QuirksMode::NoQuirks,
window_size.initial_viewport,
Scale::new(window_size.device_pixel_ratio.get()),
Box::new(LayoutFontMetricsProvider(font_context.clone())),
config.window_size.initial_viewport,
Scale::new(config.window_size.device_pixel_ratio.get()),
Box::new(LayoutFontMetricsProvider(config.font_context.clone())),
ComputedValues::initial_values_with_font_override(font),
// TODO: obtain preferred color scheme from embedder
PrefersColorScheme::Light,
);
LayoutThread {
id,
url,
is_iframe,
script_chan: script_chan.clone(),
time_profiler_chan,
id: config.id,
webview_id: config.webview_id,
url: config.url,
is_iframe: config.is_iframe,
script_chan: config.script_chan.clone(),
time_profiler_chan: config.time_profiler_chan,
registered_painters: RegisteredPaintersImpl(Default::default()),
image_cache,
font_context,
image_cache: config.image_cache,
font_context: config.font_context,
first_reflow: Cell::new(true),
generation: Cell::new(0),
box_tree: Default::default(),
@ -531,14 +513,14 @@ impl LayoutThread {
// Epoch starts at 1 because of the initial display list for epoch 0 that we send to WR
epoch: Cell::new(Epoch(1)),
viewport_size: Size2D::new(
Au::from_f32_px(window_size.initial_viewport.width),
Au::from_f32_px(window_size.initial_viewport.height),
Au::from_f32_px(config.window_size.initial_viewport.width),
Au::from_f32_px(config.window_size.initial_viewport.height),
),
compositor_api,
compositor_api: config.compositor_api,
scroll_offsets: Default::default(),
stylist: Stylist::new(device, QuirksMode::NoQuirks),
webrender_image_cache: Default::default(),
paint_time_metrics,
paint_time_metrics: config.paint_time_metrics,
debug: opts::get().debug.clone(),
}
}
@ -619,6 +601,7 @@ impl LayoutThread {
};
self.font_context.add_all_web_fonts_from_stylesheet(
self.webview_id,
stylesheet,
guard,
self.stylist.device(),