Skip to content

Commit

Permalink
Configure now playing media session to support external playback
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=287684
rdar://137156850

Reviewed by Andy Estes.

Add a new visionOS WKWebView method to enable configuring the now playing media
session for external playback. This puts the visionOS media player into a
custom presentation (external) and returns the media player's view controller
to the caller who has the responsibility to present it. It also provides a method
to exit this external playback.

On entering presentation, it sets the playerIdentifier for the video element
which normally gets set as part of the fullscreen flow but we are bypassing that
route in this mode -- without this the media player will not be able to render.
It also puts LinearMediaPlayer in a new presentationState (.external) which
allows WebKit to configure the player as needed without affecting video playing
outside of this feature. Finally, it makes and returns the player view
controller.

On exiting presentation, it sets the state of linearMediaPlayer back to .inline
presentation and tears down the configuration. Importantly, it clears the video
receiver endpoint to allow the media session to render in its non-LMK
presentation.

While this mode is similar conceptually to fullscreen, it intentionally does not
latch onto the fullscreen element state, as it should be a separate mode and the
media element should not falsely believe it is in a fullscreen presentation.
While in external presentation, fullscreen mode is prevented from being entered.

Note: Remove LinearMediaPlayer's fullscreenSceneBehavior property until it is
able to be published (rdar://122435030).

* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::setPlayerIdentifierForVideoElement):
* Source/WebCore/html/HTMLMediaElement.h:
* Source/WebCore/page/ChromeClient.h:
(WebCore::ChromeClient::setPlayerIdentifierForVideoElement):
* Source/WebCore/platform/cocoa/PlaybackSessionModel.h:
* Source/WebCore/platform/cocoa/PlaybackSessionModelMediaElement.h:
* Source/WebCore/platform/cocoa/PlaybackSessionModelMediaElement.mm:
(WebCore::PlaybackSessionModelMediaElement::setPlayerIdentifierForVideoElement):
* Source/WebCore/platform/ios/PlaybackSessionInterfaceIOS.h:
* Source/WebCore/platform/ios/PlaybackSessionInterfaceIOS.mm:
(WebCore::PlaybackSessionInterfaceIOS::setVideoPresentationInterface):
* Source/WebCore/platform/ios/VideoPresentationInterfaceIOS.h:
* Source/WebCore/platform/ios/VideoPresentationInterfaceIOS.mm:
(WebCore::VideoPresentationInterfaceIOS::VideoPresentationInterfaceIOS):
(WebCore::VideoPresentationInterfaceIOS::enterExternalPlayback):
(WebCore::VideoPresentationInterfaceIOS::exitExternalPlayback):
* Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm:
* Source/WebKit/Platform/ios/PlaybackSessionInterfaceLMK.mm:
(-[WKLinearMediaPlayerDelegate linearMediaPlayerClearVideoReceiverEndpoint:]):
(WebKit::PlaybackSessionInterfaceLMK::supportsLinearMediaPlayerChanged):
* Source/WebKit/Platform/ios/VideoPresentationInterfaceLMK.h:
* Source/WebKit/Platform/ios/VideoPresentationInterfaceLMK.mm:
(WebKit::VideoPresentationInterfaceLMK::enterExternalPlayback):
(WebKit::VideoPresentationInterfaceLMK::exitExternalPlayback):
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _enterExternalPlaybackForNowPlayingMediaSessionWithCompletionHandler:]):
(-[WKWebView _exitExternalPlaybackWithCompletionHandler:]):
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h:
* Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.h:
* Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.mm:
(WebKit::PlaybackSessionModelContext::setPlayerIdentifierForVideoElement):
(WebKit::PlaybackSessionManagerProxy::setPlayerIdentifierForVideoElement):
* Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::WebPageProxy::enterExternalPlaybackForNowPlayingMediaSession):
(WebKit::WebPageProxy::exitExternalPlayback):
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::setPlayerIdentifierForVideoElement):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/WebKitSwift/LinearMediaKit/LinearMediaPlayer.swift:
(SwiftOnlyData.fullscreenSceneBehaviors):
(WKSLinearMediaPlayer.enterExternalPresentation(_:(any Error)?) -> Void:)):
(WKSLinearMediaPlayer.exitExternalPresentation(_:(any Error)?) -> Void:)):
(WKSLinearMediaPlayer.enterFullscreen(_:(any Error)?) -> Void:)):
(WKSLinearMediaPlayer.exitFullscreen(_:(any Error)?) -> Void:)):
(WKSLinearMediaPlayer.presentationStateChanged(_:)):
(WKSLinearMediaPlayer.fullscreenSceneBehaviorsPublisher):
(WKSLinearMediaPlayer.toggleInlineMode):
(WKSLinearMediaPlayer.willEnterFullscreen):
(WKSLinearMediaPlayer.willExitFullscreen):
* Source/WebKit/WebKitSwift/LinearMediaKit/LinearMediaTypes.swift:
(WKSLinearMediaPresentationState.description):
* Source/WebKit/WebKitSwift/LinearMediaKit/WKSLinearMediaPlayer.h:
* Source/WebKit/WebKitSwift/LinearMediaKit/WKSLinearMediaTypes.h:
* Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::setPlayerIdentifierForVideoElement):
* Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h:
* Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.h:
* Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.messages.in:
* Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.mm:
(WebKit::PlaybackSessionManager::setPlayerIdentifierForVideoElement):
* Source/WebKit/WebProcess/cocoa/VideoPresentationManager.h:
* Source/WebKit/WebProcess/cocoa/VideoPresentationManager.mm:
(WebKit::VideoPresentationManager::setPlayerIdentifierForVideoElement):

