Bug 145986

Summary: Media Session: Improve the safety of playback toggling
Product: WebKit Reporter: Matt Rajca <mrajca>
Component: MediaAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, commit-queue, conrad_shultz, darin, eric.carlson, jer.noble, mrajca, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Bug Depends on:    
Bug Blocks: 145411    
Attachments:
Description Flags
Patch none

Description Matt Rajca 2015-06-15 13:25:12 PDT
Per Darin's feedback in Bug 145978, we should be careful about iterating elements that were deleted underneath us in MediaSession::togglePlayback.
Comment 1 Radar WebKit Bug Importer 2015-06-15 13:26:43 PDT
<rdar://problem/21388739>
Comment 2 Matt Rajca 2015-06-15 13:38:40 PDT
Created attachment 254891 [details]
Patch
Comment 3 Alex Christensen 2015-06-15 13:42:51 PDT
Comment on attachment 254891 [details]
Patch

There's no need to make a member variable for something that's only used in MediaSsession::togglePlayback.
Comment 4 Matt Rajca 2015-06-15 13:50:43 PDT
(In reply to comment #3)
> Comment on attachment 254891 [details]
> Patch
> 
> There's no need to make a member variable for something that's only used in
> MediaSsession::togglePlayback.

We will have to remove elements from that set when elements from the underlying m_activeParticipatingElements set are removed.
Comment 5 Alex Christensen 2015-06-15 14:08:14 PDT
It would be much nicer to not use so many raw pointers everywhere.
Comment 6 Darin Adler 2015-06-15 15:10:18 PDT
Comment on attachment 254891 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=254891&action=review

> Source/WebCore/Modules/mediasession/MediaSession.cpp:97
> +    ASSERT(!m_iteratedActiveParticipatingElements);

What guarantees this won’t happen? I’d think that if we make something play that some events might fire and in response we might run some code and end up back here.

Maybe we need to handle this case, perhaps by doing nothing?
Comment 7 Matt Rajca 2015-06-15 15:14:01 PDT
(In reply to comment #6)
> Comment on attachment 254891 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=254891&action=review
> 
> > Source/WebCore/Modules/mediasession/MediaSession.cpp:97
> > +    ASSERT(!m_iteratedActiveParticipatingElements);
> 
> What guarantees this won’t happen? I’d think that if we make something play
> that some events might fire and in response we might run some code and end
> up back here.
> 
> Maybe we need to handle this case, perhaps by doing nothing?

This assertion is in the MediaSession::togglePlayback method which is currently only called in response to play/pause media keys. This method will never call itself.
Comment 8 Darin Adler 2015-06-15 15:18:15 PDT
Comment on attachment 254891 [details]
Patch

Oops, just noticed this doesn’t add the needed call to remove. Why not?
Comment 9 Matt Rajca 2015-06-15 15:22:10 PDT
We cur(In reply to comment #8)
> Comment on attachment 254891 [details]
> Patch
> 
> Oops, just noticed this doesn’t add the needed call to remove. Why not?

We currently don't remove elements from m_activeParticipatingElements (and thus m_iteratedActiveParticipatingElements). That's part of 
the algorithm for "interrupting a media session from a media element" which I'll implement in the next couple days.
Comment 10 Alex Christensen 2015-06-15 15:27:22 PDT
(In reply to comment #9)
> We currently don't remove elements from m_activeParticipatingElements (and
> thus m_iteratedActiveParticipatingElements). That's part of 
> the algorithm for "interrupting a media session from a media element" which
> I'll implement in the next couple days.
This is why I was so confused. This will need to be done, but 185560 doesn't need it yet.
Comment 11 Darin Adler 2015-06-15 15:41:28 PDT
(In reply to comment #9)
> We cur(In reply to comment #8)
> > Comment on attachment 254891 [details]
> > Patch
> > 
> > Oops, just noticed this doesn’t add the needed call to remove. Why not?
> 
> We currently don't remove elements from m_activeParticipatingElements (and
> thus m_iteratedActiveParticipatingElements). That's part of 
> the algorithm for "interrupting a media session from a media element" which
> I'll implement in the next couple days.

Before that algorithm comes into play: What guarantees that m_activeParticipatingElements doesn’t point to deleted objects when media elements go away?
Comment 12 Matt Rajca 2015-06-15 15:48:24 PDT
Good catch. Section 6.5 of the Media Session spec describes what should happen when an element is removed from the document (which includes removing it from the media session's set of active participating elements). I'll get to that soon as well.
Comment 13 WebKit Commit Bot 2015-06-15 16:06:41 PDT
Comment on attachment 254891 [details]
Patch

Clearing flags on attachment: 254891

Committed r185570: <http://trac.webkit.org/changeset/185570>
Comment 14 WebKit Commit Bot 2015-06-15 16:06:48 PDT
All reviewed patches have been landed.  Closing bug.