Changeset 271531 in webkit


Ignore:
Timestamp:
Jan 15, 2021 12:53:32 PM (18 months ago)
Author:
jer.noble@apple.com
Message:

Playback fails at marketwatch.com
https://bugs.webkit.org/show_bug.cgi?id=220646
<rdar://72950166>

Reviewed by Xabier Rodriguez-Calvar.

Source/WebCore:

Test: media/media-play-promise-reject-play-notallowed-audio.html

When audio playback is blocked by settings, the HTMLMediaElement must load its source
media's metadata in order to determine whether the media should be allowed to play without a
user gesture. If a play promise is pending, the expectation is that those promises will
reject with a NotAllowedError to indicate that a user gesture is needed. However, by calling
pauseInternal() to block (possibly) existing playback, this causes those promises to be
rejected with an AbortError, as if the pause() method had been called. Call
scheduleRejectPendingPlayPromises() with NotAllowedError to ensure the correct error is used
to reject.

Drive-by fix: no reason to dispatch and call rejectPendingPlayPromises() or
resolvePendingPlayPromises() if there are no promises to reject or resolve, and not calling
these methods makes the logs less noisy.

  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::scheduleResolvePendingPlayPromises):
(WebCore::HTMLMediaElement::scheduleRejectPendingPlayPromises):
(WebCore::HTMLMediaElement::setVolume):
(WebCore::HTMLMediaElement::mediaPlayerDidAddAudioTrack):
(WebCore::HTMLMediaElement::mediaPlayerCharacteristicChanged):
(WebCore::HTMLMediaElement::updateShouldPlay):

LayoutTests:

  • media/media-play-promise-reject-play-notallowed-audio-expected.txt: Added.
  • media/media-play-promise-reject-play-notallowed-audio.html: Added.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r271524 r271531  
     12021-01-15  Jer Noble  <jer.noble@apple.com>
     2
     3        Playback fails at marketwatch.com
     4        https://bugs.webkit.org/show_bug.cgi?id=220646
     5        <rdar://72950166>
     6
     7        Reviewed by Xabier Rodriguez-Calvar.
     8
     9        * media/media-play-promise-reject-play-notallowed-audio-expected.txt: Added.
     10        * media/media-play-promise-reject-play-notallowed-audio.html: Added.
     11
    1122021-01-15  Antoine Quint  <graouts@webkit.org>
    213
  • trunk/Source/WebCore/ChangeLog

    r271530 r271531  
     12021-01-15  Jer Noble  <jer.noble@apple.com>
     2
     3        Playback fails at marketwatch.com
     4        https://bugs.webkit.org/show_bug.cgi?id=220646
     5        <rdar://72950166>
     6
     7        Reviewed by Xabier Rodriguez-Calvar.
     8
     9        Test: media/media-play-promise-reject-play-notallowed-audio.html
     10
     11        When audio playback is blocked by settings, the HTMLMediaElement must load its source
     12        media's metadata in order to determine whether the media should be allowed to play without a
     13        user gesture. If a play promise is pending, the expectation is that those promises will
     14        reject with a NotAllowedError to indicate that a user gesture is needed. However, by calling
     15        pauseInternal() to block (possibly) existing playback, this causes those promises to be
     16        rejected with an AbortError, as if the pause() method had been called. Call
     17        scheduleRejectPendingPlayPromises() with NotAllowedError to ensure the correct error is used
     18        to reject.
     19
     20        Drive-by fix: no reason to dispatch and call rejectPendingPlayPromises() or
     21        resolvePendingPlayPromises() if there are no promises to reject or resolve, and not calling
     22        these methods makes the logs less noisy.
     23
     24        * html/HTMLMediaElement.cpp:
     25        (WebCore::HTMLMediaElement::scheduleResolvePendingPlayPromises):
     26        (WebCore::HTMLMediaElement::scheduleRejectPendingPlayPromises):
     27        (WebCore::HTMLMediaElement::setVolume):
     28        (WebCore::HTMLMediaElement::mediaPlayerDidAddAudioTrack):
     29        (WebCore::HTMLMediaElement::mediaPlayerCharacteristicChanged):
     30        (WebCore::HTMLMediaElement::updateShouldPlay):
     31
    1322021-01-15  Jer Noble  <jer.noble@apple.com>
    233
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r271245 r271531  
    909909void HTMLMediaElement::scheduleResolvePendingPlayPromises()
    910910{
     911    if (m_pendingPlayPromises.isEmpty())
     912        return;
     913
    911914    m_promiseTaskQueue.enqueueTask([this, pendingPlayPromises = WTFMove(m_pendingPlayPromises)] () mutable {
    912915        resolvePendingPlayPromises(WTFMove(pendingPlayPromises));
     
    916919void HTMLMediaElement::scheduleRejectPendingPlayPromises(Ref<DOMException>&& error)
    917920{
     921    if (m_pendingPlayPromises.isEmpty())
     922        return;
     923
    918924    m_promiseTaskQueue.enqueueTask([this, error = WTFMove(error), pendingPlayPromises = WTFMove(m_pendingPlayPromises)] () mutable {
    919925        rejectPendingPlayPromises(WTFMove(pendingPlayPromises), WTFMove(error));
     
    36103616
    36113617    if (isPlaying() && !m_mediaSession->playbackPermitted()) {
     3618        scheduleRejectPendingPlayPromises(DOMException::create(NotAllowedError));
    36123619        pauseInternal();
    36133620        setAutoplayEventPlaybackState(AutoplayEventPlaybackState::PreventedAutoplay);
     
    38773884{
    38783885    if (isPlaying() && !m_mediaSession->playbackPermitted()) {
     3886        scheduleRejectPendingPlayPromises(DOMException::create(NotAllowedError));
    38793887        pauseInternal();
    38803888        setAutoplayEventPlaybackState(AutoplayEventPlaybackState::PreventedAutoplay);
     
    50515059
    50525060    if (!paused() && !m_mediaSession->playbackPermitted()) {
     5061        scheduleRejectPendingPlayPromises(DOMException::create(NotAllowedError));
    50535062        pauseInternal();
    50545063        setAutoplayEventPlaybackState(AutoplayEventPlaybackState::PreventedAutoplay);
     
    78037812{
    78047813    if (!paused() && !m_mediaSession->playbackPermitted()) {
     7814        scheduleRejectPendingPlayPromises(DOMException::create(NotAllowedError));
    78057815        pauseInternal();
    78067816        setAutoplayEventPlaybackState(AutoplayEventPlaybackState::PreventedAutoplay);
Note: See TracChangeset for help on using the changeset viewer.