Title: [166261] trunk
Revision
166261
Author
jer.no...@apple.com
Date
2014-03-25 15:26:34 -0700 (Tue, 25 Mar 2014)

Log Message

[Mac] Pause the media element during system sleep.
https://bugs.webkit.org/show_bug.cgi?id=130718

Reviewed by Eric Carlson.

Source/WebCore:

Test: media/video-system-sleep.html

Relying on the platform media system to pause and restart playback during
system sleep can cause problems on some platforms, especially where hardware
decoders are concerned. Rather than implicitly pausing the media during
system sleep, explicitly pause the media before sleeping and resume (if
appropriate) upon waking.

Add a new class to be used for system sleep notifications:
* platform/SystemSleepListener.cpp: Added.
(WebCore::SystemSleepListener::create):
(WebCore::SystemSleepListener::SystemSleepListener):
* platform/SystemSleepListener.h: Added.
(WebCore::SystemSleepListener::Client::~Client):
(WebCore::SystemSleepListener::~SystemSleepListener):
(WebCore::SystemSleepListener::client):

Add a Mac-specific implementation:
* platform/mac/SystemSleepListenerMac.h: Added.
* platform/mac/SystemSleepListenerMac.mm: Added.
(WebCore::SystemSleepListener::create):
(WebCore::SystemSleepListenerMac::SystemSleepListenerMac):
(WebCore::SystemSleepListenerMac::~SystemSleepListenerMac):

Listen for system sleep notifications in MediaSessionManager:
* platform/audio/MediaSessionManager.cpp:
(WebCore::MediaSessionManager::MediaSessionManager):
(WebCore::MediaSessionManager::systemWillSleep):
(WebCore::MediaSessionManager::systemDidWake):
* platform/audio/MediaSessionManager.h:

Drive-by fix; notify the MediaSession that playback will begin
due to autoplay, but do not begin autoplaying if the session
is already interrupted:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::parseAttribute):

Add new files to project:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.xcodeproj/project.pbxproj:
* CMakeLists.txt:
* GNUmakefile.list.am:

LayoutTests:

* media/video-system-sleep-expected.txt: Added.
* media/video-system-sleep.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (166260 => 166261)


--- trunk/LayoutTests/ChangeLog	2014-03-25 22:20:02 UTC (rev 166260)
+++ trunk/LayoutTests/ChangeLog	2014-03-25 22:26:34 UTC (rev 166261)
@@ -1,3 +1,13 @@
+2014-03-25  Jer Noble  <jer.no...@apple.com>
+
+        [Mac] Pause the media element during system sleep.
+        https://bugs.webkit.org/show_bug.cgi?id=130718
+
+        Reviewed by Eric Carlson.
+
+        * media/video-system-sleep-expected.txt: Added.
+        * media/video-system-sleep.html: Added.
+
 2014-03-25  Radu Stavila  <stav...@adobe.com>
 
         [CSS Regions] The background of children of scrollable elements flowed into regions is not properly scrolled

Added: trunk/LayoutTests/media/video-system-sleep-expected.txt (0 => 166261)


--- trunk/LayoutTests/media/video-system-sleep-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/media/video-system-sleep-expected.txt	2014-03-25 22:26:34 UTC (rev 166261)
@@ -0,0 +1,10 @@
+
+Test that video elements pause during system sleep.
+
+EVENT(playing)
+RUN(internals.simulateSystemSleep())
+EVENT(pause)
+RUN(internals.simulateSystemWake())
+EVENT(playing)
+END OF TEST
+

Added: trunk/LayoutTests/media/video-system-sleep.html (0 => 166261)


