Title: [227472] branches/safari-605-branch
Revision
227472
Author
jmarc...@apple.com
Date
2018-01-23 21:22:25 -0800 (Tue, 23 Jan 2018)

Log Message

Cherry-pick r227457. rdar://problem/36807161

Modified Paths

Diff

Modified: branches/safari-605-branch/Source/WebCore/ChangeLog (227471 => 227472)


--- branches/safari-605-branch/Source/WebCore/ChangeLog	2018-01-24 04:59:24 UTC (rev 227471)
+++ branches/safari-605-branch/Source/WebCore/ChangeLog	2018-01-24 05:22:25 UTC (rev 227472)
@@ -1,5 +1,45 @@
 2018-01-23  Jason Marcell  <jmarc...@apple.com>
 
+        Cherry-pick r227457. rdar://problem/36807161
+
+    2018-01-23  Eric Carlson  <eric.carl...@apple.com>
+
+            Resign NowPlaying status when no media element is eligible
+            https://bugs.webkit.org/show_bug.cgi?id=181914
+            <rdar://problem/35294116>
+
+            Reviewed by Jer Noble.
+
+            Updated API test.
+
+            * html/HTMLMediaElement.cpp:
+            (WebCore::HTMLMediaElement::removedFromAncestor): Call mediaSession->clientCharacteristicsChanged
+            so NowPlaying status will be updated.
+
+            * html/MediaElementSession.cpp:
+            (WebCore::MediaElementSession::playbackPermitted const): Return early when the media
+            element has been suspended.
+            (WebCore::MediaElementSession::canShowControlsManager const): Return false when being queried
+            for NowPlaying status in an inactive document or when element has been suspended.
+            (WebCore::isMainContentForPurposesOfAutoplay): Return early if it isn't safe to update
+            style because HitTest can force a layout.
+            (WebCore::MediaElementSession::updateIsMainContent const): Ditto.
+
+            * platform/audio/PlatformMediaSessionManager.cpp:
+            (WebCore::PlatformMediaSessionManager::updateNowPlayingInfoIfNecessary): Implement in for all
+            ports.
+            * platform/audio/PlatformMediaSessionManager.h:
+            (WebCore::PlatformMediaSessionManager::registeredAsNowPlayingApplication const):
+            * platform/audio/ios/MediaSessionManagerIOS.h:
+            * platform/audio/mac/MediaSessionManagerMac.h:
+            * platform/audio/mac/MediaSessionManagerMac.mm:
+            (WebCore::MediaSessionManagerMac::updateNowPlayingInfo): Call MRMediaRemoteSetCanBeNowPlayingApplication
+            whenever status changes.
+            (WebCore::PlatformMediaSessionManager::updateNowPlayingInfoIfNecessary): Deleted, implemented
+            in the base class.
+
+2018-01-23  Jason Marcell  <jmarc...@apple.com>
+
         Cherry-pick r227425. rdar://problem/36791667
 
     2018-01-23  Brady Eidson  <beid...@apple.com>

Modified: branches/safari-605-branch/Source/WebCore/html/HTMLMediaElement.cpp (227471 => 227472)


--- branches/safari-605-branch/Source/WebCore/html/HTMLMediaElement.cpp	2018-01-24 04:59:24 UTC (rev 227471)
+++ branches/safari-605-branch/Source/WebCore/html/HTMLMediaElement.cpp	2018-01-24 05:22:25 UTC (rev 227472)
@@ -971,6 +971,9 @@
         m_pauseAfterDetachedTaskQueue.enqueueTask(std::bind(&HTMLMediaElement::pauseAfterDetachedTask, this));
     }
 
+    if (m_mediaSession)
+        m_mediaSession->clientCharacteristicsChanged();
+
     HTMLElement::removedFromAncestor(removalType, oldParentOfRemovedTree);
 }
 

Modified: branches/safari-605-branch/Source/WebCore/html/HTMLMediaElement.h (227471 => 227472)


--- branches/safari-605-branch/Source/WebCore/html/HTMLMediaElement.h	2018-01-24 04:59:24 UTC (rev 227471)
+++ branches/safari-605-branch/Source/WebCore/html/HTMLMediaElement.h	2018-01-24 05:22:25 UTC (rev 227472)
@@ -551,6 +551,8 @@
 
     bool willLog(WTFLogLevel) const;
 
