diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp index db80400e20..94bb778ae6 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp @@ -6,7 +6,9 @@ #include #include +#include #include +#include #include 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); + } +} + } diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h index fafd294563..c518533636 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h @@ -6,11 +6,13 @@ #pragma once +#include #include #include #include #include #include +#include namespace Web::Fetch::Infrastructure { @@ -39,6 +41,10 @@ public: void abort(JS::Realm&, Optional); void terminate(); + void set_fetch_params(Badge, JS::NonnullGCPtr fetch_params) { m_fetch_params = fetch_params; } + + void stop_fetch(); + private: FetchController(); @@ -67,6 +73,8 @@ private: // next manual redirect steps (default null) // Null or an algorithm accepting nothing. Optional> m_next_manual_redirect_steps; + + JS::GCPtr m_fetch_params; }; } diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp index cf395ff7ad..cd0c64f48a 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp @@ -17,6 +17,7 @@ FetchParams::FetchParams(JS::NonnullGCPtr request, JS::NonnullGCPtrset_fetch_params({}, *this); } JS::NonnullGCPtr FetchParams::create(JS::VM& vm, JS::NonnullGCPtr request, JS::NonnullGCPtr timing_info)