<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Record whether a media element was prevented from playing without user interaction"
   href="https://bugs.webkit.org/show_bug.cgi?id=167214#c4">Comment # 4</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Record whether a media element was prevented from playing without user interaction"
   href="https://bugs.webkit.org/show_bug.cgi?id=167214">bug 167214</a>
              from <span class="vcard"><a class="email" href="mailto:mrajca&#64;apple.com" title="Matt Rajca &lt;mrajca&#64;apple.com&gt;"> <span class="fn">Matt Rajca</span></a>
</span></b>
        <pre>(In reply to <a href="show_bug.cgi?id=167214#c3">comment #3</a>)
<span class="quote">&gt; Comment on <span class=""><a href="attachment.cgi?id=299269&amp;action=diff" name="attach_299269" title="Patch">attachment 299269</a> <a href="attachment.cgi?id=299269&amp;action=edit" title="Patch">[details]</a></span>
&gt; Patch
&gt; 
&gt; View in context:
&gt; <a href="https://bugs.webkit.org/attachment.cgi?id=299269&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=299269&amp;action=review</a>
&gt; 
&gt; &gt; Source/WebCore/html/HTMLMediaElement.cpp:3106
&gt; &gt; +    bool preventedPlaybackWithoutUserGesture = false;
&gt; &gt; +    if (!m_mediaSession-&gt;playbackPermitted(*this, &amp;preventedPlaybackWithoutUserGesture)) {
&gt; &gt; +        if (preventedPlaybackWithoutUserGesture)
&gt; &gt; +            m_preventedFromPlayingWithoutUserGesture = true;
&gt; &gt;          return;
&gt; &gt; +    }
&gt; 
&gt; When is m_preventedFromPlayingWithoutUserGesture ever reset to false?</span >

It will get reset when the user starts playing media again with a user gesture. There's currently a FIXME in that code path but I'll make it part of this patch.

<span class="quote">&gt; 
&gt; &gt; Source/WebCore/html/HTMLMediaElement.h:719
&gt; &gt; -    bool canTransitionFromAutoplayToPlay() const;
&gt; &gt; +    bool canTransitionFromAutoplayToPlay(bool* preventedPlaybackWithoutUserGesture) const;
&gt; 
&gt; This and ...
&gt; 
&gt; &gt; Source/WebCore/html/MediaElementSession.h:55
&gt; &gt; -    bool playbackPermitted(const HTMLMediaElement&amp;) const;
&gt; &gt; +    bool playbackPermitted(const HTMLMediaElement&amp;, bool* preventedPlaybackWithoutUserGesture) const;
&gt; 
&gt; This.
&gt; 
&gt; I don't like this &quot;out boolean pointer parameter&quot; change.  We should some
&gt; other way of representing failure, on the order of &quot;ExceptionOr&lt;&gt;&quot;.  For
&gt; example, something like:
&gt; 
&gt; enum class PlaybackDenialReason {
&gt;     UserGestureRequired,
&gt;     PageConsentRequired,
&gt;     FullscreenRequired,
&gt; };
&gt; template &lt;typename T&gt;
&gt; class SuccessOr : public optional&lt;T&gt; {
&gt; public:
&gt;     explicit constexpr operator bool() const { return !optional::operator
&gt; bool(); }
&gt; };
&gt; 
&gt; And have these methods return SuccessOr&lt;PlaybackDenialReason&gt;.  I.e.:
&gt; 
&gt;     SuccessOr&lt;PlaybackDenialReason&gt; playbackPermitted(const
&gt; HTMLMediaElement&amp;) const;
&gt; 
&gt; So the call sites can remain exactly the same:
&gt; 
&gt;     if (!playbackPermitted(m_element)) { ... }
&gt; 
&gt; And in the places we care about why playback was denied, we can look at the
&gt; return value:
&gt; 
&gt;     auto success =
&gt; canTransitionFromAutoplayToPlay(&amp;preventedPlaybackWithoutUserGesture));
&gt;     if (success) { ... } else {
&gt;         m_preventedFromPlayingWithoutUserGesture = success.value() ==
&gt; PlaybackDenialReason:: UserGestureRequired;
&gt;     }</span >

Thanks for the suggestion - that would make the call sites cleaner. Working on a v2 of the patch now.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>