--- trunk/LayoutTests/media/video-system-sleep.html	                        (rev 0)
+++ trunk/LayoutTests/media/video-system-sleep.html	2014-03-25 22:26:34 UTC (rev 166261)
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <script src=""
+        <script src=""
+        <script>
+            function start()
+            {
+                if (!window.internals)
+                    consoleWrite('To run this test manually, cause the machine to sleep then wake up.');
+
+                findMediaElement();
+                waitForEventOnce('playing', playing);
+                video.src = "" "content/test");
+            }
+
+            function playing()
+            {
+                waitForEventOnce('pause', paused);
+                run('internals.simulateSystemSleep()');
+            }
+
+            function paused()
+            {
+                waitForEventOnce('playing', resumed);
+                run('internals.simulateSystemWake()');
+            }
+
+            function resumed()
+            {
+                endTest();
+            }
+        </script>
+    </head>
+
+    <body _onload_="start()">
+        <video controls autoplay></video>
+        <p>Test that video elements pause during system sleep.</p>
+    </body>
+</html>

Modified: trunk/Source/WebCore/CMakeLists.txt (166260 => 166261)


--- trunk/Source/WebCore/CMakeLists.txt	2014-03-25 22:20:02 UTC (rev 166260)
+++ trunk/Source/WebCore/CMakeLists.txt	2014-03-25 22:26:34 UTC (rev 166261)
@@ -1808,6 +1808,7 @@
     platform/PlatformEvent.cpp
     platform/PlatformStrategies.cpp
     platform/RemoteCommandListener.cpp
+    platform/SystemSleepListener.cpp
     platform/RuntimeApplicationChecks.cpp
     platform/SchemeRegistry.cpp
     platform/ScrollAnimator.cpp

Modified: trunk/Source/WebCore/ChangeLog (166260 => 166261)


--- trunk/Source/WebCore/ChangeLog	2014-03-25 22:20:02 UTC (rev 166260)
+++ trunk/Source/WebCore/ChangeLog	2014-03-25 22:26:34 UTC (rev 166261)
@@ -1,3 +1,53 @@
+2014-03-25  Jer Noble  <jer.no...@apple.com>
+
+        [Mac] Pause the media element during system sleep.
+        https://bugs.webkit.org/show_bug.cgi?id=130718
+
+        Reviewed by Eric Carlson.
+
+        Test: media/video-system-sleep.html
+
+        Relying on the platform media system to pause and restart playback during
+        system sleep can cause problems on some platforms, especially where hardware
+        decoders are concerned. Rather than implicitly pausing the media during
+        system sleep, explicitly pause the media before sleeping and resume (if
+        appropriate) upon waking.
+
+        Add a new class to be used for system sleep notifications:
+        * platform/SystemSleepListener.cpp: Added.
+        (WebCore::SystemSleepListener::create):
+        (WebCore::SystemSleepListener::SystemSleepListener):
+        * platform/SystemSleepListener.h: Added.
+        (WebCore::SystemSleepListener::Client::~Client):
+        (WebCore::SystemSleepListener::~SystemSleepListener):
+        (WebCore::SystemSleepListener::client):
+
+        Add a Mac-specific implementation:
+        * platform/mac/SystemSleepListenerMac.h: Added.
+        * platform/mac/SystemSleepListenerMac.mm: Added.
+        (WebCore::SystemSleepListener::create):
+        (WebCore::SystemSleepListenerMac::SystemSleepListenerMac):
+        (WebCore::SystemSleepListenerMac::~SystemSleepListenerMac):
+
+        Listen for system sleep notifications in MediaSessionManager:
+        * platform/audio/MediaSessionManager.cpp:
+        (WebCore::MediaSessionManager::MediaSessionManager):
+        (WebCore::MediaSessionManager::systemWillSleep):
+        (WebCore::MediaSessionManager::systemDidWake):
+        * platform/audio/MediaSessionManager.h:
+
+        Drive-by fix; notify the MediaSession that playback will begin
+        due to autoplay, but do not begin autoplaying if the session
+        is already interrupted:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::parseAttribute):
+
+        Add new files to project:
+        * WebCore.vcxproj/WebCore.vcxproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+
 2014-03-25  Radu Stavila  <stav...@adobe.com>
 
         [CSS Regions] The background of children of scrollable elements flowed into regions is not properly scrolled

Modified: trunk/Source/WebCore/GNUmakefile.list.am (166260 => 166261)


