<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>145986</bug_id>
          
          <creation_ts>2015-06-15 13:25:12 -0700</creation_ts>
          <short_desc>Media Session: Improve the safety of playback toggling</short_desc>
          <delta_ts>2015-06-15 16:06:48 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Media</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>145411</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Matt Rajca">mrajca</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>achristensen</cc>
    
    <cc>commit-queue</cc>
    
    <cc>conrad_shultz</cc>
    
    <cc>darin</cc>
    
    <cc>eric.carlson</cc>
    
    <cc>jer.noble</cc>
    
    <cc>mrajca</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1102020</commentid>
    <comment_count>0</comment_count>
    <who name="Matt Rajca">mrajca</who>
    <bug_when>2015-06-15 13:25:12 -0700</bug_when>
    <thetext>Per Darin&apos;s feedback in Bug 145978, we should be careful about iterating elements that were deleted underneath us in MediaSession::togglePlayback.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102022</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2015-06-15 13:26:43 -0700</bug_when>
    <thetext>&lt;rdar://problem/21388739&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102024</commentid>
    <comment_count>2</comment_count>
      <attachid>254891</attachid>
    <who name="Matt Rajca">mrajca</who>
    <bug_when>2015-06-15 13:38:40 -0700</bug_when>
    <thetext>Created attachment 254891
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102027</commentid>
    <comment_count>3</comment_count>
      <attachid>254891</attachid>
    <who name="Alex Christensen">achristensen</who>
    <bug_when>2015-06-15 13:42:51 -0700</bug_when>
    <thetext>Comment on attachment 254891
Patch

