
This URL library ends up being a relatively fundamental base library of the system, as LibCore depends on LibURL. This change has two main benefits: * Moving AK back more towards being an agnostic library that can be used between the kernel and userspace. URL has never really fit that description - and is not used in the kernel. * URL _should_ depend on LibUnicode, as it needs punnycode support. However, it's not really possible to do this inside of AK as it can't depend on any external library. This change brings us a little closer to being able to do that, but unfortunately we aren't there quite yet, as the code generators depend on LibCore.
76 lines
1.9 KiB
C++
76 lines
1.9 KiB
C++
/*
|
|
* Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/HashMap.h>
|
|
#include <LibJS/Heap/Cell.h>
|
|
#include <LibURL/URL.h>
|
|
#include <LibWeb/Forward.h>
|
|
#include <LibWeb/HTML/CORSSettingAttribute.h>
|
|
#include <LibWeb/HTML/Origin.h>
|
|
|
|
namespace Web::HTML {
|
|
|
|
// https://html.spec.whatwg.org/multipage/images.html#list-of-available-images
|
|
class ListOfAvailableImages : public JS::Cell {
|
|
JS_CELL(ListOfAvailableImages, Cell);
|
|
JS_DECLARE_ALLOCATOR(ListOfAvailableImages);
|
|
|
|
public:
|
|
struct Key {
|
|
URL::URL url;
|
|
HTML::CORSSettingAttribute mode;
|
|
Optional<HTML::Origin> origin;
|
|
|
|
[[nodiscard]] bool operator==(Key const& other) const;
|
|
[[nodiscard]] u32 hash() const;
|
|
|
|
private:
|
|
mutable Optional<u32> cached_hash;
|
|
};
|
|
|
|
struct Entry {
|
|
Entry(JS::NonnullGCPtr<DecodedImageData> image_data, bool ignore_higher_layer_caching)
|
|
: image_data(move(image_data))
|
|
, ignore_higher_layer_caching(ignore_higher_layer_caching)
|
|
{
|
|
}
|
|
|
|
JS::NonnullGCPtr<DecodedImageData> image_data;
|
|
bool ignore_higher_layer_caching { false };
|
|
};
|
|
|
|
ListOfAvailableImages();
|
|
~ListOfAvailableImages();
|
|
|
|
void add(Key const&, JS::NonnullGCPtr<DecodedImageData>, bool ignore_higher_layer_caching);
|
|
void remove(Key const&);
|
|
[[nodiscard]] Entry* get(Key const&);
|
|
|
|
void visit_edges(JS::Cell::Visitor& visitor) override;
|
|
|
|
private:
|
|
HashMap<Key, NonnullOwnPtr<Entry>> m_images;
|
|
};
|
|
|
|
}
|
|
|
|
namespace AK {
|
|
|
|
template<>
|
|
struct Traits<Web::HTML::ListOfAvailableImages::Key> : public DefaultTraits<Web::HTML::ListOfAvailableImages::Key> {
|
|
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;
|
|
}
|
|
};
|
|
|
|
}
|