[webkit-changes] [WebKit/WebKit] 3ac8f1: Merge AVPictureInPictureController support into Vi...

Aditya Keerthi noreply at github.com
Fri Dec 16 13:35:57 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 3ac8f1b746a6c752f8418e12277dae7744565323
      https://github.com/WebKit/WebKit/commit/3ac8f1b746a6c752f8418e12277dae7744565323
  Author: Aditya Keerthi <akeerthi at apple.com>
  Date:   2022-12-16 (Fri, 16 Dec 2022)

  Changed paths:
    M Source/WebCore/PAL/pal/spi/cocoa/AVKitSPI.h
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/html/HTMLMediaElement.cpp
    R Source/WebCore/platform/cocoa/VideoFullscreenInterfacePiP.h
    R Source/WebCore/platform/cocoa/VideoFullscreenInterfacePiP.mm
    M Source/WebCore/platform/cocoa/WebAVPlayerLayer.h
    M Source/WebCore/platform/cocoa/WebAVPlayerLayer.mm
    M Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.mm
    M Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h
    M Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm
    M Source/WebCore/platform/ios/WebAVPlayerController.h
    M Source/WebCore/platform/ios/WebAVPlayerController.mm
    M Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm
    M Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.h
    M Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm
    M Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm

  Log Message:
  -----------
  Merge AVPictureInPictureController support into VideoFullscreenInterfaceAVKit
https://bugs.webkit.org/show_bug.cgi?id=245940
rdar://98579829

Reviewed by Dean Jackson.

An iteration of an original patch by Tim Horton.

Two problems:

1) VideoFullscreenInterfacePiP should not have been separated out from
VideoFullscreenInterfaceAVKit, because that precludes the use of normal
video fullscreen if VideoFullscreenInterfacePiP is enabled, which we need
in the case of API clients who do not enable element fullscreen.

2) Our forced invalid cast of WebAVPlayerController to AVPlayerController
is causing AVKit code that now strictly checks the type of the player controller
object (via Swift's `as!`) to crash.

Fix (1) by merging VideoFullscreenInterfacePiP back into VideoFullscreenInterfaceAVKit,
and only conditionalizing AVPlayerViewController vs. AVPictureInPictureController
for the purposes of PiP, leaving video fullscreen support intact.

Fix (2) by dynamically generating an AVPlayerController subclass that
removes all of AVPlayerController's methods, replacing them with ones from
a class that simply forwards all messages to an inner WebAVPlayerController instance.
This ensures that WebAVPlayerControllerForwarder (which we pass to AVKit as
an invalidly-casted `AVPlayerController`) actually (sort of) inherits
from AVPlayerController, but otherwise behaves as if it were an WebAVPlayerController.

* Source/WebCore/PAL/pal/spi/cocoa/AVKitSPI.h:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/html/HTMLMediaElement.cpp:
* Source/WebCore/platform/cocoa/VideoFullscreenInterfacePiP.h: Removed.
* Source/WebCore/platform/cocoa/VideoFullscreenInterfacePiP.mm: Removed.
* Source/WebCore/platform/cocoa/WebAVPlayerLayer.h:
* Source/WebCore/platform/cocoa/WebAVPlayerLayer.mm:
(-[WebAVPlayerLayer setPlayerController:]):
* Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.mm:
(WebCore::PlaybackSessionInterfaceAVKit::PlaybackSessionInterfaceAVKit):
* Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h:
* Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm:
(-[WebAVPlayerViewControllerDelegate pictureInPictureControllerWillStartPictureInPicture:]):
(-[WebAVPlayerViewControllerDelegate pictureInPictureControllerDidStartPictureInPicture:]):
(-[WebAVPlayerViewControllerDelegate pictureInPictureController:failedToStartPictureInPictureWithError:]):
(-[WebAVPlayerViewControllerDelegate pictureInPictureControllerWillStopPictureInPicture:]):
(-[WebAVPlayerViewControllerDelegate pictureInPictureControllerDidStopPictureInPicture:]):
(-[WebAVPlayerViewControllerDelegate pictureInPictureController:restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:]):
(WebAVPictureInPictureContentViewController_initWithController):
(WebAVPictureInPictureContentViewController_controller):
(WebAVPictureInPictureContentViewController_playerLayer):
(WebAVPictureInPictureContentViewController_setPlayerLayer):
(WebAVPictureInPictureContentViewController_viewWillLayoutSubviews):
(WebAVPictureInPictureContentViewController_dealloc):
(allocWebAVPictureInPictureContentViewControllerInstance):
(-[WebAVPlayerViewController initWithFullscreenInterface:]):
(-[WebAVPlayerViewController dealloc]):
(-[WebAVPlayerViewController playerViewControllerShouldHandleDoneButtonTap:]):
(-[WebAVPlayerViewController initObserver]):
(-[WebAVPlayerViewController removeObserver]):
(-[WebAVPlayerViewController MY_NO_RETURN]):
(-[WebAVPlayerViewController isPictureInPicturePossible]):
(-[WebAVPlayerViewController isPictureInPictureActive]):
(-[WebAVPlayerViewController pictureInPictureActive]):
(-[WebAVPlayerViewController pictureInPictureWasStartedWhenEnteringBackground]):
(-[WebAVPlayerViewController view]):
(-[WebAVPlayerViewController setDelegate:]):
(VideoFullscreenInterfaceAVKit::willStartPictureInPicture):

Merge in the useful parts of VideoFullscreenInterfacePiP. Decide if we use
AVPlayerViewController vs. AVPictureInPictureController for PiP at compile time.

* Source/WebCore/platform/ios/WebAVPlayerController.h:
* Source/WebCore/platform/ios/WebAVPlayerController.mm:

Add a simple class that just owns a WebAVPlayerController and forwards messages to it.

(-[WebAVPlayerControllerForwarder init]):
(-[WebAVPlayerControllerForwarder respondsToSelector:]):
(-[WebAVPlayerControllerForwarder forwardingTargetForSelector:]):
(-[WebAVPlayerControllerForwarder valueForKey:]):
(-[WebAVPlayerControllerForwarder valueForKeyPath:]):
(-[WebAVPlayerControllerForwarder valueForUndefinedKey:]):
(-[WebAVPlayerControllerForwarder addObserver:forKeyPath:options:context:]):
(-[WebAVPlayerControllerForwarder removeObserver:forKeyPath:context:]):
(-[WebAVPlayerControllerForwarder removeObserver:forKeyPath:]):
(-[WebAVPlayerControllerForwarder _forwardingTargetForKeyPath:]):

Only use the proxy object for key paths identifying undefined properties on
WebAVPlayerController. Properties such as contentDimensions and isPlaying
are defined on WebAVPlayerController, and are unchanged on the proxy object.

(createWebAVPlayerControllerForwarderClass):

Dynamically create a AVPlayerController subclass and move WebAVPlayerControllerForwarder's
implementation onto it. This is the object we'll actually hand to AVKit.

(createWebAVPlayerController):
(webAVPlayerControllerClass):
* Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm:
(VideoFullscreenControllerContext::setUpFullscreen):
* Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.h:
* Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm:
(WebKit::VideoFullscreenManagerProxy::playerViewController const):
* Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm:

Remove VideoFullscreenInterfacePiP.

Canonical link: https://commits.webkit.org/258013@main




More information about the webkit-changes mailing list