Coverage Report

Created: 2026-02-16 07:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <AK/Forward.h>
10
#include <LibJS/Forward.h>
11
#include <LibJS/Heap/Cell.h>
12
#include <LibJS/Heap/GCPtr.h>
13
#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>
14
#include <LibWeb/Fetch/Infrastructure/FetchController.h>
15
#include <LibWeb/Fetch/Infrastructure/FetchTimingInfo.h>
16
#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
17
#include <LibWeb/Fetch/Infrastructure/Task.h>
18
19
namespace Web::Fetch::Infrastructure {
20
21
// https://fetch.spec.whatwg.org/#fetch-params
22
class FetchParams : public JS::Cell {
23
    JS_CELL(FetchParams, JS::Cell);
24
    JS_DECLARE_ALLOCATOR(FetchParams);
25
26
public:
27
    struct PreloadedResponseCandidatePendingTag { };
28
    using PreloadedResponseCandidate = Variant<Empty, PreloadedResponseCandidatePendingTag, JS::NonnullGCPtr<Response>>;
29
30
    [[nodiscard]] static JS::NonnullGCPtr<FetchParams> create(JS::VM&, JS::NonnullGCPtr<Request>, JS::NonnullGCPtr<FetchTimingInfo>);
31
32
0
    [[nodiscard]] JS::NonnullGCPtr<Request> request() const { return m_request; }
33
0
    [[nodiscard]] JS::NonnullGCPtr<FetchController> controller() const { return m_controller; }
34
0
    [[nodiscard]] JS::NonnullGCPtr<FetchTimingInfo> timing_info() const { return m_timing_info; }
35
36
0
    [[nodiscard]] JS::NonnullGCPtr<FetchAlgorithms const> algorithms() const { return m_algorithms; }
37
0
    void set_algorithms(JS::NonnullGCPtr<FetchAlgorithms const> algorithms) { m_algorithms = algorithms; }
38
39
0
    [[nodiscard]] TaskDestination& task_destination() { return m_task_destination; }
40
0
    [[nodiscard]] TaskDestination const& task_destination() const { return m_task_destination; }
41
0
    void set_task_destination(TaskDestination task_destination) { m_task_destination = move(task_destination); }
42
43
0
    [[nodiscard]] HTML::CanUseCrossOriginIsolatedAPIs cross_origin_isolated_capability() const { return m_cross_origin_isolated_capability; }
44
0
    void set_cross_origin_isolated_capability(HTML::CanUseCrossOriginIsolatedAPIs cross_origin_isolated_capability) { m_cross_origin_isolated_capability = cross_origin_isolated_capability; }
45
46
0
    [[nodiscard]] PreloadedResponseCandidate& preloaded_response_candidate() { return m_preloaded_response_candidate; }
47
0
    [[nodiscard]] PreloadedResponseCandidate const& preloaded_response_candidate() const { return m_preloaded_response_candidate; }
48
0
    void set_preloaded_response_candidate(PreloadedResponseCandidate preloaded_response_candidate) { m_preloaded_response_candidate = move(preloaded_response_candidate); }
49
50
    [[nodiscard]] bool is_aborted() const;
51
    [[nodiscard]] bool is_canceled() const;
52
53
private:
54
    FetchParams(JS::NonnullGCPtr<Request>, JS::NonnullGCPtr<FetchAlgorithms>, JS::NonnullGCPtr<FetchController>, JS::NonnullGCPtr<FetchTimingInfo>);
55
56
    virtual void visit_edges(JS::Cell::Visitor&) override;
57
58
    // https://fetch.spec.whatwg.org/#fetch-params-request
59
    // request
60
    //     A request.
61
    JS::NonnullGCPtr<Request> m_request;
62
63
    // https://fetch.spec.whatwg.org/#fetch-params-process-request-body
64
    // process request body chunk length (default null)
65
    // https://fetch.spec.whatwg.org/#fetch-params-process-request-end-of-body
66
    // process request end-of-body (default null)
67
    // https://fetch.spec.whatwg.org/#fetch-params-process-early-hints-response
68
    // process early hints response (default null)
69
    // https://fetch.spec.whatwg.org/#fetch-params-process-response
70
    // process response (default null)
71
    // https://fetch.spec.whatwg.org/#fetch-params-process-response-end-of-body
72
    // process response end-of-body (default null)
73
    // https://fetch.spec.whatwg.org/#fetch-params-process-response-consume-body
74
    // process response consume body (default null)
75
    //     Null or an algorithm.
76
    JS::NonnullGCPtr<FetchAlgorithms const> m_algorithms;
77
78
    // https://fetch.spec.whatwg.org/#fetch-params-task-destination
79
    // task destination (default null)
80
    //     Null, a global object, or a parallel queue.
81
    TaskDestination m_task_destination;
82
83
    // https://fetch.spec.whatwg.org/#fetch-params-cross-origin-isolated-capability
84
    // cross-origin isolated capability (default false)
85
    //     A boolean.
86
    HTML::CanUseCrossOriginIsolatedAPIs m_cross_origin_isolated_capability { HTML::CanUseCrossOriginIsolatedAPIs::No };
87
88
    // https://fetch.spec.whatwg.org/#fetch-params-controller
89
    // controller (default a new fetch controller)
90
    //     A fetch controller.
91
    JS::NonnullGCPtr<FetchController> m_controller;
92
93
    // https://fetch.spec.whatwg.org/#fetch-params-timing-info
94
    // timing info
95
    //     A fetch timing info.
96
    JS::NonnullGCPtr<FetchTimingInfo> m_timing_info;
97
98
    // https://fetch.spec.whatwg.org/#fetch-params-preloaded-response-candidate
99
    // preloaded response candidate (default null)
100
    //     Null, "pending", or a response.
101
    PreloadedResponseCandidate m_preloaded_response_candidate;
102
};
103
104
}