/* * Copyright (c) 2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include namespace Web::HTML { class SharedImageRequest final : public JS::Cell { JS_CELL(ImageRequest, JS::Cell); JS_DECLARE_ALLOCATOR(SharedImageRequest); public: [[nodiscard]] static JS::NonnullGCPtr get_or_create(JS::Realm&, JS::NonnullGCPtr, URL::URL const&); virtual ~SharedImageRequest() override; URL::URL const& url() const { return m_url; } [[nodiscard]] JS::GCPtr image_data() const; [[nodiscard]] JS::GCPtr fetch_controller(); void set_fetch_controller(JS::GCPtr); void fetch_image(JS::Realm&, JS::NonnullGCPtr); void add_callbacks(Function on_finish, Function on_fail); bool is_fetching() const; bool needs_fetching() const; private: explicit SharedImageRequest(JS::NonnullGCPtr, URL::URL, JS::NonnullGCPtr); virtual void finalize() override; virtual void visit_edges(JS::Cell::Visitor&) override; void handle_successful_fetch(URL::URL const&, StringView mime_type, ByteBuffer data); void handle_failed_fetch(); enum class State { New, Fetching, Finished, Failed, }; State m_state { State::New }; JS::NonnullGCPtr m_page; struct Callbacks { JS::GCPtr> on_finish; JS::GCPtr> on_fail; }; Vector m_callbacks; URL::URL m_url; JS::GCPtr m_image_data; JS::GCPtr m_fetch_controller; JS::GCPtr m_document; }; }