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"
21 class HTMLSourceElement final
: public nsGenericHTMLElement
24 explicit HTMLSourceElement(already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
);
27 NS_DECL_ISUPPORTS_INHERITED
28 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLSourceElement
,
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(nsIDocument
* aDocument
, nsIContent
* aParent
,
38 nsIContent
* aBindingParent
) override
;
40 // If this element's media attr matches for its owner document. Returns true
41 // if no media attr was set.
42 bool MatchesCurrentMedia();
44 // True if a source tag would match the given media attribute for the
45 // specified document. Used by the preloader to determine valid <source> tags
46 // prior to DOM creation.
47 static bool WouldMatchMediaForDocument(const nsAString
& aMediaStr
,
48 const nsIDocument
*aDocument
);
50 // Return the MediaSource object if any associated with the src attribute
52 MediaSource
* GetSrcMediaSource() { return mSrcMediaSource
; };
55 void GetSrc(nsString
& aSrc
)
57 GetURIAttr(nsGkAtoms::src
, nullptr, aSrc
);
59 void SetSrc(const nsAString
& aSrc
, nsIPrincipal
* aTriggeringPrincipal
, mozilla::ErrorResult
& rv
)
61 SetHTMLAttr(nsGkAtoms::src
, aSrc
, aTriggeringPrincipal
, rv
);
64 nsIPrincipal
* GetSrcTriggeringPrincipal() const
66 return mSrcTriggeringPrincipal
;
69 nsIPrincipal
* GetSrcsetTriggeringPrincipal() const
71 return mSrcsetTriggeringPrincipal
;
74 void GetType(DOMString
& aType
)
76 GetHTMLAttr(nsGkAtoms::type
, aType
);
78 void SetType(const nsAString
& aType
, ErrorResult
& rv
)
80 SetHTMLAttr(nsGkAtoms::type
, aType
, rv
);
83 void GetSrcset(DOMString
& aSrcset
)
85 GetHTMLAttr(nsGkAtoms::srcset
, aSrcset
);
87 void SetSrcset(const nsAString
& aSrcset
, nsIPrincipal
* aTriggeringPrincipal
, mozilla::ErrorResult
& rv
)
89 SetHTMLAttr(nsGkAtoms::srcset
, aSrcset
, aTriggeringPrincipal
, rv
);
92 void GetSizes(DOMString
& aSizes
)
94 GetHTMLAttr(nsGkAtoms::sizes
, aSizes
);
96 void SetSizes(const nsAString
& aSizes
, mozilla::ErrorResult
& rv
)
98 SetHTMLAttr(nsGkAtoms::sizes
, aSizes
, rv
);
101 void GetMedia(DOMString
& aMedia
)
103 GetHTMLAttr(nsGkAtoms::media
, aMedia
);
105 void SetMedia(const nsAString
& aMedia
, mozilla::ErrorResult
& rv
)
107 SetHTMLAttr(nsGkAtoms::media
, aMedia
, rv
);
111 virtual ~HTMLSourceElement();
113 virtual JSObject
* WrapNode(JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) override
;
116 virtual nsresult
AfterSetAttr(int32_t aNameSpaceID
, nsAtom
* aName
,
117 const nsAttrValue
* aValue
,
118 const nsAttrValue
* aOldValue
,
119 nsIPrincipal
* aMaybeScriptedPrincipal
,
120 bool aNotify
) override
;
123 RefPtr
<MediaList
> mMediaList
;
124 RefPtr
<MediaSource
> mSrcMediaSource
;
126 // The triggering principal for the src attribute.
127 nsCOMPtr
<nsIPrincipal
> mSrcTriggeringPrincipal
;
129 // The triggering principal for the srcset attribute.
130 nsCOMPtr
<nsIPrincipal
> mSrcsetTriggeringPrincipal
;
132 // Generates a new MediaList using the given input
133 void UpdateMediaList(const nsAttrValue
* aValue
);
137 } // namespace mozilla
139 #endif // mozilla_dom_HTMLSourceElement_h