/* * Copyright (c) 2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include namespace Web::HTML { // https://html.spec.whatwg.org/multipage/images.html#list-of-available-images class ListOfAvailableImages : public JS::Cell { GC_CELL(ListOfAvailableImages, JS::Cell); GC_DECLARE_ALLOCATOR(ListOfAvailableImages); public: struct Key { URL::URL url; HTML::CORSSettingAttribute mode; Optional origin; [[nodiscard]] bool operator==(Key const& other) const; [[nodiscard]] u32 hash() const; private: mutable Optional cached_hash; }; struct Entry { Entry(GC::Ref image_data, bool ignore_higher_layer_caching) : image_data(move(image_data)) , ignore_higher_layer_caching(ignore_higher_layer_caching) { } GC::Ref image_data; bool ignore_higher_layer_caching { false }; }; ListOfAvailableImages(); ~ListOfAvailableImages(); void add(Key const&, GC::Ref, bool ignore_higher_layer_caching); void remove(Key const&); [[nodiscard]] Entry* get(Key const&); void visit_edges(JS::Cell::Visitor& visitor) override; private: HashMap> m_images; }; } namespace AK { template<> struct Traits : public DefaultTraits { static unsigned hash(Web::HTML::ListOfAvailableImages::Key const& key) { return key.hash(); } static bool equals(Web::HTML::ListOfAvailableImages::Key const& a, Web::HTML::ListOfAvailableImages::Key const& b) { return a == b; } }; }