⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 221016 in webkit


Ignore:
Timestamp:
Aug 22, 2017, 9:13:22 AM (9 years ago)
Author:
jer.noble@apple.com
Message:

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.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r221014 r221016  
     12017-08-22  Jer Noble  <jer.noble@apple.com>
     2
     3        Autoplay Muted Videos Don't Play When Outside Viewport
     4        https://bugs.webkit.org/show_bug.cgi?id=175748
     5        <rdar://problem/33974383>
     6
     7        Reviewed by Eric Carlson.
     8
     9        * media/video-restricted-invisible-autoplay-not-allowed-source-expected.txt: Added.
     10        * media/video-restricted-invisible-autoplay-not-allowed-source.html: Added.
     11
    1122017-08-21  Matt Rajca  <mrajca@apple.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r221014 r221016  
     12017-08-22  Jer Noble  <jer.noble@apple.com>
     2
     3        Autoplay Muted Videos Don't Play When Outside Viewport
     4        https://bugs.webkit.org/show_bug.cgi?id=175748
     5        <rdar://problem/33974383>
     6
     7        Reviewed by Eric Carlson.
     8
     9        Test: media/video-restricted-invisible-autoplay-not-allowed-source.html
     10
     11        The media session is notified that its client (the media element) will begin autoplaying inside
     12        prepareForLoad(), where the m_autoplaying flag is also set. But loading via <source> elements does not go
     13        through prepareForLoad(); the HTML standard states that the <source> element loading path does not trigger the
     14        "media element load algorithm" which is implemented in prepareForLoad(). Since the m_autoplaying flag is
     15        initially set to true, notify the media session that the element will begin autoplaying inside the element's
     16        constructor.
     17
     18        Drive-by fix: Doing the above causes other tests to crash, as purturbing play state during style change can cause
     19        re-entrancy in the native controls code, or fail, since we will transition from autoplay -> play even if there's
     20        not yet a src or source to the media element. Add a task queue for updating the autoplay state and check the ready
     21        state before allowing autoplay to transition to play.
     22
     23        * html/HTMLMediaElement.cpp:
     24        (WebCore::HTMLMediaElement::HTMLMediaElement):
     25        (WebCore::HTMLMediaElement::~HTMLMediaElement):
     26        (WebCore::HTMLMediaElement::canTransitionFromAutoplayToPlay const):
     27        (WebCore::HTMLMediaElement::isVisibleInViewportChanged):
     28
    1292017-08-21  Matt Rajca  <mrajca@apple.com>
    230
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r220962 r221016  
    520520    AudioSession::sharedSession().addMutedStateObserver(this);
    521521#endif
     522
     523    mediaSession().clientWillBeginAutoplaying();
    522524}
    523525
    … …  
    596598    m_playbackControlsManagerBehaviorRestrictionsQueue.close();
    597599    m_resourceSelectionTaskQueue.close();
     600    m_visibilityChangeTaskQueue.close();
    598601#if ENABLE(ENCRYPTED_MEDIA)
    599602    m_encryptedMediaQueue.close();
    … …  
    23332336{
    23342337    if (isAutoplaying()
    2335      && mediaSession().autoplayPermitted()
    2336      && paused()
    2337      && autoplay()
    2338      && !pausedForUserInteraction()
    2339      && !document().isSandboxed(SandboxAutomaticFeatures))
     2338        && mediaSession().autoplayPermitted()
     2339        && paused()
     2340        && autoplay()
     2341        && !pausedForUserInteraction()
     2342        && !document().isSandboxed(SandboxAutomaticFeatures)
     2343        && m_readyState == HAVE_ENOUGH_DATA)
    23402344        return mediaSession().playbackPermitted(*this);
    23412345
    … …  
    76227626void HTMLMediaElement::isVisibleInViewportChanged()
    76237627{
    7624     updateShouldAutoplay();
    7625     scheduleUpdatePlaybackControlsManager();
     7628    m_visibilityChangeTaskQueue.enqueueTask([this] {
     7629        updateShouldAutoplay();
     7630        scheduleUpdatePlaybackControlsManager();
     7631    });
    76267632}
    76277633
  • trunk/Source/WebCore/html/HTMLMediaElement.h

    r220962 r221016  
    902902    GenericTaskQueue<Timer> m_playbackControlsManagerBehaviorRestrictionsQueue;
    903903    GenericTaskQueue<Timer> m_resourceSelectionTaskQueue;
     904    GenericTaskQueue<Timer> m_visibilityChangeTaskQueue;
    904905    RefPtr<TimeRanges> m_playedTimeRanges;
    905906    GenericEventQueue m_asyncEventQueue;
Note: See TracChangeset for help on using the changeset viewer.