Playing media elements which call "pause(); play()" will have the play promise rejected.
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Dec 2017 17:43:50 +0000 (17:43 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Dec 2017 17:43:50 +0000 (17:43 +0000)
commit70387411f7595390f58e69e618fdec191bef329b
treec65bf5aa98301b79a4f2999ad3ff08fd677055e5
parent07f6e7e7414ef327acb21a8ba2891a1b2b240978
Playing media elements which call "pause(); play()" will have the play promise rejected.
https://bugs.webkit.org/show_bug.cgi?id=180781

Reviewed by Eric Carlson.

Source/WebCore:

Test: media/video-pause-play-resolve.html

When scheduling a rejection or resolution of existing play promises, move() the existing
promises into the block. This ensures that valid promises aren't added to the play promise
vector between when a rejection is scheduled and when it runs.

Drive-by fix: Don't return false from playInternal() just so the newly created promise will
get rejected. The pause() command will reject the promise, so just make sure it's added to
the m_pendingPlayPromises before calling playInternal().

Drive-by fix #2: The spec referenced by playInternal() and pauseInternal() doesn't say to
call the "Media Element Load Algorithm" (i.e., prepareForLoad()); it says to call the
"Resource Selection Algorithm" (i.e., selectMediaResource()). But fixing this bug caused
an assertion crash when the resource selection task was fired and m_player was null. This
was because the algorithm is being run at stop() time due to stop() calling pause(). The
solution to this ASSERT is to stop the m_resourceSelectionTaskQueue in stop().

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::scheduleRejectPendingPlayPromises):
(WebCore::HTMLMediaElement::rejectPendingPlayPromises):
(WebCore::HTMLMediaElement::resolvePendingPlayPromises):
(WebCore::HTMLMediaElement::scheduleNotifyAboutPlaying):
(WebCore::HTMLMediaElement::notifyAboutPlaying):
(WebCore::HTMLMediaElement::noneSupported):
(WebCore::HTMLMediaElement::cancelPendingEventsAndCallbacks):
(WebCore::HTMLMediaElement::play):
(WebCore::HTMLMediaElement::playInternal):
(WebCore::HTMLMediaElement::pauseInternal):
(WebCore::HTMLMediaElement::stop):
* html/HTMLMediaElement.h:

LayoutTests:

* media/audio-dealloc-crash.html:
* media/video-pause-play-resolve-expected.txt: Added.
* media/video-pause-play-resolve.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226059 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/http/tests/security/video-cross-origin-caching-expected.txt
LayoutTests/media/audio-dealloc-crash.html
LayoutTests/media/video-pause-play-resolve-expected.txt [new file with mode: 0644]
LayoutTests/media/video-pause-play-resolve.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h