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 namespace mozilla::dom
{
18 class HTMLScriptElement final
: public nsGenericHTMLElement
,
19 public ScriptElement
{
21 using Element::GetText
;
23 HTMLScriptElement(already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
,
24 FromParser aFromParser
);
27 NS_DECL_ISUPPORTS_INHERITED
29 void GetInnerHTML(nsAString
& aInnerHTML
, OOMReporter
& aError
) override
;
30 virtual void SetInnerHTML(const nsAString
& aInnerHTML
,
31 nsIPrincipal
* aSubjectPrincipal
,
32 mozilla::ErrorResult
& aError
) override
;
35 virtual void GetScriptText(nsAString
& text
) const override
;
36 virtual void GetScriptCharset(nsAString
& charset
) override
;
37 virtual void FreezeExecutionAttrs(const Document
* aOwnerDoc
) override
;
38 virtual CORSMode
GetCORSMode() const override
;
39 virtual FetchPriority
GetFetchPriority() const override
;
40 virtual mozilla::dom::ReferrerPolicy
GetReferrerPolicy() override
;
43 virtual nsresult
BindToTree(BindContext
&, nsINode
& aParent
) override
;
44 virtual bool ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
45 const nsAString
& aValue
,
46 nsIPrincipal
* aMaybeScriptedPrincipal
,
47 nsAttrValue
& aResult
) override
;
49 virtual nsresult
Clone(dom::NodeInfo
*, nsINode
** aResult
) const override
;
52 virtual void AfterSetAttr(int32_t aNamespaceID
, nsAtom
* aName
,
53 const nsAttrValue
* aValue
,
54 const nsAttrValue
* aOldValue
,
55 nsIPrincipal
* aMaybeScriptedPrincipal
,
56 bool aNotify
) override
;
59 void GetText(nsAString
& aValue
, ErrorResult
& aRv
) const;
61 void SetText(const nsAString
& aValue
, ErrorResult
& aRv
);
63 void GetCharset(nsAString
& aCharset
) {
64 GetHTMLAttr(nsGkAtoms::charset
, aCharset
);
66 void SetCharset(const nsAString
& aCharset
, ErrorResult
& aRv
) {
67 SetHTMLAttr(nsGkAtoms::charset
, aCharset
, aRv
);
70 bool Defer() { return GetBoolAttr(nsGkAtoms::defer
); }
71 void SetDefer(bool aDefer
, ErrorResult
& aRv
) {
72 SetHTMLBoolAttr(nsGkAtoms::defer
, aDefer
, aRv
);
75 void GetSrc(nsAString
& aSrc
) { GetURIAttr(nsGkAtoms::src
, nullptr, aSrc
); }
76 void SetSrc(const nsAString
& aSrc
, nsIPrincipal
* aTriggeringPrincipal
,
78 SetHTMLAttr(nsGkAtoms::src
, aSrc
, aTriggeringPrincipal
, aRv
);
81 void GetType(nsAString
& aType
) { GetHTMLAttr(nsGkAtoms::type
, aType
); }
82 void SetType(const nsAString
& aType
, ErrorResult
& aRv
) {
83 SetHTMLAttr(nsGkAtoms::type
, aType
, aRv
);
86 void GetHtmlFor(nsAString
& aHtmlFor
) {
87 GetHTMLAttr(nsGkAtoms::_for
, aHtmlFor
);
89 void SetHtmlFor(const nsAString
& aHtmlFor
, ErrorResult
& aRv
) {
90 SetHTMLAttr(nsGkAtoms::_for
, aHtmlFor
, aRv
);
93 void GetEvent(nsAString
& aEvent
) { GetHTMLAttr(nsGkAtoms::event
, aEvent
); }
94 void SetEvent(const nsAString
& aEvent
, ErrorResult
& aRv
) {
95 SetHTMLAttr(nsGkAtoms::event
, aEvent
, aRv
);
98 bool Async() { return mForceAsync
|| GetBoolAttr(nsGkAtoms::async
); }
100 void SetAsync(bool aValue
, ErrorResult
& aRv
) {
102 SetHTMLBoolAttr(nsGkAtoms::async
, aValue
, aRv
);
105 bool NoModule() { return GetBoolAttr(nsGkAtoms::nomodule
); }
107 void SetNoModule(bool aValue
, ErrorResult
& aRv
) {
108 SetHTMLBoolAttr(nsGkAtoms::nomodule
, aValue
, aRv
);
111 void GetCrossOrigin(nsAString
& aResult
) {
112 // Null for both missing and invalid defaults is ok, since we
113 // always parse to an enum value, so we don't need an invalid
114 // default, and we _want_ the missing default to be null.
115 GetEnumAttr(nsGkAtoms::crossorigin
, nullptr, aResult
);
117 void SetCrossOrigin(const nsAString
& aCrossOrigin
, ErrorResult
& aError
) {
118 SetOrRemoveNullableStringAttr(nsGkAtoms::crossorigin
, aCrossOrigin
, aError
);
120 void GetIntegrity(nsAString
& aIntegrity
) {
121 GetHTMLAttr(nsGkAtoms::integrity
, aIntegrity
);
123 void SetIntegrity(const nsAString
& aIntegrity
, ErrorResult
& aRv
) {
124 SetHTMLAttr(nsGkAtoms::integrity
, aIntegrity
, aRv
);
126 void SetReferrerPolicy(const nsAString
& aReferrerPolicy
,
127 ErrorResult
& aError
) {
128 SetHTMLAttr(nsGkAtoms::referrerpolicy
, aReferrerPolicy
, aError
);
130 void GetReferrerPolicy(nsAString
& aReferrerPolicy
) {
131 GetEnumAttr(nsGkAtoms::referrerpolicy
, "", aReferrerPolicy
);
134 // Required for the webidl-binding because `GetFetchPriority` is overloaded.
135 using nsGenericHTMLElement::GetFetchPriority
;
137 [[nodiscard
]] static bool Supports(const GlobalObject
& aGlobal
,
138 const nsAString
& aType
);
141 virtual ~HTMLScriptElement();
143 virtual bool GetAsyncState() override
{ return Async(); }
145 virtual JSObject
* WrapNode(JSContext
* aCx
,
146 JS::Handle
<JSObject
*> aGivenProto
) override
;
149 nsIContent
* GetAsContent() override
{ return this; }
152 virtual bool HasScriptContent() override
;
155 } // namespace mozilla::dom
157 #endif // mozilla_dom_HTMLScriptElement_h