Title: [280670] trunk/Source/WebKit
Revision
280670
Author
[email protected]
Date
2021-08-04 16:47:46 -0700 (Wed, 04 Aug 2021)

Log Message

Use Observer in place of VideoFullscreenManagerProxyClient
https://bugs.webkit.org/show_bug.cgi?id=228761
rdar://problem/81489026

Reviewed by Jer Noble.

Use an Observer member rather than creating a child class that would be used
when the PiP state change. This prevents having to deal with lifetime and
potentially setting it up multiple times.
No change in observable behaviour, covered with existing tests.

* UIProcess/Cocoa/VideoFullscreenManagerProxy.h: Remove VideoFullscreenManagerProxyClient
class. Use WeakHashSet to store observers.
* UIProcess/Cocoa/VideoFullscreenManagerProxy.mm:
(WebKit::VideoFullscreenManagerProxy::addVideoInPictureInPictureDidChangeObserver):
Method added, replace older setClient
(WebKit::VideoFullscreenManagerProxy::hasVideoInPictureInPictureDidChange):
Iterate over all observers and call accordingly.
* UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm:
(-[WKFullScreenWindowController initWithWebView:]): Remove no longer necessary
code.
(-[WKFullScreenWindowController dealloc]): Remove no longer necessary
code.
(-[WKFullScreenWindowController beganEnterFullScreenWithInitialFrame:finalFrame:]):
set PiP change observer if none already exists.
* UIProcess/mac/WKFullScreenWindowController.mm:
(-[WKFullScreenWindowController initWithWindow:webView:page:]): Remove no longer necessary
code.
(-[WKFullScreenWindowController dealloc]): Remove no longer necessary
code.
(-[WKFullScreenWindowController clearVideoFullscreenManagerObserver]):
(-[WKFullScreenWindowController setVideoFullscreenManagerObserver]):
(-[WKFullScreenWindowController didExitPictureInPicture]):
(-[WKFullScreenWindowController windowDidEnterFullScreen:]):
(-[WKFullScreenWindowController windowDidFailToExitFullScreen:]):
(-[WKFullScreenWindowController windowDidExitFullScreen:]):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (280669 => 280670)


--- trunk/Source/WebKit/ChangeLog	2021-08-04 23:08:39 UTC (rev 280669)
+++ trunk/Source/WebKit/ChangeLog	2021-08-04 23:47:46 UTC (rev 280670)
@@ -1,3 +1,42 @@
+2021-08-04  Jean-Yves Avenard  <[email protected]>
+
+        Use Observer in place of VideoFullscreenManagerProxyClient
+        https://bugs.webkit.org/show_bug.cgi?id=228761
+        rdar://problem/81489026
+
+        Reviewed by Jer Noble.
+
+        Use an Observer member rather than creating a child class that would be used
+        when the PiP state change. This prevents having to deal with lifetime and
+        potentially setting it up multiple times.
+        No change in observable behaviour, covered with existing tests.
+
+        * UIProcess/Cocoa/VideoFullscreenManagerProxy.h: Remove VideoFullscreenManagerProxyClient
+        class. Use WeakHashSet to store observers.
+        * UIProcess/Cocoa/VideoFullscreenManagerProxy.mm:
+        (WebKit::VideoFullscreenManagerProxy::addVideoInPictureInPictureDidChangeObserver):
+        Method added, replace older setClient
+        (WebKit::VideoFullscreenManagerProxy::hasVideoInPictureInPictureDidChange):
+        Iterate over all observers and call accordingly.
+        * UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm:
+        (-[WKFullScreenWindowController initWithWebView:]): Remove no longer necessary
+        code.
+        (-[WKFullScreenWindowController dealloc]): Remove no longer necessary
+        code.
+        (-[WKFullScreenWindowController beganEnterFullScreenWithInitialFrame:finalFrame:]):
+        set PiP change observer if none already exists.
+        * UIProcess/mac/WKFullScreenWindowController.mm:
+        (-[WKFullScreenWindowController initWithWindow:webView:page:]): Remove no longer necessary
+        code.
+        (-[WKFullScreenWindowController dealloc]): Remove no longer necessary
+        code.
+        (-[WKFullScreenWindowController clearVideoFullscreenManagerObserver]):
+        (-[WKFullScreenWindowController setVideoFullscreenManagerObserver]):
+        (-[WKFullScreenWindowController didExitPictureInPicture]):
+        (-[WKFullScreenWindowController windowDidEnterFullScreen:]):
+        (-[WKFullScreenWindowController windowDidFailToExitFullScreen:]):
+        (-[WKFullScreenWindowController windowDidExitFullScreen:]):
+
 2021-08-04  Tim Horton  <[email protected]>
 
         RemoteLayerBackingStore: Adopt a new bifurcated layer switch

