Skip to content

[Swift in WebKit] Fix Swift 6 warnings and errors in WKSLinearMediaPlayer #47043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

rr-codes
Copy link
Contributor

@rr-codes rr-codes commented Jun 23, 2025

facbe72

[Swift in WebKit] Fix Swift 6 warnings and errors in WKSLinearMediaPlayer
https://bugs.webkit.org/show_bug.cgi?id=294823
rdar://154057962

Reviewed by Andy Estes.

Address Swift 6 errors in WKSLinearMediaPlayer and related code.

- If it walks like a duck and talks like a duck... it's not always a duck. In this case, AVKit has a public
Swift class `PlayableViewController` and annotated with `@objc(LMPlayableViewController)`. This annotation
makes the type compatible and indistuinguishable from an Objective C type. However, Swift types cannot be accessed
by Objective-C in another framework; within their own framework, the Swift bridging header is used.

AVKit attempted to work around this by creating an Objective-C interface that was essentially a forward declaration
of `LMPlayableViewController`; this is an unsupported configuration as it removes all compile-time checking, which
results in the Swift compiler being confused.

To fix, the `LMPlayableViewController` type is now never used within WebKit; only the `PlayableViewController` type
is used from within Swift WebKit code. Consequently, a new wrapper type is created that abstracts the
`PlayableViewController` and exposes the needed symbols to Objective-C, so that the compiler can function properly.

- Use `@objc @implementation` instead of `@_objcImplementation`.

- Use `RealityKit` instead of the re-exported `RealityFoundation` module.

- Adopt `@preconcurrency` when needed, to silence errors due to the underlying framework symbols
not having proper annotations.

* Source/WebCore/platform/ios/VideoPresentationInterfaceAVKit.h:
* Source/WebCore/platform/ios/VideoPresentationInterfaceIOS.h:
(WebCore::VideoPresentationInterfaceIOS::playableViewController):
* Source/WebKit/Platform/ios/VideoPresentationInterfaceLMK.h:
* Source/WebKit/Platform/ios/VideoPresentationInterfaceLMK.mm:
(WebKit::VideoPresentationInterfaceLMK::setupFullscreen):
(WebKit::VideoPresentationInterfaceLMK::enterExternalPlayback):
(WebKit::VideoPresentationInterfaceLMK::playerViewController const):
(WebKit::VideoPresentationInterfaceLMK::playableViewController):
(WebKit::VideoPresentationInterfaceLMK::ensurePlayableViewController):
* Source/WebKit/UIProcess/Cocoa/VideoPresentationManagerProxy.h:
* Source/WebKit/UIProcess/Cocoa/VideoPresentationManagerProxy.mm:
(WebKit::VideoPresentationManagerProxy::playableViewController const):
* Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenViewController.mm:
(-[WKFullScreenViewController configureEnvironmentPickerOrFullscreenVideoButtonView]):
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Source/WebKit/WebKitSwift/LinearMediaKit/LinearMediaKitExtras.h: Removed.
* Source/WebKit/WebKitSwift/LinearMediaKit/LinearMediaKitExtras.swift: Removed.
* Source/WebKit/WebKitSwift/LinearMediaKit/LinearMediaKitSPI.h: Removed.
* Source/WebKit/WebKitSwift/LinearMediaKit/LinearMediaPlayer.swift:
(SwiftOnlyData.viewController):
(WKSLinearMediaPlayer.makeViewController):
(WKSLinearMediaPlayer.enterExternalPresentation(_:(any Error)?) -> Void:)):
(WKSLinearMediaPlayer.exitExternalPresentation(_:(any Error)?) -> Void:)):
(WKSLinearMediaPlayer.enterFullscreen(_:(any Error)?) -> Void:)):
(WKSLinearMediaPlayer.exitFullscreen(_:(any Error)?) -> Void:)):
(WKSLinearMediaPlayer.maybeCreateSpatialOrImmersiveEntity):
(WKSLinearMediaPlayer.maybeClearSpatialOrImmersiveEntity):
* Source/WebKit/WebKitSwift/LinearMediaKit/LinearMediaTypes.swift:
(WKSPlayableViewControllerHost.baseViewController):
(WKSPlayableViewControllerHost.automaticallyDockOnFullScreenPresentation):
(WKSPlayableViewControllerHost.dismissFullScreenOnExitingDocking):
(WKSPlayableViewControllerHost.environmentPickerButtonViewController):
(WKSPlayableViewControllerHost.playable):
(WKSPlayableViewControllerHost.prefersAutoDimming):
* Source/WebKit/WebKitSwift/LinearMediaKit/WKSLinearMediaPlayer.h:
* Source/WebKit/WebKitSwift/LinearMediaKit/WKSLinearMediaTypes.h:
* Source/WebKit/WebKitSwift/WebKitSwift.h:

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

