Title: [247118] trunk/Source/WebCore
Revision
247118
Author
jer.no...@apple.com
Date
2019-07-03 17:08:00 -0700 (Wed, 03 Jul 2019)

Log Message

HTMLMediaElement can hold onto display sleep assertion while process is suspended.
https://bugs.webkit.org/show_bug.cgi?id=199471
<rdar://problem/52124320>

If the WebContent process is suspended before HTMLMediaElement gets a callback telling it
that the MediaPlayer has stopped playing, the SleepDisabler may stay set (and hold a display
or system sleep assertion) for the entire duration the process is suspended, causing excess
power drain.

Add a PlatformMediaSessionClient method (and an implementation in HTMLMediaElement) which will
be called during the preperation for process suspension, and in this callback, clear the
SleepDisabler token.

Reviewed by Eric Carlson.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::shouldDisableSleep const):
(WebCore::HTMLMediaElement::processIsSuspendedChanged):
* html/HTMLMediaElement.h:
* platform/audio/PlatformMediaSession.h:
(WebCore::PlatformMediaSessionClient::processIsSuspendedChanged):
* platform/audio/PlatformMediaSessionManager.cpp:
(WebCore::PlatformMediaSessionManager::processWillSuspend):
(WebCore::PlatformMediaSessionManager::processDidResume):
* platform/audio/PlatformMediaSessionManager.h:
(WebCore::PlatformMediaSessionManager::processIsSuspended const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (247117 => 247118)


--- trunk/Source/WebCore/ChangeLog	2019-07-03 23:26:03 UTC (rev 247117)
+++ trunk/Source/WebCore/ChangeLog	2019-07-04 00:08:00 UTC (rev 247118)
@@ -1,3 +1,32 @@
+2019-07-03  Jer Noble  <jer.no...@apple.com>
+
+        HTMLMediaElement can hold onto display sleep assertion while process is suspended.
+        https://bugs.webkit.org/show_bug.cgi?id=199471
+        <rdar://problem/52124320>
+
+        If the WebContent process is suspended before HTMLMediaElement gets a callback telling it
+        that the MediaPlayer has stopped playing, the SleepDisabler may stay set (and hold a display
+        or system sleep assertion) for the entire duration the process is suspended, causing excess
+        power drain.
+
+        Add a PlatformMediaSessionClient method (and an implementation in HTMLMediaElement) which will
+        be called during the preperation for process suspension, and in this callback, clear the
+        SleepDisabler token.
+
+        Reviewed by Eric Carlson.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::shouldDisableSleep const):
+        (WebCore::HTMLMediaElement::processIsSuspendedChanged):
+        * html/HTMLMediaElement.h:
+        * platform/audio/PlatformMediaSession.h:
+        (WebCore::PlatformMediaSessionClient::processIsSuspendedChanged):
+        * platform/audio/PlatformMediaSessionManager.cpp:
+        (WebCore::PlatformMediaSessionManager::processWillSuspend):
+        (WebCore::PlatformMediaSessionManager::processDidResume):
+        * platform/audio/PlatformMediaSessionManager.h:
+        (WebCore::PlatformMediaSessionManager::processIsSuspended const):
+
 2019-07-03  Jonathan Bedard  <jbed...@apple.com>
 
         [Catalina] Enable WebKit build

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (247117 => 247118)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2019-07-03 23:26:03 UTC (rev 247117)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2019-07-04 00:08:00 UTC (rev 247118)
@@ -6923,6 +6923,9 @@
         return SleepType::System;
 #endif
 
+    if (PlatformMediaSessionManager::sharedManager().processIsSuspended())
+        return SleepType::None;
+
     bool shouldBeAbleToSleep = !hasVideo() || !hasAudio();
 #if ENABLE(MEDIA_STREAM)
     // Remote media stream video tracks may have their corresponding audio tracks being played outside of the media element. Let's ensure to not IDLE the screen in that case.
@@ -7742,6 +7745,12 @@
 {
     return document().processingUserGestureForMedia();
 }
+
+void HTMLMediaElement::processIsSuspendedChanged()
+{
+    updateSleepDisabling();
+}
+
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
 
 void HTMLMediaElement::scheduleUpdateMediaState()

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (247117 => 247118)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2019-07-03 23:26:03 UTC (rev 247117)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2019-07-04 00:08:00 UTC (rev 247118)
@@ -894,6 +894,7 @@
     bool canProduceAudio() const final;
     bool processingUserGestureForMedia() const final;
     bool hasMediaStreamSource() const final;
+    void processIsSuspendedChanged() final;
 
     void pageMutedStateDidChange() override;
 

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSession.h (247117 => 247118)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSession.h	2019-07-03 23:26:03 UTC (rev 247117)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSession.h	2019-07-04 00:08:00 UTC (rev 247118)
@@ -259,6 +259,8 @@
 
     virtual bool hasMediaStreamSource() const { return false; }
 
+    virtual void processIsSuspendedChanged() { }
+
 protected:
     virtual ~PlatformMediaSessionClient() = default;
 };

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp (247117 => 247118)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp	2019-07-03 23:26:03 UTC (rev 247117)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp	2019-07-04 00:08:00 UTC (rev 247118)
@@ -368,6 +368,10 @@
         return;
     m_processIsSuspended = true;
 
+    forEachSession([&] (auto& session) {
+        session.client().processIsSuspendedChanged();
+    });
+
 #if USE(AUDIO_SESSION)
     if (m_becameActive && shouldDeactivateAudioSession()) {
         AudioSession::sharedSession().tryToSetActive(false);
@@ -383,6 +387,10 @@
         return;
     m_processIsSuspended = false;
 
+    forEachSession([&] (auto& session) {
+        session.client().processIsSuspendedChanged();
+    });
+
 #if USE(AUDIO_SESSION)
     if (!m_becameActive && activeAudioSessionRequired()) {
         m_becameActive = AudioSession::sharedSession().tryToSetActive(true);

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h (247117 => 247118)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h	2019-07-03 23:26:03 UTC (rev 247117)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h	2019-07-04 00:08:00 UTC (rev 247118)
@@ -134,6 +134,8 @@
 
     void forEachMatchingSession(const Function<bool(const PlatformMediaSession&)>& predicate, const Function<void(PlatformMediaSession&)>& matchingCallback);
 
+    bool processIsSuspended() const { return m_processIsSuspended; }
+
 protected:
     friend class PlatformMediaSession;
     explicit PlatformMediaSessionManager();
@@ -147,8 +149,6 @@
 
     AudioHardwareListener* audioHardwareListener() { return m_audioHardwareListener.get(); }
 
-    bool processIsSuspended() const { return m_processIsSuspended; }
-
 #if !RELEASE_LOG_DISABLED
     const Logger& logger() const final { return m_logger; }
     const void* logIdentifier() const final { return nullptr; }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to