--- trunk/Source/WebCore/GNUmakefile.list.am	2014-03-25 22:20:02 UTC (rev 166260)
+++ trunk/Source/WebCore/GNUmakefile.list.am	2014-03-25 22:26:34 UTC (rev 166261)
@@ -5514,6 +5514,8 @@
 	Source/WebCore/platform/ScrollAnimator.h \
 	Source/WebCore/platform/ScrollAnimatorNone.cpp \
 	Source/WebCore/platform/ScrollAnimatorNone.h \
+	Source/WebCore/platform/SystemSleepListener.cpp \
+	Source/WebCore/platform/SystemSleepListener.h \
 	Source/WebCore/platform/ThreadGlobalData.cpp \
 	Source/WebCore/platform/ThreadGlobalData.h \
 	Source/WebCore/platform/UserActivity.cpp \

Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (166260 => 166261)


--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj	2014-03-25 22:20:02 UTC (rev 166260)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj	2014-03-25 22:26:34 UTC (rev 166261)
@@ -7622,6 +7622,7 @@
     <ClCompile Include="..\platform\ScrollView.cpp" />
     <ClCompile Include="..\platform\SharedBuffer.cpp" />
     <ClCompile Include="..\platform\SharedBufferChunkReader.cpp" />
+    <ClCompile Include="..\platform\SystemSleepListener.cpp" />
     <ClCompile Include="..\platform\ThreadGlobalData.cpp" />
     <ClCompile Include="..\platform\ThreadTimers.cpp" />
     <ClCompile Include="..\platform\Timer.cpp" />
@@ -19253,6 +19254,7 @@
     <ClInclude Include="..\platform\Sound.h" />
     <ClInclude Include="..\platform\SSLKeyGenerator.h" />
     <ClInclude Include="..\platform\SuddenTermination.h" />
+    <ClInclude Include="..\platform\SystemSleepListener.h" />
     <ClInclude Include="..\platform\ThemeTypes.h" />
     <ClInclude Include="..\platform\ThreadGlobalData.h" />
     <ClInclude Include="..\platform\ThreadTimers.h" />

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (166260 => 166261)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2014-03-25 22:20:02 UTC (rev 166260)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2014-03-25 22:26:34 UTC (rev 166261)
@@ -5559,6 +5559,10 @@
 		CD9DE17D17AAC75B00EA386D /* JSSourceBufferList.h in Headers */ = {isa = PBXBuildFile; fileRef = CD9DE17917AAC75B00EA386D /* JSSourceBufferList.h */; };
 		CD9DE18117AAD6A400EA386D /* DOMURLMediaSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD9DE17E17AAD64E00EA386D /* DOMURLMediaSource.cpp */; };
 		CD9DE18217AAD6A400EA386D /* DOMURLMediaSource.h in Headers */ = {isa = PBXBuildFile; fileRef = CD9DE17F17AAD64E00EA386D /* DOMURLMediaSource.h */; };
