Title: [186251] trunk/Source/WebCore
Revision
186251
Author
bfulg...@apple.com
Date
2015-07-02 18:44:40 -0700 (Thu, 02 Jul 2015)

Log Message

Ensure media playback is stopped during page close
https://bugs.webkit.org/show_bug.cgi?id=146554
<rdar://problem/18033944>

Reviewed by Zalan Bujtas.

Add new method to Page class to stop all media playback. It just uses the process
MediaSessionManager singleton to inform all hosted in a particular document to stop.

* Modules/webaudio/AudioContext.h:
(WebCore::WebAudio::hostingDocument): Added.
* html/HTMLMediaElement.h:
(WebCore::HTMLMediaElement::hostingDocument): Added.
* dom/Document.cpp:
(WebCore::Document::commonTeardown): Call the new PlatformMediaSessionManager::stopAllMediaPlaybackForDocument
method on document cleanup.
* platform/audio/PlatformMediaSession.h:
Made PlatformMediaSessionManager a friend so it can access the protected 'client' accessor.
Updated PlatformMediaSessionClient to require clients to have a "hostingDocument" member.
* platform/audio/PlatformMediaSessionManager.cpp:
(WebCore::PlatformMediaSessionManager::stopAllMediaPlaybackForDocument): Added. Only pauses
playback on elements that match the provided document.
* platform/audio/PlatformMediaSessionManager.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (186250 => 186251)


--- trunk/Source/WebCore/ChangeLog	2015-07-03 01:43:21 UTC (rev 186250)
+++ trunk/Source/WebCore/ChangeLog	2015-07-03 01:44:40 UTC (rev 186251)
@@ -1,3 +1,29 @@
+2015-07-02  Brent Fulgham  <bfulg...@apple.com>
+
+        Ensure media playback is stopped during page close
+        https://bugs.webkit.org/show_bug.cgi?id=146554
+        <rdar://problem/18033944>
+
+        Reviewed by Zalan Bujtas.
+
+        Add new method to Page class to stop all media playback. It just uses the process
+        MediaSessionManager singleton to inform all hosted in a particular document to stop.
+
+        * Modules/webaudio/AudioContext.h:
+        (WebCore::WebAudio::hostingDocument): Added.
+        * html/HTMLMediaElement.h:
+        (WebCore::HTMLMediaElement::hostingDocument): Added.
+        * dom/Document.cpp:
+        (WebCore::Document::commonTeardown): Call the new PlatformMediaSessionManager::stopAllMediaPlaybackForDocument
+        method on document cleanup.
+        * platform/audio/PlatformMediaSession.h:
+        Made PlatformMediaSessionManager a friend so it can access the protected 'client' accessor.
+        Updated PlatformMediaSessionClient to require clients to have a "hostingDocument" member.
+        * platform/audio/PlatformMediaSessionManager.cpp:
+        (WebCore::PlatformMediaSessionManager::stopAllMediaPlaybackForDocument): Added. Only pauses
+        playback on elements that match the provided document.
+        * platform/audio/PlatformMediaSessionManager.h:
+
 2015-07-02  Dean Jackson  <d...@apple.com>
 
         Tapping a video in Safari causes the video to flash gray for a quick moment

Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.h (186250 => 186251)


--- trunk/Source/WebCore/Modules/webaudio/AudioContext.h	2015-07-03 01:43:21 UTC (rev 186250)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.h	2015-07-03 01:44:40 UTC (rev 186251)
@@ -90,6 +90,8 @@
 
     Document* document() const; // ASSERTs if document no longer exists.
 
+    Document* hostingDocument() const override final { return document(); }
+
     AudioDestinationNode* destination() { return m_destinationNode.get(); }
     size_t currentSampleFrame() const { return m_destinationNode->currentSampleFrame(); }
     double currentTime() const { return m_destinationNode->currentTime(); }

Modified: trunk/Source/WebCore/dom/Document.cpp (186250 => 186251)


