diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 83b710dd1b8..795c859ec46 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -119,6 +119,26 @@ FontLoader::~FontLoader() = default; void FontLoader::resource_did_load() { + resource_did_load_or_fail(); + if (m_on_load) + m_on_load(*this); +} + +void FontLoader::resource_did_fail() +{ + resource_did_load_or_fail(); + if (m_on_fail) { + m_on_fail(); + } +} + +void FontLoader::resource_did_load_or_fail() +{ + // NOTE: Even if the resource "failed" to load, we still want to try to parse it as a font. + // This is necessary for https://wpt.live/ to work correctly, as it just drops the connection + // after sending a resource, which looks like an error, but is actually recoverable. + // FIXME: It would be nice to solve this in the network layer instead. + // It would also be nice to move font loading to using fetch primitives. auto result = try_load_font(); if (result.is_error()) { dbgln("Failed to parse font: {}", result.error()); @@ -127,15 +147,6 @@ void FontLoader::resource_did_load() } m_vector_font = result.release_value(); m_style_computer.did_load_font(m_family_name); - if (m_on_load) - m_on_load(*this); -} - -void FontLoader::resource_did_fail() -{ - if (m_on_fail) { - m_on_fail(); - } } RefPtr FontLoader::font_with_point_size(float point_size) diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.h b/Userland/Libraries/LibWeb/CSS/StyleComputer.h index 93cc9373ccc..0ae43b8139d 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.h +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.h @@ -251,13 +251,16 @@ public: Vector const& unicode_ranges() const { return m_unicode_ranges; } RefPtr vector_font() const { return m_vector_font; } - virtual void resource_did_load() override; - virtual void resource_did_fail() override; - RefPtr font_with_point_size(float point_size); void start_loading_next_url(); private: + // ^ResourceClient + virtual void resource_did_load() override; + virtual void resource_did_fail() override; + + void resource_did_load_or_fail(); + ErrorOr> try_load_font(); StyleComputer& m_style_computer; diff --git a/Userland/Libraries/LibWeb/Loader/Resource.cpp b/Userland/Libraries/LibWeb/Loader/Resource.cpp index 29a3c27afc7..9fc871adad7 100644 --- a/Userland/Libraries/LibWeb/Loader/Resource.cpp +++ b/Userland/Libraries/LibWeb/Loader/Resource.cpp @@ -120,9 +120,11 @@ void Resource::did_load(Badge, ReadonlyBytes data, HTTP::HeaderM }); } -void Resource::did_fail(Badge, ByteString const& error, Optional status_code) +void Resource::did_fail(Badge, ByteString const& error, ReadonlyBytes data, HTTP::HeaderMap const& headers, Optional status_code) { m_error = error; + m_encoded_data = ByteBuffer::copy(data).release_value_but_fixme_should_propagate_errors(); + m_response_headers = headers; m_status_code = move(status_code); m_state = State::Failed; diff --git a/Userland/Libraries/LibWeb/Loader/Resource.h b/Userland/Libraries/LibWeb/Loader/Resource.h index 3201271cc92..062479c4c36 100644 --- a/Userland/Libraries/LibWeb/Loader/Resource.h +++ b/Userland/Libraries/LibWeb/Loader/Resource.h @@ -68,7 +68,7 @@ public: void for_each_client(Function); void did_load(Badge, ReadonlyBytes data, HTTP::HeaderMap const&, Optional status_code); - void did_fail(Badge, ByteString const& error, Optional status_code); + void did_fail(Badge, ByteString const& error, ReadonlyBytes data, HTTP::HeaderMap const&, Optional status_code); protected: explicit Resource(Type, LoadRequest const&); diff --git a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp index 4c39d4076a8..1a627e72667 100644 --- a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp @@ -121,8 +121,8 @@ RefPtr ResourceLoader::load_resource(Resource::Type type, LoadRequest& [=](auto data, auto& headers, auto status_code) { const_cast(*resource).did_load({}, data, headers, status_code); }, - [=](auto& error, auto status_code, auto, auto) { - const_cast(*resource).did_fail({}, error, status_code); + [=](auto& error, auto status_code, auto data, auto& headers) { + const_cast(*resource).did_fail({}, error, data, headers, status_code); }); return resource;