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

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

Issue 2199363002: Change play promises behaviour in the load algorithm. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make it match the spec Created 4 years, 4 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 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 if (m_playPromiseResolveTask->isPending()) {
772 m_playPromiseResolveTask->cancel();
773 resolveScheduledPlayPromises();
774 }
775 if (m_playPromiseRejectTask->isPending()) {
776 m_playPromiseRejectTask->cancel();
777 rejectScheduledPlayPromises();
778 }
779
780 // 4 - Remove each task in pending tasks from its task queue.
766 cancelPendingEventsAndCallbacks(); 781 cancelPendingEventsAndCallbacks();
767 782
768 rejectPlayPromises(AbortError, "The play() request was interrupted by a new load request."); 783 // 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. 784 // a task to fire a simple event named abort at the media element.
772 if (m_networkState == kNetworkLoading || m_networkState == kNetworkIdle) 785 if (m_networkState == kNetworkLoading || m_networkState == kNetworkIdle)
773 scheduleEvent(EventTypeNames::abort); 786 scheduleEvent(EventTypeNames::abort);
774 787
775 resetMediaPlayerAndMediaSource(); 788 resetMediaPlayerAndMediaSource();
776 789
777 // 4 - If the media element's networkState is not set to NETWORK_EMPTY, then run these substeps 790 // 6 - If the media element's networkState is not set to NETWORK_EMPTY, then run these substeps
778 if (m_networkState != kNetworkEmpty) { 791 if (m_networkState != kNetworkEmpty) {
779 // 4.1 - Queue a task to fire a simple event named emptied at the media element. 792 // 4.1 - Queue a task to fire a simple event named emptied at the media element.
780 scheduleEvent(EventTypeNames::emptied); 793 scheduleEvent(EventTypeNames::emptied);
781 794
782 // 4.2 - If a fetching process is in progress for the media element, the user agent should stop it. 795 // 4.2 - If a fetching process is in progress for the media element, the user agent should stop it.
783 setNetworkState(kNetworkEmpty); 796 setNetworkState(kNetworkEmpty);
784 797
785 // 4.3 - Forget the media element's media-resource-specific tracks. 798 // 4.4 - Forget the media element's media-resource-specific tracks.
786 forgetResourceSpecificTracks(); 799 forgetResourceSpecificTracks();
787 800
788 // 4.4 - If readyState is not set to HAVE_NOTHING, then set it to that s tate. 801 // 4.5 - If readyState is not set to kHaveNothing, then set it to that s tate.
789 m_readyState = kHaveNothing; 802 m_readyState = kHaveNothing;
790 m_readyStateMaximum = kHaveNothing; 803 m_readyStateMaximum = kHaveNothing;
791 804
792 // 4.5 - If the paused attribute is false, then set it to true. 805 // 4.6 - If the paused attribute is false, then run these substeps
793 m_paused = true; 806 if (!m_paused) {
807 // 4.6.1 - Set the paused attribute to true.
808 m_paused = true;
794 809
795 // 4.6 - If seeking is true, set it to false. 810 // 4.6.2 - Take pending play promises and reject pending play promis es with the result and an "AbortError" DOMException.
811 rejectPlayPromises(AbortError, "The play() request was interrupted b y a new load request.");
812 }
813
814 // 4.7 - If seeking is true, set it to false.
796 m_seeking = false; 815 m_seeking = false;
797 816
798 // 4.7 - Set the current playback position to 0. 817 // 4.8 - Set the current playback position to 0.
799 // Set the official playback position to 0. 818 // 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. 819 // 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. 820 // FIXME: Add support for firing this event.
802 821
803 // 4.8 - Set the initial playback position to 0. 822 // 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. 823 // FIXME: Make this less subtle. The position only becomes 0 because the ready state is HAVE_NOTHING.
805 invalidateCachedTime(); 824 invalidateCachedTime();
806 825
807 // 4.9 - Set the timeline offset to Not-a-Number (NaN). 826 // 4.10 - Set the timeline offset to Not-a-Number (NaN).
808 // 4.10 - Update the duration attribute to Not-a-Number (NaN). 827 // 4.11 - Update the duration attribute to Not-a-Number (NaN).
809 828
810 cueTimeline().updateActiveCues(0); 829 cueTimeline().updateActiveCues(0);
811 } else if (!m_paused) { 830 } else if (!m_paused) {
812 // TODO(foolip): There is a proposal to always reset the paused state 831 // 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 832 // in the media element load algorithm, to avoid a bogus play() promise
814 // rejection: https://github.com/whatwg/html/issues/869 833 // rejection: https://github.com/whatwg/html/issues/869
815 // This is where that change would have an effect, and it is measured to 834 // 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. 835 // verify the assumption that it's a very rare situation.
817 UseCounter::count(document(), UseCounter::HTMLMediaElementLoadNetworkEmp tyNotPaused); 836 UseCounter::count(document(), UseCounter::HTMLMediaElementLoadNetworkEmp tyNotPaused);
818 } 837 }
819 838
820 // 5 - Set the playbackRate attribute to the value of the defaultPlaybackRat e attribute. 839 // 7 - Set the playbackRate attribute to the value of the defaultPlaybackRat e attribute.
821 setPlaybackRate(defaultPlaybackRate()); 840 setPlaybackRate(defaultPlaybackRate());
822 841
823 // 6 - Set the error attribute to null and the autoplaying flag to true. 842 // 8 - Set the error attribute to null and the autoplaying flag to true.
824 m_error = nullptr; 843 m_error = nullptr;
825 m_autoplaying = true; 844 m_autoplaying = true;
826 845
827 // 7 - Invoke the media element's resource selection algorithm. 846 // 9 - Invoke the media element's resource selection algorithm.
828 invokeResourceSelectionAlgorithm(); 847 invokeResourceSelectionAlgorithm();
829 848
830 // 8 - Note: Playback of any previously playing media resource for this elem ent stops. 849 // 10 - Note: Playback of any previously playing media resource for this ele ment stops.
831 } 850 }
832 851
833 void HTMLMediaElement::invokeResourceSelectionAlgorithm() 852 void HTMLMediaElement::invokeResourceSelectionAlgorithm()
834 { 853 {
835 BLINK_MEDIA_LOG << "invokeResourceSelectionAlgorithm(" << (void*)this << ")" ; 854 BLINK_MEDIA_LOG << "invokeResourceSelectionAlgorithm(" << (void*)this << ")" ;
836 // The resource selection algorithm 855 // The resource selection algorithm
837 // 1 - Set the networkState to NETWORK_NO_SOURCE 856 // 1 - Set the networkState to NETWORK_NO_SOURCE
838 setNetworkState(kNetworkNoSource); 857 setNetworkState(kNetworkNoSource);
839 858
840 // 2 - Set the element's show poster flag to true 859 // 2 - Set the element's show poster flag to true
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 m_currentSourceNode = nullptr; 1412 m_currentSourceNode = nullptr;
1394 } 1413 }
1395 1414
1396 void HTMLMediaElement::cancelPendingEventsAndCallbacks() 1415 void HTMLMediaElement::cancelPendingEventsAndCallbacks()
1397 { 1416 {
1398 BLINK_MEDIA_LOG << "cancelPendingEventsAndCallbacks(" << (void*)this << ")"; 1417 BLINK_MEDIA_LOG << "cancelPendingEventsAndCallbacks(" << (void*)this << ")";
1399 m_asyncEventQueue->cancelAllEvents(); 1418 m_asyncEventQueue->cancelAllEvents();
1400 1419
1401 for (HTMLSourceElement* source = Traversal<HTMLSourceElement>::firstChild(*t his); source; source = Traversal<HTMLSourceElement>::nextSibling(*source)) 1420 for (HTMLSourceElement* source = Traversal<HTMLSourceElement>::firstChild(*t his); source; source = Traversal<HTMLSourceElement>::nextSibling(*source))
1402 source->cancelPendingErrorEvent(); 1421 source->cancelPendingErrorEvent();
1403
1404 m_playPromiseResolveTask->cancel();
1405 m_playPromiseResolveList.clear();
1406 m_playPromiseRejectTask->cancel();
1407 m_playPromiseRejectList.clear();
1408 } 1422 }
1409 1423
1410 void HTMLMediaElement::networkStateChanged() 1424 void HTMLMediaElement::networkStateChanged()
1411 { 1425 {
1412 setNetworkState(webMediaPlayer()->getNetworkState()); 1426 setNetworkState(webMediaPlayer()->getNetworkState());
1413 } 1427 }
1414 1428
1415 void HTMLMediaElement::mediaLoadingFailed(WebMediaPlayer::NetworkState error) 1429 void HTMLMediaElement::mediaLoadingFailed(WebMediaPlayer::NetworkState error)
1416 { 1430 {
1417 stopPeriodicTimers(); 1431 stopPeriodicTimers();
(...skipping 2602 matching lines...) Expand 10 before | Expand all | Expand 10 after
4020 4034
4021 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co nst 4035 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co nst
4022 { 4036 {
4023 IntRect result; 4037 IntRect result;
4024 if (LayoutObject* object = m_element->layoutObject()) 4038 if (LayoutObject* object = m_element->layoutObject())
4025 result = object->absoluteBoundingBoxRect(); 4039 result = object->absoluteBoundingBoxRect();
4026 return result; 4040 return result;
4027 } 4041 }
4028 4042
4029 } // namespace blink 4043 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698