Skip to content

Commit

Permalink
[iOS] Stop using AVSystemController and AVAudioSession SPIs when medi…
Browse files Browse the repository at this point in the history
…a capability grants are enabled

https://bugs.webkit.org/show_bug.cgi?id=266975
rdar://115750175

Reviewed by Per Arne Vollan.

When media capability grants are enabled, setting the
AVSystemController_PIDToInheritApplicationStateFrom attribute on AVSystemController and calling
-[AVAudioSession setAuditTokensForProcessAssertion:error:] are no longer necessary. Plumbed the
MediaCapabilityGrantsEnabled web preference to the GPU process and avoided calling these SPIs when
the preference is activated. Added a WKPreferences SPI to deactivate the preference for use by
clients that are not yet ready to adopt media capability grants.

* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml:
* Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp:
(WebCore::PlatformMediaSessionManager::mediaCapabilityGrantsEnabled):
(WebCore::PlatformMediaSessionManager::setMediaCapabilityGrantsEnabled):
* Source/WebCore/platform/audio/PlatformMediaSessionManager.h:
* Source/WebCore/platform/audio/ios/MediaSessionHelperIOS.mm:
(MediaSessionHelperIOS::providePresentingApplicationPID):
* Source/WebKit/GPUProcess/GPUProcess.cpp:
(WebKit::GPUProcess::updateGPUProcessPreferences):
* Source/WebKit/GPUProcess/GPUProcessPreferences.cpp:
(WebKit::GPUProcessPreferences::copyEnabledWebPreferences):
* Source/WebKit/GPUProcess/GPUProcessPreferences.h:
* Source/WebKit/GPUProcess/media/RemoteAudioSessionProxyManager.cpp:
(WebKit::RemoteAudioSessionProxyManager::updatePresentingProcesses):
* Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm:
(-[WKPreferences _mediaCapabilityGrantsEnabled]):
(-[WKPreferences _setMediaCapabilityGrantsEnabled:]):
* Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h:

Canonical link: https://commits.webkit.org/272675@main
  • Loading branch information
aestes committed Jan 5, 2024
1 parent 8862bd5 commit f0f4cef
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4222,7 +4222,7 @@ MediaCapabilitiesExtensionsEnabled:

MediaCapabilityGrantsEnabled:
type: bool
status: unstable
status: embedder
condition: ENABLE(EXTENSION_CAPABILITIES)
humanReadableName: "Media Capability Grants"
humanReadableDescription: "Enable granting and revoking of media capabilities"
Expand Down
16 changes: 16 additions & 0 deletions Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ bool PlatformMediaSessionManager::m_vp8DecoderEnabled;
bool PlatformMediaSessionManager::m_vp9SWDecoderEnabled;
#endif

#if ENABLE(EXTENSION_CAPABILITIES)
bool PlatformMediaSessionManager::s_mediaCapabilityGrantsEnabled;
#endif

