зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1839316: part 2) Implement getting and setting "fetchpriority" content attribute of `<script>` element. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D181752
This commit is contained in:
Родитель
8810321bff
Коммит
bfca7dd8a2
|
@ -0,0 +1,13 @@
|
|||
/* -*- 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/dom/FetchPriority.h"
|
||||
|
||||
namespace mozilla::dom {
|
||||
const char* kFetchPriorityAttributeValueHigh = "high";
|
||||
const char* kFetchPriorityAttributeValueLow = "low";
|
||||
const char* kFetchPriorityAttributeValueAuto = "auto";
|
||||
} // namespace mozilla::dom
|
|
@ -0,0 +1,23 @@
|
|||
/* -*- 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 mozilla_dom_FetchPriority_h
|
||||
#define mozilla_dom_FetchPriority_h
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
// <https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fetch-priority-attributes>.
|
||||
enum class FetchPriority : uint8_t { High, Low, Auto };
|
||||
|
||||
extern const char* kFetchPriorityAttributeValueHigh;
|
||||
extern const char* kFetchPriorityAttributeValueLow;
|
||||
extern const char* kFetchPriorityAttributeValueAuto;
|
||||
|
||||
} // namespace mozilla::dom
|
||||
|
||||
#endif // mozilla_dom_FetchPriority_h
|
|
@ -4,6 +4,7 @@
|
|||
* 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 "nsAttrValue.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
|
@ -18,6 +19,7 @@
|
|||
#include "nsDOMJSUtils.h"
|
||||
#include "nsIScriptError.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "mozilla/dom/FetchPriority.h"
|
||||
#include "mozilla/dom/HTMLScriptElement.h"
|
||||
#include "mozilla/dom/HTMLScriptElementBinding.h"
|
||||
#include "mozilla/StaticPrefs_dom.h"
|
||||
|
@ -58,6 +60,19 @@ nsresult HTMLScriptElement::BindToTree(BindContext& aContext,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
bool HTMLScriptElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsIPrincipal* aMaybeScriptedPrincipal,
|
||||
|
@ -72,6 +87,13 @@ bool HTMLScriptElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|||
aResult.ParseStringOrAtom(aValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (aAttribute == nsGkAtoms::fetchpriority) {
|
||||
aResult.ParseEnumValue(aValue, kFetchPriorityEnumTable,
|
||||
false /* aCaseSensitive */,
|
||||
kFetchPriorityEnumTableInvalidValueDefault);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
||||
|
@ -211,6 +233,12 @@ bool HTMLScriptElement::HasScriptContent() {
|
|||
nsContentUtils::HasNonEmptyTextContent(this);
|
||||
}
|
||||
|
||||
void HTMLScriptElement::GetFetchPriority(nsAString& aFetchPriority) const {
|
||||
// <https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fetch-priority-attributes>.
|
||||
GetEnumAttr(nsGkAtoms::fetchpriority, kFetchPriorityAttributeValueAuto,
|
||||
aFetchPriority);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/scripting.html#dom-script-supports
|
||||
/* static */
|
||||
bool HTMLScriptElement::Supports(const GlobalObject& aGlobal,
|
||||
|
|
|
@ -128,12 +128,10 @@ class HTMLScriptElement final : public nsGenericHTMLElement,
|
|||
GetEnumAttr(nsGkAtoms::referrerpolicy, "", aReferrerPolicy);
|
||||
}
|
||||
|
||||
void GetFetchPriority(nsAString& aFetchPriority) {
|
||||
// TODO: impl.
|
||||
}
|
||||
void GetFetchPriority(nsAString& aFetchPriority) const;
|
||||
|
||||
void SetFetchPriority(const nsAString& aFetchPriority) {
|
||||
// TODO: impl.
|
||||
SetHTMLAttr(nsGkAtoms::fetchpriority, aFetchPriority);
|
||||
}
|
||||
|
||||
[[nodiscard]] static bool Supports(const GlobalObject& aGlobal,
|
||||
|
|
|
@ -43,6 +43,7 @@ EXPORTS.mozilla += [
|
|||
EXPORTS.mozilla.dom += [
|
||||
"ConstraintValidation.h",
|
||||
"ElementInternals.h",
|
||||
"FetchPriority.h",
|
||||
"HTMLAllCollection.h",
|
||||
"HTMLAnchorElement.h",
|
||||
"HTMLAreaElement.h",
|
||||
|
@ -127,6 +128,7 @@ EXPORTS.mozilla.dom += [
|
|||
UNIFIED_SOURCES += [
|
||||
"ConstraintValidation.cpp",
|
||||
"ElementInternals.cpp",
|
||||
"FetchPriority.cpp",
|
||||
"HTMLAllCollection.cpp",
|
||||
"HTMLAnchorElement.cpp",
|
||||
"HTMLAreaElement.cpp",
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
[attr-script-fetchpriority.html]
|
||||
[fetchpriority attribute on <script> elements should reflect valid IDL values]
|
||||
expected: FAIL
|
||||
|
||||
[default fetchpriority attribute on <script> elements should be 'auto']
|
||||
expected: FAIL
|
Загрузка…
Ссылка в новой задаче