Changeset 247417 in webkit


Ignore:
Timestamp:
Jul 13, 2019 8:28:51 AM (5 years ago)
Author:
Chris Dumez
Message:

Drop non thread-safe usage of WeakPtr in VideoFullscreenInterfaceAVKit
https://bugs.webkit.org/show_bug.cgi?id=199775

Reviewed by Eric Carlson.

The VideoFullscreenInterfaceAVKit constructor was making a weakPtr on the UI Thread
of an WebThread object. The WeakPtr would then be used as a data member throughout
the class on the UIThread. This is not thread-safe.

This patch switches to using a raw pointer instead of a WeakPtr. This is a partial
rollout of r243298, which turned the raw pointer into a WeakPtr for hardening
purposes. For extra safety, this patch updates the VideoFullscreenControllerContext
so that it notifies its clients (i.e. PlaybackSessionInterfaceAVKit) that it is
getting destroyed, so that they can null-out their m_videoFullscreenModel &
m_fullscreenChangeObserver data members. This gives the sames guarantees as WeakPtr
but in a thread-safe way.

This is very similar to the fix that was done for PlaybackSessionInterfaceAVKit in
r247380.

  • platform/cocoa/VideoFullscreenModel.h:

(WebCore::VideoFullscreenModelClient::modelDestroyed):

  • platform/ios/VideoFullscreenInterfaceAVKit.h:
  • platform/ios/VideoFullscreenInterfaceAVKit.mm:

(VideoFullscreenInterfaceAVKit::setVideoFullscreenModel):
(VideoFullscreenInterfaceAVKit::setVideoFullscreenChangeObserver):
(VideoFullscreenInterfaceAVKit::modelDestroyed):

  • platform/ios/WebVideoFullscreenControllerAVKit.mm:

(VideoFullscreenControllerContext::~VideoFullscreenControllerContext):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r247416 r247417  
     12019-07-13  Chris Dumez  <cdumez@apple.com>
     2
     3        Drop non thread-safe usage of WeakPtr in VideoFullscreenInterfaceAVKit
     4        https://bugs.webkit.org/show_bug.cgi?id=199775
     5
     6        Reviewed by Eric Carlson.
     7
     8        The VideoFullscreenInterfaceAVKit constructor was making a weakPtr on the UI Thread
     9        of an WebThread object. The WeakPtr would then be used as a data member throughout
     10        the class on the UIThread. This is not thread-safe.
     11
     12        This patch switches to using a raw pointer instead of a WeakPtr. This is a partial
     13        rollout of r243298, which turned the raw pointer into a WeakPtr for hardening
     14        purposes. For extra safety, this patch updates the VideoFullscreenControllerContext
     15        so that it notifies its clients (i.e. PlaybackSessionInterfaceAVKit) that it is
     16        getting destroyed, so that they can null-out their m_videoFullscreenModel &
     17        m_fullscreenChangeObserver data members. This gives the sames guarantees as WeakPtr
     18        but in a thread-safe way.
     19
     20        This is very similar to the fix that was done for PlaybackSessionInterfaceAVKit in
     21        r247380.
     22
     23        * platform/cocoa/VideoFullscreenModel.h:
     24        (WebCore::VideoFullscreenModelClient::modelDestroyed):
     25        * platform/ios/VideoFullscreenInterfaceAVKit.h:
     26        * platform/ios/VideoFullscreenInterfaceAVKit.mm:
     27        (VideoFullscreenInterfaceAVKit::setVideoFullscreenModel):
     28        (VideoFullscreenInterfaceAVKit::setVideoFullscreenChangeObserver):
     29        (VideoFullscreenInterfaceAVKit::modelDestroyed):
     30        * platform/ios/WebVideoFullscreenControllerAVKit.mm:
     31        (VideoFullscreenControllerContext::~VideoFullscreenControllerContext):
     32
    1332019-07-13  Zalan Bujtas  <zalan@apple.com>
    234
  • trunk/Source/WebCore/platform/cocoa/VideoFullscreenModel.h

    r243627 r247417  
    8484    virtual void willExitPictureInPicture() { }
    8585    virtual void didExitPictureInPicture() { }
     86    virtual void modelDestroyed() { }
    8687};
    8788
  • trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h

    r243298 r247417  
    7575    WEBCORE_EXPORT void hasVideoChanged(bool) final;
    7676    WEBCORE_EXPORT void videoDimensionsChanged(const FloatSize&) final;
     77    WEBCORE_EXPORT void modelDestroyed() final;
    7778
    7879    // PlaybackSessionModelClient
     
    128129    Mode m_targetMode;
    129130
    130     VideoFullscreenModel* videoFullscreenModel() const { return m_videoFullscreenModel.get(); }
     131    VideoFullscreenModel* videoFullscreenModel() const { return m_videoFullscreenModel; }
    131132    bool shouldExitFullscreenWithReason(ExitFullScreenReason);
    132133    HTMLMediaElementEnums::VideoFullscreenMode mode() const { return m_currentMode.mode(); }
     
    172173    RetainPtr<WebAVPlayerViewControllerDelegate> m_playerViewControllerDelegate;
    173174    RetainPtr<WebAVPlayerViewController> m_playerViewController;
    174     WeakPtr<VideoFullscreenModel> m_videoFullscreenModel;
    175     WeakPtr<VideoFullscreenChangeObserver> m_fullscreenChangeObserver;
     175    VideoFullscreenModel* m_videoFullscreenModel { nullptr };
     176    VideoFullscreenChangeObserver* m_fullscreenChangeObserver { nullptr };
    176177
    177178    // These are only used when fullscreen is presented in a separate window.
  • trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm

    r246892 r247417  
    761761        m_videoFullscreenModel->removeClient(*this);
    762762
    763     m_videoFullscreenModel = makeWeakPtr(model);
     763    m_videoFullscreenModel = model;
    764764
    765765    if (m_videoFullscreenModel) {
     
    780780void VideoFullscreenInterfaceAVKit::setVideoFullscreenChangeObserver(VideoFullscreenChangeObserver* observer)
    781781{
    782     m_fullscreenChangeObserver = makeWeakPtr(observer);
     782    m_fullscreenChangeObserver = observer;
    783783}
    784784
     
    929929   
    930930    cleanupFullscreen();
     931}
     932
     933void VideoFullscreenInterfaceAVKit::modelDestroyed()
     934{
     935    ASSERT(isUIThread());
     936    invalidate();
    931937}
    932938
  • trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm

    r247380 r247417  
    224224        while (!m_playbackClients.isEmpty())
    225225            (*m_playbackClients.begin())->modelDestroyed();
     226        while (!m_fullscreenClients.isEmpty())
     227            (*m_fullscreenClients.begin())->modelDestroyed();
    226228    };
    227229    if (isUIThread())
Note: See TracChangeset for help on using the changeset viewer.