Bug 1795723 - Unified extensions UI should support High Contrast Mode. r=ayeddi,deskt...
[gecko.git] / dom / html / HTMLScriptElement.h
blobfb678d77fea66a61b0829d922a63911bcfbdd01c
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 "nsGenericHTMLElement.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/dom/ScriptElement.h"
14 namespace mozilla::dom {
16 class HTMLScriptElement final : public nsGenericHTMLElement,
17 public ScriptElement {
18 public:
19 using Element::GetText;
21 HTMLScriptElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
22 FromParser aFromParser);
24 // nsISupports
25 NS_DECL_ISUPPORTS_INHERITED
27 void GetInnerHTML(nsAString& aInnerHTML, OOMReporter& aError) override;
28 virtual void SetInnerHTML(const nsAString& aInnerHTML,
29 nsIPrincipal* aSubjectPrincipal,
30 mozilla::ErrorResult& aError) override;
32 // nsIScriptElement
33 virtual bool GetScriptType(nsAString& type) override;
34 virtual void GetScriptText(nsAString& text) const override;
35 virtual void GetScriptCharset(nsAString& charset) override;
36 virtual void FreezeExecutionAttrs(Document* aOwnerDoc) override;
37 virtual CORSMode GetCORSMode() const override;
38 virtual mozilla::dom::ReferrerPolicy GetReferrerPolicy() override;
40 // nsIContent
41 virtual nsresult BindToTree(BindContext&, nsINode& aParent) override;
42 virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
43 const nsAString& aValue,
44 nsIPrincipal* aMaybeScriptedPrincipal,
45 nsAttrValue& aResult) override;
47 virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
49 // Element
50 virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
51 const nsAttrValue* aValue,
52 const nsAttrValue* aOldValue,
53 nsIPrincipal* aMaybeScriptedPrincipal,
54 bool aNotify) override;
56 // WebIDL
57 void GetText(nsAString& aValue, ErrorResult& aRv) const;
59 void SetText(const nsAString& aValue, ErrorResult& aRv);
61 void GetCharset(nsAString& aCharset) {
62 GetHTMLAttr(nsGkAtoms::charset, aCharset);
64 void SetCharset(const nsAString& aCharset, ErrorResult& aRv) {
65 SetHTMLAttr(nsGkAtoms::charset, aCharset, aRv);
68 bool Defer() { return GetBoolAttr(nsGkAtoms::defer); }
69 void SetDefer(bool aDefer, ErrorResult& aRv) {
70 SetHTMLBoolAttr(nsGkAtoms::defer, aDefer, aRv);
73 void GetSrc(nsAString& aSrc) { GetURIAttr(nsGkAtoms::src, nullptr, aSrc); }
74 void SetSrc(const nsAString& aSrc, nsIPrincipal* aTriggeringPrincipal,
75 ErrorResult& aRv) {
76 SetHTMLAttr(nsGkAtoms::src, aSrc, aTriggeringPrincipal, aRv);
79 void GetType(nsAString& aType) { GetHTMLAttr(nsGkAtoms::type, aType); }
80 void SetType(const nsAString& aType, ErrorResult& aRv) {
81 SetHTMLAttr(nsGkAtoms::type, aType, aRv);
84 void GetHtmlFor(nsAString& aHtmlFor) {
85 GetHTMLAttr(nsGkAtoms::_for, aHtmlFor);
87 void SetHtmlFor(const nsAString& aHtmlFor, ErrorResult& aRv) {
88 SetHTMLAttr(nsGkAtoms::_for, aHtmlFor, aRv);
91 void GetEvent(nsAString& aEvent) { GetHTMLAttr(nsGkAtoms::event, aEvent); }
92 void SetEvent(const nsAString& aEvent, ErrorResult& aRv) {
93 SetHTMLAttr(nsGkAtoms::event, aEvent, aRv);
96 bool Async() { return mForceAsync || GetBoolAttr(nsGkAtoms::async); }
98 void SetAsync(bool aValue, ErrorResult& aRv) {
99 mForceAsync = false;
100 SetHTMLBoolAttr(nsGkAtoms::async, aValue, aRv);
103 bool NoModule() { return GetBoolAttr(nsGkAtoms::nomodule); }
105 void SetNoModule(bool aValue, ErrorResult& aRv) {
106 SetHTMLBoolAttr(nsGkAtoms::nomodule, aValue, aRv);
109 void GetCrossOrigin(nsAString& aResult) {
110 // Null for both missing and invalid defaults is ok, since we
111 // always parse to an enum value, so we don't need an invalid
112 // default, and we _want_ the missing default to be null.
113 GetEnumAttr(nsGkAtoms::crossorigin, nullptr, aResult);
115 void SetCrossOrigin(const nsAString& aCrossOrigin, ErrorResult& aError) {
116 SetOrRemoveNullableStringAttr(nsGkAtoms::crossorigin, aCrossOrigin, aError);
118 void GetIntegrity(nsAString& aIntegrity) {
119 GetHTMLAttr(nsGkAtoms::integrity, aIntegrity);
121 void SetIntegrity(const nsAString& aIntegrity, ErrorResult& aRv) {
122 SetHTMLAttr(nsGkAtoms::integrity, aIntegrity, aRv);
124 void SetReferrerPolicy(const nsAString& aReferrerPolicy,
125 ErrorResult& aError) {
126 SetHTMLAttr(nsGkAtoms::referrerpolicy, aReferrerPolicy, aError);
128 void GetReferrerPolicy(nsAString& aReferrerPolicy) {
129 GetEnumAttr(nsGkAtoms::referrerpolicy, "", aReferrerPolicy);
132 [[nodiscard]] static bool Supports(const GlobalObject& aGlobal,
133 const nsAString& aType);
135 protected:
136 virtual ~HTMLScriptElement();
138 virtual bool GetAsyncState() override { return Async(); }
140 virtual JSObject* WrapNode(JSContext* aCx,
141 JS::Handle<JSObject*> aGivenProto) override;
143 // ScriptElement
144 virtual bool HasScriptContent() override;
147 } // namespace mozilla::dom
149 #endif // mozilla_dom_HTMLScriptElement_h