From e0f2e42687583aa7ae997de21f5504ba45c2985c Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sat, 3 Aug 2024 14:18:43 +1200 Subject: [PATCH] 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. --- .../Libraries/LibWeb/HTML/SharedImageRequest.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/SharedImageRequest.cpp b/Userland/Libraries/LibWeb/HTML/SharedImageRequest.cpp index 7715175b6c2..50e7a33f507 100644 --- a/Userland/Libraries/LibWeb/HTML/SharedImageRequest.cpp +++ b/Userland/Libraries/LibWeb/HTML/SharedImageRequest.cpp @@ -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)); }