Bug 1655413 [wpt PR 24763] - Make CSP default-src without 'unsafe-eval' block eval...
[gecko.git] / dom / html / HTMLIFrameElement.h
blob049381f953dde7b53febba4dc29f6ae3b242cb7a
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 "nsGenericHTMLFrameElement.h"
12 #include "nsDOMTokenList.h"
14 namespace mozilla {
15 namespace dom {
17 class HTMLIFrameElement final : public nsGenericHTMLFrameElement {
18 public:
19 explicit HTMLIFrameElement(
20 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
21 FromParser aFromParser = NOT_FROM_PARSER);
23 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLIFrameElement, iframe)
25 // nsISupports
26 NS_DECL_ISUPPORTS_INHERITED
27 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLIFrameElement,
28 nsGenericHTMLFrameElement)
30 // Element
31 virtual bool IsInteractiveHTMLContent() const override { return true; }
33 // nsIContent
34 virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
35 const nsAString& aValue,
36 nsIPrincipal* aMaybeScriptedPrincipal,
37 nsAttrValue& aResult) override;
38 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
39 virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction()
40 const override;
42 virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
44 void BindToBrowsingContext(BrowsingContext* aBrowsingContext);
46 uint32_t GetSandboxFlags() const;
48 // Web IDL binding methods
49 void GetSrc(nsString& aSrc) const {
50 GetURIAttr(nsGkAtoms::src, nullptr, aSrc);
52 void SetSrc(const nsAString& aSrc, nsIPrincipal* aTriggeringPrincipal,
53 ErrorResult& aError) {
54 SetHTMLAttr(nsGkAtoms::src, aSrc, aTriggeringPrincipal, aError);
56 void GetSrcdoc(DOMString& aSrcdoc) {
57 GetHTMLAttr(nsGkAtoms::srcdoc, aSrcdoc);
59 void SetSrcdoc(const nsAString& aSrcdoc, ErrorResult& aError) {
60 SetHTMLAttr(nsGkAtoms::srcdoc, aSrcdoc, aError);
62 void GetName(DOMString& aName) { GetHTMLAttr(nsGkAtoms::name, aName); }
63 void SetName(const nsAString& aName, ErrorResult& aError) {
64 SetHTMLAttr(nsGkAtoms::name, aName, aError);
66 nsDOMTokenList* Sandbox() {
67 if (!mSandbox) {
68 mSandbox =
69 new nsDOMTokenList(this, nsGkAtoms::sandbox, sSupportedSandboxTokens);
71 return mSandbox;
74 bool AllowFullscreenForBindings() const {
75 return GetBoolAttr(nsGkAtoms::allowfullscreen);
78 void SetAllowFullscreenForBindings(bool aAllow, ErrorResult& aError) {
79 SetHTMLBoolAttr(nsGkAtoms::allowfullscreen, aAllow, aError);
82 bool AllowFullscreen() const;
84 bool HasAllowFullscreenAttribute() const;
86 bool AllowPaymentRequest() const {
87 return GetBoolAttr(nsGkAtoms::allowpaymentrequest);
89 void SetAllowPaymentRequest(bool aAllow, ErrorResult& aError) {
90 SetHTMLBoolAttr(nsGkAtoms::allowpaymentrequest, aAllow, aError);
92 void GetWidth(DOMString& aWidth) { GetHTMLAttr(nsGkAtoms::width, aWidth); }
93 void SetWidth(const nsAString& aWidth, ErrorResult& aError) {
94 SetHTMLAttr(nsGkAtoms::width, aWidth, aError);
96 void GetHeight(DOMString& aHeight) {
97 GetHTMLAttr(nsGkAtoms::height, aHeight);
99 void SetHeight(const nsAString& aHeight, ErrorResult& aError) {
100 SetHTMLAttr(nsGkAtoms::height, aHeight, aError);
102 using nsGenericHTMLFrameElement::GetContentDocument;
103 using nsGenericHTMLFrameElement::GetContentWindow;
104 void GetAlign(DOMString& aAlign) { GetHTMLAttr(nsGkAtoms::align, aAlign); }
105 void SetAlign(const nsAString& aAlign, ErrorResult& aError) {
106 SetHTMLAttr(nsGkAtoms::align, aAlign, aError);
108 void GetAllow(DOMString& aAllow) { GetHTMLAttr(nsGkAtoms::allow, aAllow); }
109 void SetAllow(const nsAString& aAllow, ErrorResult& aError) {
110 SetHTMLAttr(nsGkAtoms::allow, aAllow, aError);
112 void GetScrolling(DOMString& aScrolling) {
113 GetHTMLAttr(nsGkAtoms::scrolling, aScrolling);
115 void SetScrolling(const nsAString& aScrolling, ErrorResult& aError) {
116 SetHTMLAttr(nsGkAtoms::scrolling, aScrolling, aError);
118 void GetFrameBorder(DOMString& aFrameBorder) {
119 GetHTMLAttr(nsGkAtoms::frameborder, aFrameBorder);
121 void SetFrameBorder(const nsAString& aFrameBorder, ErrorResult& aError) {
122 SetHTMLAttr(nsGkAtoms::frameborder, aFrameBorder, aError);
124 void GetLongDesc(nsAString& aLongDesc) const {
125 GetURIAttr(nsGkAtoms::longdesc, nullptr, aLongDesc);
127 void SetLongDesc(const nsAString& aLongDesc, ErrorResult& aError) {
128 SetHTMLAttr(nsGkAtoms::longdesc, aLongDesc, aError);
130 void GetMarginWidth(DOMString& aMarginWidth) {
131 GetHTMLAttr(nsGkAtoms::marginwidth, aMarginWidth);
133 void SetMarginWidth(const nsAString& aMarginWidth, ErrorResult& aError) {
134 SetHTMLAttr(nsGkAtoms::marginwidth, aMarginWidth, aError);
136 void GetMarginHeight(DOMString& aMarginHeight) {
137 GetHTMLAttr(nsGkAtoms::marginheight, aMarginHeight);
139 void SetMarginHeight(const nsAString& aMarginHeight, ErrorResult& aError) {
140 SetHTMLAttr(nsGkAtoms::marginheight, aMarginHeight, aError);
142 void SetReferrerPolicy(const nsAString& aReferrer, ErrorResult& aError) {
143 SetHTMLAttr(nsGkAtoms::referrerpolicy, aReferrer, aError);
145 void GetReferrerPolicy(nsAString& aReferrer) {
146 GetEnumAttr(nsGkAtoms::referrerpolicy, EmptyCString().get(), aReferrer);
148 Document* GetSVGDocument(nsIPrincipal& aSubjectPrincipal) {
149 return GetContentDocument(aSubjectPrincipal);
151 bool Mozbrowser() const { return GetBoolAttr(nsGkAtoms::mozbrowser); }
152 void SetMozbrowser(bool aAllow, ErrorResult& aError) {
153 SetHTMLBoolAttr(nsGkAtoms::mozbrowser, aAllow, aError);
155 using nsGenericHTMLFrameElement::SetMozbrowser;
156 // nsGenericHTMLFrameElement::GetFrameLoader is fine
157 // nsGenericHTMLFrameElement::GetAppManifestURL is fine
159 // The fullscreen flag is set to true only when requestFullscreen is
160 // explicitly called on this <iframe> element. In case this flag is
161 // set, the fullscreen state of this element will not be reverted
162 // automatically when its subdocument exits fullscreen.
163 bool FullscreenFlag() const { return mFullscreenFlag; }
164 void SetFullscreenFlag(bool aValue) { mFullscreenFlag = aValue; }
166 mozilla::dom::FeaturePolicy* FeaturePolicy() const;
168 protected:
169 virtual ~HTMLIFrameElement();
171 virtual JSObject* WrapNode(JSContext* aCx,
172 JS::Handle<JSObject*> aGivenProto) override;
174 virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
175 const nsAttrValue* aValue,
176 const nsAttrValue* aOldValue,
177 nsIPrincipal* aMaybeScriptedPrincipal,
178 bool aNotify) override;
179 virtual nsresult OnAttrSetButNotChanged(int32_t aNamespaceID, nsAtom* aName,
180 const nsAttrValueOrString& aValue,
181 bool aNotify) override;
183 private:
184 static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
185 MappedDeclarations&);
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
200 * set or unset.
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 } // namespace dom
219 } // namespace mozilla
221 #endif