+		CDA07FBD18E0A16A004699FA /* SystemSleepListener.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDA07FBB18E0A16A004699FA /* SystemSleepListener.cpp */; };
+		CDA07FBE18E0A16A004699FA /* SystemSleepListener.h in Headers */ = {isa = PBXBuildFile; fileRef = CDA07FBC18E0A16A004699FA /* SystemSleepListener.h */; };
+		CDA07FC118E0A22B004699FA /* SystemSleepListenerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDA07FBF18E0A22B004699FA /* SystemSleepListenerMac.mm */; };
+		CDA07FC218E0A22B004699FA /* SystemSleepListenerMac.h in Headers */ = {isa = PBXBuildFile; fileRef = CDA07FC018E0A22B004699FA /* SystemSleepListenerMac.h */; };
 		CDA79824170A258300D45C55 /* AudioSession.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDA79823170A258300D45C55 /* AudioSession.cpp */; };
 		CDA79827170A279100D45C55 /* AudioSessionIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDA79825170A279000D45C55 /* AudioSessionIOS.mm */; };
 		CDA7982A170A3D0000D45C55 /* AudioSession.h in Headers */ = {isa = PBXBuildFile; fileRef = CDA79821170A22DC00D45C55 /* AudioSession.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -12870,6 +12874,10 @@
 		CD9DE17E17AAD64E00EA386D /* DOMURLMediaSource.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DOMURLMediaSource.cpp; sourceTree = "<group>"; };
 		CD9DE17F17AAD64E00EA386D /* DOMURLMediaSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DOMURLMediaSource.h; sourceTree = "<group>"; };
 		CD9DE18017AAD64E00EA386D /* DOMURLMediaSource.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = DOMURLMediaSource.idl; sourceTree = "<group>"; };
+		CDA07FBB18E0A16A004699FA /* SystemSleepListener.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SystemSleepListener.cpp; sourceTree = "<group>"; };
+		CDA07FBC18E0A16A004699FA /* SystemSleepListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SystemSleepListener.h; sourceTree = "<group>"; };
+		CDA07FBF18E0A22B004699FA /* SystemSleepListenerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SystemSleepListenerMac.mm; sourceTree = "<group>"; };
+		CDA07FC018E0A22B004699FA /* SystemSleepListenerMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SystemSleepListenerMac.h; sourceTree = "<group>"; };
 		CDA79821170A22DC00D45C55 /* AudioSession.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AudioSession.h; sourceTree = "<group>"; };
 		CDA79822170A24F400D45C55 /* AudioSessionListener.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AudioSessionListener.h; sourceTree = "<group>"; };
 		CDA79823170A258300D45C55 /* AudioSession.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioSession.cpp; sourceTree = "<group>"; };
@@ -16118,6 +16126,8 @@
 				4B3043C80AE0371D00A82647 /* SoundMac.mm */,
 				84B2B24F056BF15F00D2B771 /* SSLKeyGeneratorMac.cpp */,
 				93B2D8170F9920EE006AE6B2 /* SuddenTermination.mm */,
+				CDA07FBF18E0A22B004699FA /* SystemSleepListenerMac.mm */,
+				CDA07FC018E0A22B004699FA /* SystemSleepListenerMac.h */,
 				5DA97ECB168E787B000E3676 /* SystemVersionMac.h */,
 				5DA97ECC168E787B000E3676 /* SystemVersionMac.mm */,
 				BCE659E50EA92FB2007E4533 /* ThemeMac.h */,
@@ -21045,6 +21055,8 @@
 				E1E1BEFF115FF6FB006F52CA /* WindowsKeyboardCodes.h */,
 				CDFC360318CA61C20026E56F /* RemoteCommandListener.cpp */,
 				CDFC360418CA61C20026E56F /* RemoteCommandListener.h */,
+				CDA07FBB18E0A16A004699FA /* SystemSleepListener.cpp */,
+				CDA07FBC18E0A16A004699FA /* SystemSleepListener.h */,
 			);
 			path = platform;
 			sourceTree = "<group>";
@@ -23508,6 +23520,7 @@
 				85E711B90AC5D5350053270F /* DOMHTMLMapElementInternal.h in Headers */,
 				BC51579F0C03BBD3008BB0EE /* DOMHTMLMarqueeElement.h in Headers */,
 				BC5156EA0C03B741008BB0EE /* DOMHTMLMarqueeElementInternal.h in Headers */,
+				CDA07FBE18E0A16A004699FA /* SystemSleepListener.h in Headers */,
 				85BA4D130AA688680088052D /* DOMHTMLMenuElement.h in Headers */,
 				85E711BA0AC5D5350053270F /* DOMHTMLMenuElementInternal.h in Headers */,
 				859A9C4D0AA5E3BD00B694B2 /* DOMHTMLMetaElement.h in Headers */,
@@ -25902,6 +25915,7 @@
 				1C18DA59181AF6A500C4EF22 /* TextPainter.h in Headers */,
 				E4C91A0E1802343100A17F6D /* TextPaintStyle.h in Headers */,
 				930FC68A1072B9280045293E /* TextRenderingMode.h in Headers */,
