mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb: Do not return an exception from fetching CSS resources
The exception returned here is never used or logged. Let's just return a null request, to make it clearer that these are not exceptions shown to the user (thus not observable).
This commit is contained in:
parent
2811c75031
commit
d8ec204be8
Notes:
github-actions[bot]
2025-11-12 17:32:01 +00:00
Author: https://github.com/trflynn89
Commit: d8ec204be8
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6801
Reviewed-by: https://github.com/gmta ✅
3 changed files with 13 additions and 14 deletions
|
|
@ -15,7 +15,7 @@
|
|||
namespace Web::CSS {
|
||||
|
||||
// https://drafts.csswg.org/css-values-4/#fetch-a-style-resource
|
||||
static WebIDL::ExceptionOr<GC::Ref<Fetch::Infrastructure::Request>> fetch_a_style_resource_impl(StyleResourceURL const& url_value, StyleSheetOrDocument sheet_or_document, Fetch::Infrastructure::Request::Destination destination, CorsMode cors_mode)
|
||||
static GC::Ptr<Fetch::Infrastructure::Request> fetch_a_style_resource_impl(StyleResourceURL const& url_value, StyleSheetOrDocument sheet_or_document, Fetch::Infrastructure::Request::Destination destination, CorsMode cors_mode)
|
||||
{
|
||||
// AD-HOC: Not every caller has a CSSStyleSheet, so allow passing a Document in instead for URL completion.
|
||||
// Spec issue: https://github.com/w3c/csswg-drafts/issues/12065
|
||||
|
|
@ -42,7 +42,7 @@ static WebIDL::ExceptionOr<GC::Ref<Fetch::Infrastructure::Request>> fetch_a_styl
|
|||
|
||||
auto parsed_url = DOMURL::parse(url_string, base);
|
||||
if (!parsed_url.has_value())
|
||||
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::URIError, "Failed to parse URL"sv };
|
||||
return {};
|
||||
|
||||
// 4. Let req be a new request whose url is parsedUrl, whose destination is destination, mode is corsMode,
|
||||
// origin is environmentSettings’s origin, credentials mode is "same-origin", use-url-credentials flag is set,
|
||||
|
|
@ -91,9 +91,12 @@ static WebIDL::ExceptionOr<GC::Ref<Fetch::Infrastructure::Request>> fetch_a_styl
|
|||
}
|
||||
|
||||
// https://drafts.csswg.org/css-values-4/#fetch-a-style-resource
|
||||
WebIDL::ExceptionOr<GC::Ref<Fetch::Infrastructure::FetchController>> fetch_a_style_resource(StyleResourceURL const& url_value, StyleSheetOrDocument sheet_or_document, Fetch::Infrastructure::Request::Destination destination, CorsMode cors_mode, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction process_response)
|
||||
GC::Ptr<Fetch::Infrastructure::FetchController> fetch_a_style_resource(StyleResourceURL const& url_value, StyleSheetOrDocument sheet_or_document, Fetch::Infrastructure::Request::Destination destination, CorsMode cors_mode, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction process_response)
|
||||
{
|
||||
auto request = TRY(fetch_a_style_resource_impl(url_value, sheet_or_document, destination, cors_mode));
|
||||
auto request = fetch_a_style_resource_impl(url_value, sheet_or_document, destination, cors_mode);
|
||||
if (!request)
|
||||
return {};
|
||||
|
||||
auto& environment_settings = HTML::relevant_settings_object(sheet_or_document.visit([](auto& it) -> JS::Object& { return it; }));
|
||||
auto& vm = environment_settings.vm();
|
||||
|
||||
|
|
@ -114,10 +117,9 @@ GC::Ptr<HTML::SharedResourceRequest> fetch_an_external_image_for_a_stylesheet(St
|
|||
// NB: We can't directly call fetch_a_style_resource() because we want to make use of SharedResourceRequest to
|
||||
// deduplicate image requests.
|
||||
|
||||
auto maybe_request = fetch_a_style_resource_impl(url_value, sheet_or_document, Fetch::Infrastructure::Request::Destination::Image, CorsMode::NoCors);
|
||||
if (maybe_request.is_error())
|
||||
return nullptr;
|
||||
auto& request = maybe_request.value();
|
||||
auto request = fetch_a_style_resource_impl(url_value, sheet_or_document, Fetch::Infrastructure::Request::Destination::Image, CorsMode::NoCors);
|
||||
if (!request)
|
||||
return {};
|
||||
|
||||
auto document = sheet_or_document.visit(
|
||||
[&](GC::Ref<CSSStyleSheet> const& sheet) -> GC::Ref<DOM::Document> { return *sheet->owning_document(); },
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ using StyleResourceURL = Variant<::URL::URL, CSS::URL>;
|
|||
using StyleSheetOrDocument = Variant<GC::Ref<CSSStyleSheet>, GC::Ref<DOM::Document>>;
|
||||
|
||||
// https://drafts.csswg.org/css-values-4/#fetch-a-style-resource
|
||||
WebIDL::ExceptionOr<GC::Ref<Fetch::Infrastructure::FetchController>> fetch_a_style_resource(StyleResourceURL const& url, StyleSheetOrDocument, Fetch::Infrastructure::Request::Destination, CorsMode, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction process_response);
|
||||
GC::Ptr<Fetch::Infrastructure::FetchController> fetch_a_style_resource(StyleResourceURL const& url, StyleSheetOrDocument, Fetch::Infrastructure::Request::Destination, CorsMode, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction process_response);
|
||||
|
||||
// https://drafts.csswg.org/css-images-4/#fetch-an-external-image-for-a-stylesheet
|
||||
GC::Ptr<HTML::SharedResourceRequest> fetch_an_external_image_for_a_stylesheet(StyleResourceURL const&, StyleSheetOrDocument);
|
||||
|
|
|
|||
|
|
@ -265,7 +265,7 @@ void FontLoader::start_loading_next_url()
|
|||
// CSS style sheet, destination "font", CORS mode "cors", and processResponse being the following steps given
|
||||
// response res and null, failure or a byte stream stream:
|
||||
auto style_sheet_or_document = m_parent_style_sheet ? StyleSheetOrDocument { *m_parent_style_sheet } : StyleSheetOrDocument { m_style_computer->document() };
|
||||
auto maybe_fetch_controller = fetch_a_style_resource(m_urls.take_first(), style_sheet_or_document, Fetch::Infrastructure::Request::Destination::Font, CorsMode::Cors,
|
||||
m_fetch_controller = fetch_a_style_resource(m_urls.take_first(), style_sheet_or_document, Fetch::Infrastructure::Request::Destination::Font, CorsMode::Cors,
|
||||
[loader = this](auto response, auto stream) {
|
||||
// 1. If stream is null, return.
|
||||
// 2. Load a font from stream according to its type.
|
||||
|
|
@ -290,11 +290,8 @@ void FontLoader::start_loading_next_url()
|
|||
}
|
||||
});
|
||||
|
||||
if (maybe_fetch_controller.is_error()) {
|
||||
if (!m_fetch_controller)
|
||||
font_did_load_or_fail(nullptr);
|
||||
} else {
|
||||
m_fetch_controller = maybe_fetch_controller.release_value();
|
||||
}
|
||||
}
|
||||
|
||||
void FontLoader::font_did_load_or_fail(RefPtr<Gfx::Typeface const> typeface)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue