HTMLIFrameElement.h (8920B)
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/. */ 6 7 #ifndef mozilla_dom_HTMLIFrameElement_h 8 #define mozilla_dom_HTMLIFrameElement_h 9 10 #include "mozilla/Attributes.h" 11 #include "nsDOMTokenList.h" 12 #include "nsGenericHTMLElement.h" 13 #include "nsGenericHTMLFrameElement.h" 14 15 namespace mozilla::dom { 16 17 class OwningTrustedHTMLOrString; 18 class TrustedHTMLOrString; 19 20 class FeaturePolicy; 21 22 class HTMLIFrameElement final : public nsGenericHTMLFrameElement { 23 public: 24 explicit HTMLIFrameElement( 25 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, 26 FromParser aFromParser = NOT_FROM_PARSER); 27 28 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLIFrameElement, iframe) 29 30 // nsISupports 31 NS_DECL_ISUPPORTS_INHERITED 32 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLIFrameElement, 33 nsGenericHTMLFrameElement) 34 35 // Element 36 virtual bool IsInteractiveHTMLContent() const override { return true; } 37 38 // nsIContent 39 virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute, 40 const nsAString& aValue, 41 nsIPrincipal* aMaybeScriptedPrincipal, 42 nsAttrValue& aResult) override; 43 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override; 44 virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() 45 const override; 46 47 virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; 48 49 void NodeInfoChanged(Document* aOldDoc) override; 50 51 void BindToBrowsingContext(BrowsingContext* aBrowsingContext); 52 53 uint32_t GetSandboxFlags() const; 54 55 // Web IDL binding methods 56 void GetSrc(nsString& aSrc) const { 57 GetURIAttr(nsGkAtoms::src, nullptr, aSrc); 58 } 59 void SetSrc(const nsAString& aSrc, nsIPrincipal* aTriggeringPrincipal, 60 ErrorResult& aError) { 61 SetHTMLAttr(nsGkAtoms::src, aSrc, aTriggeringPrincipal, aError); 62 } 63 64 // @param aSrcdoc will always be of type `String`. 65 void GetSrcdoc(OwningTrustedHTMLOrString& aSrcdoc); 66 67 MOZ_CAN_RUN_SCRIPT void SetSrcdoc(const TrustedHTMLOrString& aSrcdoc, 68 nsIPrincipal* aSubjectPrincipal, 69 ErrorResult& aError); 70 71 void GetName(DOMString& aName) { GetHTMLAttr(nsGkAtoms::name, aName); } 72 void SetName(const nsAString& aName, ErrorResult& aError) { 73 SetHTMLAttr(nsGkAtoms::name, aName, aError); 74 } 75 nsDOMTokenList* Sandbox() { 76 if (!mSandbox) { 77 mSandbox = 78 new nsDOMTokenList(this, nsGkAtoms::sandbox, sSupportedSandboxTokens); 79 } 80 return mSandbox; 81 } 82 83 bool AllowFullscreen() const { 84 return GetBoolAttr(nsGkAtoms::allowfullscreen); 85 } 86 87 void SetAllowFullscreen(bool aAllow, ErrorResult& aError) { 88 SetHTMLBoolAttr(nsGkAtoms::allowfullscreen, aAllow, aError); 89 } 90 91 void GetWidth(DOMString& aWidth) { GetHTMLAttr(nsGkAtoms::width, aWidth); } 92 void SetWidth(const nsAString& aWidth, ErrorResult& aError) { 93 SetHTMLAttr(nsGkAtoms::width, aWidth, aError); 94 } 95 void GetHeight(DOMString& aHeight) { 96 GetHTMLAttr(nsGkAtoms::height, aHeight); 97 } 98 void SetHeight(const nsAString& aHeight, ErrorResult& aError) { 99 SetHTMLAttr(nsGkAtoms::height, aHeight, aError); 100 } 101 using nsGenericHTMLFrameElement::GetContentDocument; 102 using nsGenericHTMLFrameElement::GetContentWindow; 103 void GetAlign(DOMString& aAlign) { GetHTMLAttr(nsGkAtoms::align, aAlign); } 104 void SetAlign(const nsAString& aAlign, ErrorResult& aError) { 105 SetHTMLAttr(nsGkAtoms::align, aAlign, aError); 106 } 107 void GetAllow(DOMString& aAllow) { GetHTMLAttr(nsGkAtoms::allow, aAllow); } 108 void SetAllow(const nsAString& aAllow, ErrorResult& aError) { 109 SetHTMLAttr(nsGkAtoms::allow, aAllow, aError); 110 } 111 void GetScrolling(DOMString& aScrolling) { 112 GetHTMLAttr(nsGkAtoms::scrolling, aScrolling); 113 } 114 void SetScrolling(const nsAString& aScrolling, ErrorResult& aError) { 115 SetHTMLAttr(nsGkAtoms::scrolling, aScrolling, aError); 116 } 117 void GetFrameBorder(DOMString& aFrameBorder) { 118 GetHTMLAttr(nsGkAtoms::frameborder, aFrameBorder); 119 } 120 void SetFrameBorder(const nsAString& aFrameBorder, ErrorResult& aError) { 121 SetHTMLAttr(nsGkAtoms::frameborder, aFrameBorder, aError); 122 } 123 void GetLongDesc(nsAString& aLongDesc) const { 124 GetURIAttr(nsGkAtoms::longdesc, nullptr, aLongDesc); 125 } 126 void SetLongDesc(const nsAString& aLongDesc, ErrorResult& aError) { 127 SetHTMLAttr(nsGkAtoms::longdesc, aLongDesc, aError); 128 } 129 void GetMarginWidth(DOMString& aMarginWidth) { 130 GetHTMLAttr(nsGkAtoms::marginwidth, aMarginWidth); 131 } 132 void SetMarginWidth(const nsAString& aMarginWidth, ErrorResult& aError) { 133 SetHTMLAttr(nsGkAtoms::marginwidth, aMarginWidth, aError); 134 } 135 void GetMarginHeight(DOMString& aMarginHeight) { 136 GetHTMLAttr(nsGkAtoms::marginheight, aMarginHeight); 137 } 138 void SetMarginHeight(const nsAString& aMarginHeight, ErrorResult& aError) { 139 SetHTMLAttr(nsGkAtoms::marginheight, aMarginHeight, aError); 140 } 141 void SetReferrerPolicy(const nsAString& aReferrer, ErrorResult& aError) { 142 SetHTMLAttr(nsGkAtoms::referrerpolicy, aReferrer, aError); 143 } 144 void GetReferrerPolicy(nsAString& aReferrer) { 145 GetEnumAttr(nsGkAtoms::referrerpolicy, "", aReferrer); 146 } 147 Document* GetSVGDocument(nsIPrincipal& aSubjectPrincipal) { 148 return GetContentDocument(aSubjectPrincipal); 149 } 150 // nsGenericHTMLFrameElement::GetFrameLoader is fine 151 // nsGenericHTMLFrameElement::GetAppManifestURL is fine 152 153 // The fullscreen flag is set to true only when requestFullscreen is 154 // explicitly called on this <iframe> element. In case this flag is 155 // set, the fullscreen state of this element will not be reverted 156 // automatically when its subdocument exits fullscreen. 157 bool FullscreenFlag() const { return mFullscreenFlag; } 158 void SetFullscreenFlag(bool aValue) { mFullscreenFlag = aValue; } 159 160 mozilla::dom::FeaturePolicy* FeaturePolicy() const; 161 162 void SetLoading(const nsAString& aLoading, ErrorResult& aError) { 163 SetHTMLAttr(nsGkAtoms::loading, aLoading, aError); 164 } 165 166 void SetLazyLoading(); 167 void StopLazyLoading(); 168 void CancelLazyLoading(bool aClearLazyLoadState); 169 170 const LazyLoadFrameResumptionState& GetLazyLoadFrameResumptionState() const { 171 return mLazyLoadState; 172 } 173 174 protected: 175 virtual ~HTMLIFrameElement(); 176 177 virtual JSObject* WrapNode(JSContext* aCx, 178 JS::Handle<JSObject*> aGivenProto) override; 179 180 virtual void AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, 181 const nsAttrValue* aValue, 182 const nsAttrValue* aOldValue, 183 nsIPrincipal* aMaybeScriptedPrincipal, 184 bool aNotify) override; 185 virtual void OnAttrSetButNotChanged(int32_t aNamespaceID, nsAtom* aName, 186 const nsAttrValueOrString& aValue, 187 bool aNotify) override; 188 nsresult BindToTree(BindContext&, nsINode& aParent) override; 189 190 private: 191 static void MapAttributesIntoRule(MappedDeclarationsBuilder&); 192 193 static const DOMTokenListSupportedToken sSupportedSandboxTokens[]; 194 195 void RefreshFeaturePolicy(bool aParseAllowAttribute); 196 void RefreshEmbedderReferrerPolicy(ReferrerPolicy aPolicy); 197 198 // If this iframe has a 'srcdoc' attribute, the document's origin will be 199 // returned. Otherwise, if this iframe has a 'src' attribute, the origin will 200 // be the parsing of its value as URL. If the URL is invalid, or 'src' 201 // attribute doesn't exist, the origin will be the document's origin. 202 already_AddRefed<nsIPrincipal> GetFeaturePolicyDefaultOrigin() const; 203 204 /** 205 * This function is called by AfterSetAttr and OnAttrSetButNotChanged. 206 * This function will be called by AfterSetAttr whether the attribute is being 207 * set or unset. 208 * 209 * @param aNamespaceID the namespace of the attr being set 210 * @param aName the localname of the attribute being set 211 * @param aNotify Whether we plan to notify document observers. 212 */ 213 void AfterMaybeChangeAttr(int32_t aNamespaceID, nsAtom* aName, bool aNotify); 214 215 /** 216 * Feature policy inheritance is broken in cross process model, so we may 217 * have to store feature policy in browsingContext when neccesary. 218 */ 219 void MaybeStoreCrossOriginFeaturePolicy(); 220 221 RefPtr<dom::FeaturePolicy> mFeaturePolicy; 222 RefPtr<nsDOMTokenList> mSandbox; 223 224 /** 225 * Current lazy load resumption state (base URI and referrer policy). 226 * https://html.spec.whatwg.org/#lazy-load-resumption-steps 227 */ 228 LazyLoadFrameResumptionState mLazyLoadState; 229 230 // Update lazy load state internally 231 void UpdateLazyLoadState(); 232 }; 233 234 } // namespace mozilla::dom 235 236 #endif