LibWeb: Load external images with image/svg+xml as SVG-as-image
This commit is contained in:
parent
94a26e2715
commit
3c7b0192fa
Notes:
sideshowbarker
2024-07-16 19:57:13 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/3c7b0192fa Pull-request: https://github.com/SerenityOS/serenity/pull/18943 Reviewed-by: https://github.com/winfr34k
2 changed files with 7 additions and 6 deletions
Userland/Libraries/LibWeb/HTML
|
@ -499,8 +499,10 @@ after_step_6:
|
|||
// - If the resource type and data corresponds to a supported image format, as described below
|
||||
// - The next task that is queued by the networking task source while the image is being fetched must run the following steps:
|
||||
queue_an_element_task(HTML::Task::Source::Networking, [this, response, image_request, url_string] {
|
||||
auto process_body = [image_request, url_string, this](ByteBuffer data) {
|
||||
handle_successful_fetch(url_string, image_request, move(data));
|
||||
auto process_body = [response, image_request, url_string, this](ByteBuffer data) {
|
||||
auto extracted_mime_type = response->header_list()->extract_mime_type().release_value_but_fixme_should_propagate_errors();
|
||||
auto mime_type = extracted_mime_type.has_value() ? extracted_mime_type.value().essence().bytes_as_string_view() : StringView {};
|
||||
handle_successful_fetch(url_string, mime_type, image_request, move(data));
|
||||
};
|
||||
auto process_body_error = [this](auto) {
|
||||
handle_failed_fetch();
|
||||
|
@ -537,7 +539,7 @@ after_step_6:
|
|||
return {};
|
||||
}
|
||||
|
||||
void HTMLImageElement::handle_successful_fetch(AK::URL const& url_string, ImageRequest& image_request, ByteBuffer data)
|
||||
void HTMLImageElement::handle_successful_fetch(AK::URL const& url_string, StringView mime_type, ImageRequest& image_request, ByteBuffer data)
|
||||
{
|
||||
// AD-HOC: At this point, things gets very ad-hoc.
|
||||
// FIXME: Bring this closer to spec.
|
||||
|
@ -546,8 +548,7 @@ void HTMLImageElement::handle_successful_fetch(AK::URL const& url_string, ImageR
|
|||
m_load_event_delayer.clear();
|
||||
};
|
||||
|
||||
// FIXME: Look at the MIME type instead!
|
||||
bool is_svg_image = url_string.basename().ends_with(".svg"sv);
|
||||
bool is_svg_image = mime_type == "image/svg+xml"sv || url_string.basename().ends_with(".svg"sv);
|
||||
|
||||
RefPtr<DecodedImageData> image_data;
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ private:
|
|||
|
||||
virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
|
||||
|
||||
void handle_successful_fetch(AK::URL const&, ImageRequest&, ByteBuffer);
|
||||
void handle_successful_fetch(AK::URL const&, StringView mime_type, ImageRequest&, ByteBuffer);
|
||||
void handle_failed_fetch();
|
||||
|
||||
void animate();
|
||||
|
|
Loading…
Add table
Reference in a new issue