ladybird/Libraries/LibWeb/CSS/URL.h
Andreas Kling 222c1f7044 LibWeb: Move CSS image loading state to Document
Move the SharedResourceRequest, animation timer, and current frame
state out of ImageStyleValue and into a Document-owned table keyed
by resolved image URL. ImageStyleValue now keeps only URL metadata
and its client list, so image style values no longer need to trace
GC edges themselves.

Thread the Document through AbstractImageStyleValue APIs that need
decoded image data. CSS image fetches snapshot the stylesheet base URL,
referrer behavior, and origin-clean state instead of retaining the
stylesheet.

Remember each client's registered resolved URL when unregistering. This
keeps a later document base change from leaving an animated image
resource alive.

Add text coverage for inline relative image base URLs, stylesheet
referrers, imported stylesheet origin-clean behavior, inline @import
initiator type, and unregistering an animated background image after a
base element change.
2026-06-06 23:29:48 +02:00

76 lines
1.9 KiB
C++

/*
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/FlyString.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibGC/Ptr.h>
#include <LibWeb/Export.h>
#include <LibWeb/Forward.h>
namespace Web::CSS {
// https://drafts.csswg.org/css-values-5/#request-url-modifiers
class RequestURLModifier {
public:
enum class Type : u8 {
CrossOrigin,
Integrity,
ReferrerPolicy,
};
static RequestURLModifier create_cross_origin(CrossOriginModifierValue);
static RequestURLModifier create_integrity(FlyString);
static RequestURLModifier create_referrer_policy(ReferrerPolicyModifierValue);
~RequestURLModifier() = default;
void modify_request(GC::Ref<Fetch::Infrastructure::Request>) const;
Type type() const { return m_type; }
String to_string() const;
bool operator==(RequestURLModifier const&) const;
private:
using Value = Variant<CrossOriginModifierValue, ReferrerPolicyModifierValue, FlyString>;
RequestURLModifier(Type, Value);
Type m_type;
Value m_value;
};
// https://drafts.csswg.org/css-values-4/#urls
class WEB_API URL {
public:
enum class Type : u8 {
Url,
Src,
};
URL(String url, Type = Type::Url, Vector<RequestURLModifier> = {});
String const& url() const { return m_url; }
Type type() const { return m_type; }
Vector<RequestURLModifier> const& request_url_modifiers() const { return m_request_url_modifiers; }
String to_string() const;
bool operator==(URL const&) const;
private:
Type m_type;
String m_url;
Vector<RequestURLModifier> m_request_url_modifiers;
};
}
template<>
struct AK::Formatter<Web::CSS::URL> : AK::Formatter<StringView> {
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::URL const& value)
{
return Formatter<StringView>::format(builder, value.to_string());
}
};