HTMLIFrameElement.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_HTMLIFrameElement_h
  6. #define mozilla_dom_HTMLIFrameElement_h
  7. #include "mozilla/Attributes.h"
  8. #include "nsGenericHTMLFrameElement.h"
  9. #include "nsIDOMHTMLIFrameElement.h"
  10. #include "nsDOMTokenList.h"
  11. namespace mozilla {
  12. namespace dom {
  13. class HTMLIFrameElement final : public nsGenericHTMLFrameElement
  14. , public nsIDOMHTMLIFrameElement
  15. {
  16. public:
  17. explicit HTMLIFrameElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
  18. FromParser aFromParser = NOT_FROM_PARSER);
  19. NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLIFrameElement, iframe)
  20. // nsISupports
  21. NS_DECL_ISUPPORTS_INHERITED
  22. // Element
  23. virtual bool IsInteractiveHTMLContent(bool aIgnoreTabindex) const override
  24. {
  25. return true;
  26. }
  27. // nsIDOMHTMLIFrameElement
  28. NS_DECL_NSIDOMHTMLIFRAMEELEMENT
  29. // nsIContent
  30. virtual bool ParseAttribute(int32_t aNamespaceID,
  31. nsIAtom* aAttribute,
  32. const nsAString& aValue,
  33. nsAttrValue& aResult) override;
  34. NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const override;
  35. virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override;
  36. virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override;
  37. uint32_t GetSandboxFlags();
  38. // Web IDL binding methods
  39. // The XPCOM GetSrc is fine for our purposes
  40. void SetSrc(const nsAString& aSrc, ErrorResult& aError)
  41. {
  42. SetHTMLAttr(nsGkAtoms::src, aSrc, aError);
  43. }
  44. void GetSrcdoc(DOMString& aSrcdoc)
  45. {
  46. GetHTMLAttr(nsGkAtoms::srcdoc, aSrcdoc);
  47. }
  48. void SetSrcdoc(const nsAString& aSrcdoc, ErrorResult& aError)
  49. {
  50. SetHTMLAttr(nsGkAtoms::srcdoc, aSrcdoc, aError);
  51. }
  52. void GetName(DOMString& aName)
  53. {
  54. GetHTMLAttr(nsGkAtoms::name, aName);
  55. }
  56. void SetName(const nsAString& aName, ErrorResult& aError)
  57. {
  58. SetHTMLAttr(nsGkAtoms::name, aName, aError);
  59. }
  60. nsDOMTokenList* Sandbox()
  61. {
  62. return GetTokenList(nsGkAtoms::sandbox, sSupportedSandboxTokens);
  63. }
  64. bool AllowFullscreen() const
  65. {
  66. return GetBoolAttr(nsGkAtoms::allowfullscreen);
  67. }
  68. void SetAllowFullscreen(bool aAllow, ErrorResult& aError)
  69. {
  70. SetHTMLBoolAttr(nsGkAtoms::allowfullscreen, aAllow, aError);
  71. }
  72. void GetWidth(DOMString& aWidth)
  73. {
  74. GetHTMLAttr(nsGkAtoms::width, aWidth);
  75. }
  76. void SetWidth(const nsAString& aWidth, ErrorResult& aError)
  77. {
  78. SetHTMLAttr(nsGkAtoms::width, aWidth, aError);
  79. }
  80. void GetHeight(DOMString& aHeight)
  81. {
  82. GetHTMLAttr(nsGkAtoms::height, aHeight);
  83. }
  84. void SetHeight(const nsAString& aHeight, ErrorResult& aError)
  85. {
  86. SetHTMLAttr(nsGkAtoms::height, aHeight, aError);
  87. }
  88. using nsGenericHTMLFrameElement::GetContentDocument;
  89. using nsGenericHTMLFrameElement::GetContentWindow;
  90. void GetAlign(DOMString& aAlign)
  91. {
  92. GetHTMLAttr(nsGkAtoms::align, aAlign);
  93. }
  94. void SetAlign(const nsAString& aAlign, ErrorResult& aError)
  95. {
  96. SetHTMLAttr(nsGkAtoms::align, aAlign, aError);
  97. }
  98. void GetScrolling(DOMString& aScrolling)
  99. {
  100. GetHTMLAttr(nsGkAtoms::scrolling, aScrolling);
  101. }
  102. void SetScrolling(const nsAString& aScrolling, ErrorResult& aError)
  103. {
  104. SetHTMLAttr(nsGkAtoms::scrolling, aScrolling, aError);
  105. }
  106. void GetFrameBorder(DOMString& aFrameBorder)
  107. {
  108. GetHTMLAttr(nsGkAtoms::frameborder, aFrameBorder);
  109. }
  110. void SetFrameBorder(const nsAString& aFrameBorder, ErrorResult& aError)
  111. {
  112. SetHTMLAttr(nsGkAtoms::frameborder, aFrameBorder, aError);
  113. }
  114. // The XPCOM GetLongDesc is fine
  115. void SetLongDesc(const nsAString& aLongDesc, ErrorResult& aError)
  116. {
  117. SetHTMLAttr(nsGkAtoms::longdesc, aLongDesc, aError);
  118. }
  119. void GetMarginWidth(DOMString& aMarginWidth)
  120. {
  121. GetHTMLAttr(nsGkAtoms::marginwidth, aMarginWidth);
  122. }
  123. void SetMarginWidth(const nsAString& aMarginWidth, ErrorResult& aError)
  124. {
  125. SetHTMLAttr(nsGkAtoms::marginwidth, aMarginWidth, aError);
  126. }
  127. void GetMarginHeight(DOMString& aMarginHeight)
  128. {
  129. GetHTMLAttr(nsGkAtoms::marginheight, aMarginHeight);
  130. }
  131. void SetMarginHeight(const nsAString& aMarginHeight, ErrorResult& aError)
  132. {
  133. SetHTMLAttr(nsGkAtoms::marginheight, aMarginHeight, aError);
  134. }
  135. void SetReferrerPolicy(const nsAString& aReferrer, ErrorResult& aError)
  136. {
  137. SetHTMLAttr(nsGkAtoms::referrerpolicy, aReferrer, aError);
  138. }
  139. void GetReferrerPolicy(nsAString& aReferrer)
  140. {
  141. GetEnumAttr(nsGkAtoms::referrerpolicy, EmptyCString().get(), aReferrer);
  142. }
  143. nsIDocument*
  144. GetSVGDocument(nsIPrincipal& aSubjectPrincipal)
  145. {
  146. return GetContentDocument(aSubjectPrincipal);
  147. }
  148. bool Mozbrowser() const
  149. {
  150. return GetBoolAttr(nsGkAtoms::mozbrowser);
  151. }
  152. void SetMozbrowser(bool aAllow, ErrorResult& aError)
  153. {
  154. SetHTMLBoolAttr(nsGkAtoms::mozbrowser, aAllow, aError);
  155. }
  156. using nsGenericHTMLFrameElement::SetMozbrowser;
  157. // nsGenericHTMLFrameElement::GetFrameLoader is fine
  158. // 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; }
  165. protected:
  166. virtual ~HTMLIFrameElement();
  167. virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
  168. virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
  169. const nsAttrValue* aValue,
  170. const nsAttrValue* aOldValue,
  171. bool aNotify) override;
  172. virtual nsresult OnAttrSetButNotChanged(int32_t aNamespaceID, nsIAtom* aName,
  173. const nsAttrValueOrString& aValue,
  174. bool aNotify) override;
  175. private:
  176. static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
  177. nsRuleData* aData);
  178. static const DOMTokenListSupportedToken sSupportedSandboxTokens[];
  179. /**
  180. * This function is called by AfterSetAttr and OnAttrSetButNotChanged.
  181. * This function will be called by AfterSetAttr whether the attribute is being
  182. * set or unset.
  183. *
  184. * @param aNamespaceID the namespace of the attr being set
  185. * @param aName the localname of the attribute being set
  186. * @param aNotify Whether we plan to notify document observers.
  187. */
  188. void AfterMaybeChangeAttr(int32_t aNamespaceID, nsIAtom* aName, bool aNotify);
  189. };
  190. } // namespace dom
  191. } // namespace mozilla
  192. #endif