2023-06-14 12:45:56 +02:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2023, Andreas Kling <andreas@ladybird.org>
|
2023-06-14 12:45:56 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Error.h>
|
|
|
|
#include <AK/OwnPtr.h>
|
2024-11-15 04:01:23 +13:00
|
|
|
#include <LibGC/Function.h>
|
|
|
|
#include <LibGC/Root.h>
|
2023-06-14 12:45:56 +02:00
|
|
|
#include <LibGfx/Size.h>
|
2024-03-18 16:22:27 +13:00
|
|
|
#include <LibURL/URL.h>
|
2023-06-14 12:45:56 +02:00
|
|
|
#include <LibWeb/Forward.h>
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
2024-08-03 15:27:08 +12:00
|
|
|
class SharedResourceRequest final : public JS::Cell {
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_CELL(SharedResourceRequest, JS::Cell);
|
|
|
|
GC_DECLARE_ALLOCATOR(SharedResourceRequest);
|
2023-08-18 14:11:55 +02:00
|
|
|
|
2023-06-14 12:45:56 +02:00
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
[[nodiscard]] static GC::Ref<SharedResourceRequest> get_or_create(JS::Realm&, GC::Ref<Page>, URL::URL const&);
|
2023-08-18 14:11:55 +02:00
|
|
|
|
2024-08-03 15:27:08 +12:00
|
|
|
virtual ~SharedResourceRequest() override;
|
2023-06-14 12:45:56 +02:00
|
|
|
|
2024-03-18 16:22:27 +13:00
|
|
|
URL::URL const& url() const { return m_url; }
|
2023-06-14 12:45:56 +02:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
[[nodiscard]] GC::Ptr<DecodedImageData> image_data() const;
|
2023-06-14 12:45:56 +02:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
[[nodiscard]] GC::Ptr<Fetch::Infrastructure::FetchController> fetch_controller();
|
|
|
|
void set_fetch_controller(GC::Ptr<Fetch::Infrastructure::FetchController>);
|
2023-06-14 12:45:56 +02:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
void fetch_resource(JS::Realm&, GC::Ref<Fetch::Infrastructure::Request>);
|
2023-06-14 12:45:56 +02:00
|
|
|
|
2023-09-25 14:27:11 +02:00
|
|
|
void add_callbacks(Function<void()> on_finish, Function<void()> on_fail);
|
2023-06-14 12:45:56 +02:00
|
|
|
|
|
|
|
bool is_fetching() const;
|
|
|
|
bool needs_fetching() const;
|
|
|
|
|
|
|
|
private:
|
2024-11-15 04:01:23 +13:00
|
|
|
explicit SharedResourceRequest(GC::Ref<Page>, URL::URL, GC::Ref<DOM::Document>);
|
2023-06-14 12:45:56 +02:00
|
|
|
|
2023-12-23 20:50:23 +01:00
|
|
|
virtual void finalize() override;
|
|
|
|
virtual void visit_edges(JS::Cell::Visitor&) override;
|
|
|
|
|
2024-03-18 16:22:27 +13:00
|
|
|
void handle_successful_fetch(URL::URL const&, StringView mime_type, ByteBuffer data);
|
2023-06-14 12:45:56 +02:00
|
|
|
void handle_failed_fetch();
|
2024-08-03 14:25:42 +12:00
|
|
|
void handle_successful_resource_load();
|
2023-06-14 12:45:56 +02:00
|
|
|
|
|
|
|
enum class State {
|
|
|
|
New,
|
|
|
|
Fetching,
|
|
|
|
Finished,
|
|
|
|
Failed,
|
|
|
|
};
|
|
|
|
|
|
|
|
State m_state { State::New };
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<Page> m_page;
|
2023-06-14 12:45:56 +02:00
|
|
|
|
|
|
|
struct Callbacks {
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<GC::Function<void()>> on_finish;
|
|
|
|
GC::Ptr<GC::Function<void()>> on_fail;
|
2023-06-14 12:45:56 +02:00
|
|
|
};
|
|
|
|
Vector<Callbacks> m_callbacks;
|
|
|
|
|
2024-03-18 16:22:27 +13:00
|
|
|
URL::URL m_url;
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<DecodedImageData> m_image_data;
|
|
|
|
GC::Ptr<Fetch::Infrastructure::FetchController> m_fetch_controller;
|
2023-10-17 16:52:16 +02:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<DOM::Document> m_document;
|
2023-06-14 12:45:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|