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

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

Issue 244493002: Oilpan: add transition types to track interface objects. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Explicitly dispose of TextTrackList + fix handling of {Inband,Loadable}TextTrack Created 6 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple 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
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 299 }
300 300
301 HTMLMediaElement::~HTMLMediaElement() 301 HTMLMediaElement::~HTMLMediaElement()
302 { 302 {
303 WTF_LOG(Media, "HTMLMediaElement::~HTMLMediaElement"); 303 WTF_LOG(Media, "HTMLMediaElement::~HTMLMediaElement");
304 304
305 m_asyncEventQueue->close(); 305 m_asyncEventQueue->close();
306 306
307 setShouldDelayLoadEvent(false); 307 setShouldDelayLoadEvent(false);
308 308
309 if (m_textTracks) 309 if (m_textTracks) {
310 m_textTracks->clearOwner(); 310 m_textTracks->clearOwner();
311 m_textTracks->dispose();
haraken 2014/04/22 02:37:47 Can we merge clearOwner() into dispose()?
sof 2014/04/22 06:27:52 Done; dispose() remained.
312 }
311 313
312 if (m_mediaController) { 314 if (m_mediaController) {
313 m_mediaController->removeMediaElement(this); 315 m_mediaController->removeMediaElement(this);
314 m_mediaController = nullptr; 316 m_mediaController = nullptr;
315 } 317 }
316 318
317 closeMediaSource(); 319 closeMediaSource();
318 320
319 removeElementFromDocumentMap(this, &document()); 321 removeElementFromDocumentMap(this, &document());
320 322
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 1256
1255 void HTMLMediaElement::textTrackRemoveCues(TextTrack*, const TextTrackCueList* c ues) 1257 void HTMLMediaElement::textTrackRemoveCues(TextTrack*, const TextTrackCueList* c ues)
1256 { 1258 {
1257 WTF_LOG(Media, "HTMLMediaElement::textTrackRemoveCues"); 1259 WTF_LOG(Media, "HTMLMediaElement::textTrackRemoveCues");
1258 1260
1259 TrackDisplayUpdateScope scope(this); 1261 TrackDisplayUpdateScope scope(this);
1260 for (size_t i = 0; i < cues->length(); ++i) 1262 for (size_t i = 0; i < cues->length(); ++i)
1261 textTrackRemoveCue(cues->item(i)->track(), cues->item(i)); 1263 textTrackRemoveCue(cues->item(i)->track(), cues->item(i));
1262 } 1264 }
1263 1265
1264 void HTMLMediaElement::textTrackAddCue(TextTrack* track, PassRefPtr<TextTrackCue > cue) 1266 void HTMLMediaElement::textTrackAddCue(TextTrack* track, PassRefPtrWillBeRawPtr< TextTrackCue> cue)
1265 { 1267 {
1266 if (track->mode() == TextTrack::disabledKeyword()) 1268 if (track->mode() == TextTrack::disabledKeyword())
1267 return; 1269 return;
1268 1270
1269 // Negative duration cues need be treated in the interval tree as 1271 // Negative duration cues need be treated in the interval tree as
1270 // zero-length cues. 1272 // zero-length cues.
1271 double endTime = max(cue->startTime(), cue->endTime()); 1273 double endTime = max(cue->startTime(), cue->endTime());
1272 1274
1273 CueInterval interval = m_cueTree.createInterval(cue->startTime(), endTime, c ue.get()); 1275 CueInterval interval = m_cueTree.createInterval(cue->startTime(), endTime, c ue.get());
1274 if (!m_cueTree.contains(interval)) 1276 if (!m_cueTree.contains(interval))
1275 m_cueTree.add(interval); 1277 m_cueTree.add(interval);
1276 updateActiveTextTrackCues(currentTime()); 1278 updateActiveTextTrackCues(currentTime());
1277 } 1279 }
1278 1280
1279 void HTMLMediaElement::textTrackRemoveCue(TextTrack*, PassRefPtr<TextTrackCue> c ue) 1281 void HTMLMediaElement::textTrackRemoveCue(TextTrack*, PassRefPtrWillBeRawPtr<Tex tTrackCue> cue)
1280 { 1282 {
1281 // Negative duration cues need to be treated in the interval tree as 1283 // Negative duration cues need to be treated in the interval tree as
1282 // zero-length cues. 1284 // zero-length cues.
1283 double endTime = max(cue->startTime(), cue->endTime()); 1285 double endTime = max(cue->startTime(), cue->endTime());
1284 1286
1285 CueInterval interval = m_cueTree.createInterval(cue->startTime(), endTime, c ue.get()); 1287 CueInterval interval = m_cueTree.createInterval(cue->startTime(), endTime, c ue.get());
1286 m_cueTree.remove(interval); 1288 m_cueTree.remove(interval);
1287 1289
1288 // Since the cue will be removed from the media element and likely the 1290 // Since the cue will be removed from the media element and likely the
1289 // TextTrack might also be destructed, notifying the region of the cue 1291 // TextTrack might also be destructed, notifying the region of the cue
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after
2289 2291
2290 void HTMLMediaElement::forgetResourceSpecificTracks() 2292 void HTMLMediaElement::forgetResourceSpecificTracks()
2291 { 2293 {
2292 if (m_textTracks) { 2294 if (m_textTracks) {
2293 TrackDisplayUpdateScope scope(this); 2295 TrackDisplayUpdateScope scope(this);
2294 m_textTracks->removeAllInbandTracks(); 2296 m_textTracks->removeAllInbandTracks();
2295 closeCaptionTracksChanged(); 2297 closeCaptionTracksChanged();
2296 } 2298 }
2297 } 2299 }
2298 2300
2299 PassRefPtr<TextTrack> HTMLMediaElement::addTextTrack(const AtomicString& kind, c onst AtomicString& label, const AtomicString& language, ExceptionState& exceptio nState) 2301 PassRefPtrWillBeRawPtr<TextTrack> HTMLMediaElement::addTextTrack(const AtomicStr ing& kind, const AtomicString& label, const AtomicString& language, ExceptionSta te& exceptionState)
2300 { 2302 {
2301 // 4.8.10.12.4 Text track API 2303 // 4.8.10.12.4 Text track API
2302 // The addTextTrack(kind, label, language) method of media elements, when in voked, must run the following steps: 2304 // The addTextTrack(kind, label, language) method of media elements, when in voked, must run the following steps:
2303 2305
2304 // 1. If kind is not one of the following strings, then throw a SyntaxError exception and abort these steps 2306 // 1. If kind is not one of the following strings, then throw a SyntaxError exception and abort these steps
2305 if (!TextTrack::isValidKindKeyword(kind)) { 2307 if (!TextTrack::isValidKindKeyword(kind)) {
2306 exceptionState.throwDOMException(SyntaxError, "The 'kind' provided ('" + kind + "') is invalid."); 2308 exceptionState.throwDOMException(SyntaxError, "The 'kind' provided ('" + kind + "') is invalid.");
2307 return nullptr; 2309 return nullptr;
2308 } 2310 }
2309 2311
2310 // 2. If the label argument was omitted, let label be the empty string. 2312 // 2. If the label argument was omitted, let label be the empty string.
2311 // 3. If the language argument was omitted, let language be the empty string . 2313 // 3. If the language argument was omitted, let language be the empty string .
2312 // 4. Create a new TextTrack object. 2314 // 4. Create a new TextTrack object.
2313 2315
2314 // 5. Create a new text track corresponding to the new object, and set its t ext track kind to kind, its text 2316 // 5. Create a new text track corresponding to the new object, and set its t ext track kind to kind, its text
2315 // track label to label, its text track language to language... 2317 // track label to label, its text track language to language...
2316 RefPtr<TextTrack> textTrack = TextTrack::create(document(), kind, label, lan guage); 2318 RefPtrWillBeRawPtr<TextTrack> textTrack = TextTrack::create(document(), kind , label, language);
2317 2319
2318 // Note, due to side effects when changing track parameters, we have to 2320 // Note, due to side effects when changing track parameters, we have to
2319 // first append the track to the text track list. 2321 // first append the track to the text track list.
2320 2322
2321 // 6. Add the new text track to the media element's list of text tracks. 2323 // 6. Add the new text track to the media element's list of text tracks.
2322 addTextTrack(textTrack.get()); 2324 addTextTrack(textTrack.get());
2323 2325
2324 // ... its text track readiness state to the text track loaded state ... 2326 // ... its text track readiness state to the text track loaded state ...
2325 textTrack->setReadinessState(TextTrack::Loaded); 2327 textTrack->setReadinessState(TextTrack::Loaded);
2326 2328
(...skipping 10 matching lines...) Expand all
2337 2339
2338 return m_textTracks.get(); 2340 return m_textTracks.get();
2339 } 2341 }
2340 2342
2341 void HTMLMediaElement::didAddTrackElement(HTMLTrackElement* trackElement) 2343 void HTMLMediaElement::didAddTrackElement(HTMLTrackElement* trackElement)
2342 { 2344 {
2343 // 4.8.10.12.3 Sourcing out-of-band text tracks 2345 // 4.8.10.12.3 Sourcing out-of-band text tracks
2344 // When a track element's parent element changes and the new parent is a med ia element, 2346 // When a track element's parent element changes and the new parent is a med ia element,
2345 // then the user agent must add the track element's corresponding text track to the 2347 // then the user agent must add the track element's corresponding text track to the
2346 // media element's list of text tracks ... [continues in TextTrackList::appe nd] 2348 // media element's list of text tracks ... [continues in TextTrackList::appe nd]
2347 RefPtr<TextTrack> textTrack = trackElement->track(); 2349 RefPtrWillBeRawPtr<TextTrack> textTrack = trackElement->track();
2348 if (!textTrack) 2350 if (!textTrack)
2349 return; 2351 return;
2350 2352
2351 addTextTrack(textTrack.get()); 2353 addTextTrack(textTrack.get());
2352 2354
2353 // Do not schedule the track loading until parsing finishes so we don't star t before all tracks 2355 // Do not schedule the track loading until parsing finishes so we don't star t before all tracks
2354 // in the markup have been added. 2356 // in the markup have been added.
2355 if (isFinishedParsingChildren()) 2357 if (isFinishedParsingChildren())
2356 scheduleDelayedAction(LoadTextTrackResource); 2358 scheduleDelayedAction(LoadTextTrackResource);
2357 2359
2358 if (hasMediaControls()) 2360 if (hasMediaControls())
2359 mediaControls()->closedCaptionTracksChanged(); 2361 mediaControls()->closedCaptionTracksChanged();
2360 } 2362 }
2361 2363
2362 void HTMLMediaElement::didRemoveTrackElement(HTMLTrackElement* trackElement) 2364 void HTMLMediaElement::didRemoveTrackElement(HTMLTrackElement* trackElement)
2363 { 2365 {
2364 #if !LOG_DISABLED 2366 #if !LOG_DISABLED
2365 KURL url = trackElement->getNonEmptyURLAttribute(srcAttr); 2367 KURL url = trackElement->getNonEmptyURLAttribute(srcAttr);
2366 WTF_LOG(Media, "HTMLMediaElement::didRemoveTrackElement - 'src' is %s", urlF orLoggingMedia(url).utf8().data()); 2368 WTF_LOG(Media, "HTMLMediaElement::didRemoveTrackElement - 'src' is %s", urlF orLoggingMedia(url).utf8().data());
2367 #endif 2369 #endif
2368 2370
2369 RefPtr<TextTrack> textTrack = trackElement->track(); 2371 RefPtrWillBeRawPtr<TextTrack> textTrack = trackElement->track();
2370 if (!textTrack) 2372 if (!textTrack)
2371 return; 2373 return;
2372 2374
2373 textTrack->setHasBeenConfigured(false); 2375 textTrack->setHasBeenConfigured(false);
2374 2376
2375 if (!m_textTracks) 2377 if (!m_textTracks)
2376 return; 2378 return;
2377 2379
2378 // 4.8.10.12.3 Sourcing out-of-band text tracks 2380 // 4.8.10.12.3 Sourcing out-of-band text tracks
2379 // When a track element's parent element changes and the old parent was a me dia element, 2381 // When a track element's parent element changes and the old parent was a me dia element,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2421 2423
2422 void HTMLMediaElement::configureTextTrackGroup(const TrackGroup& group) 2424 void HTMLMediaElement::configureTextTrackGroup(const TrackGroup& group)
2423 { 2425 {
2424 ASSERT(group.tracks.size()); 2426 ASSERT(group.tracks.size());
2425 2427
2426 WTF_LOG(Media, "HTMLMediaElement::configureTextTrackGroup(%d)", group.kind); 2428 WTF_LOG(Media, "HTMLMediaElement::configureTextTrackGroup(%d)", group.kind);
2427 2429
2428 Settings* settings = document().settings(); 2430 Settings* settings = document().settings();
2429 2431
2430 // First, find the track in the group that should be enabled (if any). 2432 // First, find the track in the group that should be enabled (if any).
2431 Vector<RefPtr<TextTrack> > currentlyEnabledTracks; 2433 WillBeHeapVector<RefPtrWillBeMember<TextTrack> > currentlyEnabledTracks;
2432 RefPtr<TextTrack> trackToEnable; 2434 RefPtrWillBeRawPtr<TextTrack> trackToEnable = nullptr;
2433 RefPtr<TextTrack> defaultTrack; 2435 RefPtrWillBeRawPtr<TextTrack> defaultTrack = nullptr;
2434 RefPtr<TextTrack> fallbackTrack; 2436 RefPtrWillBeRawPtr<TextTrack> fallbackTrack = nullptr;
2435 int highestTrackScore = 0; 2437 int highestTrackScore = 0;
2436 for (size_t i = 0; i < group.tracks.size(); ++i) { 2438 for (size_t i = 0; i < group.tracks.size(); ++i) {
2437 RefPtr<TextTrack> textTrack = group.tracks[i]; 2439 RefPtrWillBeRawPtr<TextTrack> textTrack = group.tracks[i];
2438 2440
2439 if (m_processingPreferenceChange && textTrack->mode() == TextTrack::show ingKeyword()) 2441 if (m_processingPreferenceChange && textTrack->mode() == TextTrack::show ingKeyword())
2440 currentlyEnabledTracks.append(textTrack); 2442 currentlyEnabledTracks.append(textTrack);
2441 2443
2442 int trackScore = textTrackSelectionScore(*textTrack, settings); 2444 int trackScore = textTrackSelectionScore(*textTrack, settings);
2443 if (trackScore) { 2445 if (trackScore) {
2444 // * If the text track kind is { [subtitles or captions] [descriptio ns] } and the user has indicated an interest in having a 2446 // * If the text track kind is { [subtitles or captions] [descriptio ns] } and the user has indicated an interest in having a
2445 // track with this text track kind, text track language, and text tr ack label enabled, and there is no 2447 // track with this text track kind, text track language, and text tr ack label enabled, and there is no
2446 // other text track in the media element's list of text tracks with a text track kind of either subtitles 2448 // other text track in the media element's list of text tracks with a text track kind of either subtitles
2447 // or captions whose text track mode is showing 2449 // or captions whose text track mode is showing
(...skipping 25 matching lines...) Expand all
2473 // If no track matches the user's preferred language and non was marked 'def ault', enable the first track 2475 // If no track matches the user's preferred language and non was marked 'def ault', enable the first track
2474 // because the user has explicitly stated a preference for this kind of trac k. 2476 // because the user has explicitly stated a preference for this kind of trac k.
2475 if (!fallbackTrack && m_closedCaptionsVisible && group.kind == TrackGroup::C aptionsAndSubtitles) 2477 if (!fallbackTrack && m_closedCaptionsVisible && group.kind == TrackGroup::C aptionsAndSubtitles)
2476 fallbackTrack = group.tracks[0]; 2478 fallbackTrack = group.tracks[0];
2477 2479
2478 if (!trackToEnable && fallbackTrack) 2480 if (!trackToEnable && fallbackTrack)
2479 trackToEnable = fallbackTrack; 2481 trackToEnable = fallbackTrack;
2480 2482
2481 if (currentlyEnabledTracks.size()) { 2483 if (currentlyEnabledTracks.size()) {
2482 for (size_t i = 0; i < currentlyEnabledTracks.size(); ++i) { 2484 for (size_t i = 0; i < currentlyEnabledTracks.size(); ++i) {
2483 RefPtr<TextTrack> textTrack = currentlyEnabledTracks[i]; 2485 RefPtrWillBeRawPtr<TextTrack> textTrack = currentlyEnabledTracks[i];
2484 if (textTrack != trackToEnable) 2486 if (textTrack != trackToEnable)
2485 textTrack->setMode(TextTrack::disabledKeyword()); 2487 textTrack->setMode(TextTrack::disabledKeyword());
2486 } 2488 }
2487 } 2489 }
2488 2490
2489 if (trackToEnable) 2491 if (trackToEnable)
2490 trackToEnable->setMode(TextTrack::showingKeyword()); 2492 trackToEnable->setMode(TextTrack::showingKeyword());
2491 } 2493 }
2492 2494
2493 void HTMLMediaElement::configureTextTracks() 2495 void HTMLMediaElement::configureTextTracks()
2494 { 2496 {
2495 TrackGroup captionAndSubtitleTracks(TrackGroup::CaptionsAndSubtitles); 2497 TrackGroup captionAndSubtitleTracks(TrackGroup::CaptionsAndSubtitles);
2496 TrackGroup descriptionTracks(TrackGroup::Description); 2498 TrackGroup descriptionTracks(TrackGroup::Description);
2497 TrackGroup chapterTracks(TrackGroup::Chapter); 2499 TrackGroup chapterTracks(TrackGroup::Chapter);
2498 TrackGroup metadataTracks(TrackGroup::Metadata); 2500 TrackGroup metadataTracks(TrackGroup::Metadata);
2499 TrackGroup otherTracks(TrackGroup::Other); 2501 TrackGroup otherTracks(TrackGroup::Other);
2500 2502
2501 if (!m_textTracks) 2503 if (!m_textTracks)
2502 return; 2504 return;
2503 2505
2504 for (size_t i = 0; i < m_textTracks->length(); ++i) { 2506 for (size_t i = 0; i < m_textTracks->length(); ++i) {
2505 RefPtr<TextTrack> textTrack = m_textTracks->item(i); 2507 RefPtrWillBeRawPtr<TextTrack> textTrack = m_textTracks->item(i);
2506 if (!textTrack) 2508 if (!textTrack)
2507 continue; 2509 continue;
2508 2510
2509 String kind = textTrack->kind(); 2511 String kind = textTrack->kind();
2510 TrackGroup* currentGroup; 2512 TrackGroup* currentGroup;
2511 if (kind == TextTrack::subtitlesKeyword() || kind == TextTrack::captions Keyword()) 2513 if (kind == TextTrack::subtitlesKeyword() || kind == TextTrack::captions Keyword())
2512 currentGroup = &captionAndSubtitleTracks; 2514 currentGroup = &captionAndSubtitleTracks;
2513 else if (kind == TextTrack::descriptionsKeyword()) 2515 else if (kind == TextTrack::descriptionsKeyword())
2514 currentGroup = &descriptionTracks; 2516 currentGroup = &descriptionTracks;
2515 else if (kind == TextTrack::chaptersKeyword()) 2517 else if (kind == TextTrack::chaptersKeyword())
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after
3384 { 3386 {
3385 if (!m_textTracks) 3387 if (!m_textTracks)
3386 return; 3388 return;
3387 3389
3388 // Mark all tracks as not "configured" so that configureTextTracks() 3390 // Mark all tracks as not "configured" so that configureTextTracks()
3389 // will reconsider which tracks to display in light of new user preferences 3391 // will reconsider which tracks to display in light of new user preferences
3390 // (e.g. default tracks should not be displayed if the user has turned off 3392 // (e.g. default tracks should not be displayed if the user has turned off
3391 // captions and non-default tracks should be displayed based on language 3393 // captions and non-default tracks should be displayed based on language
3392 // preferences if the user has turned captions on). 3394 // preferences if the user has turned captions on).
3393 for (unsigned i = 0; i < m_textTracks->length(); ++i) { 3395 for (unsigned i = 0; i < m_textTracks->length(); ++i) {
3394 RefPtr<TextTrack> textTrack = m_textTracks->item(i); 3396 RefPtrWillBeRawPtr<TextTrack> textTrack = m_textTracks->item(i);
3395 String kind = textTrack->kind(); 3397 String kind = textTrack->kind();
3396 3398
3397 if (kind == TextTrack::subtitlesKeyword() || kind == TextTrack::captions Keyword()) 3399 if (kind == TextTrack::subtitlesKeyword() || kind == TextTrack::captions Keyword())
3398 textTrack->setHasBeenConfigured(false); 3400 textTrack->setHasBeenConfigured(false);
3399 } 3401 }
3400 configureTextTracks(); 3402 configureTextTracks();
3401 } 3403 }
3402 3404
3403 bool HTMLMediaElement::willRespondToMouseClickEvents() 3405 bool HTMLMediaElement::willRespondToMouseClickEvents()
3404 { 3406 {
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
3642 return fastHasAttribute(controlsAttr); 3644 return fastHasAttribute(controlsAttr);
3643 } 3645 }
3644 3646
3645 void HTMLMediaElement::trace(Visitor* visitor) 3647 void HTMLMediaElement::trace(Visitor* visitor)
3646 { 3648 {
3647 Supplementable<HTMLMediaElement>::trace(visitor); 3649 Supplementable<HTMLMediaElement>::trace(visitor);
3648 HTMLElement::trace(visitor); 3650 HTMLElement::trace(visitor);
3649 } 3651 }
3650 3652
3651 } 3653 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698