Bug 1554951 [wpt PR 17043] - wake-lock: Fix invalid types test in wakelock-type.https...
[gecko.git] / dom / html / HTMLSourceElement.h
blob943c9e23d7044d04caa106a52d785b792f6eb847
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_HTMLSourceElement_h
8 #define mozilla_dom_HTMLSourceElement_h
10 #include "mozilla/Attributes.h"
11 #include "nsGenericHTMLElement.h"
12 #include "mozilla/dom/HTMLMediaElement.h"
14 class nsAttrValue;
16 namespace mozilla {
17 namespace dom {
19 class MediaList;
21 class HTMLSourceElement final : public nsGenericHTMLElement {
22 public:
23 explicit HTMLSourceElement(
24 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
26 // nsISupports
27 NS_DECL_ISUPPORTS_INHERITED
28 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLSourceElement,
29 nsGenericHTMLElement)
31 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLSourceElement, source)
33 virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
35 // Override BindToTree() so that we can trigger a load when we add a
36 // child source element.
37 virtual nsresult BindToTree(BindContext&, nsINode& aParent) override;
39 // If this element's media attr matches for its owner document. Returns true
40 // if no media attr was set.
41 bool MatchesCurrentMedia();
43 // True if a source tag would match the given media attribute for the
44 // specified document. Used by the preloader to determine valid <source> tags
45 // prior to DOM creation.
46 static bool WouldMatchMediaForDocument(const nsAString& aMediaStr,
47 const Document* aDocument);
49 // Return the MediaSource object if any associated with the src attribute
50 // when it was set.
51 MediaSource* GetSrcMediaSource() { return mSrcMediaSource; };
53 // WebIDL
54 void GetSrc(nsString& aSrc) { GetURIAttr(nsGkAtoms::src, nullptr, aSrc); }
55 void SetSrc(const nsAString& aSrc, nsIPrincipal* aTriggeringPrincipal,
56 mozilla::ErrorResult& rv) {
57 SetHTMLAttr(nsGkAtoms::src, aSrc, aTriggeringPrincipal, rv);
60 nsIPrincipal* GetSrcTriggeringPrincipal() const {
61 return mSrcTriggeringPrincipal;
64 nsIPrincipal* GetSrcsetTriggeringPrincipal() const {
65 return mSrcsetTriggeringPrincipal;
68 void GetType(DOMString& aType) { GetHTMLAttr(nsGkAtoms::type, aType); }
69 void SetType(const nsAString& aType, ErrorResult& rv) {
70 SetHTMLAttr(nsGkAtoms::type, aType, rv);
73 void GetSrcset(DOMString& aSrcset) {
74 GetHTMLAttr(nsGkAtoms::srcset, aSrcset);
76 void SetSrcset(const nsAString& aSrcset, nsIPrincipal* aTriggeringPrincipal,
77 mozilla::ErrorResult& rv) {
78 SetHTMLAttr(nsGkAtoms::srcset, aSrcset, aTriggeringPrincipal, rv);
81 void GetSizes(DOMString& aSizes) { GetHTMLAttr(nsGkAtoms::sizes, aSizes); }
82 void SetSizes(const nsAString& aSizes, mozilla::ErrorResult& rv) {
83 SetHTMLAttr(nsGkAtoms::sizes, aSizes, rv);
86 void GetMedia(DOMString& aMedia) { GetHTMLAttr(nsGkAtoms::media, aMedia); }
87 void SetMedia(const nsAString& aMedia, mozilla::ErrorResult& rv) {
88 SetHTMLAttr(nsGkAtoms::media, aMedia, rv);
91 protected:
92 virtual ~HTMLSourceElement();
94 virtual JSObject* WrapNode(JSContext* aCx,
95 JS::Handle<JSObject*> aGivenProto) override;
97 protected:
98 virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
99 const nsAttrValue* aValue,
100 const nsAttrValue* aOldValue,
101 nsIPrincipal* aMaybeScriptedPrincipal,
102 bool aNotify) override;
104 private:
105 RefPtr<MediaList> mMediaList;
106 RefPtr<MediaSource> mSrcMediaSource;
108 // The triggering principal for the src attribute.
109 nsCOMPtr<nsIPrincipal> mSrcTriggeringPrincipal;
111 // The triggering principal for the srcset attribute.
112 nsCOMPtr<nsIPrincipal> mSrcsetTriggeringPrincipal;
114 // Generates a new MediaList using the given input
115 void UpdateMediaList(const nsAttrValue* aValue);
118 } // namespace dom
119 } // namespace mozilla
121 #endif // mozilla_dom_HTMLSourceElement_h