Title: [182029] trunk/Source/WebCore
- Revision
- 182029
- Author
- [email protected]
- Date
- 2015-03-26 15:31:46 -0700 (Thu, 26 Mar 2015)
Log Message
[iOS] Accessibility crashing because MediaPlayer is laying out UI off the main thread
https://bugs.webkit.org/show_bug.cgi?id=142970
Reviewed by Eric Carlson.
isMainThread() will (ironically) return true if called from the web thread. Rather than dispatch
synchronously to the main thread to allocate the _volumeView, dispatch asynchronously and handle
the case where the MPVolumeView has not yet been created.
* platform/audio/ios/MediaSessionManagerIOS.mm:
(-[WebMediaSessionHelper allocateVolumeView]): Dispatch to the main thread to allocate. Move notification
registration to -setVolumeView:.
(-[WebMediaSessionHelper setVolumeView:]): Added. Register/Unregister for route availablitiy notifications.
(-[WebMediaSessionHelper hasWirelessTargetsAvailable]): Handle the possibility of a nil _volumeView.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (182028 => 182029)
--- trunk/Source/WebCore/ChangeLog 2015-03-26 22:20:45 UTC (rev 182028)
+++ trunk/Source/WebCore/ChangeLog 2015-03-26 22:31:46 UTC (rev 182029)
@@ -1,3 +1,20 @@
+2015-03-26 Jer Noble <[email protected]>
+
+ [iOS] Accessibility crashing because MediaPlayer is laying out UI off the main thread
+ https://bugs.webkit.org/show_bug.cgi?id=142970
+
+ Reviewed by Eric Carlson.
+
+ isMainThread() will (ironically) return true if called from the web thread. Rather than dispatch
+ synchronously to the main thread to allocate the _volumeView, dispatch asynchronously and handle
+ the case where the MPVolumeView has not yet been created.
+
+ * platform/audio/ios/MediaSessionManagerIOS.mm:
+ (-[WebMediaSessionHelper allocateVolumeView]): Dispatch to the main thread to allocate. Move notification
+ registration to -setVolumeView:.
+ (-[WebMediaSessionHelper setVolumeView:]): Added. Register/Unregister for route availablitiy notifications.
+ (-[WebMediaSessionHelper hasWirelessTargetsAvailable]): Handle the possibility of a nil _volumeView.
+
2015-03-26 Benjamin Poulain <[email protected]>
Fix state maching debugging after r181964
Modified: trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm (182028 => 182029)
--- trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm 2015-03-26 22:20:45 UTC (rev 182028)
+++ trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm 2015-03-26 22:31:46 UTC (rev 182029)
@@ -97,6 +97,7 @@
- (id)initWithCallback:(MediaSessionManageriOS*)callback;
- (void)allocateVolumeView;
+- (void)setVolumeView:(RetainPtr<MPVolumeView>)volumeView;
- (void)clearCallback;
- (void)interruption:(NSNotification *)notification;
- (void)applicationWillEnterForeground:(NSNotification *)notification;
@@ -245,21 +246,31 @@
- (void)allocateVolumeView
{
- if (!isMainThread()) {
- // Call synchronously to the main thread so that _volumeView will be completely setup before the constructor completes
- // because hasWirelessTargetsAvailable is synchronous and can be called on the WebThread.
- RetainPtr<WebMediaSessionHelper> strongSelf = self;
- dispatch_sync(dispatch_get_main_queue(), [strongSelf]() {
- [strongSelf allocateVolumeView];
- });
+ if (pthread_main_np()) {
+ [self setVolumeView:adoptNS([allocMPVolumeViewInstance() init])];
return;
}
- _volumeView = adoptNS([allocMPVolumeViewInstance() init]);
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(wirelessRoutesAvailableDidChange:) name:MPVolumeViewWirelessRoutesAvailableDidChangeNotification object:_volumeView.get()];
-
+ RetainPtr<WebMediaSessionHelper> strongSelf = self;
+ dispatch_async(dispatch_get_main_queue(), [strongSelf]() {
+ RetainPtr<MPVolumeView> volumeView = adoptNS([allocMPVolumeViewInstance() init]);
+ callOnWebThreadOrDispatchAsyncOnMainThread([strongSelf, volumeView]() {
+ [strongSelf setVolumeView:volumeView];
+ });
+ });
}
+- (void)setVolumeView:(RetainPtr<MPVolumeView>)volumeView
+{
+ if (_volumeView)
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:MPVolumeViewWirelessRoutesAvailableDidChangeNotification object:_volumeView.get()];
+
+ _volumeView = volumeView;
+
+ if (_volumeView)
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(wirelessRoutesAvailableDidChange:) name:MPVolumeViewWirelessRoutesAvailableDidChangeNotification object:_volumeView.get()];
+}
+
- (id)initWithCallback:(MediaSessionManageriOS*)callback
{
LOG(Media, "-[WebMediaSessionHelper initWithCallback]");
@@ -321,7 +332,7 @@
- (BOOL)hasWirelessTargetsAvailable
{
LOG(Media, "-[WebMediaSessionHelper hasWirelessTargetsAvailable]");
- return [_volumeView areWirelessRoutesAvailable];
+ return _volumeView ? [_volumeView areWirelessRoutesAvailable] : NO;
}
- (void)startMonitoringAirPlayRoutes
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes