mirror of
				https://github.com/LadybirdBrowser/ladybird.git
				synced 2025-10-31 21:30:58 +00:00 
			
		
		
		
	LbiWeb: Add and use SharedImageRequest::handle_successful_resource_load
This closer mirrors handle_failed_fetch, making the handling slightly more clear to understand. It also means that we don't need to take a strong reference to this on a successful SVG resource load.
This commit is contained in:
		
							parent
							
								
									e0f2e42687
								
							
						
					
					
						commit
						2fb5054603
					
				
				
				Notes:
				
					github-actions[bot]
				
				2024-08-05 09:27:42 +00:00 
				
			
			Author: https://github.com/shannonbooth
Commit: 2fb5054603
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/873
Reviewed-by: https://github.com/tcl3
			
					 2 changed files with 14 additions and 12 deletions
				
			
		|  | @ -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<void> { | ||||
|     auto handle_successful_bitmap_decode = [strong_this = JS::Handle(*this)](Web::Platform::DecodedImage& result) -> ErrorOr<void> { | ||||
|         Vector<AnimatedBitmapDecodedImageData::Frame> 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; | ||||
|  |  | |||
|  | @ -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, | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Shannon Booth
						Shannon Booth