Diff
Modified: branches/safari-602-branch/Source/WebCore/ChangeLog (206544 => 206545)
--- branches/safari-602-branch/Source/WebCore/ChangeLog 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebCore/ChangeLog 2016-09-28 20:48:35 UTC (rev 206545)
@@ -1,5 +1,35 @@
2016-09-28 Babak Shafiei <[email protected]>
+ Merge r206527. rdar://problem/28499358
+
+ 2016-09-27 Wenson Hsieh <[email protected]>
+
+ Adopt MediaRemote SPI to achieve desired Now Playing behavior
+ https://bugs.webkit.org/show_bug.cgi?id=162658
+ <rdar://problem/28499358>
+
+ Reviewed by Jer Noble.
+
+ Restores the changes previously rolled out in r206444, and adopts new MediaRemote SPI to achieve the desired
+ behavior for media in background tabs without breaking other features.
+
+ Introduces 2 new unit tests in NowPlayingControlsTests.
+
+ * html/MediaElementSession.cpp:
+ (WebCore::MediaElementSession::pageAllowsNowPlayingControls):
+ * page/Page.cpp:
+ (WebCore::Page::setViewState):
+ * platform/audio/PlatformMediaSessionManager.h:
+ (WebCore::PlatformMediaSessionManager::hasActiveNowPlayingSession):
+ * platform/audio/mac/MediaSessionManagerMac.h:
+ * platform/audio/mac/MediaSessionManagerMac.mm:
+ (WebCore::MediaSessionManagerMac::updateNowPlayingInfo):
+ * platform/mac/MediaRemoteSoftLink.cpp:
+ * platform/mac/MediaRemoteSoftLink.h:
+ * platform/spi/mac/MediaRemoteSPI.h:
+
+2016-09-28 Babak Shafiei <[email protected]>
+
Merge r206520. rdar://problem/28412512
2016-09-28 Jer Noble <[email protected]>
Modified: branches/safari-602-branch/Source/WebCore/html/MediaElementSession.cpp (206544 => 206545)
--- branches/safari-602-branch/Source/WebCore/html/MediaElementSession.cpp 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebCore/html/MediaElementSession.cpp 2016-09-28 20:48:35 UTC (rev 206545)
@@ -735,8 +735,8 @@
bool MediaElementSession::pageAllowsNowPlayingControls() const
{
- // FIXME: Ideally, we should not allow Now Playing controls for the active tab in the main window.
- return true;
+ auto page = m_element.document().page();
+ return page && !page->isVisibleAndActive();
}
}
Modified: branches/safari-602-branch/Source/WebCore/page/Page.cpp (206544 => 206545)
--- branches/safari-602-branch/Source/WebCore/page/Page.cpp 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebCore/page/Page.cpp 2016-09-28 20:48:35 UTC (rev 206545)
@@ -1450,6 +1450,7 @@
ViewState::Flags oldViewState = m_viewState;
+ bool wasVisibleAndActive = isVisibleAndActive();
m_viewState = viewState;
m_focusController->setViewState(viewState);
@@ -1466,6 +1467,9 @@
for (auto* observer : m_viewStateChangeObservers)
observer->viewStateDidChange(oldViewState, m_viewState);
+
+ if (wasVisibleAndActive != isVisibleAndActive())
+ PlatformMediaSessionManager::updateNowPlayingInfoIfNecessary();
}
bool Page::isVisibleAndActive() const
Modified: branches/safari-602-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.h (206544 => 206545)
--- branches/safari-602-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.h 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.h 2016-09-28 20:48:35 UTC (rev 206545)
@@ -57,6 +57,8 @@
bool activeAudioSessionRequired() const;
bool canProduceAudio() const;
+ WEBCORE_EXPORT virtual bool hasActiveNowPlayingSession() const { return false; }
+
bool willIgnoreSystemInterruptions() const { return m_willIgnoreSystemInterruptions; }
void setWillIgnoreSystemInterruptions(bool ignore) { m_willIgnoreSystemInterruptions = ignore; }
Modified: branches/safari-602-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.h (206544 => 206545)
--- branches/safari-602-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.h 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.h 2016-09-28 20:48:35 UTC (rev 206545)
@@ -37,6 +37,8 @@
public:
virtual ~MediaSessionManagerMac();
+ bool hasActiveNowPlayingSession() const override { return m_nowPlayingActive; }
+
private:
friend class PlatformMediaSessionManager;
Modified: branches/safari-602-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm (206544 => 206545)
--- branches/safari-602-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm 2016-09-28 20:48:35 UTC (rev 206545)
@@ -130,7 +130,7 @@
if (!currentSession) {
if (m_nowPlayingActive) {
- MRMediaRemoteSetCanBeNowPlayingApplication(false);
+ MRMediaRemoteSetNowPlayingVisibility(MRMediaRemoteGetLocalOrigin(), MRNowPlayingClientVisibilityNeverVisible);
LOG(Media, "MediaSessionManagerMac::updateNowPlayingInfo - clearing now playing info");
MRMediaRemoteSetNowPlayingInfo(nullptr);
m_nowPlayingActive = false;
@@ -146,11 +146,13 @@
return;
}
- if (!MRMediaRemoteSetCanBeNowPlayingApplication(true)) {
- LOG(Media, "MediaSessionManagerMac::updateNowPlayingInfo - MRMediaRemoteSetCanBeNowPlayingApplication(true) failed");
- return;
- }
+ static dispatch_once_t enableNowPlayingToken;
+ dispatch_once(&enableNowPlayingToken, ^() {
+ MRMediaRemoteSetCanBeNowPlayingApplication(true);
+ });
+ MRMediaRemoteSetNowPlayingVisibility(MRMediaRemoteGetLocalOrigin(), MRNowPlayingClientVisibilityAlwaysVisible);
+
String title = currentSession->title();
double duration = currentSession->duration();
double rate = currentSession->state() == PlatformMediaSession::Playing ? 1 : 0;
Modified: branches/safari-602-branch/Source/WebCore/platform/mac/MediaRemoteSoftLink.cpp (206544 => 206545)
--- branches/safari-602-branch/Source/WebCore/platform/mac/MediaRemoteSoftLink.cpp 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebCore/platform/mac/MediaRemoteSoftLink.cpp 2016-09-28 20:48:35 UTC (rev 206545)
@@ -35,6 +35,7 @@
SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, MediaRemote, MRMediaRemoteAddAsyncCommandHandlerBlock, void*, (MRMediaRemoteAsyncCommandHandlerBlock block), (block))
SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, MediaRemote, MRMediaRemoteRemoveCommandHandlerBlock, void, (void* observer), (observer))
SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, MediaRemote, MRMediaRemoteSetSupportedCommands, void, (CFArrayRef commands, MROriginRef origin, dispatch_queue_t replyQ, void(^completion)(MRMediaRemoteError err)), (commands, origin, replyQ, completion))
+SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, MediaRemote, MRMediaRemoteSetNowPlayingVisibility, void, (MROriginRef origin, MRNowPlayingClientVisibility visibility), (origin, visibility))
SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, MediaRemote, MRMediaRemoteCommandInfoCreate, MRMediaRemoteCommandInfoRef, (CFAllocatorRef allocator), (allocator));
SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, MediaRemote, MRMediaRemoteCommandInfoSetCommand, void, (MRMediaRemoteCommandInfoRef commandInfo, MRMediaRemoteCommand command), (commandInfo, command))
SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, MediaRemote, MRMediaRemoteCommandInfoSetEnabled, void, (MRMediaRemoteCommandInfoRef commandInfo, Boolean enabled), (commandInfo, enabled))
Modified: branches/safari-602-branch/Source/WebCore/platform/mac/MediaRemoteSoftLink.h (206544 => 206545)
--- branches/safari-602-branch/Source/WebCore/platform/mac/MediaRemoteSoftLink.h 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebCore/platform/mac/MediaRemoteSoftLink.h 2016-09-28 20:48:35 UTC (rev 206545)
@@ -39,6 +39,8 @@
#define MRMediaRemoteRemoveCommandHandlerBlock softLink_MediaRemote_MRMediaRemoteRemoveCommandHandlerBlock
SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, MediaRemote, MRMediaRemoteSetSupportedCommands, void, (CFArrayRef commands, MROriginRef origin, dispatch_queue_t replyQ, void(^completion)(MRMediaRemoteError err)), (commands, origin, replyQ, completion))
#define MRMediaRemoteSetSupportedCommands softLink_MediaRemote_MRMediaRemoteSetSupportedCommands
+SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, MediaRemote, MRMediaRemoteSetNowPlayingVisibility, void, (MROriginRef origin, MRNowPlayingClientVisibility visibility), (origin, visibility))
+#define MRMediaRemoteSetNowPlayingVisibility softLink_MediaRemote_MRMediaRemoteSetNowPlayingVisibility
SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, MediaRemote, MRMediaRemoteCommandInfoCreate, MRMediaRemoteCommandInfoRef, (CFAllocatorRef allocator), (allocator));
#define MRMediaRemoteCommandInfoCreate softLink_MediaRemote_MRMediaRemoteCommandInfoCreate
SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, MediaRemote, MRMediaRemoteCommandInfoSetCommand, void, (MRMediaRemoteCommandInfoRef commandInfo, MRMediaRemoteCommand command), (commandInfo, command))
Modified: branches/safari-602-branch/Source/WebCore/platform/spi/mac/MediaRemoteSPI.h (206544 => 206545)
--- branches/safari-602-branch/Source/WebCore/platform/spi/mac/MediaRemoteSPI.h 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebCore/platform/spi/mac/MediaRemoteSPI.h 2016-09-28 20:48:35 UTC (rev 206545)
@@ -27,6 +27,22 @@
#if USE(MEDIAREMOTE)
+#if __has_include(<MediaRemote/MRNowPlayingTypes.h>)
+
+#include <MediaRemote/MRNowPlayingTypes.h>
+
+#else
+
+enum {
+ MRNowPlayingClientVisibilityUndefined = 0,
+ MRNowPlayingClientVisibilityAlwaysVisible,
+ MRNowPlayingClientVisibilityVisibleWhenBackgrounded,
+ MRNowPlayingClientVisibilityNeverVisible
+};
+typedef uint32_t MRNowPlayingClientVisibility;
+
+#endif
+
#if USE(APPLE_INTERNAL_SDK)
#include <MediaRemote/MediaRemote.h>
@@ -87,6 +103,7 @@
void* MRMediaRemoteAddAsyncCommandHandlerBlock(MRMediaRemoteAsyncCommandHandlerBlock);
void MRMediaRemoteRemoveCommandHandlerBlock(void *observer);
void MRMediaRemoteSetSupportedCommands(CFArrayRef commands, MROriginRef, dispatch_queue_t replyQ, void(^completion)(MRMediaRemoteError err));
+void MRMediaRemoteSetNowPlayingVisibility(MROriginRef, MRNowPlayingClientVisibility);
#pragma mark - MROrigin
Modified: branches/safari-602-branch/Source/WebKit2/ChangeLog (206544 => 206545)
--- branches/safari-602-branch/Source/WebKit2/ChangeLog 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebKit2/ChangeLog 2016-09-28 20:48:35 UTC (rev 206545)
@@ -1,5 +1,39 @@
2016-09-28 Babak Shafiei <[email protected]>
+ Merge r206527. rdar://problem/28499358
+
+ 2016-09-27 Wenson Hsieh <[email protected]>
+
+ Adopt MediaRemote SPI to achieve desired Now Playing behavior
+ https://bugs.webkit.org/show_bug.cgi?id=162658
+ <rdar://problem/28499358>
+
+ Reviewed by Jer Noble.
+
+ Plumbs Now Playing session information (for now, this is just a flag indicating whether or not there is an
+ active session) across from the web process to the UI process for testing in the form of asynchronous request/
+ handle-response messages on the WebPage and its proxy in the UI process.
+
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView _requestActiveNowPlayingSessionInfo]):
+ (-[WKWebView _handleActiveNowPlayingSessionInfoResponse:]):
+ * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+ * UIProcess/PageClient.h:
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::requestActiveNowPlayingSessionInfo):
+ (WebKit::WebPageProxy::handleActiveNowPlayingSessionInfoResponse):
+ * UIProcess/WebPageProxy.h:
+ * UIProcess/WebPageProxy.messages.in:
+ * UIProcess/mac/PageClientImpl.h:
+ * UIProcess/mac/PageClientImpl.mm:
+ (WebKit::PageClientImpl::handleActiveNowPlayingSessionInfoResponse):
+ * WebProcess/WebPage/WebPage.h:
+ * WebProcess/WebPage/WebPage.messages.in:
+ * WebProcess/WebPage/mac/WebPageMac.mm:
+ (WebKit::WebPage::requestActiveNowPlayingSessionInfo):
+
+2016-09-28 Babak Shafiei <[email protected]>
+
Merge r206135. rdar://problem/28499358
2016-09-19 Wenson Hsieh <[email protected]>
Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (206544 => 206545)
--- branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2016-09-28 20:48:35 UTC (rev 206545)
@@ -4579,6 +4579,17 @@
{
return _impl->shouldRequestCandidates();
}
+
+- (void)_requestActiveNowPlayingSessionInfo
+{
+ if (_page)
+ _page->requestActiveNowPlayingSessionInfo();
+}
+
+- (void)_handleActiveNowPlayingSessionInfoResponse:(BOOL)hasActiveSession
+{
+ // Overridden by subclasses.
+}
#endif // PLATFORM(MAC)
// Execute the supplied block after the next transaction from the WebProcess.
Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (206544 => 206545)
--- branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h 2016-09-28 20:48:35 UTC (rev 206545)
@@ -275,6 +275,8 @@
- (void)_forceRequestCandidates WK_API_AVAILABLE(macosx(WK_MAC_TBA));
- (void)_didUpdateCandidateListVisibility:(BOOL)visible WK_API_AVAILABLE(macosx(WK_MAC_TBA));
@property (nonatomic, readonly) BOOL _shouldRequestCandidates WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+- (void)_requestActiveNowPlayingSessionInfo WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+- (void)_handleActiveNowPlayingSessionInfoResponse:(BOOL)hasActiveSession WK_API_AVAILABLE(macosx(WK_MAC_TBA));
#endif
- (void)_doAfterNextPresentationUpdate:(void (^)(void))updateBlock WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/PageClient.h (206544 => 206545)
--- branches/safari-602-branch/Source/WebKit2/UIProcess/PageClient.h 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/PageClient.h 2016-09-28 20:48:35 UTC (rev 206545)
@@ -249,6 +249,7 @@
virtual void recommendedScrollbarStyleDidChange(WebCore::ScrollbarStyle) = 0;
virtual void removeNavigationGestureSnapshot() = 0;
virtual void handleControlledElementIDResponse(const String&) = 0;
+ virtual void handleActiveNowPlayingSessionInfoResponse(bool hasActiveSession) = 0;
virtual CGRect boundsOfLayerInLayerBackedWindowCoordinates(CALayer *) const = 0;
Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/WebPageProxy.cpp (206544 => 206545)
--- branches/safari-602-branch/Source/WebKit2/UIProcess/WebPageProxy.cpp 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/WebPageProxy.cpp 2016-09-28 20:48:35 UTC (rev 206545)
@@ -6304,6 +6304,16 @@
#endif
}
+void WebPageProxy::requestActiveNowPlayingSessionInfo()
+{
+ m_process->send(Messages::WebPage::RequestActiveNowPlayingSessionInfo(), m_pageID);
+}
+
+void WebPageProxy::handleActiveNowPlayingSessionInfoResponse(bool hasActiveSession) const
+{
+ m_pageClient.handleActiveNowPlayingSessionInfoResponse(hasActiveSession);
+}
+
void WebPageProxy::handleControlledElementIDResponse(const String& identifier) const
{
m_pageClient.handleControlledElementIDResponse(identifier);
Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/WebPageProxy.h (206544 => 206545)
--- branches/safari-602-branch/Source/WebKit2/UIProcess/WebPageProxy.h 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/WebPageProxy.h 2016-09-28 20:48:35 UTC (rev 206545)
@@ -1034,6 +1034,8 @@
bool hasActiveVideoForControlsManager() const;
void requestControlledElementID() const;
void handleControlledElementIDResponse(const String&) const;
+ void requestActiveNowPlayingSessionInfo();
+ void handleActiveNowPlayingSessionInfoResponse(bool hasActiveSession) const;
bool isPlayingVideoInEnhancedFullscreen() const;
#endif
Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/WebPageProxy.messages.in (206544 => 206545)
--- branches/safari-602-branch/Source/WebKit2/UIProcess/WebPageProxy.messages.in 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/WebPageProxy.messages.in 2016-09-28 20:48:35 UTC (rev 206545)
@@ -462,5 +462,6 @@
#if PLATFORM(MAC)
DidHandleAcceptedCandidate()
+ HandleActiveNowPlayingSessionInfoResponse(bool hasActiveSession)
#endif
}
Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/mac/PageClientImpl.h (206544 => 206545)
--- branches/safari-602-branch/Source/WebKit2/UIProcess/mac/PageClientImpl.h 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/mac/PageClientImpl.h 2016-09-28 20:48:35 UTC (rev 206545)
@@ -208,6 +208,7 @@
void didSameDocumentNavigationForMainFrame(SameDocumentNavigationType) override;
void removeNavigationGestureSnapshot() override;
void handleControlledElementIDResponse(const String&) override;
+ void handleActiveNowPlayingSessionInfoResponse(bool hasActiveSession) override;
void didPerformImmediateActionHitTest(const WebHitTestResultData&, bool contentPreventsDefault, API::Object*) override;
void* immediateActionAnimationControllerForHitTestResult(RefPtr<API::HitTestResult>, uint64_t, RefPtr<API::Object>) override;
Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/mac/PageClientImpl.mm (206544 => 206545)
--- branches/safari-602-branch/Source/WebKit2/UIProcess/mac/PageClientImpl.mm 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/mac/PageClientImpl.mm 2016-09-28 20:48:35 UTC (rev 206545)
@@ -763,6 +763,13 @@
#endif
}
+void PageClientImpl::handleActiveNowPlayingSessionInfoResponse(bool hasActiveSession)
+{
+#if WK_API_ENABLED
+ [m_webView _handleActiveNowPlayingSessionInfoResponse:hasActiveSession];
+#endif
+}
+
void PageClientImpl::didChangeBackgroundColor()
{
notImplemented();
Modified: branches/safari-602-branch/Source/WebKit2/WebProcess/WebPage/WebPage.h (206544 => 206545)
--- branches/safari-602-branch/Source/WebKit2/WebProcess/WebPage/WebPage.h 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebKit2/WebProcess/WebPage/WebPage.h 2016-09-28 20:48:35 UTC (rev 206545)
@@ -1187,6 +1187,7 @@
void dataDetectorsDidHideUI(WebCore::PageOverlay::PageOverlayID);
void handleAcceptedCandidate(WebCore::TextCheckingResult);
+ void requestActiveNowPlayingSessionInfo();
#endif
void setShouldDispatchFakeMouseMoveEvents(bool dispatch) { m_shouldDispatchFakeMouseMoveEvents = dispatch; }
Modified: branches/safari-602-branch/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (206544 => 206545)
--- branches/safari-602-branch/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in 2016-09-28 20:48:35 UTC (rev 206545)
@@ -413,6 +413,7 @@
DataDetectorsDidChangeUI(WebCore::PageOverlay::PageOverlayID pageOverlay)
DataDetectorsDidHideUI(WebCore::PageOverlay::PageOverlayID pageOverlay)
HandleAcceptedCandidate(struct WebCore::TextCheckingResult acceptedCandidate)
+ RequestActiveNowPlayingSessionInfo()
#endif
SetShouldDispatchFakeMouseMoveEvents(bool shouldDispatchFakeMouseMoveEvents)
Modified: branches/safari-602-branch/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (206544 => 206545)
--- branches/safari-602-branch/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm 2016-09-28 20:48:35 UTC (rev 206545)
@@ -74,6 +74,7 @@
#import <WebCore/Page.h>
#import <WebCore/PageOverlayController.h>
#import <WebCore/PlatformKeyboardEvent.h>
+#import <WebCore/PlatformMediaSessionManager.h>
#import <WebCore/PluginDocument.h>
#import <WebCore/RenderElement.h>
#import <WebCore/RenderObject.h>
@@ -159,6 +160,15 @@
send(Messages::WebPageProxy::DidHandleAcceptedCandidate());
}
+void WebPage::requestActiveNowPlayingSessionInfo()
+{
+ bool hasActiveSession = false;
+ if (auto* sharedManager = WebCore::PlatformMediaSessionManager::sharedManagerIfExists())
+ hasActiveSession = sharedManager->hasActiveNowPlayingSession();
+
+ send(Messages::WebPageProxy::HandleActiveNowPlayingSessionInfoResponse(hasActiveSession));
+}
+
NSObject *WebPage::accessibilityObjectForMainFramePlugin()
{
if (!m_page)
Modified: branches/safari-602-branch/Tools/ChangeLog (206544 => 206545)
--- branches/safari-602-branch/Tools/ChangeLog 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Tools/ChangeLog 2016-09-28 20:48:35 UTC (rev 206545)
@@ -1,5 +1,32 @@
2016-09-28 Babak Shafiei <[email protected]>
+ Merge r206527. rdar://problem/28499358
+
+ 2016-09-27 Wenson Hsieh <[email protected]>
+
+ Adopt MediaRemote SPI to achieve desired Now Playing behavior
+ https://bugs.webkit.org/show_bug.cgi?id=162658
+ <rdar://problem/28499358>
+
+ Reviewed by Jer Noble.
+
+ Introduces 2 unit tests in the new NowPlayingControlsTests test suite. Also provides some basic support for
+ mocking key window status for TestWKWebViews.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebKit2Cocoa/NowPlayingControlsTests.mm: Added.
+ (-[NowPlayingTestWebView hasActiveNowPlayingSession]):
+ (-[NowPlayingTestWebView expectHasActiveNowPlayingSession:]):
+ (-[NowPlayingTestWebView _handleActiveNowPlayingSessionInfoResponse:]):
+ (TestWebKitAPI::TEST):
+ * TestWebKitAPI/Tests/WebKit2Cocoa/large-video-test-now-playing.html: Added.
+ * TestWebKitAPI/mac/TestWKWebViewMac.mm:
+ (-[TestWKWebViewHostWindow isKeyWindow]):
+ (-[TestWKWebViewHostWindow makeKeyWindow]):
+ (-[TestWKWebViewHostWindow resignKeyWindow]):
+
+2016-09-28 Babak Shafiei <[email protected]>
+
Merge r206335. rdar://problem/28499358
2016-09-23 Wenson Hsieh <[email protected]>
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (206544 => 206545)
--- branches/safari-602-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2016-09-28 20:48:35 UTC (rev 206545)
@@ -73,6 +73,7 @@
2E7765CD16C4D80A00BA2BB1 /* mainIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */; };
2E7765CF16C4D81100BA2BB1 /* mainMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E7765CE16C4D81100BA2BB1 /* mainMac.mm */; };
2E9896151D8F093800739892 /* text-and-password-inputs.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E9896141D8F092B00739892 /* text-and-password-inputs.html */; };
+ 2ECFF5551D9B12F800B55394 /* NowPlayingControlsTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2ECFF5541D9B12F800B55394 /* NowPlayingControlsTests.mm */; };
2EFF06C31D88621E0004BB30 /* large-video-offscreen.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2EFF06C21D8862120004BB30 /* large-video-offscreen.html */; };
2EFF06C51D8867760004BB30 /* change-video-source-on-click.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2EFF06C41D8867700004BB30 /* change-video-source-on-click.html */; };
2EFF06C71D886A580004BB30 /* change-video-source-on-end.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2EFF06C61D886A560004BB30 /* change-video-source-on-end.html */; };
@@ -453,6 +454,7 @@
E1220DCA155B28AA0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */; };
E194E1BD177E53C7009C4D4E /* StopLoadingFromDidReceiveResponse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E194E1BC177E534A009C4D4E /* StopLoadingFromDidReceiveResponse.html */; };
F42DA5161D8CEFE400336F40 /* large-input-field-focus-onload.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */; };
+ F4F137921D9B683E002BEC57 /* large-video-test-now-playing.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F137911D9B6832002BEC57 /* large-video-test-now-playing.html */; };
F4F405BC1D4C0D1C007A9707 /* full-size-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */; };
F4F405BD1D4C0D1C007A9707 /* skinny-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */; };
F660AA1115A5F631003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F660AA0F15A5F624003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp */; };
@@ -580,6 +582,7 @@
7AE9E5091AE5AE8B00CF874B /* test.pdf in Copy Resources */,
7A1458FC1AD5C07000E06772 /* mouse-button-listener.html in Copy Resources */,
7C486BA11AA12567003F6F9B /* bundle-file.html in Copy Resources */,
+ F4F137921D9B683E002BEC57 /* large-video-test-now-playing.html in Copy Resources */,
2E9896151D8F093800739892 /* text-and-password-inputs.html in Copy Resources */,
F42DA5161D8CEFE400336F40 /* large-input-field-focus-onload.html in Copy Resources */,
2EFF06CD1D8A429A0004BB30 /* input-field-in-scrollable-document.html in Copy Resources */,
@@ -767,6 +770,7 @@
2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = mainIOS.mm; sourceTree = "<group>"; };
2E7765CE16C4D81100BA2BB1 /* mainMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = mainMac.mm; sourceTree = "<group>"; };
2E9896141D8F092B00739892 /* text-and-password-inputs.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "text-and-password-inputs.html"; sourceTree = "<group>"; };
+ 2ECFF5541D9B12F800B55394 /* NowPlayingControlsTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NowPlayingControlsTests.mm; sourceTree = "<group>"; };
2EFF06C21D8862120004BB30 /* large-video-offscreen.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-offscreen.html"; sourceTree = "<group>"; };
2EFF06C41D8867700004BB30 /* change-video-source-on-click.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "change-video-source-on-click.html"; sourceTree = "<group>"; };
2EFF06C61D886A560004BB30 /* change-video-source-on-end.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "change-video-source-on-end.html"; sourceTree = "<group>"; };
@@ -1138,6 +1142,7 @@
E4C9ABC71B3DB1710040A987 /* RunLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoop.cpp; sourceTree = "<group>"; };
F3FC3EE213678B7300126A65 /* libgtest.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgtest.a; sourceTree = BUILT_PRODUCTS_DIR; };
F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = "large-input-field-focus-onload.html"; path = "Tests/WebKit2Cocoa/large-input-field-focus-onload.html"; sourceTree = SOURCE_ROOT; };
+ F4F137911D9B6832002BEC57 /* large-video-test-now-playing.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-test-now-playing.html"; sourceTree = "<group>"; };
F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "full-size-autoplaying-video-with-audio.html"; sourceTree = "<group>"; };
F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "skinny-autoplaying-video-with-audio.html"; sourceTree = "<group>"; };
F660AA0C15A5F061003A1243 /* GetInjectedBundleInitializationUserDataCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetInjectedBundleInitializationUserDataCallback.cpp; sourceTree = "<group>"; };
@@ -1315,6 +1320,7 @@
46C519D81D355A7300DAA51A /* LocalStorageNullEntries.mm */,
51CD1C6A1B38CE3600142CA5 /* ModalAlerts.mm */,
1ABC3DED1899BE6D004F0626 /* Navigation.mm */,
+ 2ECFF5541D9B12F800B55394 /* NowPlayingControlsTests.mm */,
CEA6CF2219CCF5BD0064F5A7 /* OpenAndCloseWindow.mm */,
C95501BE19AD2FAF0049BE3E /* Preferences.mm */,
5798E2AF1CAF5C2800C5CBA0 /* ProvisionalURLNotChange.mm */,
@@ -1419,6 +1425,7 @@
2E1DFDF01D42E14400714A00 /* large-video-seek-to-beginning-and-play-after-ending.html */,
2E1B7B011D41B1B3007558B4 /* large-video-hides-controls-after-seek-to-end.html */,
2E1DFDEE1D42A6EB00714A00 /* large-videos-with-audio-autoplay.html */,
+ F4F137911D9B6832002BEC57 /* large-video-test-now-playing.html */,
2E9896141D8F092B00739892 /* text-and-password-inputs.html */,
2EFF06CC1D8A42910004BB30 /* input-field-in-scrollable-document.html */,
2EFF06C61D886A560004BB30 /* change-video-source-on-end.html */,
@@ -2246,6 +2253,7 @@
37BCA61C1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm in Sources */,
7C83E0411D0A63F200FEBCF3 /* CandidateTests.mm in Sources */,
7CEFA9661AC0B9E200B910FD /* _WKUserContentExtensionStore.mm in Sources */,
+ 2ECFF5551D9B12F800B55394 /* NowPlayingControlsTests.mm in Sources */,
7CCE7EE01A411A9A00447C4C /* EditorCommands.mm in Sources */,
7CCE7EBF1A411A7E00447C4C /* ElementAtPointInWebFrame.mm in Sources */,
5E4B1D2E1D404C6100053621 /* WKScrollViewDelegateCrash.mm in Sources */,
Added: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/NowPlayingControlsTests.mm (0 => 206545)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/NowPlayingControlsTests.mm (rev 0)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/NowPlayingControlsTests.mm 2016-09-28 20:48:35 UTC (rev 206545)
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#import "PlatformUtilities.h"
+#import "TestWKWebViewMac.h"
+
+#import <WebKit/WKWebViewConfigurationPrivate.h>
+#import <WebKit/WKWebViewPrivate.h>
+
+#if WK_API_ENABLED && PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101201
+
+@interface NowPlayingTestWebView : TestWKWebView
+@property (nonatomic, readonly) BOOL hasActiveNowPlayingSession;
+@end
+
+@implementation NowPlayingTestWebView {
+ bool _receivedNowPlayingInfoResponse;
+ BOOL _hasActiveNowPlayingSession;
+}
+- (BOOL)hasActiveNowPlayingSession
+{
+ _receivedNowPlayingInfoResponse = false;
+ [self _requestActiveNowPlayingSessionInfo];
+ TestWebKitAPI::Util::run(&_receivedNowPlayingInfoResponse);
+
+ return _hasActiveNowPlayingSession;
+}
+
+- (void)expectHasActiveNowPlayingSession:(BOOL)hasActiveNowPlayingSession
+{
+ bool finishedWaiting = false;
+ while (!finishedWaiting) {
+ [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantPast]];
+ finishedWaiting = self.hasActiveNowPlayingSession == hasActiveNowPlayingSession;
+ }
+}
+
+- (void)_handleActiveNowPlayingSessionInfoResponse:(BOOL)hasActiveSession
+{
+ _hasActiveNowPlayingSession = hasActiveSession;
+ _receivedNowPlayingInfoResponse = true;
+}
+@end
+
+namespace TestWebKitAPI {
+
+TEST(NowPlayingControlsTests, NowPlayingControlsDoNotShowForForegroundPage)
+{
+ WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
+ configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
+ NowPlayingTestWebView *webView = [[NowPlayingTestWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration];
+ [webView loadTestPageNamed:@"large-video-test-now-playing"];
+ [webView waitForMessage:@"playing"];
+
+ [webView.window setIsVisible:YES];
+ [webView.window makeKeyWindow];
+ [webView expectHasActiveNowPlayingSession:NO];
+}
+
+TEST(NowPlayingControlsTests, NowPlayingControlsShowForBackgroundPage)
+{
+ WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
+ configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
+ NowPlayingTestWebView *webView = [[NowPlayingTestWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration];
+ [webView loadTestPageNamed:@"large-video-test-now-playing"];
+ [webView waitForMessage:@"playing"];
+
+ [webView.window setIsVisible:NO];
+ [webView.window resignKeyWindow];
+ [webView expectHasActiveNowPlayingSession:YES];
+}
+
+} // namespace TestWebKitAPI
+
+#endif // WK_API_ENABLED && PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101201
Added: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-test-now-playing.html (0 => 206545)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-test-now-playing.html (rev 0)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-test-now-playing.html 2016-09-28 20:48:35 UTC (rev 206545)
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <style>
+ video {
+ width: 480px;
+ height: 320px;
+ position: absolute;
+ }
+ </style>
+ <script>
+ function playing() {
+ setTimeout(function() {
+ try {
+ window.webkit.messageHandlers.testHandler.postMessage("playing");
+ } catch(e) {
+ }
+ }, 0);
+ }
+ </script>
+</head>
+<body>
+ <video autoplay _onplaying_=playing()><source src=""
+</body>
+<html>
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/mac/TestWKWebViewMac.mm (206544 => 206545)
--- branches/safari-602-branch/Tools/TestWebKitAPI/mac/TestWKWebViewMac.mm 2016-09-28 20:48:27 UTC (rev 206544)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/mac/TestWKWebViewMac.mm 2016-09-28 20:48:35 UTC (rev 206545)
@@ -63,7 +63,9 @@
@interface TestWKWebViewHostWindow : NSWindow
@end
-@implementation TestWKWebViewHostWindow
+@implementation TestWKWebViewHostWindow {
+ BOOL _forceKeyWindow;
+}
static int gEventNumber = 1;
@@ -110,6 +112,26 @@
#endif
}
+- (BOOL)isKeyWindow
+{
+ return _forceKeyWindow || [super isKeyWindow];
+}
+
+- (void)makeKeyWindow
+{
+ if (_forceKeyWindow)
+ return;
+
+ _forceKeyWindow = YES;
+ [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowDidBecomeKeyNotification object:self];
+}
+
+- (void)resignKeyWindow
+{
+ _forceKeyWindow = NO;
+ [super resignKeyWindow];
+}
+
@end
@implementation TestWKWebView {