Title: [282999] branches/safari-612-branch/Source/WebCore
Revision
282999
Author
[email protected]
Date
2021-09-23 13:14:18 -0700 (Thu, 23 Sep 2021)

Log Message

Cherry-pick r281996. rdar://problem/83460851

    [iOS] Media playback continues after backgrounding Safari
    https://bugs.webkit.org/show_bug.cgi?id=229827

    Reviewed by Eric Carlson.

    In r277766, we make a video element ignore the background playback restriction
    (`HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction()` returns true)
    if the video element can *potentially* enter picture-in-picture automatically
    (either the video element is currently in the video fullscreen mode
    or m_videoFullscreenStandby is true).

    Unfortunately, this is not the correct fix if the OS has disabled the
    "Start PiP Automatically" feature. The problem is that a video continues
    playing after Safari is in the background.

    Only when the video element is in the picture-in-picture mode, the video element
    can ignore the background playback restriction.

    The UI process will receive "didStartPictureInPicture" notification (if any)
    and "applicationDidEnterBackground" notification in order. The UI process will
    send IPC messages to the WebContent process regarding the notifications.

    1) For the "didStartPictureInPicture" notification, the WebContent process will
    modify the corresponding video element's presentation mode to picture-in-picture.
    2) For the "applicationDidEnterBackground" notification, the WebContent process
    will call `PlatformMediaSession::beginInterruption()` to suspend media playback
    if needed.

    It is guaranteed that 1) happens before 2). Therefore, when
    `PlatformMediaSession::beginInterruption()` calls `HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction()`,
    if the video element enters picture-in-picture ("Start PiP Automatically" is enabled),
    `m_videoFullscreenMode` must be `VideoFullscreenModePictureInPicture`.
    Therefore, `HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction()`
    should return true when `m_videoFullscreenMode == VideoFullscreenModePictureInPicture`.

    Tested manually.

    * html/HTMLMediaElement.cpp:
    (WebCore::HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction const):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281996 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-612-branch/Source/WebCore/ChangeLog (282998 => 282999)


--- branches/safari-612-branch/Source/WebCore/ChangeLog	2021-09-23 20:14:14 UTC (rev 282998)
+++ branches/safari-612-branch/Source/WebCore/ChangeLog	2021-09-23 20:14:18 UTC (rev 282999)
@@ -1,5 +1,94 @@
 2021-09-23  Russell Epstein  <[email protected]>
 
