HTMLMetaElement.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. * Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibWeb/Bindings/Intrinsics.h>
  8. #include <LibWeb/DOM/Document.h>
  9. #include <LibWeb/HTML/HTMLMetaElement.h>
  10. namespace Web::HTML {
  11. HTMLMetaElement::HTMLMetaElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  12. : HTMLElement(document, move(qualified_name))
  13. {
  14. }
  15. HTMLMetaElement::~HTMLMetaElement() = default;
  16. void HTMLMetaElement::initialize(JS::Realm& realm)
  17. {
  18. Base::initialize(realm);
  19. set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLMetaElementPrototype>(realm, "HTMLMetaElement"));
  20. }
  21. Optional<HTMLMetaElement::HttpEquivAttributeState> HTMLMetaElement::http_equiv_state() const
  22. {
  23. auto value = deprecated_attribute(HTML::AttributeNames::http_equiv);
  24. #define __ENUMERATE_HTML_META_HTTP_EQUIV_ATTRIBUTE(keyword, state) \
  25. if (value.equals_ignoring_ascii_case(#keyword##sv)) \
  26. return HTMLMetaElement::HttpEquivAttributeState::state;
  27. ENUMERATE_HTML_META_HTTP_EQUIV_ATTRIBUTES
  28. #undef __ENUMERATE_HTML_META_HTTP_EQUIV_ATTRIBUTE
  29. return OptionalNone {};
  30. }
  31. void HTMLMetaElement::inserted()
  32. {
  33. Base::inserted();
  34. // https://html.spec.whatwg.org/multipage/semantics.html#pragma-directives
  35. // When a meta element is inserted into the document, if its http-equiv attribute is present and represents one of
  36. // the above states, then the user agent must run the algorithm appropriate for that state, as described in the
  37. // following list:
  38. auto http_equiv = http_equiv_state();
  39. if (http_equiv.has_value()) {
  40. switch (http_equiv.value()) {
  41. case HttpEquivAttributeState::Refresh: {
  42. // https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-refresh
  43. // 1. If the meta element has no content attribute, or if that attribute's value is the empty string, then return.
  44. // 2. Let input be the value of the element's content attribute.
  45. if (!has_attribute(AttributeNames::content))
  46. break;
  47. auto input = deprecated_attribute(AttributeNames::content);
  48. if (input.is_empty())
  49. break;
  50. // 3. Run the shared declarative refresh steps with the meta element's node document, input, and the meta element.
  51. document().shared_declarative_refresh_steps(input, this);
  52. break;
  53. }
  54. default:
  55. dbgln("FIXME: Implement '{}' http-equiv state", deprecated_attribute(AttributeNames::http_equiv));
  56. break;
  57. }
  58. }
  59. }
  60. }