Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / html / HTMLScriptElement.h
blobc5e99c9e5d0401b534078c82d6ae19c6a2bbf196
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_HTMLScriptElement_h
8 #define mozilla_dom_HTMLScriptElement_h
10 #include "mozilla/dom/FetchPriority.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/dom/ScriptElement.h"
13 #include "nsGenericHTMLElement.h"
14 #include "nsStringFwd.h"
16 class nsDOMTokenList;
18 namespace mozilla::dom {
20 class HTMLScriptElement final : public nsGenericHTMLElement,
21 public ScriptElement {
22 public:
23 using Element::GetText;
25 HTMLScriptElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
26 FromParser aFromParser);
28 // nsISupports
29 NS_DECL_ISUPPORTS_INHERITED
31 // CC
32 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLScriptElement,
33 nsGenericHTMLElement)
35 void GetInnerHTML(nsAString& aInnerHTML, OOMReporter& aError) override;
36 virtual void SetInnerHTML(const nsAString& aInnerHTML,
37 nsIPrincipal* aSubjectPrincipal,
38 mozilla::ErrorResult& aError) override;
40 // nsIScriptElement
41 virtual void GetScriptText(nsAString& text) const override;
42 virtual void GetScriptCharset(nsAString& charset) override;
43 virtual void FreezeExecutionAttrs(const Document* aOwnerDoc) override;
44 virtual CORSMode GetCORSMode() const override;
45 virtual FetchPriority GetFetchPriority() const override;
46 virtual mozilla::dom::ReferrerPolicy GetReferrerPolicy() override;
48 // nsIContent
49 virtual nsresult BindToTree(BindContext&, nsINode& aParent) override;
50 virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
51 const nsAString& aValue,
52 nsIPrincipal* aMaybeScriptedPrincipal,
53 nsAttrValue& aResult) override;
55 virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
57 // Element
58 virtual void AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
59 const nsAttrValue* aValue,
60 const nsAttrValue* aOldValue,
61 nsIPrincipal* aMaybeScriptedPrincipal,
62 bool aNotify) override;
64 // WebIDL
65 void GetText(nsAString& aValue, ErrorResult& aRv) const;
67 void SetText(const nsAString& aValue, ErrorResult& aRv);
69 void GetCharset(nsAString& aCharset) {
70 GetHTMLAttr(nsGkAtoms::charset, aCharset);
72 void SetCharset(const nsAString& aCharset, ErrorResult& aRv) {
73 SetHTMLAttr(nsGkAtoms::charset, aCharset, aRv);
76 bool Defer() { return GetBoolAttr(nsGkAtoms::defer); }
77 void SetDefer(bool aDefer, ErrorResult& aRv) {
78 SetHTMLBoolAttr(nsGkAtoms::defer, aDefer, aRv);
81 void GetSrc(nsAString& aSrc) { GetURIAttr(nsGkAtoms::src, nullptr, aSrc); }
82 void SetSrc(const nsAString& aSrc, nsIPrincipal* aTriggeringPrincipal,
83 ErrorResult& aRv) {
84 SetHTMLAttr(nsGkAtoms::src, aSrc, aTriggeringPrincipal, aRv);
87 void GetType(nsAString& aType) { GetHTMLAttr(nsGkAtoms::type, aType); }
88 void SetType(const nsAString& aType, ErrorResult& aRv) {
89 SetHTMLAttr(nsGkAtoms::type, aType, aRv);
92 void GetHtmlFor(nsAString& aHtmlFor) {
93 GetHTMLAttr(nsGkAtoms::_for, aHtmlFor);
95 void SetHtmlFor(const nsAString& aHtmlFor, ErrorResult& aRv) {
96 SetHTMLAttr(nsGkAtoms::_for, aHtmlFor, aRv);
99 void GetEvent(nsAString& aEvent) { GetHTMLAttr(nsGkAtoms::event, aEvent); }
100 void SetEvent(const nsAString& aEvent, ErrorResult& aRv) {
101 SetHTMLAttr(nsGkAtoms::event, aEvent, aRv);
104 bool Async() { return mForceAsync || GetBoolAttr(nsGkAtoms::async); }
106 void SetAsync(bool aValue, ErrorResult& aRv) {
107 mForceAsync = false;
108 SetHTMLBoolAttr(nsGkAtoms::async, aValue, aRv);
111 bool NoModule() { return GetBoolAttr(nsGkAtoms::nomodule); }
113 void SetNoModule(bool aValue, ErrorResult& aRv) {
114 SetHTMLBoolAttr(nsGkAtoms::nomodule, aValue, aRv);
117 void GetCrossOrigin(nsAString& aResult) {
118 // Null for both missing and invalid defaults is ok, since we
119 // always parse to an enum value, so we don't need an invalid
120 // default, and we _want_ the missing default to be null.
121 GetEnumAttr(nsGkAtoms::crossorigin, nullptr, aResult);
123 void SetCrossOrigin(const nsAString& aCrossOrigin, ErrorResult& aError) {
124 SetOrRemoveNullableStringAttr(nsGkAtoms::crossorigin, aCrossOrigin, aError);
126 void GetIntegrity(nsAString& aIntegrity) {
127 GetHTMLAttr(nsGkAtoms::integrity, aIntegrity);
129 void SetIntegrity(const nsAString& aIntegrity, ErrorResult& aRv) {
130 SetHTMLAttr(nsGkAtoms::integrity, aIntegrity, aRv);
132 void SetReferrerPolicy(const nsAString& aReferrerPolicy,
133 ErrorResult& aError) {
134 SetHTMLAttr(nsGkAtoms::referrerpolicy, aReferrerPolicy, aError);
136 void GetReferrerPolicy(nsAString& aReferrerPolicy) {
137 GetEnumAttr(nsGkAtoms::referrerpolicy, "", aReferrerPolicy);
140 nsDOMTokenList* Blocking();
141 bool IsPotentiallyRenderBlocking() override;
143 // Required for the webidl-binding because `GetFetchPriority` is overloaded.
144 using nsGenericHTMLElement::GetFetchPriority;
146 [[nodiscard]] static bool Supports(const GlobalObject& aGlobal,
147 const nsAString& aType);
149 protected:
150 virtual ~HTMLScriptElement();
152 virtual bool GetAsyncState() override { return Async(); }
154 virtual JSObject* WrapNode(JSContext* aCx,
155 JS::Handle<JSObject*> aGivenProto) override;
157 // nsIScriptElement
158 nsIContent* GetAsContent() override { return this; }
160 // ScriptElement
161 virtual bool HasScriptContent() override;
163 RefPtr<nsDOMTokenList> mBlocking;
166 } // namespace mozilla::dom
168 #endif // mozilla_dom_HTMLScriptElement_h