Bug 185487

Summary: Media continues loading after rendered invisible (removed from DOM; scrolled off screen)
Product: WebKit Reporter: Jer Noble <jer.noble>
Component: New BugsAssignee: Jer Noble <jer.noble>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, eric.carlson, ews-watchlist, rniwa, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Archive of layout-test-results from ews100 for mac-sierra
none
Archive of layout-test-results from ews106 for mac-sierra-wk2
none
Patch for landing
none
Patch for landing
none
Patch for landing
none
Archive of layout-test-results from ews117 for mac-sierra
none
Patch for landing none

Description Jer Noble 2018-05-09 13:35:32 PDT
Media continues loading after rendered invisible (removed from DOM; scrolled off screen)
Comment 1 Jer Noble 2018-05-09 13:41:40 PDT
<rdar://problem/38897810>
Comment 2 Jer Noble 2018-05-09 13:42:25 PDT
Created attachment 340016 [details]
Patch
Comment 3 EWS Watchlist 2018-05-09 14:32:12 PDT Comment hidden (obsolete)
Comment 4 EWS Watchlist 2018-05-09 14:32:13 PDT Comment hidden (obsolete)
Comment 5 Eric Carlson 2018-05-09 14:34:51 PDT
Comment on attachment 340016 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=340016&action=review

r=me once the bots are also satisfied with it.

> Source/WebCore/html/HTMLMediaElement.h:1072
> +    bool m_elementWasRemovedFromDOM : 1;

As you pointed out, this isn't used.

> Source/WebCore/html/MediaElementSession.cpp:133
> +    PlatformMediaSession::clientWillPausePlayback();

Don't you want to call PlatformMediaSession::clientWillBeginAutoplaying() instead?

> Source/WebCore/html/MediaElementSession.cpp:134
> +    m_elementWasRemovedFromDOM = false;

Why does playback clear m_elementWasRemovedFromDOM?

> Source/WebCore/html/MediaElementSession.cpp:143
> +    m_elementWasRemovedFromDOM = false;

Ditto.

> Source/WebCore/html/MediaElementSession.cpp:162
> +    if (m_element.elementIsHidden())
> +        m_elementIsHiddenUntilVisibleInViewport = true;

Should this also check m_element.isFullscreen as inisVisibleInViewportChanged?

> LayoutTests/media/video-buffering-allowed.html:15
> +        function waitFor(element, event) {
> +            return new Promise(resolve => {
> +                element.addEventListener(event, event => {
> +                    consoleWrite(`EVENT(${event.type})`);
> +                    resolve(event);
> +                }, { once: true });
> +            });
> +        }

Nit: why not put this in video-test.js?

> LayoutTests/media/video-buffering-allowed.html:30
> +            run ('video.play()');

Nit: extra space after "run"

> LayoutTests/media/video-test.js:106
> +    return new Promise(async (resolve, reject) => {

Nit: reject is not used.
Comment 6 EWS Watchlist 2018-05-09 14:53:11 PDT Comment hidden (obsolete)
Comment 7 EWS Watchlist 2018-05-09 14:53:12 PDT Comment hidden (obsolete)
Comment 8 Jer Noble 2018-05-09 14:53:15 PDT
Comment on attachment 340016 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=340016&action=review

>> Source/WebCore/html/MediaElementSession.cpp:133
>> +    PlatformMediaSession::clientWillPausePlayback();
> 
> Don't you want to call PlatformMediaSession::clientWillBeginAutoplaying() instead?

Oof, yes.

>> Source/WebCore/html/MediaElementSession.cpp:134
>> +    m_elementWasRemovedFromDOM = false;
> 
> Why does playback clear m_elementWasRemovedFromDOM?

We only want to block loading until the media element tries to play.  If a video element was removed from the DOM, and then someone sets a src= and calls load(), we should unblock loading at this point.

>> Source/WebCore/html/MediaElementSession.cpp:143
>> +    m_elementWasRemovedFromDOM = false;
> 
> Ditto.

Ditto above.

>> Source/WebCore/html/MediaElementSession.cpp:162
>> +        m_elementIsHiddenUntilVisibleInViewport = true;
> 
> Should this also check m_element.isFullscreen as inisVisibleInViewportChanged?

So this is confusing. elementIsHidden() == document().hidden() && m_videoFullscreenMode != VideoFullscreenModePictureInPicture.  So it's already checking whether it's PiP.  I don't /think/ that the Document will be hidden() when the video element is in standard fullscreen mode, and it definitely won't when in element fullscreen mode.  But just for sake of clarity, maybe we should explicitly check isFullscreen() here.

>> LayoutTests/media/video-buffering-allowed.html:15
>> +        }
> 
> Nit: why not put this in video-test.js?

Mostly just because of the risk of name collisions, and not wanting to make all the waitForEventAnd...() variants. :)

>> LayoutTests/media/video-test.js:106
>> +    return new Promise(async (resolve, reject) => {
> 
> Nit: reject is not used.

will remove.
Comment 9 Eric Carlson 2018-05-09 15:39:32 PDT
Comment on attachment 340016 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=340016&action=review

>>> Source/WebCore/html/MediaElementSession.cpp:134
>>> +    m_elementWasRemovedFromDOM = false;
>> 
>> Why does playback clear m_elementWasRemovedFromDOM?
> 
> We only want to block loading until the media element tries to play.  If a video element was removed from the DOM, and then someone sets a src= and calls load(), we should unblock loading at this point.

Sure, but m_elementWasRemovedFromDOM is probably not the right name for a variable that really means "allowed to load data".

>>> Source/WebCore/html/MediaElementSession.cpp:143
>>> +    m_elementWasRemovedFromDOM = false;
>> 
>> Ditto.
> 
> Ditto above.

Ditto.
Comment 10 Jer Noble 2018-05-09 15:53:22 PDT
Created attachment 340045 [details]
Patch for landing
Comment 11 Jer Noble 2018-05-14 10:21:27 PDT
Created attachment 340326 [details]
Patch for landing
Comment 12 Jer Noble 2018-05-14 11:07:11 PDT
Created attachment 340332 [details]
Patch for landing
Comment 13 EWS Watchlist 2018-05-14 13:08:35 PDT
Comment on attachment 340332 [details]
Patch for landing

Attachment 340332 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/7680059

Number of test failures exceeded the failure limit.
Comment 14 EWS Watchlist 2018-05-14 13:08:36 PDT
Created attachment 340347 [details]
Archive of layout-test-results from ews117 for mac-sierra

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews117  Port: mac-sierra  Platform: Mac OS X 10.12.6
Comment 15 Jer Noble 2018-05-14 16:40:04 PDT
Created attachment 340376 [details]
Patch for landing
Comment 16 WebKit Commit Bot 2018-05-15 16:01:19 PDT
Comment on attachment 340376 [details]
Patch for landing

Clearing flags on attachment: 340376

Committed r231817: <https://trac.webkit.org/changeset/231817>
Comment 17 WebKit Commit Bot 2018-05-15 16:01:21 PDT
All reviewed patches have been landed.  Closing bug.