+    bool isSuspended() const final;
+
 protected:
     HTMLMediaElement(const QualifiedName&, Document&, bool createdByParser);
     virtual void finishInitialization();
@@ -864,7 +866,6 @@
     bool shouldOverrideBackgroundLoadingRestriction() const override;
     bool canProduceAudio() const final;
     bool processingUserGestureForMedia() const final;
-    bool isSuspended() const final;
 
     void pageMutedStateDidChange() override;
 

Modified: branches/safari-605-branch/Source/WebCore/html/MediaElementSession.cpp (227471 => 227472)


--- branches/safari-605-branch/Source/WebCore/html/MediaElementSession.cpp	2018-01-24 04:59:24 UTC (rev 227471)
+++ branches/safari-605-branch/Source/WebCore/html/MediaElementSession.cpp	2018-01-24 05:22:25 UTC (rev 227472)
@@ -162,6 +162,9 @@
 
 SuccessOr<MediaPlaybackDenialReason> MediaElementSession::playbackPermitted(const HTMLMediaElement& element) const
 {
+    if (m_element.isSuspended())
+        return { };
+
     if (element.document().isMediaDocument() && !element.document().ownerElement())
         return { };
 
@@ -295,6 +298,11 @@
 
 bool MediaElementSession::canShowControlsManager(PlaybackControlsPurpose purpose) const
 {
+    if (m_element.isSuspended() || !m_element.inActiveDocument()) {
+        LOG(Media, "MediaElementSession::canShowControlsManager - returning FALSE: isSuspended()");
+        return false;
+    }
+
     if (m_element.isFullscreen()) {
         LOG(Media, "MediaElementSession::canShowControlsManager - returning TRUE: Is fullscreen");
         return true;
@@ -335,11 +343,6 @@
         return false;
     }
 
-    if (m_element.document().activeDOMObjectsAreSuspended()) {
-        LOG(Media, "MediaElementSession::canShowControlsManager - returning FALSE: activeDOMObjectsAreSuspended()");
-        return false;
-    }
-
     if (!playbackPermitted(m_element)) {
         LOG(Media, "MediaElementSession::canShowControlsManager - returning FALSE: Playback not permitted");
         return false;
@@ -691,7 +694,8 @@
 
 static bool isMainContentForPurposesOfAutoplay(const HTMLMediaElement& element)
 {
-    if (!element.hasAudio() || !element.hasVideo())
+    Document& document = element.document();
+    if (!document.isSafeToUpdateStyleOrLayout() || !element.hasAudio() || !element.hasVideo())
         return false;
 
     // Elements which have not yet been laid out, or which are not yet in the DOM, cannot be main content.
@@ -711,7 +715,6 @@
         return false;
 
     // Main content elements must be in the main frame.
-    Document& document = element.document();
     if (!document.frame() || !document.frame()->isMainFrame())
         return false;
 
@@ -818,6 +821,9 @@
 
 bool MediaElementSession::updateIsMainContent() const
 {
+    if (m_element.isSuspended())
+        return false;
+
     bool wasMainContent = m_isMainContent;
     m_isMainContent = isMainContentForPurposesOfAutoplay(m_element);
 

Modified: branches/safari-605-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp (227471 => 227472)


--- branches/safari-605-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp	2018-01-24 04:59:24 UTC (rev 227471)
+++ branches/safari-605-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp	2018-01-24 05:22:25 UTC (rev 227472)
@@ -33,12 +33,6 @@
 
 namespace WebCore {
 
-#if !PLATFORM(MAC)
-void PlatformMediaSessionManager::updateNowPlayingInfoIfNecessary()
-{
-}
-#endif
-
 #if ENABLE(VIDEO) || ENABLE(WEB_AUDIO)
 
 #if !PLATFORM(COCOA)
@@ -57,6 +51,12 @@
 }
 #endif // !PLATFORM(COCOA)
 
+void PlatformMediaSessionManager::updateNowPlayingInfoIfNecessary()
+{
+    if (auto existingManager = PlatformMediaSessionManager::sharedManagerIfExists())
+        existingManager->scheduleUpdateNowPlayingInfo();
+}
+
 PlatformMediaSessionManager::PlatformMediaSessionManager()
     : m_systemSleepListener(PAL::SystemSleepListener::create(*this))
 {

Modified: branches/safari-605-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.h (227471 => 227472)


--- branches/safari-605-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.h	2018-01-24 04:59:24 UTC (rev 227471)
+++ branches/safari-605-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.h	2018-01-24 05:22:25 UTC (rev 227472)
@@ -61,6 +61,7 @@
     WEBCORE_EXPORT virtual double lastUpdatedNowPlayingDuration() const { return NAN; }
     WEBCORE_EXPORT virtual double lastUpdatedNowPlayingElapsedTime() const { return NAN; }
     WEBCORE_EXPORT virtual uint64_t lastUpdatedNowPlayingInfoUniqueIdentifier() const { return 0; }
+    WEBCORE_EXPORT virtual bool registeredAsNowPlayingApplication() const { return false; }
 
     bool willIgnoreSystemInterruptions() const { return m_willIgnoreSystemInterruptions; }
     void setWillIgnoreSystemInterruptions(bool ignore) { m_willIgnoreSystemInterruptions = ignore; }

Modified: branches/safari-605-branch/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.h (227471 => 227472)


--- branches/safari-605-branch/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.h	2018-01-24 04:59:24 UTC (rev 227471)
+++ branches/safari-605-branch/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.h	2018-01-24 05:22:25 UTC (rev 227472)
@@ -73,6 +73,7 @@
     double lastUpdatedNowPlayingDuration() const final { return m_reportedDuration; }
     double lastUpdatedNowPlayingElapsedTime() const final { return m_reportedCurrentTime; }
     uint64_t lastUpdatedNowPlayingInfoUniqueIdentifier() const final { return m_lastUpdatedNowPlayingInfoUniqueIdentifier; }
+    bool registeredAsNowPlayingApplication() const final { return m_nowPlayingActive; }
 
     PlatformMediaSession* nowPlayingEligibleSession();
     

Modified: branches/safari-605-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.h (227471 => 227472)


--- branches/safari-605-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.h	2018-01-24 04:59:24 UTC (rev 227471)
+++ branches/safari-605-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.h	2018-01-24 05:22:25 UTC (rev 227472)
@@ -41,6 +41,7 @@
     double lastUpdatedNowPlayingDuration() const final { return m_lastUpdatedNowPlayingDuration; }
     double lastUpdatedNowPlayingElapsedTime() const final { return m_lastUpdatedNowPlayingElapsedTime; }
     uint64_t lastUpdatedNowPlayingInfoUniqueIdentifier() const final { return m_lastUpdatedNowPlayingInfoUniqueIdentifier; }
+    bool registeredAsNowPlayingApplication() const final { return m_registeredAsNowPlayingApplication; }
 
 private:
     friend class PlatformMediaSessionManager;
@@ -61,6 +62,7 @@
 
     bool m_nowPlayingActive { false };
     bool m_isInBackground { false };
+    bool m_registeredAsNowPlayingApplication { false };
 
     // For testing purposes only.
     String m_lastUpdatedNowPlayingTitle;

Modified: branches/safari-605-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm (227471 => 227472)


--- branches/safari-605-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm	2018-01-24 04:59:24 UTC (rev 227471)
+++ branches/safari-605-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm	2018-01-24 05:22:25 UTC (rev 227472)
@@ -54,12 +54,6 @@
     return platformMediaSessionManager;
 }
 
-void PlatformMediaSessionManager::updateNowPlayingInfoIfNecessary()
-{
-    if (auto existingManager = (MediaSessionManagerMac *)PlatformMediaSessionManager::sharedManagerIfExists())
-        existingManager->scheduleUpdateNowPlayingInfo();
-}
-
 MediaSessionManagerMac::MediaSessionManagerMac()
     : PlatformMediaSessionManager()
 {
@@ -136,6 +130,10 @@
             MRMediaRemoteSetNowPlayingVisibility(MRMediaRemoteGetLocalOrigin(), MRNowPlayingClientVisibilityNeverVisible);
 
         LOG(Media, "MediaSessionManagerMac::updateNowPlayingInfo - clearing now playing info");
+
+        MRMediaRemoteSetCanBeNowPlayingApplication(false);
+        m_registeredAsNowPlayingApplication = false;
+
         MRMediaRemoteSetNowPlayingInfo(nullptr);
         m_nowPlayingActive = false;
         m_lastUpdatedNowPlayingTitle = emptyString();
@@ -154,10 +152,10 @@
         return;
     }
 
-    static dispatch_once_t enableNowPlayingToken;
-    dispatch_once(&enableNowPlayingToken, ^() {
+    if (!m_registeredAsNowPlayingApplication) {
+        m_registeredAsNowPlayingApplication = true;
         MRMediaRemoteSetCanBeNowPlayingApplication(true);
-    });
+    }
 
     String title = currentSession->title();
     double duration = currentSession->supportsSeeking() ? currentSession->duration() : MediaPlayer::invalidTime();

Modified: branches/safari-605-branch/Source/WebKit/ChangeLog (227471 => 227472)


--- branches/safari-605-branch/Source/WebKit/ChangeLog	2018-01-24 04:59:24 UTC (rev 227471)
+++ branches/safari-605-branch/Source/WebKit/ChangeLog	2018-01-24 05:22:25 UTC (rev 227472)
@@ -1,5 +1,29 @@
 2018-01-23  Jason Marcell  <jmarc...@apple.com>
 
+        Cherry-pick r227457. rdar://problem/36807161
+
+    2018-01-23  Eric Carlson  <eric.carl...@apple.com>
+
+            Resign NowPlaying status when no media element is eligible
+            https://bugs.webkit.org/show_bug.cgi?id=181914
+            <rdar://problem/35294116>
+
+            Reviewed by Jer Noble.
+
+            * UIProcess/API/Cocoa/WKWebView.mm:
+            (-[WKWebView _requestActiveNowPlayingSessionInfo:]): Return registeredAsNowPlayingApplication
+            status.
+            * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+
+            * UIProcess/WebPageProxy.cpp:
+            (WebKit::WebPageProxy::nowPlayingInfoCallback): Ditto.
+            * UIProcess/WebPageProxy.h:
+            * UIProcess/WebPageProxy.messages.in:
+            * WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
+            (WebKit::WebPage::requestActiveNowPlayingSessionInfo): Ditto.
+
+2018-01-23  Jason Marcell  <jmarc...@apple.com>
+
         Cherry-pick r227425. rdar://problem/36791667
 
     2018-01-23  Brady Eidson  <beid...@apple.com>

Modified: branches/safari-605-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (227471 => 227472)


--- branches/safari-605-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2018-01-24 04:59:24 UTC (rev 227471)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2018-01-24 05:22:25 UTC (rev 227472)
@@ -6072,16 +6072,16 @@
 
 #endif // PLATFORM(MAC)
 
-- (void)_requestActiveNowPlayingSessionInfo:(void(^)(BOOL, NSString*, double, double, NSInteger))callback
+- (void)_requestActiveNowPlayingSessionInfo:(void(^)(BOOL, BOOL, NSString*, double, double, NSInteger))callback
 {
     if (!_page) {
-        callback(NO, @"", std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(), 0);
+        callback(NO, NO, @"", std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(), 0);
         return;
     }
 
     auto handler = makeBlockPtr(callback);
-    auto localCallback = WebKit::NowPlayingInfoCallback::create([handler](bool active, String title, double duration, double elapsedTime, uint64_t uniqueIdentifier, WebKit::CallbackBase::Error) {
-        handler(active, title, duration, elapsedTime, uniqueIdentifier);
+    auto localCallback = WebKit::NowPlayingInfoCallback::create([handler](bool active, bool registeredAsNowPlayingApplication, String title, double duration, double elapsedTime, uint64_t uniqueIdentifier, WebKit::CallbackBase::Error) {
+        handler(active, registeredAsNowPlayingApplication, title, duration, elapsedTime, uniqueIdentifier);
     });
 
     _page->requestActiveNowPlayingSessionInfo(WTFMove(localCallback));

Modified: branches/safari-605-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (227471 => 227472)


--- branches/safari-605-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2018-01-24 04:59:24 UTC (rev 227471)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2018-01-24 05:22:25 UTC (rev 227472)
@@ -442,7 +442,7 @@
 - (void)_setFooterBannerHeight:(int)height WK_API_AVAILABLE(macosx(10.12.3));
 #endif
 
-- (void)_requestActiveNowPlayingSessionInfo:(void(^)(BOOL, NSString*, double, double, NSInteger))callback WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_requestActiveNowPlayingSessionInfo:(void(^)(BOOL, BOOL, NSString*, double, double, NSInteger))callback WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 - (void)_setPageScale:(CGFloat)scale withOrigin:(CGPoint)origin WK_API_AVAILABLE(ios(10.3));
 - (CGFloat)_pageScale WK_API_AVAILABLE(ios(10.3));

Modified: branches/safari-605-branch/Source/WebKit/UIProcess/WebPageProxy.cpp (227471 => 227472)


--- branches/safari-605-branch/Source/WebKit/UIProcess/WebPageProxy.cpp	2018-01-24 04:59:24 UTC (rev 227471)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/WebPageProxy.cpp	2018-01-24 05:22:25 UTC (rev 227472)
@@ -6814,7 +6814,7 @@
     m_process->send(Messages::WebPage::RequestActiveNowPlayingSessionInfo(callbackID), m_pageID);
 }
 
-void WebPageProxy::nowPlayingInfoCallback(bool hasActiveSession, const String& title, double duration, double elapsedTime, uint64_t uniqueIdentifier, CallbackID callbackID)
+void WebPageProxy::nowPlayingInfoCallback(bool hasActiveSession, bool registeredAsNowPlayingApplication, const String& title, double duration, double elapsedTime, uint64_t uniqueIdentifier, CallbackID callbackID)
 {
     auto callback = m_callbacks.take<NowPlayingInfoCallback>(callbackID);
     if (!callback) {
@@ -6822,7 +6822,7 @@
         return;
     }
 
-    callback->performCallbackWithReturnValue(hasActiveSession, title, duration, elapsedTime, uniqueIdentifier);
+    callback->performCallbackWithReturnValue(hasActiveSession, registeredAsNowPlayingApplication, title, duration, elapsedTime, uniqueIdentifier);
 }
 #endif
 

Modified: branches/safari-605-branch/Source/WebKit/UIProcess/WebPageProxy.h (227471 => 227472)


--- branches/safari-605-branch/Source/WebKit/UIProcess/WebPageProxy.h	2018-01-24 04:59:24 UTC (rev 227471)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/WebPageProxy.h	2018-01-24 05:22:25 UTC (rev 227472)
@@ -293,7 +293,7 @@
 
 #if PLATFORM(COCOA)
 typedef GenericCallback<const WebCore::MachSendRight&> MachSendRightCallback;
-typedef GenericCallback<bool, String, double, double, uint64_t> NowPlayingInfoCallback;
+typedef GenericCallback<bool, bool, String, double, double, uint64_t> NowPlayingInfoCallback;
 #endif
 
 class WebPageProxy : public API::ObjectImpl<API::Object::Type::Page>
@@ -1122,7 +1122,7 @@
 
 #if PLATFORM(COCOA)
     void requestActiveNowPlayingSessionInfo(Ref<NowPlayingInfoCallback>&&);
-    void nowPlayingInfoCallback(bool, const String&, double, double, uint64_t, CallbackID);
+    void nowPlayingInfoCallback(bool, bool, const String&, double, double, uint64_t, CallbackID);
 #endif
 
 #if ENABLE(MEDIA_SESSION)

Modified: branches/safari-605-branch/Source/WebKit/UIProcess/WebPageProxy.messages.in (227471 => 227472)


--- branches/safari-605-branch/Source/WebKit/UIProcess/WebPageProxy.messages.in	2018-01-24 04:59:24 UTC (rev 227471)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/WebPageProxy.messages.in	2018-01-24 05:22:25 UTC (rev 227472)
@@ -202,7 +202,7 @@
 #endif
 #if PLATFORM(COCOA)
     MachSendRightCallback(WebCore::MachSendRight sendRight, WebKit::CallbackID callbackID)
-    NowPlayingInfoCallback(bool active, String title, double duration, double elapsedTime, uint64_t uniqueIdentifier, WebKit::CallbackID callbackID)
+    NowPlayingInfoCallback(bool active, bool registeredAsNowPlayingApplication, String title, double duration, double elapsedTime, uint64_t uniqueIdentifier, WebKit::CallbackID callbackID)
 #endif
 
     PageScaleFactorDidChange(double scaleFactor)

Modified: branches/safari-605-branch/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm (227471 => 227472)


--- branches/safari-605-branch/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm	2018-01-24 04:59:24 UTC (rev 227471)
+++ branches/safari-605-branch/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm	2018-01-24 05:22:25 UTC (rev 227472)
@@ -48,6 +48,7 @@
     double duration = NAN;
     double elapsedTime = NAN;
     uint64_t uniqueIdentifier = 0;
+    bool registeredAsNowPlayingApplication = false;
     if (auto* sharedManager = WebCore::PlatformMediaSessionManager::sharedManagerIfExists()) {
         hasActiveSession = sharedManager->hasActiveNowPlayingSession();
         title = sharedManager->lastUpdatedNowPlayingTitle();
@@ -54,9 +55,10 @@
         duration = sharedManager->lastUpdatedNowPlayingDuration();
         elapsedTime = sharedManager->lastUpdatedNowPlayingElapsedTime();
         uniqueIdentifier = sharedManager->lastUpdatedNowPlayingInfoUniqueIdentifier();
+        registeredAsNowPlayingApplication = sharedManager->registeredAsNowPlayingApplication();
     }
 
-    send(Messages::WebPageProxy::NowPlayingInfoCallback(hasActiveSession, title, duration, elapsedTime, uniqueIdentifier, callbackID));
+    send(Messages::WebPageProxy::NowPlayingInfoCallback(hasActiveSession, registeredAsNowPlayingApplication, title, duration, elapsedTime, uniqueIdentifier, callbackID));
 }
 
 } // namespace WebKit

Modified: branches/safari-605-branch/Tools/ChangeLog (227471 => 227472)


--- branches/safari-605-branch/Tools/ChangeLog	2018-01-24 04:59:24 UTC (rev 227471)
+++ branches/safari-605-branch/Tools/ChangeLog	2018-01-24 05:22:25 UTC (rev 227472)
@@ -1,3 +1,20 @@
+2018-01-23  Jason Marcell  <jmarc...@apple.com>
+
+        Cherry-pick r227457. rdar://problem/36807161
+
+    2018-01-23  Eric Carlson  <eric.carl...@apple.com>
+
+            Resign NowPlaying status when no media element is eligible
+            https://bugs.webkit.org/show_bug.cgi?id=181914
+            <rdar://problem/35294116>
+
+            Reviewed by Jer Noble.
+
+            * TestWebKitAPI/Tests/WebKitCocoa/NowPlayingControlsTests.mm:
+            (-[NowPlayingTestWebView hasActiveNowPlayingSession]):
+            (TestWebKitAPI::TEST):
+            * TestWebKitAPI/Tests/WebKitCocoa/large-video-test-now-playing.html:
+
 2018-01-22  Jason Marcell  <jmarc...@apple.com>
 
         Cherry-pick r227351. rdar://problem/36746029

Modified: branches/safari-605-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/NowPlayingControlsTests.mm (227471 => 227472)


--- branches/safari-605-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/NowPlayingControlsTests.mm	2018-01-24 04:59:24 UTC (rev 227471)
+++ branches/safari-605-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/NowPlayingControlsTests.mm	2018-01-24 05:22:25 UTC (rev 227472)
@@ -35,6 +35,7 @@
 
 @interface NowPlayingTestWebView : TestWKWebView
 @property (nonatomic, readonly) BOOL hasActiveNowPlayingSession;
+@property (nonatomic, readonly) BOOL registeredAsNowPlayingApplication;
 @property (readonly) NSString *lastUpdatedTitle;
 @property (readonly) double lastUpdatedDuration;
 @property (readonly) double lastUpdatedElapsedTime;
@@ -44,13 +45,15 @@
 @implementation NowPlayingTestWebView {
     bool _receivedNowPlayingInfoResponse;
     BOOL _hasActiveNowPlayingSession;
+    BOOL _registeredAsNowPlayingApplication;
 }
 - (BOOL)hasActiveNowPlayingSession
 {
     _receivedNowPlayingInfoResponse = false;
 
-    auto completionHandler = [retainedSelf = retainPtr(self), self](BOOL active, NSString *title, double duration, double elapsedTime, NSInteger uniqueIdentifier) {
+    auto completionHandler = [retainedSelf = retainPtr(self), self](BOOL active, BOOL registeredAsNowPlayingApplication, NSString *title, double duration, double elapsedTime, NSInteger uniqueIdentifier) {
         _hasActiveNowPlayingSession = active;
+        _registeredAsNowPlayingApplication = registeredAsNowPlayingApplication;
         _lastUpdatedTitle = [title copy];
         _lastUpdatedDuration = duration;
         _lastUpdatedElapsedTime = elapsedTime;
@@ -185,6 +188,31 @@
     ASSERT_TRUE(isnan(webView.get().lastUpdatedElapsedTime));
     ASSERT_TRUE(!webView.get().lastUniqueIdentifier);
 }
+
+TEST(NowPlayingControlsTests, NowPlayingControlsCheckRegistered)
+{
+    WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
+    configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
+    auto webView = adoptNS([[NowPlayingTestWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration]);
+    [webView loadTestPageNamed:@"large-video-test-now-playing"];
+    [webView waitForMessage:@"playing"];
+    [webView setWindowVisible:NO];
+    [webView.get().window resignKeyWindow];
+
+    [webView expectHasActiveNowPlayingSession:YES];
+    ASSERT_TRUE(webView.get().registeredAsNowPlayingApplication);
+
+    [webView stringByEvaluatingJavaScript:@"pause()"];
+    [webView waitForMessage:@"paused"];
+    [webView expectHasActiveNowPlayingSession:YES];
+    ASSERT_TRUE(webView.get().registeredAsNowPlayingApplication);
+
+    auto result = [webView stringByEvaluatingJavaScript:@"removeVideoElement()"];
+    ASSERT_STREQ("<null>", result.UTF8String);
+    [webView expectHasActiveNowPlayingSession:NO];
+    ASSERT_FALSE(webView.get().registeredAsNowPlayingApplication);
+}
+
 #endif // PLATFORM(MAC)
 
 #if PLATFORM(IOS)

Modified: branches/safari-605-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/large-video-test-now-playing.html (227471 => 227472)


--- branches/safari-605-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/large-video-test-now-playing.html	2018-01-24 04:59:24 UTC (rev 227471)
+++ branches/safari-605-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/large-video-test-now-playing.html	2018-01-24 05:22:25 UTC (rev 227472)
@@ -8,6 +8,12 @@
             position: absolute;
         }
 
+        button {
+            top: 320px;
+            left: 20px;
+            position: absolute;
+        }
+
         body {
             margin: 0;
         }
@@ -25,9 +31,30 @@
         function mousedown() {
             document.querySelector("video").muted = true;
         }
+
+        function removeVideoElement() {
+            document.body.removeChild(document.querySelector("video"));
+            return document.querySelector("video");
+        }
+
+        function pause() {
+            document.querySelector("video").pause();
+        }
+
+        function stopped() {
+            setTimeout(function() {
+               try {
+                    window.webkit.messageHandlers.testHandler.postMessage("paused");
+               } catch(e) {
+                   console.debug(`error: ${e}`);
+               }
+           }, 0);
+        }
+
     </script>
 </head>
 <body>
-    <video autoplay title="foo" _onmousedown_=mousedown() _onplaying_=playing()><source src=""
+    <video autoplay title="foo" _onmousedown_=mousedown() _onplaying_=playing() _onpause_=stopped()><source src=""
+    <button _onclick_="console.log(removeVideoElement())">Stop!</button>
 </body>
 <html>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to