LibWeb: Don't load fallback icon for SVG documents

Skip loading a fallback favicon if Document represents a decoded SVG.

Issue: #23405
This commit is contained in:
mobounya 2024-02-29 18:13:24 +01:00 committed by Andrew Kaster
parent 44d3fd0546
commit bdb8af94ee
4 changed files with 47 additions and 34 deletions

View file

@ -107,6 +107,7 @@
#include <LibWeb/PermissionsPolicy/AutoplayAllowlist.h> #include <LibWeb/PermissionsPolicy/AutoplayAllowlist.h>
#include <LibWeb/ResizeObserver/ResizeObserver.h> #include <LibWeb/ResizeObserver/ResizeObserver.h>
#include <LibWeb/ResizeObserver/ResizeObserverEntry.h> #include <LibWeb/ResizeObserver/ResizeObserverEntry.h>
#include <LibWeb/SVG/SVGDecodedImageData.h>
#include <LibWeb/SVG/SVGElement.h> #include <LibWeb/SVG/SVGElement.h>
#include <LibWeb/SVG/SVGTitleElement.h> #include <LibWeb/SVG/SVGTitleElement.h>
#include <LibWeb/SVG/TagNames.h> #include <LibWeb/SVG/TagNames.h>
@ -2154,6 +2155,9 @@ void Document::update_readiness(HTML::DocumentReadyState readiness_value)
if (readiness_value == HTML::DocumentReadyState::Complete) { if (readiness_value == HTML::DocumentReadyState::Complete) {
auto navigable = this->navigable(); auto navigable = this->navigable();
if (navigable && navigable->is_traversable()) { if (navigable && navigable->is_traversable()) {
if (!is_decoded_svg()) {
HTML::HTMLLinkElement::load_fallback_favicon_if_needed(*this).release_value_but_fixme_should_propagate_errors();
}
HTML::HTMLLinkElement::load_fallback_favicon_if_needed(*this).release_value_but_fixme_should_propagate_errors(); HTML::HTMLLinkElement::load_fallback_favicon_if_needed(*this).release_value_but_fixme_should_propagate_errors();
navigable->traversable_navigable()->page().client().page_did_finish_loading(url()); navigable->traversable_navigable()->page().client().page_did_finish_loading(url());
} else { } else {
@ -4803,6 +4807,11 @@ void Document::for_each_shadow_root(Function<void(DOM::ShadowRoot&)>&& callback)
callback(shadow_root); callback(shadow_root);
} }
bool Document::is_decoded_svg() const
{
return is<Web::SVG::SVGDecodedImageData::SVGPageClient>(page().client());
}
// https://drafts.csswg.org/css-position-4/#add-an-element-to-the-top-layer // https://drafts.csswg.org/css-position-4/#add-an-element-to-the-top-layer
void Document::add_an_element_to_the_top_layer(JS::NonnullGCPtr<Element> element) void Document::add_an_element_to_the_top_layer(JS::NonnullGCPtr<Element> element)
{ {

View file

@ -634,6 +634,9 @@ public:
size_t transition_generation() const { return m_transition_generation; } size_t transition_generation() const { return m_transition_generation; }
// Does document represent an embedded svg img
[[nodiscard]] bool is_decoded_svg() const;
protected: protected:
virtual void initialize(JS::Realm&) override; virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override; virtual void visit_edges(Cell::Visitor&) override;

View file

@ -25,39 +25,6 @@ namespace Web::SVG {
JS_DEFINE_ALLOCATOR(SVGDecodedImageData); JS_DEFINE_ALLOCATOR(SVGDecodedImageData);
class SVGDecodedImageData::SVGPageClient final : public PageClient {
JS_CELL(SVGDecodedImageData::SVGPageClient, PageClient);
public:
static JS::NonnullGCPtr<SVGPageClient> create(JS::VM& vm, Page& page)
{
return vm.heap().allocate_without_realm<SVGPageClient>(page);
}
virtual ~SVGPageClient() override = default;
Page& m_host_page;
Page* m_svg_page { nullptr };
virtual Page& page() override { return *m_svg_page; }
virtual Page const& page() const override { return *m_svg_page; }
virtual bool is_connection_open() const override { return false; }
virtual Gfx::Palette palette() const override { return m_host_page.client().palette(); }
virtual DevicePixelRect screen_rect() const override { return {}; }
virtual double device_pixels_per_css_pixel() const override { return 1.0; }
virtual CSS::PreferredColorScheme preferred_color_scheme() const override { return m_host_page.client().preferred_color_scheme(); }
virtual void request_file(FileRequest) override { }
virtual void paint(DevicePixelRect const&, Gfx::Bitmap&, Web::PaintOptions = {}) override { }
virtual void schedule_repaint() override { }
virtual bool is_ready_to_paint() const override { return true; }
private:
explicit SVGPageClient(Page& host_page)
: m_host_page(host_page)
{
}
};
ErrorOr<JS::NonnullGCPtr<SVGDecodedImageData>> SVGDecodedImageData::create(JS::Realm& realm, JS::NonnullGCPtr<Page> host_page, URL::URL const& url, ByteBuffer data) ErrorOr<JS::NonnullGCPtr<SVGDecodedImageData>> SVGDecodedImageData::create(JS::Realm& realm, JS::NonnullGCPtr<Page> host_page, URL::URL const& url, ByteBuffer data)
{ {
auto page_client = SVGPageClient::create(Bindings::main_thread_vm(), host_page); auto page_client = SVGPageClient::create(Bindings::main_thread_vm(), host_page);

View file

@ -8,6 +8,7 @@
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/DecodedImageData.h> #include <LibWeb/HTML/DecodedImageData.h>
#include <WebContent/PageClient.h>
namespace Web::SVG { namespace Web::SVG {
@ -16,6 +17,7 @@ class SVGDecodedImageData final : public HTML::DecodedImageData {
JS_DECLARE_ALLOCATOR(SVGDecodedImageData); JS_DECLARE_ALLOCATOR(SVGDecodedImageData);
public: public:
class SVGPageClient;
static ErrorOr<JS::NonnullGCPtr<SVGDecodedImageData>> create(JS::Realm&, JS::NonnullGCPtr<Page>, URL::URL const&, ByteBuffer encoded_svg); static ErrorOr<JS::NonnullGCPtr<SVGDecodedImageData>> create(JS::Realm&, JS::NonnullGCPtr<Page>, URL::URL const&, ByteBuffer encoded_svg);
virtual ~SVGDecodedImageData() override; virtual ~SVGDecodedImageData() override;
@ -36,7 +38,6 @@ public:
virtual void visit_edges(Cell::Visitor& visitor) override; virtual void visit_edges(Cell::Visitor& visitor) override;
private: private:
class SVGPageClient;
SVGDecodedImageData(JS::NonnullGCPtr<Page>, JS::NonnullGCPtr<SVGPageClient>, JS::NonnullGCPtr<DOM::Document>, JS::NonnullGCPtr<SVG::SVGSVGElement>); SVGDecodedImageData(JS::NonnullGCPtr<Page>, JS::NonnullGCPtr<SVGPageClient>, JS::NonnullGCPtr<DOM::Document>, JS::NonnullGCPtr<SVG::SVGSVGElement>);
RefPtr<Gfx::Bitmap> render(Gfx::IntSize) const; RefPtr<Gfx::Bitmap> render(Gfx::IntSize) const;
@ -50,4 +51,37 @@ private:
JS::NonnullGCPtr<SVG::SVGSVGElement> m_root_element; JS::NonnullGCPtr<SVG::SVGSVGElement> m_root_element;
}; };
class SVGDecodedImageData::SVGPageClient final : public PageClient {
JS_CELL(SVGDecodedImageData::SVGPageClient, PageClient);
public:
static JS::NonnullGCPtr<SVGPageClient> create(JS::VM& vm, Page& page)
{
return vm.heap().allocate_without_realm<SVGPageClient>(page);
}
virtual ~SVGPageClient() override = default;
Page& m_host_page;
Page* m_svg_page { nullptr };
virtual Page& page() override { return *m_svg_page; }
virtual Page const& page() const override { return *m_svg_page; }
virtual bool is_connection_open() const override { return false; }
virtual Gfx::Palette palette() const override { return m_host_page.client().palette(); }
virtual DevicePixelRect screen_rect() const override { return {}; }
virtual double device_pixels_per_css_pixel() const override { return 1.0; }
virtual CSS::PreferredColorScheme preferred_color_scheme() const override { return m_host_page.client().preferred_color_scheme(); }
virtual void request_file(FileRequest) override { }
virtual void paint(DevicePixelRect const&, Gfx::Bitmap&, Web::PaintOptions = {}) override { }
virtual void schedule_repaint() override { }
virtual bool is_ready_to_paint() const override { return true; }
private:
explicit SVGPageClient(Page& host_page)
: m_host_page(host_page)
{
}
};
} }