diff --git a/dom/html/HTMLLinkElement.cpp b/dom/html/HTMLLinkElement.cpp index 4135e74f0f4c..f78e24453b80 100644 --- a/dom/html/HTMLLinkElement.cpp +++ b/dom/html/HTMLLinkElement.cpp @@ -49,7 +49,7 @@ namespace mozilla::dom { HTMLLinkElement::HTMLLinkElement( already_AddRefed&& aNodeInfo) - : nsGenericHTMLElementWithFetchPriorityAttribute(std::move(aNodeInfo)) {} + : nsGenericHTMLElement(std::move(aNodeInfo)) {} HTMLLinkElement::~HTMLLinkElement() { SupportsDNSPrefetch::Destroyed(*this); } @@ -163,10 +163,15 @@ bool HTMLLinkElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute, aResult.ParseStringOrAtom(aValue); return true; } + + if (aAttribute == nsGkAtoms::fetchpriority) { + ParseFetchPriority(aValue, aResult); + return true; + } } - return nsGenericHTMLElementWithFetchPriorityAttribute::ParseAttribute( - aNamespaceID, aAttribute, aValue, aMaybeScriptedPrincipal, aResult); + return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue, + aMaybeScriptedPrincipal, aResult); } void HTMLLinkElement::CreateAndDispatchEvent(const nsAString& aEventName) { diff --git a/dom/html/HTMLLinkElement.h b/dom/html/HTMLLinkElement.h index 697468519e73..49969b2c9ab0 100644 --- a/dom/html/HTMLLinkElement.h +++ b/dom/html/HTMLLinkElement.h @@ -8,12 +8,12 @@ #define mozilla_dom_HTMLLinkElement_h #include "mozilla/Attributes.h" -#include "mozilla/nsGenericHTMLElementWithFetchPriorityAttribute.h" #include "mozilla/dom/HTMLDNSPrefetch.h" #include "mozilla/dom/LinkStyle.h" #include "mozilla/dom/Link.h" #include "mozilla/WeakPtr.h" #include "nsDOMTokenList.h" +#include "nsGenericHTMLElement.h" namespace mozilla { class EventChainPostVisitor; @@ -22,10 +22,9 @@ class PreloaderBase; namespace dom { -class HTMLLinkElement final - : public nsGenericHTMLElementWithFetchPriorityAttribute, - public LinkStyle, - public SupportsDNSPrefetch { +class HTMLLinkElement final : public nsGenericHTMLElement, + public LinkStyle, + public SupportsDNSPrefetch { public: explicit HTMLLinkElement( already_AddRefed&& aNodeInfo); diff --git a/dom/html/HTMLScriptElement.cpp b/dom/html/HTMLScriptElement.cpp index 8b0191ed6b93..8d568e0022a3 100644 --- a/dom/html/HTMLScriptElement.cpp +++ b/dom/html/HTMLScriptElement.cpp @@ -41,8 +41,7 @@ JSObject* HTMLScriptElement::WrapNode(JSContext* aCx, HTMLScriptElement::HTMLScriptElement( already_AddRefed&& aNodeInfo, FromParser aFromParser) - : nsGenericHTMLElementWithFetchPriorityAttribute(std::move(aNodeInfo)), - ScriptElement(aFromParser) { + : nsGenericHTMLElement(std::move(aNodeInfo)), ScriptElement(aFromParser) { AddMutationObserver(this); } @@ -78,10 +77,15 @@ bool HTMLScriptElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute, aResult.ParseStringOrAtom(aValue); return true; } + + if (aAttribute == nsGkAtoms::fetchpriority) { + ParseFetchPriority(aValue, aResult); + return true; + } } - return nsGenericHTMLElementWithFetchPriorityAttribute::ParseAttribute( - aNamespaceID, aAttribute, aValue, aMaybeScriptedPrincipal, aResult); + return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue, + aMaybeScriptedPrincipal, aResult); } nsresult HTMLScriptElement::Clone(dom::NodeInfo* aNodeInfo, diff --git a/dom/html/HTMLScriptElement.h b/dom/html/HTMLScriptElement.h index e0c7c045daf7..e1c64b6f5c7b 100644 --- a/dom/html/HTMLScriptElement.h +++ b/dom/html/HTMLScriptElement.h @@ -8,16 +8,15 @@ #define mozilla_dom_HTMLScriptElement_h #include "mozilla/dom/FetchPriority.h" -#include "mozilla/nsGenericHTMLElementWithFetchPriorityAttribute.h" #include "mozilla/Attributes.h" #include "mozilla/dom/ScriptElement.h" +#include "nsGenericHTMLElement.h" #include "nsStringFwd.h" namespace mozilla::dom { -class HTMLScriptElement final - : public nsGenericHTMLElementWithFetchPriorityAttribute, - public ScriptElement { +class HTMLScriptElement final : public nsGenericHTMLElement, + public ScriptElement { public: using Element::GetText; @@ -133,7 +132,7 @@ class HTMLScriptElement final } // Required for the webidl-binding because `GetFetchPriority` is overloaded. - using nsGenericHTMLElementWithFetchPriorityAttribute::GetFetchPriority; + using nsGenericHTMLElement::GetFetchPriority; [[nodiscard]] static bool Supports(const GlobalObject& aGlobal, const nsAString& aType); diff --git a/dom/html/moz.build b/dom/html/moz.build index a7a7de69ce03..779bdb65cbee 100644 --- a/dom/html/moz.build +++ b/dom/html/moz.build @@ -34,7 +34,6 @@ EXPORTS += [ ] EXPORTS.mozilla += [ - "nsGenericHTMLElementWithFetchPriorityAttribute.h", "TextControlElement.h", "TextControlState.h", "TextInputListener.h", @@ -205,7 +204,6 @@ UNIFIED_SOURCES += [ "nsBrowserElement.cpp", "nsDOMStringMap.cpp", "nsGenericHTMLElement.cpp", - "nsGenericHTMLElementWithFetchPriorityAttribute.cpp", "nsGenericHTMLFrameElement.cpp", "nsHTMLContentSink.cpp", "nsHTMLDocument.cpp", diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp index 11b02b96c20d..ebeb823abc73 100644 --- a/dom/html/nsGenericHTMLElement.cpp +++ b/dom/html/nsGenericHTMLElement.cpp @@ -20,6 +20,7 @@ #include "mozilla/TextEvents.h" #include "mozilla/StaticPrefs_html5.h" #include "mozilla/StaticPrefs_accessibility.h" +#include "mozilla/dom/FetchPriority.h" #include "mozilla/dom/FormData.h" #include "nscore.h" #include "nsGenericHTMLElement.h" @@ -188,6 +189,41 @@ static const nsAttrValue::EnumTable* kPopoverTableInvalidValueDefault = &kPopoverTable[2]; } // namespace +void nsGenericHTMLElement::GetFetchPriority(nsAString& aFetchPriority) const { + // . + GetEnumAttr(nsGkAtoms::fetchpriority, kFetchPriorityAttributeValueAuto, + aFetchPriority); +} + +/* static */ +FetchPriority nsGenericHTMLElement::ToFetchPriority(const nsAString& aValue) { + nsAttrValue attrValue; + ParseFetchPriority(aValue, attrValue); + MOZ_ASSERT(attrValue.Type() == nsAttrValue::eEnum); + return FetchPriority(attrValue.GetEnumValue()); +} + +namespace { +// . +static const nsAttrValue::EnumTable kFetchPriorityEnumTable[] = { + {kFetchPriorityAttributeValueHigh, FetchPriority::High}, + {kFetchPriorityAttributeValueLow, FetchPriority::Low}, + {kFetchPriorityAttributeValueAuto, FetchPriority::Auto}, + {nullptr, 0}}; + +// . +static const nsAttrValue::EnumTable* + kFetchPriorityEnumTableInvalidValueDefault = &kFetchPriorityEnumTable[2]; +} // namespace + +/* static */ +void nsGenericHTMLElement::ParseFetchPriority(const nsAString& aValue, + nsAttrValue& aResult) { + aResult.ParseEnumValue(aValue, kFetchPriorityEnumTable, + false /* aCaseSensitive */, + kFetchPriorityEnumTableInvalidValueDefault); +} + void nsGenericHTMLElement::AddToNameTable(nsAtom* aName) { MOZ_ASSERT(HasName(), "Node doesn't have name?"); Document* doc = GetUncomposedDoc(); diff --git a/dom/html/nsGenericHTMLElement.h b/dom/html/nsGenericHTMLElement.h index 95b1957ab24b..f935f1ad34a8 100644 --- a/dom/html/nsGenericHTMLElement.h +++ b/dom/html/nsGenericHTMLElement.h @@ -42,6 +42,7 @@ class PresState; namespace dom { class ElementInternals; class HTMLFormElement; +enum class FetchPriority : uint8_t; } // namespace dom } // namespace mozilla @@ -683,7 +684,19 @@ class nsGenericHTMLElement : public nsGenericHTMLElementBase { GetAttr(nsGkAtoms::value, aResult); } + // . + static mozilla::dom::FetchPriority ToFetchPriority(const nsAString& aValue); + + void GetFetchPriority(nsAString& aFetchPriority) const; + + void SetFetchPriority(const nsAString& aFetchPriority) { + SetHTMLAttr(nsGkAtoms::fetchpriority, aFetchPriority); + } + protected: + static void ParseFetchPriority(const nsAString& aValue, nsAttrValue& aResult); + + private: /** * Add/remove this element to the documents name cache */ diff --git a/dom/html/nsGenericHTMLElementWithFetchPriorityAttribute.cpp b/dom/html/nsGenericHTMLElementWithFetchPriorityAttribute.cpp deleted file mode 100644 index aefcdaaa102c..000000000000 --- a/dom/html/nsGenericHTMLElementWithFetchPriorityAttribute.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "mozilla/nsGenericHTMLElementWithFetchPriorityAttribute.h" - -#include "mozilla/dom/FetchPriority.h" - -namespace mozilla { - -// Can't use `using namespace dom;` because it breaks the unified build. -using dom::FetchPriority; -using dom::kFetchPriorityAttributeValueAuto; -using dom::kFetchPriorityAttributeValueHigh; -using dom::kFetchPriorityAttributeValueLow; - -bool nsGenericHTMLElementWithFetchPriorityAttribute::ParseAttribute( - int32_t aNamespaceID, nsAtom* aAttribute, const nsAString& aValue, - nsIPrincipal* aMaybeScriptedPrincipal, nsAttrValue& aResult) { - if (aNamespaceID == kNameSpaceID_None && - aAttribute == nsGkAtoms::fetchpriority) { - ParseFetchPriority(aValue, aResult); - return true; - } - - return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue, - aMaybeScriptedPrincipal, aResult); -} - -void nsGenericHTMLElementWithFetchPriorityAttribute::GetFetchPriority( - nsAString& aFetchPriority) const { - // . - GetEnumAttr(nsGkAtoms::fetchpriority, kFetchPriorityAttributeValueAuto, - aFetchPriority); -} - -/* static */ -dom::FetchPriority -nsGenericHTMLElementWithFetchPriorityAttribute::ToFetchPriority( - const nsAString& aValue) { - nsAttrValue attrValue; - ParseFetchPriority(aValue, attrValue); - MOZ_ASSERT(attrValue.Type() == nsAttrValue::eEnum); - return FetchPriority(attrValue.GetEnumValue()); -} - -namespace { -// . -static const nsAttrValue::EnumTable kFetchPriorityEnumTable[] = { - {kFetchPriorityAttributeValueHigh, FetchPriority::High}, - {kFetchPriorityAttributeValueLow, FetchPriority::Low}, - {kFetchPriorityAttributeValueAuto, FetchPriority::Auto}, - {nullptr, 0}}; - -// . -static const nsAttrValue::EnumTable* - kFetchPriorityEnumTableInvalidValueDefault = &kFetchPriorityEnumTable[2]; -} // namespace - -/* static */ -void nsGenericHTMLElementWithFetchPriorityAttribute::ParseFetchPriority( - const nsAString& aValue, nsAttrValue& aResult) { - aResult.ParseEnumValue(aValue, kFetchPriorityEnumTable, - false /* aCaseSensitive */, - kFetchPriorityEnumTableInvalidValueDefault); -} - -} // namespace mozilla diff --git a/dom/html/nsGenericHTMLElementWithFetchPriorityAttribute.h b/dom/html/nsGenericHTMLElementWithFetchPriorityAttribute.h deleted file mode 100644 index 72fcbe0ac5e7..000000000000 --- a/dom/html/nsGenericHTMLElementWithFetchPriorityAttribute.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef DOM_HTML_NSGENERICHTMLELEMENTWITHFETCHPRIORITYATTRIBUTE_H_ -#define DOM_HTML_NSGENERICHTMLELEMENTWITHFETCHPRIORITYATTRIBUTE_H_ - -#include "nsGenericHTMLElement.h" - -#include - -#include "nsStringFwd.h" - -namespace mozilla { - -namespace dom { -enum class FetchPriority : uint8_t; -} // namespace dom - -// . -class nsGenericHTMLElementWithFetchPriorityAttribute - : public nsGenericHTMLElement { - public: - using nsGenericHTMLElement::nsGenericHTMLElement; - - bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute, - const nsAString& aValue, - nsIPrincipal* aMaybeScriptedPrincipal, - nsAttrValue& aResult) override; - - void GetFetchPriority(nsAString& aFetchPriority) const; - - void SetFetchPriority(const nsAString& aFetchPriority) { - SetHTMLAttr(nsGkAtoms::fetchpriority, aFetchPriority); - } - - // . - static mozilla::dom::FetchPriority ToFetchPriority(const nsAString& aValue); - - private: - static void ParseFetchPriority(const nsAString& aValue, nsAttrValue& aResult); -}; - -} // namespace mozilla - -#endif // DOM_HTML_NSGENERICHTMLELEMENTWITHFETCHPRIORITYATTRIBUTE_H_ diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index 18c987e6f055..f263af11628f 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -8,9 +8,9 @@ #include "ScriptLoadHandler.h" #include "ScriptTrace.h" #include "ModuleLoader.h" +#include "nsGenericHTMLElement.h" #include "mozilla/Assertions.h" -#include "mozilla/nsGenericHTMLElementWithFetchPriorityAttribute.h" #include "mozilla/dom/FetchPriority.h" #include "mozilla/dom/RequestBinding.h" #include "nsIChildChannel.h" @@ -3892,8 +3892,7 @@ void ScriptLoader::PreloadURI( GetSRIMetadata(aIntegrity, &sriMetadata); const auto requestPriority = FetchPriorityToRequestPriority( - nsGenericHTMLElementWithFetchPriorityAttribute::ToFetchPriority( - aFetchPriority)); + nsGenericHTMLElement::ToFetchPriority(aFetchPriority)); // For link type "modulepreload": // https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload