HTMLLinkElement.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, the SerenityOS developers.
  4. * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
  5. * Copyright (c) 2023, Srikavin Ramkumar <me@srikavin.me>
  6. *
  7. * SPDX-License-Identifier: BSD-2-Clause
  8. */
  9. #pragma once
  10. #include <LibWeb/DOM/DocumentLoadEventDelayer.h>
  11. #include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>
  12. #include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
  13. #include <LibWeb/HTML/CORSSettingAttribute.h>
  14. #include <LibWeb/HTML/HTMLElement.h>
  15. #include <LibWeb/Loader/Resource.h>
  16. namespace Web::HTML {
  17. class HTMLLinkElement final
  18. : public HTMLElement
  19. , public ResourceClient {
  20. WEB_PLATFORM_OBJECT(HTMLLinkElement, HTMLElement);
  21. public:
  22. virtual ~HTMLLinkElement() override;
  23. virtual void inserted() override;
  24. DeprecatedString rel() const { return attribute(HTML::AttributeNames::rel); }
  25. DeprecatedString type() const { return attribute(HTML::AttributeNames::type); }
  26. DeprecatedString href() const { return attribute(HTML::AttributeNames::href); }
  27. bool has_loaded_icon() const;
  28. bool load_favicon_and_use_if_window_is_active();
  29. private:
  30. HTMLLinkElement(DOM::Document&, DOM::QualifiedName);
  31. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  32. void parse_attribute(DeprecatedFlyString const&, DeprecatedString const&) override;
  33. // ^ResourceClient
  34. virtual void resource_did_fail() override;
  35. virtual void resource_did_load() override;
  36. // ^ HTMLElement
  37. virtual void did_remove_attribute(DeprecatedFlyString const&) override;
  38. virtual void visit_edges(Cell::Visitor&) override;
  39. struct LinkProcessingOptions {
  40. // href (default the empty string)
  41. String href {};
  42. // destination (default the empty string)
  43. Optional<Fetch::Infrastructure::Request::Destination> destination {};
  44. // initiator (default "link")
  45. Optional<Fetch::Infrastructure::Request::InitiatorType> initiator { Fetch::Infrastructure::Request::InitiatorType::Link };
  46. // integrity (default the empty string)
  47. String integrity {};
  48. // type (default the empty string)
  49. String type {};
  50. // cryptographic nonce metadata (default the empty string)
  51. // A string
  52. String cryptographic_nonce_metadata {};
  53. // crossorigin (default No CORS)
  54. // A CORS settings attribute state
  55. CORSSettingAttribute crossorigin { CORSSettingAttribute::NoCORS };
  56. // referrer policy (default the empty string)
  57. // A referrer policy
  58. Optional<ReferrerPolicy::ReferrerPolicy> referrer_policy {};
  59. // FIXME: source set (default null)
  60. // Null or a source set
  61. // base URL
  62. // A URL
  63. AK::URL base_url;
  64. // origin
  65. // An origin
  66. HTML::Origin origin;
  67. // environment
  68. // An environment
  69. JS::GCPtr<HTML::EnvironmentSettingsObject> environment;
  70. // policy container
  71. // A policy container
  72. HTML::PolicyContainer policy_container;
  73. // document (default null)
  74. // Null or a Document
  75. JS::GCPtr<Web::DOM::Document> document;
  76. // FIXME: on document ready (default null)
  77. // Null or an algorithm accepting a Document
  78. };
  79. // https://html.spec.whatwg.org/multipage/semantics.html#create-link-options-from-element
  80. LinkProcessingOptions create_link_options();
  81. // https://html.spec.whatwg.org/multipage/semantics.html#create-a-link-request
  82. JS::GCPtr<Fetch::Infrastructure::Request> create_link_request(LinkProcessingOptions const&);
  83. // https://html.spec.whatwg.org/multipage/semantics.html#linked-resource-fetch-setup-steps
  84. bool linked_resource_fetch_setup_steps(Fetch::Infrastructure::Request&);
  85. // https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet:linked-resource-fetch-setup-steps
  86. bool stylesheet_linked_resource_fetch_setup_steps(Fetch::Infrastructure::Request&);
  87. // https://html.spec.whatwg.org/multipage/semantics.html#fetch-and-process-the-linked-resource
  88. void fetch_and_process_linked_resource();
  89. // https://html.spec.whatwg.org/multipage/semantics.html#process-the-linked-resource
  90. void process_linked_resource(bool success, Fetch::Infrastructure::Response const&, Variant<Empty, Fetch::Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag, ByteBuffer>);
  91. // https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet:process-the-linked-resource
  92. void process_stylesheet_resource(bool success, Fetch::Infrastructure::Response const&, Variant<Empty, Fetch::Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag, ByteBuffer>);
  93. // https://html.spec.whatwg.org/multipage/semantics.html#default-fetch-and-process-the-linked-resource
  94. void default_fetch_and_process_linked_resource();
  95. void resource_did_load_favicon();
  96. struct Relationship {
  97. enum {
  98. Alternate = 1 << 0,
  99. Stylesheet = 1 << 1,
  100. Preload = 1 << 2,
  101. DNSPrefetch = 1 << 3,
  102. Preconnect = 1 << 4,
  103. Icon = 1 << 5,
  104. };
  105. };
  106. JS::GCPtr<CSS::CSSStyleSheet> m_loaded_style_sheet;
  107. Optional<DOM::DocumentLoadEventDelayer> m_document_load_event_delayer;
  108. unsigned m_relationship { 0 };
  109. };
  110. }