VideoFullscreenManagerProxy.h [plain text]
#pragma once
#if (PLATFORM(IOS) && HAVE(AVKIT)) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))
#include "GenericCallback.h"
#include "MessageReceiver.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)
#include <WebCore/VideoFullscreenInterfaceAVKit.h>
#else
#include <WebCore/VideoFullscreenInterfaceMac.h>
#endif
#if PLATFORM(IOS)
typedef WebCore::VideoFullscreenInterfaceAVKit PlatformVideoFullscreenInterface;
#else
typedef WebCore::VideoFullscreenInterfaceMac PlatformVideoFullscreenInterface;
#endif
namespace WebKit {
class WebPageProxy;
class PlaybackSessionManagerProxy;
class PlaybackSessionModelContext;
class VideoFullscreenManagerProxy;
typedef GenericCallback<WebCore::RouteSharingPolicy, String> RequestRouteSharingPolicyAndContextUIDCallback;
class VideoFullscreenModelContext final
: public RefCounted<VideoFullscreenModelContext>
, public WebCore::VideoFullscreenModel
, public WebCore::VideoFullscreenChangeObserver {
public:
static Ref<VideoFullscreenModelContext> create(VideoFullscreenManagerProxy& manager, PlaybackSessionModelContext& playbackSessionModel, uint64_t 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&, uint64_t);
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(VideoGravity) override;
void fullscreenModeChanged(WebCore::HTMLMediaElementEnums::VideoFullscreenMode) override;
bool isVisible() const override;
bool hasVideo() const override { return m_hasVideo; }
WebCore::FloatSize videoDimensions() const override { return m_videoDimensions; }
#if PLATFORM(IOS)
UIViewController *presentingViewController() final;
UIViewController *createVideoFullscreenViewController(AVPlayerViewController*) final;
#endif
void requestRouteSharingPolicyAndContextUID(CompletionHandler<void(WebCore::RouteSharingPolicy, String)>&&) final;
void requestUpdateInlineRect() final;
void requestVideoContentLayer() final;
void returnVideoContentLayer() final;
void didSetupFullscreen() final;
void didEnterFullscreen() final;
void willExitFullscreen() final;
void didExitFullscreen() final;
void didCleanupFullscreen() final;
void fullscreenMayReturnToInline() final;
VideoFullscreenManagerProxy* m_manager;
Ref<PlaybackSessionModelContext> m_playbackSessionModel;
uint64_t m_contextId;
RetainPtr<PlatformView *> m_layerHostView;
HashSet<WebCore::VideoFullscreenModelClient*> m_clients;
WebCore::FloatSize m_videoDimensions;
bool m_hasVideo { false };
};
class VideoFullscreenManagerProxy : public RefCounted<VideoFullscreenManagerProxy>, private IPC::MessageReceiver {
public:
static RefPtr<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 requestRouteSharingPolicyAndContextUID(uint64_t contextId, CompletionHandler<void(WebCore::RouteSharingPolicy, String)>&&);
#if ENABLE(VIDEO_PRESENTATION_MODE)
bool isPlayingVideoInEnhancedFullscreen() const;
#endif
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(uint64_t contextId);
ModelInterfaceTuple& ensureModelAndInterface(uint64_t contextId);
VideoFullscreenModelContext& ensureModel(uint64_t contextId);
PlatformVideoFullscreenInterface& ensureInterface(uint64_t contextId);
void addClientForContext(uint64_t contextId);
void removeClientForContext(uint64_t contextId);
void setupFullscreenWithID(uint64_t contextId, uint32_t videoLayerID, const WebCore::IntRect& initialRect, float hostingScaleFactor, WebCore::HTMLMediaElementEnums::VideoFullscreenMode, bool allowsPictureInPicture, bool standby);
void setInlineRect(uint64_t contextId, const WebCore::IntRect& inlineRect, bool visible);
void setHasVideoContentLayer(uint64_t contextId, bool value);
void setHasVideo(uint64_t contextId, bool);
void setVideoDimensions(uint64_t contextId, const WebCore::FloatSize&);
void enterFullscreen(uint64_t contextId);
void exitFullscreen(uint64_t contextId, WebCore::IntRect finalRect);
void cleanupFullscreen(uint64_t contextId);
void preparedToReturnToInline(uint64_t contextId, bool visible, WebCore::IntRect inlineRect);
void preparedToExitFullscreen(uint64_t contextId);
#if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
void exitFullscreenWithoutAnimationToMode(uint64_t contextId, WebCore::HTMLMediaElementEnums::VideoFullscreenMode);
#endif
void requestRouteSharingPolicyAndContextUIDCallback(WebCore::RouteSharingPolicy, String, WebKit::CallbackID);
void requestFullscreenMode(uint64_t contextId, WebCore::HTMLMediaElementEnums::VideoFullscreenMode, bool finishedWithMedia = false);
void requestUpdateInlineRect(uint64_t contextId);
void requestVideoContentLayer(uint64_t contextId);
void returnVideoContentLayer(uint64_t contextId);
void didSetupFullscreen(uint64_t contextId);
void willExitFullscreen(uint64_t contextId);
void didExitFullscreen(uint64_t contextId);
void didEnterFullscreen(uint64_t contextId);
void didCleanupFullscreen(uint64_t contextId);
void setVideoLayerFrame(uint64_t contextId, WebCore::FloatRect);
void setVideoLayerGravity(uint64_t contextId, WebCore::VideoFullscreenModel::VideoGravity);
void fullscreenModeChanged(uint64_t contextId, WebCore::HTMLMediaElementEnums::VideoFullscreenMode);
void fullscreenMayReturnToInline(uint64_t contextId);
WebPageProxy* m_page;
Ref<PlaybackSessionManagerProxy> m_playbackSessionManagerProxy;
HashMap<uint64_t, ModelInterfaceTuple> m_contextMap;
uint64_t m_controlsManagerContextId { 0 };
HashMap<uint64_t, int> m_clientCounts;
CallbackMap m_callbacks;
};
}
#endif // PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))