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 <tvanderlippe@gmail.com>
This commit is contained in:
Tim van der Lippe 2025-05-04 22:20:56 +02:00 committed by GitHub
parent 3db0194e5a
commit 8a837778d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 68 additions and 95 deletions

View file

@ -431,7 +431,7 @@ pub struct ImageCacheImpl {
store: Arc<Mutex<ImageCacheStore>>,
/// Thread pool for image decoding
thread_pool: CoreResourceThreadPool,
thread_pool: Arc<CoreResourceThreadPool>,
}
impl ImageCache for ImageCacheImpl {
@ -454,7 +454,10 @@ impl ImageCache for ImageCacheImpl {
placeholder_url: ServoUrl::parse("chrome://resources/rippy.png").unwrap(),
compositor_api,
})),
thread_pool: CoreResourceThreadPool::new(thread_count, "ImageCache".to_string()),
thread_pool: Arc::new(CoreResourceThreadPool::new(
thread_count,
"ImageCache".to_string(),
)),
}
}
@ -651,6 +654,25 @@ impl ImageCache for ImageCacheImpl {
},
}
}
fn create_new_image_cache(
&self,
compositor_api: CrossProcessCompositorApi,
) -> Arc<dyn ImageCache> {
let store = self.store.lock().unwrap();
let placeholder_image = store.placeholder_image.clone();
let placeholder_url = store.placeholder_url.clone();
Arc::new(ImageCacheImpl {
store: Arc::new(Mutex::new(ImageCacheStore {
pending_loads: AllPendingLoads::new(),
completed_loads: HashMap::new(),
placeholder_image,
placeholder_url,
compositor_api,
})),
thread_pool: self.thread_pool.clone(),
})
}
}
impl ImageCacheImpl {