OLD | NEW |
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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 addElementToDocumentMap(this, &document); | 326 addElementToDocumentMap(this, &document); |
327 } | 327 } |
328 | 328 |
329 HTMLMediaElement::~HTMLMediaElement() | 329 HTMLMediaElement::~HTMLMediaElement() |
330 { | 330 { |
331 WTF_LOG(Media, "HTMLMediaElement::~HTMLMediaElement"); | 331 WTF_LOG(Media, "HTMLMediaElement::~HTMLMediaElement"); |
332 | 332 |
333 m_asyncEventQueue->close(); | 333 m_asyncEventQueue->close(); |
334 | 334 |
335 setShouldDelayLoadEvent(false); | 335 setShouldDelayLoadEvent(false); |
336 | |
337 if (m_textTracks) | 336 if (m_textTracks) |
338 m_textTracks->clearOwnerAndClients(); | 337 m_textTracks->clearOwner(); |
| 338 if (m_textTracks) { |
| 339 for (unsigned i = 0; i < m_textTracks->length(); ++i) |
| 340 m_textTracks->item(i)->clearClient(); |
| 341 } |
339 | 342 |
340 if (m_mediaController) { | 343 if (m_mediaController) { |
341 m_mediaController->removeMediaElement(this); | 344 m_mediaController->removeMediaElement(this); |
342 m_mediaController = nullptr; | 345 m_mediaController = nullptr; |
343 } | 346 } |
344 | 347 |
345 closeMediaSource(); | 348 closeMediaSource(); |
346 | 349 |
347 setMediaKeysInternal(0); | 350 setMediaKeysInternal(0); |
348 | 351 |
(...skipping 2091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2440 m_lastTimeUpdateEventWallTime = now; | 2443 m_lastTimeUpdateEventWallTime = now; |
2441 m_lastTimeUpdateEventMovieTime = movieTime; | 2444 m_lastTimeUpdateEventMovieTime = movieTime; |
2442 } | 2445 } |
2443 } | 2446 } |
2444 | 2447 |
2445 bool HTMLMediaElement::canPlay() const | 2448 bool HTMLMediaElement::canPlay() const |
2446 { | 2449 { |
2447 return paused() || ended() || m_readyState < HAVE_METADATA; | 2450 return paused() || ended() || m_readyState < HAVE_METADATA; |
2448 } | 2451 } |
2449 | 2452 |
2450 void HTMLMediaElement::mediaPlayerDidAddTextTrack(WebInbandTextTrack* webTrack) | 2453 void HTMLMediaElement::mediaPlayerDidAddTrack(WebInbandTextTrack* webTrack) |
2451 { | 2454 { |
2452 if (!RuntimeEnabledFeatures::videoTrackEnabled()) | 2455 if (!RuntimeEnabledFeatures::videoTrackEnabled()) |
2453 return; | 2456 return; |
2454 | 2457 |
2455 // 4.8.10.12.2 Sourcing in-band text tracks | 2458 // 4.8.10.12.2 Sourcing in-band text tracks |
2456 // 1. Associate the relevant data with a new text track and its correspondin
g new TextTrack object. | 2459 // 1. Associate the relevant data with a new text track and its correspondin
g new TextTrack object. |
2457 RefPtr<InbandTextTrack> textTrack = InbandTextTrack::create(document(), this
, webTrack); | 2460 RefPtr<InbandTextTrack> textTrack = InbandTextTrack::create(document(), this
, webTrack); |
2458 | 2461 |
2459 // 2. Set the new text track's kind, label, and language based on the semant
ics of the relevant data, | 2462 // 2. Set the new text track's kind, label, and language based on the semant
ics of the relevant data, |
2460 // as defined by the relevant specification. If there is no label in that da
ta, then the label must | 2463 // as defined by the relevant specification. If there is no label in that da
ta, then the label must |
(...skipping 11 matching lines...) Expand all Loading... |
2472 | 2475 |
2473 // 7. Set the new text track's mode to the mode consistent with the user's p
references and the requirements of | 2476 // 7. Set the new text track's mode to the mode consistent with the user's p
references and the requirements of |
2474 // the relevant specification for the data. | 2477 // the relevant specification for the data. |
2475 // - This will happen in configureTextTracks() | 2478 // - This will happen in configureTextTracks() |
2476 scheduleDelayedAction(LoadTextTrackResource); | 2479 scheduleDelayedAction(LoadTextTrackResource); |
2477 | 2480 |
2478 // 8. Add the new text track to the media element's list of text tracks. | 2481 // 8. Add the new text track to the media element's list of text tracks. |
2479 // 9. Fire an event with the name addtrack, that does not bubble and is not
cancelable, and that uses the TrackEvent | 2482 // 9. Fire an event with the name addtrack, that does not bubble and is not
cancelable, and that uses the TrackEvent |
2480 // interface, with the track attribute initialized to the text track's TextT
rack object, at the media element's | 2483 // interface, with the track attribute initialized to the text track's TextT
rack object, at the media element's |
2481 // textTracks attribute's TextTrackList object. | 2484 // textTracks attribute's TextTrackList object. |
2482 addTextTrack(textTrack.get()); | 2485 addTrack(textTrack.get()); |
2483 } | 2486 } |
2484 | 2487 |
2485 void HTMLMediaElement::mediaPlayerDidRemoveTextTrack(WebInbandTextTrack* webTrac
k) | 2488 void HTMLMediaElement::mediaPlayerDidRemoveTrack(WebInbandTextTrack* webTrack) |
2486 { | 2489 { |
2487 if (!RuntimeEnabledFeatures::videoTrackEnabled()) | 2490 if (!RuntimeEnabledFeatures::videoTrackEnabled()) |
2488 return; | 2491 return; |
2489 | 2492 |
2490 if (!m_textTracks) | 2493 if (!m_textTracks) |
2491 return; | 2494 return; |
2492 | 2495 |
2493 // This cast is safe because we created the InbandTextTrack with the WebInba
ndTextTrack | 2496 // This cast is safe because we created the InbandTextTrack with the WebInba
ndTextTrack |
2494 // passed to mediaPlayerDidAddTextTrack. | 2497 // passed to mediaPlayerDidAddTrack. |
2495 RefPtr<InbandTextTrack> textTrack = static_cast<InbandTextTrack*>(webTrack->
client()); | 2498 RefPtr<InbandTextTrack> textTrack = static_cast<InbandTextTrack*>(webTrack->
client()); |
2496 if (!textTrack) | 2499 if (!textTrack) |
2497 return; | 2500 return; |
2498 | 2501 |
2499 removeTextTrack(textTrack.get()); | 2502 removeTrack(textTrack.get()); |
2500 } | 2503 } |
2501 | 2504 |
2502 void HTMLMediaElement::closeCaptionTracksChanged() | 2505 void HTMLMediaElement::closeCaptionTracksChanged() |
2503 { | 2506 { |
2504 if (hasMediaControls()) | 2507 if (hasMediaControls()) |
2505 mediaControls()->closedCaptionTracksChanged(); | 2508 mediaControls()->closedCaptionTracksChanged(); |
2506 } | 2509 } |
2507 | 2510 |
2508 void HTMLMediaElement::addTextTrack(TextTrack* track) | 2511 void HTMLMediaElement::addTrack(TextTrack* track) |
2509 { | 2512 { |
2510 textTracks()->append(track); | 2513 textTracks()->append(track); |
2511 | 2514 |
2512 closeCaptionTracksChanged(); | 2515 closeCaptionTracksChanged(); |
2513 } | 2516 } |
2514 | 2517 |
2515 void HTMLMediaElement::removeTextTrack(TextTrack* track) | 2518 void HTMLMediaElement::removeTrack(TextTrack* track) |
2516 { | 2519 { |
2517 TrackDisplayUpdateScope scope(this); | 2520 TrackDisplayUpdateScope scope(this); |
2518 TextTrackCueList* cues = track->cues(); | 2521 TextTrackCueList* cues = track->cues(); |
2519 if (cues) | 2522 if (cues) |
2520 textTrackRemoveCues(track, cues); | 2523 textTrackRemoveCues(track, cues); |
2521 m_textTracks->remove(track); | 2524 m_textTracks->remove(track); |
2522 | 2525 |
2523 closeCaptionTracksChanged(); | 2526 closeCaptionTracksChanged(); |
2524 } | 2527 } |
2525 | 2528 |
2526 void HTMLMediaElement::removeAllInbandTracks() | 2529 void HTMLMediaElement::removeAllInbandTracks() |
2527 { | 2530 { |
2528 if (!m_textTracks) | 2531 if (!m_textTracks) |
2529 return; | 2532 return; |
2530 | 2533 |
2531 TrackDisplayUpdateScope scope(this); | 2534 TrackDisplayUpdateScope scope(this); |
2532 for (int i = m_textTracks->length() - 1; i >= 0; --i) { | 2535 for (int i = m_textTracks->length() - 1; i >= 0; --i) { |
2533 TextTrack* track = m_textTracks->item(i); | 2536 TextTrack* track = m_textTracks->item(i); |
2534 | 2537 |
2535 if (track->trackType() == TextTrack::InBand) | 2538 if (track->trackType() == TextTrack::InBand) |
2536 removeTextTrack(track); | 2539 removeTrack(track); |
2537 } | 2540 } |
2538 } | 2541 } |
2539 | 2542 |
2540 PassRefPtr<TextTrack> HTMLMediaElement::addTextTrack(const AtomicString& kind, c
onst AtomicString& label, const AtomicString& language, ExceptionState& exceptio
nState) | 2543 PassRefPtr<TextTrack> HTMLMediaElement::addTextTrack(const AtomicString& kind, c
onst AtomicString& label, const AtomicString& language, ExceptionState& exceptio
nState) |
2541 { | 2544 { |
2542 ASSERT(RuntimeEnabledFeatures::videoTrackEnabled()); | 2545 ASSERT(RuntimeEnabledFeatures::videoTrackEnabled()); |
2543 | 2546 |
2544 // 4.8.10.12.4 Text track API | 2547 // 4.8.10.12.4 Text track API |
2545 // The addTextTrack(kind, label, language) method of media elements, when in
voked, must run the following steps: | 2548 // The addTextTrack(kind, label, language) method of media elements, when in
voked, must run the following steps: |
2546 | 2549 |
2547 // 1. If kind is not one of the following strings, then throw a SyntaxError
exception and abort these steps | 2550 // 1. If kind is not one of the following strings, then throw a SyntaxError
exception and abort these steps |
2548 if (!TextTrack::isValidKindKeyword(kind)) { | 2551 if (!TextTrack::isValidKindKeyword(kind)) { |
2549 exceptionState.throwDOMException(SyntaxError, "The 'kind' provided ('" +
kind + "') is invalid."); | 2552 exceptionState.throwDOMException(SyntaxError, "The 'kind' provided ('" +
kind + "') is invalid."); |
2550 return nullptr; | 2553 return nullptr; |
2551 } | 2554 } |
2552 | 2555 |
2553 // 2. If the label argument was omitted, let label be the empty string. | 2556 // 2. If the label argument was omitted, let label be the empty string. |
2554 // 3. If the language argument was omitted, let language be the empty string
. | 2557 // 3. If the language argument was omitted, let language be the empty string
. |
2555 // 4. Create a new TextTrack object. | 2558 // 4. Create a new TextTrack object. |
2556 | 2559 |
2557 // 5. Create a new text track corresponding to the new object, and set its t
ext track kind to kind, its text | 2560 // 5. Create a new text track corresponding to the new object, and set its t
ext track kind to kind, its text |
2558 // track label to label, its text track language to language... | 2561 // track label to label, its text track language to language... |
2559 RefPtr<TextTrack> textTrack = TextTrack::create(document(), this, kind, labe
l, language); | 2562 RefPtr<TextTrack> textTrack = TextTrack::create(document(), this, kind, labe
l, language); |
2560 | 2563 |
2561 // Note, due to side effects when changing track parameters, we have to | 2564 // Note, due to side effects when changing track parameters, we have to |
2562 // first append the track to the text track list. | 2565 // first append the track to the text track list. |
2563 | 2566 |
2564 // 6. Add the new text track to the media element's list of text tracks. | 2567 // 6. Add the new text track to the media element's list of text tracks. |
2565 addTextTrack(textTrack.get()); | 2568 addTrack(textTrack.get()); |
2566 | 2569 |
2567 // ... its text track readiness state to the text track loaded state ... | 2570 // ... its text track readiness state to the text track loaded state ... |
2568 textTrack->setReadinessState(TextTrack::Loaded); | 2571 textTrack->setReadinessState(TextTrack::Loaded); |
2569 | 2572 |
2570 // ... its text track mode to the text track hidden mode, and its text track
list of cues to an empty list ... | 2573 // ... its text track mode to the text track hidden mode, and its text track
list of cues to an empty list ... |
2571 textTrack->setMode(TextTrack::hiddenKeyword()); | 2574 textTrack->setMode(TextTrack::hiddenKeyword()); |
2572 | 2575 |
2573 return textTrack.release(); | 2576 return textTrack.release(); |
2574 } | 2577 } |
2575 | 2578 |
2576 TextTrackList* HTMLMediaElement::textTracks() | 2579 TextTrackList* HTMLMediaElement::textTracks() |
2577 { | 2580 { |
2578 ASSERT(RuntimeEnabledFeatures::videoTrackEnabled()); | 2581 ASSERT(RuntimeEnabledFeatures::videoTrackEnabled()); |
2579 | 2582 |
2580 if (!m_textTracks) | 2583 if (!m_textTracks) |
2581 m_textTracks = TextTrackList::create(this); | 2584 m_textTracks = TextTrackList::create(this); |
2582 | 2585 |
2583 return m_textTracks.get(); | 2586 return m_textTracks.get(); |
2584 } | 2587 } |
2585 | 2588 |
2586 void HTMLMediaElement::didAddTrackElement(HTMLTrackElement* trackElement) | 2589 void HTMLMediaElement::didAddTrack(HTMLTrackElement* trackElement) |
2587 { | 2590 { |
2588 ASSERT(trackElement->hasTagName(trackTag)); | 2591 ASSERT(trackElement->hasTagName(trackTag)); |
2589 | 2592 |
2590 if (!RuntimeEnabledFeatures::videoTrackEnabled()) | 2593 if (!RuntimeEnabledFeatures::videoTrackEnabled()) |
2591 return; | 2594 return; |
2592 | 2595 |
2593 // 4.8.10.12.3 Sourcing out-of-band text tracks | 2596 // 4.8.10.12.3 Sourcing out-of-band text tracks |
2594 // When a track element's parent element changes and the new parent is a med
ia element, | 2597 // When a track element's parent element changes and the new parent is a med
ia element, |
2595 // then the user agent must add the track element's corresponding text track
to the | 2598 // then the user agent must add the track element's corresponding text track
to the |
2596 // media element's list of text tracks ... [continues in TextTrackList::appe
nd] | 2599 // media element's list of text tracks ... [continues in TextTrackList::appe
nd] |
2597 RefPtr<TextTrack> textTrack = trackElement->track(); | 2600 RefPtr<TextTrack> textTrack = trackElement->track(); |
2598 if (!textTrack) | 2601 if (!textTrack) |
2599 return; | 2602 return; |
2600 | 2603 |
2601 addTextTrack(textTrack.get()); | 2604 addTrack(textTrack.get()); |
2602 | 2605 |
2603 // Do not schedule the track loading until parsing finishes so we don't star
t before all tracks | 2606 // Do not schedule the track loading until parsing finishes so we don't star
t before all tracks |
2604 // in the markup have been added. | 2607 // in the markup have been added. |
2605 if (isFinishedParsingChildren()) | 2608 if (isFinishedParsingChildren()) |
2606 scheduleDelayedAction(LoadTextTrackResource); | 2609 scheduleDelayedAction(LoadTextTrackResource); |
2607 | 2610 |
2608 if (hasMediaControls()) | 2611 if (hasMediaControls()) |
2609 mediaControls()->closedCaptionTracksChanged(); | 2612 mediaControls()->closedCaptionTracksChanged(); |
2610 } | 2613 } |
2611 | 2614 |
2612 void HTMLMediaElement::didRemoveTrackElement(HTMLTrackElement* trackElement) | 2615 void HTMLMediaElement::didRemoveTrack(HTMLTrackElement* trackElement) |
2613 { | 2616 { |
2614 ASSERT(trackElement->hasTagName(trackTag)); | 2617 ASSERT(trackElement->hasTagName(trackTag)); |
2615 | 2618 |
2616 if (!RuntimeEnabledFeatures::videoTrackEnabled()) | 2619 if (!RuntimeEnabledFeatures::videoTrackEnabled()) |
2617 return; | 2620 return; |
2618 | 2621 |
2619 #if !LOG_DISABLED | 2622 #if !LOG_DISABLED |
2620 if (trackElement->hasTagName(trackTag)) { | 2623 if (trackElement->hasTagName(trackTag)) { |
2621 KURL url = trackElement->getNonEmptyURLAttribute(srcAttr); | 2624 KURL url = trackElement->getNonEmptyURLAttribute(srcAttr); |
2622 WTF_LOG(Media, "HTMLMediaElement::didRemoveTrackElement - 'src' is %s",
urlForLoggingMedia(url).utf8().data()); | 2625 WTF_LOG(Media, "HTMLMediaElement::didRemoveTrack - 'src' is %s", urlForL
oggingMedia(url).utf8().data()); |
2623 } | 2626 } |
2624 #endif | 2627 #endif |
2625 | 2628 |
2626 RefPtr<TextTrack> textTrack = trackElement->track(); | 2629 RefPtr<TextTrack> textTrack = trackElement->track(); |
2627 if (!textTrack) | 2630 if (!textTrack) |
2628 return; | 2631 return; |
2629 | 2632 |
2630 textTrack->setHasBeenConfigured(false); | 2633 textTrack->setHasBeenConfigured(false); |
2631 | 2634 |
2632 if (!m_textTracks) | 2635 if (!m_textTracks) |
2633 return; | 2636 return; |
2634 | 2637 |
2635 // 4.8.10.12.3 Sourcing out-of-band text tracks | 2638 // 4.8.10.12.3 Sourcing out-of-band text tracks |
2636 // When a track element's parent element changes and the old parent was a me
dia element, | 2639 // When a track element's parent element changes and the old parent was a me
dia element, |
2637 // then the user agent must remove the track element's corresponding text tr
ack from the | 2640 // then the user agent must remove the track element's corresponding text tr
ack from the |
2638 // media element's list of text tracks. | 2641 // media element's list of text tracks. |
2639 removeTextTrack(textTrack.get()); | 2642 removeTrack(textTrack.get()); |
2640 | 2643 |
2641 size_t index = m_textTracksWhenResourceSelectionBegan.find(textTrack.get()); | 2644 size_t index = m_textTracksWhenResourceSelectionBegan.find(textTrack.get()); |
2642 if (index != kNotFound) | 2645 if (index != kNotFound) |
2643 m_textTracksWhenResourceSelectionBegan.remove(index); | 2646 m_textTracksWhenResourceSelectionBegan.remove(index); |
2644 } | 2647 } |
2645 | 2648 |
2646 static int textTrackLanguageSelectionScore(const TextTrack& track) | 2649 static int textTrackLanguageSelectionScore(const TextTrack& track) |
2647 { | 2650 { |
2648 if (track.language().isEmpty()) | 2651 if (track.language().isEmpty()) |
2649 return 0; | 2652 return 0; |
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3904 { | 3907 { |
3905 m_mediaSource->setWebMediaSourceAndOpen(adoptPtr(webMediaSource)); | 3908 m_mediaSource->setWebMediaSourceAndOpen(adoptPtr(webMediaSource)); |
3906 } | 3909 } |
3907 | 3910 |
3908 bool HTMLMediaElement::isInteractiveContent() const | 3911 bool HTMLMediaElement::isInteractiveContent() const |
3909 { | 3912 { |
3910 return fastHasAttribute(controlsAttr); | 3913 return fastHasAttribute(controlsAttr); |
3911 } | 3914 } |
3912 | 3915 |
3913 } | 3916 } |
OLD | NEW |