FetchParams.h 4.8 KB

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