Modified: trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.h (280669 => 280670)


--- trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.h	2021-08-04 23:08:39 UTC (rev 280669)
+++ trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.h	2021-08-04 23:47:46 UTC (rev 280670)
@@ -37,8 +37,10 @@
 #include <WebCore/VideoFullscreenModel.h>
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
+#include <wtf/Observer.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
+#include <wtf/WeakHashSet.h>
 #include <wtf/text/WTFString.h>
 
 #if PLATFORM(IOS_FAMILY)
@@ -123,13 +125,6 @@
     bool m_hasVideo { false };
 };
 
-class VideoFullscreenManagerProxyClient : public CanMakeWeakPtr<VideoFullscreenManagerProxyClient> {
-public:
-    virtual ~VideoFullscreenManagerProxyClient() { };
-
-    virtual void hasVideoInPictureInPictureDidChange(bool value) = 0;
-};
-
 class VideoFullscreenManagerProxy : public RefCounted<VideoFullscreenManagerProxy>, private IPC::MessageReceiver {
 public:
     static Ref<VideoFullscreenManagerProxy> create(WebPageProxy&, PlaybackSessionManagerProxy&);
@@ -150,8 +145,8 @@
     bool isPlayingVideoInEnhancedFullscreen() const;
 
     PlatformVideoFullscreenInterface* controlsManagerInterface();
-    void setClient(VideoFullscreenManagerProxyClient* client) { m_client = makeWeakPtr(client); }
-    VideoFullscreenManagerProxyClient* client() const { return m_client.get(); }
+    using VideoInPictureInPictureDidChangeObserver = WTF::Observer<void(bool)>;
+    void addVideoInPictureInPictureDidChangeObserver(const VideoInPictureInPictureDidChangeObserver&);
 
     void forEachSession(Function<void(VideoFullscreenModelContext&, PlatformVideoFullscreenInterface&)>&&);
 
@@ -212,8 +207,8 @@
     HashMap<PlaybackSessionContextIdentifier, ModelInterfaceTuple> m_contextMap;
     PlaybackSessionContextIdentifier m_controlsManagerContextId;
     HashMap<PlaybackSessionContextIdentifier, int> m_clientCounts;
-    WeakPtr<VideoFullscreenManagerProxyClient> m_client;
     Vector<CompletionHandler<void()>> m_closeCompletionHandlers;
+    WeakHashSet<VideoInPictureInPictureDidChangeObserver> m_pipChangeObservers;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm (280669 => 280670)


--- trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm	2021-08-04 23:08:39 UTC (rev 280669)
+++ trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm	2021-08-04 23:47:46 UTC (rev 280670)
@@ -511,11 +511,16 @@
     }
 }
 
+void VideoFullscreenManagerProxy::addVideoInPictureInPictureDidChangeObserver(const VideoInPictureInPictureDidChangeObserver& observer)
+{
+    ASSERT(!m_pipChangeObservers.contains(observer));
+    m_pipChangeObservers.add(observer);
+}
+
 void VideoFullscreenManagerProxy::hasVideoInPictureInPictureDidChange(bool value)
 {
     m_page->uiClient().hasVideoInPictureInPictureDidChange(m_page, value);
-    if (m_client)
-        m_client->hasVideoInPictureInPictureDidChange(value);
+    m_pipChangeObservers.forEach([value] (auto& observer) { observer(value); });
 }
 
 #pragma mark Messages from VideoFullscreenManager

