⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 280670 in webkit


Ignore:
Timestamp:
Aug 4, 2021, 4:47:46 PM (5 years ago)
Author:
Jean-Yves Avenard
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:]):

Location:
trunk/Source/WebKit
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r280669 r280670  
     12021-08-04  Jean-Yves Avenard  <jya@apple.com>
     2
     3        Use Observer in place of VideoFullscreenManagerProxyClient
     4        https://bugs.webkit.org/show_bug.cgi?id=228761
     5        rdar://problem/81489026
     6
     7        Reviewed by Jer Noble.
     8
     9        Use an Observer member rather than creating a child class that would be used
     10        when the PiP state change. This prevents having to deal with lifetime and
     11        potentially setting it up multiple times.
     12        No change in observable behaviour, covered with existing tests.
     13
     14        * UIProcess/Cocoa/VideoFullscreenManagerProxy.h: Remove VideoFullscreenManagerProxyClient
     15        class. Use WeakHashSet to store observers.
     16        * UIProcess/Cocoa/VideoFullscreenManagerProxy.mm:
     17        (WebKit::VideoFullscreenManagerProxy::addVideoInPictureInPictureDidChangeObserver):
     18        Method added, replace older setClient
     19        (WebKit::VideoFullscreenManagerProxy::hasVideoInPictureInPictureDidChange):
     20        Iterate over all observers and call accordingly.
     21        * UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm:
     22        (-[WKFullScreenWindowController initWithWebView:]): Remove no longer necessary
     23        code.
     24        (-[WKFullScreenWindowController dealloc]): Remove no longer necessary
     25        code.
     26        (-[WKFullScreenWindowController beganEnterFullScreenWithInitialFrame:finalFrame:]):
     27        set PiP change observer if none already exists.
     28        * UIProcess/mac/WKFullScreenWindowController.mm:
     29        (-[WKFullScreenWindowController initWithWindow:webView:page:]): Remove no longer necessary
     30        code.
     31        (-[WKFullScreenWindowController dealloc]): Remove no longer necessary
     32        code.
     33        (-[WKFullScreenWindowController clearVideoFullscreenManagerObserver]):
     34        (-[WKFullScreenWindowController setVideoFullscreenManagerObserver]):
     35        (-[WKFullScreenWindowController didExitPictureInPicture]):
     36        (-[WKFullScreenWindowController windowDidEnterFullScreen:]):
     37        (-[WKFullScreenWindowController windowDidFailToExitFullScreen:]):
     38        (-[WKFullScreenWindowController windowDidExitFullScreen:]):
     39
    1402021-08-04  Tim Horton  <timothy_horton@apple.com>
    241
  • trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.h

    r277242 r280670  
    3838#include <wtf/HashMap.h>
    3939#include <wtf/HashSet.h>
     40#include <wtf/Observer.h>
    4041#include <wtf/RefCounted.h>
    4142#include <wtf/RefPtr.h>
     43#include <wtf/WeakHashSet.h>
    4244#include <wtf/text/WTFString.h>
    4345
     
    124126};
    125127
    126 class VideoFullscreenManagerProxyClient : public CanMakeWeakPtr<VideoFullscreenManagerProxyClient> {
    127 public:
    128     virtual ~VideoFullscreenManagerProxyClient() { };
    129 
    130     virtual void hasVideoInPictureInPictureDidChange(bool value) = 0;
    131 };
    132 
    133128class VideoFullscreenManagerProxy : public RefCounted<VideoFullscreenManagerProxy>, private IPC::MessageReceiver {
    134129public:
     
    151146
    152147    PlatformVideoFullscreenInterface* controlsManagerInterface();
    153     void setClient(VideoFullscreenManagerProxyClient* client) { m_client = makeWeakPtr(client); }
    154     VideoFullscreenManagerProxyClient* client() const { return m_client.get(); }
     148    using VideoInPictureInPictureDidChangeObserver = WTF::Observer<void(bool)>;
     149    void addVideoInPictureInPictureDidChangeObserver(const VideoInPictureInPictureDidChangeObserver&);
    155150
    156151    void forEachSession(Function<void(VideoFullscreenModelContext&, PlatformVideoFullscreenInterface&)>&&);
     
    213208    PlaybackSessionContextIdentifier m_controlsManagerContextId;
    214209    HashMap<PlaybackSessionContextIdentifier, int> m_clientCounts;
    215     WeakPtr<VideoFullscreenManagerProxyClient> m_client;
    216210    Vector<CompletionHandler<void()>> m_closeCompletionHandlers;
     211    WeakHashSet<VideoInPictureInPictureDidChangeObserver> m_pipChangeObservers;
    217212};
    218213
  • trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm

    r278663 r280670  
    512512}
    513513
     514void VideoFullscreenManagerProxy::addVideoInPictureInPictureDidChangeObserver(const VideoInPictureInPictureDidChangeObserver& observer)
     515{
     516    ASSERT(!m_pipChangeObservers.contains(observer));
     517    m_pipChangeObservers.add(observer);
     518}
     519
    514520void VideoFullscreenManagerProxy::hasVideoInPictureInPictureDidChange(bool value)
    515521{
    516522    m_page->uiClient().hasVideoInPictureInPictureDidChange(m_page, value);
    517     if (m_client)
    518         m_client->hasVideoInPictureInPictureDidChange(value);
     523    m_pipChangeObservers.forEach([value] (auto& observer) { observer(value); });
    519524}
    520525
  • trunk/Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm

    r279287 r280670  
    436436@end
    437437
    438 class WKFullScreenWindowControllerVideoFullscreenManagerProxyClient : public WebKit::VideoFullscreenManagerProxyClient {
    439     WTF_MAKE_FAST_ALLOCATED;
    440 public:
    441     void setParent(WKFullScreenWindowController *parent) { m_parent = parent; }
    442 
    443 private:
    444     void hasVideoInPictureInPictureDidChange(bool value) final
    445     {
    446         if (value)
    447             [m_parent didEnterPictureInPicture];
    448         else
    449             [m_parent didExitPictureInPicture];
    450     }
    451 
    452     WKFullScreenWindowController *m_parent { nullptr };
    453 };
    454 
    455438#pragma mark -
    456439
     
    471454    RetainPtr<WKFullScreenInteractiveTransition> _interactiveDismissTransitionCoordinator;
    472455
    473     WKFullScreenWindowControllerVideoFullscreenManagerProxyClient _videoFullscreenManagerProxyClient;
     456    std::unique_ptr<WebKit::VideoFullscreenManagerProxy::VideoInPictureInPictureDidChangeObserver> _pipObserver;
    474457    BOOL _shouldReturnToFullscreenFromPictureInPicture;
    475458    BOOL _enterFullscreenNeedsExitPictureInPicture;
     
    498481
    499482    self._webView = webView;
    500     _videoFullscreenManagerProxyClient.setParent(self);
    501483
    502484    return self;
     
    507489    [NSObject cancelPreviousPerformRequestsWithTarget:self];
    508490    [[NSNotificationCenter defaultCenter] removeObserver:self];
    509 
    510     _videoFullscreenManagerProxyClient.setParent(nullptr);
    511491
    512492    [super dealloc];
     
    696676
    697677            if (auto* videoFullscreenManager = self._videoFullscreenManager) {
    698                 videoFullscreenManager->setClient(&_videoFullscreenManagerProxyClient);
    699 
     678                if (!_pipObserver) {
     679                    _pipObserver = WTF::makeUnique<WebKit::VideoFullscreenManagerProxy::VideoInPictureInPictureDidChangeObserver>([self] (bool inPiP) {
     680                        if (inPiP)
     681                            [self didEnterPictureInPicture];
     682                        else
     683                            [self didExitPictureInPicture];
     684                    });
     685                    videoFullscreenManager->addVideoInPictureInPictureDidChangeObserver(*_pipObserver);
     686                }
    700687                if (auto* videoFullscreenInterface = videoFullscreenManager ? videoFullscreenManager->controlsManagerInterface() : nullptr) {
    701688                    if (_returnToFullscreenFromPictureInPicture)
  • trunk/Source/WebKit/UIProcess/mac/WKFullScreenWindowController.mm

    r280628 r280670  
    6060@end
    6161
    62 class WKFullScreenWindowControllerVideoFullscreenManagerProxyClient : public WebKit::VideoFullscreenManagerProxyClient {
    63     WTF_MAKE_FAST_ALLOCATED;
    64 public:
    65     void setParent(WKFullScreenWindowController *parent) { m_parent = parent; }
    66 
    67 private:
    68     void hasVideoInPictureInPictureDidChange(bool value) final
    69     {
    70         if (value)
    71             [m_parent didEnterPictureInPicture];
    72         else
    73             [m_parent didExitPictureInPicture];
    74     }
    75 
    76     WKFullScreenWindowController *m_parent { nullptr };
    77 };
    78 
    7962enum FullScreenState : NSInteger {
    8063    NotInFullScreen,
     
    10588
    10689@implementation WKFullScreenWindowController {
    107     WKFullScreenWindowControllerVideoFullscreenManagerProxyClient _videoFullscreenManagerProxyClient;
     90    std::unique_ptr<WebKit::VideoFullscreenManagerProxy::VideoInPictureInPictureDidChangeObserver> _pipObserver;
    10891}
    10992
     
    142125    _page = page.ptr();
    143126
    144     _videoFullscreenManagerProxyClient.setParent(self);
    145 
    146127    [self videoControlsManagerDidChange];
    147128
     
    156137   
    157138    [[NSNotificationCenter defaultCenter] removeObserver:self];
    158 
    159     _videoFullscreenManagerProxyClient.setParent(nullptr);
    160139
    161140    [super dealloc];
     
    640619}
    641620
     621- (void)clearVideoFullscreenManagerObserver
     622{
     623    _pipObserver = nullptr;
     624}
     625
     626- (void)setVideoFullscreenManagerObserver
     627{
     628    auto* videoFullscreenManager = self._videoFullscreenManager;
     629    if (!videoFullscreenManager)
     630        return;
     631
     632    ASSERT(!_pipObserver);
     633    if (_pipObserver)
     634        return;
     635
     636    _pipObserver = WTF::makeUnique<WebKit::VideoFullscreenManagerProxy::VideoInPictureInPictureDidChangeObserver>([self] (bool inPiP) {
     637        if (inPiP)
     638            [self didEnterPictureInPicture];
     639        else
     640            [self didExitPictureInPicture];
     641    });
     642
     643    videoFullscreenManager->addVideoInPictureInPictureDidChangeObserver(*_pipObserver);
     644}
     645
    642646- (void)didEnterPictureInPicture
    643647{
     
    646650}
    647651
    648 - (void)setVideoFullscreenManagerClient:(WebKit::VideoFullscreenManagerProxyClient *)client
    649 {
    650     if (auto* videoFullscreenManager = self._videoFullscreenManager) {
    651         ASSERT((client && !videoFullscreenManager->client()) || (!client && videoFullscreenManager->client() == &_videoFullscreenManagerProxyClient));
    652         videoFullscreenManager->setClient(client);
    653     }
    654 }
    655 
    656652- (void)didExitPictureInPicture
    657653{
    658     [self setVideoFullscreenManagerClient:nullptr];
     654    [self clearVideoFullscreenManagerObserver];
    659655}
    660656
     
    691687    RetainPtr<WKFullScreenWindowController> retain = self;
    692688    [self finishedEnterFullScreenAnimation:YES];
    693     [self setVideoFullscreenManagerClient:&_videoFullscreenManagerProxyClient];
     689    [self setVideoFullscreenManagerObserver];
    694690}
    695691
     
    698694    RetainPtr<WKFullScreenWindowController> retain = self;
    699695    [self finishedExitFullScreenAnimation:NO];
    700     [self setVideoFullscreenManagerClient:nullptr];
     696    [self clearVideoFullscreenManagerObserver];
    701697}
    702698
     
    705701    RetainPtr<WKFullScreenWindowController> retain = self;
    706702    [self finishedExitFullScreenAnimation:YES];
    707     [self setVideoFullscreenManagerClient:nullptr];
     703    [self clearVideoFullscreenManagerObserver];
    708704}
    709705
Note: See TracChangeset for help on using the changeset viewer.