mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-05 15:49:11 +00:00
LibWeb: Make CSS font loader tolerate WPT web server shenanigans
The web server for WPT has a tendency to just disconnect after sending us a resource. This makes curl think an error occurred, but it's actually still recoverable and we have the data. So instead of just bailing, do what we already do for other kinds of resources and try to parse the data we got. If it works out, great! It would be nice to solve this in the networking layer instead, but I'll leave that as an exercise for our future selves.
This commit is contained in:
parent
2303142386
commit
32299e74cb
Notes:
github-actions[bot]
2024-09-21 17:21:21 +00:00
Author: https://github.com/awesomekling
Commit: 32299e74cb
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1473
5 changed files with 32 additions and 16 deletions
|
@ -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<Gfx::Font> FontLoader::font_with_point_size(float point_size)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue