mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-07 15:12:28 +00:00
Bug 1839315: part 6) Lift code for fetchpriority
attribute from nsGenericHTMLElementWithFetchPriorityAttribute
to nsGenericHTMLElement
. r=smaug
As requested in the review of part 1. Differential Revision: https://phabricator.services.mozilla.com/D191274
This commit is contained in:
parent
06401bfd3f
commit
dc52b1401a
@ -49,7 +49,7 @@ namespace mozilla::dom {
|
||||
|
||||
HTMLLinkElement::HTMLLinkElement(
|
||||
already_AddRefed<mozilla::dom::NodeInfo>&& 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) {
|
||||
|
@ -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<mozilla::dom::NodeInfo>&& aNodeInfo);
|
||||
|
@ -41,8 +41,7 @@ JSObject* HTMLScriptElement::WrapNode(JSContext* aCx,
|
||||
HTMLScriptElement::HTMLScriptElement(
|
||||
already_AddRefed<mozilla::dom::NodeInfo>&& 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,
|
||||
|
@ -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);
|
||||
|
@ -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",
|
||||
|
@ -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 {
|
||||
// <https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fetch-priority-attributes>.
|
||||
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 {
|
||||
// <https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fetch-priority-attributes>.
|
||||
static const nsAttrValue::EnumTable kFetchPriorityEnumTable[] = {
|
||||
{kFetchPriorityAttributeValueHigh, FetchPriority::High},
|
||||
{kFetchPriorityAttributeValueLow, FetchPriority::Low},
|
||||
{kFetchPriorityAttributeValueAuto, FetchPriority::Auto},
|
||||
{nullptr, 0}};
|
||||
|
||||
// <https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fetch-priority-attributes>.
|
||||
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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
// <https://html.spec.whatwg.org/#fetch-priority-attribute>.
|
||||
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
|
||||
*/
|
||||
|
@ -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 {
|
||||
// <https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fetch-priority-attributes>.
|
||||
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 {
|
||||
// <https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fetch-priority-attributes>.
|
||||
static const nsAttrValue::EnumTable kFetchPriorityEnumTable[] = {
|
||||
{kFetchPriorityAttributeValueHigh, FetchPriority::High},
|
||||
{kFetchPriorityAttributeValueLow, FetchPriority::Low},
|
||||
{kFetchPriorityAttributeValueAuto, FetchPriority::Auto},
|
||||
{nullptr, 0}};
|
||||
|
||||
// <https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fetch-priority-attributes>.
|
||||
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
|
@ -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 <cstdint>
|
||||
|
||||
#include "nsStringFwd.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
namespace dom {
|
||||
enum class FetchPriority : uint8_t;
|
||||
} // namespace dom
|
||||
|
||||
// <https://html.spec.whatwg.org/#fetch-priority-attribute>.
|
||||
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);
|
||||
}
|
||||
|
||||
// <https://html.spec.whatwg.org/#fetch-priority-attribute>.
|
||||
static mozilla::dom::FetchPriority ToFetchPriority(const nsAString& aValue);
|
||||
|
||||
private:
|
||||
static void ParseFetchPriority(const nsAString& aValue, nsAttrValue& aResult);
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // DOM_HTML_NSGENERICHTMLELEMENTWITHFETCHPRIORITYATTRIBUTE_H_
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user