HTMLStyleElement.h (4094B)
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_HTMLStyleElement_h 8 #define mozilla_dom_HTMLStyleElement_h 9 10 #include "mozilla/dom/LinkStyle.h" 11 #include "nsGenericHTMLElement.h" 12 #include "nsStubMutationObserver.h" 13 14 class nsDOMTokenList; 15 16 namespace mozilla::dom { 17 18 class HTMLStyleElement final : public nsGenericHTMLElement, 19 public LinkStyle, 20 public nsStubMutationObserver { 21 public: 22 explicit HTMLStyleElement( 23 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo); 24 25 // nsISupports 26 NS_DECL_ISUPPORTS_INHERITED 27 28 // CC 29 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLStyleElement, 30 nsGenericHTMLElement) 31 32 void GetInnerHTML(nsAString& aInnerHTML, OOMReporter& aError) override; 33 using nsGenericHTMLElement::SetInnerHTML; 34 35 void SetInnerHTMLTrusted(const nsAString& aInnerHTML, 36 nsIPrincipal* aSubjectPrincipal, 37 mozilla::ErrorResult& aError) override; 38 39 public: 40 virtual void SetTextContentInternal( 41 const nsAString& aTextContent, nsIPrincipal* aSubjectPrincipal, 42 mozilla::ErrorResult& aError, 43 MutationEffectOnScript aMutationEffectOnScript = 44 MutationEffectOnScript::DropTrustWorthiness) override; 45 /** 46 * Mark this style element with a devtools-specific principal that 47 * skips Content Security Policy unsafe-inline checks. This triggering 48 * principal will be overwritten by any callers that set textContent 49 * or innerHTML on this element. 50 */ 51 void SetDevtoolsAsTriggeringPrincipal(); 52 53 virtual nsresult BindToTree(BindContext&, nsINode& aParent) override; 54 virtual void UnbindFromTree(UnbindContext&) override; 55 bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute, 56 const nsAString& aValue, 57 nsIPrincipal* aMaybeScriptedPrincipal, 58 nsAttrValue& aResult) override; 59 virtual void AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, 60 const nsAttrValue* aValue, 61 const nsAttrValue* aOldValue, 62 nsIPrincipal* aSubjectPrincipal, 63 bool aNotify) override; 64 65 virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; 66 67 // nsIMutationObserver 68 NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED 69 NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED 70 NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED 71 NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED 72 73 bool Disabled() const; 74 void SetDisabled(bool aDisabled); 75 void GetMedia(nsAString& aValue) { GetHTMLAttr(nsGkAtoms::media, aValue); } 76 void SetMedia(const nsAString& aMedia, ErrorResult& aError) { 77 SetHTMLAttr(nsGkAtoms::media, aMedia, aError); 78 } 79 void GetType(nsAString& aValue) { GetHTMLAttr(nsGkAtoms::type, aValue); } 80 void SetType(const nsAString& aType, ErrorResult& aError) { 81 SetHTMLAttr(nsGkAtoms::type, aType, aError); 82 } 83 84 nsDOMTokenList* Blocking(); 85 bool IsPotentiallyRenderBlocking() override; 86 87 virtual JSObject* WrapNode(JSContext* aCx, 88 JS::Handle<JSObject*> aGivenProto) override; 89 90 protected: 91 virtual ~HTMLStyleElement(); 92 93 nsIContent& AsContent() final { return *this; } 94 const LinkStyle* AsLinkStyle() const final { return this; } 95 Maybe<SheetInfo> GetStyleSheetInfo() final; 96 97 /** 98 * Common method to call from the various mutation observer methods. 99 * aContent is a content node that's either the one that changed or its 100 * parent; we should only respond to the change if aContent is non-anonymous. 101 */ 102 void ContentChanged(nsIContent* aContent); 103 nsresult CopyInnerTo(HTMLStyleElement* aDest); 104 105 RefPtr<nsDOMTokenList> mBlocking; 106 }; 107 108 } // namespace mozilla::dom 109 110 #endif