--- trunk/Source/WebCore/dom/Document.cpp	2015-07-03 01:43:21 UTC (rev 186250)
+++ trunk/Source/WebCore/dom/Document.cpp	2015-07-03 01:44:40 UTC (rev 186251)
@@ -112,6 +112,7 @@
 #include "PageGroup.h"
 #include "PageTransitionEvent.h"
 #include "PlatformLocale.h"
+#include "PlatformMediaSessionManager.h"
 #include "PlatformStrategies.h"
 #include "PlugInsResources.h"
 #include "PluginDocument.h"
@@ -700,6 +701,8 @@
     if (svgExtensions())
         accessSVGExtensions().pauseAnimations();
 
+    PlatformMediaSessionManager::sharedManager().stopAllMediaPlaybackForDocument(*this);
+
 #if ENABLE(REQUEST_ANIMATION_FRAME)
     clearScriptedAnimationController();
 #endif

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (186250 => 186251)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2015-07-03 01:43:21 UTC (rev 186250)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2015-07-03 01:44:40 UTC (rev 186251)
@@ -147,7 +147,9 @@
     MediaPlayerEnums::MovieLoadType movieLoadType() const;
     
     bool inActiveDocument() const { return m_inActiveDocument; }
-    
+
+    Document* hostingDocument() const override final { return &document(); }
+
 // DOM API
 // error state
     PassRefPtr<MediaError> error() const;

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSession.h (186250 => 186251)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSession.h	2015-07-03 01:43:21 UTC (rev 186250)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSession.h	2015-07-03 01:44:40 UTC (rev 186251)
@@ -37,6 +37,7 @@
 
 namespace WebCore {
 
+class Document;
 class MediaPlaybackTarget;
 class PlatformMediaSessionClient;
 
@@ -145,6 +146,8 @@
     State m_stateToRestore;
     int m_interruptionCount { 0 };
     bool m_notifyingClient;
+
+    friend class PlatformMediaSessionManager;
 };
 
 class PlatformMediaSessionClient {
@@ -177,6 +180,8 @@
     virtual bool isPlayingToWirelessPlaybackTarget() const { return false; }
     virtual void setShouldPlayToPlaybackTarget(bool) { }
 
+    virtual Document* hostingDocument() const = 0;
+
 protected:
     virtual ~PlatformMediaSessionClient() { }
 };

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp (186250 => 186251)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp	2015-07-03 01:43:21 UTC (rev 186250)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp	2015-07-03 01:44:40 UTC (rev 186251)
@@ -29,6 +29,7 @@
 #if ENABLE(VIDEO)
 
 #include "AudioSession.h"
+#include "Document.h"
 #include "Logging.h"
 #include "NotImplemented.h"
 #include "PlatformMediaSession.h"
@@ -329,6 +330,14 @@
     updateSessionState();
 }
 
+void PlatformMediaSessionManager::stopAllMediaPlaybackForDocument(const Document& document)
+{
+    for (auto session : m_sessions) {
+        if (session->client().hostingDocument() == &document)
+            session->pauseSession();
+    }
 }
 
+}
+
 #endif

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h (186250 => 186251)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h	2015-07-03 01:43:21 UTC (rev 186250)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h	2015-07-03 01:44:40 UTC (rev 186251)
@@ -36,6 +36,7 @@
 
 namespace WebCore {
 
+class Document;
 class HTMLMediaElement;
 class PlatformMediaSession;
 class RemoteCommandListener;
@@ -56,6 +57,8 @@
     WEBCORE_EXPORT void applicationWillEnterForeground() const;
     WEBCORE_EXPORT void applicationWillEnterBackground() const;
 
+    void stopAllMediaPlaybackForDocument(const Document&);
+
     enum SessionRestrictionFlags {
         NoRestrictions = 0,
         ConcurrentPlaybackNotPermitted = 1 << 0,
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to