1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 11:45:06 +00:00

LibWeb: Invent a method to stop an in-progress fetch without errors

The HTMLMediaElement will need to stop fetching processes when its load
algorithm is invoked while a fetch is ongoing. We don't have a way to
really stop the process, due to the way it runs on nested deferred task
invocations. So for now, this swaps the fetch callbacks (e.g. to process
a fetch response) with empty callbacks.
This commit is contained in:
Timothy Flynn 2023-04-19 09:15:16 -04:00 committed by Andreas Kling
parent 1fb0c7826b
commit 8d4d01d99a
3 changed files with 26 additions and 0 deletions

View file

@ -6,7 +6,9 @@
#include <LibJS/Heap/Heap.h>
#include <LibJS/Runtime/VM.h>
#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>
#include <LibWeb/Fetch/Infrastructure/FetchController.h>
#include <LibWeb/Fetch/Infrastructure/FetchParams.h>
#include <LibWeb/WebIDL/DOMException.h>
namespace Web::Fetch::Infrastructure {
@ -22,6 +24,7 @@ void FetchController::visit_edges(JS::Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_full_timing_info);
visitor.visit(m_fetch_params);
}
// https://fetch.spec.whatwg.org/#finalize-and-report-timing
@ -81,4 +84,18 @@ void FetchController::terminate()
m_state = State::Terminated;
}
void FetchController::stop_fetch()
{
auto& vm = this->vm();
// AD-HOC: Some HTML elements need to stop an ongoing fetching process without causing any network error to be raised
// (which abort() and terminate() will both do). This is tricky because the fetch process runs across several
// nested Platform::EventLoopPlugin::deferred_invoke() invocations. For now, we "stop" the fetch process by
// ignoring any callbacks.
if (m_fetch_params) {
auto fetch_algorithms = FetchAlgorithms::create(vm, {});
m_fetch_params->set_algorithms(fetch_algorithms);
}
}
}