+				CDA07FC218E0A22B004699FA /* SystemSleepListenerMac.h in Headers */,
 				93F198F608245E59001E9ABC /* TextResourceDecoder.h in Headers */,
 				A824B4650E2EF2EA0081A7B7 /* TextRun.h in Headers */,
 				448B1B7A0F3A2F9B0047A9E2 /* TextSizeAdjustment.h in Headers */,
@@ -28224,6 +28238,7 @@
 				31611E5A0E1C4DE000F6A579 /* JSWebKitCSSTransformValue.cpp in Sources */,
 				3F2B33EE165AF15600E3987C /* JSWebKitCSSViewportRule.cpp in Sources */,
 				D7613AC414753E5600DB8606 /* JSWebKitNamedFlow.cpp in Sources */,
+				CDA07FC118E0A22B004699FA /* SystemSleepListenerMac.mm in Sources */,
 				0FDA7C261883333200C954B5 /* JSWebKitPlaybackTargetAvailabilityEvent.cpp in Sources */,
 				494BD79D0F55C94C00747828 /* JSWebKitPoint.cpp in Sources */,
 				BC275B7911C5D1C300C9206C /* JSWebKitPointCustom.cpp in Sources */,
@@ -29050,6 +29065,7 @@
 				B2227A320D00BF220071B782 /* SVGLength.cpp in Sources */,
 				7134496D146941B300720312 /* SVGLengthContext.cpp in Sources */,
 				B2227A350D00BF220071B782 /* SVGLengthList.cpp in Sources */,
+				CDA07FBD18E0A16A004699FA /* SystemSleepListener.cpp in Sources */,
 				B2227A380D00BF220071B782 /* SVGLinearGradientElement.cpp in Sources */,
 				B2227A3B0D00BF220071B782 /* SVGLineElement.cpp in Sources */,
 				B2227A400D00BF220071B782 /* SVGLocatable.cpp in Sources */,

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (166260 => 166261)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2014-03-25 22:20:02 UTC (rev 166260)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2014-03-25 22:26:34 UTC (rev 166261)
@@ -4429,6 +4429,8 @@
         invalidateCachedTime();
 
         if (playerPaused) {
+            m_mediaSession->clientWillBeginPlayback();
+
             if (m_mediaSession->requiresFullscreenForVideoPlayback(*this) && !isFullscreen())
                 enterFullscreen();
 

Added: trunk/Source/WebCore/platform/SystemSleepListener.cpp (0 => 166261)


--- trunk/Source/WebCore/platform/SystemSleepListener.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/SystemSleepListener.cpp	2014-03-25 22:26:34 UTC (rev 166261)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "SystemSleepListener.h"
+
+namespace WebCore {
+
+#if !PLATFORM(MAC)
+std::unique_ptr<SystemSleepListener> SystemSleepListener::create(Client& client)
+{
+    return std::unique_ptr<SystemSleepListener>(new SystemSleepListener(client));
+}
+#endif
+
+SystemSleepListener::SystemSleepListener(Client& client)
+    : m_client(client)
+{
+}
+
+}

Added: trunk/Source/WebCore/platform/SystemSleepListener.h (0 => 166261)


--- trunk/Source/WebCore/platform/SystemSleepListener.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/SystemSleepListener.h	2014-03-25 22:26:34 UTC (rev 166261)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SystemSleepListener_h
+#define SystemSleepListener_h
+
+namespace WebCore {
+
+class SystemSleepListener {
+public:
+    class Client {
+    public:
+        virtual ~Client() { }
+        virtual void systemWillSleep() = 0;
+        virtual void systemDidWake() = 0;
+    };
+
+    static std::unique_ptr<SystemSleepListener> create(Client&);
+    virtual ~SystemSleepListener() { }
+
+    Client& client() { return m_client; }
+
+protected:
+    SystemSleepListener(Client&);
+    
+    Client& m_client;
+};
+
+}
+
+
+#endif // SystemSleepListener_h

Modified: trunk/Source/WebCore/platform/audio/MediaSessionManager.cpp (166260 => 166261)


--- trunk/Source/WebCore/platform/audio/MediaSessionManager.cpp	2014-03-25 22:20:02 UTC (rev 166260)
+++ trunk/Source/WebCore/platform/audio/MediaSessionManager.cpp	2014-03-25 22:26:34 UTC (rev 166261)
@@ -42,7 +42,8 @@
 #endif
 
 MediaSessionManager::MediaSessionManager()
-    : m_interrupted(false)
+    : m_systemSleepListener(SystemSleepListener::create(*this))
+    , m_interrupted(false)
 {
     resetRestrictions();
 }
@@ -301,6 +302,24 @@
     m_clients.remove(m_clients.find(client));
 }
 
