OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google 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 |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "core/html/track/LoadableTextTrack.h" | 27 #include "core/html/track/LoadableTextTrack.h" |
28 | 28 |
29 #include "core/dom/ElementTraversal.h" | 29 #include "core/dom/ElementTraversal.h" |
30 #include "core/html/HTMLMediaElement.h" | |
31 #include "core/html/HTMLTrackElement.h" | 30 #include "core/html/HTMLTrackElement.h" |
32 #include "core/html/track/vtt/VTTRegionList.h" | 31 #include "core/html/track/vtt/VTTRegionList.h" |
33 | 32 |
34 namespace blink { | 33 namespace blink { |
35 | 34 |
36 using namespace HTMLNames; | |
37 | |
38 LoadableTextTrack::LoadableTextTrack(HTMLTrackElement* track) | 35 LoadableTextTrack::LoadableTextTrack(HTMLTrackElement* track) |
39 : TextTrack(emptyAtom, emptyAtom, emptyAtom, emptyAtom, TrackElement) | 36 : TextTrack(emptyAtom, emptyAtom, emptyAtom, emptyAtom, TrackElement) |
40 , m_trackElement(track) | 37 , m_trackElement(track) |
41 , m_loadTimer(this, &LoadableTextTrack::loadTimerFired) | |
42 { | 38 { |
43 } | 39 } |
44 | 40 |
45 LoadableTextTrack::~LoadableTextTrack() | 41 LoadableTextTrack::~LoadableTextTrack() |
46 { | 42 { |
47 #if !ENABLE(OILPAN) | 43 #if !ENABLE(OILPAN) |
48 ASSERT(!m_trackElement); | 44 ASSERT(!m_trackElement); |
49 #endif | 45 #endif |
50 } | 46 } |
51 | 47 |
52 #if !ENABLE(OILPAN) | 48 #if !ENABLE(OILPAN) |
53 void LoadableTextTrack::clearTrackElement() | 49 void LoadableTextTrack::clearTrackElement() |
54 { | 50 { |
55 m_trackElement = nullptr; | 51 m_trackElement = nullptr; |
56 } | 52 } |
57 #endif | 53 #endif |
58 | 54 |
59 bool LoadableTextTrack::isDefault() const | 55 bool LoadableTextTrack::isDefault() const |
60 { | 56 { |
61 ASSERT(m_trackElement); | 57 ASSERT(m_trackElement); |
62 return m_trackElement->fastHasAttribute(defaultAttr); | 58 return m_trackElement->fastHasAttribute(HTMLNames::defaultAttr); |
63 } | 59 } |
64 | 60 |
65 void LoadableTextTrack::setMode(const AtomicString& mode) | 61 void LoadableTextTrack::setMode(const AtomicString& mode) |
66 { | 62 { |
67 TextTrack::setMode(mode); | 63 TextTrack::setMode(mode); |
68 #if !ENABLE(OILPAN) | 64 #if !ENABLE(OILPAN) |
69 if (!m_trackElement) | 65 if (!m_trackElement) |
70 return; | 66 return; |
71 #endif | 67 #endif |
72 | 68 |
73 if (m_trackElement->readyState() == HTMLTrackElement::NONE) | 69 if (m_trackElement->readyState() == HTMLTrackElement::NONE) |
74 m_trackElement->scheduleLoad(); | 70 m_trackElement->scheduleLoad(); |
75 } | 71 } |
76 | 72 |
77 void LoadableTextTrack::scheduleLoad(const KURL& url) | 73 void LoadableTextTrack::addRegions(const WillBeHeapVector<RefPtrWillBeMember<VTT
Region>>& newRegions) |
78 { | 74 { |
79 if (url == m_url) { | |
80 // If loading of the resource from this URL is in progress, return early
. | |
81 ASSERT(m_loader && m_trackElement); | |
82 if (m_loader->loadState() < TextTrackLoader::Finished) | |
83 return; | |
84 | |
85 // The track element might have changed its state to HTMLTrackElement::L
oading | |
86 // waiting for a call to didCompleteLoad to continue. | |
87 cueLoadingCompleted(m_loader.get(), m_loader->loadState() == TextTrackLo
ader::Failed); | |
88 return; | |
89 } | |
90 | |
91 // 4.8.10.12.3 Sourcing out-of-band text tracks (continued) | |
92 | |
93 // 2. Let URL be the track URL of the track element. | |
94 m_url = url; | |
95 | |
96 // 3. Asynchronously run the remaining steps, while continuing with whatever
task | |
97 // was responsible for creating the text track or changing the text track mo
de. | |
98 if (!m_loadTimer.isActive()) | |
99 m_loadTimer.startOneShot(0, FROM_HERE); | |
100 } | |
101 | |
102 void LoadableTextTrack::loadTimerFired(Timer<LoadableTextTrack>*) | |
103 { | |
104 if (m_loader) | |
105 m_loader->cancelLoad(); | |
106 | |
107 #if !ENABLE(OILPAN) | |
108 if (!m_trackElement) | |
109 return; | |
110 #endif | |
111 | |
112 // 4.8.10.12.3 Sourcing out-of-band text tracks (continued) | |
113 | |
114 // 4. Download: If URL is not the empty string, perform a potentially CORS-e
nabled fetch of URL, with the | |
115 // mode being the state of the media element's crossorigin content attribute
, the origin being the | |
116 // origin of the media element's Document, and the default origin behaviour
set to fail. | |
117 m_loader = TextTrackLoader::create(*this, m_trackElement->document()); | |
118 if (!m_loader->load(m_url, m_trackElement->mediaElementCrossOriginAttribute(
))) | |
119 m_trackElement->didCompleteLoad(HTMLTrackElement::Failure); | |
120 } | |
121 | |
122 void LoadableTextTrack::newCuesAvailable(TextTrackLoader* loader) | |
123 { | |
124 ASSERT_UNUSED(loader, m_loader == loader); | |
125 | |
126 WillBeHeapVector<RefPtrWillBeMember<TextTrackCue>> newCues; | |
127 m_loader->getNewCues(newCues); | |
128 | |
129 addListOfCues(newCues); | |
130 } | |
131 | |
132 void LoadableTextTrack::cueLoadingCompleted(TextTrackLoader* loader, bool loadin
gFailed) | |
133 { | |
134 ASSERT_UNUSED(loader, m_loader == loader); | |
135 | |
136 #if !ENABLE(OILPAN) | |
137 if (!m_trackElement) | |
138 return; | |
139 #endif | |
140 | |
141 m_trackElement->didCompleteLoad(loadingFailed ? HTMLTrackElement::Failure :
HTMLTrackElement::Success); | |
142 } | |
143 | |
144 void LoadableTextTrack::newRegionsAvailable(TextTrackLoader* loader) | |
145 { | |
146 ASSERT_UNUSED(loader, m_loader == loader); | |
147 | |
148 WillBeHeapVector<RefPtrWillBeMember<VTTRegion>> newRegions; | |
149 m_loader->getNewRegions(newRegions); | |
150 | |
151 for (size_t i = 0; i < newRegions.size(); ++i) { | 75 for (size_t i = 0; i < newRegions.size(); ++i) { |
152 newRegions[i]->setTrack(this); | 76 newRegions[i]->setTrack(this); |
153 regions()->add(newRegions[i]); | 77 regions()->add(newRegions[i]); |
154 } | 78 } |
155 } | 79 } |
156 | 80 |
157 size_t LoadableTextTrack::trackElementIndex() | 81 size_t LoadableTextTrack::trackElementIndex() |
158 { | 82 { |
159 ASSERT(m_trackElement); | 83 ASSERT(m_trackElement); |
160 ASSERT(m_trackElement->parentNode()); | 84 ASSERT(m_trackElement->parentNode()); |
161 | 85 |
162 size_t index = 0; | 86 size_t index = 0; |
163 for (HTMLTrackElement* track = Traversal<HTMLTrackElement>::firstChild(*m_tr
ackElement->parentNode()); track; track = Traversal<HTMLTrackElement>::nextSibli
ng(*track)) { | 87 for (HTMLTrackElement* track = Traversal<HTMLTrackElement>::firstChild(*m_tr
ackElement->parentNode()); track; track = Traversal<HTMLTrackElement>::nextSibli
ng(*track)) { |
164 if (!track->parentNode()) | 88 if (!track->parentNode()) |
165 continue; | 89 continue; |
166 if (track == m_trackElement) | 90 if (track == m_trackElement) |
167 return index; | 91 return index; |
168 ++index; | 92 ++index; |
169 } | 93 } |
170 ASSERT_NOT_REACHED(); | 94 ASSERT_NOT_REACHED(); |
171 | 95 |
172 return 0; | 96 return 0; |
173 } | 97 } |
174 | 98 |
175 DEFINE_TRACE(LoadableTextTrack) | 99 DEFINE_TRACE(LoadableTextTrack) |
176 { | 100 { |
177 visitor->trace(m_trackElement); | 101 visitor->trace(m_trackElement); |
178 visitor->trace(m_loader); | |
179 TextTrack::trace(visitor); | 102 TextTrack::trace(visitor); |
180 } | 103 } |
181 | 104 |
182 } // namespace blink | 105 } // namespace blink |
OLD | NEW |