VideoFullscreenManagerProxy.h [plain text]
#pragma once
#if ENABLE(VIDEO_PRESENTATION_MODE)
#include "LayerHostingContext.h"
#include "MessageReceiver.h"
#include "PlaybackSessionContextIdentifier.h"
#include <WebCore/AudioSession.h>
#include <WebCore/GraphicsLayer.h>
#include <WebCore/PlatformView.h>
#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/text/WTFString.h>
#if PLATFORM(IOS_FAMILY)
#include <WebCore/VideoFullscreenInterfaceAVKit.h>
#else
#include <WebCore/VideoFullscreenInterfaceMac.h>
#endif
#if PLATFORM(IOS_FAMILY)
typedef WebCore::VideoFullscreenInterfaceAVKit PlatformVideoFullscreenInterface;
#else
typedef WebCore::VideoFullscreenInterfaceMac PlatformVideoFullscreenInterface;
#endif
namespace WebKit {
constexpr size_t DefaultMockPictureInPictureWindowWidth = 100;
constexpr size_t DefaultMockPictureInPictureWindowHeight = 100;
class WebPageProxy;
class PlaybackSessionManagerProxy;
class PlaybackSessionModelContext;
class VideoFullscreenManagerProxy;
class VideoFullscreenModelContext final
: public RefCounted<VideoFullscreenModelContext>
, public WebCore::VideoFullscreenModel
, public WebCore::VideoFullscreenChangeObserver {
public:
static Ref<VideoFullscreenModelContext> create(VideoFullscreenManagerProxy& manager, PlaybackSessionModelContext& playbackSessionModel, PlaybackSessionContextIdentifier contextId)
{
return adoptRef(*new VideoFullscreenModelContext(manager, playbackSessionModel, contextId));
}
virtual ~VideoFullscreenModelContext();
void invalidate() { m_manager = nullptr; }
PlatformView *layerHostView() const { return m_layerHostView.get(); }
void setLayerHostView(RetainPtr<PlatformView>&& layerHostView) { m_layerHostView = WTFMove(layerHostView); }
private:
VideoFullscreenModelContext(VideoFullscreenManagerProxy&, PlaybackSessionModelContext&, PlaybackSessionContextIdentifier);
void addClient(WebCore::VideoFullscreenModelClient&) override;
void removeClient(WebCore::VideoFullscreenModelClient&) override;
void requestFullscreenMode(WebCore::HTMLMediaElementEnums::VideoFullscreenMode, bool finishedWithMedia = false) override;
void setVideoLayerFrame(WebCore::FloatRect) override;
void setVideoLayerGravity(WebCore::MediaPlayerEnums::VideoGravity) override;
void fullscreenModeChanged(WebCore::HTMLMediaElementEnums::VideoFullscreenMode) override;
bool hasVideo() const override { return m_hasVideo; }
WebCore::FloatSize videoDimensions() const override { return m_videoDimensions; }
#if PLATFORM(IOS_FAMILY)
UIViewController *presentingViewController() final;
UIViewController *createVideoFullscreenViewController(AVPlayerViewController*) final;
#endif
void willEnterPictureInPicture() final;
void didEnterPictureInPicture() final;
void failedToEnterPictureInPicture() final;
void willExitPictureInPicture() final;
void didExitPictureInPicture() final;
void requestRouteSharingPolicyAndContextUID(CompletionHandler<void(WebCore::RouteSharingPolicy, String)>&&) final;
void requestUpdateInlineRect() final;
void requestVideoContentLayer() final;
void returnVideoContentLayer() final;
void didSetupFullscreen() final;
void didEnterFullscreen(const WebCore::FloatSize&) final;
void willExitFullscreen() final;
void didExitFullscreen() final;
void didCleanupFullscreen() final;
void fullscreenMayReturnToInline() final;
VideoFullscreenManagerProxy* m_manager;
Ref<PlaybackSessionModelContext> m_playbackSessionModel;
PlaybackSessionContextIdentifier m_contextId;
RetainPtr<PlatformView> m_layerHostView;
HashSet<WebCore::VideoFullscreenModelClient*> m_clients;
WebCore::FloatSize m_videoDimensions;
bool m_hasVideo { false };
};
class VideoFullscreenManagerProxyClient : public CanMakeWeakPtr<VideoFullscreenManagerProxyClient> {
public:
virtual ~VideoFullscreenManagerProxyClient() { };
virtual void hasVideoInPictureInPictureDidChange(bool value) = 0;
};
class VideoFullscreenManagerProxy : public RefCounted<VideoFullscreenManagerProxy>, private IPC::MessageReceiver {
public:
static Ref<VideoFullscreenManagerProxy> create(WebPageProxy&, PlaybackSessionManagerProxy&);
virtual ~VideoFullscreenManagerProxy();
void invalidate();
void requestHideAndExitFullscreen();
bool hasMode(WebCore::HTMLMediaElementEnums::VideoFullscreenMode) const;
bool mayAutomaticallyShowVideoPictureInPicture() const;
void applicationDidBecomeActive();
bool isVisible() const;
void setMockVideoPresentationModeEnabled(bool enabled) { m_mockVideoPresentationModeEnabled = enabled; }
void requestRouteSharingPolicyAndContextUID(PlaybackSessionContextIdentifier, CompletionHandler<void(WebCore::RouteSharingPolicy, String)>&&);
bool isPlayingVideoInEnhancedFullscreen() const;
PlatformVideoFullscreenInterface* controlsManagerInterface();
void setClient(VideoFullscreenManagerProxyClient* client) { m_client = makeWeakPtr(client); }
VideoFullscreenManagerProxyClient* client() const { return m_client.get(); }
void forEachSession(Function<void(WebCore::VideoFullscreenModel&, PlatformVideoFullscreenInterface&)>&&);
private:
friend class VideoFullscreenModelContext;
explicit VideoFullscreenManagerProxy(WebPageProxy&, PlaybackSessionManagerProxy&);
void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
typedef std::tuple<RefPtr<VideoFullscreenModelContext>, RefPtr<PlatformVideoFullscreenInterface>> ModelInterfaceTuple;
ModelInterfaceTuple createModelAndInterface(PlaybackSessionContextIdentifier);
ModelInterfaceTuple& ensureModelAndInterface(PlaybackSessionContextIdentifier);
VideoFullscreenModelContext& ensureModel(PlaybackSessionContextIdentifier);
PlatformVideoFullscreenInterface& ensureInterface(PlaybackSessionContextIdentifier);
PlatformVideoFullscreenInterface* findInterface(PlaybackSessionContextIdentifier);
void ensureClientForContext(PlaybackSessionContextIdentifier);
void addClientForContext(PlaybackSessionContextIdentifier);
void removeClientForContext(PlaybackSessionContextIdentifier);
void hasVideoInPictureInPictureDidChange(bool);
void setupFullscreenWithID(PlaybackSessionContextIdentifier, WebKit::LayerHostingContextID videoLayerID, const WebCore::IntRect& initialRect, const WebCore::FloatSize& videoDimensions, float hostingScaleFactor, WebCore::HTMLMediaElementEnums::VideoFullscreenMode, bool allowsPictureInPicture, bool standby, bool blocksReturnToFullscreenFromPictureInPicture);
void setInlineRect(PlaybackSessionContextIdentifier, const WebCore::IntRect& inlineRect, bool visible);
void setHasVideoContentLayer(PlaybackSessionContextIdentifier, bool value);
void setHasVideo(PlaybackSessionContextIdentifier, bool);
void setVideoDimensions(PlaybackSessionContextIdentifier, const WebCore::FloatSize&);
void enterFullscreen(PlaybackSessionContextIdentifier);
void exitFullscreen(PlaybackSessionContextIdentifier, WebCore::IntRect finalRect, CompletionHandler<void(bool)>&&);
void cleanupFullscreen(PlaybackSessionContextIdentifier);
void preparedToReturnToInline(PlaybackSessionContextIdentifier, bool visible, WebCore::IntRect inlineRect);
void preparedToExitFullscreen(PlaybackSessionContextIdentifier);
void exitFullscreenWithoutAnimationToMode(PlaybackSessionContextIdentifier, WebCore::HTMLMediaElementEnums::VideoFullscreenMode);
void requestFullscreenMode(PlaybackSessionContextIdentifier, WebCore::HTMLMediaElementEnums::VideoFullscreenMode, bool finishedWithMedia = false);
void requestUpdateInlineRect(PlaybackSessionContextIdentifier);
void requestVideoContentLayer(PlaybackSessionContextIdentifier);
void returnVideoContentLayer(PlaybackSessionContextIdentifier);
void didSetupFullscreen(PlaybackSessionContextIdentifier);
void willExitFullscreen(PlaybackSessionContextIdentifier);
void didExitFullscreen(PlaybackSessionContextIdentifier);
void didEnterFullscreen(PlaybackSessionContextIdentifier, const WebCore::FloatSize&);
void didCleanupFullscreen(PlaybackSessionContextIdentifier);
void setVideoLayerFrame(PlaybackSessionContextIdentifier, WebCore::FloatRect);
void setVideoLayerGravity(PlaybackSessionContextIdentifier, WebCore::MediaPlayerEnums::VideoGravity);
void fullscreenModeChanged(PlaybackSessionContextIdentifier, WebCore::HTMLMediaElementEnums::VideoFullscreenMode);
void fullscreenMayReturnToInline(PlaybackSessionContextIdentifier);
bool m_mockVideoPresentationModeEnabled { false };
WebCore::FloatSize m_mockPictureInPictureWindowSize { DefaultMockPictureInPictureWindowWidth, DefaultMockPictureInPictureWindowHeight };
WebPageProxy* m_page;
Ref<PlaybackSessionManagerProxy> m_playbackSessionManagerProxy;
HashMap<PlaybackSessionContextIdentifier, ModelInterfaceTuple> m_contextMap;
PlaybackSessionContextIdentifier m_controlsManagerContextId;
HashMap<PlaybackSessionContextIdentifier, int> m_clientCounts;
WeakPtr<VideoFullscreenManagerProxyClient> m_client;
};
}
#endif // ENABLE(VIDEO_PRESENTATION_MODE)