mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
LibWeb: Use handle_failed_fetch to implement handle_failed_decode
...When loading images through SharedImageRequest. There is a small behavioural difference here - handle_failed_fetch clears the pending callbacks whereas handled_failed_decode was previously not. This does not seem intentional, and appears like a bug. Implementing it this way is _slightly_ simpler - and also means we don't need to take a strong handle to this in the case of loading an SVG image.
This commit is contained in:
parent
85e8e7ec23
commit
e0f2e42687
Notes:
github-actions[bot]
2024-08-05 09:27:49 +00:00
Author: https://github.com/shannonbooth Commit: https://github.com/LadybirdBrowser/ladybird/commit/e0f2e426875 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/873 Reviewed-by: https://github.com/tcl3
1 changed files with 5 additions and 9 deletions
|
@ -145,14 +145,6 @@ void SharedImageRequest::handle_successful_fetch(URL::URL const& url_string, Str
|
|||
|
||||
bool const is_svg_image = mime_type == "image/svg+xml"sv || url_string.basename().ends_with(".svg"sv);
|
||||
|
||||
auto handle_failed_decode = [strong_this = JS::Handle(*this)](Error&) -> void {
|
||||
strong_this->m_state = State::Failed;
|
||||
for (auto& callback : strong_this->m_callbacks) {
|
||||
if (callback.on_fail)
|
||||
callback.on_fail->function()();
|
||||
}
|
||||
};
|
||||
|
||||
auto handle_successful_decode = [](SharedImageRequest& self) {
|
||||
self.m_state = State::Finished;
|
||||
for (auto& callback : self.m_callbacks) {
|
||||
|
@ -165,7 +157,7 @@ void SharedImageRequest::handle_successful_fetch(URL::URL const& url_string, Str
|
|||
if (is_svg_image) {
|
||||
auto result = SVG::SVGDecodedImageData::create(m_document->realm(), m_page, url_string, data);
|
||||
if (result.is_error()) {
|
||||
handle_failed_decode(result.error());
|
||||
handle_failed_fetch();
|
||||
} else {
|
||||
m_image_data = result.release_value();
|
||||
handle_successful_decode(*this);
|
||||
|
@ -186,6 +178,10 @@ void SharedImageRequest::handle_successful_fetch(URL::URL const& url_string, Str
|
|||
return {};
|
||||
};
|
||||
|
||||
auto handle_failed_decode = [strong_this = JS::Handle(*this)](Error&) -> void {
|
||||
strong_this->handle_failed_fetch();
|
||||
};
|
||||
|
||||
(void)Web::Platform::ImageCodecPlugin::the().decode_image(data.bytes(), move(handle_successful_bitmap_decode), move(handle_failed_decode));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue