/* * 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: struct Key { AK::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 final : public RefCounted { static ErrorOr> create(NonnullRefPtr, bool ignore_higher_layer_caching); ~Entry(); bool ignore_higher_layer_caching { false }; NonnullRefPtr image_data; private: Entry(NonnullRefPtr, bool ignore_higher_layer_caching); }; ListOfAvailableImages(); ~ListOfAvailableImages(); ErrorOr add(Key const&, NonnullRefPtr, bool ignore_higher_layer_caching); void remove(Key const&); [[nodiscard]] RefPtr get(Key const&) const; private: HashMap> m_images; }; } namespace AK { template<> struct Traits : public GenericTraits { 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; } }; }