| 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 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 // FIXME: Figure out appropriate place to reset LoadTextTrackResource if nec
essary and set m_pendingActionFlags to 0 here. | 754 // FIXME: Figure out appropriate place to reset LoadTextTrackResource if nec
essary and set m_pendingActionFlags to 0 here. |
| 755 m_pendingActionFlags &= ~LoadMediaResource; | 755 m_pendingActionFlags &= ~LoadMediaResource; |
| 756 m_sentStalledEvent = false; | 756 m_sentStalledEvent = false; |
| 757 m_haveFiredLoadedData = false; | 757 m_haveFiredLoadedData = false; |
| 758 m_displayMode = Unknown; | 758 m_displayMode = Unknown; |
| 759 | 759 |
| 760 // 1 - Abort any already-running instance of the resource selection algorith
m for this element. | 760 // 1 - Abort any already-running instance of the resource selection algorith
m for this element. |
| 761 m_loadState = WaitingForSource; | 761 m_loadState = WaitingForSource; |
| 762 m_currentSourceNode = nullptr; | 762 m_currentSourceNode = nullptr; |
| 763 | 763 |
| 764 // 2 - If there are any tasks from the media element's media element event t
ask source in | 764 // 2 - Let pending tasks be a list of tasks from the media element's media |
| 765 // one of the task queues, then remove those tasks. | 765 // element task source in one of the task queues. |
| 766 // |
| 767 // 3 - For each task in the pending tasks that would run resolve pending |
| 768 // play promises or project pending play prmoises algorithms, immediately |
| 769 // resolve or reject those promises in the order the corresponding tasks |
| 770 // were queued. |
| 771 // |
| 772 // TODO(mlamouri): the promises are first resolved then rejected but the |
| 773 // order between resolved/rejected promises isn't respected. This could be |
| 774 // improved when the same task is used for both cases. |
| 775 if (m_playPromiseResolveTask->isPending()) { |
| 776 m_playPromiseResolveTask->cancel(); |
| 777 resolveScheduledPlayPromises(); |
| 778 } |
| 779 if (m_playPromiseRejectTask->isPending()) { |
| 780 m_playPromiseRejectTask->cancel(); |
| 781 rejectScheduledPlayPromises(); |
| 782 } |
| 783 |
| 784 // 4 - Remove each task in pending tasks from its task queue. |
| 766 cancelPendingEventsAndCallbacks(); | 785 cancelPendingEventsAndCallbacks(); |
| 767 | 786 |
| 768 rejectPlayPromises(AbortError, "The play() request was interrupted by a new
load request."); | 787 // 5 - If the media element's networkState is set to NETWORK_LOADING or NETW
ORK_IDLE, queue |
| 769 | |
| 770 // 3 - If the media element's networkState is set to NETWORK_LOADING or NETW
ORK_IDLE, queue | |
| 771 // a task to fire a simple event named abort at the media element. | 788 // a task to fire a simple event named abort at the media element. |
| 772 if (m_networkState == kNetworkLoading || m_networkState == kNetworkIdle) | 789 if (m_networkState == kNetworkLoading || m_networkState == kNetworkIdle) |
| 773 scheduleEvent(EventTypeNames::abort); | 790 scheduleEvent(EventTypeNames::abort); |
| 774 | 791 |
| 775 resetMediaPlayerAndMediaSource(); | 792 resetMediaPlayerAndMediaSource(); |
| 776 | 793 |
| 777 // 4 - If the media element's networkState is not set to NETWORK_EMPTY, then
run these substeps | 794 // 6 - If the media element's networkState is not set to NETWORK_EMPTY, then
run these substeps |
| 778 if (m_networkState != kNetworkEmpty) { | 795 if (m_networkState != kNetworkEmpty) { |
| 779 // 4.1 - Queue a task to fire a simple event named emptied at the media
element. | 796 // 4.1 - Queue a task to fire a simple event named emptied at the media
element. |
| 780 scheduleEvent(EventTypeNames::emptied); | 797 scheduleEvent(EventTypeNames::emptied); |
| 781 | 798 |
| 782 // 4.2 - If a fetching process is in progress for the media element, the
user agent should stop it. | 799 // 4.2 - If a fetching process is in progress for the media element, the
user agent should stop it. |
| 783 setNetworkState(kNetworkEmpty); | 800 setNetworkState(kNetworkEmpty); |
| 784 | 801 |
| 785 // 4.3 - Forget the media element's media-resource-specific tracks. | 802 // 4.4 - Forget the media element's media-resource-specific tracks. |
| 786 forgetResourceSpecificTracks(); | 803 forgetResourceSpecificTracks(); |
| 787 | 804 |
| 788 // 4.4 - If readyState is not set to HAVE_NOTHING, then set it to that s
tate. | 805 // 4.5 - If readyState is not set to kHaveNothing, then set it to that s
tate. |
| 789 m_readyState = kHaveNothing; | 806 m_readyState = kHaveNothing; |
| 790 m_readyStateMaximum = kHaveNothing; | 807 m_readyStateMaximum = kHaveNothing; |
| 791 | 808 |
| 792 // 4.5 - If the paused attribute is false, then set it to true. | 809 DCHECK(!m_paused || m_playPromiseResolvers.isEmpty()); |
| 793 m_paused = true; | |
| 794 | 810 |
| 795 // 4.6 - If seeking is true, set it to false. | 811 // 4.6 - If the paused attribute is false, then run these substeps |
| 812 if (!m_paused) { |
| 813 // 4.6.1 - Set the paused attribute to true. |
| 814 m_paused = true; |
| 815 |
| 816 // 4.6.2 - Take pending play promises and reject pending play promis
es with the result and an "AbortError" DOMException. |
| 817 rejectPlayPromises(AbortError, "The play() request was interrupted b
y a new load request."); |
| 818 } |
| 819 |
| 820 // 4.7 - If seeking is true, set it to false. |
| 796 m_seeking = false; | 821 m_seeking = false; |
| 797 | 822 |
| 798 // 4.7 - Set the current playback position to 0. | 823 // 4.8 - Set the current playback position to 0. |
| 799 // Set the official playback position to 0. | 824 // Set the official playback position to 0. |
| 800 // If this changed the official playback position, then queue a ta
sk to fire a simple event named timeupdate at the media element. | 825 // If this changed the official playback position, then queue a ta
sk to fire a simple event named timeupdate at the media element. |
| 801 // FIXME: Add support for firing this event. | 826 // FIXME: Add support for firing this event. |
| 802 | 827 |
| 803 // 4.8 - Set the initial playback position to 0. | 828 // 4.9 - Set the initial playback position to 0. |
| 804 // FIXME: Make this less subtle. The position only becomes 0 because the
ready state is kHaveNothing. | 829 // FIXME: Make this less subtle. The position only becomes 0 because the
ready state is HAVE_NOTHING. |
| 805 invalidateCachedTime(); | 830 invalidateCachedTime(); |
| 806 | 831 |
| 807 // 4.9 - Set the timeline offset to Not-a-Number (NaN). | 832 // 4.10 - Set the timeline offset to Not-a-Number (NaN). |
| 808 // 4.10 - Update the duration attribute to Not-a-Number (NaN). | 833 // 4.11 - Update the duration attribute to Not-a-Number (NaN). |
| 809 | 834 |
| 810 cueTimeline().updateActiveCues(0); | 835 cueTimeline().updateActiveCues(0); |
| 811 } else if (!m_paused) { | 836 } else if (!m_paused) { |
| 812 // TODO(foolip): There is a proposal to always reset the paused state | 837 // TODO(foolip): There is a proposal to always reset the paused state |
| 813 // in the media element load algorithm, to avoid a bogus play() promise | 838 // in the media element load algorithm, to avoid a bogus play() promise |
| 814 // rejection: https://github.com/whatwg/html/issues/869 | 839 // rejection: https://github.com/whatwg/html/issues/869 |
| 815 // This is where that change would have an effect, and it is measured to | 840 // This is where that change would have an effect, and it is measured to |
| 816 // verify the assumption that it's a very rare situation. | 841 // verify the assumption that it's a very rare situation. |
| 817 UseCounter::count(document(), UseCounter::HTMLMediaElementLoadNetworkEmp
tyNotPaused); | 842 UseCounter::count(document(), UseCounter::HTMLMediaElementLoadNetworkEmp
tyNotPaused); |
| 818 } | 843 } |
| 819 | 844 |
| 820 // 5 - Set the playbackRate attribute to the value of the defaultPlaybackRat
e attribute. | 845 // 7 - Set the playbackRate attribute to the value of the defaultPlaybackRat
e attribute. |
| 821 setPlaybackRate(defaultPlaybackRate()); | 846 setPlaybackRate(defaultPlaybackRate()); |
| 822 | 847 |
| 823 // 6 - Set the error attribute to null and the autoplaying flag to true. | 848 // 8 - Set the error attribute to null and the autoplaying flag to true. |
| 824 m_error = nullptr; | 849 m_error = nullptr; |
| 825 m_autoplaying = true; | 850 m_autoplaying = true; |
| 826 | 851 |
| 827 // 7 - Invoke the media element's resource selection algorithm. | 852 // 9 - Invoke the media element's resource selection algorithm. |
| 828 invokeResourceSelectionAlgorithm(); | 853 invokeResourceSelectionAlgorithm(); |
| 829 | 854 |
| 830 // 8 - Note: Playback of any previously playing media resource for this elem
ent stops. | 855 // 10 - Note: Playback of any previously playing media resource for this ele
ment stops. |
| 831 } | 856 } |
| 832 | 857 |
| 833 void HTMLMediaElement::invokeResourceSelectionAlgorithm() | 858 void HTMLMediaElement::invokeResourceSelectionAlgorithm() |
| 834 { | 859 { |
| 835 BLINK_MEDIA_LOG << "invokeResourceSelectionAlgorithm(" << (void*)this << ")"
; | 860 BLINK_MEDIA_LOG << "invokeResourceSelectionAlgorithm(" << (void*)this << ")"
; |
| 836 // The resource selection algorithm | 861 // The resource selection algorithm |
| 837 // 1 - Set the networkState to NETWORK_NO_SOURCE | 862 // 1 - Set the networkState to NETWORK_NO_SOURCE |
| 838 setNetworkState(kNetworkNoSource); | 863 setNetworkState(kNetworkNoSource); |
| 839 | 864 |
| 840 // 2 - Set the element's show poster flag to true | 865 // 2 - Set the element's show poster flag to true |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1393 m_currentSourceNode = nullptr; | 1418 m_currentSourceNode = nullptr; |
| 1394 } | 1419 } |
| 1395 | 1420 |
| 1396 void HTMLMediaElement::cancelPendingEventsAndCallbacks() | 1421 void HTMLMediaElement::cancelPendingEventsAndCallbacks() |
| 1397 { | 1422 { |
| 1398 BLINK_MEDIA_LOG << "cancelPendingEventsAndCallbacks(" << (void*)this << ")"; | 1423 BLINK_MEDIA_LOG << "cancelPendingEventsAndCallbacks(" << (void*)this << ")"; |
| 1399 m_asyncEventQueue->cancelAllEvents(); | 1424 m_asyncEventQueue->cancelAllEvents(); |
| 1400 | 1425 |
| 1401 for (HTMLSourceElement* source = Traversal<HTMLSourceElement>::firstChild(*t
his); source; source = Traversal<HTMLSourceElement>::nextSibling(*source)) | 1426 for (HTMLSourceElement* source = Traversal<HTMLSourceElement>::firstChild(*t
his); source; source = Traversal<HTMLSourceElement>::nextSibling(*source)) |
| 1402 source->cancelPendingErrorEvent(); | 1427 source->cancelPendingErrorEvent(); |
| 1403 | |
| 1404 m_playPromiseResolveTask->cancel(); | |
| 1405 m_playPromiseResolveList.clear(); | |
| 1406 m_playPromiseRejectTask->cancel(); | |
| 1407 m_playPromiseRejectList.clear(); | |
| 1408 } | 1428 } |
| 1409 | 1429 |
| 1410 void HTMLMediaElement::networkStateChanged() | 1430 void HTMLMediaElement::networkStateChanged() |
| 1411 { | 1431 { |
| 1412 setNetworkState(webMediaPlayer()->getNetworkState()); | 1432 setNetworkState(webMediaPlayer()->getNetworkState()); |
| 1413 } | 1433 } |
| 1414 | 1434 |
| 1415 void HTMLMediaElement::mediaLoadingFailed(WebMediaPlayer::NetworkState error) | 1435 void HTMLMediaElement::mediaLoadingFailed(WebMediaPlayer::NetworkState error) |
| 1416 { | 1436 { |
| 1417 stopPeriodicTimers(); | 1437 stopPeriodicTimers(); |
| (...skipping 2602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4020 | 4040 |
| 4021 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co
nst | 4041 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co
nst |
| 4022 { | 4042 { |
| 4023 IntRect result; | 4043 IntRect result; |
| 4024 if (LayoutObject* object = m_element->layoutObject()) | 4044 if (LayoutObject* object = m_element->layoutObject()) |
| 4025 result = object->absoluteBoundingBoxRect(); | 4045 result = object->absoluteBoundingBoxRect(); |
| 4026 return result; | 4046 return result; |
| 4027 } | 4047 } |
| 4028 | 4048 |
| 4029 } // namespace blink | 4049 } // namespace blink |
| OLD | NEW |