From 4ad8ba11d53dc36c174fb553fa6abda6003cee88 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Thu, 28 Nov 2024 20:38:36 +0000 Subject: [PATCH] LibWeb: Use the [Reflect] attribute to implement `HTMLLinkElement.as` Also ensure that all valid potential destinations are allowed permitted. --- Libraries/LibWeb/HTML/HTMLLinkElement.cpp | 19 -------------- Libraries/LibWeb/HTML/HTMLLinkElement.h | 1 - Libraries/LibWeb/HTML/HTMLLinkElement.idl | 30 ++++++++++++++++++++++- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp index 4c9a38d7584..4b67f2f8d81 100644 --- a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp @@ -91,25 +91,6 @@ void HTMLLinkElement::inserted() } } -// https://html.spec.whatwg.org/multipage/semantics.html#dom-link-as -String HTMLLinkElement::as() const -{ - String attribute_value = get_attribute_value(HTML::AttributeNames::as); - - if (attribute_value.equals_ignoring_ascii_case("fetch"sv) - || attribute_value.equals_ignoring_ascii_case("image"sv) - || attribute_value.equals_ignoring_ascii_case("script"sv) - || attribute_value.equals_ignoring_ascii_case("style"sv) - || attribute_value.equals_ignoring_ascii_case("video"sv) - || attribute_value.equals_ignoring_ascii_case("audio"sv) - || attribute_value.equals_ignoring_ascii_case("track"sv) - || attribute_value.equals_ignoring_ascii_case("font"sv)) { - return attribute_value.to_lowercase().release_value(); - } - - return String {}; -} - WebIDL::ExceptionOr HTMLLinkElement::set_as(String const& value) { return set_attribute(HTML::AttributeNames::as, move(value)); diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.h b/Libraries/LibWeb/HTML/HTMLLinkElement.h index 09398005c16..cd1b958137e 100644 --- a/Libraries/LibWeb/HTML/HTMLLinkElement.h +++ b/Libraries/LibWeb/HTML/HTMLLinkElement.h @@ -33,7 +33,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); } - String as() const; WebIDL::ExceptionOr set_as(String const&); GC::Ref rel_list(); diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.idl b/Libraries/LibWeb/HTML/HTMLLinkElement.idl index 0fe41bdbd9a..05fc7800ec0 100644 --- a/Libraries/LibWeb/HTML/HTMLLinkElement.idl +++ b/Libraries/LibWeb/HTML/HTMLLinkElement.idl @@ -3,6 +3,34 @@ #import #import +// https://fetch.spec.whatwg.org/#concept-potential-destination +enum PotentialDestination { + "", + "audio", + "audioworklet", + "document", + "embed", + "font", + "frame", + "iframe", + "image", + "json", + "manifest", + "object", + "paintworklet", + "report", + "script", + "serviceworker", + "sharedworker", + "style", + "track", + "video", + "webidentity", + "worker", + "xslt", + "fetch" +}; + // https://html.spec.whatwg.org/multipage/semantics.html#htmllinkelement [Exposed=Window] interface HTMLLinkElement : HTMLElement { @@ -12,7 +40,7 @@ interface HTMLLinkElement : HTMLElement { [CEReactions, Reflect, URL] attribute USVString href; [CEReactions, Reflect=crossorigin, Enumerated=CORSSettingsAttribute] attribute DOMString? crossOrigin; [CEReactions, Reflect] attribute DOMString rel; - [CEReactions] attribute DOMString as; + [CEReactions, Reflect, Enumerated=PotentialDestination] attribute DOMString as; [SameObject, PutForwards=value] readonly attribute DOMTokenList relList; [CEReactions, Reflect] attribute DOMString media; [CEReactions, Reflect] attribute DOMString integrity;