Canonical link: https://commits.webkit.org/290837@main
  • Loading branch information
rsfuller authored and aestes committed Feb 22, 2025
1 parent 32a639f commit d1ed61f
Show file tree
Hide file tree
Showing 34 changed files with 324 additions and 10 deletions.
18 changes: 18 additions & 0 deletions Source/WebCore/html/HTMLMediaElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7295,6 +7295,24 @@ bool HTMLMediaElement::videoUsesElementFullscreen() const
return false;
}

void HTMLMediaElement::setPlayerIdentifierForVideoElement()
{
ALWAYS_LOG(LOGIDENTIFIER);

RefPtr page = document().page();
if (!page || page->mediaPlaybackIsSuspended())
return;

RefPtr window = document().domWindow();
if (!window)
return;

if (RefPtr asVideo = dynamicDowncast<HTMLVideoElement>(*this)) {
auto& client = document().page()->chrome().client();
client.setPlayerIdentifierForVideoElement(*asVideo);
}
}

void HTMLMediaElement::enterFullscreen(VideoFullscreenMode mode)
{
ALWAYS_LOG(LOGIDENTIFIER, ", m_videoFullscreenMode = ", m_videoFullscreenMode, ", mode = ", mode);
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/html/HTMLMediaElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ class HTMLMediaElement
VideoFullscreenMode fullscreenMode() const { return m_videoFullscreenMode; }

void enterFullscreen(VideoFullscreenMode);
WEBCORE_EXPORT void setPlayerIdentifierForVideoElement();
WEBCORE_EXPORT void enterFullscreen() override;
WEBCORE_EXPORT void exitFullscreen();
WEBCORE_EXPORT void prepareForVideoFullscreenStandby();
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/page/ChromeClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ class ChromeClient {
#endif

#if ENABLE(VIDEO)
virtual void setPlayerIdentifierForVideoElement(HTMLVideoElement&) { }
virtual void enterVideoFullscreenForVideoElement(HTMLVideoElement&, HTMLMediaElementEnums::VideoFullscreenMode, bool standby) { UNUSED_PARAM(standby); }
virtual void setUpPlaybackControlsManager(HTMLMediaElement&) { }
virtual void clearPlaybackControlsManager() { }
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/platform/cocoa/PlaybackSessionModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class PlaybackSessionModel : public CanMakeWeakPtr<PlaybackSessionModel> {
virtual void togglePictureInPicture() = 0;
virtual void enterInWindowFullscreen() = 0;
virtual void exitInWindowFullscreen() = 0;
virtual void setPlayerIdentifierForVideoElement() = 0;
virtual void enterFullscreen() = 0;
virtual void exitFullscreen() = 0;
virtual void toggleMuted() = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class PlaybackSessionModelMediaElement final
WEBCORE_EXPORT void enterInWindowFullscreen() final;
WEBCORE_EXPORT void exitInWindowFullscreen() final;
WEBCORE_EXPORT void enterFullscreen() final;
WEBCORE_EXPORT void setPlayerIdentifierForVideoElement() final;
WEBCORE_EXPORT void exitFullscreen() final;
WEBCORE_EXPORT void toggleMuted() final;
WEBCORE_EXPORT void setMuted(bool) final;
Expand Down
10 changes: 10 additions & 0 deletions Source/WebCore/platform/cocoa/PlaybackSessionModelMediaElement.mm
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,16 @@
element->enterFullscreenIgnoringPermissionsPolicy();
}

void PlaybackSessionModelMediaElement::setPlayerIdentifierForVideoElement()
{
RefPtr element = dynamicDowncast<HTMLVideoElement>(m_mediaElement);
ASSERT(element);
if (!element)
return;

element->setPlayerIdentifierForVideoElement();
}

void PlaybackSessionModelMediaElement::exitFullscreen()
{
RefPtr element = dynamicDowncast<HTMLVideoElement>(m_mediaElement);
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/platform/ios/PlaybackSessionInterfaceIOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace WebCore {

class IntRect;
class PlaybackSessionModel;
class VideoPresentationInterfaceIOS;
class WebPlaybackSessionChangeObserver;

class WEBCORE_EXPORT PlaybackSessionInterfaceIOS
Expand Down Expand Up @@ -81,6 +82,7 @@ class WEBCORE_EXPORT PlaybackSessionInterfaceIOS

std::optional<MediaPlayerIdentifier> playerIdentifier() const;
void setPlayerIdentifier(std::optional<MediaPlayerIdentifier>);
void setVideoPresentationInterface(WeakPtr<VideoPresentationInterfaceIOS>);

virtual void startObservingNowPlayingMetadata();
virtual void stopObservingNowPlayingMetadata();
Expand Down Expand Up @@ -108,6 +110,8 @@ class WEBCORE_EXPORT PlaybackSessionInterfaceIOS
void incrementCheckedPtrCount() const final;
void decrementCheckedPtrCount() const final;

WeakPtr<VideoPresentationInterfaceIOS> m_videoPresentationInterface;

private:
std::optional<MediaPlayerIdentifier> m_playerIdentifier;
#if HAVE(SPATIAL_TRACKING_LABEL)
Expand Down
5 changes: 5 additions & 0 deletions Source/WebCore/platform/ios/PlaybackSessionInterfaceIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@
m_playerIdentifier = WTFMove(identifier);
}

void PlaybackSessionInterfaceIOS::setVideoPresentationInterface(WeakPtr<VideoPresentationInterfaceIOS> videoPresentationInterface)
{
m_videoPresentationInterface = WTFMove(videoPresentationInterface);
}

void PlaybackSessionInterfaceIOS::startObservingNowPlayingMetadata()
{
}
Expand Down
5 changes: 5 additions & 0 deletions Source/WebCore/platform/ios/VideoPresentationInterfaceIOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class VideoPresentationInterfaceIOS
WTF_MAKE_TZONE_ALLOCATED_EXPORT(VideoPresentationInterfaceIOS, WEBCORE_EXPORT);
WTF_OVERRIDE_DELETE_FOR_CHECKED_PTR(VideoPresentationInterfaceIOS);
public:
USING_CAN_MAKE_WEAKPTR(VideoPresentationModelClient);

WEBCORE_EXPORT ~VideoPresentationInterfaceIOS();

// CheckedPtr interface
Expand Down Expand Up @@ -103,6 +105,8 @@ class VideoPresentationInterfaceIOS
WEBCORE_EXPORT void preparedToReturnToStandby();
bool changingStandbyOnly() { return m_changingStandbyOnly; }
WEBCORE_EXPORT void failedToRestoreFullscreen();
WEBCORE_EXPORT virtual void enterExternalPlayback(CompletionHandler<void(bool, UIViewController *)>&&);
WEBCORE_EXPORT virtual void exitExternalPlayback(CompletionHandler<void(bool)>&&);

enum class ExitFullScreenReason {
DoneButtonTapped,
Expand Down Expand Up @@ -218,6 +222,7 @@ class VideoPresentationInterfaceIOS
virtual void updateRouteSharingPolicy() = 0;
virtual void setupPlayerViewController() = 0;
virtual void invalidatePlayerViewController() = 0;
virtual bool cleanupExternalPlayback() { return false; }
virtual UIViewController *playerViewController() const = 0;
WEBCORE_EXPORT void doSetup();

Expand Down
17 changes: 17 additions & 0 deletions Source/WebCore/platform/ios/VideoPresentationInterfaceIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ @interface UIViewController ()
: m_watchdogTimer(RunLoop::main(), this, &VideoPresentationInterfaceIOS::watchdogTimerFired)
, m_playbackSessionInterface(playbackSessionInterface)
{
m_playbackSessionInterface->setVideoPresentationInterface(this);
}

VideoPresentationInterfaceIOS::~VideoPresentationInterfaceIOS()
Expand Down Expand Up @@ -369,6 +370,16 @@ @interface UIViewController ()
[playerLayerView() setHidden:enabled];
}

void VideoPresentationInterfaceIOS::enterExternalPlayback(CompletionHandler<void(bool, UIViewController *)>&& completionHandler)
{
completionHandler(false, nil);
}

void VideoPresentationInterfaceIOS::exitExternalPlayback(CompletionHandler<void(bool)>&& completionHandler)
{
completionHandler(false);
}

void VideoPresentationInterfaceIOS::setInlineRect(const FloatRect& inlineRect, bool visible)
{
m_inlineRect = inlineRect;
Expand Down Expand Up @@ -583,6 +594,12 @@ @interface UIViewController ()
void VideoPresentationInterfaceIOS::cleanupFullscreen()
{
LOG(Fullscreen, "VideoPresentationInterfaceIOS::cleanupFullscreen(%p)", this);

if (this->cleanupExternalPlayback()) {
ASSERT(m_currentMode == HTMLMediaElementEnums::VideoFullscreenModeNone);
return;
}

m_shouldIgnoreAVKitCallbackAboutExitFullscreenReason = false;

m_cleanupNeedsReturnVideoContentLayer = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ void togglePictureInPicture() override { }
void enterInWindowFullscreen() override { }
void exitInWindowFullscreen() override { }
void enterFullscreen() override { }
void setPlayerIdentifierForVideoElement() final { }
void toggleMuted() override;
void setMuted(bool) final;
void setVolume(double) final;
Expand Down
13 changes: 13 additions & 0 deletions Source/WebKit/Platform/ios/PlaybackSessionInterfaceLMK.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#if ENABLE(LINEAR_MEDIA_PLAYER)

#import "VideoPresentationInterfaceLMK.h"
#import "WKSLinearMediaPlayer.h"
#import "WKSLinearMediaTypes.h"
#import <WebCore/MediaSelectionOption.h>
Expand Down Expand Up @@ -215,6 +216,12 @@ - (void)linearMediaPlayer:(WKSLinearMediaPlayer *)player setVideoReceiverEndpoin
model->setVideoReceiverEndpoint(videoReceiverEndpoint);
}

- (void)linearMediaPlayerClearVideoReceiverEndpoint:(WKSLinearMediaPlayer *)player
{
if (auto model = _model.get())
model->setVideoReceiverEndpoint(nullptr);
}

@end

namespace WebKit {
Expand Down Expand Up @@ -358,6 +365,12 @@ - (void)linearMediaPlayer:(WKSLinearMediaPlayer *)player setVideoReceiverEndpoin
if (m_playbackSessionModel)
m_playbackSessionModel->exitFullscreen();
break;
case WKSLinearMediaPresentationStateExternal:
// If the player is in external presentation (which uses LinearMediaPlayer) but the current
// media engine does not support it, exit external presentation.
if (RefPtr videoPresentationInterface = m_videoPresentationInterface.get())
videoPresentationInterface->exitExternalPlayback([](bool) { });
break;
case WKSLinearMediaPresentationStateInline:
case WKSLinearMediaPresentationStateExitingFullscreen:
break;
Expand Down
3 changes: 3 additions & 0 deletions Source/WebKit/Platform/ios/VideoPresentationInterfaceLMK.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class VideoPresentationInterfaceLMK final : public WebCore::VideoPresentationInt
void setupPlayerViewController() final;
void invalidatePlayerViewController() final;
UIViewController *playerViewController() const final;
void enterExternalPlayback(CompletionHandler<void(bool, UIViewController *)> &&) final;
void exitExternalPlayback(CompletionHandler<void(bool)>&&) final;
void tryToStartPictureInPicture() final { }
void stopPictureInPicture() final { }
void presentFullscreen(bool animated, Function<void(BOOL, NSError *)>&&) final;
Expand All @@ -73,6 +75,7 @@ class VideoPresentationInterfaceLMK final : public WebCore::VideoPresentationInt
void setContentDimensions(const WebCore::FloatSize&) final;
void setAllowsPictureInPicturePlayback(bool) final { }
bool isExternalPlaybackActive() const final { return false; }
bool cleanupExternalPlayback() final;
bool willRenderToLayer() const final { return false; }
AVPlayerViewController *avPlayerViewController() const final { return nullptr; }
CALayer *captionsLayer() final;
Expand Down
51 changes: 51 additions & 0 deletions Source/WebKit/Platform/ios/VideoPresentationInterfaceLMK.mm
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,57 @@ - (void)layoutSublayers
}).get()];
}

void VideoPresentationInterfaceLMK::enterExternalPlayback(CompletionHandler<void(bool, UIViewController *)>&& completionHandler)
{
ALWAYS_LOG_IF_POSSIBLE(LOGIDENTIFIER);

if (linearMediaPlayer().presentationState != WKSLinearMediaPresentationStateInline) {
completionHandler(false, nil);
return;
}
setupPlayerViewController();

playbackSessionInterface().startObservingNowPlayingMetadata();
[linearMediaPlayer() enterExternalPresentationWithCompletionHandler:makeBlockPtr([this, protectedThis = Ref { *this }, completionHandler = WTFMove(completionHandler)] (BOOL success, NSError *error) mutable {
if (auto* playbackSessionModel = this->playbackSessionModel()) {
playbackSessionModel->setSpatialTrackingLabel(m_spatialTrackingLabel);
playbackSessionModel->setSoundStageSize(WebCore::AudioSessionSoundStageSize::Large);
}
completionHandler(success, m_playerViewController.get());
}).get()];
}

void VideoPresentationInterfaceLMK::exitExternalPlayback(CompletionHandler<void(bool)>&& completionHandler)
{
ALWAYS_LOG_IF_POSSIBLE(LOGIDENTIFIER);

if (linearMediaPlayer().presentationState != WKSLinearMediaPresentationStateExternal) {
completionHandler(false);
return;
}

playbackSessionInterface().stopObservingNowPlayingMetadata();
[linearMediaPlayer() exitExternalPresentationWithCompletionHandler:makeBlockPtr([this, protectedThis = Ref { *this }, completionHandler = WTFMove(completionHandler)] (BOOL success, NSError *error) mutable {
if (auto* playbackSessionModel = this->playbackSessionModel()) {
playbackSessionModel->setSpatialTrackingLabel(nullString());
playbackSessionModel->setSoundStageSize(WebCore::AudioSessionSoundStageSize::Automatic);
}
invalidatePlayerViewController();
completionHandler(success);
}).get()];
}

bool VideoPresentationInterfaceLMK::cleanupExternalPlayback()
{
if (linearMediaPlayer().presentationState != WKSLinearMediaPresentationStateExternal)
return false;

ALWAYS_LOG_IF_POSSIBLE(LOGIDENTIFIER);

exitExternalPlayback([](bool) { });
return true;
}

UIViewController *VideoPresentationInterfaceLMK::playerViewController() const
{
return m_playerViewController.get();
Expand Down
3 changes: 3 additions & 0 deletions Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,9 @@ typedef NS_OPTIONS(NSUInteger, _WKWebViewDataType) {
#if TARGET_OS_VISION
@interface WKWebView (WKPrivateVision)
@property (copy, setter=_setDefaultSTSLabel:) NSString *_defaultSTSLabel;

- (void)_enterExternalPlaybackForNowPlayingMediaSessionWithCompletionHandler:(void (^)(UIViewController *nowPlayingViewController, NSError *error))completionHandler WK_API_AVAILABLE(visionos(WK_XROS_TBA));
- (void)_exitExternalPlaybackWithCompletionHandler:(void (^)(NSError *error))completionHandler WK_API_AVAILABLE(visionos(WK_XROS_TBA));
@end
#endif

Expand Down
29 changes: 29 additions & 0 deletions Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#import "WKBackForwardListItemInternal.h"
#import "WKContentViewInteraction.h"
#import "WKDataDetectorTypesInternal.h"
#import "WKErrorInternal.h"
#import "WKPasswordView.h"
#import "WKProcessPoolPrivate.h"
#import "WKScrollView.h"
Expand Down Expand Up @@ -4942,6 +4943,34 @@ - (void)_setDefaultSTSLabel:(NSString *)defaultSTSLabel
{
_page->setDefaultSpatialTrackingLabel(defaultSTSLabel);
}

- (void)_enterExternalPlaybackForNowPlayingMediaSessionWithCompletionHandler:(void(^)(UIViewController *, NSError *))completionHandler
{
if (!_page) {
completionHandler(nil, [NSError errorWithDomain:WKErrorDomain code:WKErrorUnknown userInfo:nil]);
return;
}

_page->setPlayerIdentifierForVideoElement();
_page->enterExternalPlaybackForNowPlayingMediaSession([handler = makeBlockPtr(completionHandler)](bool entered, UIViewController *viewController) {
if (entered)
handler(viewController, nil);
else
handler(nil, createNSError(WKErrorUnknown).get());
});
}

- (void)_exitExternalPlaybackWithCompletionHandler:(void (^)(NSError *error))completionHandler
{
if (!_page) {
completionHandler([NSError errorWithDomain:WKErrorDomain code:WKErrorUnknown userInfo:nil]);
return;
}

_page->exitExternalPlayback([handler = makeBlockPtr(completionHandler)](bool success) {
handler(success ? nil : createNSError(WKErrorUnknown).get());
});
}
@end
#endif

Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class PlaybackSessionModelContext final
void enterInWindowFullscreen() final;
void exitInWindowFullscreen() final;
void enterFullscreen() final;
void setPlayerIdentifierForVideoElement() final;
void exitFullscreen() final;
void toggleMuted() final;
void setMuted(bool) final;
Expand Down Expand Up @@ -320,6 +321,7 @@ class PlaybackSessionManagerProxy
void selectLegibleMediaOption(PlaybackSessionContextIdentifier, uint64_t index);
void togglePictureInPicture(PlaybackSessionContextIdentifier);
void enterFullscreen(PlaybackSessionContextIdentifier);
void setPlayerIdentifierForVideoElement(PlaybackSessionContextIdentifier);
void exitFullscreen(PlaybackSessionContextIdentifier);
void enterInWindow(PlaybackSessionContextIdentifier);
void exitInWindow(PlaybackSessionContextIdentifier);
Expand Down
13 changes: 13 additions & 0 deletions Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.mm
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@
manager->enterFullscreen(m_contextId);
}

void PlaybackSessionModelContext::setPlayerIdentifierForVideoElement()
{
ALWAYS_LOG_IF_POSSIBLE(LOGIDENTIFIER);
if (RefPtr manager = m_manager.get())
manager->setPlayerIdentifierForVideoElement(m_contextId);
}

void PlaybackSessionModelContext::exitFullscreen()
{
ALWAYS_LOG_IF_POSSIBLE(LOGIDENTIFIER);
Expand Down Expand Up @@ -915,6 +922,12 @@
page->protectedLegacyMainFrameProcess()->send(Messages::PlaybackSessionManager::EnterFullscreen(contextId), page->webPageIDInMainFrameProcess());
}

void PlaybackSessionManagerProxy::setPlayerIdentifierForVideoElement(PlaybackSessionContextIdentifier contextId)
{
if (RefPtr page = m_page.get())
page->protectedLegacyMainFrameProcess()->send(Messages::PlaybackSessionManager::SetPlayerIdentifierForVideoElement(contextId), page->webPageIDInMainFrameProcess());
}

void PlaybackSessionManagerProxy::exitFullscreen(PlaybackSessionContextIdentifier contextId)
{
if (RefPtr page = m_page.get())
Expand Down
Loading

0 comments on commit d1ed61f

Please sign in to comment.