+        Cherry-pick r281996. rdar://problem/83460851
+
+    [iOS] Media playback continues after backgrounding Safari
+    https://bugs.webkit.org/show_bug.cgi?id=229827
+    
+    Reviewed by Eric Carlson.
+    
+    In r277766, we make a video element ignore the background playback restriction
+    (`HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction()` returns true)
+    if the video element can *potentially* enter picture-in-picture automatically
+    (either the video element is currently in the video fullscreen mode
+    or m_videoFullscreenStandby is true).
+    
+    Unfortunately, this is not the correct fix if the OS has disabled the
+    "Start PiP Automatically" feature. The problem is that a video continues
+    playing after Safari is in the background.
+    
+    Only when the video element is in the picture-in-picture mode, the video element
+    can ignore the background playback restriction.
+    
+    The UI process will receive "didStartPictureInPicture" notification (if any)
+    and "applicationDidEnterBackground" notification in order. The UI process will
+    send IPC messages to the WebContent process regarding the notifications.
+    
+    1) For the "didStartPictureInPicture" notification, the WebContent process will
+    modify the corresponding video element's presentation mode to picture-in-picture.
+    2) For the "applicationDidEnterBackground" notification, the WebContent process
+    will call `PlatformMediaSession::beginInterruption()` to suspend media playback
+    if needed.
+    
+    It is guaranteed that 1) happens before 2). Therefore, when
+    `PlatformMediaSession::beginInterruption()` calls `HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction()`,
+    if the video element enters picture-in-picture ("Start PiP Automatically" is enabled),
+    `m_videoFullscreenMode` must be `VideoFullscreenModePictureInPicture`.
+    Therefore, `HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction()`
+    should return true when `m_videoFullscreenMode == VideoFullscreenModePictureInPicture`.
+    
+    Tested manually.
+    
+    * html/HTMLMediaElement.cpp:
+    (WebCore::HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction const):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281996 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-09-03  Peng Liu  <[email protected]>
+
+            [iOS] Media playback continues after backgrounding Safari
+            https://bugs.webkit.org/show_bug.cgi?id=229827
+
+            Reviewed by Eric Carlson.
+
+            In r277766, we make a video element ignore the background playback restriction
+            (`HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction()` returns true)
+            if the video element can *potentially* enter picture-in-picture automatically
+            (either the video element is currently in the video fullscreen mode
+            or m_videoFullscreenStandby is true).
+
+            Unfortunately, this is not the correct fix if the OS has disabled the
+            "Start PiP Automatically" feature. The problem is that a video continues
+            playing after Safari is in the background.
+
+            Only when the video element is in the picture-in-picture mode, the video element
+            can ignore the background playback restriction.
+
+            The UI process will receive "didStartPictureInPicture" notification (if any)
+            and "applicationDidEnterBackground" notification in order. The UI process will
+            send IPC messages to the WebContent process regarding the notifications.
+
+            1) For the "didStartPictureInPicture" notification, the WebContent process will
+            modify the corresponding video element's presentation mode to picture-in-picture.
+            2) For the "applicationDidEnterBackground" notification, the WebContent process
+            will call `PlatformMediaSession::beginInterruption()` to suspend media playback
+            if needed.
+
+            It is guaranteed that 1) happens before 2). Therefore, when
+            `PlatformMediaSession::beginInterruption()` calls `HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction()`,
+            if the video element enters picture-in-picture ("Start PiP Automatically" is enabled),
+            `m_videoFullscreenMode` must be `VideoFullscreenModePictureInPicture`.
+            Therefore, `HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction()`
+            should return true when `m_videoFullscreenMode == VideoFullscreenModePictureInPicture`.
+
+            Tested manually.
+
+            * html/HTMLMediaElement.cpp:
+            (WebCore::HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction const):
+
+2021-09-23  Russell Epstein  <[email protected]>
+
         Cherry-pick r281984. rdar://problem/83460908
 
     RemoteVideoSample needs CVPixelBufferRef to be kept alive, but relies on caller to retain it

Modified: branches/safari-612-branch/Source/WebCore/html/HTMLMediaElement.cpp (282998 => 282999)


--- branches/safari-612-branch/Source/WebCore/html/HTMLMediaElement.cpp	2021-09-23 20:14:14 UTC (rev 282998)
+++ branches/safari-612-branch/Source/WebCore/html/HTMLMediaElement.cpp	2021-09-23 20:14:18 UTC (rev 282999)
@@ -7804,11 +7804,9 @@
             INFO_LOG(LOGIDENTIFIER, "returning true because isPlayingToAutomotiveHeadUnit() is true");
             return true;
         }
-        if (m_videoFullscreenMode & VideoFullscreenModePictureInPicture)
+#if ENABLE(VIDEO_PRESENTATION_MODE)
+        if (m_videoFullscreenMode == VideoFullscreenModePictureInPicture)
             return true;
-#if PLATFORM(COCOA) && ENABLE(VIDEO_PRESENTATION_MODE)
-        if (((m_videoFullscreenMode == VideoFullscreenModeStandard) || m_videoFullscreenStandby) && supportsPictureInPicture() && isPlaying())
-            return true;
 #endif
 #if ENABLE(MEDIA_STREAM)
         if (hasMediaStreamSrcObject() && mediaState().containsAny(MediaProducer::MediaState::IsPlayingAudio) && document().mediaState().containsAny(MediaProducer::MediaState::HasActiveAudioCaptureDevice)) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to