Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1002)

Side by Side Diff: Source/core/html/HTMLTrackElement.cpp

Issue 999773002: Move loading machinery out of LoadableTextTrack (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/HTMLTrackElement.h ('k') | Source/core/html/track/LoadableTextTrack.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/HTMLTrackElement.h" 27 #include "core/html/HTMLTrackElement.h"
28 28
29 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
30 #include "core/HTMLNames.h" 29 #include "core/HTMLNames.h"
31 #include "core/dom/Document.h" 30 #include "core/dom/Document.h"
32 #include "core/events/Event.h" 31 #include "core/events/Event.h"
33 #include "core/frame/csp/ContentSecurityPolicy.h" 32 #include "core/frame/csp/ContentSecurityPolicy.h"
34 #include "core/html/HTMLMediaElement.h" 33 #include "core/html/HTMLMediaElement.h"
34 #include "core/html/track/LoadableTextTrack.h"
35 #include "platform/Logging.h" 35 #include "platform/Logging.h"
36 36
37 namespace blink { 37 namespace blink {
38 38
39 using namespace HTMLNames; 39 using namespace HTMLNames;
40 40
41 #if !LOG_DISABLED 41 #if !LOG_DISABLED
42 static String urlForLoggingTrack(const KURL& url) 42 static String urlForLoggingTrack(const KURL& url)
43 { 43 {
44 static const unsigned maximumURLLengthForLogging = 128; 44 static const unsigned maximumURLLengthForLogging = 128;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 return; 149 return;
150 150
151 // 2. If the text track's text track mode is not set to one of hidden or sho wing, abort these steps. 151 // 2. If the text track's text track mode is not set to one of hidden or sho wing, abort these steps.
152 if (ensureTrack()->mode() != TextTrack::hiddenKeyword() && ensureTrack()->mo de() != TextTrack::showingKeyword()) 152 if (ensureTrack()->mode() != TextTrack::hiddenKeyword() && ensureTrack()->mo de() != TextTrack::showingKeyword())
153 return; 153 return;
154 154
155 // 3. If the text track's track element does not have a media element as a p arent, abort these steps. 155 // 3. If the text track's track element does not have a media element as a p arent, abort these steps.
156 if (!mediaElement()) 156 if (!mediaElement())
157 return; 157 return;
158 158
159 // 4. Run the remainder of these steps asynchronously, allowing whatever cau sed these steps to run to continue. 159 // 4. Run the remainder of these steps in parallel, allowing whatever caused these steps to run to continue.
160 m_loadTimer.startOneShot(0, FROM_HERE); 160 m_loadTimer.startOneShot(0, FROM_HERE);
161 } 161 }
162 162
163 void HTMLTrackElement::loadTimerFired(Timer<HTMLTrackElement>*) 163 void HTMLTrackElement::loadTimerFired(Timer<HTMLTrackElement>*)
164 { 164 {
165 if (!fastHasAttribute(srcAttr))
166 return;
167
168 WTF_LOG(Media, "HTMLTrackElement::loadTimerFired"); 165 WTF_LOG(Media, "HTMLTrackElement::loadTimerFired");
169 166
170 // 6. Set the text track readiness state to loading. 167 // 5. Top: Await a stable state. The synchronous section consists of the fol lowing steps. (The steps in the
philipj_slow 2015/03/12 04:24:07 I think moving this to where the timer is started
fs 2015/03/12 15:22:18 Moved, FIXME added.
171 setReadyState(HTMLTrackElement::LOADING); 168 // synchronous section are marked with [X])
172 169
173 // 7. Let URL be the track URL of the track element. 170 // 6. [X] Set the text track readiness state to loading.
171 setReadyState(LOADING);
172
173 // 7. [X] Let URL be the track URL of the track element.
174 KURL url = getNonEmptyURLAttribute(srcAttr); 174 KURL url = getNonEmptyURLAttribute(srcAttr);
175 175
176 // 8. If the track element's parent is a media element then let CORS mode be the state of the parent media 176 // 8. [X] If the track element's parent is a media element then let CORS mod e be the state of the parent media
177 // element's crossorigin content attribute. Otherwise, let CORS mode be No C ORS. 177 // element's crossorigin content attribute. Otherwise, let CORS mode be No C ORS.
178 const AtomicString& corsMode = mediaElementCrossOriginAttribute();
179
180 // 9. End the synchronous section, continuing the remaining steps in paralle l.
181
182 // 10. If URL is not the empty string, perform a potentially CORS-enabled fe tch of URL, with the mode being CORS
183 // mode, the origin being the origin of the track element's node document, a nd the default origin behaviour set to
184 // fail.
178 if (!canLoadUrl(url)) { 185 if (!canLoadUrl(url)) {
179 didCompleteLoad(HTMLTrackElement::Failure); 186 didCompleteLoad(Failure);
180 return; 187 return;
181 } 188 }
182 189
183 ensureTrack()->scheduleLoad(url); 190 if (url == m_url) {
191 ASSERT(m_loader);
192 // If loading of the resource from this URL is in progress, return early .
193 if (m_loader->loadState() < TextTrackLoader::Finished)
194 return;
195
196 // The track element might have changed its state to Loading waiting for a call to didCompleteLoad to continue.
philipj_slow 2015/03/12 04:24:08 This is the track element, and this comment doesn'
fs 2015/03/12 15:22:18 Adding switch and dropping this comment (which I h
philipj_slow 2015/03/13 03:27:31 New structure looks much more sane to me, thanks!
197 didCompleteLoad(m_loader->loadState() == TextTrackLoader::Failed ? Failu re : Success);
198 return;
199 }
200
201 m_url = url;
202
203 if (m_loader)
204 m_loader->cancelLoad();
205
206 m_loader = TextTrackLoader::create(*this, document());
207 if (!m_loader->load(m_url, corsMode))
208 didCompleteLoad(Failure);
184 } 209 }
185 210
186 bool HTMLTrackElement::canLoadUrl(const KURL& url) 211 bool HTMLTrackElement::canLoadUrl(const KURL& url)
187 { 212 {
188 HTMLMediaElement* parent = mediaElement(); 213 HTMLMediaElement* parent = mediaElement();
189 if (!parent) 214 if (!parent)
190 return false; 215 return false;
191 216
192 // 4.8.10.12.3 Sourcing out-of-band text tracks
193
194 // 4. Download: If URL is not the empty string, perform a potentially CORS-e nabled fetch of URL, with the
195 // mode being the state of the media element's crossorigin content attribute , the origin being the
196 // origin of the media element's Document, and the default origin behaviour set to fail.
197 if (url.isEmpty()) 217 if (url.isEmpty())
198 return false; 218 return false;
199 219
200 if (!document().contentSecurityPolicy()->allowMediaFromSource(url)) { 220 if (!document().contentSecurityPolicy()->allowMediaFromSource(url)) {
201 WTF_LOG(Media, "HTMLTrackElement::canLoadUrl(%s) -> rejected by Content Security Policy", urlForLoggingTrack(url).utf8().data()); 221 WTF_LOG(Media, "HTMLTrackElement::canLoadUrl(%s) -> rejected by Content Security Policy", urlForLoggingTrack(url).utf8().data());
202 return false; 222 return false;
203 } 223 }
204 224
205 return true; 225 return true;
206 } 226 }
207 227
208 void HTMLTrackElement::didCompleteLoad(LoadStatus status) 228 void HTMLTrackElement::didCompleteLoad(LoadStatus status)
209 { 229 {
210 // 4.8.10.12.3 Sourcing out-of-band text tracks (continued) 230 // 10. ... (continued)
211 231
212 // 4. Download: ... 232 // If the fetching algorithm fails for any reason (network error, the server returns an error code, a cross-origin
213 // If the fetching algorithm fails for any reason (network error, the server returns an error 233 // check fails, etc), or if URL is the empty string, then queue a task to fi rst change the text track readiness
philipj_slow 2015/03/12 04:24:07 Firing the event here is indistinguishable from qu
fs 2015/03/12 15:22:18 Done.
214 // code, a cross-origin check fails, etc), or if URL is the empty string or has the wrong origin 234 // state to failed to load and then fire a simple event named error at the t rack element. This task must use the DOM
215 // as determined by the condition at the start of this step, or if the fetch ed resource is not in 235 // manipulation task source.
216 // a supported format, then queue a task to first change the text track read iness state to failed 236 //
217 // to load and then fire a simple event named error at the track element; an d then, once that task 237 // If the fetching algorithm does not fail, but the type of the resource is not a supported text track format, or
218 // is queued, move on to the step below labeled monitoring. 238 // the file was not successfully processed (e.g. the format in question is a n XML format and the file contained a
219 239 // well-formedness error that the XML specification requires be detected and reported to the application), then the
240 // task that is queued by the networking task source in which the aforementi oned problem is found must change the
241 // text track readiness state to failed to load and fire a simple event name d error at the track element.
220 if (status == Failure) { 242 if (status == Failure) {
221 setReadyState(HTMLTrackElement::TRACK_ERROR); 243 setReadyState(TRACK_ERROR);
222 dispatchEvent(Event::create(EventTypeNames::error), IGNORE_EXCEPTION); 244 dispatchEvent(Event::create(EventTypeNames::error));
223 return; 245 return;
224 } 246 }
225 247
226 // If the fetching algorithm does not fail, then the final task that is queu ed by the networking 248 // If the fetching algorithm does not fail, and the file was successfully pr ocessed, then the final task that is
227 // task source must run the following steps: 249 // queued by the networking task source, after it has finished parsing the d ata, must change the text track
228 // 1. Change the text track readiness state to loaded. 250 // readiness state to loaded, and fire a simple event named load at the trac k element.
229 setReadyState(HTMLTrackElement::LOADED); 251 setReadyState(LOADED);
252 dispatchEvent(Event::create(EventTypeNames::load));
253 }
230 254
231 // 2. If the file was successfully processed, fire a simple event named load at the 255 void HTMLTrackElement::newCuesAvailable(TextTrackLoader* loader)
232 // track element. 256 {
233 dispatchEvent(Event::create(EventTypeNames::load), IGNORE_EXCEPTION); 257 ASSERT_UNUSED(loader, m_loader == loader);
258 ASSERT(m_track);
259
260 WillBeHeapVector<RefPtrWillBeMember<TextTrackCue>> newCues;
261 m_loader->getNewCues(newCues);
262
263 m_track->addListOfCues(newCues);
264 }
265
266 void HTMLTrackElement::newRegionsAvailable(TextTrackLoader* loader)
267 {
268 ASSERT_UNUSED(loader, m_loader == loader);
269 ASSERT(m_track);
270
271 WillBeHeapVector<RefPtrWillBeMember<VTTRegion>> newRegions;
272 m_loader->getNewRegions(newRegions);
273
274 m_track->addRegions(newRegions);
275 }
276
277 void HTMLTrackElement::cueLoadingCompleted(TextTrackLoader* loader, bool loading Failed)
278 {
279 ASSERT_UNUSED(loader, m_loader == loader);
280
281 didCompleteLoad(loadingFailed ? Failure : Success);
234 } 282 }
235 283
236 // NOTE: The values in the TextTrack::ReadinessState enum must stay in sync with those in HTMLTrackElement::ReadyState. 284 // NOTE: The values in the TextTrack::ReadinessState enum must stay in sync with those in HTMLTrackElement::ReadyState.
237 static_assert(HTMLTrackElement::NONE == static_cast<HTMLTrackElement::ReadyState >(TextTrack::NotLoaded), "HTMLTrackElement::NONE should be in sync with TextTrac k::NotLoaded"); 285 static_assert(HTMLTrackElement::NONE == static_cast<HTMLTrackElement::ReadyState >(TextTrack::NotLoaded), "HTMLTrackElement::NONE should be in sync with TextTrac k::NotLoaded");
238 static_assert(HTMLTrackElement::LOADING == static_cast<HTMLTrackElement::ReadySt ate>(TextTrack::Loading), "HTMLTrackElement::LOADING should be in sync with Text Track::Loading"); 286 static_assert(HTMLTrackElement::LOADING == static_cast<HTMLTrackElement::ReadySt ate>(TextTrack::Loading), "HTMLTrackElement::LOADING should be in sync with Text Track::Loading");
239 static_assert(HTMLTrackElement::LOADED == static_cast<HTMLTrackElement::ReadySta te>(TextTrack::Loaded), "HTMLTrackElement::LOADED should be in sync with TextTra ck::Loaded"); 287 static_assert(HTMLTrackElement::LOADED == static_cast<HTMLTrackElement::ReadySta te>(TextTrack::Loaded), "HTMLTrackElement::LOADED should be in sync with TextTra ck::Loaded");
240 static_assert(HTMLTrackElement::TRACK_ERROR == static_cast<HTMLTrackElement::Rea dyState>(TextTrack::FailedToLoad), "HTMLTrackElement::TRACK_ERROR should be in s ync with TextTrack::FailedToLoad"); 288 static_assert(HTMLTrackElement::TRACK_ERROR == static_cast<HTMLTrackElement::Rea dyState>(TextTrack::FailedToLoad), "HTMLTrackElement::TRACK_ERROR should be in s ync with TextTrack::FailedToLoad");
241 289
242 void HTMLTrackElement::setReadyState(ReadyState state) 290 void HTMLTrackElement::setReadyState(ReadyState state)
243 { 291 {
(...skipping 19 matching lines...) Expand all
263 { 311 {
264 Element* parent = parentElement(); 312 Element* parent = parentElement();
265 if (isHTMLMediaElement(parent)) 313 if (isHTMLMediaElement(parent))
266 return toHTMLMediaElement(parent); 314 return toHTMLMediaElement(parent);
267 return nullptr; 315 return nullptr;
268 } 316 }
269 317
270 DEFINE_TRACE(HTMLTrackElement) 318 DEFINE_TRACE(HTMLTrackElement)
271 { 319 {
272 visitor->trace(m_track); 320 visitor->trace(m_track);
321 visitor->trace(m_loader);
273 HTMLElement::trace(visitor); 322 HTMLElement::trace(visitor);
274 } 323 }
275 324
276 } 325 }
OLDNEW
« no previous file with comments | « Source/core/html/HTMLTrackElement.h ('k') | Source/core/html/track/LoadableTextTrack.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698