+void MediaSessionManager::systemWillSleep()
+{
+    if (m_interrupted)
+        return;
+
+    for (auto session : m_sessions)
+        session->beginInterruption();
 }
 
+void MediaSessionManager::systemDidWake()
+{
+    if (m_interrupted)
+        return;
+
+    for (auto session : m_sessions)
+        session->endInterruption(MediaSession::MayResumePlaying);
+}
+
+}
+
 #endif

Modified: trunk/Source/WebCore/platform/audio/MediaSessionManager.h (166260 => 166261)


--- trunk/Source/WebCore/platform/audio/MediaSessionManager.h	2014-03-25 22:20:02 UTC (rev 166260)
+++ trunk/Source/WebCore/platform/audio/MediaSessionManager.h	2014-03-25 22:26:34 UTC (rev 166261)
@@ -29,6 +29,7 @@
 #include "MediaSession.h"
 #include "RemoteCommandListener.h"
 #include "Settings.h"
+#include "SystemSleepListener.h"
 #include <map>
 #include <wtf/Vector.h>
 
@@ -51,7 +52,7 @@
     MediaSessionManagerClient() { }
 };
 
-class MediaSessionManager : RemoteCommandListenerClient {
+class MediaSessionManager : RemoteCommandListenerClient, SystemSleepListener::Client {
 public:
     static MediaSessionManager& sharedManager();
     virtual ~MediaSessionManager() { }
@@ -105,13 +106,19 @@
     MediaSession* currentSession();
     
 private:
+    friend class Internals;
+
     void updateSessionState();
 
+    virtual void systemWillSleep();
+    virtual void systemDidWake();
+
     SessionRestrictions m_restrictions[MediaSession::WebAudio + 1];
 
     Vector<MediaSession*> m_sessions;
     Vector<MediaSessionManagerClient*> m_clients;
     std::unique_ptr<RemoteCommandListener> m_remoteCommandListener;
+    std::unique_ptr<SystemSleepListener> m_systemSleepListener;
     bool m_interrupted;
 };
 

Added: trunk/Source/WebCore/platform/mac/SystemSleepListenerMac.h (0 => 166261)


--- trunk/Source/WebCore/platform/mac/SystemSleepListenerMac.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/mac/SystemSleepListenerMac.h	2014-03-25 22:26:34 UTC (rev 166261)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SystemSleepListenerMac_h
+#define SystemSleepListenerMac_h
+
+#if PLATFORM(MAC)
+
+#include "SystemSleepListener.h"
+
+#include <wtf/WeakPtr.h>
+
+namespace WebCore {
+
+class SystemSleepListenerMac : public SystemSleepListener {
+protected:
+    SystemSleepListenerMac(Client&);
+    virtual ~SystemSleepListenerMac();
+
+    friend std::unique_ptr<SystemSleepListener> SystemSleepListener::create(Client&);
+
+    WeakPtrFactory<SystemSleepListenerMac> m_weakPtrFactory;
+    id m_sleepObserver;
+    id m_wakeObserver;
+};
+
+}
+
+#endif // PLATFORM(MAC)
+
+#endif // SystemSleepListenerMac_h

Added: trunk/Source/WebCore/platform/mac/SystemSleepListenerMac.mm (0 => 166261)


--- trunk/Source/WebCore/platform/mac/SystemSleepListenerMac.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/mac/SystemSleepListenerMac.mm	2014-03-25 22:26:34 UTC (rev 166261)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "SystemSleepListenerMac.h"
+
+#if PLATFORM(MAC)
+
+#import <wtf/MainThread.h>
+
+namespace WebCore {
+
+std::unique_ptr<SystemSleepListener> SystemSleepListener::create(Client& client)
+{
+    return std::unique_ptr<SystemSleepListener>(new SystemSleepListenerMac(client));
+}
+
+SystemSleepListenerMac::SystemSleepListenerMac(Client& client)
+    : SystemSleepListener(client)
+    , m_weakPtrFactory(this)
+    , m_sleepObserver(nil)
+    , m_wakeObserver(nil)
+{
+    NSNotificationCenter *center = [[NSWorkspace sharedWorkspace] notificationCenter];
+    NSOperationQueue *queue = [NSOperationQueue mainQueue];
+
+    auto weakThis = m_weakPtrFactory.createWeakPtr();
+
+    m_sleepObserver = [center addObserverForName:NSWorkspaceWillSleepNotification object:nil queue:queue usingBlock:^(NSNotification *) {
+        callOnMainThread([weakThis] {
+            if (weakThis)
+                weakThis->m_client.systemWillSleep();
+        });
+    }];
+
+    m_wakeObserver = [center addObserverForName:NSWorkspaceDidWakeNotification object:nil queue:queue usingBlock:^(NSNotification *) {
+        callOnMainThread([weakThis] {
+            if (weakThis)
+                weakThis->m_client.systemDidWake();
+        });
+    }];
+}
+
+SystemSleepListenerMac::~SystemSleepListenerMac()
+{
+    NSNotificationCenter* center = [[NSWorkspace sharedWorkspace] notificationCenter];
+    [center removeObserver:m_sleepObserver];
+    [center removeObserver:m_wakeObserver];
+}
+
+}
+
+#endif // PLATFORM(MAC)

Modified: trunk/Source/WebCore/testing/Internals.cpp (166260 => 166261)


--- trunk/Source/WebCore/testing/Internals.cpp	2014-03-25 22:20:02 UTC (rev 166260)
+++ trunk/Source/WebCore/testing/Internals.cpp	2014-03-25 22:26:34 UTC (rev 166261)
@@ -2333,4 +2333,14 @@
 }
 #endif // ENABLE(VIDEO)
 
