Bug 1878888 - Add the runtime flag and parsing for the blocking attribute, r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D200810
This commit is contained in:
Cathie Chen 2024-02-07 17:06:56 +00:00
parent 214e343253
commit d7bb85c04b
15 changed files with 80 additions and 21 deletions

View File

@ -276,6 +276,9 @@ nsIFrame* nsIContent::GetPrimaryFrame(mozilla::FlushType aType) {
namespace mozilla::dom {
const DOMTokenListSupportedToken Element::sSupportedBlockingValues[] = {
"render", nullptr};
nsDOMAttributeMap* Element::Attributes() {
nsDOMSlots* slots = DOMSlots();
if (!slots->mAttributeMap) {

View File

@ -1834,6 +1834,11 @@ class Element : public FragmentOrElement {
static const bool kCallAfterSetAttr = true;
static const bool kDontCallAfterSetAttr = false;
/*
* The supported values of blocking attribute for use with nsDOMTokenList.
*/
static const DOMTokenListSupportedToken sSupportedBlockingValues[];
/**
* Set attribute and (if needed) notify documentobservers and fire off
* mutation events. This will send the AttributeChanged notification.

View File

@ -60,6 +60,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLLinkElement,
tmp->LinkStyle::Traverse(cb);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRelList)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSizes)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBlocking)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLLinkElement,
@ -67,6 +68,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLLinkElement,
tmp->LinkStyle::Unlink();
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRelList)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSizes)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mBlocking)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(HTMLLinkElement,
@ -693,4 +695,12 @@ bool HTMLLinkElement::IsCSSMimeTypeAttributeForLinkElement(
return mimeType.IsEmpty() || mimeType.LowerCaseEqualsLiteral("text/css");
}
nsDOMTokenList* HTMLLinkElement::Blocking() {
if (!mBlocking) {
mBlocking =
new nsDOMTokenList(this, nsGkAtoms::blocking, sSupportedBlockingValues);
}
return mBlocking;
}
} // namespace mozilla::dom

View File

@ -166,6 +166,8 @@ class HTMLLinkElement final : public nsGenericHTMLElement,
return AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin));
}
nsDOMTokenList* Blocking();
void NodeInfoChanged(Document* aOldDoc) final {
mCachedURI = nullptr;
nsGenericHTMLElement::NodeInfoChanged(aOldDoc);
@ -197,6 +199,7 @@ class HTMLLinkElement final : public nsGenericHTMLElement,
RefPtr<nsDOMTokenList> mRelList;
RefPtr<nsDOMTokenList> mSizes;
RefPtr<nsDOMTokenList> mBlocking;
// A weak reference to our preload is held only to cancel the preload when
// this node updates or unbounds from the tree. We want to prevent cycles,

View File

@ -21,6 +21,7 @@
#include "nsDOMJSUtils.h"
#include "nsIScriptError.h"
#include "nsISupportsImpl.h"
#include "nsDOMTokenList.h"
#include "mozilla/dom/FetchPriority.h"
#include "mozilla/dom/HTMLScriptElement.h"
#include "mozilla/dom/HTMLScriptElementBinding.h"
@ -47,9 +48,14 @@ HTMLScriptElement::HTMLScriptElement(
HTMLScriptElement::~HTMLScriptElement() = default;
NS_IMPL_ISUPPORTS_INHERITED(HTMLScriptElement, nsGenericHTMLElement,
nsIScriptLoaderObserver, nsIScriptElement,
nsIMutationObserver)
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(HTMLScriptElement,
nsGenericHTMLElement,
nsIScriptLoaderObserver,
nsIScriptElement,
nsIMutationObserver)
NS_IMPL_CYCLE_COLLECTION_INHERITED(HTMLScriptElement, nsGenericHTMLElement,
mBlocking)
nsresult HTMLScriptElement::BindToTree(BindContext& aContext,
nsINode& aParent) {
@ -237,4 +243,12 @@ bool HTMLScriptElement::Supports(const GlobalObject& aGlobal,
aType.EqualsLiteral("importmap");
}
nsDOMTokenList* HTMLScriptElement::Blocking() {
if (!mBlocking) {
mBlocking =
new nsDOMTokenList(this, nsGkAtoms::blocking, sSupportedBlockingValues);
}
return mBlocking;
}
} // namespace mozilla::dom

View File

@ -13,6 +13,8 @@
#include "nsGenericHTMLElement.h"
#include "nsStringFwd.h"
class nsDOMTokenList;
namespace mozilla::dom {
class HTMLScriptElement final : public nsGenericHTMLElement,
@ -26,6 +28,10 @@ class HTMLScriptElement final : public nsGenericHTMLElement,
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
// CC
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLScriptElement,
nsGenericHTMLElement)
void GetInnerHTML(nsAString& aInnerHTML, OOMReporter& aError) override;
virtual void SetInnerHTML(const nsAString& aInnerHTML,
nsIPrincipal* aSubjectPrincipal,
@ -131,6 +137,8 @@ class HTMLScriptElement final : public nsGenericHTMLElement,
GetEnumAttr(nsGkAtoms::referrerpolicy, "", aReferrerPolicy);
}
nsDOMTokenList* Blocking();
// Required for the webidl-binding because `GetFetchPriority` is overloaded.
using nsGenericHTMLElement::GetFetchPriority;
@ -150,6 +158,8 @@ class HTMLScriptElement final : public nsGenericHTMLElement,
// ScriptElement
virtual bool HasScriptContent() override;
RefPtr<nsDOMTokenList> mBlocking;
};
} // namespace mozilla::dom

View File

@ -14,6 +14,7 @@
#include "nsThreadUtils.h"
#include "nsContentUtils.h"
#include "nsStubMutationObserver.h"
#include "nsDOMTokenList.h"
NS_IMPL_NS_NEW_HTML_ELEMENT(Style)
@ -32,11 +33,13 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLStyleElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLStyleElement,
nsGenericHTMLElement)
tmp->LinkStyle::Traverse(cb);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBlocking)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLStyleElement,
nsGenericHTMLElement)
tmp->LinkStyle::Unlink();
NS_IMPL_CYCLE_COLLECTION_UNLINK(mBlocking)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(HTMLStyleElement,
@ -188,4 +191,12 @@ JSObject* HTMLStyleElement::WrapNode(JSContext* aCx,
return HTMLStyleElement_Binding::Wrap(aCx, this, aGivenProto);
}
nsDOMTokenList* HTMLStyleElement::Blocking() {
if (!mBlocking) {
mBlocking =
new nsDOMTokenList(this, nsGkAtoms::blocking, sSupportedBlockingValues);
}
return mBlocking;
}
} // namespace mozilla::dom

View File

@ -12,6 +12,8 @@
#include "nsGenericHTMLElement.h"
#include "nsStubMutationObserver.h"
class nsDOMTokenList;
namespace mozilla::dom {
class HTMLStyleElement final : public nsGenericHTMLElement,
@ -71,6 +73,8 @@ class HTMLStyleElement final : public nsGenericHTMLElement,
SetHTMLAttr(nsGkAtoms::type, aType, aError);
}
nsDOMTokenList* Blocking();
virtual JSObject* WrapNode(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
@ -87,6 +91,8 @@ class HTMLStyleElement final : public nsGenericHTMLElement,
* parent; we should only respond to the change if aContent is non-anonymous.
*/
void ContentChanged(nsIContent* aContent);
RefPtr<nsDOMTokenList> mBlocking;
};
} // namespace mozilla::dom

View File

@ -39,6 +39,8 @@ interface HTMLLinkElement : HTMLElement {
attribute USVString imageSrcset;
[CEReactions, SetterThrows, Pure]
attribute USVString imageSizes;
[Pref="dom.element.blocking.enabled", SameObject, PutForwards=value]
readonly attribute DOMTokenList blocking;
[Pref="network.fetchpriority.enabled", CEReactions]
attribute DOMString fetchPriority;
};

View File

@ -30,6 +30,8 @@ interface HTMLScriptElement : HTMLElement {
attribute DOMString referrerPolicy;
[CEReactions, Throws]
attribute DOMString text;
[Pref="dom.element.blocking.enabled", SameObject, PutForwards=value]
readonly attribute DOMTokenList blocking;
[Pref="network.fetchpriority.enabled", CEReactions]
attribute DOMString fetchPriority;

View File

@ -18,6 +18,8 @@ interface HTMLStyleElement : HTMLElement {
attribute DOMString media;
[CEReactions, SetterThrows, Pure]
attribute DOMString type;
[Pref="dom.element.blocking.enabled", SameObject, PutForwards=value]
readonly attribute DOMTokenList blocking;
};
HTMLStyleElement includes LinkStyle;

View File

@ -2343,6 +2343,13 @@
mirror: always
rust: true
# Whether the blocking attribute implementation is enabled,
# see https://html.spec.whatwg.org/#blocking-attributes
- name: dom.element.blocking.enabled
type: bool
value: false
mirror: always
# Whether CustomStateSet is enabled
- name: dom.element.customstateset.enabled
type: RelaxedAtomicBool

View File

@ -0,0 +1 @@
prefs: [dom.element.blocking.enabled: true]

View File

@ -1,18 +0,0 @@
[blocking-idl-attr.html]
[Supported tokens of the 'blocking' IDL attribute of the link element]
expected: FAIL
[Setting the 'blocking' IDL attribute of the link element]
expected: FAIL
[Supported tokens of the 'blocking' IDL attribute of the script element]
expected: FAIL
[Setting the 'blocking' IDL attribute of the script element]
expected: FAIL
[Supported tokens of the 'blocking' IDL attribute of the style element]
expected: FAIL
[Setting the 'blocking' IDL attribute of the style element]
expected: FAIL

View File

@ -189,6 +189,7 @@ STATIC_ATOMS = [
Atom("black", "black"),
Atom("block", "block"),
Atom("block_size", "block-size"),
Atom("blocking", "blocking"),
Atom("blockquote", "blockquote"),
Atom("blur", "blur"),
Atom("body", "body"),