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 "nsGenericHTMLElement.h"
12 #include "nsGenericHTMLFrameElement.h"
13 #include "nsDOMTokenList.h"
15 namespace mozilla::dom
{
19 class HTMLIFrameElement final
: public nsGenericHTMLFrameElement
{
21 explicit HTMLIFrameElement(
22 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
,
23 FromParser aFromParser
= NOT_FROM_PARSER
);
25 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLIFrameElement
, iframe
)
28 NS_DECL_ISUPPORTS_INHERITED
29 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLIFrameElement
,
30 nsGenericHTMLFrameElement
)
33 virtual bool IsInteractiveHTMLContent() const override
{ return true; }
36 virtual bool ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
37 const nsAString
& aValue
,
38 nsIPrincipal
* aMaybeScriptedPrincipal
,
39 nsAttrValue
& aResult
) override
;
40 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom
* aAttribute
) const override
;
41 virtual nsMapRuleToAttributesFunc
GetAttributeMappingFunction()
44 virtual nsresult
Clone(dom::NodeInfo
*, nsINode
** aResult
) const override
;
46 void NodeInfoChanged(Document
* aOldDoc
) override
;
48 void BindToBrowsingContext(BrowsingContext
* aBrowsingContext
);
50 uint32_t GetSandboxFlags() const;
52 // Web IDL binding methods
53 void GetSrc(nsString
& aSrc
) const {
54 GetURIAttr(nsGkAtoms::src
, nullptr, aSrc
);
56 void SetSrc(const nsAString
& aSrc
, nsIPrincipal
* aTriggeringPrincipal
,
57 ErrorResult
& aError
) {
58 SetHTMLAttr(nsGkAtoms::src
, aSrc
, aTriggeringPrincipal
, aError
);
60 void GetSrcdoc(DOMString
& aSrcdoc
) {
61 GetHTMLAttr(nsGkAtoms::srcdoc
, aSrcdoc
);
63 void SetSrcdoc(const nsAString
& aSrcdoc
, ErrorResult
& aError
) {
64 SetHTMLAttr(nsGkAtoms::srcdoc
, aSrcdoc
, aError
);
66 void GetName(DOMString
& aName
) { GetHTMLAttr(nsGkAtoms::name
, aName
); }
67 void SetName(const nsAString
& aName
, ErrorResult
& aError
) {
68 SetHTMLAttr(nsGkAtoms::name
, aName
, aError
);
70 nsDOMTokenList
* Sandbox() {
73 new nsDOMTokenList(this, nsGkAtoms::sandbox
, sSupportedSandboxTokens
);
78 bool AllowFullscreen() const {
79 return GetBoolAttr(nsGkAtoms::allowfullscreen
);
82 void SetAllowFullscreen(bool aAllow
, ErrorResult
& aError
) {
83 SetHTMLBoolAttr(nsGkAtoms::allowfullscreen
, aAllow
, aError
);
86 void GetWidth(DOMString
& aWidth
) { GetHTMLAttr(nsGkAtoms::width
, aWidth
); }
87 void SetWidth(const nsAString
& aWidth
, ErrorResult
& aError
) {
88 SetHTMLAttr(nsGkAtoms::width
, aWidth
, aError
);
90 void GetHeight(DOMString
& aHeight
) {
91 GetHTMLAttr(nsGkAtoms::height
, aHeight
);
93 void SetHeight(const nsAString
& aHeight
, ErrorResult
& aError
) {
94 SetHTMLAttr(nsGkAtoms::height
, aHeight
, aError
);
96 using nsGenericHTMLFrameElement::GetContentDocument
;
97 using nsGenericHTMLFrameElement::GetContentWindow
;
98 void GetAlign(DOMString
& aAlign
) { GetHTMLAttr(nsGkAtoms::align
, aAlign
); }
99 void SetAlign(const nsAString
& aAlign
, ErrorResult
& aError
) {
100 SetHTMLAttr(nsGkAtoms::align
, aAlign
, aError
);
102 void GetAllow(DOMString
& aAllow
) { GetHTMLAttr(nsGkAtoms::allow
, aAllow
); }
103 void SetAllow(const nsAString
& aAllow
, ErrorResult
& aError
) {
104 SetHTMLAttr(nsGkAtoms::allow
, aAllow
, aError
);
106 void GetScrolling(DOMString
& aScrolling
) {
107 GetHTMLAttr(nsGkAtoms::scrolling
, aScrolling
);
109 void SetScrolling(const nsAString
& aScrolling
, ErrorResult
& aError
) {
110 SetHTMLAttr(nsGkAtoms::scrolling
, aScrolling
, aError
);
112 void GetFrameBorder(DOMString
& aFrameBorder
) {
113 GetHTMLAttr(nsGkAtoms::frameborder
, aFrameBorder
);
115 void SetFrameBorder(const nsAString
& aFrameBorder
, ErrorResult
& aError
) {
116 SetHTMLAttr(nsGkAtoms::frameborder
, aFrameBorder
, aError
);
118 void GetLongDesc(nsAString
& aLongDesc
) const {
119 GetURIAttr(nsGkAtoms::longdesc
, nullptr, aLongDesc
);
121 void SetLongDesc(const nsAString
& aLongDesc
, ErrorResult
& aError
) {
122 SetHTMLAttr(nsGkAtoms::longdesc
, aLongDesc
, aError
);
124 void GetMarginWidth(DOMString
& aMarginWidth
) {
125 GetHTMLAttr(nsGkAtoms::marginwidth
, aMarginWidth
);
127 void SetMarginWidth(const nsAString
& aMarginWidth
, ErrorResult
& aError
) {
128 SetHTMLAttr(nsGkAtoms::marginwidth
, aMarginWidth
, aError
);
130 void GetMarginHeight(DOMString
& aMarginHeight
) {
131 GetHTMLAttr(nsGkAtoms::marginheight
, aMarginHeight
);
133 void SetMarginHeight(const nsAString
& aMarginHeight
, ErrorResult
& aError
) {
134 SetHTMLAttr(nsGkAtoms::marginheight
, aMarginHeight
, aError
);
136 void SetReferrerPolicy(const nsAString
& aReferrer
, ErrorResult
& aError
) {
137 SetHTMLAttr(nsGkAtoms::referrerpolicy
, aReferrer
, aError
);
139 void GetReferrerPolicy(nsAString
& aReferrer
) {
140 GetEnumAttr(nsGkAtoms::referrerpolicy
, "", aReferrer
);
142 Document
* GetSVGDocument(nsIPrincipal
& aSubjectPrincipal
) {
143 return GetContentDocument(aSubjectPrincipal
);
145 // nsGenericHTMLFrameElement::GetFrameLoader is fine
146 // nsGenericHTMLFrameElement::GetAppManifestURL is fine
148 // The fullscreen flag is set to true only when requestFullscreen is
149 // explicitly called on this <iframe> element. In case this flag is
150 // set, the fullscreen state of this element will not be reverted
151 // automatically when its subdocument exits fullscreen.
152 bool FullscreenFlag() const { return mFullscreenFlag
; }
153 void SetFullscreenFlag(bool aValue
) { mFullscreenFlag
= aValue
; }
155 mozilla::dom::FeaturePolicy
* FeaturePolicy() const;
157 void SetLoading(const nsAString
& aLoading
, ErrorResult
& aError
) {
158 SetHTMLAttr(nsGkAtoms::loading
, aLoading
, aError
);
161 void SetLazyLoading();
162 void StopLazyLoading();
164 const LazyLoadFrameResumptionState
& GetLazyLoadFrameResumptionState() const {
165 return mLazyLoadState
;
169 virtual ~HTMLIFrameElement();
171 virtual JSObject
* WrapNode(JSContext
* aCx
,
172 JS::Handle
<JSObject
*> aGivenProto
) override
;
174 virtual void AfterSetAttr(int32_t aNameSpaceID
, nsAtom
* aName
,
175 const nsAttrValue
* aValue
,
176 const nsAttrValue
* aOldValue
,
177 nsIPrincipal
* aMaybeScriptedPrincipal
,
178 bool aNotify
) override
;
179 virtual void OnAttrSetButNotChanged(int32_t aNamespaceID
, nsAtom
* aName
,
180 const nsAttrValueOrString
& aValue
,
181 bool aNotify
) override
;
182 nsresult
BindToTree(BindContext
&, nsINode
& aParent
) override
;
185 static void MapAttributesIntoRule(MappedDeclarationsBuilder
&);
187 static const DOMTokenListSupportedToken sSupportedSandboxTokens
[];
189 void RefreshFeaturePolicy(bool aParseAllowAttribute
);
191 // If this iframe has a 'srcdoc' attribute, the document's origin will be
192 // returned. Otherwise, if this iframe has a 'src' attribute, the origin will
193 // be the parsing of its value as URL. If the URL is invalid, or 'src'
194 // attribute doesn't exist, the origin will be the document's origin.
195 already_AddRefed
<nsIPrincipal
> GetFeaturePolicyDefaultOrigin() const;
198 * This function is called by AfterSetAttr and OnAttrSetButNotChanged.
199 * This function will be called by AfterSetAttr whether the attribute is being
202 * @param aNamespaceID the namespace of the attr being set
203 * @param aName the localname of the attribute being set
204 * @param aNotify Whether we plan to notify document observers.
206 void AfterMaybeChangeAttr(int32_t aNamespaceID
, nsAtom
* aName
, bool aNotify
);
209 * Feature policy inheritance is broken in cross process model, so we may
210 * have to store feature policy in browsingContext when neccesary.
212 void MaybeStoreCrossOriginFeaturePolicy();
214 RefPtr
<dom::FeaturePolicy
> mFeaturePolicy
;
215 RefPtr
<nsDOMTokenList
> mSandbox
;
218 * Current lazy load resumption state (base URI and referrer policy).
219 * https://html.spec.whatwg.org/#lazy-load-resumption-steps
221 LazyLoadFrameResumptionState mLazyLoadState
;
223 // Update lazy load state internally
224 void UpdateLazyLoadState();
227 } // namespace mozilla::dom