Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/HTMLSourceElement.h
Line
Count
Source (jump to first uncovered line)
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_HTMLSourceElement_h
8
#define mozilla_dom_HTMLSourceElement_h
9
10
#include "mozilla/Attributes.h"
11
#include "nsGenericHTMLElement.h"
12
#include "mozilla/dom/HTMLMediaElement.h"
13
14
class nsAttrValue;
15
16
namespace mozilla {
17
namespace dom {
18
19
class MediaList;
20
21
class HTMLSourceElement final : public nsGenericHTMLElement
22
{
23
public:
24
  explicit HTMLSourceElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
25
26
  // nsISupports
27
  NS_DECL_ISUPPORTS_INHERITED
28
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLSourceElement,
29
                                           nsGenericHTMLElement)
30
31
  NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLSourceElement, source)
32
33
  virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
34
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;
39
40
  // If this element's media attr matches for its owner document.  Returns true
41
  // if no media attr was set.
42
  bool MatchesCurrentMedia();
43
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);
49
50
  // Return the MediaSource object if any associated with the src attribute
51
  // when it was set.
52
0
  MediaSource* GetSrcMediaSource() { return mSrcMediaSource; };
53
54
  // WebIDL
55
  void GetSrc(nsString& aSrc)
56
0
  {
57
0
    GetURIAttr(nsGkAtoms::src, nullptr, aSrc);
58
0
  }
59
  void SetSrc(const nsAString& aSrc, nsIPrincipal* aTriggeringPrincipal, mozilla::ErrorResult& rv)
60
0
  {
61
0
    SetHTMLAttr(nsGkAtoms::src, aSrc, aTriggeringPrincipal, rv);
62
0
  }
63
64
  nsIPrincipal* GetSrcTriggeringPrincipal() const
65
0
  {
66
0
    return mSrcTriggeringPrincipal;
67
0
  }
68
69
  nsIPrincipal* GetSrcsetTriggeringPrincipal() const
70
0
  {
71
0
    return mSrcsetTriggeringPrincipal;
72
0
  }
73
74
  void GetType(DOMString& aType)
75
0
  {
76
0
    GetHTMLAttr(nsGkAtoms::type, aType);
77
0
  }
78
  void SetType(const nsAString& aType, ErrorResult& rv)
79
0
  {
80
0
    SetHTMLAttr(nsGkAtoms::type, aType, rv);
81
0
  }
82
83
  void GetSrcset(DOMString& aSrcset)
84
0
  {
85
0
    GetHTMLAttr(nsGkAtoms::srcset, aSrcset);
86
0
  }
87
  void SetSrcset(const nsAString& aSrcset, nsIPrincipal* aTriggeringPrincipal, mozilla::ErrorResult& rv)
88
0
  {
89
0
    SetHTMLAttr(nsGkAtoms::srcset, aSrcset, aTriggeringPrincipal, rv);
90
0
  }
91
92
  void GetSizes(DOMString& aSizes)
93
0
  {
94
0
    GetHTMLAttr(nsGkAtoms::sizes, aSizes);
95
0
  }
96
  void SetSizes(const nsAString& aSizes, mozilla::ErrorResult& rv)
97
0
  {
98
0
    SetHTMLAttr(nsGkAtoms::sizes, aSizes, rv);
99
0
  }
100
101
  void GetMedia(DOMString& aMedia)
102
0
  {
103
0
    GetHTMLAttr(nsGkAtoms::media, aMedia);
104
0
  }
105
  void SetMedia(const nsAString& aMedia, mozilla::ErrorResult& rv)
106
0
  {
107
0
    SetHTMLAttr(nsGkAtoms::media, aMedia, rv);
108
0
  }
109
110
protected:
111
  virtual ~HTMLSourceElement();
112
113
  virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
114
115
protected:
116
  virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
117
                                const nsAttrValue* aValue,
118
                                const nsAttrValue* aOldValue,
119
                                nsIPrincipal* aMaybeScriptedPrincipal,
120
                                bool aNotify) override;
121
122
private:
123
  RefPtr<MediaList> mMediaList;
124
  RefPtr<MediaSource> mSrcMediaSource;
125
126
  // The triggering principal for the src attribute.
127
  nsCOMPtr<nsIPrincipal> mSrcTriggeringPrincipal;
128
129
  // The triggering principal for the srcset attribute.
130
  nsCOMPtr<nsIPrincipal> mSrcsetTriggeringPrincipal;
131
132
  // Generates a new MediaList using the given input
133
  void UpdateMediaList(const nsAttrValue* aValue);
134
};
135
136
} // namespace dom
137
} // namespace mozilla
138
139
#endif // mozilla_dom_HTMLSourceElement_h