Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/svg/SVGStyleElement.cpp
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
#include "mozilla/dom/Element.h"
8
#include "mozilla/dom/SVGStyleElement.h"
9
#include "nsContentUtils.h"
10
#include "mozilla/dom/SVGStyleElementBinding.h"
11
12
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Style)
13
14
namespace mozilla {
15
namespace dom {
16
17
JSObject*
18
SVGStyleElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
19
0
{
20
0
  return SVGStyleElement_Binding::Wrap(aCx, this, aGivenProto);
21
0
}
22
23
//----------------------------------------------------------------------
24
// nsISupports methods
25
26
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(SVGStyleElement,
27
                                             SVGStyleElementBase,
28
                                             nsIStyleSheetLinkingElement,
29
                                             nsIMutationObserver)
30
31
NS_IMPL_CYCLE_COLLECTION_CLASS(SVGStyleElement)
32
33
0
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SVGStyleElement,
34
0
                                                  SVGStyleElementBase)
35
0
  tmp->nsStyleLinkElement::Traverse(cb);
36
0
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
37
38
0
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SVGStyleElement,
39
0
                                                SVGStyleElementBase)
40
0
  tmp->nsStyleLinkElement::Unlink();
41
0
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
42
43
//----------------------------------------------------------------------
44
// Implementation
45
46
SVGStyleElement::SVGStyleElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
47
  : SVGStyleElementBase(std::move(aNodeInfo))
48
0
{
49
0
  AddMutationObserver(this);
50
0
}
51
52
SVGStyleElement::~SVGStyleElement()
53
0
{
54
0
}
55
56
//----------------------------------------------------------------------
57
// nsINode methods
58
59
60
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGStyleElement)
61
62
63
//----------------------------------------------------------------------
64
// nsIContent methods
65
66
nsresult
67
SVGStyleElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
68
                            nsIContent* aBindingParent)
69
0
{
70
0
  nsresult rv = SVGStyleElementBase::BindToTree(aDocument, aParent,
71
0
                                                aBindingParent);
72
0
  NS_ENSURE_SUCCESS(rv, rv);
73
0
74
0
  void (SVGStyleElement::*update)() = &SVGStyleElement::UpdateStyleSheetInternal;
75
0
  nsContentUtils::AddScriptRunner(
76
0
    NewRunnableMethod("dom::SVGStyleElement::BindToTree", this, update));
77
0
78
0
  return rv;
79
0
}
80
81
void
82
SVGStyleElement::UnbindFromTree(bool aDeep, bool aNullParent)
83
0
{
84
0
  nsCOMPtr<nsIDocument> oldDoc = GetUncomposedDoc();
85
0
  ShadowRoot* oldShadow = GetContainingShadow();
86
0
  SVGStyleElementBase::UnbindFromTree(aDeep, aNullParent);
87
0
  Unused << UpdateStyleSheetInternal(oldDoc, oldShadow);
88
0
}
89
90
nsresult
91
SVGStyleElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
92
                              const nsAttrValue* aValue,
93
                              const nsAttrValue* aOldValue,
94
                              nsIPrincipal* aMaybeScriptedPrincipal,
95
                              bool aNotify)
96
0
{
97
0
  if (aNameSpaceID == kNameSpaceID_None) {
98
0
    if (aName == nsGkAtoms::title ||
99
0
        aName == nsGkAtoms::media ||
100
0
        aName == nsGkAtoms::type) {
101
0
      Unused << UpdateStyleSheetInternal(nullptr, nullptr, ForceUpdate::Yes);
102
0
    }
103
0
  }
104
0
105
0
  return SVGStyleElementBase::AfterSetAttr(aNameSpaceID, aName, aValue,
106
0
                                           aOldValue, aMaybeScriptedPrincipal,
107
0
                                           aNotify);
108
0
}
109
110
bool
111
SVGStyleElement::ParseAttribute(int32_t aNamespaceID,
112
                                nsAtom* aAttribute,
113
                                const nsAString& aValue,
114
                                nsIPrincipal* aMaybeScriptedPrincipal,
115
                                nsAttrValue& aResult)
