- Revision
- 213683
- Author
- [email protected]
- Date
- 2017-03-09 15:58:02 -0800 (Thu, 09 Mar 2017)
Log Message
WKWebView should provide a way for clients to know the specific media state.
https://bugs.webkit.org/show_bug.cgi?id=169140
<rdar://problem/30838285>
Patch by Andrew Gold <[email protected]> on 2017-03-09
Reviewed by Alex Christensen.
Instead of notifying the UIDelegate only when a capture begins and ends,
we now notify the UIDelegate of any change in capture state.
* UIProcess/API/APIUIClient.h:
(API::UIClient::mediaCaptureStateDidChange):
(API::UIClient::didBeginCaptureSession): Deleted.
(API::UIClient::didEndCaptureSession): Deleted.
* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/Cocoa/UIDelegate.h:
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::setDelegate):
(WebKit::UIDelegate::UIClient::mediaCaptureStateDidChange):
(WebKit::UIDelegate::UIClient::didBeginCaptureSession): Deleted.
(WebKit::UIDelegate::UIClient::didEndCaptureSession): Deleted.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::isPlayingMediaDidChange):
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (213682 => 213683)
--- trunk/Source/WebKit2/ChangeLog 2017-03-09 23:44:12 UTC (rev 213682)
+++ trunk/Source/WebKit2/ChangeLog 2017-03-09 23:58:02 UTC (rev 213683)
@@ -1,3 +1,34 @@
+2017-03-09 Andrew Gold <[email protected]>
+
+ WKWebView should provide a way for clients to know the specific media state.
+ https://bugs.webkit.org/show_bug.cgi?id=169140
+ <rdar://problem/30838285>
+
+ Reviewed by Alex Christensen.
+
+ Instead of notifying the UIDelegate only when a capture begins and ends,
+ we now notify the UIDelegate of any change in capture state.
+
+ * UIProcess/API/APIUIClient.h:
+
+ (API::UIClient::mediaCaptureStateDidChange):
+ (API::UIClient::didBeginCaptureSession): Deleted.
+ (API::UIClient::didEndCaptureSession): Deleted.
+
+ * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+
+ * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+
+ * UIProcess/Cocoa/UIDelegate.h:
+ * UIProcess/Cocoa/UIDelegate.mm:
+ (WebKit::UIDelegate::setDelegate):
+ (WebKit::UIDelegate::UIClient::mediaCaptureStateDidChange):
+ (WebKit::UIDelegate::UIClient::didBeginCaptureSession): Deleted.
+ (WebKit::UIDelegate::UIClient::didEndCaptureSession): Deleted.
+
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::isPlayingMediaDidChange):
+
2017-03-09 Joseph Pecoraro <[email protected]>
Web Inspector: Show HTTP protocol version and other Network Load Metrics (IP Address, Priority, Connection ID)
Modified: trunk/Source/WebKit2/UIProcess/API/APIUIClient.h (213682 => 213683)
--- trunk/Source/WebKit2/UIProcess/API/APIUIClient.h 2017-03-09 23:44:12 UTC (rev 213682)
+++ trunk/Source/WebKit2/UIProcess/API/APIUIClient.h 2017-03-09 23:58:02 UTC (rev 213683)
@@ -150,8 +150,7 @@
virtual void pinnedStateDidChange(WebKit::WebPageProxy&) { }
virtual void isPlayingAudioDidChange(WebKit::WebPageProxy&) { }
- virtual void didBeginCaptureSession() { }
- virtual void didEndCaptureSession() { }
+ virtual void mediaCaptureStateDidChange(WebCore::MediaProducer::MediaStateFlags) { }
virtual void handleAutoplayEvent(WebKit::WebPageProxy&, WebCore::AutoplayEvent) { }
#if ENABLE(MEDIA_SESSION)
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUIDelegatePrivate.h (213682 => 213683)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUIDelegatePrivate.h 2017-03-09 23:44:12 UTC (rev 213682)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUIDelegatePrivate.h 2017-03-09 23:58:02 UTC (rev 213683)
@@ -28,6 +28,7 @@
#if WK_API_ENABLED
#import <WebKit/WKSecurityOrigin.h>
+#import <WebKit/WKWebViewPrivate.h>
#import <WebKit/_WKActivatedElementInfo.h>
@class UIItemProvider;
@@ -63,8 +64,7 @@
- (NSDictionary *)_dataDetectionContextForWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(10.12), ios(10.0));
- (void)_webView:(WKWebView *)webView requestUserMediaAuthorizationForMicrophone:(BOOL)microphone camera:(BOOL)camera url:(NSURL *)url mainFrameURL:(NSURL *)mainFrameURL decisionHandler:(void (^)(BOOL authorizedMicrophone, BOOL authorizedCamera))decisionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
- (void)_webView:(WKWebView *)webView checkUserMediaPermissionForURL:(NSURL *)url mainFrameURL:(NSURL *)mainFrameURL frameIdentifier:(NSUInteger)frameIdentifier decisionHandler:(void (^)(NSString *salt, BOOL authorized))decisionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
-- (void)_webViewDidBeginCaptureSession:(WKWebView *)webView WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
-- (void)_webViewDidEndCaptureSession:(WKWebView *)webView WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_webView:(WKWebView *)webView mediaCaptureStateDidChange:(_WKMediaCaptureState)state WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
#if TARGET_OS_IPHONE
- (BOOL)_webView:(WKWebView *)webView shouldIncludeAppLinkActionsForElement:(_WKActivatedElementInfo *)element WK_API_AVAILABLE(ios(9.0));
- (NSArray *)_webView:(WKWebView *)webView actionsForElement:(_WKActivatedElementInfo *)element defaultActions:(NSArray<_WKElementAction *> *)defaultActions;
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (213682 => 213683)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h 2017-03-09 23:44:12 UTC (rev 213682)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h 2017-03-09 23:58:02 UTC (rev 213683)
@@ -39,6 +39,12 @@
_WKPaginationModeBottomToTop,
} WK_API_AVAILABLE(macosx(10.10), ios(8.0));
+typedef NS_OPTIONS(NSInteger, _WKMediaCaptureState) {
+ _WKMediaCaptureStateNone = 0,
+ _WKMediaCaptureStateMicrophone = 1 << 0,
+ _WKMediaCaptureStateCamera = 1 << 1,
+} WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
#if !TARGET_OS_IPHONE
typedef NS_ENUM(NSInteger, _WKImmediateActionType) {
Modified: trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.h (213682 => 213683)
--- trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.h 2017-03-09 23:44:12 UTC (rev 213682)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.h 2017-03-09 23:58:02 UTC (rev 213683)
@@ -91,8 +91,7 @@
#endif
bool decidePolicyForUserMediaPermissionRequest(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, WebKit::UserMediaPermissionRequestProxy&) override;
bool checkUserMediaPermissionForOrigin(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, WebKit::UserMediaPermissionCheckProxy&) override;
- void didBeginCaptureSession() override;
- void didEndCaptureSession() override;
+ void mediaCaptureStateDidChange(WebCore::MediaProducer::MediaStateFlags) override;
void printFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*) override;
#if PLATFORM(IOS)
#if HAVE(APP_LINKS)
@@ -136,8 +135,7 @@
bool webViewDidExitFullscreen : 1;
bool webViewRequestUserMediaAuthorizationForMicrophoneCameraURLMainFrameURLDecisionHandler : 1;
bool webViewCheckUserMediaPermissionForURLMainFrameURLFrameIdentifierDecisionHandler : 1;
- bool webViewDidBeginCaptureSession : 1;
- bool webViewDidEndCaptureSession : 1;
+ bool webViewMediaCaptureStateDidChange : 1;
#if PLATFORM(IOS)
#if HAVE(APP_LINKS)
bool webViewShouldIncludeAppLinkActionsForElement : 1;
Modified: trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm (213682 => 213683)
--- trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm 2017-03-09 23:44:12 UTC (rev 213682)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm 2017-03-09 23:58:02 UTC (rev 213683)
@@ -116,8 +116,7 @@
m_delegateMethods.webViewDidNotHandleTapAsClickAtPoint = [delegate respondsToSelector:@selector(_webView:didNotHandleTapAsClickAtPoint:)];
m_delegateMethods.webViewRequestUserMediaAuthorizationForMicrophoneCameraURLMainFrameURLDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestUserMediaAuthorizationForMicrophone:camera:url:mainFrameURL:decisionHandler:)];
m_delegateMethods.webViewCheckUserMediaPermissionForURLMainFrameURLFrameIdentifierDecisionHandler = [delegate respondsToSelector:@selector(_webView:checkUserMediaPermissionForURL:mainFrameURL:frameIdentifier:decisionHandler:)];
- m_delegateMethods.webViewDidBeginCaptureSession = [delegate respondsToSelector:@selector(_webViewDidBeginCaptureSession:)];
- m_delegateMethods.webViewDidEndCaptureSession = [delegate respondsToSelector:@selector(_webViewDidEndCaptureSession:)];
+ m_delegateMethods.webViewMediaCaptureStateDidChange = [delegate respondsToSelector:@selector(_webView:mediaCaptureStateDidChange:)];
m_delegateMethods.presentingViewControllerForWebView = [delegate respondsToSelector:@selector(_presentingViewControllerForWebView:)];
#endif
m_delegateMethods.dataDetectionContextForWebView = [delegate respondsToSelector:@selector(_dataDetectionContextForWebView:)];
@@ -435,22 +434,20 @@
return true;
}
-void UIDelegate::UIClient::didBeginCaptureSession()
+void UIDelegate::UIClient::mediaCaptureStateDidChange(WebCore::MediaProducer::MediaStateFlags state)
{
+ WKWebView *webView = m_uiDelegate.m_webView;
auto delegate = m_uiDelegate.m_delegate.get();
- if (!delegate || !m_uiDelegate.m_delegateMethods.webViewDidBeginCaptureSession)
+ if (!delegate || !m_uiDelegate.m_delegateMethods.webViewMediaCaptureStateDidChange)
return;
- [(id <WKUIDelegatePrivate>)delegate _webViewDidBeginCaptureSession:m_uiDelegate.m_webView];
-}
+ _WKMediaCaptureState mediaCaptureState = _WKMediaCaptureStateNone;
+ if (state & WebCore::MediaProducer::HasActiveAudioCaptureDevice)
+ mediaCaptureState |= _WKMediaCaptureStateMicrophone;
+ if (state & WebCore::MediaProducer::HasActiveVideoCaptureDevice)
+ mediaCaptureState |= _WKMediaCaptureStateCamera;
-void UIDelegate::UIClient::didEndCaptureSession()
-{
- auto delegate = m_uiDelegate.m_delegate.get();
- if (!delegate || !m_uiDelegate.m_delegateMethods.webViewDidEndCaptureSession)
- return;
-
- [(id <WKUIDelegatePrivate>)delegate _webViewDidEndCaptureSession:m_uiDelegate.m_webView];
+ [(id <WKUIDelegatePrivate>)delegate _webView:webView mediaCaptureStateDidChange:mediaCaptureState];
}
void UIDelegate::UIClient::reachedApplicationCacheOriginQuota(WebPageProxy*, const WebCore::SecurityOrigin& securityOrigin, uint64_t currentQuota, uint64_t totalBytesNeeded, Function<void (unsigned long long)>&& completionHandler)
Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (213682 => 213683)
--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp 2017-03-09 23:44:12 UTC (rev 213682)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp 2017-03-09 23:58:02 UTC (rev 213683)
@@ -6446,9 +6446,10 @@
if (state == m_mediaState)
return;
+ WebCore::MediaProducer::MediaStateFlags activeCaptureMask = WebCore::MediaProducer::HasActiveAudioCaptureDevice | WebCore::MediaProducer::HasActiveVideoCaptureDevice;
#if ENABLE(MEDIA_STREAM)
- WebCore::MediaProducer::MediaStateFlags oldMediaStateHasActiveCapture = m_mediaState & (WebCore::MediaProducer::HasActiveAudioCaptureDevice | WebCore::MediaProducer::HasActiveVideoCaptureDevice);
- WebCore::MediaProducer::MediaStateFlags newMediaStateHasActiveCapture = state & (WebCore::MediaProducer::HasActiveAudioCaptureDevice | WebCore::MediaProducer::HasActiveVideoCaptureDevice);
+ WebCore::MediaProducer::MediaStateFlags oldMediaStateHasActiveCapture = m_mediaState & activeCaptureMask;
+ WebCore::MediaProducer::MediaStateFlags newMediaStateHasActiveCapture = state & activeCaptureMask;
#endif
MediaProducer::MediaStateFlags playingMediaMask = MediaProducer::IsPlayingAudio | MediaProducer::IsPlayingVideo;
@@ -6456,18 +6457,17 @@
m_mediaState = state;
#if ENABLE(MEDIA_STREAM)
- if (!oldMediaStateHasActiveCapture && newMediaStateHasActiveCapture) {
- m_uiClient->didBeginCaptureSession();
+ if (oldMediaStateHasActiveCapture != newMediaStateHasActiveCapture)
+ m_uiClient->mediaCaptureStateDidChange(m_mediaState);
+ if (!oldMediaStateHasActiveCapture && newMediaStateHasActiveCapture)
userMediaPermissionRequestManager().startedCaptureSession();
- } else if (oldMediaStateHasActiveCapture && !newMediaStateHasActiveCapture) {
- m_uiClient->didEndCaptureSession();
+ else if (oldMediaStateHasActiveCapture && !newMediaStateHasActiveCapture)
userMediaPermissionRequestManager().endedCaptureSession();
- }
#endif
activityStateDidChange(ActivityState::IsAudible);
- playingMediaMask |= MediaProducer::HasActiveAudioCaptureDevice | MediaProducer::HasActiveVideoCaptureDevice;
+ playingMediaMask |= activeCaptureMask;
if ((oldState & playingMediaMask) != (m_mediaState & playingMediaMask))
m_uiClient->isPlayingAudioDidChange(*this);
#if PLATFORM(MAC)