2
* Copyright (C) 2011 Google Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
#if ENABLE(VIDEO_TRACK)
30
#include "LoadableTextTrack.h"
33
#include "HTMLTrackElement.h"
34
#include "ScriptEventListener.h"
35
#include "ScriptExecutionContext.h"
36
#include "TextTrackCueList.h"
40
LoadableTextTrack::LoadableTextTrack(HTMLTrackElement* track, const String& kind, const String& label, const String& language)
41
: TextTrack(track->document(), track, kind, label, language, TrackElement)
42
, m_trackElement(track)
43
, m_loadTimer(this, &LoadableTextTrack::loadTimerFired)
48
LoadableTextTrack::~LoadableTextTrack()
52
void LoadableTextTrack::clearClient()
55
TextTrack::clearClient();
58
void LoadableTextTrack::scheduleLoad(const KURL& url)
63
// 4.8.10.12.3 Sourcing out-of-band text tracks (continued)
65
// 2. Let URL be the track URL of the track element.
68
// 3. Asynchronously run the remaining steps, while continuing with whatever task
69
// was responsible for creating the text track or changing the text track mode.
70
if (!m_loadTimer.isActive())
71
m_loadTimer.startOneShot(0);
74
void LoadableTextTrack::loadTimerFired(Timer<LoadableTextTrack>*)
77
m_loader->cancelLoad();
82
// 4.8.10.12.3 Sourcing out-of-band text tracks (continued)
84
// 4. Download: If URL is not the empty string, perform a potentially CORS-enabled fetch of URL, with the
85
// mode being the state of the media element's crossorigin content attribute, the origin being the
86
// origin of the media element's Document, and the default origin behaviour set to fail.
87
m_loader = TextTrackLoader::create(this, static_cast<ScriptExecutionContext*>(m_trackElement->document()));
88
if (!m_loader->load(m_url, m_trackElement->mediaElementCrossOriginAttribute()))
89
m_trackElement->didCompleteLoad(this, HTMLTrackElement::Failure);
92
void LoadableTextTrack::newCuesAvailable(TextTrackLoader* loader)
94
ASSERT_UNUSED(loader, m_loader == loader);
96
Vector<RefPtr<TextTrackCue> > newCues;
97
m_loader->getNewCues(newCues);
100
m_cues = TextTrackCueList::create();
102
for (size_t i = 0; i < newCues.size(); ++i) {
103
newCues[i]->setTrack(this);
104
m_cues->add(newCues[i]);
108
client()->textTrackAddCues(this, m_cues.get());
111
void LoadableTextTrack::cueLoadingStarted(TextTrackLoader* loader)
113
ASSERT_UNUSED(loader, m_loader == loader);
116
void LoadableTextTrack::cueLoadingCompleted(TextTrackLoader* loader, bool loadingFailed)
118
ASSERT_UNUSED(loader, m_loader == loader);
123
m_trackElement->didCompleteLoad(this, loadingFailed ? HTMLTrackElement::Failure : HTMLTrackElement::Success);
126
size_t LoadableTextTrack::trackElementIndex()
128
ASSERT(m_trackElement);
129
ASSERT(m_trackElement->parentNode());
132
for (Node* node = m_trackElement->parentNode()->firstChild(); node; node = node->nextSibling()) {
133
if (!node->hasTagName(trackTag) || !node->parentNode())
135
if (node == m_trackElement)
139
ASSERT_NOT_REACHED();
144
} // namespace WebCore