33e59b5

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ⏳ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-cairo
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 vision 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 ✅ 🛠 playstation
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@rr-codes rr-codes self-assigned this Jun 23, 2025
@rr-codes rr-codes added the WebKit Misc. For miscellaneous bugs in the WebKit framework (and not JavaScriptCore or WebCore). label Jun 23, 2025
@rr-codes rr-codes force-pushed the eng/Swift-in-WebKit-Fix-Swift-6-warnings-and-errors-in-WKS-code branch from d87fddc to 1f51336 Compare June 23, 2025 04:06
@rr-codes rr-codes force-pushed the eng/Swift-in-WebKit-Fix-Swift-6-warnings-and-errors-in-WKS-code branch from 1f51336 to 9847f2a Compare June 23, 2025 04:22
@rr-codes rr-codes force-pushed the eng/Swift-in-WebKit-Fix-Swift-6-warnings-and-errors-in-WKS-code branch from 9847f2a to 7492c7c Compare June 23, 2025 04:44
@rr-codes rr-codes force-pushed the eng/Swift-in-WebKit-Fix-Swift-6-warnings-and-errors-in-WKS-code branch from 7492c7c to 2876c9a Compare June 23, 2025 04:56
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jun 23, 2025
@rr-codes rr-codes removed the merging-blocked Applied to prevent a change from being merged label Jun 23, 2025
@rr-codes rr-codes force-pushed the eng/Swift-in-WebKit-Fix-Swift-6-warnings-and-errors-in-WKS-code branch from 2876c9a to e7c9669 Compare June 23, 2025 07:15
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jun 23, 2025
@rr-codes rr-codes removed the merging-blocked Applied to prevent a change from being merged label Jun 23, 2025
@rr-codes rr-codes force-pushed the eng/Swift-in-WebKit-Fix-Swift-6-warnings-and-errors-in-WKS-code branch from e7c9669 to 753e491 Compare June 23, 2025 16:49
@rr-codes rr-codes force-pushed the eng/Swift-in-WebKit-Fix-Swift-6-warnings-and-errors-in-WKS-code branch from 753e491 to a39e08c Compare June 23, 2025 17:50
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jun 23, 2025
@rr-codes rr-codes removed the merging-blocked Applied to prevent a change from being merged label Jun 23, 2025
@rr-codes rr-codes force-pushed the eng/Swift-in-WebKit-Fix-Swift-6-warnings-and-errors-in-WKS-code branch from a39e08c to d35b378 Compare June 23, 2025 18:49
@@ -47,7 +47,7 @@
#include <wtf/ThreadSafeWeakPtr.h>

OBJC_CLASS AVPlayerViewController;
OBJC_CLASS LMPlayableViewController;
OBJC_CLASS WKPlayableViewController;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: mis-sorted

@@ -30,7 +30,7 @@
#include <WebCore/VideoPresentationInterfaceIOS.h>
#include <wtf/TZoneMalloc.h>

OBJC_CLASS LMPlayableViewController;
OBJC_CLASS WKPlayableViewController;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: mis-sorted

@@ -300,7 +298,7 @@ - (void)layoutSublayers

ALWAYS_LOG_IF_POSSIBLE(LOGIDENTIFIER);
m_playerViewController = [linearMediaPlayer() makeViewController];
[m_playerViewController view].alpha = 0;
[[m_playerViewController baseViewController] view].alpha = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
[[m_playerViewController baseViewController] view].alpha = 0;
[m_playerViewController baseViewController].view.alpha = 0;

@@ -45,7 +45,7 @@
#include <wtf/WeakHashSet.h>
#include <wtf/text/WTFString.h>

OBJC_CLASS LMPlayableViewController;
OBJC_CLASS WKPlayableViewController;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: mis-sorted

@@ -98,6 +94,19 @@ API_AVAILABLE(visionos(1.0))
@property (nonatomic, readonly) float disparityAdjustment;
@end

