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

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: Comments; Use switch for same-url case. 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
162 // 5. Top: Await a stable state. The synchronous section consists of the fol lowing steps. (The steps in the
163 // synchronous section are marked with [X])
164 // FIXME: We use a timer to approximate a "stable state" - i.e. this is not 100% per spec.
161 } 165 }
162 166
163 void HTMLTrackElement::loadTimerFired(Timer<HTMLTrackElement>*) 167 void HTMLTrackElement::loadTimerFired(Timer<HTMLTrackElement>*)
164 { 168 {
165 if (!fastHasAttribute(srcAttr))
166 return;
167
168 WTF_LOG(Media, "HTMLTrackElement::loadTimerFired"); 169 WTF_LOG(Media, "HTMLTrackElement::loadTimerFired");
169 170
170 // 6. Set the text track readiness state to loading. 171 // 6. [X] Set the text track readiness state to loading.
171 setReadyState(HTMLTrackElement::LOADING); 172 setReadyState(LOADING);
172 173
173 // 7. Let URL be the track URL of the track element. 174 // 7. [X] Let URL be the track URL of the track element.
174 KURL url = getNonEmptyURLAttribute(srcAttr); 175 KURL url = getNonEmptyURLAttribute(srcAttr);
175 176
176 // 8. If the track element's parent is a media element then let CORS mode be the state of the parent media 177 // 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. 178 // element's crossorigin content attribute. Otherwise, let CORS mode be No C ORS.
179 const AtomicString& corsMode = mediaElementCrossOriginAttribute();
180
181 // 9. End the synchronous section, continuing the remaining steps in paralle l.
182
183 // 10. If URL is not the empty string, perform a potentially CORS-enabled fe tch of URL, with the mode being CORS
184 // mode, the origin being the origin of the track element's node document, a nd the default origin behaviour set to
185 // fail.
178 if (!canLoadUrl(url)) { 186 if (!canLoadUrl(url)) {
179 didCompleteLoad(HTMLTrackElement::Failure); 187 didCompleteLoad(Failure);
180 return; 188 return;
181 } 189 }
182 190
183 ensureTrack()->scheduleLoad(url); 191 if (url == m_url) {
192 ASSERT(m_loader);
193 switch (m_loader->loadState()) {
194 case TextTrackLoader::Idle:
195 case TextTrackLoader::Loading:
196 // If loading of the resource from this URL is in progress, return e arly.
197 break;
198 case TextTrackLoader::Finished:
199 didCompleteLoad(Success);
200 break;
201 case TextTrackLoader::Failed:
202 didCompleteLoad(Failure);
203 break;
204 default:
205 ASSERT_NOT_REACHED();
206 }
207 return;
208 }
209
210 m_url = url;
211
212 if (m_loader)
213 m_loader->cancelLoad();
214
215 m_loader = TextTrackLoader::create(*this, document());
216 if (!m_loader->load(m_url, corsMode))
217 didCompleteLoad(Failure);
184 } 218 }
185 219
186 bool HTMLTrackElement::canLoadUrl(const KURL& url) 220 bool HTMLTrackElement::canLoadUrl(const KURL& url)
187 { 221 {
188 HTMLMediaElement* parent = mediaElement(); 222 HTMLMediaElement* parent = mediaElement();
189 if (!parent) 223 if (!parent)
190 return false; 224 return false;
191 225
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()) 226 if (url.isEmpty())
198 return false; 227 return false;
199 228
200 if (!document().contentSecurityPolicy()->allowMediaFromSource(url)) { 229 if (!document().contentSecurityPolicy()->allowMediaFromSource(url)) {
201 WTF_LOG(Media, "HTMLTrackElement::canLoadUrl(%s) -> rejected by Content Security Policy", urlForLoggingTrack(url).utf8().data()); 230 WTF_LOG(Media, "HTMLTrackElement::canLoadUrl(%s) -> rejected by Content Security Policy", urlForLoggingTrack(url).utf8().data());
202 return false; 231 return false;
203 } 232 }
204 233
205 return true; 234 return true;
206 } 235 }
207 236
208 void HTMLTrackElement::didCompleteLoad(LoadStatus status) 237 void HTMLTrackElement::didCompleteLoad(LoadStatus status)
209 { 238 {
210 // 4.8.10.12.3 Sourcing out-of-band text tracks (continued) 239 // 10. ... (continued)
211 240
212 // 4. Download: ... 241 // 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 242 // check fails, etc), or if URL is the empty string, then queue a task to fi rst change the text track readiness
214 // code, a cross-origin check fails, etc), or if URL is the empty string or has the wrong origin 243 // 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 244 // manipulation task source.
216 // a supported format, then queue a task to first change the text track read iness state to failed 245 //
217 // to load and then fire a simple event named error at the track element; an d then, once that task 246 // (Note: We don't "queue a task" here because this method will only be call ed from a timer - m_loadTimer or
218 // is queued, move on to the step below labeled monitoring. 247 // TextTrackLoader::m_cueLoadTimer - which should be a reasonable, and hopef ully non-observable, approximation of
219 248 // the spec text. I.e we could consider this to be run from the "networking task source".)
249 //
250 // If the fetching algorithm does not fail, but the type of the resource is not a supported text track format, or
251 // the file was not successfully processed (e.g. the format in question is a n XML format and the file contained a
252 // well-formedness error that the XML specification requires be detected and reported to the application), then the
253 // task that is queued by the networking task source in which the aforementi oned problem is found must change the
254 // text track readiness state to failed to load and fire a simple event name d error at the track element.
220 if (status == Failure) { 255 if (status == Failure) {
221 setReadyState(HTMLTrackElement::TRACK_ERROR); 256 setReadyState(TRACK_ERROR);
222 dispatchEvent(Event::create(EventTypeNames::error), IGNORE_EXCEPTION); 257 dispatchEvent(Event::create(EventTypeNames::error));
223 return; 258 return;
224 } 259 }
225 260
226 // If the fetching algorithm does not fail, then the final task that is queu ed by the networking 261 // 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: 262 // 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. 263 // readiness state to loaded, and fire a simple event named load at the trac k element.
229 setReadyState(HTMLTrackElement::LOADED); 264 setReadyState(LOADED);
265 dispatchEvent(Event::create(EventTypeNames::load));
266 }
230 267
231 // 2. If the file was successfully processed, fire a simple event named load at the 268 void HTMLTrackElement::newCuesAvailable(TextTrackLoader* loader)
232 // track element. 269 {
233 dispatchEvent(Event::create(EventTypeNames::load), IGNORE_EXCEPTION); 270 ASSERT_UNUSED(loader, m_loader == loader);
271 ASSERT(m_track);
272
273 WillBeHeapVector<RefPtrWillBeMember<TextTrackCue>> newCues;
274 m_loader->getNewCues(newCues);
275
276 m_track->addListOfCues(newCues);
277 }
278
279 void HTMLTrackElement::newRegionsAvailable(TextTrackLoader* loader)
280 {
281 ASSERT_UNUSED(loader, m_loader == loader);
282 ASSERT(m_track);
283
284 WillBeHeapVector<RefPtrWillBeMember<VTTRegion>> newRegions;
285 m_loader->getNewRegions(newRegions);
286
287 m_track->addRegions(newRegions);
288 }
289
290 void HTMLTrackElement::cueLoadingCompleted(TextTrackLoader* loader, bool loading Failed)
291 {
292 ASSERT_UNUSED(loader, m_loader == loader);
293
294 didCompleteLoad(loadingFailed ? Failure : Success);
234 } 295 }
235 296
236 // NOTE: The values in the TextTrack::ReadinessState enum must stay in sync with those in HTMLTrackElement::ReadyState. 297 // 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"); 298 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"); 299 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"); 300 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"); 301 static_assert(HTMLTrackElement::TRACK_ERROR == static_cast<HTMLTrackElement::Rea dyState>(TextTrack::FailedToLoad), "HTMLTrackElement::TRACK_ERROR should be in s ync with TextTrack::FailedToLoad");
241 302
242 void HTMLTrackElement::setReadyState(ReadyState state) 303 void HTMLTrackElement::setReadyState(ReadyState state)
243 { 304 {
(...skipping 19 matching lines...) Expand all
263 { 324 {
264 Element* parent = parentElement(); 325 Element* parent = parentElement();
265 if (isHTMLMediaElement(parent)) 326 if (isHTMLMediaElement(parent))
266 return toHTMLMediaElement(parent); 327 return toHTMLMediaElement(parent);
267 return nullptr; 328 return nullptr;
268 } 329 }
269 330
270 DEFINE_TRACE(HTMLTrackElement) 331 DEFINE_TRACE(HTMLTrackElement)
271 { 332 {
272 visitor->trace(m_track); 333 visitor->trace(m_track);
334 visitor->trace(m_loader);
273 HTMLElement::trace(visitor); 335 HTMLElement::trace(visitor);
274 } 336 }
275 337
276 } 338 }
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