| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2023-06-06 07:03:30 +02:00
										 |  |  |  * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2021-02-21 18:44:17 +02:00
										 |  |  |  * Copyright (c) 2021, the SerenityOS developers. | 
					
						
							| 
									
										
										
										
											2021-11-18 19:22:59 +00:00
										 |  |  |  * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> | 
					
						
							| 
									
										
										
										
											2023-01-14 19:05:28 +05:30
										 |  |  |  * Copyright (c) 2023, Srikavin Ramkumar <me@srikavin.me> | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-07 19:06:47 +02:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-18 19:22:59 +00:00
										 |  |  | #include <LibWeb/DOM/DocumentLoadEventDelayer.h>
 | 
					
						
							| 
									
										
										
										
											2023-01-14 19:05:28 +05:30
										 |  |  | #include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
 | 
					
						
							|  |  |  | #include <LibWeb/HTML/CORSSettingAttribute.h>
 | 
					
						
							| 
									
										
										
										
											2020-07-26 15:08:16 +02:00
										 |  |  | #include <LibWeb/HTML/HTMLElement.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-25 14:11:11 +00:00
										 |  |  | #include <LibWeb/Loader/Resource.h>
 | 
					
						
							| 
									
										
										
										
											2019-10-07 19:06:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 18:20:36 +02:00
										 |  |  | namespace Web::HTML { | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-18 19:22:59 +00:00
										 |  |  | class HTMLLinkElement final | 
					
						
							|  |  |  |     : public HTMLElement | 
					
						
							|  |  |  |     , public ResourceClient { | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     WEB_PLATFORM_OBJECT(HTMLLinkElement, HTMLElement); | 
					
						
							| 
									
										
										
										
											2023-11-19 19:47:52 +01:00
										 |  |  |     JS_DECLARE_ALLOCATOR(HTMLLinkElement); | 
					
						
							| 
									
										
										
										
											2020-07-27 05:04:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2019-10-07 19:06:47 +02:00
										 |  |  |     virtual ~HTMLLinkElement() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-06 17:58:20 +01:00
										 |  |  |     virtual void inserted() override; | 
					
						
							| 
									
										
										
										
											2024-04-21 19:46:37 +02:00
										 |  |  |     virtual void removed_from(Node* old_parent) override; | 
					
						
							| 
									
										
										
										
											2019-10-07 19:06:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-16 19:04:45 +01:00
										 |  |  |     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); } | 
					
						
							| 
									
										
										
										
											2024-06-04 08:04:44 +01:00
										 |  |  |     String as() const; | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<void> set_as(String const&); | 
					
						
							| 
									
										
										
										
											2020-06-02 12:53:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-18 05:54:15 +01:00
										 |  |  |     JS::NonnullGCPtr<DOM::DOMTokenList> rel_list(); | 
					
						
							| 
									
										
										
										
											2024-05-16 06:02:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-03 19:49:38 +02:00
										 |  |  |     bool has_loaded_icon() const; | 
					
						
							|  |  |  |     bool load_favicon_and_use_if_window_is_active(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-30 10:47:34 -04:00
										 |  |  |     static WebIDL::ExceptionOr<void> load_fallback_favicon_if_needed(JS::NonnullGCPtr<DOM::Document>); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-02 12:53:29 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     HTMLLinkElement(DOM::Document&, DOM::QualifiedName); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  |     virtual void initialize(JS::Realm&) override; | 
					
						
							| 
									
										
										
										
											2024-05-16 06:02:56 +01:00
										 |  |  |     virtual void attribute_changed(FlyString const&, Optional<String> const&) override; | 
					
						
							| 
									
										
										
										
											2020-06-15 20:25:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-18 19:22:59 +00:00
										 |  |  |     // ^ResourceClient
 | 
					
						
							|  |  |  |     virtual void resource_did_fail() override; | 
					
						
							|  |  |  |     virtual void resource_did_load() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-20 01:46:25 +01:00
										 |  |  |     // ^ HTMLElement
 | 
					
						
							|  |  |  |     virtual void visit_edges(Cell::Visitor&) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-14 19:05:28 +05:30
										 |  |  |     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
 | 
					
						
							| 
									
										
										
										
											2024-03-05 09:35:25 -07:00
										 |  |  |         ReferrerPolicy::ReferrerPolicy referrer_policy { ReferrerPolicy::ReferrerPolicy::EmptyString }; | 
					
						
							| 
									
										
										
										
											2023-01-14 19:05:28 +05:30
										 |  |  |         // FIXME: source set (default null)
 | 
					
						
							|  |  |  |         //          Null or a source set
 | 
					
						
							|  |  |  |         // base URL
 | 
					
						
							|  |  |  |         //      A URL
 | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  |         URL::URL base_url; | 
					
						
							| 
									
										
										
										
											2023-01-14 19:05:28 +05:30
										 |  |  |         // origin
 | 
					
						
							|  |  |  |         //      An origin
 | 
					
						
							|  |  |  |         HTML::Origin origin; | 
					
						
							|  |  |  |         // environment
 | 
					
						
							|  |  |  |         //      An environment
 | 
					
						
							| 
									
										
										
										
											2023-03-20 13:30:04 -07:00
										 |  |  |         JS::GCPtr<HTML::EnvironmentSettingsObject> environment; | 
					
						
							| 
									
										
										
										
											2023-01-14 19:05:28 +05:30
										 |  |  |         // policy container
 | 
					
						
							|  |  |  |         //      A policy container
 | 
					
						
							|  |  |  |         HTML::PolicyContainer policy_container; | 
					
						
							|  |  |  |         // document (default null)
 | 
					
						
							|  |  |  |         //      Null or a Document
 | 
					
						
							| 
									
										
										
										
											2023-03-20 13:30:04 -07:00
										 |  |  |         JS::GCPtr<Web::DOM::Document> document; | 
					
						
							| 
									
										
										
										
											2023-01-14 19:05:28 +05:30
										 |  |  |         // FIXME: on document ready (default null)
 | 
					
						
							|  |  |  |         //          Null or an algorithm accepting a Document
 | 
					
						
							| 
									
										
										
										
											2024-05-30 21:31:14 +01:00
										 |  |  |         // fetch priority (default auto)
 | 
					
						
							|  |  |  |         //      A fetch priority attribute state
 | 
					
						
							|  |  |  |         Fetch::Infrastructure::Request::Priority fetch_priority { Fetch::Infrastructure::Request::Priority::Auto }; | 
					
						
							| 
									
										
										
										
											2023-01-14 19:05:28 +05:30
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // 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
 | 
					
						
							|  |  |  |     JS::GCPtr<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(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-03 19:49:38 +02:00
										 |  |  |     void resource_did_load_favicon(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-15 20:25:25 +02:00
										 |  |  |     struct Relationship { | 
					
						
							|  |  |  |         enum { | 
					
						
							|  |  |  |             Alternate = 1 << 0, | 
					
						
							|  |  |  |             Stylesheet = 1 << 1, | 
					
						
							| 
									
										
										
										
											2021-09-27 02:06:37 +02:00
										 |  |  |             Preload = 1 << 2, | 
					
						
							| 
									
										
										
										
											2021-09-28 00:08:29 +03:30
										 |  |  |             DNSPrefetch = 1 << 3, | 
					
						
							|  |  |  |             Preconnect = 1 << 4, | 
					
						
							| 
									
										
										
										
											2022-04-03 19:39:38 +02:00
										 |  |  |             Icon = 1 << 5, | 
					
						
							| 
									
										
										
										
											2020-06-15 20:25:25 +02:00
										 |  |  |         }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-20 01:46:25 +01:00
										 |  |  |     JS::GCPtr<CSS::CSSStyleSheet> m_loaded_style_sheet; | 
					
						
							| 
									
										
										
										
											2021-09-27 02:06:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-18 19:22:59 +00:00
										 |  |  |     Optional<DOM::DocumentLoadEventDelayer> m_document_load_event_delayer; | 
					
						
							| 
									
										
										
										
											2024-05-16 06:02:56 +01:00
										 |  |  |     JS::GCPtr<DOM::DOMTokenList> m_rel_list; | 
					
						
							| 
									
										
										
										
											2021-03-08 15:43:03 +01:00
										 |  |  |     unsigned m_relationship { 0 }; | 
					
						
							| 
									
										
										
										
											2024-04-16 21:02:50 +01:00
										 |  |  |     // https://html.spec.whatwg.org/multipage/semantics.html#explicitly-enabled
 | 
					
						
							|  |  |  |     bool m_explicitly_enabled { false }; | 
					
						
							| 
									
										
										
										
											2019-10-07 19:06:47 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |