Changeset 198211 in webkit


Ignore:
Timestamp:
Mar 15, 2016 8:20:40 AM (8 years ago)
Author:
jer.noble@apple.com
Message:

Video elements with autoplay do not begin playing when scrolling into view if InvisibleAutoplayNotPermitted is set.
https://bugs.webkit.org/show_bug.cgi?id=155468

Reviewed by Eric Carlson.

Source/WebCore:

Test: media/video-restricted-invisible-autoplay-allowed-when-visible.html

A few bugs came together to cause this behavior. We were not telling the media session that we were going to begin
the autoplaying state, we were not restoring the correct state when the interruption ended, and we were not checking
to see if we could actually play correctly when the interruption ended.

  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::prepareForLoad):
(WebCore::HTMLMediaElement::canTransitionFromAutoplayToPlay):
(WebCore::HTMLMediaElement::setReadyState):
(WebCore::HTMLMediaElement::resumeAutoplaying):
(WebCore::HTMLMediaElement::updateShouldPlay):
(WebCore::elementCanTransitionFromAutoplayToPlay): Deleted.

  • html/HTMLMediaElement.h:
  • platform/audio/PlatformMediaSession.cpp:

(WebCore::PlatformMediaSession::endInterruption):

LayoutTests:

  • media/video-restricted-invisible-autoplay-allowed-when-visible-expected.txt: Added.
  • media/video-restricted-invisible-autoplay-allowed-when-visible.html: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r198203 r198211  
     12016-03-14  Jer Noble  <jer.noble@apple.com>
     2
     3        Video elements with autoplay do not begin playing when scrolling into view if InvisibleAutoplayNotPermitted is set.
     4        https://bugs.webkit.org/show_bug.cgi?id=155468
     5
     6        Reviewed by Eric Carlson.
     7
     8        * media/video-restricted-invisible-autoplay-allowed-when-visible-expected.txt: Added.
     9        * media/video-restricted-invisible-autoplay-allowed-when-visible.html: Added.
     10
    1112016-03-15  Jiewen Tan  <jiewen_tan@apple.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r198210 r198211  
     12016-03-14  Jer Noble  <jer.noble@apple.com>
     2
     3        Video elements with autoplay do not begin playing when scrolling into view if InvisibleAutoplayNotPermitted is set.
     4        https://bugs.webkit.org/show_bug.cgi?id=155468
     5
     6        Reviewed by Eric Carlson.
     7
     8        Test: media/video-restricted-invisible-autoplay-allowed-when-visible.html
     9
     10        A few bugs came together to cause this behavior. We were not telling the media session that we were going to begin
     11        the autoplaying state, we were not restoring the correct state when the interruption ended, and we were not checking
     12        to see if we could actually play correctly when the interruption ended.
     13
     14        * html/HTMLMediaElement.cpp:
     15        (WebCore::HTMLMediaElement::prepareForLoad):
     16        (WebCore::HTMLMediaElement::canTransitionFromAutoplayToPlay):
     17        (WebCore::HTMLMediaElement::setReadyState):
     18        (WebCore::HTMLMediaElement::resumeAutoplaying):
     19        (WebCore::HTMLMediaElement::updateShouldPlay):
     20        (WebCore::elementCanTransitionFromAutoplayToPlay): Deleted.
     21        * html/HTMLMediaElement.h:
     22        * platform/audio/PlatformMediaSession.cpp:
     23        (WebCore::PlatformMediaSession::endInterruption):
     24
    1252016-03-15  Manuel Rego Casasnovas  <rego@igalia.com>
    226
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r198180 r198211  
    10701070    m_error = nullptr;
    10711071    m_autoplaying = true;
     1072    mediaSession().clientWillBeginAutoplaying();
    10721073
    10731074    // 7 - Invoke the media element's resource selection algorithm.
     
    20912092}
    20922093
    2093 static bool elementCanTransitionFromAutoplayToPlay(HTMLMediaElement& element)
    2094 {
    2095     return element.isAutoplaying()
    2096         && element.paused()
    2097         && element.autoplay()
    2098         && !element.document().isSandboxed(SandboxAutomaticFeatures)
    2099         && element.mediaSession().playbackPermitted(element);
     2094bool HTMLMediaElement::canTransitionFromAutoplayToPlay() const
     2095{
     2096    return isAutoplaying()
     2097        && paused()
     2098        && autoplay()
     2099        && !pausedForUserInteraction()
     2100        && !document().isSandboxed(SandboxAutomaticFeatures)
     2101        && mediaSession().playbackPermitted(*this);
    21002102}
    21012103
     
    22102212            scheduleEvent(eventNames().playingEvent);
    22112213
    2212         if (elementCanTransitionFromAutoplayToPlay(*this)) {
     2214        if (canTransitionFromAutoplayToPlay()) {
    22132215            m_paused = false;
    22142216            invalidateCachedTime();
     
    65376539    m_autoplaying = true;
    65386540
    6539     if (elementCanTransitionFromAutoplayToPlay(*this))
     6541    if (canTransitionFromAutoplayToPlay())
    65406542        play();
    65416543}
     
    68326834    if (isPlaying() && !m_mediaSession->playbackPermitted(*this))
    68336835        pauseInternal();
    6834     else if (elementCanTransitionFromAutoplayToPlay(*this))
     6836    else if (canTransitionFromAutoplayToPlay())
    68356837        play();
    68366838}
  • trunk/Source/WebCore/html/HTMLMediaElement.h

    r198002 r198211  
    691691    bool pausedForUserInteraction() const;
    692692    bool couldPlayIfEnoughData() const;
     693    bool canTransitionFromAutoplayToPlay() const;
    693694
    694695    MediaTime minTimeSeekable() const;
  • trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp

    r195154 r198211  
    130130    m_stateToRestore = Idle;
    131131    m_interruptionType = NoInterruption;
    132     setState(Paused);
     132    setState(stateToRestore);
    133133
    134134    if (stateToRestore == Autoplaying)
Note: See TracChangeset for help on using the changeset viewer.