2024-05-26 08:03:29 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
2025-04-17 07:58:24 -04:00
|
|
|
* Copyright (c) 2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
2024-05-26 08:03:29 -04:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/ByteBuffer.h>
|
2024-11-15 04:01:23 +13:00
|
|
|
#include <LibGC/CellAllocator.h>
|
2024-05-26 08:03:29 -04:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
|
|
|
|
#include <LibWeb/Forward.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::Fetch::Fetching {
|
|
|
|
|
|
|
|
|
|
class FetchedDataReceiver final : public JS::Cell {
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_CELL(FetchedDataReceiver, JS::Cell);
|
|
|
|
|
GC_DECLARE_ALLOCATOR(FetchedDataReceiver);
|
2024-05-26 08:03:29 -04:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
virtual ~FetchedDataReceiver() override;
|
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
void set_pending_promise(GC::Ref<WebIDL::Promise>);
|
2025-04-17 07:58:24 -04:00
|
|
|
|
|
|
|
|
enum class NetworkState {
|
|
|
|
|
Ongoing,
|
|
|
|
|
Complete,
|
|
|
|
|
Error,
|
|
|
|
|
};
|
|
|
|
|
void handle_network_bytes(ReadonlyBytes, NetworkState);
|
2024-05-26 08:03:29 -04:00
|
|
|
|
|
|
|
|
private:
|
2024-11-15 04:01:23 +13:00
|
|
|
FetchedDataReceiver(GC::Ref<Infrastructure::FetchParams const>, GC::Ref<Streams::ReadableStream>);
|
2024-05-26 08:03:29 -04:00
|
|
|
|
|
|
|
|
virtual void visit_edges(Visitor& visitor) override;
|
|
|
|
|
|
2025-04-17 07:58:24 -04:00
|
|
|
void pull_bytes_into_stream(ByteBuffer&&);
|
|
|
|
|
void close_stream();
|
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<Infrastructure::FetchParams const> m_fetch_params;
|
|
|
|
|
GC::Ref<Streams::ReadableStream> m_stream;
|
|
|
|
|
GC::Ptr<WebIDL::Promise> m_pending_promise;
|
2025-04-17 07:58:24 -04:00
|
|
|
|
2024-05-26 08:03:29 -04:00
|
|
|
ByteBuffer m_buffer;
|
2025-04-17 07:58:24 -04:00
|
|
|
enum class LifecycleState {
|
|
|
|
|
Receiving,
|
|
|
|
|
CompletePending,
|
|
|
|
|
ReadyToClose,
|
|
|
|
|
Closed,
|
|
|
|
|
};
|
|
|
|
|
LifecycleState m_lifecycle_state { LifecycleState::Receiving };
|
|
|
|
|
bool m_has_unfulfilled_promise { false };
|
2024-05-26 08:03:29 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|