NS_ASSUME_NONNULL_END
NS_SWIFT_UI_ACTOR
@interface WKPlayableViewController : NSObject
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be called WKSPlayableViewController so long as it lives in WebKitSwift. It's also strange to call this a view controller when it isn't (i.e. is not a UIViewController).

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jun 23, 2025
@rr-codes rr-codes removed the merging-blocked Applied to prevent a change from being merged label Jun 24, 2025
@rr-codes rr-codes force-pushed the eng/Swift-in-WebKit-Fix-Swift-6-warnings-and-errors-in-WKS-code branch from d35b378 to eba036f Compare June 24, 2025 04:44
@rr-codes rr-codes changed the title [Swift in WebKit] Fix Swift 6 warnings and errors in WKS code [Swift in WebKit] Fix Swift 6 warnings and errors in WKSLinearMediaPlayer Jun 24, 2025
@rr-codes rr-codes force-pushed the eng/Swift-in-WebKit-Fix-Swift-6-warnings-and-errors-in-WKS-code branch from eba036f to ea175e3 Compare June 24, 2025 18:34
OBJC_CLASS UIImage;
OBJC_CLASS UIViewController;
OBJC_CLASS UIWindow;
OBJC_CLASS UIView;
OBJC_CLASS CALayer;
OBJC_CLASS NSError;
OBJC_CLASS WebAVPlayerController;
OBJC_CLASS WKSPlayableViewControllerHost;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: mis-sorted

void setSpatialImmersive(bool) final;
void swapFullscreenModesWith(VideoPresentationInterfaceIOS&) final;

WKSLinearMediaPlayer *linearMediaPlayer() const;
void ensurePlayableViewController();

RetainPtr<LMPlayableViewController> m_playerViewController;
RetainPtr<WKSPlayableViewControllerHost> m_playerViewController;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RetainPtr<WKSPlayableViewControllerHost> m_playerViewController;
RetainPtr<WKSPlayableViewControllerHost> m_playerViewControllerHost;

@@ -186,7 +186,7 @@ class VideoPresentationManagerProxy
#endif

#if ENABLE(LINEAR_MEDIA_PLAYER)
LMPlayableViewController *playableViewController(PlaybackSessionContextIdentifier) const;
WKSPlayableViewControllerHost *playableViewController(PlaybackSessionContextIdentifier) const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
WKSPlayableViewControllerHost *playableViewController(PlaybackSessionContextIdentifier) const;
WKSPlayableViewControllerHost *playableViewController(PlaybackSessionContextIdentifier) const;

NS_SWIFT_UI_ACTOR
@interface WKSPlayableViewControllerHost : NSObject

@property (nonatomic, readonly) UIViewController *baseViewController;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be OK to just call this viewController or playableViewController now that the class has a better name.

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jun 24, 2025
@aestes
Copy link
Contributor

aestes commented Jun 24, 2025

r=me

I'm not 100% convinced this statement is factual:

Swift types cannot be accessed by Objective-C in another framework

... but I think the introduction of WKSPlayableViewControllerHost makes sense as a workaround to the Swift 6 compiler error.

@rr-codes rr-codes removed the merging-blocked Applied to prevent a change from being merged label Jun 24, 2025
@rr-codes rr-codes force-pushed the eng/Swift-in-WebKit-Fix-Swift-6-warnings-and-errors-in-WKS-code branch from ea175e3 to 33e59b5 Compare June 24, 2025 23:14
@rr-codes rr-codes added the merge-queue Applied to send a pull request to merge-queue label Jun 25, 2025
…ayer

https://bugs.webkit.org/show_bug.cgi?id=294823
rdar://154057962

Reviewed by Andy Estes.

Address Swift 6 errors in WKSLinearMediaPlayer and related code.

- If it walks like a duck and talks like a duck... it's not always a duck. In this case, AVKit has a public
Swift class `PlayableViewController` and annotated with `@objc(LMPlayableViewController)`. This annotation
makes the type compatible and indistuinguishable from an Objective C type. However, Swift types cannot be accessed
by Objective-C in another framework; within their own framework, the Swift bridging header is used.

AVKit attempted to work around this by creating an Objective-C interface that was essentially a forward declaration
of `LMPlayableViewController`; this is an unsupported configuration as it removes all compile-time checking, which
results in the Swift compiler being confused.

