WebKit Bugzilla
Attachment 347515 Details for
Bug 188747
: Refactoring: eliminate raw pointer usage in Fullscreen code
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-188747-20180820112849.patch (text/plain), 101.29 KB, created by
Jer Noble
on 2018-08-20 11:28:50 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Jer Noble
Created:
2018-08-20 11:28:50 PDT
Size:
101.29 KB
patch
obsolete
>Subversion Revision: 234985 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 0cb77c8f315ca022df72249d51784df7cb7ffe66..9cfa6233d570f713db4cf8b7580d5c0b079f127b 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,125 @@ >+2018-08-20 Jer Noble <jer.noble@apple.com> >+ >+ Refactoring: eliminate raw pointer usage in Fullscreen code >+ https://bugs.webkit.org/show_bug.cgi?id=188747 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Two sources of raw pointers in the Fullscreen code: >+ - Model classes (PlaybackSessionModel and VideoFullscreenModel) aren't ref-able, so >+ they are passed around as raw references. >+ - Observer classes (PlaybackSessionModelClient and VideoFullscreenModelClient, and >+ VideoFullscreenChangeObserver) are also passed around as raw pointers, but shouldn't >+ be ref-able. >+ >+ Make Model classes ref-able by adding ref() and deref() which call virtual refModel and >+ derefModel methods, overridden by implementing subclasses. Make every concrete observer >+ inherit from CanMakeWeakPtr, and every registration method take WeakPtr wrappers around >+ the client interface. >+ >+ Since every Interface class now holds a strong reference to its Model classes, and each >+ Model class holds a weak reference to all its clients, no explicit invalidate() method >+ is necessary. >+ >+ Notes: >+ >+ - Since the weak pointer methods need to be able to downcast to the abstract base class, >+ observers need to inherit publically (rather than privately) from those base classes. >+ - Media element Models should compose EventListener rather than inheriting from it, since >+ EventListener has its own RefCount. >+ - WeakPtrs can't be held in HashSets (because they change value, and therefore hash, when >+ their underlying object is destroyed), so clients should be stored in a Vector instead. >+ - Interfaces should be given all required Refs at creation time, so that they can store >+ those parameters as Refs instead of RefPtrs. >+ >+ * platform/cocoa/PlaybackSessionModel.h: >+ (WebCore::PlaybackSessionModel::ref): >+ (WebCore::PlaybackSessionModel::deref): >+ (WebCore::PlaybackSessionModel::~PlaybackSessionModel): Deleted. >+ * platform/cocoa/PlaybackSessionModelMediaElement.h: >+ * platform/cocoa/PlaybackSessionModelMediaElement.mm: >+ (WebCore::PlaybackSessionModelMediaElement::PlaybackSessionModelMediaElement): >+ (WebCore::PlaybackSessionModelMediaElement::~PlaybackSessionModelMediaElement): >+ (WebCore::PlaybackSessionModelMediaElement::setMediaElement): >+ (WebCore::PlaybackSessionModelMediaElement::addClient): >+ (WebCore::PlaybackSessionModelMediaElement::removeClient): >+ (WebCore::PlaybackSessionModelMediaElement::handleEvent): Deleted. >+ * platform/cocoa/VideoFullscreenChangeObserver.h: >+ (WebCore::VideoFullscreenChangeObserver::~VideoFullscreenChangeObserver): Deleted. >+ * platform/cocoa/VideoFullscreenModel.h: >+ (WebCore::VideoFullscreenModel::ref): >+ (WebCore::VideoFullscreenModel::deref): >+ (WebCore::VideoFullscreenModel::~VideoFullscreenModel): Deleted. >+ * platform/cocoa/VideoFullscreenModelVideoElement.h: >+ * platform/cocoa/VideoFullscreenModelVideoElement.mm: >+ (VideoFullscreenModelVideoElement::VideoFullscreenModelVideoElement): >+ (VideoFullscreenModelVideoElement::setVideoElement): >+ (VideoFullscreenModelVideoElement::addClient): >+ (VideoFullscreenModelVideoElement::removeClient): >+ (VideoFullscreenModelVideoElement::handleEvent): Deleted. >+ * platform/ios/PlaybackSessionInterfaceAVKit.h: >+ * platform/ios/PlaybackSessionInterfaceAVKit.mm: >+ (WebCore::PlaybackSessionInterfaceAVKit::PlaybackSessionInterfaceAVKit): >+ (WebCore::PlaybackSessionInterfaceAVKit::~PlaybackSessionInterfaceAVKit): >+ (WebCore::PlaybackSessionInterfaceAVKit::invalidate): Deleted. >+ * platform/ios/VideoFullscreenInterfaceAVKit.h: >+ * platform/ios/VideoFullscreenInterfaceAVKit.mm: >+ (-[WebAVPlayerLayer layoutSublayers]): >+ (-[WebAVPlayerLayer resolveBounds]): >+ (-[WebAVPlayerLayer setVideoGravity:]): >+ (VideoFullscreenInterfaceAVKit::create): >+ (VideoFullscreenInterfaceAVKit::VideoFullscreenInterfaceAVKit): >+ (VideoFullscreenInterfaceAVKit::~VideoFullscreenInterfaceAVKit): >+ (VideoFullscreenInterfaceAVKit::setVideoFullscreenChangeObserver): >+ (VideoFullscreenInterfaceAVKit::applicationDidBecomeActive): >+ (VideoFullscreenInterfaceAVKit::invalidate): >+ (VideoFullscreenInterfaceAVKit::requestHideAndExitFullscreen): >+ (VideoFullscreenInterfaceAVKit::preparedToExitFullscreen): >+ (VideoFullscreenInterfaceAVKit::willStartPictureInPicture): >+ (VideoFullscreenInterfaceAVKit::didStartPictureInPicture): >+ (VideoFullscreenInterfaceAVKit::failedToStartPictureInPicture): >+ (VideoFullscreenInterfaceAVKit::willStopPictureInPicture): >+ (VideoFullscreenInterfaceAVKit::didStopPictureInPicture): >+ (VideoFullscreenInterfaceAVKit::shouldExitFullscreenWithReason): >+ (VideoFullscreenInterfaceAVKit::doSetup): >+ (VideoFullscreenInterfaceAVKit::setMode): >+ (VideoFullscreenInterfaceAVKit::clearMode): >+ (VideoFullscreenInterfaceAVKit::setVideoFullscreenModel): Deleted. >+ * platform/ios/WebAVPlayerController.h: >+ * platform/ios/WebAVPlayerController.mm: >+ (-[WebAVPlayerController delegate]): >+ (-[WebAVPlayerController playbackSessionInterface]): >+ (-[WebAVPlayerController setPlaybackSessionInterface:]): >+ * platform/ios/WebVideoFullscreenControllerAVKit.mm: >+ (VideoFullscreenControllerContext::didCleanupFullscreen): >+ (VideoFullscreenControllerContext::addClient): >+ (VideoFullscreenControllerContext::removeClient): >+ (VideoFullscreenControllerContext::willEnterPictureInPicture): >+ (VideoFullscreenControllerContext::didEnterPictureInPicture): >+ (VideoFullscreenControllerContext::failedToEnterPictureInPicture): >+ (VideoFullscreenControllerContext::willExitPictureInPicture): >+ (VideoFullscreenControllerContext::didExitPictureInPicture): >+ (VideoFullscreenControllerContext::setUpFullscreen): >+ * platform/mac/PlaybackSessionInterfaceMac.h: >+ * platform/mac/PlaybackSessionInterfaceMac.mm: >+ (WebCore::PlaybackSessionInterfaceMac::create): >+ * platform/mac/VideoFullscreenInterfaceMac.h: >+ (WebCore::VideoFullscreenInterfaceMac::create): >+ (WebCore::VideoFullscreenInterfaceMac::videoFullscreenModel const): >+ (WebCore::VideoFullscreenInterfaceMac::videoFullscreenChangeObserver const): >+ * platform/mac/VideoFullscreenInterfaceMac.mm: >+ (-[WebVideoFullscreenInterfaceMacObjC setUpPIPForVideoView:withFrame:inWindow:]): >+ (-[WebVideoFullscreenInterfaceMacObjC boundsDidChangeForVideoViewContainer:]): >+ (-[WebVideoFullscreenInterfaceMacObjC pipDidClose:]): >+ (WebCore::VideoFullscreenInterfaceMac::VideoFullscreenInterfaceMac): >+ (WebCore::VideoFullscreenInterfaceMac::~VideoFullscreenInterfaceMac): >+ (WebCore::VideoFullscreenInterfaceMac::setVideoFullscreenChangeObserver): >+ (WebCore::VideoFullscreenInterfaceMac::setMode): >+ (WebCore::VideoFullscreenInterfaceMac::clearMode): >+ (WebCore::VideoFullscreenInterfaceMac::invalidate): >+ (WebCore::VideoFullscreenInterfaceMac::requestHideAndExitPiP): >+ (WebCore::VideoFullscreenInterfaceMac::setVideoFullscreenModel): Deleted. >+ > 2018-08-17 Yusuke Suzuki <yusukesuzuki@slowstart.org> and Fujii Hironori <Hironori.Fujii@sony.com> > > [JSC] Add GPRReg::InvalidGPRReg and FPRReg::InvalidFPRReg >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 2fc6ece7d7c5ddf20aa771116e6dff832b786be0..0f4bc17c1bca967f6f8614070d4f1f7fcd74cb2c 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,54 @@ >+2018-08-20 Jer Noble <jer.noble@apple.com> >+ >+ Refactoring: eliminate raw pointer usage in Fullscreen code >+ https://bugs.webkit.org/show_bug.cgi?id=188747 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Adopt those Ref and WeakPtr changes made in WebCore. >+ >+ * UIProcess/Cocoa/PlaybackSessionManagerProxy.h: >+ * UIProcess/Cocoa/PlaybackSessionManagerProxy.mm: >+ (WebKit::PlaybackSessionModelContext::addClient): >+ (WebKit::PlaybackSessionModelContext::removeClient): >+ (WebKit::PlaybackSessionModelContext::durationChanged): >+ (WebKit::PlaybackSessionModelContext::currentTimeChanged): >+ (WebKit::PlaybackSessionModelContext::bufferedTimeChanged): >+ (WebKit::PlaybackSessionModelContext::rateChanged): >+ (WebKit::PlaybackSessionModelContext::seekableRangesChanged): >+ (WebKit::PlaybackSessionModelContext::canPlayFastReverseChanged): >+ (WebKit::PlaybackSessionModelContext::audioMediaSelectionOptionsChanged): >+ (WebKit::PlaybackSessionModelContext::legibleMediaSelectionOptionsChanged): >+ (WebKit::PlaybackSessionModelContext::audioMediaSelectionIndexChanged): >+ (WebKit::PlaybackSessionModelContext::legibleMediaSelectionIndexChanged): >+ (WebKit::PlaybackSessionModelContext::externalPlaybackChanged): >+ (WebKit::PlaybackSessionModelContext::wirelessVideoPlaybackDisabledChanged): >+ (WebKit::PlaybackSessionModelContext::mutedChanged): >+ (WebKit::PlaybackSessionModelContext::volumeChanged): >+ (WebKit::PlaybackSessionModelContext::pictureInPictureActiveChanged): >+ (WebKit::PlaybackSessionManagerProxy::invalidate): >+ (WebKit::PlaybackSessionManagerProxy::createModelAndInterface): >+ (WebKit::PlaybackSessionManagerProxy::removeClientForContext): >+ * UIProcess/Cocoa/VideoFullscreenManagerProxy.h: >+ * UIProcess/Cocoa/VideoFullscreenManagerProxy.mm: >+ (WebKit::VideoFullscreenModelContext::addClient): >+ (WebKit::VideoFullscreenModelContext::removeClient): >+ (WebKit::VideoFullscreenManagerProxy::createModelAndInterface): >+ (WebKit::VideoFullscreenManagerProxy::removeClientForContext): >+ * UIProcess/ios/fullscreen/WKFullScreenViewController.mm: >+ (WKFullScreenViewControllerPlaybackSessionModelClient::setInterface): >+ (WKFullScreenViewControllerVideoFullscreenModelClient::setInterface): >+ (-[WKFullScreenViewController videoControlsManagerDidChange]): >+ (-[WKFullScreenViewController _togglePiPAction:]): >+ * UIProcess/mac/WKFullScreenWindowController.mm: >+ (WebKit::WKFullScreenWindowControllerVideoFullscreenModelClient::setInterface): >+ * WebProcess/cocoa/PlaybackSessionManager.h: >+ * WebProcess/cocoa/PlaybackSessionManager.mm: >+ (WebKit::PlaybackSessionManager::createModelAndInterface): >+ * WebProcess/cocoa/VideoFullscreenManager.h: >+ * WebProcess/cocoa/VideoFullscreenManager.mm: >+ (WebKit::VideoFullscreenManager::createModelAndInterface): >+ > 2018-08-17 Alex Christensen <achristensen@webkit.org> > > Replace WebPageProxy::loadAlternateHTMLString with loadAlternateHTML >diff --git a/Source/WebCore/platform/cocoa/PlaybackSessionModel.h b/Source/WebCore/platform/cocoa/PlaybackSessionModel.h >index 1c4f0e3aee94113f70814ae850c84d44e77e2e99..08d82a4519a2ef6ec66a8344367f5f6a7d9f3319 100644 >--- a/Source/WebCore/platform/cocoa/PlaybackSessionModel.h >+++ b/Source/WebCore/platform/cocoa/PlaybackSessionModel.h >@@ -30,6 +30,7 @@ > #include <wtf/Forward.h> > #include <wtf/Ref.h> > #include <wtf/Vector.h> >+#include <wtf/WeakPtr.h> > > namespace WebCore { > >@@ -39,8 +40,12 @@ struct MediaSelectionOption; > > class PlaybackSessionModel { > public: >- virtual ~PlaybackSessionModel() { }; >- virtual void addClient(PlaybackSessionModelClient&) = 0; >+ virtual ~PlaybackSessionModel() = default; >+ >+ void ref() { refPlaybackSessionModel(); } >+ void deref() { derefPlaybackSessionModel(); } >+ >+ virtual void addClient(WeakPtr<PlaybackSessionModelClient>&&) = 0; > virtual void removeClient(PlaybackSessionModelClient&) = 0; > > virtual void play() = 0; >@@ -84,6 +89,10 @@ public: > virtual bool isMuted() const = 0; > virtual double volume() const = 0; > virtual bool isPictureInPictureActive() const = 0; >+ >+private: >+ virtual void refPlaybackSessionModel() = 0; >+ virtual void derefPlaybackSessionModel() = 0; > }; > > class PlaybackSessionModelClient { >diff --git a/Source/WebCore/platform/cocoa/PlaybackSessionModelMediaElement.h b/Source/WebCore/platform/cocoa/PlaybackSessionModelMediaElement.h >index f5927dce035a7de7c0c6c9046e6d5b0204cac8d3..77f23157bf65337bd0ba5f185e5026d0397f6097 100644 >--- a/Source/WebCore/platform/cocoa/PlaybackSessionModelMediaElement.h >+++ b/Source/WebCore/platform/cocoa/PlaybackSessionModelMediaElement.h >@@ -30,9 +30,9 @@ > #include "EventListener.h" > #include "HTMLMediaElementEnums.h" > #include "PlaybackSessionModel.h" >-#include <wtf/HashSet.h> > #include <wtf/RefPtr.h> > #include <wtf/Vector.h> >+#include <wtf/WeakPtr.h> > > namespace WebCore { > >@@ -41,7 +41,10 @@ class HTMLMediaElement; > class TextTrack; > class PlaybackSessionInterface; > >-class PlaybackSessionModelMediaElement final : public PlaybackSessionModel, public EventListener { >+class PlaybackSessionModelMediaElement final >+ : public RefCounted<PlaybackSessionModelMediaElement> >+ , public CanMakeWeakPtr<PlaybackSessionModelMediaElement> >+ , public PlaybackSessionModel { > public: > static Ref<PlaybackSessionModelMediaElement> create() > { >@@ -51,11 +54,9 @@ public: > WEBCORE_EXPORT void setMediaElement(HTMLMediaElement*); > HTMLMediaElement* mediaElement() const { return m_mediaElement.get(); } > >- WEBCORE_EXPORT void handleEvent(WebCore::ScriptExecutionContext&, WebCore::Event&) final; > void updateForEventName(const WTF::AtomicString&); >- bool operator==(const EventListener& rhs) const final { return static_cast<const WebCore::EventListener*>(this) == &rhs; } > >- WEBCORE_EXPORT void addClient(PlaybackSessionModelClient&); >+ WEBCORE_EXPORT void addClient(WeakPtr<PlaybackSessionModelClient>&&); > WEBCORE_EXPORT void removeClient(PlaybackSessionModelClient&); > WEBCORE_EXPORT void play() final; > WEBCORE_EXPORT void pause() final; >@@ -96,19 +97,27 @@ public: > double volume() const final; > bool isPictureInPictureActive() const final; > >+ using RefCounted::ref; >+ using RefCounted::deref; >+ > protected: > WEBCORE_EXPORT PlaybackSessionModelMediaElement(); > > private: >+ void refPlaybackSessionModel() final { ref(); } >+ void derefPlaybackSessionModel() final { deref(); } >+ > void progressEventTimerFired(); > static const Vector<WTF::AtomicString>& observedEventNames(); > const WTF::AtomicString& eventNameAll(); > >+ class MediaElementEventListener; >+ > RefPtr<HTMLMediaElement> m_mediaElement; >- bool m_isListening { false }; >- HashSet<PlaybackSessionModelClient*> m_clients; >+ Vector<WeakPtr<PlaybackSessionModelClient>> m_clients; > Vector<RefPtr<TextTrack>> m_legibleTracksForMenu; > Vector<RefPtr<AudioTrack>> m_audioTracksForMenu; >+ Ref<MediaElementEventListener> m_eventListener; > > double playbackStartedTime() const; > void updateMediaSelectionOptions(); >diff --git a/Source/WebCore/platform/cocoa/PlaybackSessionModelMediaElement.mm b/Source/WebCore/platform/cocoa/PlaybackSessionModelMediaElement.mm >index a11b70c1ed296ce0cd1ec1798df61d17fd0273d7..c407e7a60f435085f9e7dd68d7bfd8c9c5198c9f 100644 >--- a/Source/WebCore/platform/cocoa/PlaybackSessionModelMediaElement.mm >+++ b/Source/WebCore/platform/cocoa/PlaybackSessionModelMediaElement.mm >@@ -47,13 +47,33 @@ > > namespace WebCore { > >+class PlaybackSessionModelMediaElement::MediaElementEventListener final : public EventListener { >+public: >+ MediaElementEventListener(WeakPtr<PlaybackSessionModelMediaElement>&& parent) >+ : EventListener(CPPEventListenerType) >+ , m_parent(WTFMove(parent)) >+ { >+ } >+private: >+ void handleEvent(WebCore::ScriptExecutionContext&, WebCore::Event& event) final >+ { >+ if (m_parent) >+ m_parent->updateForEventName(event.type()); >+ } >+ bool operator==(const EventListener& rhs) const final { return static_cast<const WebCore::EventListener*>(this) == &rhs; } >+ >+ WeakPtr<PlaybackSessionModelMediaElement> m_parent; >+}; >+ > PlaybackSessionModelMediaElement::PlaybackSessionModelMediaElement() >- : EventListener(EventListener::CPPEventListenerType) >+ : m_eventListener(adoptRef(*new MediaElementEventListener(makeWeakPtr(*this)))) > { > } > > PlaybackSessionModelMediaElement::~PlaybackSessionModelMediaElement() > { >+ m_clients.clear(); >+ setMediaElement(nullptr); > } > > void PlaybackSessionModelMediaElement::setMediaElement(HTMLMediaElement* mediaElement) >@@ -63,51 +83,43 @@ void PlaybackSessionModelMediaElement::setMediaElement(HTMLMediaElement* mediaEl > > auto& events = eventNames(); > >- if (m_mediaElement && m_isListening) { >+ if (m_mediaElement) { > for (auto& eventName : observedEventNames()) >- m_mediaElement->removeEventListener(eventName, *this, false); >+ m_mediaElement->removeEventListener(eventName, m_eventListener.copyRef(), false); > if (auto* audioTracks = m_mediaElement->audioTracks()) { >- audioTracks->removeEventListener(events.addtrackEvent, *this, false); >- audioTracks->removeEventListener(events.changeEvent, *this, false); >- audioTracks->removeEventListener(events.removetrackEvent, *this, false); >+ audioTracks->removeEventListener(events.addtrackEvent, m_eventListener.copyRef(), false); >+ audioTracks->removeEventListener(events.changeEvent, m_eventListener.copyRef(), false); >+ audioTracks->removeEventListener(events.removetrackEvent, m_eventListener.copyRef(), false); > } > > if (auto* textTracks = m_mediaElement->audioTracks()) { >- textTracks->removeEventListener(events.addtrackEvent, *this, false); >- textTracks->removeEventListener(events.changeEvent, *this, false); >- textTracks->removeEventListener(events.removetrackEvent, *this, false); >+ textTracks->removeEventListener(events.addtrackEvent, m_eventListener.copyRef(), false); >+ textTracks->removeEventListener(events.changeEvent, m_eventListener.copyRef(), false); >+ textTracks->removeEventListener(events.removetrackEvent, m_eventListener.copyRef(), false); > } >- } >- m_isListening = false; >- >- if (m_mediaElement) > m_mediaElement->resetPlaybackSessionState(); >+ } > > m_mediaElement = mediaElement; > > if (m_mediaElement) { > for (auto& eventName : observedEventNames()) >- m_mediaElement->addEventListener(eventName, *this, false); >+ m_mediaElement->addEventListener(eventName, m_eventListener.copyRef(), false); > > auto& audioTracks = m_mediaElement->ensureAudioTracks(); >- audioTracks.addEventListener(events.addtrackEvent, *this, false); >- audioTracks.addEventListener(events.changeEvent, *this, false); >- audioTracks.addEventListener(events.removetrackEvent, *this, false); >+ audioTracks.addEventListener(events.addtrackEvent, m_eventListener.copyRef(), false); >+ audioTracks.addEventListener(events.changeEvent, m_eventListener.copyRef(), false); >+ audioTracks.addEventListener(events.removetrackEvent, m_eventListener.copyRef(), false); > > auto& textTracks = m_mediaElement->ensureTextTracks(); >- textTracks.addEventListener(events.addtrackEvent, *this, false); >- textTracks.addEventListener(events.changeEvent, *this, false); >- textTracks.addEventListener(events.removetrackEvent, *this, false); >+ textTracks.addEventListener(events.addtrackEvent, m_eventListener.copyRef(), false); >+ textTracks.addEventListener(events.changeEvent, m_eventListener.copyRef(), false); >+ textTracks.addEventListener(events.removetrackEvent, m_eventListener.copyRef(), false); > } > > updateForEventName(eventNameAll()); > } > >-void PlaybackSessionModelMediaElement::handleEvent(WebCore::ScriptExecutionContext&, WebCore::Event& event) >-{ >- updateForEventName(event.type()); >-} >- > void PlaybackSessionModelMediaElement::updateForEventName(const WTF::AtomicString& eventName) > { > if (m_clients.isEmpty()) >@@ -205,16 +217,16 @@ void PlaybackSessionModelMediaElement::updateForEventName(const WTF::AtomicStrin > } > } > } >-void PlaybackSessionModelMediaElement::addClient(PlaybackSessionModelClient& client) >+void PlaybackSessionModelMediaElement::addClient(WeakPtr<PlaybackSessionModelClient>&& client) > { >- ASSERT(!m_clients.contains(&client)); >- m_clients.add(&client); >+ ASSERT(!m_clients.contains(client)); >+ m_clients.append(client); > } > > void PlaybackSessionModelMediaElement::removeClient(PlaybackSessionModelClient& client) > { > ASSERT(m_clients.contains(&client)); >- m_clients.remove(&client); >+ m_clients.removeAll(&client); > } > > void PlaybackSessionModelMediaElement::play() >diff --git a/Source/WebCore/platform/cocoa/VideoFullscreenChangeObserver.h b/Source/WebCore/platform/cocoa/VideoFullscreenChangeObserver.h >index 4eb0580c96139dd47e75812e619bc905d6b76ed5..4990813a3909e602cf5566a897f8707194dd6b9b 100644 >--- a/Source/WebCore/platform/cocoa/VideoFullscreenChangeObserver.h >+++ b/Source/WebCore/platform/cocoa/VideoFullscreenChangeObserver.h >@@ -32,7 +32,7 @@ namespace WebCore { > > class VideoFullscreenChangeObserver { > public: >- virtual ~VideoFullscreenChangeObserver() { }; >+ virtual ~VideoFullscreenChangeObserver() = default; > virtual void requestUpdateInlineRect() = 0; > virtual void requestVideoContentLayer() = 0; > virtual void returnVideoContentLayer() = 0; >diff --git a/Source/WebCore/platform/cocoa/VideoFullscreenModel.h b/Source/WebCore/platform/cocoa/VideoFullscreenModel.h >index ce513541642ffba32f7db6b8037b60b8007d1eed..6d1b7e98a9e35b67a2c371cba60afc388b6ab5be 100644 >--- a/Source/WebCore/platform/cocoa/VideoFullscreenModel.h >+++ b/Source/WebCore/platform/cocoa/VideoFullscreenModel.h >@@ -30,7 +30,7 @@ > > #include "FloatRect.h" > #include "HTMLMediaElementEnums.h" >-#include "PlaybackSessionModel.h" >+#include <wtf/WeakPtr.h> > > #if PLATFORM(IOS) > OBJC_CLASS AVPlayerViewController; >@@ -43,8 +43,15 @@ class VideoFullscreenModelClient; > > class VideoFullscreenModel { > public: >- virtual ~VideoFullscreenModel() { }; >- virtual void addClient(VideoFullscreenModelClient&) = 0; >+ virtual ~VideoFullscreenModel() = default; >+ >+ void ref() { refVideoFullscreenModel(); } >+ void deref() { derefVideoFullscreenModel(); } >+ >+ virtual void refVideoFullscreenModel() = 0; >+ virtual void derefVideoFullscreenModel() = 0; >+ >+ virtual void addClient(WeakPtr<VideoFullscreenModelClient>&&) = 0; > virtual void removeClient(VideoFullscreenModelClient&)= 0; > > virtual void requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenMode, bool finishedWithMedia = false) = 0; >diff --git a/Source/WebCore/platform/cocoa/VideoFullscreenModelVideoElement.h b/Source/WebCore/platform/cocoa/VideoFullscreenModelVideoElement.h >index 037dd02b61d3b1a824b3f9c0ec161d599f310de7..af0dcb60c42c963398590b7685eac7682150c32a 100644 >--- a/Source/WebCore/platform/cocoa/VideoFullscreenModelVideoElement.h >+++ b/Source/WebCore/platform/cocoa/VideoFullscreenModelVideoElement.h >@@ -28,16 +28,15 @@ > > #if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) > >-#include "EventListener.h" > #include "FloatRect.h" > #include "HTMLMediaElementEnums.h" > #include "PlatformLayer.h" > #include "VideoFullscreenModel.h" > #include <wtf/Function.h> >-#include <wtf/HashSet.h> > #include <wtf/RefPtr.h> > #include <wtf/RetainPtr.h> > #include <wtf/Vector.h> >+#include <wtf/WeakPtr.h> > > namespace WebCore { > class AudioTrack; >@@ -45,7 +44,10 @@ class HTMLVideoElement; > class TextTrack; > class PlaybackSessionModelMediaElement; > >-class VideoFullscreenModelVideoElement : public VideoFullscreenModel, public EventListener { >+class VideoFullscreenModelVideoElement >+ : public RefCounted<VideoFullscreenModelVideoElement> >+ , public CanMakeWeakPtr<VideoFullscreenModelVideoElement> >+ , public VideoFullscreenModel { > public: > static RefPtr<VideoFullscreenModelVideoElement> create() > { >@@ -58,11 +60,9 @@ public: > WEBCORE_EXPORT void willExitFullscreen(); > WEBCORE_EXPORT void waitForPreparedForInlineThen(WTF::Function<void()>&& completionHandler = [] { }); > >- WEBCORE_EXPORT void handleEvent(WebCore::ScriptExecutionContext&, WebCore::Event&) override; > void updateForEventName(const WTF::AtomicString&); >- bool operator==(const EventListener& rhs) const override { return static_cast<const WebCore::EventListener*>(this) == &rhs; } > >- WEBCORE_EXPORT void addClient(VideoFullscreenModelClient&) override; >+ WEBCORE_EXPORT void addClient(WeakPtr<VideoFullscreenModelClient>&&) override; > WEBCORE_EXPORT void removeClient(VideoFullscreenModelClient&) override; > WEBCORE_EXPORT void requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenMode, bool finishedWithMedia = false) override; > WEBCORE_EXPORT void setVideoLayerFrame(FloatRect) override; >@@ -72,6 +72,8 @@ public: > FloatSize videoDimensions() const override { return m_videoDimensions; } > bool hasVideo() const override { return m_hasVideo; } > >+ using RefCounted::ref; >+ using RefCounted::deref; > > protected: > WEBCORE_EXPORT VideoFullscreenModelVideoElement(); >@@ -80,6 +82,8 @@ private: > void setHasVideo(bool); > void setVideoDimensions(const FloatSize&); > >+ void refVideoFullscreenModel() final { ref(); } >+ void derefVideoFullscreenModel() final { deref(); } > void willEnterPictureInPicture() override; > void didEnterPictureInPicture() override; > void failedToEnterPictureInPicture() override; >@@ -89,15 +93,17 @@ private: > static const Vector<WTF::AtomicString>& observedEventNames(); > const WTF::AtomicString& eventNameAll(); > >+ class MediaElementEventListener; >+ > RefPtr<HTMLVideoElement> m_videoElement; > RetainPtr<PlatformLayer> m_videoFullscreenLayer; >- bool m_isListening { false }; >- HashSet<VideoFullscreenModelClient*> m_clients; >+ Vector<WeakPtr<VideoFullscreenModelClient>> m_clients; > bool m_hasVideo { false }; > FloatSize m_videoDimensions; > FloatRect m_videoFrame; > Vector<RefPtr<TextTrack>> m_legibleTracksForMenu; > Vector<RefPtr<AudioTrack>> m_audioTracksForMenu; >+ Ref<MediaElementEventListener> m_eventListener; > }; > > } >diff --git a/Source/WebCore/platform/cocoa/VideoFullscreenModelVideoElement.mm b/Source/WebCore/platform/cocoa/VideoFullscreenModelVideoElement.mm >index c0a4fa5f0eb5af0f87f585dcca5d65706a7f504e..874cef4bae8f50c42c3f092434b1aa5522130e82 100644 >--- a/Source/WebCore/platform/cocoa/VideoFullscreenModelVideoElement.mm >+++ b/Source/WebCore/platform/cocoa/VideoFullscreenModelVideoElement.mm >@@ -47,8 +47,27 @@ > > using namespace WebCore; > >+ >+class VideoFullscreenModelVideoElement::MediaElementEventListener final : public EventListener { >+public: >+ MediaElementEventListener(WeakPtr<VideoFullscreenModelVideoElement>&& parent) >+ : EventListener(CPPEventListenerType) >+ , m_parent(WTFMove(parent)) >+ { >+ } >+private: >+ void handleEvent(WebCore::ScriptExecutionContext&, WebCore::Event& event) final >+ { >+ if (m_parent) >+ m_parent->updateForEventName(event.type()); >+ } >+ bool operator==(const EventListener& rhs) const final { return static_cast<const WebCore::EventListener*>(this) == &rhs; } >+ >+ WeakPtr<VideoFullscreenModelVideoElement> m_parent; >+}; >+ > VideoFullscreenModelVideoElement::VideoFullscreenModelVideoElement() >- : EventListener(EventListener::CPPEventListenerType) >+ : m_eventListener(adoptRef(*new MediaElementEventListener(makeWeakPtr(*this)))) > { > } > >@@ -64,28 +83,21 @@ void VideoFullscreenModelVideoElement::setVideoElement(HTMLVideoElement* videoEl > if (m_videoElement && m_videoElement->videoFullscreenLayer()) > m_videoElement->setVideoFullscreenLayer(nullptr); > >- if (m_videoElement && m_isListening) { >+ if (m_videoElement) { > for (auto& eventName : observedEventNames()) >- m_videoElement->removeEventListener(eventName, *this, false); >+ m_videoElement->removeEventListener(eventName, m_eventListener.copyRef(), false); > } >- m_isListening = false; > > m_videoElement = videoElement; > > if (m_videoElement) { > for (auto& eventName : observedEventNames()) >- m_videoElement->addEventListener(eventName, *this, false); >- m_isListening = true; >+ m_videoElement->addEventListener(eventName, m_eventListener.copyRef(), false); > } > > updateForEventName(eventNameAll()); > } > >-void VideoFullscreenModelVideoElement::handleEvent(WebCore::ScriptExecutionContext&, WebCore::Event& event) >-{ >- updateForEventName(event.type()); >-} >- > void VideoFullscreenModelVideoElement::updateForEventName(const WTF::AtomicString& eventName) > { > if (m_clients.isEmpty()) >@@ -195,16 +207,16 @@ void VideoFullscreenModelVideoElement::fullscreenModeChanged(HTMLMediaElementEnu > m_videoElement->fullscreenModeChanged(videoFullscreenMode); > } > >-void VideoFullscreenModelVideoElement::addClient(VideoFullscreenModelClient& client) >+void VideoFullscreenModelVideoElement::addClient(WeakPtr<VideoFullscreenModelClient>&& client) > { >- ASSERT(!m_clients.contains(&client)); >- m_clients.add(&client); >+ ASSERT(!m_clients.contains(client)); >+ m_clients.append(WTFMove(client)); > } > > void VideoFullscreenModelVideoElement::removeClient(VideoFullscreenModelClient& client) > { > ASSERT(m_clients.contains(&client)); >- m_clients.remove(&client); >+ m_clients.removeFirst(&client); > } > > bool VideoFullscreenModelVideoElement::isVisible() const >diff --git a/Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.h b/Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.h >index 85801915e0f019680df47c816c0bddb5b60bc393..1d6b6e1a0b6ab0480ed751b32ce2ba8fcee79d9f 100644 >--- a/Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.h >+++ b/Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.h >@@ -51,18 +51,19 @@ class IntRect; > class PlaybackSessionModel; > class WebPlaybackSessionChangeObserver; > >-class WEBCORE_EXPORT PlaybackSessionInterfaceAVKit >+class PlaybackSessionInterfaceAVKit > : public PlaybackSessionInterface > , public PlaybackSessionModelClient >- , public RefCounted<PlaybackSessionInterfaceAVKit> { >+ , public RefCounted<PlaybackSessionInterfaceAVKit> >+ , public CanMakeWeakPtr<PlaybackSessionInterfaceAVKit> { > > public: >- static Ref<PlaybackSessionInterfaceAVKit> create(PlaybackSessionModel& model) >+ static Ref<PlaybackSessionInterfaceAVKit> create(Ref<PlaybackSessionModel>&& model) > { >- return adoptRef(*new PlaybackSessionInterfaceAVKit(model)); >+ return adoptRef(*new PlaybackSessionInterfaceAVKit(WTFMove(model))); > } > virtual ~PlaybackSessionInterfaceAVKit(); >- PlaybackSessionModel* playbackSessionModel() const { return m_playbackSessionModel; } >+ PlaybackSessionModel& playbackSessionModel() const { return m_playbackSessionModel; } > > // PlaybackSessionInterface > WEBCORE_EXPORT void resetMediaState() override; >@@ -81,15 +82,13 @@ public: > WEBCORE_EXPORT void mutedChanged(bool) override; > WEBCORE_EXPORT void volumeChanged(double) override; > >- WEBCORE_EXPORT virtual void invalidate(); >- > WebAVPlayerController *playerController() const { return m_playerController.get(); } > > protected: >- WEBCORE_EXPORT PlaybackSessionInterfaceAVKit(PlaybackSessionModel&); >+ WEBCORE_EXPORT PlaybackSessionInterfaceAVKit(Ref<PlaybackSessionModel>&&); > > RetainPtr<WebAVPlayerController> m_playerController; >- PlaybackSessionModel* m_playbackSessionModel { nullptr }; >+ Ref<PlaybackSessionModel> m_playbackSessionModel; > }; > > } >diff --git a/Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.mm b/Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.mm >index 0a28548b7f5951619534432da9a0007ddb9ae864..ed3285b9e4de19f101d74a41600c35a3528947bb 100644 >--- a/Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.mm >+++ b/Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.mm >@@ -49,32 +49,30 @@ SOFT_LINK_CLASS_OPTIONAL(AVKit, AVValueTiming) > namespace WebCore { > using namespace PAL; > >-PlaybackSessionInterfaceAVKit::PlaybackSessionInterfaceAVKit(PlaybackSessionModel& model) >+PlaybackSessionInterfaceAVKit::PlaybackSessionInterfaceAVKit(Ref<PlaybackSessionModel>&& model) > : m_playerController(adoptNS([[WebAVPlayerController alloc] init])) >- , m_playbackSessionModel(&model) >+ , m_playbackSessionModel(WTFMove(model)) > { >- model.addClient(*this); >+ m_playbackSessionModel->addClient(makeWeakPtr(*this)); > [m_playerController setPlaybackSessionInterface:this]; >- [m_playerController setDelegate:&model]; > >- durationChanged(model.duration()); >- currentTimeChanged(model.currentTime(), [[NSProcessInfo processInfo] systemUptime]); >- bufferedTimeChanged(model.bufferedTime()); >- rateChanged(model.isPlaying(), model.playbackRate()); >- seekableRangesChanged(model.seekableRanges(), model.seekableTimeRangesLastModifiedTime(), model.liveUpdateInterval()); >- canPlayFastReverseChanged(model.canPlayFastReverse()); >- audioMediaSelectionOptionsChanged(model.audioMediaSelectionOptions(), model.audioMediaSelectedIndex()); >- legibleMediaSelectionOptionsChanged(model.legibleMediaSelectionOptions(), model.legibleMediaSelectedIndex()); >- externalPlaybackChanged(model.externalPlaybackEnabled(), model.externalPlaybackTargetType(), model.externalPlaybackLocalizedDeviceName()); >- wirelessVideoPlaybackDisabledChanged(model.wirelessVideoPlaybackDisabled()); >+ durationChanged(m_playbackSessionModel->duration()); >+ currentTimeChanged(m_playbackSessionModel->currentTime(), [[NSProcessInfo processInfo] systemUptime]); >+ bufferedTimeChanged(m_playbackSessionModel->bufferedTime()); >+ rateChanged(m_playbackSessionModel->isPlaying(), m_playbackSessionModel->playbackRate()); >+ seekableRangesChanged(m_playbackSessionModel->seekableRanges(), m_playbackSessionModel->seekableTimeRangesLastModifiedTime(), m_playbackSessionModel->liveUpdateInterval()); >+ canPlayFastReverseChanged(m_playbackSessionModel->canPlayFastReverse()); >+ audioMediaSelectionOptionsChanged(m_playbackSessionModel->audioMediaSelectionOptions(), m_playbackSessionModel->audioMediaSelectedIndex()); >+ legibleMediaSelectionOptionsChanged(m_playbackSessionModel->legibleMediaSelectionOptions(), m_playbackSessionModel->legibleMediaSelectedIndex()); >+ externalPlaybackChanged(m_playbackSessionModel->externalPlaybackEnabled(), m_playbackSessionModel->externalPlaybackTargetType(), m_playbackSessionModel->externalPlaybackLocalizedDeviceName()); >+ wirelessVideoPlaybackDisabledChanged(m_playbackSessionModel->wirelessVideoPlaybackDisabled()); > } > > PlaybackSessionInterfaceAVKit::~PlaybackSessionInterfaceAVKit() > { >+ m_playbackSessionModel->removeClient(*this); > [m_playerController setPlaybackSessionInterface:nullptr]; > [m_playerController setExternalPlaybackActive:false]; >- >- invalidate(); > } > > void PlaybackSessionInterfaceAVKit::resetMediaState() >@@ -206,16 +204,6 @@ void PlaybackSessionInterfaceAVKit::volumeChanged(double volume) > [m_playerController volumeChanged:volume]; > } > >-void PlaybackSessionInterfaceAVKit::invalidate() >-{ >- if (!m_playbackSessionModel) >- return; >- >- [m_playerController setDelegate:nullptr]; >- m_playbackSessionModel->removeClient(*this); >- m_playbackSessionModel = nullptr; >-} >- > } > > #endif // HAVE(AVKIT) >diff --git a/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h b/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h >index c6d2ead9542cf843420ce953cd3f24f9272bdec6..ca081418d580e38741d4f2a7d832845c0e04ff68 100644 >--- a/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h >+++ b/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h >@@ -40,6 +40,7 @@ > #include <wtf/RefPtr.h> > #include <wtf/RetainPtr.h> > #include <wtf/RunLoop.h> >+#include <wtf/WeakPtr.h> > > OBJC_CLASS UIViewController; > OBJC_CLASS UIWindow; >@@ -64,12 +65,11 @@ class VideoFullscreenInterfaceAVKit final > , public ThreadSafeRefCounted<VideoFullscreenInterfaceAVKit> { > > public: >- WEBCORE_EXPORT static Ref<VideoFullscreenInterfaceAVKit> create(PlaybackSessionInterfaceAVKit&); >+ WEBCORE_EXPORT static Ref<VideoFullscreenInterfaceAVKit> create(Ref<PlaybackSessionInterfaceAVKit>&&, Ref<VideoFullscreenModel>&&); > virtual ~VideoFullscreenInterfaceAVKit(); >- WEBCORE_EXPORT void setVideoFullscreenModel(VideoFullscreenModel*); >- WEBCORE_EXPORT void setVideoFullscreenChangeObserver(VideoFullscreenChangeObserver*); >+ WEBCORE_EXPORT void setVideoFullscreenChangeObserver(WeakPtr<VideoFullscreenChangeObserver>); > PlaybackSessionInterfaceAVKit& playbackSessionInterface() const { return m_playbackSessionInterface.get(); } >- PlaybackSessionModel* playbackSessionModel() const { return m_playbackSessionInterface->playbackSessionModel(); } >+ PlaybackSessionModel& playbackSessionModel() const { return m_playbackSessionInterface->playbackSessionModel(); } > > // VideoFullscreenModelClient > WEBCORE_EXPORT void hasVideoChanged(bool) final; >@@ -131,7 +131,7 @@ public: > Mode m_targetMode; > #endif > >- VideoFullscreenModel* videoFullscreenModel() const { return m_videoFullscreenModel; } >+ VideoFullscreenModel& videoFullscreenModel() const { return m_videoFullscreenModel; } > bool shouldExitFullscreenWithReason(ExitFullScreenReason); > HTMLMediaElementEnums::VideoFullscreenMode mode() const { return m_currentMode.mode(); } > bool allowsPictureInPicturePlayback() const { return m_allowsPictureInPicturePlayback; } >@@ -164,7 +164,7 @@ public: > #endif > > protected: >- WEBCORE_EXPORT VideoFullscreenInterfaceAVKit(PlaybackSessionInterfaceAVKit&); >+ WEBCORE_EXPORT VideoFullscreenInterfaceAVKit(Ref<PlaybackSessionInterfaceAVKit>&&, Ref<VideoFullscreenModel>&&); > > #if ENABLE(FULLSCREEN_API) > void doSetup(); >@@ -180,10 +180,10 @@ protected: > WebAVPlayerController *playerController() const; > > Ref<PlaybackSessionInterfaceAVKit> m_playbackSessionInterface; >+ Ref<VideoFullscreenModel> m_videoFullscreenModel; > RetainPtr<WebAVPlayerViewControllerDelegate> m_playerViewControllerDelegate; > RetainPtr<WebAVPlayerViewController> m_playerViewController; >- VideoFullscreenModel* m_videoFullscreenModel { nullptr }; >- VideoFullscreenChangeObserver* m_fullscreenChangeObserver { nullptr }; >+ WeakPtr<VideoFullscreenChangeObserver> m_fullscreenChangeObserver; > > // These are only used when fullscreen is presented in a separate window. > RetainPtr<UIWindow> m_window; >diff --git a/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm b/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm >index 5cc320e19dad39c009c73368a5871c86093e8b7d..c558bffc83abcb43f376ae59e826ffb89125d09a 100644 >--- a/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm >+++ b/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm >@@ -289,8 +289,7 @@ - (void)layoutSublayers > } else if ([getAVLayerVideoGravityResizeAspectFill() isEqualToString:self.videoGravity]) { > sourceVideoFrame = smallestRectWithAspectRatioAroundRect(videoAspectRatio, self.modelVideoLayerFrame); > self.modelVideoLayerFrame = CGRectMake(0, 0, sourceVideoFrame.width(), sourceVideoFrame.height()); >- if (auto* model = _fullscreenInterface->videoFullscreenModel()) >- model->setVideoLayerFrame(self.modelVideoLayerFrame); >+ _fullscreenInterface->videoFullscreenModel().setVideoLayerFrame(self.modelVideoLayerFrame); > targetVideoFrame = smallestRectWithAspectRatioAroundRect(videoAspectRatio, self.bounds); > } else > ASSERT_NOT_REACHED(); >@@ -325,8 +324,7 @@ - (void)resolveBounds > > if (!CGRectEqualToRect(self.modelVideoLayerFrame, [self bounds])) { > self.modelVideoLayerFrame = [self bounds]; >- if (auto* model = _fullscreenInterface->videoFullscreenModel()) >- model->setVideoLayerFrame(self.modelVideoLayerFrame); >+ _fullscreenInterface->videoFullscreenModel().setVideoLayerFrame(self.modelVideoLayerFrame); > } > [(UIView *)[_videoSublayer delegate] setTransform:CGAffineTransformIdentity]; > >@@ -350,8 +348,7 @@ - (void)setVideoGravity:(NSString *)videoGravity > else > ASSERT_NOT_REACHED(); > >- if (auto* model = _fullscreenInterface->videoFullscreenModel()) >- model->setVideoLayerGravity(gravity); >+ _fullscreenInterface->videoFullscreenModel().setVideoLayerGravity(gravity); > } > > - (NSString *)videoGravity >@@ -725,15 +722,16 @@ - (void)removeFromParentViewController > } > @end > >-Ref<VideoFullscreenInterfaceAVKit> VideoFullscreenInterfaceAVKit::create(PlaybackSessionInterfaceAVKit& playbackSessionInterface) >+Ref<VideoFullscreenInterfaceAVKit> VideoFullscreenInterfaceAVKit::create(Ref<PlaybackSessionInterfaceAVKit>&& playbackSessionInterface, Ref<VideoFullscreenModel>&& videoFullscreenModel) > { >- Ref<VideoFullscreenInterfaceAVKit> interface = adoptRef(*new VideoFullscreenInterfaceAVKit(playbackSessionInterface)); >+ Ref<VideoFullscreenInterfaceAVKit> interface = adoptRef(*new VideoFullscreenInterfaceAVKit(WTFMove(playbackSessionInterface), WTFMove(videoFullscreenModel))); > [interface->m_playerViewControllerDelegate setFullscreenInterface:interface.ptr()]; > return interface; > } > >-VideoFullscreenInterfaceAVKit::VideoFullscreenInterfaceAVKit(PlaybackSessionInterfaceAVKit& playbackSessionInterface) >- : m_playbackSessionInterface(playbackSessionInterface) >+VideoFullscreenInterfaceAVKit::VideoFullscreenInterfaceAVKit(Ref<PlaybackSessionInterfaceAVKit>&& playbackSessionInterface, Ref<VideoFullscreenModel>&& videoFullscreenModel) >+ : m_playbackSessionInterface(WTFMove(playbackSessionInterface)) >+ , m_videoFullscreenModel(WTFMove(videoFullscreenModel)) > , m_playerViewControllerDelegate(adoptNS([[WebAVPlayerViewControllerDelegate alloc] init])) > , m_watchdogTimer(RunLoop::main(), this, &VideoFullscreenInterfaceAVKit::watchdogTimerFired) > { >@@ -744,8 +742,7 @@ VideoFullscreenInterfaceAVKit::~VideoFullscreenInterfaceAVKit() > WebAVPlayerController* playerController = this->playerController(); > if (playerController && playerController.externalPlaybackActive) > externalPlaybackChanged(false, PlaybackSessionModel::TargetTypeNone, ""); >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->removeClient(*this); >+ videoFullscreenModel().removeClient(*this); > } > > WebAVPlayerController *VideoFullscreenInterfaceAVKit::playerController() const >@@ -753,21 +750,7 @@ WebAVPlayerController *VideoFullscreenInterfaceAVKit::playerController() const > return m_playbackSessionInterface->playerController(); > } > >-void VideoFullscreenInterfaceAVKit::setVideoFullscreenModel(VideoFullscreenModel* model) >-{ >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->removeClient(*this); >- >- m_videoFullscreenModel = model; >- >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->addClient(*this); >- >- hasVideoChanged(m_videoFullscreenModel ? m_videoFullscreenModel->hasVideo() : false); >- videoDimensionsChanged(m_videoFullscreenModel ? m_videoFullscreenModel->videoDimensions() : FloatSize()); >-} >- >-void VideoFullscreenInterfaceAVKit::setVideoFullscreenChangeObserver(VideoFullscreenChangeObserver* observer) >+void VideoFullscreenInterfaceAVKit::setVideoFullscreenChangeObserver(WeakPtr<VideoFullscreenChangeObserver> observer) > { > m_fullscreenChangeObserver = observer; > } >@@ -807,7 +790,7 @@ bool VideoFullscreenInterfaceAVKit::pictureInPictureWasStartedWhenEnteringBackgr > void VideoFullscreenInterfaceAVKit::applicationDidBecomeActive() > { > LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::applicationDidBecomeActive(%p)", this); >- if (m_shouldReturnToFullscreenAfterEnteringForeground && m_videoFullscreenModel && m_videoFullscreenModel->isVisible()) { >+ if (m_shouldReturnToFullscreenAfterEnteringForeground && videoFullscreenModel().isVisible()) { > [m_playerViewController stopPictureInPicture]; > return; > } >@@ -884,7 +867,7 @@ void VideoFullscreenInterfaceAVKit::setupFullscreen(UIView& videoView, const Int > [playerController() setPictureInPicturePossible:m_allowsPictureInPicturePlayback]; > > #if PLATFORM(WATCHOS) >- m_viewController = videoFullscreenModel()->createVideoFullscreenViewController(m_playerViewController.get().avPlayerViewController); >+ m_viewController = videoFullscreenModel().createVideoFullscreenViewController(m_playerViewController.get().avPlayerViewController); > #endif > > if (m_viewController) { >@@ -949,7 +932,7 @@ static UIViewController *fallbackViewController(UIView *view) > > UIViewController *VideoFullscreenInterfaceAVKit::presentingViewController() > { >- auto *controller = videoFullscreenModel()->presentingViewController(); >+ auto *controller = videoFullscreenModel().presentingViewController(); > if (!controller) > controller = fallbackViewController(m_parentView.get()); > >@@ -1079,7 +1062,6 @@ void VideoFullscreenInterfaceAVKit::cleanupFullscreen() > > void VideoFullscreenInterfaceAVKit::invalidate() > { >- m_videoFullscreenModel = nil; > m_fullscreenChangeObserver = nil; > > cleanupFullscreen(); >@@ -1098,9 +1080,9 @@ void VideoFullscreenInterfaceAVKit::requestHideAndExitFullscreen() > [m_window setHidden:YES]; > [[m_playerViewController view] setHidden:YES]; > >- if (playbackSessionModel() && m_videoFullscreenModel && !m_exitRequested) { >- playbackSessionModel()->pause(); >- m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone); >+ if (!m_exitRequested) { >+ playbackSessionModel().pause(); >+ videoFullscreenModel().requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone); > } > } > >@@ -1120,7 +1102,7 @@ void VideoFullscreenInterfaceAVKit::preparedToExitFullscreen() > return; > > m_waitingForPreparedToExit = false; >- m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone, true); >+ videoFullscreenModel().requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone, true); > } > > bool VideoFullscreenInterfaceAVKit::mayAutomaticallyShowVideoPictureInPicture() const >@@ -1139,8 +1121,7 @@ void VideoFullscreenInterfaceAVKit::willStartPictureInPicture() > { > LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::willStartPictureInPicture(%p)", this); > setMode(HTMLMediaElementEnums::VideoFullscreenModePictureInPicture); >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->willEnterPictureInPicture(); >+ videoFullscreenModel().willEnterPictureInPicture(); > } > > void VideoFullscreenInterfaceAVKit::didStartPictureInPicture() >@@ -1166,8 +1147,7 @@ void VideoFullscreenInterfaceAVKit::didStartPictureInPicture() > > if (m_fullscreenChangeObserver) > m_fullscreenChangeObserver->didEnterFullscreen(); >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->didEnterPictureInPicture(); >+ videoFullscreenModel().didEnterPictureInPicture(); > } > > void VideoFullscreenInterfaceAVKit::failedToStartPictureInPicture() >@@ -1182,11 +1162,8 @@ void VideoFullscreenInterfaceAVKit::failedToStartPictureInPicture() > > if (m_fullscreenChangeObserver) > m_fullscreenChangeObserver->didEnterFullscreen(); >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->failedToEnterPictureInPicture(); >- >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone); >+ videoFullscreenModel().failedToEnterPictureInPicture(); >+ videoFullscreenModel().requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone); > } > > void VideoFullscreenInterfaceAVKit::willStopPictureInPicture() >@@ -1202,10 +1179,8 @@ void VideoFullscreenInterfaceAVKit::willStopPictureInPicture() > [m_window setHidden:NO]; > [[m_playerViewController view] setHidden:NO]; > >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone); >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->willExitPictureInPicture(); >+ videoFullscreenModel().requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone); >+ videoFullscreenModel().willExitPictureInPicture(); > } > > void VideoFullscreenInterfaceAVKit::didStopPictureInPicture() >@@ -1228,8 +1203,7 @@ void VideoFullscreenInterfaceAVKit::didStopPictureInPicture() > > if (m_fullscreenChangeObserver) > m_fullscreenChangeObserver->didExitFullscreen(); >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->didExitPictureInPicture(); >+ videoFullscreenModel().didExitPictureInPicture(); > } > > void VideoFullscreenInterfaceAVKit::prepareForPictureInPictureStopWithCompletionHandler(void (^completionHandler)(BOOL restored)) >@@ -1266,9 +1240,6 @@ void VideoFullscreenInterfaceAVKit::prepareForPictureInPictureStopWithCompletion > > bool VideoFullscreenInterfaceAVKit::shouldExitFullscreenWithReason(VideoFullscreenInterfaceAVKit::ExitFullScreenReason reason) > { >- if (!m_videoFullscreenModel) >- return true; >- > if (reason == ExitFullScreenReason::PictureInPictureStarted) { > if (pictureInPictureWasStartedWhenEnteringBackground()) > return false; >@@ -1278,8 +1249,8 @@ bool VideoFullscreenInterfaceAVKit::shouldExitFullscreenWithReason(VideoFullscre > return true; > } > >- if (playbackSessionModel() && (reason == ExitFullScreenReason::DoneButtonTapped || reason == ExitFullScreenReason::RemoteControlStopEventReceived)) >- playbackSessionModel()->pause(); >+ if (reason == ExitFullScreenReason::DoneButtonTapped || reason == ExitFullScreenReason::RemoteControlStopEventReceived) >+ playbackSessionModel().pause(); > > if (!m_watchdogTimer.isActive() && !ignoreWatchdogForDebugging) > m_watchdogTimer.startOneShot(defaultWatchdogTimerInterval); >@@ -1293,7 +1264,7 @@ bool VideoFullscreenInterfaceAVKit::shouldExitFullscreenWithReason(VideoFullscre > #endif > > BOOL finished = reason == ExitFullScreenReason::DoneButtonTapped || reason == ExitFullScreenReason::PinchGestureHandled; >- m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone, finished); >+ videoFullscreenModel().requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone, finished); > > return false; > } >@@ -1387,7 +1358,6 @@ void VideoFullscreenInterfaceAVKit::cleanupFullscreen() > > void VideoFullscreenInterfaceAVKit::invalidate() > { >- m_videoFullscreenModel = nil; > m_fullscreenChangeObserver = nil; > > cleanupFullscreen(); >@@ -1403,10 +1373,8 @@ void VideoFullscreenInterfaceAVKit::requestHideAndExitFullscreen() > [m_window setHidden:YES]; > [[m_playerViewController view] setHidden:YES]; > >- if (playbackSessionModel() && m_videoFullscreenModel) { >- playbackSessionModel()->pause(); >- m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone); >- } >+ playbackSessionModel().pause(); >+ videoFullscreenModel().requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone); > } > > void VideoFullscreenInterfaceAVKit::preparedToReturnToInline(bool visible, const IntRect& inlineRect) >@@ -1445,8 +1413,7 @@ void VideoFullscreenInterfaceAVKit::willStartPictureInPicture() > > if (!m_hasVideoContentLayer) > m_fullscreenChangeObserver->requestVideoContentLayer(); >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->willEnterPictureInPicture(); >+ videoFullscreenModel().willEnterPictureInPicture(); > } > > void VideoFullscreenInterfaceAVKit::didStartPictureInPicture() >@@ -1466,8 +1433,7 @@ void VideoFullscreenInterfaceAVKit::didStartPictureInPicture() > [[m_playerViewController view] setHidden:YES]; > } > >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->didEnterPictureInPicture(); >+ videoFullscreenModel().didEnterPictureInPicture(); > > if (m_enterFullscreenNeedsEnterPictureInPicture) > doEnterFullscreen(); >@@ -1485,11 +1451,8 @@ void VideoFullscreenInterfaceAVKit::failedToStartPictureInPicture() > if (m_fullscreenChangeObserver) > m_fullscreenChangeObserver->didEnterFullscreen(); > >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->failedToEnterPictureInPicture(); >- >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone); >+ videoFullscreenModel().failedToEnterPictureInPicture(); >+ videoFullscreenModel().requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone); > } > > void VideoFullscreenInterfaceAVKit::willStopPictureInPicture() >@@ -1504,8 +1467,7 @@ void VideoFullscreenInterfaceAVKit::willStopPictureInPicture() > [m_window setHidden:NO]; > [[m_playerViewController view] setHidden:NO]; > >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->willExitPictureInPicture(); >+ videoFullscreenModel().willExitPictureInPicture(); > } > > void VideoFullscreenInterfaceAVKit::didStopPictureInPicture() >@@ -1525,13 +1487,11 @@ void VideoFullscreenInterfaceAVKit::didStopPictureInPicture() > [m_playerLayerView setBackgroundColor:clearUIColor()]; > [[m_playerViewController view] setBackgroundColor:clearUIColor()]; > >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone); >+ videoFullscreenModel().requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone); > > clearMode(HTMLMediaElementEnums::VideoFullscreenModePictureInPicture); > >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->didExitPictureInPicture(); >+ videoFullscreenModel().didExitPictureInPicture(); > > if (m_enterFullscreenNeedsExitPictureInPicture) > doEnterFullscreen(); >@@ -1567,17 +1527,14 @@ void VideoFullscreenInterfaceAVKit::prepareForPictureInPictureStopWithCompletion > > bool VideoFullscreenInterfaceAVKit::shouldExitFullscreenWithReason(VideoFullscreenInterfaceAVKit::ExitFullScreenReason reason) > { >- if (!m_videoFullscreenModel) >- return true; >- > if (reason == ExitFullScreenReason::PictureInPictureStarted) > return false; > >- if (playbackSessionModel() && (reason == ExitFullScreenReason::DoneButtonTapped || reason == ExitFullScreenReason::RemoteControlStopEventReceived)) >- playbackSessionModel()->pause(); >+ if (reason == ExitFullScreenReason::DoneButtonTapped || reason == ExitFullScreenReason::RemoteControlStopEventReceived) >+ playbackSessionModel().pause(); > > BOOL finished = reason == ExitFullScreenReason::DoneButtonTapped || reason == ExitFullScreenReason::PinchGestureHandled; >- m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone, finished); >+ videoFullscreenModel().requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone, finished); > > if (!m_watchdogTimer.isActive() && !ignoreWatchdogForDebugging) > m_watchdogTimer.startOneShot(defaultWatchdogTimerInterval); >@@ -1672,8 +1629,7 @@ void VideoFullscreenInterfaceAVKit::doSetup() > [playerLayer setModelVideoLayerFrame:modelVideoLayerFrame]; > [playerLayer setVideoDimensions:[playerController() contentDimensions]]; > playerLayer.fullscreenInterface = this; >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->setVideoLayerFrame(modelVideoLayerFrame); >+ videoFullscreenModel().setVideoLayerFrame(modelVideoLayerFrame); > > if (!m_playerViewController) > m_playerViewController = adoptNS([[WebAVPlayerViewController alloc] initWithFullscreenInterface:this]); >@@ -1685,7 +1641,7 @@ void VideoFullscreenInterfaceAVKit::doSetup() > [playerController() setPictureInPicturePossible:m_allowsPictureInPicturePlayback]; > > #if PLATFORM(WATCHOS) >- m_viewController = videoFullscreenModel()->createVideoFullscreenViewController(m_playerViewController.get().avPlayerViewController); >+ m_viewController = videoFullscreenModel().createVideoFullscreenViewController(m_playerViewController.get().avPlayerViewController); > #endif > > if (m_viewController) { >@@ -1892,8 +1848,7 @@ void VideoFullscreenInterfaceAVKit::setMode(HTMLMediaElementEnums::VideoFullscre > return; > > m_currentMode.setMode(mode); >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->fullscreenModeChanged(m_currentMode.mode()); >+ videoFullscreenModel().fullscreenModeChanged(m_currentMode.mode()); > } > > void VideoFullscreenInterfaceAVKit::clearMode(HTMLMediaElementEnums::VideoFullscreenMode mode) >@@ -1902,8 +1857,7 @@ void VideoFullscreenInterfaceAVKit::clearMode(HTMLMediaElementEnums::VideoFullsc > return; > > m_currentMode.clearMode(mode); >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->fullscreenModeChanged(m_currentMode.mode()); >+ videoFullscreenModel().fullscreenModeChanged(m_currentMode.mode()); > } > > bool VideoFullscreenInterfaceAVKit::isPlayingVideoInEnhancedFullscreen() const >diff --git a/Source/WebCore/platform/ios/WebAVPlayerController.h b/Source/WebCore/platform/ios/WebAVPlayerController.h >index a45346cddc0f475a91a3897b5aa263b7f81c7225..1e78ab06fe4b47b13d6030501a453412d2c26862 100644 >--- a/Source/WebCore/platform/ios/WebAVPlayerController.h >+++ b/Source/WebCore/platform/ios/WebAVPlayerController.h >@@ -26,6 +26,7 @@ > #if PLATFORM(IOS) && HAVE(AVKIT) > > #import <pal/spi/cocoa/AVKitSPI.h> >+#import <wtf/WeakPtr.h> > > namespace WebCore { > class PlaybackSessionModel; >@@ -39,13 +40,14 @@ class PlaybackSessionInterfaceAVKit; > @interface WebAVPlayerController : NSObject { > WebAVMediaSelectionOption *_currentAudioMediaSelectionOption; > WebAVMediaSelectionOption *_currentLegibleMediaSelectionOption; >+ RefPtr<WebCore::PlaybackSessionInterfaceAVKit> _playbackSessionInterface; > BOOL _pictureInPictureInterrupted; > BOOL _muted; > } > > @property (retain) AVPlayerController* playerControllerProxy; >-@property (assign) WebCore::PlaybackSessionModel* delegate; >-@property (assign) WebCore::PlaybackSessionInterfaceAVKit* playbackSessionInterface; >+@property (readonly) WebCore::PlaybackSessionModel* delegate; >+@property WebCore::PlaybackSessionInterfaceAVKit* playbackSessionInterface; > > @property (readonly) BOOL canScanForward; > @property BOOL canScanBackward; >diff --git a/Source/WebCore/platform/ios/WebAVPlayerController.mm b/Source/WebCore/platform/ios/WebAVPlayerController.mm >index 84814233e8d4f84e3da5374574fb1ad53e7e94bd..66e20319a1cf39038cf15d8ba4f21e0897d2308d 100644 >--- a/Source/WebCore/platform/ios/WebAVPlayerController.mm >+++ b/Source/WebCore/platform/ios/WebAVPlayerController.mm >@@ -95,6 +95,23 @@ - (void)dealloc > [super dealloc]; > } > >+@dynamic delegate; >+- (WebCore::PlaybackSessionModel*)delegate >+{ >+ return _playbackSessionInterface ? &_playbackSessionInterface->playbackSessionModel() : nullptr; >+} >+ >+@dynamic playbackSessionInterface; >+- (WebCore::PlaybackSessionInterfaceAVKit*)playbackSessionInterface >+{ >+ return _playbackSessionInterface.get(); >+} >+ >+- (void)setPlaybackSessionInterface:(WebCore::PlaybackSessionInterfaceAVKit*)playbackSessionInterface >+{ >+ _playbackSessionInterface = playbackSessionInterface; >+} >+ > - (AVPlayer *)player > { > return nil; >diff --git a/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm b/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm >index 3efbb17cfa649d31c5088035e0adfe0425299588..96fa026f543ee59406db97554347ed21c49777bd 100644 >--- a/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm >+++ b/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm >@@ -99,11 +99,12 @@ -(void)didFinishFullscreen:(VideoFullscreenControllerContext*)context; > @end > > class VideoFullscreenControllerContext final >- : private VideoFullscreenModel >- , private VideoFullscreenModelClient >- , private VideoFullscreenChangeObserver >+ : public VideoFullscreenModel >+ , public VideoFullscreenModelClient >+ , public VideoFullscreenChangeObserver > , private PlaybackSessionModel >- , private PlaybackSessionModelClient >+ , public PlaybackSessionModelClient >+ , public CanMakeWeakPtr<VideoFullscreenControllerContext> > , public ThreadSafeRefCounted<VideoFullscreenControllerContext> { > > public: >@@ -118,6 +119,9 @@ public: > void requestHideAndExitFullscreen(); > void invalidate(); > >+ using ThreadSafeRefCounted::ref; >+ using ThreadSafeRefCounted::deref; >+ > private: > VideoFullscreenControllerContext() { } > >@@ -137,7 +141,9 @@ private: > void videoDimensionsChanged(const FloatSize&) override; > > // PlaybackSessionModel >- void addClient(PlaybackSessionModelClient&) override; >+ void refPlaybackSessionModel() final { ref(); } >+ void derefPlaybackSessionModel() final { deref(); } >+ void addClient(WeakPtr<PlaybackSessionModelClient>&&) override; > void removeClient(PlaybackSessionModelClient&) override; > void play() override; > void pause() override; >@@ -190,7 +196,9 @@ private: > void volumeChanged(double) override; > > // VideoFullscreenModel >- void addClient(VideoFullscreenModelClient&) override; >+ void refVideoFullscreenModel() final { ref(); } >+ void derefVideoFullscreenModel() final { deref(); } >+ void addClient(WeakPtr<VideoFullscreenModelClient>&&) override; > void removeClient(VideoFullscreenModelClient&) override; > void requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenMode, bool finishedWithMedia = false) override; > void setVideoLayerFrame(FloatRect) override; >@@ -208,8 +216,8 @@ private: > void willExitPictureInPicture() final; > void didExitPictureInPicture() final; > >- HashSet<PlaybackSessionModelClient*> m_playbackClients; >- HashSet<VideoFullscreenModelClient*> m_fullscreenClients; >+ Vector<WeakPtr<PlaybackSessionModelClient>> m_playbackClients; >+ Vector<WeakPtr<VideoFullscreenModelClient>> m_fullscreenClients; > RefPtr<VideoFullscreenInterfaceAVKit> m_interface; > RefPtr<VideoFullscreenModelVideoElement> m_fullscreenModel; > RefPtr<PlaybackSessionModelMediaElement> m_playbackModel; >@@ -319,8 +327,6 @@ void VideoFullscreenControllerContext::didExitFullscreen() > void VideoFullscreenControllerContext::didCleanupFullscreen() > { > ASSERT(isUIThread()); >- m_interface->setVideoFullscreenModel(nullptr); >- m_interface->setVideoFullscreenChangeObserver(nullptr); > m_interface = nullptr; > m_videoFullscreenView = nil; > >@@ -328,6 +334,8 @@ void VideoFullscreenControllerContext::didCleanupFullscreen() > m_fullscreenModel->setVideoFullscreenLayer(nil); > m_fullscreenModel->setVideoElement(nullptr); > m_playbackModel->setMediaElement(nullptr); >+ m_playbackModel->removeClient(*this); >+ m_playbackModel = nullptr; > m_fullscreenModel->removeClient(*this); > m_fullscreenModel = nullptr; > m_videoElement = nullptr; >@@ -542,16 +550,16 @@ void VideoFullscreenControllerContext::volumeChanged(double volume) > } > #pragma mark VideoFullscreenModel > >-void VideoFullscreenControllerContext::addClient(VideoFullscreenModelClient& client) >+void VideoFullscreenControllerContext::addClient(WeakPtr<VideoFullscreenModelClient>&& client) > { >- ASSERT(!m_fullscreenClients.contains(&client)); >- m_fullscreenClients.add(&client); >+ ASSERT(!m_fullscreenClients.contains(client)); >+ m_fullscreenClients.append(WTFMove(client)); > } > > void VideoFullscreenControllerContext::removeClient(VideoFullscreenModelClient& client) > { > ASSERT(m_fullscreenClients.contains(&client)); >- m_fullscreenClients.remove(&client); >+ m_fullscreenClients.removeAll(&client); > } > > void VideoFullscreenControllerContext::requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenMode mode, bool finishedWithMedia) >@@ -635,35 +643,35 @@ bool VideoFullscreenControllerContext::isPictureInPictureActive() const > void VideoFullscreenControllerContext::willEnterPictureInPicture() > { > ASSERT(isUIThread()); >- for (auto* client : m_fullscreenClients) >+ for (auto& client : m_fullscreenClients) > client->willEnterPictureInPicture(); > } > > void VideoFullscreenControllerContext::didEnterPictureInPicture() > { > ASSERT(isUIThread()); >- for (auto* client : m_fullscreenClients) >+ for (auto& client : m_fullscreenClients) > client->didEnterPictureInPicture(); > } > > void VideoFullscreenControllerContext::failedToEnterPictureInPicture() > { > ASSERT(isUIThread()); >- for (auto* client : m_fullscreenClients) >+ for (auto& client : m_fullscreenClients) > client->failedToEnterPictureInPicture(); > } > > void VideoFullscreenControllerContext::willExitPictureInPicture() > { > ASSERT(isUIThread()); >- for (auto* client : m_fullscreenClients) >+ for (auto& client : m_fullscreenClients) > client->willExitPictureInPicture(); > } > > void VideoFullscreenControllerContext::didExitPictureInPicture() > { > ASSERT(isUIThread()); >- for (auto* client : m_fullscreenClients) >+ for (auto& client : m_fullscreenClients) > client->didExitPictureInPicture(); > } > >@@ -675,16 +683,16 @@ FloatSize VideoFullscreenControllerContext::videoDimensions() const > > #pragma mark - PlaybackSessionModel > >-void VideoFullscreenControllerContext::addClient(PlaybackSessionModelClient& client) >+void VideoFullscreenControllerContext::addClient(WeakPtr<PlaybackSessionModelClient>&& client) > { >- ASSERT(!m_playbackClients.contains(&client)); >- m_playbackClients.add(&client); >+ ASSERT(!m_playbackClients.contains(client)); >+ m_playbackClients.append(WTFMove(client)); > } > > void VideoFullscreenControllerContext::removeClient(PlaybackSessionModelClient& client) > { > ASSERT(m_playbackClients.contains(&client)); >- m_playbackClients.remove(&client); >+ m_playbackClients.removeAll(&client); > } > > void VideoFullscreenControllerContext::play() >@@ -936,11 +944,11 @@ void VideoFullscreenControllerContext::setUpFullscreen(HTMLVideoElement& videoEl > RetainPtr<UIView> viewRef = view; > m_videoElement = &videoElement; > m_playbackModel = PlaybackSessionModelMediaElement::create(); >- m_playbackModel->addClient(*this); >+ m_playbackModel->addClient(makeWeakPtr(this)); > m_playbackModel->setMediaElement(m_videoElement.get()); > > m_fullscreenModel = VideoFullscreenModelVideoElement::create(); >- m_fullscreenModel->addClient(*this); >+ m_fullscreenModel->addClient(makeWeakPtr(this)); > m_fullscreenModel->setVideoElement(m_videoElement.get()); > > bool allowsPictureInPicture = m_videoElement->webkitSupportsPresentationMode(HTMLVideoElement::VideoPresentationMode::PictureInPicture); >@@ -953,10 +961,8 @@ void VideoFullscreenControllerContext::setUpFullscreen(HTMLVideoElement& videoEl > ASSERT(isUIThread()); > > Ref<PlaybackSessionInterfaceAVKit> sessionInterface = PlaybackSessionInterfaceAVKit::create(*this); >- m_interface = VideoFullscreenInterfaceAVKit::create(sessionInterface.get()); >- m_interface->setVideoFullscreenChangeObserver(this); >- m_interface->setVideoFullscreenModel(this); >- m_interface->setVideoFullscreenChangeObserver(this); >+ m_interface = VideoFullscreenInterfaceAVKit::create(sessionInterface.get(), *this); >+ m_interface->setVideoFullscreenChangeObserver(makeWeakPtr(this)); > > m_videoFullscreenView = adoptNS([allocUIViewInstance() init]); > >diff --git a/Source/WebCore/platform/mac/PlaybackSessionInterfaceMac.h b/Source/WebCore/platform/mac/PlaybackSessionInterfaceMac.h >index 9aa955fc44fa4c84b9e4a0f66a943aa5b84b29e8..9077c0379fef3fa8a2aaf2a7fc494ce44216ae82 100644 >--- a/Source/WebCore/platform/mac/PlaybackSessionInterfaceMac.h >+++ b/Source/WebCore/platform/mac/PlaybackSessionInterfaceMac.h >@@ -43,7 +43,8 @@ class PlaybackSessionModel; > class WEBCORE_EXPORT PlaybackSessionInterfaceMac final > : public PlaybackSessionInterface > , public PlaybackSessionModelClient >- , public RefCounted<PlaybackSessionInterfaceMac> { >+ , public RefCounted<PlaybackSessionInterfaceMac> >+ , public CanMakeWeakPtr<PlaybackSessionInterfaceMac> { > public: > static Ref<PlaybackSessionInterfaceMac> create(PlaybackSessionModel&); > virtual ~PlaybackSessionInterfaceMac(); >diff --git a/Source/WebCore/platform/mac/PlaybackSessionInterfaceMac.mm b/Source/WebCore/platform/mac/PlaybackSessionInterfaceMac.mm >index 602eddba51fce11393dbce445fbb86086648c967..ae16c82002920039400d2e2b1210b1426aeda3fb 100644 >--- a/Source/WebCore/platform/mac/PlaybackSessionInterfaceMac.mm >+++ b/Source/WebCore/platform/mac/PlaybackSessionInterfaceMac.mm >@@ -47,7 +47,7 @@ namespace WebCore { > Ref<PlaybackSessionInterfaceMac> PlaybackSessionInterfaceMac::create(PlaybackSessionModel& model) > { > auto interface = adoptRef(*new PlaybackSessionInterfaceMac(model)); >- model.addClient(interface); >+ model.addClient(makeWeakPtr(interface.get())); > return interface; > } > >diff --git a/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.h b/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.h >index af2c649f57e5e1585831df8b246262b2e73d6cb5..37cc5909904a894ea164e542c603d51e6ba6c5f3 100644 >--- a/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.h >+++ b/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.h >@@ -33,6 +33,7 @@ > #include "VideoFullscreenModel.h" > #include <wtf/RefCounted.h> > #include <wtf/RetainPtr.h> >+#include <wtf/WeakPtr.h> > #include <wtf/text/WTFString.h> > > OBJC_CLASS NSWindow; >@@ -46,21 +47,21 @@ class VideoFullscreenChangeObserver; > > class VideoFullscreenInterfaceMac > : public VideoFullscreenModelClient >- , private PlaybackSessionModelClient >- , public RefCounted<VideoFullscreenInterfaceMac> { >+ , public PlaybackSessionModelClient >+ , public RefCounted<VideoFullscreenInterfaceMac> >+ , public CanMakeWeakPtr<VideoFullscreenInterfaceMac> { > > public: >- static Ref<VideoFullscreenInterfaceMac> create(PlaybackSessionInterfaceMac& playbackSessionInterface) >+ static Ref<VideoFullscreenInterfaceMac> create(Ref<PlaybackSessionInterfaceMac>&& playbackSessionInterface, Ref<VideoFullscreenModel> videoFullscreenModel) > { >- return adoptRef(*new VideoFullscreenInterfaceMac(playbackSessionInterface)); >+ return adoptRef(*new VideoFullscreenInterfaceMac(WTFMove(playbackSessionInterface), WTFMove(videoFullscreenModel))); > } > virtual ~VideoFullscreenInterfaceMac(); > PlaybackSessionInterfaceMac& playbackSessionInterface() const { return m_playbackSessionInterface.get(); } >- VideoFullscreenModel* videoFullscreenModel() const { return m_videoFullscreenModel; } >+ VideoFullscreenModel& videoFullscreenModel() const { return m_videoFullscreenModel; } > PlaybackSessionModel* playbackSessionModel() const { return m_playbackSessionInterface->playbackSessionModel(); } >- WEBCORE_EXPORT void setVideoFullscreenModel(VideoFullscreenModel*); >- VideoFullscreenChangeObserver* videoFullscreenChangeObserver() const { return m_fullscreenChangeObserver; } >- WEBCORE_EXPORT void setVideoFullscreenChangeObserver(VideoFullscreenChangeObserver*); >+ VideoFullscreenChangeObserver* videoFullscreenChangeObserver() const { return m_fullscreenChangeObserver.get(); } >+ WEBCORE_EXPORT void setVideoFullscreenChangeObserver(WeakPtr<VideoFullscreenChangeObserver>); > > // PlaybackSessionModelClient > WEBCORE_EXPORT void rateChanged(bool isPlaying, float playbackRate) override; >@@ -97,10 +98,10 @@ public: > WEBCORE_EXPORT void requestHideAndExitPiP(); > > private: >- WEBCORE_EXPORT VideoFullscreenInterfaceMac(PlaybackSessionInterfaceMac&); >+ WEBCORE_EXPORT VideoFullscreenInterfaceMac(Ref<PlaybackSessionInterfaceMac>&&, Ref<VideoFullscreenModel>&&); > Ref<PlaybackSessionInterfaceMac> m_playbackSessionInterface; >- VideoFullscreenModel* m_videoFullscreenModel { nullptr }; >- VideoFullscreenChangeObserver* m_fullscreenChangeObserver { nullptr }; >+ Ref<VideoFullscreenModel> m_videoFullscreenModel; >+ WeakPtr<VideoFullscreenChangeObserver> m_fullscreenChangeObserver; > HTMLMediaElementEnums::VideoFullscreenMode m_mode { HTMLMediaElementEnums::VideoFullscreenModeNone }; > RetainPtr<WebVideoFullscreenInterfaceMacObjC> m_webVideoFullscreenInterfaceObjC; > }; >diff --git a/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.mm b/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.mm >index 0ae6afeade313175d2e3685cd7a2b54e8506b07b..07cd50bfbc2e1b78b4b5807544aa95643d9ae4da 100644 >--- a/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.mm >+++ b/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.mm >@@ -192,8 +192,8 @@ - (void)setUpPIPForVideoView:(NSView *)videoView withFrame:(NSRect)frame inWindo > [_pipViewController setUserCanResize:YES]; > [_pipViewController setPlaying:_playing]; > [self setVideoDimensions:NSEqualSizes(_videoDimensions, NSZeroSize) ? frame.size : _videoDimensions]; >- if (_videoFullscreenInterfaceMac && _videoFullscreenInterfaceMac->videoFullscreenModel()) >- _videoFullscreenInterfaceMac->videoFullscreenModel()->setVideoLayerGravity(VideoFullscreenModel::VideoGravityResizeAspectFill); >+ if (_videoFullscreenInterfaceMac) >+ _videoFullscreenInterfaceMac->videoFullscreenModel().setVideoLayerGravity(VideoFullscreenModel::VideoGravityResizeAspectFill); > > _videoViewContainer = adoptNS([[WebVideoViewContainer alloc] initWithFrame:frame]); > [_videoViewContainer setVideoViewContainerDelegate:self]; >@@ -246,8 +246,8 @@ - (void)boundsDidChangeForVideoViewContainer:(WebVideoViewContainer *)videoViewC > > ASSERT_UNUSED(videoViewContainer, videoViewContainer == _videoViewContainer); > >- if (_videoFullscreenInterfaceMac && _videoFullscreenInterfaceMac->videoFullscreenModel()) >- _videoFullscreenInterfaceMac->videoFullscreenModel()->setVideoLayerFrame([_videoViewContainer bounds]); >+ if (_videoFullscreenInterfaceMac) >+ _videoFullscreenInterfaceMac->videoFullscreenModel().setVideoLayerFrame([_videoViewContainer bounds]); > } > > - (void)superviewDidChangeForVideoViewContainer:(WebVideoViewContainer *)videoViewContainer >@@ -283,12 +283,12 @@ - (void)pipDidClose:(PIPViewController *)pip > { > ASSERT_UNUSED(pip, pip == _pipViewController); > >- if (_videoFullscreenInterfaceMac && _videoFullscreenInterfaceMac->videoFullscreenModel() && _videoViewContainer && _returningWindow && !NSEqualRects(_returningRect, NSZeroRect)) { >+ if (_videoFullscreenInterfaceMac && _videoViewContainer && _returningWindow && !NSEqualRects(_returningRect, NSZeroRect)) { > [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) { > context.allowsImplicitAnimation = NO; > [_videoViewContainer setFrame:_returningRect]; >- _videoFullscreenInterfaceMac->videoFullscreenModel()->setVideoLayerFrame([_videoViewContainer bounds]); >- _videoFullscreenInterfaceMac->videoFullscreenModel()->setVideoLayerGravity(VideoFullscreenModel::VideoGravityResizeAspect); >+ _videoFullscreenInterfaceMac->videoFullscreenModel().setVideoLayerFrame([_videoViewContainer bounds]); >+ _videoFullscreenInterfaceMac->videoFullscreenModel().setVideoLayerGravity(VideoFullscreenModel::VideoGravityResizeAspect); > > [[_returningWindow contentView] addSubview:_videoViewContainer.get() positioned:NSWindowAbove relativeTo:nil]; > } completionHandler:nil]; >@@ -296,10 +296,9 @@ - (void)pipDidClose:(PIPViewController *)pip > > if (_videoFullscreenInterfaceMac) { > if (!self.isExitingToStandardFullscreen) { >- if (VideoFullscreenModel* videoFullscreenModel = _videoFullscreenInterfaceMac->videoFullscreenModel()) { >- videoFullscreenModel->didExitPictureInPicture(); >- videoFullscreenModel->setVideoLayerGravity(VideoFullscreenModel::VideoGravityResizeAspect); >- } >+ Ref<VideoFullscreenModel> videoFullscreenModel = _videoFullscreenInterfaceMac->videoFullscreenModel(); >+ videoFullscreenModel->didExitPictureInPicture(); >+ videoFullscreenModel->setVideoLayerGravity(VideoFullscreenModel::VideoGravityResizeAspect); > } > > _videoFullscreenInterfaceMac->clearMode(HTMLMediaElementEnums::VideoFullscreenModePictureInPicture); >@@ -344,33 +343,24 @@ @end > namespace WebCore { > using namespace PAL; > >-VideoFullscreenInterfaceMac::VideoFullscreenInterfaceMac(PlaybackSessionInterfaceMac& playbackSessionInterface) >- : m_playbackSessionInterface(playbackSessionInterface) >+VideoFullscreenInterfaceMac::VideoFullscreenInterfaceMac(Ref<PlaybackSessionInterfaceMac>&& playbackSessionInterface, Ref<VideoFullscreenModel>&& videoFullscreenModel) >+ : m_playbackSessionInterface(WTFMove(playbackSessionInterface)) >+ , m_videoFullscreenModel(WTFMove(videoFullscreenModel)) > { > ASSERT(m_playbackSessionInterface->playbackSessionModel()); > auto model = m_playbackSessionInterface->playbackSessionModel(); >- model->addClient(*this); >+ model->addClient(makeWeakPtr(this)); > [videoFullscreenInterfaceObjC() updateIsPlaying:model->isPlaying() newPlaybackRate:model->playbackRate()]; > } > > VideoFullscreenInterfaceMac::~VideoFullscreenInterfaceMac() > { >- if (m_playbackSessionInterface->playbackSessionModel()) >- m_playbackSessionInterface->playbackSessionModel()->removeClient(*this); >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->removeClient(*this); >+ if (auto model = m_playbackSessionInterface->playbackSessionModel()) >+ model->removeClient(*this); >+ m_videoFullscreenModel->removeClient(*this); > } > >-void VideoFullscreenInterfaceMac::setVideoFullscreenModel(VideoFullscreenModel* model) >-{ >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->removeClient(*this); >- m_videoFullscreenModel = model; >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->addClient(*this); >-} >- >-void VideoFullscreenInterfaceMac::setVideoFullscreenChangeObserver(VideoFullscreenChangeObserver* observer) >+void VideoFullscreenInterfaceMac::setVideoFullscreenChangeObserver(WeakPtr<VideoFullscreenChangeObserver> observer) > { > m_fullscreenChangeObserver = observer; > } >@@ -382,8 +372,7 @@ void VideoFullscreenInterfaceMac::setMode(HTMLMediaElementEnums::VideoFullscreen > return; > > m_mode = newMode; >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->fullscreenModeChanged(m_mode); >+ m_videoFullscreenModel->fullscreenModeChanged(m_mode); > } > > void VideoFullscreenInterfaceMac::clearMode(HTMLMediaElementEnums::VideoFullscreenMode mode) >@@ -393,8 +382,7 @@ void VideoFullscreenInterfaceMac::clearMode(HTMLMediaElementEnums::VideoFullscre > return; > > m_mode = newMode; >- if (m_videoFullscreenModel) >- m_videoFullscreenModel->fullscreenModeChanged(m_mode); >+ m_videoFullscreenModel->fullscreenModeChanged(m_mode); > } > > void VideoFullscreenInterfaceMac::rateChanged(bool isPlaying, float playbackRate) >@@ -499,7 +487,6 @@ void VideoFullscreenInterfaceMac::invalidate() > { > LOG(Fullscreen, "VideoFullscreenInterfaceMac::invalidate(%p)", this); > >- m_videoFullscreenModel = nil; > m_fullscreenChangeObserver = nil; > > cleanupFullscreen(); >@@ -510,9 +497,6 @@ void VideoFullscreenInterfaceMac::invalidate() > > void VideoFullscreenInterfaceMac::requestHideAndExitPiP() > { >- if (!m_videoFullscreenModel) >- return; >- > m_videoFullscreenModel->requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenModeNone); > m_videoFullscreenModel->willExitPictureInPicture(); > } >diff --git a/Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.h b/Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.h >index 835bb9baf819706fdfaebece2ec0d78e53ea300b..db34778b09cf97f924ddb0c83fff6458eed90990 100644 >--- a/Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.h >+++ b/Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.h >@@ -35,9 +35,9 @@ > #include <WebCore/TimeRanges.h> > #include <wtf/HashCountedSet.h> > #include <wtf/HashMap.h> >-#include <wtf/HashSet.h> > #include <wtf/RefCounted.h> > #include <wtf/RefPtr.h> >+#include <wtf/Vector.h> > > #if PLATFORM(IOS) > #include <WebCore/PlaybackSessionInterfaceAVKit.h> >@@ -56,7 +56,9 @@ namespace WebKit { > class WebPageProxy; > class PlaybackSessionManagerProxy; > >-class PlaybackSessionModelContext final: public RefCounted<PlaybackSessionModelContext>, public WebCore::PlaybackSessionModel { >+class PlaybackSessionModelContext final >+ : public WebCore::PlaybackSessionModel >+ , public RefCounted<PlaybackSessionModelContext> { > public: > static Ref<PlaybackSessionModelContext> create(PlaybackSessionManagerProxy& manager, uint64_t contextId) > { >@@ -67,7 +69,7 @@ public: > void invalidate() { m_manager = nullptr; } > > // PlaybackSessionModel >- void addClient(WebCore::PlaybackSessionModelClient&) final; >+ void addClient(WeakPtr<WebCore::PlaybackSessionModelClient>&&) final; > void removeClient(WebCore::PlaybackSessionModelClient&)final; > > void durationChanged(double); >@@ -87,6 +89,9 @@ public: > void volumeChanged(double); > void pictureInPictureActiveChanged(bool); > >+ using RefCounted::ref; >+ using RefCounted::deref; >+ > private: > friend class VideoFullscreenModelContext; > >@@ -97,6 +102,8 @@ private: > } > > // PlaybackSessionModel >+ void refPlaybackSessionModel() final { ref(); } >+ void derefPlaybackSessionModel() final { deref(); } > void play() final; > void pause() final; > void togglePlayState() final; >@@ -139,7 +146,7 @@ private: > > PlaybackSessionManagerProxy* m_manager; > uint64_t m_contextId; >- HashSet<WebCore::PlaybackSessionModelClient*> m_clients; >+ Vector<WeakPtr<WebCore::PlaybackSessionModelClient>> m_clients; > double m_playbackStartedTime { 0 }; > bool m_playbackStartedTimeNeedsUpdate { false }; > double m_duration { 0 }; >diff --git a/Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.mm b/Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.mm >index f4c7066c1e6ead8a80fbb35331b63bc4795384e6..29162fc73b737357b83fce8bb5ab6675e41b4557 100644 >--- a/Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.mm >+++ b/Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.mm >@@ -39,16 +39,16 @@ namespace WebKit { > > #pragma mark - PlaybackSessionModelContext > >-void PlaybackSessionModelContext::addClient(PlaybackSessionModelClient& client) >+void PlaybackSessionModelContext::addClient(WeakPtr<PlaybackSessionModelClient>&& client) > { >- ASSERT(!m_clients.contains(&client)); >- m_clients.add(&client); >+ ASSERT(!m_clients.contains(client)); >+ m_clients.append(WTFMove(client)); > } > > void PlaybackSessionModelContext::removeClient(PlaybackSessionModelClient& client) > { > ASSERT(m_clients.contains(&client)); >- m_clients.remove(&client); >+ m_clients.removeAll(&client); > } > > void PlaybackSessionModelContext::play() >@@ -161,7 +161,7 @@ void PlaybackSessionModelContext::playbackStartedTimeChanged(double playbackStar > void PlaybackSessionModelContext::durationChanged(double duration) > { > m_duration = duration; >- for (auto* client : m_clients) >+ for (auto& client : m_clients) > client->durationChanged(duration); > } > >@@ -172,14 +172,14 @@ void PlaybackSessionModelContext::currentTimeChanged(double currentTime) > if (m_playbackStartedTimeNeedsUpdate) > playbackStartedTimeChanged(currentTime); > >- for (auto* client : m_clients) >+ for (auto& client : m_clients) > client->currentTimeChanged(currentTime, anchorTime); > } > > void PlaybackSessionModelContext::bufferedTimeChanged(double bufferedTime) > { > m_bufferedTime = bufferedTime; >- for (auto* client : m_clients) >+ for (auto& client : m_clients) > client->bufferedTimeChanged(bufferedTime); > } > >@@ -187,7 +187,7 @@ void PlaybackSessionModelContext::rateChanged(bool isPlaying, float playbackRate > { > m_isPlaying = isPlaying; > m_playbackRate = playbackRate; >- for (auto* client : m_clients) >+ for (auto& client : m_clients) > client->rateChanged(isPlaying, playbackRate); > } > >@@ -196,14 +196,14 @@ void PlaybackSessionModelContext::seekableRangesChanged(WebCore::TimeRanges& see > m_seekableRanges = seekableRanges; > m_seekableTimeRangesLastModifiedTime = lastModifiedTime; > m_liveUpdateInterval = liveUpdateInterval; >- for (auto* client : m_clients) >+ for (auto& client : m_clients) > client->seekableRangesChanged(seekableRanges, lastModifiedTime, liveUpdateInterval); > } > > void PlaybackSessionModelContext::canPlayFastReverseChanged(bool canPlayFastReverse) > { > m_canPlayFastReverse = canPlayFastReverse; >- for (auto* client : m_clients) >+ for (auto& client : m_clients) > client->canPlayFastReverseChanged(canPlayFastReverse); > } > >@@ -211,7 +211,7 @@ void PlaybackSessionModelContext::audioMediaSelectionOptionsChanged(const Vector > { > m_audioMediaSelectionOptions = audioMediaSelectionOptions; > m_audioMediaSelectedIndex = audioMediaSelectedIndex; >- for (auto* client : m_clients) >+ for (auto& client : m_clients) > client->audioMediaSelectionOptionsChanged(audioMediaSelectionOptions, audioMediaSelectedIndex); > } > >@@ -220,7 +220,7 @@ void PlaybackSessionModelContext::legibleMediaSelectionOptionsChanged(const Vect > m_legibleMediaSelectionOptions = legibleMediaSelectionOptions; > m_legibleMediaSelectedIndex = legibleMediaSelectedIndex; > >- for (auto* client : m_clients) >+ for (auto& client : m_clients) > client->legibleMediaSelectionOptionsChanged(legibleMediaSelectionOptions, legibleMediaSelectedIndex); > } > >@@ -228,7 +228,7 @@ void PlaybackSessionModelContext::audioMediaSelectionIndexChanged(uint64_t selec > { > m_audioMediaSelectedIndex = selectedIndex; > >- for (auto* client : m_clients) >+ for (auto& client : m_clients) > client->audioMediaSelectionIndexChanged(selectedIndex); > } > >@@ -236,7 +236,7 @@ void PlaybackSessionModelContext::legibleMediaSelectionIndexChanged(uint64_t sel > { > m_legibleMediaSelectedIndex = selectedIndex; > >- for (auto* client : m_clients) >+ for (auto& client : m_clients) > client->legibleMediaSelectionIndexChanged(selectedIndex); > } > >@@ -246,35 +246,35 @@ void PlaybackSessionModelContext::externalPlaybackChanged(bool enabled, Playback > m_externalPlaybackTargetType = type; > m_externalPlaybackLocalizedDeviceName = localizedName; > >- for (auto* client : m_clients) >+ for (auto& client : m_clients) > client->externalPlaybackChanged(enabled, type, localizedName); > } > > void PlaybackSessionModelContext::wirelessVideoPlaybackDisabledChanged(bool wirelessVideoPlaybackDisabled) > { > m_wirelessVideoPlaybackDisabled = wirelessVideoPlaybackDisabled; >- for (auto* client : m_clients) >+ for (auto& client : m_clients) > client->wirelessVideoPlaybackDisabledChanged(wirelessVideoPlaybackDisabled); > } > > void PlaybackSessionModelContext::mutedChanged(bool muted) > { > m_muted = muted; >- for (auto* client : m_clients) >+ for (auto& client : m_clients) > client->mutedChanged(muted); > } > > void PlaybackSessionModelContext::volumeChanged(double volume) > { > m_volume = volume; >- for (auto* client : m_clients) >+ for (auto& client : m_clients) > client->volumeChanged(volume); > } > > void PlaybackSessionModelContext::pictureInPictureActiveChanged(bool active) > { > m_pictureInPictureActive = active; >- for (auto* client : m_clients) >+ for (auto& client : m_clients) > client->pictureInPictureActiveChanged(active); > } > >@@ -303,22 +303,14 @@ void PlaybackSessionManagerProxy::invalidate() > m_page->process().removeMessageReceiver(Messages::PlaybackSessionManagerProxy::messageReceiverName(), m_page->pageID()); > m_page = nullptr; > >- auto contextMap = WTFMove(m_contextMap); >+ m_contextMap.clear(); > m_clientCounts.clear(); >- >- for (auto& tuple : contextMap.values()) { >- RefPtr<PlaybackSessionModelContext> model; >- RefPtr<PlatformPlaybackSessionInterface> interface; >- std::tie(model, interface) = tuple; >- >- interface->invalidate(); >- } > } > > PlaybackSessionManagerProxy::ModelInterfaceTuple PlaybackSessionManagerProxy::createModelAndInterface(uint64_t contextId) > { > Ref<PlaybackSessionModelContext> model = PlaybackSessionModelContext::create(*this, contextId); >- Ref<PlatformPlaybackSessionInterface> interface = PlatformPlaybackSessionInterface::create(model); >+ Ref<PlatformPlaybackSessionInterface> interface = PlatformPlaybackSessionInterface::create(model.copyRef()); > > return std::make_tuple(WTFMove(model), WTFMove(interface)); > } >@@ -348,11 +340,8 @@ void PlaybackSessionManagerProxy::addClientForContext(uint64_t contextId) > > void PlaybackSessionManagerProxy::removeClientForContext(uint64_t contextId) > { >- if (!m_clientCounts.remove(contextId)) >- return; >- >- ensureInterface(contextId).invalidate(); >- m_contextMap.remove(contextId); >+ if (m_clientCounts.remove(contextId)) >+ m_contextMap.remove(contextId); > } > > #pragma mark Messages from PlaybackSessionManager >diff --git a/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.h b/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.h >index 48663c252ba878bba1a191403c2ccaee31610916..b99493e2e455b8ab6beb130a360d54bd31114749 100644 >--- a/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.h >+++ b/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.h >@@ -33,9 +33,9 @@ > #include <WebCore/VideoFullscreenChangeObserver.h> > #include <WebCore/VideoFullscreenModel.h> > #include <wtf/HashMap.h> >-#include <wtf/HashSet.h> > #include <wtf/RefCounted.h> > #include <wtf/RefPtr.h> >+#include <wtf/Vector.h> > > #if PLATFORM(IOS) > #include <WebCore/VideoFullscreenInterfaceAVKit.h> >@@ -59,7 +59,8 @@ class VideoFullscreenManagerProxy; > class VideoFullscreenModelContext final > : public RefCounted<VideoFullscreenModelContext> > , public WebCore::VideoFullscreenModel >- , public WebCore::VideoFullscreenChangeObserver { >+ , public WebCore::VideoFullscreenChangeObserver >+ , public CanMakeWeakPtr<VideoFullscreenModelContext> { > public: > static Ref<VideoFullscreenModelContext> create(VideoFullscreenManagerProxy& manager, PlaybackSessionModelContext& playbackSessionModel, uint64_t contextId) > { >@@ -72,11 +73,16 @@ public: > PlatformView *layerHostView() const { return m_layerHostView.get(); } > void setLayerHostView(RetainPtr<PlatformView>&& layerHostView) { m_layerHostView = WTFMove(layerHostView); } > >+ using RefCounted::ref; >+ using RefCounted::deref; >+ > private: > VideoFullscreenModelContext(VideoFullscreenManagerProxy&, PlaybackSessionModelContext&, uint64_t); > > // VideoFullscreenModel >- void addClient(WebCore::VideoFullscreenModelClient&) override; >+ void refVideoFullscreenModel() final { ref(); } >+ void derefVideoFullscreenModel() final { deref(); } >+ void addClient(WeakPtr<WebCore::VideoFullscreenModelClient>&&) override; > void removeClient(WebCore::VideoFullscreenModelClient&) override; > void requestFullscreenMode(WebCore::HTMLMediaElementEnums::VideoFullscreenMode, bool finishedWithMedia = false) override; > void setVideoLayerFrame(WebCore::FloatRect) override; >@@ -110,7 +116,7 @@ private: > Ref<PlaybackSessionModelContext> m_playbackSessionModel; > uint64_t m_contextId; > RetainPtr<PlatformView *> m_layerHostView; >- HashSet<WebCore::VideoFullscreenModelClient*> m_clients; >+ Vector<WeakPtr<WebCore::VideoFullscreenModelClient>> m_clients; > WebCore::FloatSize m_videoDimensions; > bool m_hasVideo { false }; > }; >diff --git a/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm b/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm >index 9100afd8c41120bb5e581d230a2476f7542fed22..5afa88e4fa9f27ddbc7d1fc0b61377bd5d3bdfc1 100644 >--- a/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm >+++ b/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm >@@ -172,16 +172,16 @@ VideoFullscreenModelContext::~VideoFullscreenModelContext() > { > } > >-void VideoFullscreenModelContext::addClient(VideoFullscreenModelClient& client) >+void VideoFullscreenModelContext::addClient(WeakPtr<VideoFullscreenModelClient>&& client) > { >- ASSERT(!m_clients.contains(&client)); >- m_clients.add(&client); >+ ASSERT(!m_clients.contains(client)); >+ m_clients.append(WTFMove(client)); > } > > void VideoFullscreenModelContext::removeClient(VideoFullscreenModelClient& client) > { > ASSERT(m_clients.contains(&client)); >- m_clients.remove(&client); >+ m_clients.removeAll(&client); > } > > void VideoFullscreenModelContext::requestFullscreenMode(HTMLMediaElementEnums::VideoFullscreenMode mode, bool finishedWithMedia) >@@ -406,11 +406,10 @@ VideoFullscreenManagerProxy::ModelInterfaceTuple VideoFullscreenManagerProxy::cr > auto& playbackSessionModel = m_playbackSessionManagerProxy->ensureModel(contextId); > Ref<VideoFullscreenModelContext> model = VideoFullscreenModelContext::create(*this, playbackSessionModel, contextId); > auto& playbackSessionInterface = m_playbackSessionManagerProxy->ensureInterface(contextId); >- Ref<PlatformVideoFullscreenInterface> interface = PlatformVideoFullscreenInterface::create(playbackSessionInterface); >+ Ref<PlatformVideoFullscreenInterface> interface = PlatformVideoFullscreenInterface::create(makeRef(playbackSessionInterface), model.copyRef()); > m_playbackSessionManagerProxy->addClientForContext(contextId); > >- interface->setVideoFullscreenModel(&model.get()); >- interface->setVideoFullscreenChangeObserver(&model.get()); >+ interface->setVideoFullscreenChangeObserver(makeWeakPtr(model.get())); > > return std::make_tuple(WTFMove(model), WTFMove(interface)); > } >@@ -449,7 +448,6 @@ void VideoFullscreenManagerProxy::removeClientForContext(uint64_t contextId) > clientCount--; > > if (clientCount <= 0) { >- ensureInterface(contextId).setVideoFullscreenModel(nullptr); > m_playbackSessionManagerProxy->removeClientForContext(contextId); > m_clientCounts.remove(contextId); > m_contextMap.remove(contextId); >diff --git a/Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenViewController.mm b/Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenViewController.mm >index d88d63d86e7e06eddcaaf66664eaff2af3553662..b612d0c18eabf44886b7841a68ab57f4ca970514 100644 >--- a/Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenViewController.mm >+++ b/Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenViewController.mm >@@ -56,7 +56,9 @@ - (void)didEnterPictureInPicture; > - (void)failedToEnterPictureInPicture; > @end > >-class WKFullScreenViewControllerPlaybackSessionModelClient : PlaybackSessionModelClient { >+class WKFullScreenViewControllerPlaybackSessionModelClient >+ : public PlaybackSessionModelClient >+ , public CanMakeWeakPtr<WKFullScreenViewControllerPlaybackSessionModelClient> { > public: > void setParent(WKFullScreenViewController *parent) { m_parent = parent; } > >@@ -75,11 +77,11 @@ public: > if (m_interface == interface) > return; > >- if (m_interface && m_interface->playbackSessionModel()) >- m_interface->playbackSessionModel()->removeClient(*this); >+ if (m_interface) >+ m_interface->playbackSessionModel().removeClient(*this); > m_interface = interface; >- if (m_interface && m_interface->playbackSessionModel()) >- m_interface->playbackSessionModel()->addClient(*this); >+ if (m_interface) >+ m_interface->playbackSessionModel().addClient(makeWeakPtr(*this)); > } > > private: >@@ -87,7 +89,9 @@ private: > RefPtr<PlaybackSessionInterfaceAVKit> m_interface; > }; > >-class WKFullScreenViewControllerVideoFullscreenModelClient : VideoFullscreenModelClient { >+class WKFullScreenViewControllerVideoFullscreenModelClient >+ : public VideoFullscreenModelClient >+ , public CanMakeWeakPtr<WKFullScreenViewControllerVideoFullscreenModelClient> { > public: > void setParent(WKFullScreenViewController *parent) { m_parent = parent; } > >@@ -96,11 +100,11 @@ public: > if (m_interface == interface) > return; > >- if (m_interface && m_interface->videoFullscreenModel()) >- m_interface->videoFullscreenModel()->removeClient(*this); >+ if (m_interface) >+ m_interface->videoFullscreenModel().removeClient(*this); > m_interface = interface; >- if (m_interface && m_interface->videoFullscreenModel()) >- m_interface->videoFullscreenModel()->addClient(*this); >+ if (m_interface) >+ m_interface->videoFullscreenModel().addClient(makeWeakPtr(*this)); > } > > VideoFullscreenInterfaceAVKit* interface() const { return m_interface.get(); } >@@ -264,9 +268,14 @@ - (void)videoControlsManagerDidChange > _playbackClient.setInterface(playbackSessionInterface); > _videoFullscreenClient.setInterface(videoFullscreenInterface); > >- PlaybackSessionModel* playbackSessionModel = playbackSessionInterface ? playbackSessionInterface->playbackSessionModel() : nullptr; >- self.playing = playbackSessionModel ? playbackSessionModel->isPlaying() : NO; >- [_pipButton setHidden:!playbackSessionModel]; >+ if (!playbackSessionInterface) { >+ self.playing = NO; >+ [_pipButton setHidden:YES]; >+ return; >+ } >+ >+ self.playing = playbackSessionInterface->playbackSessionModel().isPlaying(); >+ [_pipButton setHidden:NO]; > } > > - (void)setPrefersStatusBarHidden:(BOOL)value >@@ -512,14 +521,8 @@ - (void)_togglePiPAction:(id)sender > return; > > PlatformPlaybackSessionInterface* playbackSessionInterface = playbackSessionManager->controlsManagerInterface(); >- if (!playbackSessionInterface) >- return; >- >- PlaybackSessionModel* playbackSessionModel = playbackSessionInterface->playbackSessionModel(); >- if (!playbackSessionModel) >- return; >- >- playbackSessionModel->togglePictureInPicture(); >+ if (playbackSessionInterface) >+ playbackSessionInterface->playbackSessionModel().togglePictureInPicture(); > } > > - (void)_touchDetected:(id)sender >diff --git a/Source/WebKit/UIProcess/mac/WKFullScreenWindowController.mm b/Source/WebKit/UIProcess/mac/WKFullScreenWindowController.mm >index 47251d82fb33984d7f7f2a2f6c248ef857f2cc90..baabe1aacfecafa1c9becb214e84a6dee21c8136 100644 >--- a/Source/WebKit/UIProcess/mac/WKFullScreenWindowController.mm >+++ b/Source/WebKit/UIProcess/mac/WKFullScreenWindowController.mm >@@ -54,7 +54,9 @@ static const NSTimeInterval DefaultWatchdogTimerInterval = 1; > > namespace WebKit { > >-class WKFullScreenWindowControllerVideoFullscreenModelClient : VideoFullscreenModelClient { >+class WKFullScreenWindowControllerVideoFullscreenModelClient >+ : public CanMakeWeakPtr<WKFullScreenWindowControllerVideoFullscreenModelClient> >+ , public VideoFullscreenModelClient { > public: > void setParent(WKFullScreenWindowController *parent) { m_parent = parent; } > >@@ -63,11 +65,11 @@ public: > if (m_interface == interface) > return; > >- if (m_interface && m_interface->videoFullscreenModel()) >- m_interface->videoFullscreenModel()->removeClient(*this); >+ if (m_interface) >+ m_interface->videoFullscreenModel().removeClient(*this); > m_interface = interface; >- if (m_interface && m_interface->videoFullscreenModel()) >- m_interface->videoFullscreenModel()->addClient(*this); >+ if (m_interface) >+ m_interface->videoFullscreenModel().addClient(makeWeakPtr(this)); > } > > VideoFullscreenInterfaceMac* interface() const { return m_interface.get(); } >diff --git a/Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.h b/Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.h >index d297dac2297fff9ab88f6180b9e9d928e502812f..1746f6c60d9864ae5f64991c830959919d784ae9 100644 >--- a/Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.h >+++ b/Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.h >@@ -56,6 +56,7 @@ class PlaybackSessionManager; > > class PlaybackSessionInterfaceContext final > : public RefCounted<PlaybackSessionInterfaceContext> >+ , public CanMakeWeakPtr<PlaybackSessionInterfaceContext> > , public WebCore::PlaybackSessionInterface > , public WebCore::PlaybackSessionModelClient { > public: >diff --git a/Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.mm b/Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.mm >index b010d3076b0b30c98050319091bf7093f8c027b4..577c5dc973b03b34e70c7a7ac98b0c95d24d0ef3 100644 >--- a/Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.mm >+++ b/Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.mm >@@ -205,7 +205,7 @@ PlaybackSessionManager::ModelInterfaceTuple PlaybackSessionManager::createModelA > { > RefPtr<PlaybackSessionModelMediaElement> model = PlaybackSessionModelMediaElement::create(); > RefPtr<PlaybackSessionInterfaceContext> interface = PlaybackSessionInterfaceContext::create(*this, contextId); >- model->addClient(*interface); >+ model->addClient(makeWeakPtr(interface.get())); > > return std::make_tuple(WTFMove(model), WTFMove(interface)); > } >diff --git a/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.h b/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.h >index ff8c4baf463be3539830290ecd246ef9fcfb1dfa..da673254e8a1c897fd40f07a37147df357a454b9 100644 >--- a/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.h >+++ b/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.h >@@ -58,6 +58,7 @@ class VideoFullscreenManager; > > class VideoFullscreenInterfaceContext > : public RefCounted<VideoFullscreenInterfaceContext> >+ , public CanMakeWeakPtr<VideoFullscreenInterfaceContext> > , public WebCore::VideoFullscreenModelClient { > public: > static Ref<VideoFullscreenInterfaceContext> create(VideoFullscreenManager& manager, uint64_t contextId) >diff --git a/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm b/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm >index f9fd6afea18ec398d1fc740a58de0af2ca2a3289..6561eb033c827e35ac22cef0a709d32f6f5ce706 100644 >--- a/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm >+++ b/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm >@@ -157,7 +157,7 @@ VideoFullscreenManager::ModelInterfaceTuple VideoFullscreenManager::createModelA > m_playbackSessionManager->addClientForContext(contextId); > > interface->setLayerHostingContext(LayerHostingContext::createForExternalHostingProcess()); >- model->addClient(*interface); >+ model->addClient(makeWeakPtr(interface.get())); > > return std::make_tuple(WTFMove(model), WTFMove(interface)); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 188747
:
347511
|
347515
|
347526
|
347531
|
347533
|
347537
|
347841
|
347847
|
347870
|
347922
|
349452
|
349486
|
349491
|
349784
|
349795
|
349838
|
351008
|
351130