<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[199022] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/199022">199022</a></dd>
<dt>Author</dt> <dd>bdakin@apple.com</dd>
<dt>Date</dt> <dd>2016-04-04 14:18:57 -0700 (Mon, 04 Apr 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add some logic to decide when a video can control the videoControlsManager
https://bugs.webkit.org/show_bug.cgi?id=156089
-and corresponding-
rdar://problem/23833752

Reviewed by Eric Carlson and Tim Horton.

Source/WebCore:

With this patch, a video can take over the videoControlsManager if all of 
these conditions are met:
-Playback is permitted
-The video has a renderer
-The video is 400x300 or larger
AND
-The video has both audio and video

If those criteria are not met the video will still be allowed to take over 
the videoControlsManager if:
-Playback is permitted
-The video has a renderer
-The video started playing because of a user gesture.

If multiple videos meet this criteria, then the video that most recently 
started playing will take over the videoControlsManager.

We might consider more restrictions in the future, but this seems like a good 
place to start.

Move all decisions about the videoControlsManager to updatePlayState() 
instead of playInternal().
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::playInternal):

If the video will play after updatePlayState, then invoke 
setUpVideoControlsManager() if canControlControlsManager() is true. If the 
video will not be playing after updatePlayState, then check to see if 
endedPlayback() is true. If it is, then invoke clearVideoControlsManager().
(WebCore::HTMLMediaElement::updatePlayState):

The logic for the heuristic is here:
* html/MediaElementSession.cpp:
(WebCore::MediaElementSession::canControlControlsManager):
* html/MediaElementSession.h:

New ChromeClient function clearVideoControlsManager().
* page/ChromeClient.h:

Source/WebKit2:

The biggest change in WebKit2 is to push all of the logic for the 
videoControlsManager into WebCore. With this change, WebCore will invoke 
setUpVideoControlsManager() when there is a video to control the manager, and 
it will call clearVideoControlsManager() when there is not.

Add clearVideoControlsManager().
* UIProcess/Cocoa/WebVideoFullscreenManagerProxy.h:
* UIProcess/Cocoa/WebVideoFullscreenManagerProxy.messages.in:
* UIProcess/Cocoa/WebVideoFullscreenManagerProxy.mm:
(WebKit::WebVideoFullscreenManagerProxy::clearVideoControlsManager):

Re-name isPlayingMediaDidChange() to videoControlsManagerDidChange(). This 
ties the logic to the lifetime of the videoControlsManager instead of 
figuring it out in the UIProcess based on the media state.
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::videoControlsManagerDidChange):
(WebKit::WebViewImpl::isPlayingMediaDidChange): Deleted.
* UIProcess/PageClient.h:

Also change isPlayingVideoWithAudio() into hasActiveVideoForControlsManager() 
Again, this ties the logic to the lifetime of the videoControlsManager 
instead of figuring it out in the UIProcess based on the media state.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::isPlayingMediaDidChange):
(WebKit::WebPageProxy::videoControlsManagerDidChange):
(WebKit::WebPageProxy::hasActiveVideoForControlsManager):
(WebKit::WebPageProxy::isPlayingVideoWithAudio): Deleted.
* UIProcess/WebPageProxy.h:
* UIProcess/mac/PageClientImpl.h:
* UIProcess/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::videoControlsManagerDidChange):
(WebKit::PageClientImpl::isPlayingMediaDidChange): Deleted.

New WebChromeClient function clearVideoControlsManager().
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::clearVideoControlsManager):
* WebProcess/WebCoreSupport/WebChromeClient.h:

Do the work to clear the videoControlsManager.
* WebProcess/cocoa/WebVideoFullscreenManager.h:
* WebProcess/cocoa/WebVideoFullscreenManager.mm:
(WebKit::WebVideoFullscreenManager::clearVideoControlsManager):
(WebKit::WebVideoFullscreenManager::exitVideoFullscreenToModeWithoutAnimation):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLMediaElementcpp">trunk/Source/WebCore/html/HTMLMediaElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlMediaElementSessioncpp">trunk/Source/WebCore/html/MediaElementSession.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlMediaElementSessionh">trunk/Source/WebCore/html/MediaElementSession.h</a></li>
<li><a href="#trunkSourceWebCorepageChromeClienth">trunk/Source/WebCore/page/ChromeClient.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessCocoaWebVideoFullscreenManagerProxyh">trunk/Source/WebKit2/UIProcess/Cocoa/WebVideoFullscreenManagerProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessCocoaWebVideoFullscreenManagerProxymessagesin">trunk/Source/WebKit2/UIProcess/Cocoa/WebVideoFullscreenManagerProxy.messages.in</a></li>
<li><a href="#trunkSourceWebKit2UIProcessCocoaWebVideoFullscreenManagerProxymm">trunk/Source/WebKit2/UIProcess/Cocoa/WebVideoFullscreenManagerProxy.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessCocoaWebViewImplh">trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessCocoaWebViewImplmm">trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessPageClienth">trunk/Source/WebKit2/UIProcess/PageClient.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxycpp">trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxyh">trunk/Source/WebKit2/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacPageClientImplh">trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacPageClientImplmm">trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebChromeClientcpp">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebChromeClienth">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcesscocoaWebVideoFullscreenManagerh">trunk/Source/WebKit2/WebProcess/cocoa/WebVideoFullscreenManager.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcesscocoaWebVideoFullscreenManagermm">trunk/Source/WebKit2/WebProcess/cocoa/WebVideoFullscreenManager.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebCore/ChangeLog        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -1,3 +1,51 @@
</span><ins>+2016-04-04  Beth Dakin  &lt;bdakin@apple.com&gt;
+
+        Add some logic to decide when a video can control the videoControlsManager
+        https://bugs.webkit.org/show_bug.cgi?id=156089
+        -and corresponding-
+        rdar://problem/23833752
+
+        Reviewed by Eric Carlson and Tim Horton.
+
+        With this patch, a video can take over the videoControlsManager if all of 
+        these conditions are met:
+        -Playback is permitted
+        -The video has a renderer
+        -The video is 400x300 or larger
+        AND
+        -The video has both audio and video
+
+        If those criteria are not met the video will still be allowed to take over 
+        the videoControlsManager if:
+        -Playback is permitted
+        -The video has a renderer
+        -The video started playing because of a user gesture.
+
+        If multiple videos meet this criteria, then the video that most recently 
+        started playing will take over the videoControlsManager.
+
+        We might consider more restrictions in the future, but this seems like a good 
+        place to start.
+
+        Move all decisions about the videoControlsManager to updatePlayState() 
+        instead of playInternal().
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::playInternal):
+
+        If the video will play after updatePlayState, then invoke 
+        setUpVideoControlsManager() if canControlControlsManager() is true. If the 
+        video will not be playing after updatePlayState, then check to see if 
+        endedPlayback() is true. If it is, then invoke clearVideoControlsManager().
+        (WebCore::HTMLMediaElement::updatePlayState):
+
+        The logic for the heuristic is here:
+        * html/MediaElementSession.cpp:
+        (WebCore::MediaElementSession::canControlControlsManager):
+        * html/MediaElementSession.h:
+
+        New ChromeClient function clearVideoControlsManager().
+        * page/ChromeClient.h:
+
</ins><span class="cx"> 2016-04-03  Sam Weinig  &lt;sam@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Add SPI to allow install script message handlers in isolated worlds
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.cpp        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -2992,14 +2992,6 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    // FIXME: rdar://problem/23833752 We need to be more strategic about when we set up the video controls manager.
-    // It's really something that should be handled by the PlatformMediaSessionManager since we only want a controls
-    // manager for the currentSession.
-    if (document().page() &amp;&amp; is&lt;HTMLVideoElement&gt;(*this)) {
-        HTMLVideoElement&amp; asVideo = downcast&lt;HTMLVideoElement&gt;(*this);
-        document().page()-&gt;chrome().client().setUpVideoControlsManager(asVideo);
-    }
-
</del><span class="cx">     // 4.8.10.9. Playing the media resource
</span><span class="cx">     if (!m_player || m_networkState == NETWORK_EMPTY)
</span><span class="cx">         scheduleDelayedAction(LoadMediaResource);
</span><span class="lines">@@ -4816,6 +4808,11 @@
</span><span class="cx">     LOG(Media, &quot;HTMLMediaElement::updatePlayState(%p) - shouldBePlaying = %s, playerPaused = %s&quot;, this, boolString(shouldBePlaying), boolString(playerPaused));
</span><span class="cx"> 
</span><span class="cx">     if (shouldBePlaying) {
</span><ins>+        if (document().page() &amp;&amp; m_mediaSession-&gt;canControlControlsManager(*this)) {
+            HTMLVideoElement&amp; asVideo = downcast&lt;HTMLVideoElement&gt;(*this);
+            document().page()-&gt;chrome().client().setUpVideoControlsManager(asVideo);
+        }
+
</ins><span class="cx">         setDisplayMode(Video);
</span><span class="cx">         invalidateCachedTime();
</span><span class="cx"> 
</span><span class="lines">@@ -4848,6 +4845,9 @@
</span><span class="cx">         startPlaybackProgressTimer();
</span><span class="cx">         setPlaying(true);
</span><span class="cx">     } else {
</span><ins>+        if (endedPlayback() &amp;&amp; document().page() &amp;&amp; is&lt;HTMLVideoElement&gt;(*this))
+            document().page()-&gt;chrome().client().clearVideoControlsManager();
+
</ins><span class="cx">         if (!playerPaused)
</span><span class="cx">             m_player-&gt;pause();
</span><span class="cx">         refreshCachedTime();
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlMediaElementSessioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/MediaElementSession.cpp (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/MediaElementSession.cpp        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebCore/html/MediaElementSession.cpp        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -213,6 +213,31 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool MediaElementSession::canControlControlsManager(const HTMLMediaElement&amp; element) const
+{
+    // FIXME: rdar://problem/25537071 Audio elements should be able to have a controls manager as well.
+    // Audio elements should probably only have a controls manager if they started playing via a user gesture.
+    if (!element.isVideo())
+        return false;
+
+    if (!playbackPermitted(element))
+        return false;
+
+    RenderBox* renderer = downcast&lt;RenderBox&gt;(element.renderer());
+    if (!renderer)
+        return false;
+
+    if (renderer-&gt;clientWidth() &gt;= elementMainContentMinimumWidth &amp;&amp; renderer-&gt;clientHeight() &gt;= elementMainContentMinimumHeight) {
+        if (element.hasAudio() &amp;&amp; element.hasVideo())
+            return true;
+    }
+
+    if (ScriptController::processingUserGestureForMedia())
+        return true;
+
+    return false;
+}
+
</ins><span class="cx"> #if ENABLE(WIRELESS_PLAYBACK_TARGET)
</span><span class="cx"> void MediaElementSession::showPlaybackTargetPicker(const HTMLMediaElement&amp; element)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlMediaElementSessionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/MediaElementSession.h (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/MediaElementSession.h        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebCore/html/MediaElementSession.h        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -53,6 +53,8 @@
</span><span class="cx">     bool pageAllowsDataLoading(const HTMLMediaElement&amp;) const;
</span><span class="cx">     bool pageAllowsPlaybackAfterResuming(const HTMLMediaElement&amp;) const;
</span><span class="cx"> 
</span><ins>+    bool canControlControlsManager(const HTMLMediaElement&amp;) const;
+
</ins><span class="cx"> #if ENABLE(WIRELESS_PLAYBACK_TARGET)
</span><span class="cx">     void showPlaybackTargetPicker(const HTMLMediaElement&amp;);
</span><span class="cx">     bool hasWirelessPlaybackTargets(const HTMLMediaElement&amp;) const;
</span></span></pre></div>
<a id="trunkSourceWebCorepageChromeClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/ChromeClient.h (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/ChromeClient.h        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebCore/page/ChromeClient.h        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -342,6 +342,7 @@
</span><span class="cx"> #if ENABLE(VIDEO)
</span><span class="cx">     virtual void enterVideoFullscreenForVideoElement(HTMLVideoElement&amp;, HTMLMediaElementEnums::VideoFullscreenMode) { }
</span><span class="cx">     virtual void setUpVideoControlsManager(HTMLVideoElement&amp;) { }
</span><ins>+    virtual void clearVideoControlsManager() { }
</ins><span class="cx"> #endif
</span><span class="cx">     virtual void exitVideoFullscreenForVideoElement(WebCore::HTMLVideoElement&amp;) { }
</span><span class="cx">     virtual void exitVideoFullscreenToModeWithoutAnimation(WebCore::HTMLVideoElement&amp;, HTMLMediaElementEnums::VideoFullscreenMode /*targetMode*/) { }
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebKit2/ChangeLog        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -1,3 +1,57 @@
</span><ins>+2016-04-04  Beth Dakin  &lt;bdakin@apple.com&gt;
+
+        Add some logic to decide when a video can control the videoControlsManager
+        https://bugs.webkit.org/show_bug.cgi?id=156089
+        -and corresponding-
+        rdar://problem/23833752
+
+        Reviewed by Eric Carlson and Tim Horton.
+
+        The biggest change in WebKit2 is to push all of the logic for the 
+        videoControlsManager into WebCore. With this change, WebCore will invoke 
+        setUpVideoControlsManager() when there is a video to control the manager, and 
+        it will call clearVideoControlsManager() when there is not.
+
+        Add clearVideoControlsManager().
+        * UIProcess/Cocoa/WebVideoFullscreenManagerProxy.h:
+        * UIProcess/Cocoa/WebVideoFullscreenManagerProxy.messages.in:
+        * UIProcess/Cocoa/WebVideoFullscreenManagerProxy.mm:
+        (WebKit::WebVideoFullscreenManagerProxy::clearVideoControlsManager):
+
+        Re-name isPlayingMediaDidChange() to videoControlsManagerDidChange(). This 
+        ties the logic to the lifetime of the videoControlsManager instead of 
+        figuring it out in the UIProcess based on the media state.
+        * UIProcess/Cocoa/WebViewImpl.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::videoControlsManagerDidChange):
+        (WebKit::WebViewImpl::isPlayingMediaDidChange): Deleted.
+        * UIProcess/PageClient.h:
+
+        Also change isPlayingVideoWithAudio() into hasActiveVideoForControlsManager() 
+        Again, this ties the logic to the lifetime of the videoControlsManager 
+        instead of figuring it out in the UIProcess based on the media state.
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::isPlayingMediaDidChange):
+        (WebKit::WebPageProxy::videoControlsManagerDidChange):
+        (WebKit::WebPageProxy::hasActiveVideoForControlsManager):
+        (WebKit::WebPageProxy::isPlayingVideoWithAudio): Deleted.
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/mac/PageClientImpl.h:
+        * UIProcess/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::videoControlsManagerDidChange):
+        (WebKit::PageClientImpl::isPlayingMediaDidChange): Deleted.
+
+        New WebChromeClient function clearVideoControlsManager().
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::clearVideoControlsManager):
+        * WebProcess/WebCoreSupport/WebChromeClient.h:
+
+        Do the work to clear the videoControlsManager.
+        * WebProcess/cocoa/WebVideoFullscreenManager.h:
+        * WebProcess/cocoa/WebVideoFullscreenManager.mm:
+        (WebKit::WebVideoFullscreenManager::clearVideoControlsManager):
+        (WebKit::WebVideoFullscreenManager::exitVideoFullscreenToModeWithoutAnimation):
+
</ins><span class="cx"> 2016-04-04  Brent Fulgham  &lt;bfulgham@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         REGRESSION(r198955): com.apple.WebKit.Networking.Development crashed in WebKit::NetworkLoad::setPendingDownloadID + 11
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCocoaWebVideoFullscreenManagerProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebVideoFullscreenManagerProxy.h (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Cocoa/WebVideoFullscreenManagerProxy.h        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebVideoFullscreenManagerProxy.h        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -138,6 +138,7 @@
</span><span class="cx">     // Messages from WebVideoFullscreenManager
</span><span class="cx">     void setupFullscreenWithID(uint64_t contextId, uint32_t videoLayerID, const WebCore::IntRect&amp; initialRect, float hostingScaleFactor, WebCore::HTMLMediaElementEnums::VideoFullscreenMode, bool allowsPictureInPicture);
</span><span class="cx">     void setUpVideoControlsManagerWithID(uint64_t contextId);
</span><ins>+    void clearVideoControlsManager();
</ins><span class="cx">     void resetMediaState(uint64_t contextId);
</span><span class="cx">     void setCurrentTime(uint64_t contextId, double currentTime, double hostTime);
</span><span class="cx">     void setBufferedTime(uint64_t contextId, double bufferedTime);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCocoaWebVideoFullscreenManagerProxymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebVideoFullscreenManagerProxy.messages.in (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Cocoa/WebVideoFullscreenManagerProxy.messages.in        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebVideoFullscreenManagerProxy.messages.in        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -40,6 +40,7 @@
</span><span class="cx">     CleanupFullscreen(uint64_t contextId)
</span><span class="cx">     PreparedToReturnToInline(uint64_t contextId, bool visible, WebCore::IntRect inlineRect)
</span><span class="cx">     SetUpVideoControlsManagerWithID(uint64_t contextId)
</span><ins>+    ClearVideoControlsManager()
</ins><span class="cx"> #if PLATFORM(MAC) &amp;&amp; ENABLE(VIDEO_PRESENTATION_MODE)
</span><span class="cx">     ExitFullscreenWithoutAnimationToMode(uint64_t contextId, WebCore::HTMLMediaElementEnums::VideoFullscreenMode videoFullscreenMode)
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCocoaWebVideoFullscreenManagerProxymm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebVideoFullscreenManagerProxy.mm (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Cocoa/WebVideoFullscreenManagerProxy.mm        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebVideoFullscreenManagerProxy.mm        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -412,11 +412,25 @@
</span><span class="cx">     m_controlsManagerContextId = contextId;
</span><span class="cx">     ensureInterface(m_controlsManagerContextId).ensureControlsManager();
</span><span class="cx">     addClientForContext(m_controlsManagerContextId);
</span><ins>+
+    m_page-&gt;videoControlsManagerDidChange();
</ins><span class="cx"> #else
</span><span class="cx">     UNUSED_PARAM(contextId);
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebVideoFullscreenManagerProxy::clearVideoControlsManager()
+{
+#if PLATFORM(MAC)
+    if (!m_controlsManagerContextId)
+        return;
+
+    removeClientForContext(m_controlsManagerContextId);
+    m_controlsManagerContextId = 0;
+    m_page-&gt;videoControlsManagerDidChange();
+#endif
+}
+
</ins><span class="cx"> void WebVideoFullscreenManagerProxy::resetMediaState(uint64_t contextId)
</span><span class="cx"> {
</span><span class="cx">     ensureInterface(contextId).resetMediaState();
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCocoaWebViewImplh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -324,7 +324,7 @@
</span><span class="cx">     void completeImmediateActionAnimation();
</span><span class="cx">     void didChangeContentSize(CGSize);
</span><span class="cx">     void didHandleAcceptedCandidate();
</span><del>-    void isPlayingMediaDidChange();
</del><ins>+    void videoControlsManagerDidChange();
</ins><span class="cx"> 
</span><span class="cx">     void setIgnoresNonWheelEvents(bool);
</span><span class="cx">     bool ignoresNonWheelEvents() const { return m_ignoresNonWheelEvents; }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCocoaWebViewImplmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -2389,7 +2389,7 @@
</span><span class="cx">     m_isHandlingAcceptedCandidate = false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebViewImpl::isPlayingMediaDidChange()
</del><ins>+void WebViewImpl::videoControlsManagerDidChange()
</ins><span class="cx"> {
</span><span class="cx"> #if __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 101200
</span><span class="cx">     updateWebViewImplAdditions();
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessPageClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/PageClient.h (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/PageClient.h        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebKit2/UIProcess/PageClient.h        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -346,7 +346,7 @@
</span><span class="cx"> 
</span><span class="cx">     virtual void didHandleAcceptedCandidate() = 0;
</span><span class="cx"> 
</span><del>-    virtual void isPlayingMediaDidChange() = 0;
</del><ins>+    virtual void videoControlsManagerDidChange() = 0;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(WIRELESS_PLAYBACK_TARGET) &amp;&amp; !PLATFORM(IOS)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -6025,21 +6025,27 @@
</span><span class="cx">     MediaProducer::MediaStateFlags oldState = m_mediaState;
</span><span class="cx">     m_mediaState = state;
</span><span class="cx"> 
</span><del>-#if PLATFORM(MAC)
-    if ((oldState &amp; playingMediaMask) != (m_mediaState &amp; playingMediaMask))
-        m_pageClient.isPlayingMediaDidChange();
-#endif
-
</del><span class="cx">     playingMediaMask |= MediaProducer::HasActiveMediaCaptureDevice;
</span><span class="cx">     if ((oldState &amp; playingMediaMask) != (m_mediaState &amp; playingMediaMask))
</span><span class="cx">         m_uiClient-&gt;isPlayingAudioDidChange(*this);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool WebPageProxy::isPlayingVideoWithAudio() const
</del><ins>+#if PLATFORM(MAC)
+void WebPageProxy::videoControlsManagerDidChange()
</ins><span class="cx"> {
</span><del>-    return m_mediaState &amp; MediaProducer::IsPlayingAudio &amp;&amp; m_mediaState &amp; MediaProducer::IsPlayingVideo;
</del><ins>+    m_pageClient.videoControlsManagerDidChange();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool WebPageProxy::hasActiveVideoForControlsManager() const
+{
+#if ENABLE(VIDEO_PRESENTATION_MODE)
+    return m_videoFullscreenManager &amp;&amp; m_videoFullscreenManager-&gt;controlsManagerInterface() &amp;&amp; m_mediaState &amp; MediaProducer::HasAudioOrVideo;
+#else
+    return false;
+#endif
+}
+#endif
+
</ins><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span><span class="cx"> void WebPageProxy::hasMediaSessionWithActiveMediaElementsDidChange(bool state)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -1020,7 +1020,10 @@
</span><span class="cx">     void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags, uint64_t);
</span><span class="cx">     WebCore::MediaProducer::MediaStateFlags mediaStateFlags() const { return m_mediaState; }
</span><span class="cx"> 
</span><del>-    bool isPlayingVideoWithAudio() const;
</del><ins>+#if PLATFORM(MAC)
+    void videoControlsManagerDidChange();
+    bool hasActiveVideoForControlsManager() const;
+#endif
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span><span class="cx">     void hasMediaSessionWithActiveMediaElementsDidChange(bool);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacPageClientImplh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -211,7 +211,7 @@
</span><span class="cx"> 
</span><span class="cx">     void didHandleAcceptedCandidate() override;
</span><span class="cx"> 
</span><del>-    void isPlayingMediaDidChange() override;
</del><ins>+    void videoControlsManagerDidChange() override;
</ins><span class="cx"> 
</span><span class="cx">     void showPlatformContextMenu(NSMenu *, WebCore::IntPoint) override;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacPageClientImplmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -779,9 +779,9 @@
</span><span class="cx">     m_impl-&gt;didHandleAcceptedCandidate();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void PageClientImpl::isPlayingMediaDidChange()
</del><ins>+void PageClientImpl::videoControlsManagerDidChange()
</ins><span class="cx"> {
</span><del>-    m_impl-&gt;isPlayingMediaDidChange();
</del><ins>+    m_impl-&gt;videoControlsManagerDidChange();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void PageClientImpl::showPlatformContextMenu(NSMenu *menu, IntPoint location)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebChromeClientcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -861,6 +861,11 @@
</span><span class="cx">     m_page-&gt;videoFullscreenManager()-&gt;setUpVideoControlsManager(videoElement);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebChromeClient::clearVideoControlsManager()
+{
+    m_page-&gt;videoFullscreenManager()-&gt;clearVideoControlsManager();
+}
+
</ins><span class="cx"> void WebChromeClient::enterVideoFullscreenForVideoElement(WebCore::HTMLVideoElement&amp; videoElement, WebCore::HTMLMediaElementEnums::VideoFullscreenMode mode)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(mode != HTMLMediaElementEnums::VideoFullscreenModeNone);
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebChromeClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -245,6 +245,7 @@
</span><span class="cx"> #if PLATFORM(IOS) || (PLATFORM(MAC) &amp;&amp; ENABLE(VIDEO_PRESENTATION_MODE))
</span><span class="cx">     bool supportsVideoFullscreen(WebCore::HTMLMediaElementEnums::VideoFullscreenMode) override;
</span><span class="cx">     void setUpVideoControlsManager(WebCore::HTMLVideoElement&amp;) override;
</span><ins>+    void clearVideoControlsManager() override;
</ins><span class="cx">     void enterVideoFullscreenForVideoElement(WebCore::HTMLVideoElement&amp;, WebCore::HTMLMediaElementEnums::VideoFullscreenMode) override;
</span><span class="cx">     void exitVideoFullscreenForVideoElement(WebCore::HTMLVideoElement&amp;) override;
</span><span class="cx"> #if PLATFORM(MAC) &amp;&amp; ENABLE(VIDEO_PRESENTATION_MODE)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcesscocoaWebVideoFullscreenManagerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/cocoa/WebVideoFullscreenManager.h (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/cocoa/WebVideoFullscreenManager.h        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebKit2/WebProcess/cocoa/WebVideoFullscreenManager.h        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -118,6 +118,7 @@
</span><span class="cx">     void exitVideoFullscreenForVideoElement(WebCore::HTMLVideoElement&amp;);
</span><span class="cx">     void exitVideoFullscreenToModeWithoutAnimation(WebCore::HTMLVideoElement&amp;, WebCore::HTMLMediaElementEnums::VideoFullscreenMode);
</span><span class="cx">     void setUpVideoControlsManager(WebCore::HTMLVideoElement&amp;);
</span><ins>+    void clearVideoControlsManager();
</ins><span class="cx">     
</span><span class="cx"> protected:
</span><span class="cx">     friend class WebVideoFullscreenInterfaceContext;
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcesscocoaWebVideoFullscreenManagermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/cocoa/WebVideoFullscreenManager.mm (199021 => 199022)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/cocoa/WebVideoFullscreenManager.mm        2016-04-04 21:09:35 UTC (rev 199021)
+++ trunk/Source/WebKit2/WebProcess/cocoa/WebVideoFullscreenManager.mm        2016-04-04 21:18:57 UTC (rev 199022)
</span><span class="lines">@@ -344,6 +344,18 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebVideoFullscreenManager::clearVideoControlsManager()
+{
+#if PLATFORM(MAC)
+    if (!m_controlsManagerContextId)
+        return;
+
+    removeClientForContext(m_controlsManagerContextId);
+    m_controlsManagerContextId = 0;
+    m_page-&gt;send(Messages::WebVideoFullscreenManagerProxy::ClearVideoControlsManager(), m_page-&gt;pageID());
+#endif
+}
+
</ins><span class="cx"> void WebVideoFullscreenManager::exitVideoFullscreenToModeWithoutAnimation(WebCore::HTMLVideoElement&amp; videoElement, WebCore::HTMLMediaElementEnums::VideoFullscreenMode targetMode)
</span><span class="cx"> {
</span><span class="cx"> #if PLATFORM(MAC) &amp;&amp; ENABLE(VIDEO_PRESENTATION_MODE)
</span></span></pre>
</div>
</div>

</body>
</html>