diff --git a/Userland/Libraries/LibWeb/HTML/SharedImageRequest.cpp b/Userland/Libraries/LibWeb/HTML/SharedImageRequest.cpp
index 50e7a33f507..8ebc6ca479c 100644
--- a/Userland/Libraries/LibWeb/HTML/SharedImageRequest.cpp
+++ b/Userland/Libraries/LibWeb/HTML/SharedImageRequest.cpp
@@ -145,27 +145,18 @@ 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_successful_decode = [](SharedImageRequest& self) {
- self.m_state = State::Finished;
- for (auto& callback : self.m_callbacks) {
- if (callback.on_finish)
- callback.on_finish->function()();
- }
- self.m_callbacks.clear();
- };
-
if (is_svg_image) {
auto result = SVG::SVGDecodedImageData::create(m_document->realm(), m_page, url_string, data);
if (result.is_error()) {
handle_failed_fetch();
} else {
m_image_data = result.release_value();
- handle_successful_decode(*this);
+ handle_successful_resource_load();
}
return;
}
- auto handle_successful_bitmap_decode = [strong_this = JS::Handle(*this), handle_successful_decode = move(handle_successful_decode)](Web::Platform::DecodedImage& result) -> ErrorOr {
+ auto handle_successful_bitmap_decode = [strong_this = JS::Handle(*this)](Web::Platform::DecodedImage& result) -> ErrorOr {
Vector frames;
for (auto& frame : result.frames) {
frames.append(AnimatedBitmapDecodedImageData::Frame {
@@ -174,7 +165,7 @@ void SharedImageRequest::handle_successful_fetch(URL::URL const& url_string, Str
});
}
strong_this->m_image_data = AnimatedBitmapDecodedImageData::create(strong_this->m_document->realm(), move(frames), result.loop_count, result.is_animated).release_value_but_fixme_should_propagate_errors();
- handle_successful_decode(*strong_this);
+ strong_this->handle_successful_resource_load();
return {};
};
@@ -195,6 +186,16 @@ void SharedImageRequest::handle_failed_fetch()
m_callbacks.clear();
}
+void SharedImageRequest::handle_successful_resource_load()
+{
+ m_state = State::Finished;
+ for (auto& callback : m_callbacks) {
+ if (callback.on_finish)
+ callback.on_finish->function()();
+ }
+ m_callbacks.clear();
+}
+
bool SharedImageRequest::needs_fetching() const
{
return m_state == State::New;
diff --git a/Userland/Libraries/LibWeb/HTML/SharedImageRequest.h b/Userland/Libraries/LibWeb/HTML/SharedImageRequest.h
index c3e1ab4695e..c30bfc04c7d 100644
--- a/Userland/Libraries/LibWeb/HTML/SharedImageRequest.h
+++ b/Userland/Libraries/LibWeb/HTML/SharedImageRequest.h
@@ -48,6 +48,7 @@ private:
void handle_successful_fetch(URL::URL const&, StringView mime_type, ByteBuffer data);
void handle_failed_fetch();
+ void handle_successful_resource_load();
enum class State {
New,