Modified: trunk/Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm (280669 => 280670)


--- trunk/Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm	2021-08-04 23:08:39 UTC (rev 280669)
+++ trunk/Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm	2021-08-04 23:47:46 UTC (rev 280670)
@@ -435,23 +435,6 @@
 - (void)didExitPictureInPicture;
 @end
 
-class WKFullScreenWindowControllerVideoFullscreenManagerProxyClient : public WebKit::VideoFullscreenManagerProxyClient {
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    void setParent(WKFullScreenWindowController *parent) { m_parent = parent; }
-
-private:
-    void hasVideoInPictureInPictureDidChange(bool value) final
-    {
-        if (value)
-            [m_parent didEnterPictureInPicture];
-        else
-            [m_parent didExitPictureInPicture];
-    }
-
-    WKFullScreenWindowController *m_parent { nullptr };
-};
-
 #pragma mark -
 
 @implementation WKFullScreenWindowController {
@@ -470,7 +453,7 @@
     RetainPtr<UIPinchGestureRecognizer> _interactivePinchDismissGestureRecognizer;
     RetainPtr<WKFullScreenInteractiveTransition> _interactiveDismissTransitionCoordinator;
 
-    WKFullScreenWindowControllerVideoFullscreenManagerProxyClient _videoFullscreenManagerProxyClient;
+    std::unique_ptr<WebKit::VideoFullscreenManagerProxy::VideoInPictureInPictureDidChangeObserver> _pipObserver;
     BOOL _shouldReturnToFullscreenFromPictureInPicture;
     BOOL _enterFullscreenNeedsExitPictureInPicture;
     BOOL _returnToFullscreenFromPictureInPicture;
@@ -497,7 +480,6 @@
         return nil;
 
     self._webView = webView;
-    _videoFullscreenManagerProxyClient.setParent(self);
 
     return self;
 }
@@ -507,8 +489,6 @@
     [NSObject cancelPreviousPerformRequestsWithTarget:self];
     [[NSNotificationCenter defaultCenter] removeObserver:self];
 
-    _videoFullscreenManagerProxyClient.setParent(nullptr);
-
     [super dealloc];
 }
 
