Title: [185570] trunk/Source/WebCore
Revision
185570
Author
[email protected]
Date
2015-06-15 16:06:01 -0700 (Mon, 15 Jun 2015)

Log Message

Media Session: Improve the safety of playback toggling
https://bugs.webkit.org/show_bug.cgi?id=145986

Patch by Matt Rajca <[email protected]> on 2015-06-15
Reviewed by Darin Adler.

* Modules/mediasession/MediaSession.cpp:
(WebCore::MediaSession::togglePlayback): Improved the safety of the loop so that we don't re-visit elements that
  may have been deleted underneath us.
* Modules/mediasession/MediaSession.h: Added a pointer to the set of iterated active participating elements so
  we can remove any elements that are deleted from the underlying "real" set.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (185569 => 185570)


--- trunk/Source/WebCore/ChangeLog	2015-06-15 22:48:32 UTC (rev 185569)
+++ trunk/Source/WebCore/ChangeLog	2015-06-15 23:06:01 UTC (rev 185570)
@@ -1,3 +1,16 @@
+2015-06-15  Matt Rajca  <[email protected]>
+
+        Media Session: Improve the safety of playback toggling
+        https://bugs.webkit.org/show_bug.cgi?id=145986
+
+        Reviewed by Darin Adler.
+
+        * Modules/mediasession/MediaSession.cpp:
+        (WebCore::MediaSession::togglePlayback): Improved the safety of the loop so that we don't re-visit elements that
+          may have been deleted underneath us.
+        * Modules/mediasession/MediaSession.h: Added a pointer to the set of iterated active participating elements so
+          we can remove any elements that are deleted from the underlying "real" set.
+
 2015-06-15  Brent Fulgham  <[email protected]>
 
         REGRESSION(r175251, Mavericks Only): Playback may stall

Modified: trunk/Source/WebCore/Modules/mediasession/MediaSession.cpp (185569 => 185570)


--- trunk/Source/WebCore/Modules/mediasession/MediaSession.cpp	2015-06-15 22:48:32 UTC (rev 185569)
+++ trunk/Source/WebCore/Modules/mediasession/MediaSession.cpp	2015-06-15 23:06:01 UTC (rev 185570)
@@ -94,14 +94,21 @@
 
 void MediaSession::togglePlayback()
 {
+    ASSERT(!m_iteratedActiveParticipatingElements);
+
     HashSet<HTMLMediaElement*> activeParticipatingElementsCopy = m_activeParticipatingElements;
+    m_iteratedActiveParticipatingElements = &activeParticipatingElementsCopy;
 
-    for (auto* element : activeParticipatingElementsCopy) {
+    while (!activeParticipatingElementsCopy.isEmpty()) {
+        HTMLMediaElement* element = activeParticipatingElementsCopy.takeAny();
+
         if (element->paused())
             element->play();
         else
             element->pause();
     }
+
+    m_iteratedActiveParticipatingElements = nullptr;
 }
 
 }

Modified: trunk/Source/WebCore/Modules/mediasession/MediaSession.h (185569 => 185570)


--- trunk/Source/WebCore/Modules/mediasession/MediaSession.h	2015-06-15 22:48:32 UTC (rev 185569)
+++ trunk/Source/WebCore/Modules/mediasession/MediaSession.h	2015-06-15 23:06:01 UTC (rev 185570)
@@ -73,6 +73,7 @@
     State m_currentState { State::Idle };
     Vector<HTMLMediaElement*> m_participatingElements;
     HashSet<HTMLMediaElement*> m_activeParticipatingElements;
+    HashSet<HTMLMediaElement*>* m_iteratedActiveParticipatingElements { nullptr };
 
     const String m_kind;
     RefPtr<MediaRemoteControls> m_controls;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to