+void Internals::simulateSystemSleep() const
+{
+    MediaSessionManager::sharedManager().systemWillSleep();
 }
+
+void Internals::simulateSystemWake() const
+{
+    MediaSessionManager::sharedManager().systemDidWake();
+}
+
+}

Modified: trunk/Source/WebCore/testing/Internals.h (166260 => 166261)


--- trunk/Source/WebCore/testing/Internals.h	2014-03-25 22:20:02 UTC (rev 166260)
+++ trunk/Source/WebCore/testing/Internals.h	2014-03-25 22:26:34 UTC (rev 166261)
@@ -340,6 +340,9 @@
     void postRemoteControlCommand(const String&, ExceptionCode&);
 #endif
 
+    void simulateSystemSleep() const;
+    void simulateSystemWake() const;
+
 private:
     explicit Internals(Document*);
     Document* contextDocument() const;

Modified: trunk/Source/WebCore/testing/Internals.idl (166260 => 166261)


--- trunk/Source/WebCore/testing/Internals.idl	2014-03-25 22:20:02 UTC (rev 166260)
+++ trunk/Source/WebCore/testing/Internals.idl	2014-03-25 22:26:34 UTC (rev 166261)
@@ -286,4 +286,7 @@
     [Conditional=VIDEO] void applicationWillEnterBackground();
     [Conditional=VIDEO, RaisesException] void setMediaSessionRestrictions(DOMString mediaType, DOMString restrictions);
     [Conditional=VIDEO, RaisesException] void postRemoteControlCommand(DOMString command);
+    
+    [Conditional=VIDEO] void simulateSystemSleep();
+    [Conditional=VIDEO] void simulateSystemWake();
 };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to