@@ -695,8 +675,15 @@
 #endif
 
             if (auto* videoFullscreenManager = self._videoFullscreenManager) {
-                videoFullscreenManager->setClient(&_videoFullscreenManagerProxyClient);
-
+                if (!_pipObserver) {
+                    _pipObserver = WTF::makeUnique<WebKit::VideoFullscreenManagerProxy::VideoInPictureInPictureDidChangeObserver>([self] (bool inPiP) {
+                        if (inPiP)
+                            [self didEnterPictureInPicture];
+                        else
+                            [self didExitPictureInPicture];
+                    });
+                    videoFullscreenManager->addVideoInPictureInPictureDidChangeObserver(*_pipObserver);
+                }
                 if (auto* videoFullscreenInterface = videoFullscreenManager ? videoFullscreenManager->controlsManagerInterface() : nullptr) {
                     if (_returnToFullscreenFromPictureInPicture)
                         videoFullscreenInterface->preparedToReturnToStandby();

Modified: trunk/Source/WebKit/UIProcess/mac/WKFullScreenWindowController.mm (280669 => 280670)


--- trunk/Source/WebKit/UIProcess/mac/WKFullScreenWindowController.mm	2021-08-04 23:08:39 UTC (rev 280669)
+++ trunk/Source/WebKit/UIProcess/mac/WKFullScreenWindowController.mm	2021-08-04 23:47:46 UTC (rev 280670)
@@ -59,23 +59,6 @@
 - (void)didExitPictureInPicture;
 @end
 
-class WKFullScreenWindowControllerVideoFullscreenManagerProxyClient : public WebKit::VideoFullscreenManagerProxyClient {
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    void setParent(WKFullScreenWindowController *parent) { m_parent = parent; }
-
-private:
-    void hasVideoInPictureInPictureDidChange(bool value) final
-    {
-        if (value)
-            [m_parent didEnterPictureInPicture];
-        else
-            [m_parent didExitPictureInPicture];
-    }
-
-    WKFullScreenWindowController *m_parent { nullptr };
-};
-
 enum FullScreenState : NSInteger {
     NotInFullScreen,
     WaitingToEnterFullScreen,
@@ -104,7 +87,7 @@
 }
 
 @implementation WKFullScreenWindowController {
-    WKFullScreenWindowControllerVideoFullscreenManagerProxyClient _videoFullscreenManagerProxyClient;
+    std::unique_ptr<WebKit::VideoFullscreenManagerProxy::VideoInPictureInPictureDidChangeObserver> _pipObserver;
 }
 
 #pragma mark -
@@ -141,8 +124,6 @@
     _webView = webView;
     _page = page.ptr();
 
-    _videoFullscreenManagerProxyClient.setParent(self);
-
     [self videoControlsManagerDidChange];
 
     return self;
@@ -156,8 +137,6 @@
     
     [[NSNotificationCenter defaultCenter] removeObserver:self];
 
-    _videoFullscreenManagerProxyClient.setParent(nullptr);
-
     [super dealloc];
 }
 
@@ -639,6 +618,31 @@
 {
 }
 
+- (void)clearVideoFullscreenManagerObserver
+{
+    _pipObserver = nullptr;
+}
+
+- (void)setVideoFullscreenManagerObserver
+{
+    auto* videoFullscreenManager = self._videoFullscreenManager;
+    if (!videoFullscreenManager)
+        return;
+
+    ASSERT(!_pipObserver);
+    if (_pipObserver)
+        return;
+
+    _pipObserver = WTF::makeUnique<WebKit::VideoFullscreenManagerProxy::VideoInPictureInPictureDidChangeObserver>([self] (bool inPiP) {
+        if (inPiP)
+            [self didEnterPictureInPicture];
+        else
+            [self didExitPictureInPicture];
+    });
+
+    videoFullscreenManager->addVideoInPictureInPictureDidChangeObserver(*_pipObserver);
+}
+
 - (void)didEnterPictureInPicture
 {
     if ([self isFullScreen])
@@ -645,17 +649,9 @@
         [self requestExitFullScreen];
 }
 
-- (void)setVideoFullscreenManagerClient:(WebKit::VideoFullscreenManagerProxyClient *)client
-{
-    if (auto* videoFullscreenManager = self._videoFullscreenManager) {
-        ASSERT((client && !videoFullscreenManager->client()) || (!client && videoFullscreenManager->client() == &_videoFullscreenManagerProxyClient));
-        videoFullscreenManager->setClient(client);
-    }
-}
-
 - (void)didExitPictureInPicture
 {
-    [self setVideoFullscreenManagerClient:nullptr];
+    [self clearVideoFullscreenManagerObserver];
 }
 
 #pragma mark -
@@ -690,7 +686,7 @@
 {
     RetainPtr<WKFullScreenWindowController> retain = self;
     [self finishedEnterFullScreenAnimation:YES];
-    [self setVideoFullscreenManagerClient:&_videoFullscreenManagerProxyClient];
+    [self setVideoFullscreenManagerObserver];
 }
 
 - (void)windowDidFailToExitFullScreen:(NSWindow *)window
@@ -697,7 +693,7 @@
 {
     RetainPtr<WKFullScreenWindowController> retain = self;
     [self finishedExitFullScreenAnimation:NO];
-    [self setVideoFullscreenManagerClient:nullptr];
+    [self clearVideoFullscreenManagerObserver];
 }
 
 - (void)windowDidExitFullScreen:(NSNotification *)notification
@@ -704,7 +700,7 @@
 {
     RetainPtr<WKFullScreenWindowController> retain = self;
     [self finishedExitFullScreenAnimation:YES];
-    [self setVideoFullscreenManagerClient:nullptr];
+    [self clearVideoFullscreenManagerObserver];
 }
 
 - (NSWindow *)destinationWindowToExitFullScreenForWindow:(NSWindow *)window
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to