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_HTMLIFrameElement_h
8 #define mozilla_dom_HTMLIFrameElement_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/FeaturePolicy.h"
12 #include "nsGenericHTMLFrameElement.h"
13 #include "nsDOMTokenList.h"
18 class HTMLIFrameElement final
: public nsGenericHTMLFrameElement
{
20 explicit HTMLIFrameElement(
21 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
,
22 FromParser aFromParser
= NOT_FROM_PARSER
);
24 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLIFrameElement
, iframe
)
27 NS_DECL_ISUPPORTS_INHERITED
28 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLIFrameElement
,
29 nsGenericHTMLFrameElement
)
32 virtual bool IsInteractiveHTMLContent(bool aIgnoreTabindex
) const override
{
37 virtual nsresult
BindToTree(BindContext
&, nsINode
& aParent
) override
;
38 virtual bool ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
39 const nsAString
& aValue
,
40 nsIPrincipal
* aMaybeScriptedPrincipal
,
41 nsAttrValue
& aResult
) override
;
42 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom
* aAttribute
) const override
;
43 virtual nsMapRuleToAttributesFunc
GetAttributeMappingFunction()
46 virtual nsresult
Clone(dom::NodeInfo
*, nsINode
** aResult
) const override
;
48 uint32_t GetSandboxFlags() const;
50 // Web IDL binding methods
51 void GetSrc(nsString
& aSrc
) const {
52 GetURIAttr(nsGkAtoms::src
, nullptr, aSrc
);
54 void SetSrc(const nsAString
& aSrc
, nsIPrincipal
* aTriggeringPrincipal
,
55 ErrorResult
& aError
) {
56 SetHTMLAttr(nsGkAtoms::src
, aSrc
, aTriggeringPrincipal
, aError
);
58 void GetSrcdoc(DOMString
& aSrcdoc
) {
59 GetHTMLAttr(nsGkAtoms::srcdoc
, aSrcdoc
);
61 void SetSrcdoc(const nsAString
& aSrcdoc
, ErrorResult
& aError
) {
62 SetHTMLAttr(nsGkAtoms::srcdoc
, aSrcdoc
, aError
);
64 void GetName(DOMString
& aName
) { GetHTMLAttr(nsGkAtoms::name
, aName
); }
65 void SetName(const nsAString
& aName
, ErrorResult
& aError
) {
66 SetHTMLAttr(nsGkAtoms::name
, aName
, aError
);
68 nsDOMTokenList
* Sandbox() {
69 return GetTokenList(nsGkAtoms::sandbox
, sSupportedSandboxTokens
);
71 bool AllowFullscreen() const {
72 return GetBoolAttr(nsGkAtoms::allowfullscreen
);
74 void SetAllowFullscreen(bool aAllow
, ErrorResult
& aError
) {
75 SetHTMLBoolAttr(nsGkAtoms::allowfullscreen
, aAllow
, aError
);
77 bool AllowPaymentRequest() const {
78 return GetBoolAttr(nsGkAtoms::allowpaymentrequest
);
80 void SetAllowPaymentRequest(bool aAllow
, ErrorResult
& aError
) {
81 SetHTMLBoolAttr(nsGkAtoms::allowpaymentrequest
, aAllow
, aError
);
83 void GetWidth(DOMString
& aWidth
) { GetHTMLAttr(nsGkAtoms::width
, aWidth
); }
84 void SetWidth(const nsAString
& aWidth
, ErrorResult
& aError
) {
85 SetHTMLAttr(nsGkAtoms::width
, aWidth
, aError
);
87 void GetHeight(DOMString
& aHeight
) {
88 GetHTMLAttr(nsGkAtoms::height
, aHeight
);
90 void SetHeight(const nsAString
& aHeight
, ErrorResult
& aError
) {
91 SetHTMLAttr(nsGkAtoms::height
, aHeight
, aError
);
93 using nsGenericHTMLFrameElement::GetContentDocument
;
94 using nsGenericHTMLFrameElement::GetContentWindow
;
95 void GetAlign(DOMString
& aAlign
) { GetHTMLAttr(nsGkAtoms::align
, aAlign
); }
96 void SetAlign(const nsAString
& aAlign
, ErrorResult
& aError
) {
97 SetHTMLAttr(nsGkAtoms::align
, aAlign
, aError
);
99 void GetAllow(DOMString
& aAllow
) { GetHTMLAttr(nsGkAtoms::allow
, aAllow
); }
100 void SetAllow(const nsAString
& aAllow
, ErrorResult
& aError
) {
101 SetHTMLAttr(nsGkAtoms::allow
, aAllow
, aError
);
103 void GetScrolling(DOMString
& aScrolling
) {
104 GetHTMLAttr(nsGkAtoms::scrolling
, aScrolling
);
106 void SetScrolling(const nsAString
& aScrolling
, ErrorResult
& aError
) {
107 SetHTMLAttr(nsGkAtoms::scrolling
, aScrolling
, aError
);
109 void GetFrameBorder(DOMString
& aFrameBorder
) {
110 GetHTMLAttr(nsGkAtoms::frameborder
, aFrameBorder
);
112 void SetFrameBorder(const nsAString
& aFrameBorder
, ErrorResult
& aError
) {
113 SetHTMLAttr(nsGkAtoms::frameborder
, aFrameBorder
, aError
);
115 void GetLongDesc(nsAString
& aLongDesc
) const {
116 GetURIAttr(nsGkAtoms::longdesc
, nullptr, aLongDesc
);
118 void SetLongDesc(const nsAString
& aLongDesc
, ErrorResult
& aError
) {
119 SetHTMLAttr(nsGkAtoms::longdesc
, aLongDesc
, aError
);
121 void GetMarginWidth(DOMString
& aMarginWidth
) {
122 GetHTMLAttr(nsGkAtoms::marginwidth
, aMarginWidth
);
124 void SetMarginWidth(const nsAString
& aMarginWidth
, ErrorResult
& aError
) {
125 SetHTMLAttr(nsGkAtoms::marginwidth
, aMarginWidth
, aError
);
127 void GetMarginHeight(DOMString
& aMarginHeight
) {
128 GetHTMLAttr(nsGkAtoms::marginheight
, aMarginHeight
);
130 void SetMarginHeight(const nsAString
& aMarginHeight
, ErrorResult
& aError
) {
131 SetHTMLAttr(nsGkAtoms::marginheight
, aMarginHeight
, aError
);
133 void SetReferrerPolicy(const nsAString
& aReferrer
, ErrorResult
& aError
) {
134 SetHTMLAttr(nsGkAtoms::referrerpolicy
, aReferrer
, aError
);
136 void GetReferrerPolicy(nsAString
& aReferrer
) {
137 GetEnumAttr(nsGkAtoms::referrerpolicy
, EmptyCString().get(), aReferrer
);
139 Document
* GetSVGDocument(nsIPrincipal
& aSubjectPrincipal
) {
140 return GetContentDocument(aSubjectPrincipal
);
142 bool Mozbrowser() const { return GetBoolAttr(nsGkAtoms::mozbrowser
); }
143 void SetMozbrowser(bool aAllow
, ErrorResult
& aError
) {
144 SetHTMLBoolAttr(nsGkAtoms::mozbrowser
, aAllow
, aError
);
146 using nsGenericHTMLFrameElement::SetMozbrowser
;
147 // nsGenericHTMLFrameElement::GetFrameLoader is fine
148 // nsGenericHTMLFrameElement::GetAppManifestURL is fine
150 // The fullscreen flag is set to true only when requestFullscreen is
151 // explicitly called on this <iframe> element. In case this flag is
152 // set, the fullscreen state of this element will not be reverted
153 // automatically when its subdocument exits fullscreen.
154 bool FullscreenFlag() const { return mFullscreenFlag
; }
155 void SetFullscreenFlag(bool aValue
) { mFullscreenFlag
= aValue
; }
157 mozilla::dom::FeaturePolicy
* FeaturePolicy() const;
160 virtual ~HTMLIFrameElement();
162 virtual JSObject
* WrapNode(JSContext
* aCx
,
163 JS::Handle
<JSObject
*> aGivenProto
) override
;
165 virtual nsresult
AfterSetAttr(int32_t aNameSpaceID
, nsAtom
* aName
,
166 const nsAttrValue
* aValue
,
167 const nsAttrValue
* aOldValue
,
168 nsIPrincipal
* aMaybeScriptedPrincipal
,
169 bool aNotify
) override
;
170 virtual nsresult
OnAttrSetButNotChanged(int32_t aNamespaceID
, nsAtom
* aName
,
171 const nsAttrValueOrString
& aValue
,
172 bool aNotify
) override
;
175 static void MapAttributesIntoRule(const nsMappedAttributes
* aAttributes
,
176 MappedDeclarations
&);
178 static const DOMTokenListSupportedToken sSupportedSandboxTokens
[];
180 void RefreshFeaturePolicy(bool aParseAllowAttribute
);
182 // If this iframe has a 'srcdoc' attribute, the document's origin will be
183 // returned. Otherwise, if this iframe has a 'src' attribute, the origin will
184 // be the parsing of its value as URL. If the URL is invalid, or 'src'
185 // attribute doesn't exist, the origin will be the document's origin.
186 already_AddRefed
<nsIPrincipal
> GetFeaturePolicyDefaultOrigin() const;
189 * This function is called by AfterSetAttr and OnAttrSetButNotChanged.
190 * This function will be called by AfterSetAttr whether the attribute is being
193 * @param aNamespaceID the namespace of the attr being set
194 * @param aName the localname of the attribute being set
195 * @param aNotify Whether we plan to notify document observers.
197 void AfterMaybeChangeAttr(int32_t aNamespaceID
, nsAtom
* aName
, bool aNotify
);
199 RefPtr
<mozilla::dom::FeaturePolicy
> mFeaturePolicy
;
203 } // namespace mozilla