mirror of
https://github.com/servo/servo.git
synced 2025-08-02 04:00:32 +01:00
Auto merge of #23661 - julientregoat:i-21289, r=jdm
Refactor ImageCache::find_image_or_metadata -> ImageCache::{get_image, track_image} <!-- Please describe your changes on the following line: --> Updated the `ImageCache` trait to replace `find_image_or_metadata` with two new functions `track_image` and `get_image`, as well as a new enum (`ImageCacheResult`). As a result, I was able to refactor the functions that previously called `find_image_or_metadata` pretty cleanly. For a list of these functions, please see the commit information. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #21289 (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because tests already exist for these components. I ran `cargo test` in `net`, `net_traits`, `layout`, and `script` successfully. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23661) <!-- Reviewable:end -->
This commit is contained in:
commit
c9480c8e07
9 changed files with 282 additions and 242 deletions
|
@ -432,8 +432,7 @@ impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes {
|
|||
|
||||
pub mod utils {
|
||||
use crate::dom::window::Window;
|
||||
use net_traits::image_cache::CanRequestImages;
|
||||
use net_traits::image_cache::{ImageOrMetadataAvailable, ImageResponse, UsePlaceholder};
|
||||
use net_traits::image_cache::ImageResponse;
|
||||
use net_traits::request::CorsSettings;
|
||||
use servo_url::ServoUrl;
|
||||
|
||||
|
@ -443,18 +442,15 @@ pub mod utils {
|
|||
cors_setting: Option<CorsSettings>,
|
||||
) -> ImageResponse {
|
||||
let image_cache = window.image_cache();
|
||||
let response = image_cache.find_image_or_metadata(
|
||||
url.into(),
|
||||
let result = image_cache.get_image(
|
||||
url.clone(),
|
||||
window.origin().immutable().clone(),
|
||||
cors_setting,
|
||||
UsePlaceholder::No,
|
||||
CanRequestImages::No,
|
||||
);
|
||||
match response {
|
||||
Ok(ImageOrMetadataAvailable::ImageAvailable(image, url)) => {
|
||||
ImageResponse::Loaded(image, url)
|
||||
},
|
||||
_ => ImageResponse::None,
|
||||
|
||||
match result {
|
||||
Some(image) => ImageResponse::Loaded(image, url),
|
||||
None => ImageResponse::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue