Title: [232301] trunk/Source/WebKit
Revision
232301
Author
jer.no...@apple.com
Date
2018-05-30 11:00:27 -0700 (Wed, 30 May 2018)

Log Message

Auto-pip should use main content heuristic.
https://bugs.webkit.org/show_bug.cgi?id=186065
<rdar://problem/35862502>

Reviewed by Eric Carlson.

Make the m_pipStandbyElement clearable, which will allow the auto-pip mechanism to be torn down. Add
a WebProcess-side notification when the main content changes, to facilitate this.

* WebProcess/FullScreen/WebFullScreenManager.cpp:
(WebKit::WebFullScreenManager::videoControlsManagerDidChange):
(WebKit::WebFullScreenManager::setPIPStandbyElement):
(WebKit::WebFullScreenManager::didEnterFullScreen):
(WebKit::WebFullScreenManager::willExitFullScreen):
* WebProcess/FullScreen/WebFullScreenManager.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::videoControlsManagerDidChange):
* WebProcess/WebPage/WebPage.h:
* WebProcess/cocoa/PlaybackSessionManager.h:
* WebProcess/cocoa/PlaybackSessionManager.mm:
(WebKit::PlaybackSessionManager::setUpPlaybackControlsManager):
(WebKit::PlaybackSessionManager::clearPlaybackControlsManager):
(WebKit::PlaybackSessionManager::currentPlaybackControlsElement const):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (232300 => 232301)


--- trunk/Source/WebKit/ChangeLog	2018-05-30 18:00:23 UTC (rev 232300)
+++ trunk/Source/WebKit/ChangeLog	2018-05-30 18:00:27 UTC (rev 232301)
@@ -1,5 +1,31 @@
 2018-05-30  Jer Noble  <jer.no...@apple.com>
 
+        Auto-pip should use main content heuristic.
+        https://bugs.webkit.org/show_bug.cgi?id=186065
+        <rdar://problem/35862502>
+
+        Reviewed by Eric Carlson.
+
+        Make the m_pipStandbyElement clearable, which will allow the auto-pip mechanism to be torn down. Add
+        a WebProcess-side notification when the main content changes, to facilitate this.
+
+        * WebProcess/FullScreen/WebFullScreenManager.cpp:
+        (WebKit::WebFullScreenManager::videoControlsManagerDidChange):
+        (WebKit::WebFullScreenManager::setPIPStandbyElement):
+        (WebKit::WebFullScreenManager::didEnterFullScreen):
+        (WebKit::WebFullScreenManager::willExitFullScreen):
+        * WebProcess/FullScreen/WebFullScreenManager.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::videoControlsManagerDidChange):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/cocoa/PlaybackSessionManager.h:
+        * WebProcess/cocoa/PlaybackSessionManager.mm:
+        (WebKit::PlaybackSessionManager::setUpPlaybackControlsManager):
+        (WebKit::PlaybackSessionManager::clearPlaybackControlsManager):
+        (WebKit::PlaybackSessionManager::currentPlaybackControlsElement const):
+
+2018-05-30  Jer Noble  <jer.no...@apple.com>
+
         Fix a few issues in WKFullScreenViewController
         https://bugs.webkit.org/show_bug.cgi?id=186067
         <rdar://problem/40630944>

Modified: trunk/Source/WebKit/WebProcess/FullScreen/WebFullScreenManager.cpp (232300 => 232301)


--- trunk/Source/WebKit/WebProcess/FullScreen/WebFullScreenManager.cpp	2018-05-30 18:00:23 UTC (rev 232300)
+++ trunk/Source/WebKit/WebProcess/FullScreen/WebFullScreenManager.cpp	2018-05-30 18:00:27 UTC (rev 232301)
@@ -45,6 +45,10 @@
 #include <WebCore/Settings.h>
 #include <WebCore/TypedElementDescendantIterator.h>
 
+#if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))
+#include "PlaybackSessionManager.h"
+#endif
+
 using namespace WebCore;
 
 namespace WebKit {
@@ -81,6 +85,28 @@
     return m_element.get(); 
 }
 
+void WebFullScreenManager::videoControlsManagerDidChange()
+{
+#if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))
+    auto* currentPlaybackControlsElement = m_page->playbackSessionManager().currentPlaybackControlsElement();
+    setPIPStandbyElement(is<HTMLVideoElement>(currentPlaybackControlsElement) ? downcast<HTMLVideoElement>(currentPlaybackControlsElement) : nullptr);
+#endif
+}
+
+void WebFullScreenManager::setPIPStandbyElement(WebCore::HTMLVideoElement* pipStandbyElement)
+{
+    if (pipStandbyElement == m_pipStandbyElement)
+        return;
+
+    if (m_pipStandbyElement)
+        m_pipStandbyElement->setVideoFullscreenStandby(false);
+
+    m_pipStandbyElement = pipStandbyElement;
+
+    if (m_pipStandbyElement)
+        m_pipStandbyElement->setVideoFullscreenStandby(true);
+}
+
 void WebFullScreenManager::didReceiveMessage(IPC::Connection& connection, IPC::Decoder& decoder)
 {
     didReceiveWebFullScreenManagerMessage(connection, decoder);
@@ -125,10 +151,9 @@
     ASSERT(m_element);
     m_element->document().webkitDidEnterFullScreenForElement(m_element.get());
 
-#if ENABLE(VIDEO)
-    m_pipStandbyElement = descendantsOfType<HTMLVideoElement>(*m_element).first();
-    if (m_pipStandbyElement)
-        m_pipStandbyElement->setVideoFullscreenStandby(true);
+#if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))
+    auto* currentPlaybackControlsElement = m_page->playbackSessionManager().currentPlaybackControlsElement();
+    setPIPStandbyElement(is<HTMLVideoElement>(currentPlaybackControlsElement) ? downcast<HTMLVideoElement>(currentPlaybackControlsElement) : nullptr);
 #endif
 }
 
