HTMLEmbedElement.h (4984B)
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_HTMLEmbedElement_h 8 #define mozilla_dom_HTMLEmbedElement_h 9 10 #include "nsError.h" 11 #include "nsGenericHTMLElement.h" 12 #include "nsGkAtoms.h" 13 #include "nsObjectLoadingContent.h" 14 15 namespace mozilla::dom { 16 17 class HTMLEmbedElement final : public nsGenericHTMLElement, 18 public nsObjectLoadingContent { 19 public: 20 explicit HTMLEmbedElement( 21 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, 22 mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER); 23 24 // nsISupports 25 NS_DECL_ISUPPORTS_INHERITED 26 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLEmbedElement, embed) 27 28 bool AllowFullscreen() const { 29 // We don't need to check prefixed attributes because Flash does not support 30 // them. 31 return IsRewrittenYoutubeEmbed() && GetBoolAttr(nsGkAtoms::allowfullscreen); 32 } 33 34 // nsObjectLoadingContent 35 const Element* AsElement() const final { return this; } 36 37 nsresult BindToTree(BindContext&, nsINode& aParent) override; 38 void UnbindFromTree(UnbindContext&) override; 39 40 bool IsHTMLFocusable(IsFocusableFlags, bool* aIsFocusable, 41 int32_t* aTabIndex) override; 42 43 int32_t TabIndexDefault() override; 44 45 bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute, 46 const nsAString& aValue, 47 nsIPrincipal* aMaybeScriptedPrincipal, 48 nsAttrValue& aResult) override; 49 nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override; 50 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override; 51 void DestroyContent() override; 52 53 // nsObjectLoadingContent 54 uint32_t GetCapabilities() const override; 55 56 nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; 57 58 nsresult CopyInnerTo(HTMLEmbedElement* aDest); 59 60 void StartObjectLoad() { StartObjectLoad(true, false); } 61 62 virtual bool IsInteractiveHTMLContent() const override { return true; } 63 64 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLEmbedElement, 65 nsGenericHTMLElement) 66 67 // WebIDL <embed> api 68 void GetAlign(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::align, aValue); } 69 void SetAlign(const nsAString& aValue, ErrorResult& aRv) { 70 SetHTMLAttr(nsGkAtoms::align, aValue, aRv); 71 } 72 void GetHeight(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::height, aValue); } 73 void SetHeight(const nsAString& aValue, ErrorResult& aRv) { 74 SetHTMLAttr(nsGkAtoms::height, aValue, aRv); 75 } 76 void GetName(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::name, aValue); } 77 void SetName(const nsAString& aValue, ErrorResult& aRv) { 78 SetHTMLAttr(nsGkAtoms::name, aValue, aRv); 79 } 80 void GetWidth(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::width, aValue); } 81 void SetWidth(const nsAString& aValue, ErrorResult& aRv) { 82 SetHTMLAttr(nsGkAtoms::width, aValue, aRv); 83 } 84 // WebIDL <embed> api 85 void GetSrc(DOMString& aValue) { 86 GetURIAttr(nsGkAtoms::src, nullptr, aValue); 87 } 88 void SetSrc(const nsAString& aValue, ErrorResult& aRv) { 89 SetHTMLAttr(nsGkAtoms::src, aValue, aRv); 90 } 91 void GetType(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::type, aValue); } 92 void SetType(const nsAString& aValue, ErrorResult& aRv) { 93 SetHTMLAttr(nsGkAtoms::type, aValue, aRv); 94 } 95 Document* GetSVGDocument(nsIPrincipal& aSubjectPrincipal) { 96 return GetContentDocument(aSubjectPrincipal); 97 } 98 99 /** 100 * Calls LoadObject with the correct arguments to start the plugin load. 101 */ 102 void StartObjectLoad(bool aNotify, bool aForceLoad); 103 104 protected: 105 void AfterSetAttr(int32_t aNamespaceID, nsAtom* aName, 106 const nsAttrValue* aValue, const nsAttrValue* aOldValue, 107 nsIPrincipal* aSubjectPrincipal, bool aNotify) override; 108 void OnAttrSetButNotChanged(int32_t aNamespaceID, nsAtom* aName, 109 const nsAttrValueOrString& aValue, 110 bool aNotify) override; 111 112 private: 113 ~HTMLEmbedElement(); 114 115 nsContentPolicyType GetContentPolicyType() const override; 116 117 JSObject* WrapNode(JSContext*, JS::Handle<JSObject*> aGivenProto) override; 118 119 static void MapAttributesIntoRule(MappedDeclarationsBuilder&); 120 121 /** 122 * This function is called by AfterSetAttr and OnAttrSetButNotChanged. 123 * It will not be called if the value is being unset. 124 * 125 * @param aNamespaceID the namespace of the attr being set 126 * @param aName the localname of the attribute being set 127 * @param aNotify Whether we plan to notify document observers. 128 */ 129 void AfterMaybeChangeAttr(int32_t aNamespaceID, nsAtom* aName, bool aNotify); 130 }; 131 132 } // namespace mozilla::dom 133 134 #endif // mozilla_dom_HTMLEmbedElement_h