Diff
Modified: trunk/Source/WebCore/platform/mac/WebPlaybackControlsManager.h (235943 => 235944)
--- trunk/Source/WebCore/platform/mac/WebPlaybackControlsManager.h 2018-09-12 17:03:13 UTC (rev 235943)
+++ trunk/Source/WebCore/platform/mac/WebPlaybackControlsManager.h 2018-09-12 19:10:01 UTC (rev 235944)
@@ -74,6 +74,7 @@
@property BOOL allowsPictureInPicturePlayback;
@property (getter=isPictureInPictureActive) BOOL pictureInPictureActive;
@property BOOL canTogglePictureInPicture;
+- (void)togglePictureInPicture;
- (AVTouchBarMediaSelectionOption *)currentAudioTouchBarMediaSelectionOption;
- (void)setCurrentAudioTouchBarMediaSelectionOption:(AVTouchBarMediaSelectionOption *)option;
Modified: trunk/Source/WebCore/platform/mac/WebPlaybackControlsManager.mm (235943 => 235944)
--- trunk/Source/WebCore/platform/mac/WebPlaybackControlsManager.mm 2018-09-12 17:03:13 UTC (rev 235943)
+++ trunk/Source/WebCore/platform/mac/WebPlaybackControlsManager.mm 2018-09-12 19:10:01 UTC (rev 235944)
@@ -337,13 +337,11 @@
return NO;
}
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
- (void)togglePictureInPicture
{
if (_playbackSessionInterfaceMac && _playbackSessionInterfaceMac->playbackSessionModel())
_playbackSessionInterfaceMac->playbackSessionModel()->togglePictureInPicture();
}
-#endif
IGNORE_CLANG_WARNINGS_END
Modified: trunk/Source/WebKit/ChangeLog (235943 => 235944)
--- trunk/Source/WebKit/ChangeLog 2018-09-12 17:03:13 UTC (rev 235943)
+++ trunk/Source/WebKit/ChangeLog 2018-09-12 19:10:01 UTC (rev 235944)
@@ -1,3 +1,33 @@
+2018-09-10 Matt Rajca <[email protected]>
+
+ Expose a few WebPlaybackControlsManager-driven PIP APIs to clients
+ https://bugs.webkit.org/show_bug.cgi?id=189478
+ <rdar://problem/44312650>
+
+ Reviewed by Eric Carlson.
+
+ This patch exposes APIs necessary to toggle PIP and query its status from clients of WKWebView.
+ The existing PIP test has been updated to use the new APIs instead of simulating mouse clicks.
+ I also increased the size of the video element in the test page so it gets picked up by the
+ main content heuristics.
+
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView _updateMediaPlaybackControlsManager]): Create a media playback controls manager if necessary.
+ (-[WKWebView _isPictureInPictureActive]): Return true if the "active" media element is in PIP.
+ (-[WKWebView _togglePictureInPicture]): Toggle PIP on the "active" media element.
+ (-[WKWebView _canTogglePictureInPicture]): Renamed from...
+ (-[WKWebView _canTogglePictureInPictureForTesting]):
+ * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+ * UIProcess/Cocoa/WebViewImpl.h:
+ * UIProcess/Cocoa/WebViewImpl.mm:
+ (WebKit::WebViewImpl::isPictureInPictureActive): Return true if the "active" media element is in PIP.
+ (WebKit::WebViewImpl::togglePictureInPicture): Toggle PIP on the "active" media element.
+ (WebKit::WebViewImpl::updateMediaPlaybackControlsManager): Let clients create a playback
+ controls manager even when there is no Touch Bar present.
+ (WebKit::WebViewImpl::updateMediaTouchBar): Extract some code into a helper method.
+ (WebKit::WebViewImpl::canTogglePictureInPicture): Renamed from...
+ (WebKit::WebViewImpl::canTogglePictureInPictureForTesting):
+
2018-09-12 Fujii Hironori <[email protected]>
[Win][Clang] error: non-constant-_expression_ cannot be narrowed from type 'int' to 'SHORT'
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (235943 => 235944)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2018-09-12 17:03:13 UTC (rev 235943)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2018-09-12 19:10:01 UTC (rev 235944)
@@ -4264,6 +4264,38 @@
_navigationState->setHistoryDelegate(historyDelegate);
}
+- (void)_updateMediaPlaybackControlsManager
+{
+#if HAVE(TOUCH_BAR) && ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+ _impl->updateMediaPlaybackControlsManager();
+#endif
+}
+
+- (BOOL)_canTogglePictureInPicture
+{
+#if HAVE(TOUCH_BAR)
+ return _impl->canTogglePictureInPicture();
+#else
+ return NO;
+#endif
+}
+
+- (BOOL)_isPictureInPictureActive
+{
+#if HAVE(TOUCH_BAR) && ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+ return _impl->isPictureInPictureActive();
+#else
+ return NO;
+#endif
+}
+
+- (void)_togglePictureInPicture
+{
+#if HAVE(TOUCH_BAR) && ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+ _impl->togglePictureInPicture();
+#endif
+}
+
- (NSURL *)_unreachableURL
{
return [NSURL _web_URLWithWTFString:_page->pageLoadState().unreachableURL()];
@@ -6532,15 +6564,6 @@
_page->setDefersLoadingForTesting(defersLoading);
}
-- (BOOL)_canTogglePictureInPictureForTesting
-{
-#if HAVE(TOUCH_BAR)
- return _impl->canTogglePictureInPictureForTesting();
-#else
- return NO;
-#endif
-}
-
- (_WKInspector *)_inspector
{
if (auto* inspector = _page->inspector())
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (235943 => 235944)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h 2018-09-12 17:03:13 UTC (rev 235943)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h 2018-09-12 19:10:01 UTC (rev 235944)
@@ -356,6 +356,11 @@
@property (nonatomic, setter=_setMediaCaptureEnabled:) BOOL _mediaCaptureEnabled WK_API_AVAILABLE(macosx(10.13), ios(11.0));
+@property (nonatomic, readonly) BOOL _canTogglePictureInPicture;
+@property (nonatomic, readonly) BOOL _isPictureInPictureActive;
+- (void)_updateMediaPlaybackControlsManager;
+- (void)_togglePictureInPicture;
+
@end
#if !TARGET_OS_IPHONE
@@ -472,8 +477,6 @@
- (BOOL)_completeBackSwipeForTesting;
- (void)_setDefersLoadingForTesting:(BOOL)defersLoading;
-- (BOOL)_canTogglePictureInPictureForTesting;
-
@property (nonatomic, readonly) _WKInspector *_inspector WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
@property (nonatomic, readonly) _WKFrameHandle *_mainFrame WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h (235943 => 235944)
--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h 2018-09-12 17:03:13 UTC (rev 235943)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h 2018-09-12 19:10:01 UTC (rev 235944)
@@ -558,6 +558,10 @@
NSTouchBar *currentTouchBar() const { return m_currentTouchBar.get(); }
NSCandidateListTouchBarItem *candidateListTouchBarItem() const;
#if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+ bool isPictureInPictureActive();
+ void togglePictureInPicture();
+ void updateMediaPlaybackControlsManager();
+
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
AVTouchBarScrubber *mediaPlaybackControlsView() const;
#else
@@ -573,7 +577,7 @@
void updateTouchBarAndRefreshTextBarIdentifiers();
void setIsCustomizingTouchBar(bool isCustomizingTouchBar) { m_isCustomizingTouchBar = isCustomizingTouchBar; };
- bool canTogglePictureInPictureForTesting();
+ bool canTogglePictureInPicture();
#endif // HAVE(TOUCH_BAR)
bool beginBackSwipeForTesting();
Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (235943 => 235944)
--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm 2018-09-12 17:03:13 UTC (rev 235943)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm 2018-09-12 19:10:01 UTC (rev 235944)
@@ -1209,6 +1209,37 @@
}
}
+#if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+
+bool WebViewImpl::isPictureInPictureActive()
+{
+ return [m_playbackControlsManager isPictureInPictureActive];
+}
+
+void WebViewImpl::togglePictureInPicture()
+{
+ [m_playbackControlsManager togglePictureInPicture];
+}
+
+void WebViewImpl::updateMediaPlaybackControlsManager()
+{
+ if (!m_page->hasActiveVideoForControlsManager())
+ return;
+
+ if (!m_playbackControlsManager) {
+ m_playbackControlsManager = adoptNS([[WebPlaybackControlsManager alloc] init]);
+ [m_playbackControlsManager setAllowsPictureInPicturePlayback:m_page->preferences().allowsPictureInPictureMediaPlayback()];
+ [m_playbackControlsManager setCanTogglePictureInPicture:NO];
+ }
+
+ if (PlatformPlaybackSessionInterface* interface = m_page->playbackSessionManager()->controlsManagerInterface()) {
+ [m_playbackControlsManager setPlaybackSessionInterfaceMac:interface];
+ interface->updatePlaybackControlsManagerCanTogglePictureInPicture();
+ }
+}
+
+#endif // ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+
void WebViewImpl::updateMediaTouchBar()
{
#if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER) && ENABLE(VIDEO_PRESENTATION_MODE)
@@ -1231,17 +1262,8 @@
#endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
}
- if (!m_playbackControlsManager) {
- m_playbackControlsManager = adoptNS([[WebPlaybackControlsManager alloc] init]);
- [m_playbackControlsManager setAllowsPictureInPicturePlayback:m_page->preferences().allowsPictureInPictureMediaPlayback()];
- [m_playbackControlsManager setCanTogglePictureInPicture:NO];
- }
+ updateMediaPlaybackControlsManager();
- if (PlatformPlaybackSessionInterface* interface = m_page->playbackSessionManager()->controlsManagerInterface()) {
- [m_playbackControlsManager setPlaybackSessionInterfaceMac:interface];
- interface->updatePlaybackControlsManagerCanTogglePictureInPicture();
- }
-
[m_mediaTouchBarProvider setPlaybackControlsController:m_playbackControlsManager.get()];
[m_mediaPlaybackControlsView setPlaybackControlsController:m_playbackControlsManager.get()];
@@ -1278,7 +1300,7 @@
#if HAVE(TOUCH_BAR)
-bool WebViewImpl::canTogglePictureInPictureForTesting()
+bool WebViewImpl::canTogglePictureInPicture()
{
#if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
return [m_playbackControlsManager canTogglePictureInPicture];
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PictureInPictureDelegate.html (235943 => 235944)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PictureInPictureDelegate.html 2018-09-12 17:03:13 UTC (rev 235943)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PictureInPictureDelegate.html 2018-09-12 19:10:01 UTC (rev 235944)
@@ -19,8 +19,8 @@
<style>
#video {
background-color: red;
- width: 150px;
- height: 150px;
+ width: 640px;
+ height: 480px;
}
</style>
</head>
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PictureInPictureDelegate.mm (235943 => 235944)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PictureInPictureDelegate.mm 2018-09-12 17:03:13 UTC (rev 235943)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PictureInPictureDelegate.mm 2018-09-12 19:10:01 UTC (rev 235944)
@@ -114,7 +114,7 @@
TEST(PictureInPicture, WKUIDelegate)
{
RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
- RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) configuration:configuration.get()]);
+ RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 640, 480) configuration:configuration.get()]);
[configuration preferences]._fullScreenEnabled = YES;
[configuration preferences]._allowsPictureInPictureMediaPlayback = YES;
RetainPtr<PictureInPictureUIDelegate> handler = adoptNS([[PictureInPictureUIDelegate alloc] init]);
@@ -139,8 +139,17 @@
hasVideoInPictureInPictureValue = false;
hasVideoInPictureInPictureCalled = false;
+#if HAVE(TOUCH_BAR) && ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+ while (![webView _canTogglePictureInPicture])
+ [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.05]];
+
+ ASSERT_FALSE([webView _isPictureInPictureActive]);
+ [webView _togglePictureInPicture];
+#else
NSEvent *event = [NSEvent mouseEventWithType:NSEventTypeLeftMouseDown location:NSMakePoint(5, 5) modifierFlags:0 timestamp:0 windowNumber:window.get().windowNumber context:0 eventNumber:0 clickCount:0 pressure:0];
[webView mouseDown:event];
+#endif
+
TestWebKitAPI::Util::run(&hasVideoInPictureInPictureCalled);
ASSERT_TRUE(hasVideoInPictureInPictureValue);
@@ -147,12 +156,19 @@
// Wait for PIPAgent to launch, or it won't call -pipDidClose: callback.
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
-#if HAVE(TOUCH_BAR)
- ASSERT_TRUE([webView _canTogglePictureInPictureForTesting]);
+#if HAVE(TOUCH_BAR) && ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+ ASSERT_TRUE([webView _isPictureInPictureActive]);
+ ASSERT_TRUE([webView _canTogglePictureInPicture]);
#endif
hasVideoInPictureInPictureCalled = false;
+
+#if HAVE(TOUCH_BAR) && ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+ [webView _togglePictureInPicture];
+#else
[webView mouseDown:event];
+#endif
+
TestWebKitAPI::Util::run(&hasVideoInPictureInPictureCalled);
ASSERT_FALSE(hasVideoInPictureInPictureValue);
}
@@ -178,7 +194,7 @@
[webView evaluateJavaScript:@"play()" completionHandler:nil];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
- ASSERT_FALSE([webView _canTogglePictureInPictureForTesting]);
+ ASSERT_FALSE([webView _canTogglePictureInPicture]);
}
#endif // HAVE(TOUCH_BAR)