Autoplay Muted Videos Don't Play When Outside Viewport
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Aug 2017 16:13:22 +0000 (16:13 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Aug 2017 16:13:22 +0000 (16:13 +0000)
commitda8432aaca32968f31df4765db6744ed788693b4
tree75263c7a6267d083dccff589c7a835bc580a1775
parenteee06930a2b339b291605022f2bc83cbbba91e7b
Autoplay Muted Videos Don't Play When Outside Viewport
https://bugs.webkit.org/show_bug.cgi?id=175748
<rdar://problem/33974383>

Reviewed by Eric Carlson.

Source/WebCore:

Test: media/video-restricted-invisible-autoplay-not-allowed-source.html

The media session is notified that its client (the media element) will begin autoplaying inside
prepareForLoad(), where the m_autoplaying flag is also set. But loading via <source> elements does not go
through prepareForLoad(); the HTML standard states that the <source> element loading path does not trigger the
"media element load algorithm" which is implemented in prepareForLoad(). Since the m_autoplaying flag is
initially set to true, notify the media session that the element will begin autoplaying inside the element's
constructor.

Drive-by fix: Doing the above causes other tests to crash, as purturbing play state during style change can cause
re-entrancy in the native controls code, or fail, since we will transition from autoplay -> play even if there's
not yet a src or source to the media element. Add a task queue for updating the autoplay state and check the ready
state before allowing autoplay to transition to play.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::HTMLMediaElement):
(WebCore::HTMLMediaElement::~HTMLMediaElement):
(WebCore::HTMLMediaElement::canTransitionFromAutoplayToPlay const):
(WebCore::HTMLMediaElement::isVisibleInViewportChanged):

LayoutTests:

* media/video-restricted-invisible-autoplay-not-allowed-source-expected.txt: Added.
* media/video-restricted-invisible-autoplay-not-allowed-source.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221016 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/media/video-restricted-invisible-autoplay-not-allowed-source-expected.txt [new file with mode: 0644]
LayoutTests/media/video-restricted-invisible-autoplay-not-allowed-source.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h