116
0
{
117
0
  if (aNamespaceID == kNameSpaceID_None &&
118
0
      aAttribute == nsGkAtoms::crossorigin) {
119
0
    ParseCORSValue(aValue, aResult);
120
0
    return true;
121
0
  }
122
0
123
0
  return SVGStyleElementBase::ParseAttribute(aNamespaceID, aAttribute, aValue,
124
0
                                             aMaybeScriptedPrincipal, aResult);
125
0
}
126
127
//----------------------------------------------------------------------
128
// nsIMutationObserver methods
129
130
void
131
SVGStyleElement::CharacterDataChanged(nsIContent* aContent,
132
                                      const CharacterDataChangeInfo&)
133
0
{
134
0
  ContentChanged(aContent);
135
0
}
136
137
void
138
SVGStyleElement::ContentAppended(nsIContent* aFirstNewContent)
139
0
{
140
0
  ContentChanged(aFirstNewContent->GetParent());
141
0
}
142
143
void
144
SVGStyleElement::ContentInserted(nsIContent* aChild)
145
0
{
146
0
  ContentChanged(aChild);
147
0
}
148
149
void
150
SVGStyleElement::ContentRemoved(nsIContent* aChild,
151
                                nsIContent* aPreviousSibling)
152
0
{
153
0
  ContentChanged(aChild);
154
0
}
155
156
void
157
SVGStyleElement::ContentChanged(nsIContent* aContent)
158
0
{
159
0
  if (nsContentUtils::IsInSameAnonymousTree(this, aContent)) {
160
0
    Unused << UpdateStyleSheetInternal(nullptr, nullptr);
161
0
  }
162
0
}
163
164
//----------------------------------------------------------------------
165
166
void
167
SVGStyleElement::GetXmlspace(nsAString & aXmlspace)
168
0
{
169
0
  GetAttr(kNameSpaceID_XML, nsGkAtoms::space, aXmlspace);
170
0
}
171
172
void
173
SVGStyleElement::SetXmlspace(const nsAString & aXmlspace, ErrorResult& rv)
174
0
{
175
0
  rv = SetAttr(kNameSpaceID_XML, nsGkAtoms::space, aXmlspace, true);
176
0
}
177
178
void
179
SVGStyleElement::GetMedia(nsAString & aMedia)
180
0
{
181
0
  GetAttr(nsGkAtoms::media, aMedia);
182
0
}
183
184
void
185
SVGStyleElement::SetMedia(const nsAString& aMedia, ErrorResult& rv)
186
0
{
187
0
  SetAttr(nsGkAtoms::media, aMedia, rv);
188
0
}
189
190
void
191
SVGStyleElement::GetType(nsAString & aType)
192
0
{
193
0
  GetAttr(nsGkAtoms::type, aType);
194
0
}
195
196
void
197
SVGStyleElement::SetType(const nsAString& aType, ErrorResult& rv)
198
0
{
199
0
  SetAttr(nsGkAtoms::type, aType, rv);
200
0
}
201
202
void
203
SVGStyleElement::GetTitle(nsAString & aTitle)
204
0
{
205
0
  GetAttr(nsGkAtoms::title, aTitle);
206
0
}
207
208
void
209
SVGStyleElement::SetTitle(const nsAString& aTitle, ErrorResult& rv)
210
0
{
211
0
  SetAttr(nsGkAtoms::title, aTitle, rv);
212
0
}
213
214
//----------------------------------------------------------------------
215
// nsStyleLinkElement methods
216
217
Maybe<nsStyleLinkElement::SheetInfo>
218
SVGStyleElement::GetStyleSheetInfo()
219
0
{
220
0
  if (!IsCSSMimeTypeAttribute(*this)) {
221
0
    return Nothing();
222
0
  }
223
0
224
0
  nsAutoString title;
225
0
  nsAutoString media;
226
0
  GetTitleAndMediaForElement(*this, title, media);
227
0
228
0
  return Some(SheetInfo {
229
0
    *OwnerDoc(),
230
0
    this,
231
0
    nullptr,
232
0
    // FIXME(bug 1459822): Why doesn't this need a principal, but
233
0
    // HTMLStyleElement does?
234
0
    nullptr,
235
0
    net::ReferrerPolicy::RP_Unset,
236
0
    // FIXME(bug 1459822): Why does this need a crossorigin attribute, but
237
0
    // HTMLStyleElement doesn't?
238
0
    AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin)),
239
0
    title,
240
0
    media,
241
0
    HasAlternateRel::No,
242
0
    IsInline::Yes,
243
0
  });
244
0
}
245
246
} // namespace dom
247
} // namespace mozilla
248