LibWeb: Organize HTMLLinkElement more consistently with other IDL types

We don't typically put spec links for methods in both the .h and .cpp
(we just put them in the .cpp).

Let's also generally organize the methods in spec-order, which for
HTMLLinkElement generally goes: init fetch -> fetch -> process data.
Makes it a bit easier to scroll through the spec and the code at the
same time.
This commit is contained in:
Timothy Flynn 2025-11-05 07:05:26 -05:00 committed by Andreas Kling
parent 5b40398c39
commit 523433d57d
Notes: github-actions[bot] 2025-11-05 17:28:58 +00:00
2 changed files with 192 additions and 197 deletions

View file

@ -34,7 +34,6 @@ public:
String rel() const { return get_attribute_value(HTML::AttributeNames::rel); }
String type() const { return get_attribute_value(HTML::AttributeNames::type); }
String href() const { return get_attribute_value(HTML::AttributeNames::href); }
WebIDL::ExceptionOr<void> set_as(String const&);
GC::Ref<DOM::DOMTokenList> rel_list();
GC::Ref<DOM::DOMTokenList> sizes();
@ -44,7 +43,7 @@ public:
static WebIDL::ExceptionOr<void> load_fallback_favicon_if_needed(GC::Ref<DOM::Document>);
void set_parser_document(Badge<HTMLParser>, GC::Ref<DOM::Document>);
void set_parser_document(Badge<HTMLParser>, GC::Ref<DOM::Document> document) { m_parser_document = document; }
void set_was_enabled_when_created_by_parser(Badge<HTMLParser>, bool was_enabled_when_created_by_parser) { m_was_enabled_when_created_by_parser = was_enabled_when_created_by_parser; }
void set_media(String);
@ -52,13 +51,72 @@ public:
GC::Ptr<CSS::CSSStyleSheet> sheet() const;
virtual bool contributes_a_script_blocking_style_sheet() const final;
private:
// https://html.spec.whatwg.org/multipage/semantics.html#link-processing-options
struct LinkProcessingOptions {
// href (default the empty string)
String href {};
// initiator (default "link")
Optional<Fetch::Infrastructure::Request::InitiatorType> initiator { Fetch::Infrastructure::Request::InitiatorType::Link };
// integrity (default the empty string)
String integrity {};
// type (default the empty string)
String type {};
// cryptographic nonce metadata (default the empty string)
// A string
String cryptographic_nonce_metadata {};
// destination (default the empty string)
// A destination type.
Optional<Fetch::Infrastructure::Request::Destination> destination {};
// crossorigin (default No CORS)
// A CORS settings attribute state
CORSSettingAttribute crossorigin { CORSSettingAttribute::NoCORS };
// referrer policy (default the empty string)
// A referrer policy
ReferrerPolicy::ReferrerPolicy referrer_policy { ReferrerPolicy::ReferrerPolicy::EmptyString };
// FIXME: source set (default null)
// Null or a source set
// base URL
// A URL
URL::URL base_url;
// origin
// An origin
URL::Origin origin;
// environment
// An environment
GC::Ref<HTML::EnvironmentSettingsObject> environment;
// policy container
// A policy container
GC::Ref<HTML::PolicyContainer> policy_container;
// document (default null)
// Null or a Document
GC::Ptr<Web::DOM::Document> document;
// FIXME: on document ready (default null)
// Null or an algorithm accepting a Document
// fetch priority (default Auto)
// A fetch priority attribute state
Fetch::Infrastructure::Request::Priority fetch_priority { Fetch::Infrastructure::Request::Priority::Auto };
};
HTMLLinkElement(DOM::Document&, DOM::QualifiedName);
virtual void initialize(JS::Realm&) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
virtual void visit_edges(Cell::Visitor&) override;
// ^ResourceClient
virtual void resource_did_fail() override;
@ -68,78 +126,22 @@ private:
virtual bool is_html_link_element() const override { return true; }
// ^HTMLElement
virtual void visit_edges(Cell::Visitor&) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
virtual bool contributes_a_script_blocking_style_sheet() const final;
virtual bool is_implicitly_potentially_render_blocking() const override;
struct LinkProcessingOptions {
// href (default the empty string)
String href {};
// destination (default the empty string)
Optional<Fetch::Infrastructure::Request::Destination> destination {};
// initiator (default "link")
Optional<Fetch::Infrastructure::Request::InitiatorType> initiator { Fetch::Infrastructure::Request::InitiatorType::Link };
// integrity (default the empty string)
String integrity {};
// type (default the empty string)
String type {};
// cryptographic nonce metadata (default the empty string)
// A string
String cryptographic_nonce_metadata {};
// crossorigin (default No CORS)
// A CORS settings attribute state
CORSSettingAttribute crossorigin { CORSSettingAttribute::NoCORS };
// referrer policy (default the empty string)
// A referrer policy
ReferrerPolicy::ReferrerPolicy referrer_policy { ReferrerPolicy::ReferrerPolicy::EmptyString };
// FIXME: source set (default null)
// Null or a source set
// base URL
// A URL
URL::URL base_url;
// origin
// An origin
URL::Origin origin;
// environment
// An environment
GC::Ptr<HTML::EnvironmentSettingsObject> environment;
// policy container
// A policy container
GC::Ptr<HTML::PolicyContainer> policy_container;
// document (default null)
// Null or a Document
GC::Ptr<Web::DOM::Document> document;
// FIXME: on document ready (default null)
// Null or an algorithm accepting a Document
// fetch priority (default auto)
// A fetch priority attribute state
Fetch::Infrastructure::Request::Priority fetch_priority { Fetch::Infrastructure::Request::Priority::Auto };
};
// https://html.spec.whatwg.org/multipage/semantics.html#create-link-options-from-element
LinkProcessingOptions create_link_options();
// https://html.spec.whatwg.org/multipage/semantics.html#create-a-link-request
GC::Ptr<Fetch::Infrastructure::Request> create_link_request(LinkProcessingOptions const&);
// https://html.spec.whatwg.org/multipage/semantics.html#linked-resource-fetch-setup-steps
bool linked_resource_fetch_setup_steps(Fetch::Infrastructure::Request&);
// https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet:linked-resource-fetch-setup-steps
bool stylesheet_linked_resource_fetch_setup_steps(Fetch::Infrastructure::Request&);
// https://html.spec.whatwg.org/multipage/semantics.html#fetch-and-process-the-linked-resource
void fetch_and_process_linked_resource();
// https://html.spec.whatwg.org/multipage/semantics.html#process-the-linked-resource
void process_linked_resource(bool success, Fetch::Infrastructure::Response const&, Variant<Empty, Fetch::Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag, ByteBuffer>);
// https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet:process-the-linked-resource
void process_stylesheet_resource(bool success, Fetch::Infrastructure::Response const&, Variant<Empty, Fetch::Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag, ByteBuffer>);
// https://html.spec.whatwg.org/multipage/semantics.html#default-fetch-and-process-the-linked-resource
void default_fetch_and_process_linked_resource();
void resource_did_load_favicon();
bool linked_resource_fetch_setup_steps(Fetch::Infrastructure::Request&);
bool stylesheet_linked_resource_fetch_setup_steps(Fetch::Infrastructure::Request&);
void process_linked_resource(bool success, Fetch::Infrastructure::Response const&, Variant<Empty, Fetch::Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag, ByteBuffer>);
void process_icon_resource();
void process_stylesheet_resource(bool success, Fetch::Infrastructure::Response const&, Variant<Empty, Fetch::Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag, ByteBuffer>);
struct Relationship {
enum {
@ -153,13 +155,14 @@ private:
};
GC::Ptr<Fetch::Infrastructure::FetchController> m_fetch_controller;
Optional<DOM::DocumentLoadEventDelayer> m_document_load_event_delayer;
GC::Ptr<CSS::CSSStyleSheet> m_loaded_style_sheet;
Optional<DOM::DocumentLoadEventDelayer> m_document_load_event_delayer;
GC::Ptr<DOM::DOMTokenList> m_rel_list;
GC::Ptr<DOM::DOMTokenList> m_sizes;
unsigned m_relationship { 0 };
// https://html.spec.whatwg.org/multipage/semantics.html#explicitly-enabled
bool m_explicitly_enabled { false };