There&apos;s no need to make a member variable for something that&apos;s only used in MediaSsession::togglePlayback.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102029</commentid>
    <comment_count>4</comment_count>
    <who name="Matt Rajca">mrajca</who>
    <bug_when>2015-06-15 13:50:43 -0700</bug_when>
    <thetext>(In reply to comment #3)
&gt; Comment on attachment 254891 [details]
&gt; Patch
&gt; 
&gt; There&apos;s no need to make a member variable for something that&apos;s only used in
&gt; MediaSsession::togglePlayback.

We will have to remove elements from that set when elements from the underlying m_activeParticipatingElements set are removed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102032</commentid>
    <comment_count>5</comment_count>
    <who name="Alex Christensen">achristensen</who>
    <bug_when>2015-06-15 14:08:14 -0700</bug_when>
    <thetext>It would be much nicer to not use so many raw pointers everywhere.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102059</commentid>
    <comment_count>6</comment_count>
      <attachid>254891</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2015-06-15 15:10:18 -0700</bug_when>
    <thetext>Comment on attachment 254891
Patch

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

&gt; Source/WebCore/Modules/mediasession/MediaSession.cpp:97
&gt; +    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?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102060</commentid>
    <comment_count>7</comment_count>
    <who name="Matt Rajca">mrajca</who>
    <bug_when>2015-06-15 15:14:01 -0700</bug_when>
    <thetext>(In reply to comment #6)
&gt; Comment on attachment 254891 [details]
&gt; Patch
&gt; 
&gt; View in context:
&gt; https://bugs.webkit.org/attachment.cgi?id=254891&amp;action=review
&gt; 
&gt; &gt; Source/WebCore/Modules/mediasession/MediaSession.cpp:97
&gt; &gt; +    ASSERT(!m_iteratedActiveParticipatingElements);
&gt; 
&gt; What guarantees this won’t happen? I’d think that if we make something play
&gt; that some events might fire and in response we might run some code and end
&gt; up back here.
&gt; 
&gt; 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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102061</commentid>
    <comment_count>8</comment_count>
      <attachid>254891</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2015-06-15 15:18:15 -0700</bug_when>
    <thetext>Comment on attachment 254891
Patch

Oops, just noticed this doesn’t add the needed call to remove. Why not?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102065</commentid>
    <comment_count>9</comment_count>
    <who name="Matt Rajca">mrajca</who>
    <bug_when>2015-06-15 15:22:10 -0700</bug_when>
    <thetext>We cur(In reply to comment #8)
&gt; Comment on attachment 254891 [details]
&gt; Patch
&gt; 
&gt; Oops, just noticed this doesn’t add the needed call to remove. Why not?

We currently don&apos;t remove elements from m_activeParticipatingElements (and thus m_iteratedActiveParticipatingElements). That&apos;s part of 
the algorithm for &quot;interrupting a media session from a media element&quot; which I&apos;ll implement in the next couple days.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102069</commentid>
    <comment_count>10</comment_count>
    <who name="Alex Christensen">achristensen</who>
    <bug_when>2015-06-15 15:27:22 -0700</bug_when>
    <thetext>(In reply to comment #9)
&gt; We currently don&apos;t remove elements from m_activeParticipatingElements (and
&gt; thus m_iteratedActiveParticipatingElements). That&apos;s part of 
&gt; the algorithm for &quot;interrupting a media session from a media element&quot; which
&gt; I&apos;ll implement in the next couple days.
This is why I was so confused. This will need to be done, but 185560 doesn&apos;t need it yet.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102074</commentid>
    <comment_count>11</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2015-06-15 15:41:28 -0700</bug_when>
    <thetext>(In reply to comment #9)
&gt; We cur(In reply to comment #8)
&gt; &gt; Comment on attachment 254891 [details]
&gt; &gt; Patch
&gt; &gt; 
&gt; &gt; Oops, just noticed this doesn’t add the needed call to remove. Why not?
&gt; 
&gt; We currently don&apos;t remove elements from m_activeParticipatingElements (and
&gt; thus m_iteratedActiveParticipatingElements). That&apos;s part of 
&gt; the algorithm for &quot;interrupting a media session from a media element&quot; which
&gt; I&apos;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?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102075</commentid>
    <comment_count>12</comment_count>
    <who name="Matt Rajca">mrajca</who>
    <bug_when>2015-06-15 15:48:24 -0700</bug_when>
    <thetext>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&apos;s set of active participating elements). I&apos;ll get to that soon as well.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102080</commentid>
    <comment_count>13</comment_count>
      <attachid>254891</attachid>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2015-06-15 16:06:41 -0700</bug_when>
    <thetext>Comment on attachment 254891
Patch

Clearing flags on attachment: 254891

Committed r185570: &lt;http://trac.webkit.org/changeset/185570&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102081</commentid>
    <comment_count>14</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2015-06-15 16:06:48 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>254891</attachid>
            <date>2015-06-15 13:38:40 -0700</date>
            <delta_ts>2015-06-15 16:06:41 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-145986-20150615133805.patch</filename>
            <type>text/plain</type>
            <size>2805</size>
            <attacher name="Matt Rajca">mrajca</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMTg1NTU1CmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViQ29yZS9D
aGFuZ2VMb2cgYi9Tb3VyY2UvV2ViQ29yZS9DaGFuZ2VMb2cKaW5kZXggZGY1NTU1ZDEzYTU2NWZl
ZWQxZjdmZmY0ZWU0OTBiZDg3ZDJlMzU0OC4uMGUxZDE1ZjFhMWE4NmRkZDRhZmM3ZWI0NDc2Njcy
ZGYwMWFlYzViZiAxMDA2NDQKLS0tIGEvU291cmNlL1dlYkNvcmUvQ2hhbmdlTG9nCisrKyBiL1Nv
dXJjZS9XZWJDb3JlL0NoYW5nZUxvZwpAQCAtMSw1ICsxLDE4IEBACiAyMDE1LTA2LTE1ICBNYXR0
IFJhamNhICA8bXJhamNhQGFwcGxlLmNvbT4KIAorICAgICAgICBNZWRpYSBTZXNzaW9uOiBJbXBy
b3ZlIHRoZSBzYWZldHkgb2YgcGxheWJhY2sgdG9nZ2xpbmcKKyAgICAgICAgaHR0cHM6Ly9idWdz
LndlYmtpdC5vcmcvc2hvd19idWcuY2dpP2lkPTE0NTk4NgorCisgICAgICAgIFJldmlld2VkIGJ5
IE5PQk9EWSAoT09QUyEpLgorCisgICAgICAgICogTW9kdWxlcy9tZWRpYXNlc3Npb24vTWVkaWFT
ZXNzaW9uLmNwcDoKKyAgICAgICAgKFdlYkNvcmU6Ok1lZGlhU2Vzc2lvbjo6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