mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 06:18:59 +00:00
LibWeb: Fire error event if HTMLTrackElement src is empty on load
Previously, we would hang while waiting for the track to load.
This commit is contained in:
parent
4d1329e0ea
commit
6aeb3e8839
Notes:
github-actions[bot]
2025-03-01 13:26:09 +00:00
Author: https://github.com/tcl3
Commit: 6aeb3e8839
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3742
Reviewed-by: https://github.com/trflynn89 ✅
3 changed files with 39 additions and 5 deletions
|
@ -180,6 +180,13 @@ void HTMLTrackElement::start_the_track_processing_model_parallel_steps(JS::Realm
|
|||
|
||||
// 9. End the synchronous section, continuing the remaining steps in parallel.
|
||||
|
||||
auto fire_error_event = [&]() {
|
||||
queue_an_element_task(Task::Source::DOMManipulation, [this, &realm]() {
|
||||
m_track->set_readiness_state(TextTrack::ReadinessState::FailedToLoad);
|
||||
dispatch_event(DOM::Event::create(realm, HTML::EventNames::error));
|
||||
});
|
||||
};
|
||||
|
||||
// 10. If URL is not the empty string, then:
|
||||
if (!url.is_empty()) {
|
||||
// 1. Let request be the result of creating a potential-CORS request given URL, "track", and corsAttributeState,
|
||||
|
@ -193,17 +200,14 @@ void HTMLTrackElement::start_the_track_processing_model_parallel_steps(JS::Realm
|
|||
request->set_initiator_type(Fetch::Infrastructure::Request::InitiatorType::Track);
|
||||
|
||||
Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};
|
||||
fetch_algorithms_input.process_response_consume_body = [this, &realm](auto response, auto body_bytes) {
|
||||
fetch_algorithms_input.process_response_consume_body = [this, &realm, &fire_error_event](auto response, auto body_bytes) {
|
||||
m_loading = false;
|
||||
|
||||
// If fetching fails for any reason (network error, the server returns an error code, CORS fails, etc.),
|
||||
// or if URL is the empty string, then queue an element task on the DOM manipulation task source given the media element
|
||||
// to first change the text track readiness state to failed to load and then fire an event named error at the track element.
|
||||
if (!response->url().has_value() || body_bytes.template has<Empty>() || body_bytes.template has<Fetch::Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag>() || !Fetch::Infrastructure::is_ok_status(response->status()) || response->is_network_error()) {
|
||||
queue_an_element_task(Task::Source::DOMManipulation, [this, &realm]() {
|
||||
m_track->set_readiness_state(TextTrack::ReadinessState::FailedToLoad);
|
||||
dispatch_event(DOM::Event::create(realm, HTML::EventNames::error));
|
||||
});
|
||||
fire_error_event();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -232,6 +236,9 @@ void HTMLTrackElement::start_the_track_processing_model_parallel_steps(JS::Realm
|
|||
m_fetch_algorithms = Fetch::Infrastructure::FetchAlgorithms::create(vm(), move(fetch_algorithms_input));
|
||||
m_fetch_controller = MUST(Fetch::Fetching::fetch(realm, request, *m_fetch_algorithms));
|
||||
return;
|
||||
} else {
|
||||
fire_error_event();
|
||||
return;
|
||||
}
|
||||
|
||||
// 11. Wait until the text track readiness state is no longer set to loading.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue