OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 27 matching lines...) Expand all Loading... | |
38 | 38 |
39 TextTrackList::TextTrackList(HTMLMediaElement* owner) | 39 TextTrackList::TextTrackList(HTMLMediaElement* owner) |
40 : m_owner(owner) | 40 : m_owner(owner) |
41 , m_asyncEventQueue(GenericEventQueue::create(this)) | 41 , m_asyncEventQueue(GenericEventQueue::create(this)) |
42 { | 42 { |
43 ScriptWrappable::init(this); | 43 ScriptWrappable::init(this); |
44 } | 44 } |
45 | 45 |
46 TextTrackList::~TextTrackList() | 46 TextTrackList::~TextTrackList() |
47 { | 47 { |
48 ASSERT(!m_owner); | |
49 | |
50 m_asyncEventQueue->close(); | 48 m_asyncEventQueue->close(); |
51 | |
52 for (unsigned i = 0; i < length(); ++i) { | |
Mads Ager (chromium)
2014/04/22 13:07:15
#if !ENABLE(OILPAN)
sof
2014/04/22 14:02:48
It isn't needed here either in the non-Oilpan case
Mads Ager (chromium)
2014/04/22 14:17:59
When it comes to clearing of pointers, please do n
| |
53 item(i)->setTrackList(0); | |
54 } | |
55 } | 49 } |
56 | 50 |
57 unsigned TextTrackList::length() const | 51 unsigned TextTrackList::length() const |
58 { | 52 { |
59 return m_addTrackTracks.size() + m_elementTracks.size() + m_inbandTracks.siz e(); | 53 return m_addTrackTracks.size() + m_elementTracks.size() + m_inbandTracks.siz e(); |
60 } | 54 } |
61 | 55 |
62 int TextTrackList::getTrackIndex(TextTrack *textTrack) | 56 int TextTrackList::getTrackIndex(TextTrack *textTrack) |
63 { | 57 { |
64 if (textTrack->trackType() == TextTrack::TrackElement) | 58 if (textTrack->trackType() == TextTrack::TrackElement) |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 if (track->id() == id) | 140 if (track->id() == id) |
147 return track; | 141 return track; |
148 } | 142 } |
149 | 143 |
150 // When no tracks match the given argument, the method must return null. | 144 // When no tracks match the given argument, the method must return null. |
151 return 0; | 145 return 0; |
152 } | 146 } |
153 | 147 |
154 void TextTrackList::invalidateTrackIndexesAfterTrack(TextTrack* track) | 148 void TextTrackList::invalidateTrackIndexesAfterTrack(TextTrack* track) |
155 { | 149 { |
156 Vector<RefPtr<TextTrack> >* tracks = 0; | 150 WillBeHeapVector<RefPtrWillBeMember<TextTrack> >* tracks = 0; |
157 | 151 |
158 if (track->trackType() == TextTrack::TrackElement) { | 152 if (track->trackType() == TextTrack::TrackElement) { |
159 tracks = &m_elementTracks; | 153 tracks = &m_elementTracks; |
160 for (size_t i = 0; i < m_addTrackTracks.size(); ++i) | 154 for (size_t i = 0; i < m_addTrackTracks.size(); ++i) |
161 m_addTrackTracks[i]->invalidateTrackIndex(); | 155 m_addTrackTracks[i]->invalidateTrackIndex(); |
162 for (size_t i = 0; i < m_inbandTracks.size(); ++i) | 156 for (size_t i = 0; i < m_inbandTracks.size(); ++i) |
163 m_inbandTracks[i]->invalidateTrackIndex(); | 157 m_inbandTracks[i]->invalidateTrackIndex(); |
164 } else if (track->trackType() == TextTrack::AddTrack) { | 158 } else if (track->trackType() == TextTrack::AddTrack) { |
165 tracks = &m_addTrackTracks; | 159 tracks = &m_addTrackTracks; |
166 for (size_t i = 0; i < m_inbandTracks.size(); ++i) | 160 for (size_t i = 0; i < m_inbandTracks.size(); ++i) |
167 m_inbandTracks[i]->invalidateTrackIndex(); | 161 m_inbandTracks[i]->invalidateTrackIndex(); |
168 } else if (track->trackType() == TextTrack::InBand) | 162 } else if (track->trackType() == TextTrack::InBand) |
169 tracks = &m_inbandTracks; | 163 tracks = &m_inbandTracks; |
170 else | 164 else |
171 ASSERT_NOT_REACHED(); | 165 ASSERT_NOT_REACHED(); |
172 | 166 |
173 size_t index = tracks->find(track); | 167 size_t index = tracks->find(track); |
174 if (index == kNotFound) | 168 if (index == kNotFound) |
175 return; | 169 return; |
176 | 170 |
177 for (size_t i = index; i < tracks->size(); ++i) | 171 for (size_t i = index; i < tracks->size(); ++i) |
178 tracks->at(index)->invalidateTrackIndex(); | 172 tracks->at(index)->invalidateTrackIndex(); |
179 } | 173 } |
180 | 174 |
181 void TextTrackList::append(PassRefPtr<TextTrack> prpTrack) | 175 void TextTrackList::append(PassRefPtrWillBeRawPtr<TextTrack> prpTrack) |
182 { | 176 { |
183 RefPtr<TextTrack> track = prpTrack; | 177 RefPtrWillBeRawPtr<TextTrack> track = prpTrack; |
184 | 178 |
185 if (track->trackType() == TextTrack::AddTrack) | 179 if (track->trackType() == TextTrack::AddTrack) |
186 m_addTrackTracks.append(track); | 180 m_addTrackTracks.append(track); |
187 else if (track->trackType() == TextTrack::TrackElement) { | 181 else if (track->trackType() == TextTrack::TrackElement) { |
188 // Insert tracks added for <track> element in tree order. | 182 // Insert tracks added for <track> element in tree order. |
189 size_t index = static_cast<LoadableTextTrack*>(track.get())->trackElemen tIndex(); | 183 size_t index = static_cast<LoadableTextTrack*>(track.get())->trackElemen tIndex(); |
190 m_elementTracks.insert(index, track); | 184 m_elementTracks.insert(index, track); |
191 } else if (track->trackType() == TextTrack::InBand) { | 185 } else if (track->trackType() == TextTrack::InBand) { |
192 // Insert tracks added for in-band in the media file order. | 186 // Insert tracks added for in-band in the media file order. |
193 size_t index = static_cast<InbandTextTrack*>(track.get())->inbandTrackIn dex(); | 187 size_t index = static_cast<InbandTextTrack*>(track.get())->inbandTrackIn dex(); |
194 m_inbandTracks.insert(index, track); | 188 m_inbandTracks.insert(index, track); |
195 } else | 189 } else |
196 ASSERT_NOT_REACHED(); | 190 ASSERT_NOT_REACHED(); |
197 | 191 |
198 invalidateTrackIndexesAfterTrack(track.get()); | 192 invalidateTrackIndexesAfterTrack(track.get()); |
199 | 193 |
200 ASSERT(!track->trackList()); | 194 ASSERT(!track->trackList()); |
201 track->setTrackList(this); | 195 track->setTrackList(this); |
202 | 196 |
203 scheduleAddTrackEvent(track.release()); | 197 scheduleAddTrackEvent(track.release()); |
204 } | 198 } |
205 | 199 |
206 void TextTrackList::remove(TextTrack* track) | 200 void TextTrackList::remove(TextTrack* track) |
207 { | 201 { |
208 Vector<RefPtr<TextTrack> >* tracks = 0; | 202 WillBeHeapVector<RefPtrWillBeMember<TextTrack> >* tracks = 0; |
209 | 203 |
210 if (track->trackType() == TextTrack::TrackElement) { | 204 if (track->trackType() == TextTrack::TrackElement) { |
211 tracks = &m_elementTracks; | 205 tracks = &m_elementTracks; |
212 } else if (track->trackType() == TextTrack::AddTrack) { | 206 } else if (track->trackType() == TextTrack::AddTrack) { |
213 tracks = &m_addTrackTracks; | 207 tracks = &m_addTrackTracks; |
214 } else if (track->trackType() == TextTrack::InBand) { | 208 } else if (track->trackType() == TextTrack::InBand) { |
215 tracks = &m_inbandTracks; | 209 tracks = &m_inbandTracks; |
216 } else { | 210 } else { |
217 ASSERT_NOT_REACHED(); | 211 ASSERT_NOT_REACHED(); |
218 } | 212 } |
(...skipping 15 matching lines...) Expand all Loading... | |
234 void TextTrackList::removeAllInbandTracks() | 228 void TextTrackList::removeAllInbandTracks() |
235 { | 229 { |
236 for (unsigned i = 0; i < m_inbandTracks.size(); ++i) { | 230 for (unsigned i = 0; i < m_inbandTracks.size(); ++i) { |
237 m_inbandTracks[i]->setTrackList(0); | 231 m_inbandTracks[i]->setTrackList(0); |
238 } | 232 } |
239 m_inbandTracks.clear(); | 233 m_inbandTracks.clear(); |
240 } | 234 } |
241 | 235 |
242 bool TextTrackList::contains(TextTrack* track) const | 236 bool TextTrackList::contains(TextTrack* track) const |
243 { | 237 { |
244 const Vector<RefPtr<TextTrack> >* tracks = 0; | 238 const WillBeHeapVector<RefPtrWillBeMember<TextTrack> >* tracks = 0; |
245 | 239 |
246 if (track->trackType() == TextTrack::TrackElement) | 240 if (track->trackType() == TextTrack::TrackElement) |
247 tracks = &m_elementTracks; | 241 tracks = &m_elementTracks; |
248 else if (track->trackType() == TextTrack::AddTrack) | 242 else if (track->trackType() == TextTrack::AddTrack) |
249 tracks = &m_addTrackTracks; | 243 tracks = &m_addTrackTracks; |
250 else if (track->trackType() == TextTrack::InBand) | 244 else if (track->trackType() == TextTrack::InBand) |
251 tracks = &m_inbandTracks; | 245 tracks = &m_inbandTracks; |
252 else | 246 else |
253 ASSERT_NOT_REACHED(); | 247 ASSERT_NOT_REACHED(); |
254 | 248 |
255 return tracks->find(track) != kNotFound; | 249 return tracks->find(track) != kNotFound; |
256 } | 250 } |
257 | 251 |
258 const AtomicString& TextTrackList::interfaceName() const | 252 const AtomicString& TextTrackList::interfaceName() const |
259 { | 253 { |
260 return EventTargetNames::TextTrackList; | 254 return EventTargetNames::TextTrackList; |
261 } | 255 } |
262 | 256 |
263 ExecutionContext* TextTrackList::executionContext() const | 257 ExecutionContext* TextTrackList::executionContext() const |
264 { | 258 { |
265 ASSERT(m_owner); | 259 ASSERT(m_owner); |
266 return m_owner->executionContext(); | 260 return m_owner->executionContext(); |
267 } | 261 } |
268 | 262 |
269 void TextTrackList::clearOwner() | 263 void TextTrackList::scheduleTrackEvent(const AtomicString& eventName, PassRefPtr WillBeRawPtr<TextTrack> track) |
270 { | |
271 m_owner = 0; | |
272 } | |
273 | |
274 void TextTrackList::scheduleTrackEvent(const AtomicString& eventName, PassRefPtr <TextTrack> track) | |
275 { | 264 { |
276 TrackEventInit initializer; | 265 TrackEventInit initializer; |
277 initializer.track = track; | 266 initializer.track = track; |
278 initializer.bubbles = false; | 267 initializer.bubbles = false; |
279 initializer.cancelable = false; | 268 initializer.cancelable = false; |
280 | 269 |
281 m_asyncEventQueue->enqueueEvent(TrackEvent::create(eventName, initializer)); | 270 m_asyncEventQueue->enqueueEvent(TrackEvent::create(eventName, initializer)); |
282 } | 271 } |
283 | 272 |
284 void TextTrackList::scheduleAddTrackEvent(PassRefPtr<TextTrack> track) | 273 void TextTrackList::scheduleAddTrackEvent(PassRefPtrWillBeRawPtr<TextTrack> trac k) |
285 { | 274 { |
286 // 4.8.10.12.3 Sourcing out-of-band text tracks | 275 // 4.8.10.12.3 Sourcing out-of-band text tracks |
287 // 4.8.10.12.4 Text track API | 276 // 4.8.10.12.4 Text track API |
288 // ... then queue a task to fire an event with the name addtrack, that does not | 277 // ... then queue a task to fire an event with the name addtrack, that does not |
289 // bubble and is not cancelable, and that uses the TrackEvent interface, wit h | 278 // bubble and is not cancelable, and that uses the TrackEvent interface, wit h |
290 // the track attribute initialized to the text track's TextTrack object, at | 279 // the track attribute initialized to the text track's TextTrack object, at |
291 // the media element's textTracks attribute's TextTrackList object. | 280 // the media element's textTracks attribute's TextTrackList object. |
292 scheduleTrackEvent(EventTypeNames::addtrack, track); | 281 scheduleTrackEvent(EventTypeNames::addtrack, track); |
293 } | 282 } |
294 | 283 |
295 void TextTrackList::scheduleChangeEvent() | 284 void TextTrackList::scheduleChangeEvent() |
296 { | 285 { |
297 // 4.8.10.12.1 Text track model | 286 // 4.8.10.12.1 Text track model |
298 // Whenever a text track that is in a media element's list of text tracks | 287 // Whenever a text track that is in a media element's list of text tracks |
299 // has its text track mode change value, the user agent must run the | 288 // has its text track mode change value, the user agent must run the |
300 // following steps for the media element: | 289 // following steps for the media element: |
301 // ... | 290 // ... |
302 // Fire a simple event named change at the media element's textTracks | 291 // Fire a simple event named change at the media element's textTracks |
303 // attribute's TextTrackList object. | 292 // attribute's TextTrackList object. |
304 | 293 |
305 EventInit initializer; | 294 EventInit initializer; |
306 initializer.bubbles = false; | 295 initializer.bubbles = false; |
307 initializer.cancelable = false; | 296 initializer.cancelable = false; |
308 | 297 |
309 m_asyncEventQueue->enqueueEvent(Event::create(EventTypeNames::change, initia lizer)); | 298 m_asyncEventQueue->enqueueEvent(Event::create(EventTypeNames::change, initia lizer)); |
310 } | 299 } |
311 | 300 |
312 void TextTrackList::scheduleRemoveTrackEvent(PassRefPtr<TextTrack> track) | 301 void TextTrackList::scheduleRemoveTrackEvent(PassRefPtrWillBeRawPtr<TextTrack> t rack) |
313 { | 302 { |
314 // 4.8.10.12.3 Sourcing out-of-band text tracks | 303 // 4.8.10.12.3 Sourcing out-of-band text tracks |
315 // When a track element's parent element changes and the old parent was a | 304 // When a track element's parent element changes and the old parent was a |
316 // media element, then the user agent must remove the track element's | 305 // media element, then the user agent must remove the track element's |
317 // corresponding text track from the media element's list of text tracks, | 306 // corresponding text track from the media element's list of text tracks, |
318 // and then queue a task to fire a trusted event with the name removetrack, | 307 // and then queue a task to fire a trusted event with the name removetrack, |
319 // that does not bubble and is not cancelable, and that uses the TrackEvent | 308 // that does not bubble and is not cancelable, and that uses the TrackEvent |
320 // interface, with the track attribute initialized to the text track's | 309 // interface, with the track attribute initialized to the text track's |
321 // TextTrack object, at the media element's textTracks attribute's | 310 // TextTrack object, at the media element's textTracks attribute's |
322 // TextTrackList object. | 311 // TextTrackList object. |
323 scheduleTrackEvent(EventTypeNames::removetrack, track); | 312 scheduleTrackEvent(EventTypeNames::removetrack, track); |
324 } | 313 } |
325 | 314 |
326 HTMLMediaElement* TextTrackList::owner() const | 315 HTMLMediaElement* TextTrackList::owner() const |
327 { | 316 { |
328 return m_owner; | 317 return m_owner; |
329 } | 318 } |
319 | |
320 void TextTrackList::trace(Visitor* visitor) | |
321 { | |
322 visitor->trace(m_owner); | |
323 visitor->trace(m_addTrackTracks); | |
324 visitor->trace(m_elementTracks); | |
325 visitor->trace(m_inbandTracks); | |
326 } | |
OLD | NEW |