/src/serenity/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2022, Linus Groh <linusg@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibJS/Heap/Heap.h> |
8 | | #include <LibJS/Runtime/VM.h> |
9 | | #include <LibWeb/Fetch/Infrastructure/FetchParams.h> |
10 | | #include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h> |
11 | | |
12 | | namespace Web::Fetch::Infrastructure { |
13 | | |
14 | | JS_DEFINE_ALLOCATOR(FetchParams); |
15 | | |
16 | | FetchParams::FetchParams(JS::NonnullGCPtr<Request> request, JS::NonnullGCPtr<FetchAlgorithms> algorithms, JS::NonnullGCPtr<FetchController> controller, JS::NonnullGCPtr<FetchTimingInfo> timing_info) |
17 | 0 | : m_request(request) |
18 | 0 | , m_algorithms(algorithms) |
19 | 0 | , m_controller(controller) |
20 | 0 | , m_timing_info(timing_info) |
21 | 0 | { |
22 | 0 | m_controller->set_fetch_params({}, *this); |
23 | 0 | } |
24 | | |
25 | | JS::NonnullGCPtr<FetchParams> FetchParams::create(JS::VM& vm, JS::NonnullGCPtr<Request> request, JS::NonnullGCPtr<FetchTimingInfo> timing_info) |
26 | 0 | { |
27 | 0 | auto algorithms = Infrastructure::FetchAlgorithms::create(vm, {}); |
28 | 0 | auto controller = Infrastructure::FetchController::create(vm); |
29 | 0 | return vm.heap().allocate_without_realm<FetchParams>(request, algorithms, controller, timing_info); |
30 | 0 | } |
31 | | |
32 | | void FetchParams::visit_edges(JS::Cell::Visitor& visitor) |
33 | 0 | { |
34 | 0 | Base::visit_edges(visitor); |
35 | 0 | visitor.visit(m_request); |
36 | 0 | visitor.visit(m_algorithms); |
37 | 0 | visitor.visit(m_controller); |
38 | 0 | visitor.visit(m_timing_info); |
39 | 0 | if (m_task_destination.has<JS::NonnullGCPtr<JS::Object>>()) |
40 | 0 | visitor.visit(m_task_destination.get<JS::NonnullGCPtr<JS::Object>>()); |
41 | 0 | if (m_preloaded_response_candidate.has<JS::NonnullGCPtr<Response>>()) |
42 | 0 | visitor.visit(m_preloaded_response_candidate.get<JS::NonnullGCPtr<Response>>()); |
43 | 0 | } |
44 | | |
45 | | // https://fetch.spec.whatwg.org/#fetch-params-aborted |
46 | | bool FetchParams::is_aborted() const |
47 | 0 | { |
48 | | // A fetch params fetchParams is aborted if its controller’s state is "aborted". |
49 | 0 | return m_controller->state() == FetchController::State::Aborted; |
50 | 0 | } |
51 | | |
52 | | // https://fetch.spec.whatwg.org/#fetch-params-canceled |
53 | | bool FetchParams::is_canceled() const |
54 | 0 | { |
55 | | // A fetch params fetchParams is canceled if its controller’s state is "aborted" or "terminated". |
56 | 0 | return m_controller->state() == FetchController::State::Aborted || m_controller->state() == FetchController::State::Terminated; |
57 | 0 | } |
58 | | |
59 | | } |