~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/html/track/LoadableTextTrack.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2011 Google Inc.  All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
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.
 
12
 *
 
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.
 
24
 */
 
25
 
 
26
#include "config.h"
 
27
 
 
28
#if ENABLE(VIDEO_TRACK)
 
29
 
 
30
#include "LoadableTextTrack.h"
 
31
 
 
32
#include "Event.h"
 
33
#include "HTMLTrackElement.h"
 
34
#include "ScriptEventListener.h"
 
35
#include "ScriptExecutionContext.h"
 
36
#include "TextTrackCueList.h"
 
37
 
 
38
namespace WebCore {
 
39
 
 
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)
 
44
    , m_isDefault(false)
 
45
{
 
46
}
 
47
 
 
48
LoadableTextTrack::~LoadableTextTrack()
 
49
{
 
50
}
 
51
 
 
52
void LoadableTextTrack::clearClient()
 
53
{
 
54
    m_trackElement = 0;
 
55
    TextTrack::clearClient();
 
56
}
 
57
 
 
58
void LoadableTextTrack::scheduleLoad(const KURL& url)
 
59
{
 
60
    if (url == m_url)
 
61
        return;
 
62
 
 
63
    // 4.8.10.12.3 Sourcing out-of-band text tracks (continued)
 
64
 
 
65
    // 2. Let URL be the track URL of the track element.
 
66
    m_url = url;
 
67
    
 
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);
 
72
}
 
73
 
 
74
void LoadableTextTrack::loadTimerFired(Timer<LoadableTextTrack>*)
 
75
{
 
76
    if (m_loader)
 
77
        m_loader->cancelLoad();
 
78
 
 
79
    if (!m_trackElement)
 
80
        return;
 
81
 
 
82
    // 4.8.10.12.3 Sourcing out-of-band text tracks (continued)
 
83
 
 
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);
 
90
}
 
91
 
 
92
void LoadableTextTrack::newCuesAvailable(TextTrackLoader* loader)
 
93
{
 
94
    ASSERT_UNUSED(loader, m_loader == loader);
 
95
 
 
96
    Vector<RefPtr<TextTrackCue> > newCues;
 
97
    m_loader->getNewCues(newCues);
 
98
 
 
99
    if (!m_cues)
 
100
        m_cues = TextTrackCueList::create();    
 
101
 
 
102
    for (size_t i = 0; i < newCues.size(); ++i) {
 
103
        newCues[i]->setTrack(this);
 
104
        m_cues->add(newCues[i]);
 
105
    }
 
106
 
 
107
    if (client())
 
108
        client()->textTrackAddCues(this, m_cues.get());
 
109
}
 
110
 
 
111
void LoadableTextTrack::cueLoadingStarted(TextTrackLoader* loader)
 
112
{
 
113
    ASSERT_UNUSED(loader, m_loader == loader);
 
114
}
 
115
 
 
116
void LoadableTextTrack::cueLoadingCompleted(TextTrackLoader* loader, bool loadingFailed)
 
117
{
 
118
    ASSERT_UNUSED(loader, m_loader == loader);
 
119
 
 
120
    if (!m_trackElement)
 
121
        return;
 
122
 
 
123
    m_trackElement->didCompleteLoad(this, loadingFailed ? HTMLTrackElement::Failure : HTMLTrackElement::Success);
 
124
}
 
125
 
 
126
size_t LoadableTextTrack::trackElementIndex()
 
127
{
 
128
    ASSERT(m_trackElement);
 
129
    ASSERT(m_trackElement->parentNode());
 
130
 
 
131
    size_t index = 0;
 
132
    for (Node* node = m_trackElement->parentNode()->firstChild(); node; node = node->nextSibling()) {
 
133
        if (!node->hasTagName(trackTag) || !node->parentNode())
 
134
            continue;
 
135
        if (node == m_trackElement)
 
136
            return index;
 
137
        ++index;
 
138
    }
 
139
    ASSERT_NOT_REACHED();
 
140
 
 
141
    return 0;
 
142
}
 
143
 
 
144
} // namespace WebCore
 
145
 
 
146
#endif