static std::unique_ptr<PlatformMediaSessionManager>& sharedPlatformMediaSessionManager()
{
static NeverDestroyed<std::unique_ptr<PlatformMediaSessionManager>> platformMediaSessionManager;
Expand Down Expand Up @@ -807,6 +811,18 @@ void PlatformMediaSessionManager::updateNowPlayingInfoIfNecessary()

#endif // ENABLE(VIDEO) || ENABLE(WEB_AUDIO)

#if ENABLE(EXTENSION_CAPABILITIES)
bool PlatformMediaSessionManager::mediaCapabilityGrantsEnabled()
{
return s_mediaCapabilityGrantsEnabled;
}

void PlatformMediaSessionManager::setMediaCapabilityGrantsEnabled(bool mediaCapabilityGrantsEnabled)
{
s_mediaCapabilityGrantsEnabled = mediaCapabilityGrantsEnabled;
}
#endif

#if !RELEASE_LOG_DISABLED
WTFLogChannel& PlatformMediaSessionManager::logChannel() const
{
Expand Down
9 changes: 9 additions & 0 deletions Source/WebCore/platform/audio/PlatformMediaSessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class PlatformMediaSessionManager
WEBCORE_EXPORT static bool shouldEnableVP9SWDecoder();
#endif

#if ENABLE(EXTENSION_CAPABILITIES)
WEBCORE_EXPORT static bool mediaCapabilityGrantsEnabled();
WEBCORE_EXPORT static void setMediaCapabilityGrantsEnabled(bool);
#endif

virtual ~PlatformMediaSessionManager() = default;

virtual void scheduleSessionStatusUpdate() { }
Expand Down Expand Up @@ -257,6 +262,10 @@ class PlatformMediaSessionManager
static bool m_vp9SWDecoderEnabled;
#endif

#if ENABLE(EXTENSION_CAPABILITIES)
static bool s_mediaCapabilityGrantsEnabled;
#endif

#if !RELEASE_LOG_DISABLED
Ref<AggregateLogger> m_logger;
#endif
Expand Down
6 changes: 6 additions & 0 deletions Source/WebCore/platform/audio/ios/MediaSessionHelperIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#import "Logging.h"
#import "MediaPlaybackTargetCocoa.h"
#import "PlatformMediaSessionManager.h"
#import "WebCoreThreadRun.h"
#import <AVFoundation/AVAudioSession.h>
#import <AVFoundation/AVRouteDetector.h>
Expand Down Expand Up @@ -266,6 +267,11 @@ - (void)stopMonitoringAirPlayRoutes;

void MediaSessionHelperIOS::providePresentingApplicationPID(int pid, ShouldOverride shouldOverride)
{
#if ENABLE(EXTENSION_CAPABILITIES)
if (PlatformMediaSessionManager::mediaCapabilityGrantsEnabled())
return;
#endif

#if HAVE(CELESTIAL)
if (m_presentedApplicationPID && (*m_presentedApplicationPID == pid || shouldOverride == ShouldOverride::No))
return;
Expand Down
5 changes: 5 additions & 0 deletions Source/WebKit/GPUProcess/GPUProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ void GPUProcess::updateGPUProcessPreferences(GPUProcessPreferences&& preferences
if (updatePreference(m_preferences.useSCContentSharingPicker, preferences.useSCContentSharingPicker))
PlatformMediaSessionManager::setUseSCContentSharingPicker(*m_preferences.useSCContentSharingPicker);
#endif

#if ENABLE(EXTENSION_CAPABILITIES)
if (updatePreference(m_preferences.mediaCapabilityGrantsEnabled, preferences.mediaCapabilityGrantsEnabled))
PlatformMediaSessionManager::setMediaCapabilityGrantsEnabled(*m_preferences.mediaCapabilityGrantsEnabled);
#endif
}

bool GPUProcess::updatePreference(std::optional<bool>& oldPreference, std::optional<bool>& newPreference)
Expand Down
5 changes: 5 additions & 0 deletions Source/WebKit/GPUProcess/GPUProcessPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ void GPUProcessPreferences::copyEnabledWebPreferences(const WebPreferences& webP
if (webPreferences.alternateWebMPlayerEnabled())
alternateWebMPlayerEnabled = true;
#endif

#if ENABLE(EXTENSION_CAPABILITIES)
if (webPreferences.mediaCapabilityGrantsEnabled())
mediaCapabilityGrantsEnabled = true;
#endif
}

} // namespace WebKit
Expand Down
4 changes: 4 additions & 0 deletions Source/WebKit/GPUProcess/GPUProcessPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ struct GPUProcessPreferences {
#if HAVE(SC_CONTENT_SHARING_PICKER)
std::optional<bool> useSCContentSharingPicker;
#endif

#if ENABLE(EXTENSION_CAPABILITIES)
std::optional<bool> mediaCapabilityGrantsEnabled;
#endif
};

} // namespace WebKit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "RemoteAudioSessionProxy.h"
#include <WebCore/AudioSession.h>
#include <WebCore/CoreAudioCaptureSource.h>
#include <WebCore/PlatformMediaSessionManager.h>
#include <wtf/HashCountedSet.h>

namespace WebKit {
Expand Down Expand Up @@ -194,6 +195,11 @@ bool RemoteAudioSessionProxyManager::tryToSetActiveForProcess(RemoteAudioSession

void RemoteAudioSessionProxyManager::updatePresentingProcesses()
{
#if ENABLE(EXTENSION_CAPABILITIES)
if (PlatformMediaSessionManager::mediaCapabilityGrantsEnabled())
return;
#endif

Vector<audit_token_t> presentingProcesses;

if (auto token = m_gpuProcess.parentProcessConnection()->getAuditToken())
Expand Down
10 changes: 10 additions & 0 deletions Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,16 @@ - (BOOL)_verifyWindowOpenUserGestureFromUIProcess
return _preferences->verifyWindowOpenUserGestureFromUIProcess();
}

- (BOOL)_mediaCapabilityGrantsEnabled
{
return _preferences->mediaCapabilityGrantsEnabled();
}

- (void)_setMediaCapabilityGrantsEnabled:(BOOL)mediaCapabilityGrantsEnabled
{
_preferences->setMediaCapabilityGrantsEnabled(mediaCapabilityGrantsEnabled);
}

@end

@implementation WKPreferences (WKDeprecated)
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ typedef NS_ENUM(NSInteger, _WKPitchCorrectionAlgorithm) {
@property (nonatomic, setter=_setManagedMediaSourceEnabled:) BOOL _managedMediaSourceEnabled WK_API_AVAILABLE(macos(14.0), ios(17.0));
@property (nonatomic, setter=_setManagedMediaSourceLowThreshold:) double _managedMediaSourceLowThreshold WK_API_AVAILABLE(macos(14.0), ios(17.0));
@property (nonatomic, setter=_setManagedMediaSourceHighThreshold:) double _managedMediaSourceHighThreshold WK_API_AVAILABLE(macos(14.0), ios(17.0));
@property (nonatomic, setter=_setMediaCapabilityGrantsEnabled:) BOOL _mediaCapabilityGrantsEnabled WK_API_AVAILABLE(WK_IOS_TBA) WK_API_UNAVAILABLE(macos);

#if !TARGET_OS_IPHONE
@property (nonatomic, setter=_setWebGLEnabled:) BOOL _webGLEnabled WK_API_AVAILABLE(macos(10.13.4));
Expand Down

0 comments on commit f0f4cef

Please sign in to comment.