From 8a837778d9fe273aa8c3ce5aa9824dcca0c76e6f Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Sun, 4 May 2025 22:20:56 +0200 Subject: Create new image cache per document (#36832) Rather than sharing the full image cache in a script_thread, the image cache is now unique per document. This ensures that CSP factors no longer affect whether the image is retrieved from the cache incorrectly. To do so, the thread_pool is shared across all caches, but the store is fresh. Except for the place_holder{image,url}, which are cloned. That's because the `rippy_data` is only available in the constellation and no longer accessible at the point that we need to create the document in the script_thread. Contrary to the description in #36505, the script_thread still has an image_cache for this reason: so it has access to the store and thread_pool to clone it. With these changes, the two CSP tests no longer flake. Confirmed with running the following commmand: ``` ./mach test-wpt tests/wpt/tests/content-security-policy/generic/ --rerun=10 ``` Fixes #36505 Signed-off-by: Tim van der Lippe --- components/script/script_thread.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'components/script/script_thread.rs') diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 7241c115a2a..6e192cc920c 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -745,7 +745,9 @@ impl ScriptThread { .senders .pipeline_to_constellation_sender .clone(), - image_cache: script_thread.image_cache.clone(), + image_cache: script_thread + .image_cache + .create_new_image_cache(script_thread.compositor_api.clone()), #[cfg(feature = "webgpu")] gpu_id_hub: script_thread.gpu_id_hub.clone(), inherited_secure_context: script_thread.inherited_secure_context, @@ -2443,8 +2445,6 @@ impl ScriptThread { let prefix = format!("url({urls})"); reports.extend(self.get_cx().get_reports(prefix.clone(), ops)); - - reports.push(self.image_cache.memory_report(&prefix, ops)); }); reports_chan.send(ProcessReports::new(reports)); @@ -3145,13 +3145,17 @@ impl ScriptThread { self.resource_threads.clone(), )); + let image_cache = self + .image_cache + .create_new_image_cache(self.compositor_api.clone()); + let layout_config = LayoutConfig { id: incomplete.pipeline_id, webview_id: incomplete.webview_id, url: final_url.clone(), is_iframe: incomplete.parent_info.is_some(), script_chan: self.senders.constellation_sender.clone(), - image_cache: self.image_cache.clone(), + image_cache: image_cache.clone(), font_context: font_context.clone(), time_profiler_chan: self.senders.time_profiler_sender.clone(), compositor_api: self.compositor_api.clone(), @@ -3166,7 +3170,7 @@ impl ScriptThread { self.layout_factory.create(layout_config), font_context, self.senders.image_cache_sender.clone(), - self.image_cache.clone(), + image_cache.clone(), self.resource_threads.clone(), #[cfg(feature = "bluetooth")] self.senders.bluetooth_sender.clone(), -- cgit v1.2.3