@@ -137,9 +162,7 @@
     ASSERT(m_element);
 
 #if ENABLE(VIDEO)
-    if (m_pipStandbyElement)
-        m_pipStandbyElement->setVideoFullscreenStandby(false);
-    m_pipStandbyElement = nullptr;
+    setPIPStandbyElement(nullptr);
 #endif
 
     m_finalFrame = screenRectOfContents(m_element.get());

Modified: trunk/Source/WebKit/WebProcess/FullScreen/WebFullScreenManager.h (232300 => 232301)


--- trunk/Source/WebKit/WebProcess/FullScreen/WebFullScreenManager.h	2018-05-30 18:00:23 UTC (rev 232300)
+++ trunk/Source/WebKit/WebProcess/FullScreen/WebFullScreenManager.h	2018-05-30 18:00:27 UTC (rev 232301)
@@ -65,11 +65,15 @@
 
     WebCore::Element* element();
 
+    void videoControlsManagerDidChange();
+
     void close();
 
 protected:
     WebFullScreenManager(WebPage*);
 
+    void setPIPStandbyElement(WebCore::HTMLVideoElement*);
+
     void setAnimatingFullScreen(bool);
     void requestExitFullScreen();
     void saveScrollPosition();

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (232300 => 232301)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2018-05-30 18:00:23 UTC (rev 232300)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2018-05-30 18:00:27 UTC (rev 232301)
@@ -3289,8 +3289,17 @@
         m_videoFullscreenManager = VideoFullscreenManager::create(*this, playbackSessionManager());
     return *m_videoFullscreenManager;
 }
+
+void WebPage::videoControlsManagerDidChange()
+{
+#if ENABLE(FULLSCREEN_API)
+    if (auto* manager = fullScreenManager())
+        manager->videoControlsManagerDidChange();
 #endif
+}
 
+#endif
+
 #if PLATFORM(IOS)
 void WebPage::setAllowsMediaDocumentInlinePlayback(bool allows)
 {

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (232300 => 232301)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2018-05-30 18:00:23 UTC (rev 232300)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2018-05-30 18:00:27 UTC (rev 232301)
@@ -298,6 +298,7 @@
 #if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))
     PlaybackSessionManager& playbackSessionManager();
     VideoFullscreenManager& videoFullscreenManager();
+    void videoControlsManagerDidChange();
 #endif
 
 #if PLATFORM(IOS)

Modified: trunk/Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.h (232300 => 232301)


--- trunk/Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.h	2018-05-30 18:00:23 UTC (rev 232300)
+++ trunk/Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.h	2018-05-30 18:00:27 UTC (rev 232301)
@@ -109,6 +109,8 @@
     void clearPlaybackControlsManager();
     uint64_t contextIdForMediaElement(WebCore::HTMLMediaElement&);
 
+    WebCore::HTMLMediaElement* currentPlaybackControlsElement() const;
+
 protected:
     friend class PlaybackSessionInterfaceContext;
     friend class VideoFullscreenManager;

Modified: trunk/Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.mm (232300 => 232301)


--- trunk/Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.mm	2018-05-30 18:00:23 UTC (rev 232300)
+++ trunk/Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.mm	2018-05-30 18:00:27 UTC (rev 232301)
@@ -278,19 +278,21 @@
     }
 
     addClientForContext(m_controlsManagerContextId);
+
+    m_page->videoControlsManagerDidChange();
     m_page->send(Messages::PlaybackSessionManagerProxy::SetUpPlaybackControlsManagerWithID(m_controlsManagerContextId), m_page->pageID());
 }
 
 void PlaybackSessionManager::clearPlaybackControlsManager()
 {
-#if PLATFORM(MAC)
     if (!m_controlsManagerContextId)
         return;
 
     removeClientForContext(m_controlsManagerContextId);
     m_controlsManagerContextId = 0;
+
+    m_page->videoControlsManagerDidChange();
     m_page->send(Messages::PlaybackSessionManagerProxy::ClearPlaybackControlsManager(), m_page->pageID());
-#endif
 }
 
 uint64_t PlaybackSessionManager::contextIdForMediaElement(WebCore::HTMLMediaElement& mediaElement)
@@ -301,6 +303,18 @@
     return contextId;
 }
 
+WebCore::HTMLMediaElement* PlaybackSessionManager::currentPlaybackControlsElement() const
+{
+    if (!m_controlsManagerContextId)
+        return nullptr;
+
+    auto iter = m_contextMap.find(m_controlsManagerContextId);
+    if (iter == m_contextMap.end())
+        return nullptr;
+
+    return std::get<0>(iter->value)->mediaElement();
+}
+
 #pragma mark Interface to PlaybackSessionInterfaceContext:
 
 void PlaybackSessionManager::resetMediaState(uint64_t contextId)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to