To fix, the `LMPlayableViewController` type is now never used within WebKit; only the `PlayableViewController` type
is used from within Swift WebKit code. Consequently, a new wrapper type is created that abstracts the
`PlayableViewController` and exposes the needed symbols to Objective-C, so that the compiler can function properly.

- Use `@objc @implementation` instead of `@_objcImplementation`.

- Use `RealityKit` instead of the re-exported `RealityFoundation` module.

- Adopt `@preconcurrency` when needed, to silence errors due to the underlying framework symbols
not having proper annotations.

* Source/WebCore/platform/ios/VideoPresentationInterfaceAVKit.h:
* Source/WebCore/platform/ios/VideoPresentationInterfaceIOS.h:
(WebCore::VideoPresentationInterfaceIOS::playableViewController):
* Source/WebKit/Platform/ios/VideoPresentationInterfaceLMK.h:
* Source/WebKit/Platform/ios/VideoPresentationInterfaceLMK.mm:
(WebKit::VideoPresentationInterfaceLMK::setupFullscreen):
(WebKit::VideoPresentationInterfaceLMK::enterExternalPlayback):
(WebKit::VideoPresentationInterfaceLMK::playerViewController const):
(WebKit::VideoPresentationInterfaceLMK::playableViewController):
(WebKit::VideoPresentationInterfaceLMK::ensurePlayableViewController):
* Source/WebKit/UIProcess/Cocoa/VideoPresentationManagerProxy.h:
* Source/WebKit/UIProcess/Cocoa/VideoPresentationManagerProxy.mm:
(WebKit::VideoPresentationManagerProxy::playableViewController const):
* Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenViewController.mm:
(-[WKFullScreenViewController configureEnvironmentPickerOrFullscreenVideoButtonView]):
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Source/WebKit/WebKitSwift/LinearMediaKit/LinearMediaKitExtras.h: Removed.
* Source/WebKit/WebKitSwift/LinearMediaKit/LinearMediaKitExtras.swift: Removed.
* Source/WebKit/WebKitSwift/LinearMediaKit/LinearMediaKitSPI.h: Removed.
* Source/WebKit/WebKitSwift/LinearMediaKit/LinearMediaPlayer.swift:
(SwiftOnlyData.viewController):
(WKSLinearMediaPlayer.makeViewController):
(WKSLinearMediaPlayer.enterExternalPresentation(_:(any Error)?) -> Void:)):
(WKSLinearMediaPlayer.exitExternalPresentation(_:(any Error)?) -> Void:)):
(WKSLinearMediaPlayer.enterFullscreen(_:(any Error)?) -> Void:)):
(WKSLinearMediaPlayer.exitFullscreen(_:(any Error)?) -> Void:)):
(WKSLinearMediaPlayer.maybeCreateSpatialOrImmersiveEntity):
(WKSLinearMediaPlayer.maybeClearSpatialOrImmersiveEntity):
* Source/WebKit/WebKitSwift/LinearMediaKit/LinearMediaTypes.swift:
(WKSPlayableViewControllerHost.baseViewController):
(WKSPlayableViewControllerHost.automaticallyDockOnFullScreenPresentation):
(WKSPlayableViewControllerHost.dismissFullScreenOnExitingDocking):
(WKSPlayableViewControllerHost.environmentPickerButtonViewController):
(WKSPlayableViewControllerHost.playable):
(WKSPlayableViewControllerHost.prefersAutoDimming):
* Source/WebKit/WebKitSwift/LinearMediaKit/WKSLinearMediaPlayer.h:
* Source/WebKit/WebKitSwift/LinearMediaKit/WKSLinearMediaTypes.h:
* Source/WebKit/WebKitSwift/WebKitSwift.h:

Canonical link: https://commits.webkit.org/296600@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Swift-in-WebKit-Fix-Swift-6-warnings-and-errors-in-WKS-code branch from 33e59b5 to facbe72 Compare June 25, 2025 03:02
@webkit-commit-queue
Copy link
Collaborator

Committed 296600@main (facbe72): https://commits.webkit.org/296600@main

Reviewed commits have been landed. Closing PR #47043 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit facbe72 into WebKit:main Jun 25, 2025
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebKit Misc. For miscellaneous bugs in the WebKit framework (and not JavaScriptCore or WebCore).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants