[Mac] Restructure WebMediaSessionManager for testing
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 29 Aug 2015 00:14:54 +0000 (00:14 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 29 Aug 2015 00:14:54 +0000 (00:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=148593

Reviewed by Jer Noble.

Source/WebCore:

No new tests, no functional change.

* Modules/mediasession/WebMediaSessionManager.cpp:
(WebCore::mediaProducerStateString): Add some missing states.
(WebCore::webMediaSessionManagerOverride): New.
(WebCore::WebMediaSessionManager::singleton): New.
(WebCore::WebMediaSessionManager::setWebMediaSessionManagerOverride): New, will allow runtime
  registration of a mock manager.
* Modules/mediasession/WebMediaSessionManager.h:

* platform/graphics/avfoundation/WebMediaSessionManagerMac.cpp:
(WebCore::WebMediaSessionManager::platformManager): Renamed from singleton.
(WebCore::WebMediaSessionManagerMac::singleton): Deleted.
* platform/graphics/avfoundation/WebMediaSessionManagerMac.h:

Source/WebKit/mac:

* WebView/WebMediaPlaybackTargetPicker.mm:
(WebMediaPlaybackTargetPicker::addPlaybackTargetPickerClient): Call WebMediaSessionManager::singleton,
  not WebMediaSessionManagerMac::singleton.
(WebMediaPlaybackTargetPicker::removePlaybackTargetPickerClient): Ditto.
(WebMediaPlaybackTargetPicker::showPlaybackTargetPicker): Ditto.
(WebMediaPlaybackTargetPicker::playbackTargetPickerClientStateDidChange): Ditto.
(WebMediaPlaybackTargetPicker::setPlaybackTarget): Ditto.
(WebMediaPlaybackTargetPicker::invalidate): Ditto.

Source/WebKit2:

* UIProcess/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::mediaSessionManager): Call WebMediaSessionManager::singleton, not
  WebMediaSessionManagerMac::singleton.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189135 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/mediasession/WebMediaSessionManager.cpp
Source/WebCore/Modules/mediasession/WebMediaSessionManager.h
Source/WebCore/platform/graphics/avfoundation/WebMediaSessionManagerMac.cpp
Source/WebCore/platform/graphics/avfoundation/WebMediaSessionManagerMac.h
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebMediaPlaybackTargetPicker.mm
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/mac/PageClientImpl.mm

index a650f8c..d1f34ab 100644 (file)
@@ -1,3 +1,25 @@
+2015-08-28  Eric Carlson  <eric.carlson@apple.com>
+
+        [Mac] Restructure WebMediaSessionManager for testing
+        https://bugs.webkit.org/show_bug.cgi?id=148593
+
+        Reviewed by Jer Noble.
+
+        No new tests, no functional change.
+
+        * Modules/mediasession/WebMediaSessionManager.cpp:
+        (WebCore::mediaProducerStateString): Add some missing states.
+        (WebCore::webMediaSessionManagerOverride): New.
+        (WebCore::WebMediaSessionManager::singleton): New.
+        (WebCore::WebMediaSessionManager::setWebMediaSessionManagerOverride): New, will allow runtime
+          registration of a mock manager.
+        * Modules/mediasession/WebMediaSessionManager.h:
+
+        * platform/graphics/avfoundation/WebMediaSessionManagerMac.cpp:
+        (WebCore::WebMediaSessionManager::platformManager): Renamed from singleton.
+        (WebCore::WebMediaSessionManagerMac::singleton): Deleted.
+        * platform/graphics/avfoundation/WebMediaSessionManagerMac.h:
+
 2015-08-28  Jer Noble  <jer.noble@apple.com>
 
         [iOS] Add WebKit/WebKit2 settings to control automatic data loading
index 3bb9e00..dacaff1 100644 (file)
@@ -78,6 +78,8 @@ static String mediaProducerStateString(MediaProducer::MediaStateFlags flags)
         string.append("RequiresPlaybackTargetMonitoring + ");
     if (flags & MediaProducer::ExternalDeviceAutoPlayCandidate)
         string.append("ExternalDeviceAutoPlayCandidate + ");
+    if (flags & MediaProducer::DidPlayToEnd)
+        string.append("DidPlayToEnd + ");
     if (string.isEmpty())
         string.append("IsNotPlaying");
     else
@@ -87,6 +89,25 @@ static String mediaProducerStateString(MediaProducer::MediaStateFlags flags)
 }
 #endif
 
+static WebMediaSessionManager*& webMediaSessionManagerOverride()
+{
+    static WebMediaSessionManager* override;
+    return override;
+}
+
+WebMediaSessionManager& WebMediaSessionManager::shared()
+{
+    if (WebMediaSessionManager* override = webMediaSessionManagerOverride())
+        return *override;
+
+    return WebMediaSessionManager::platformManager();
+}
+
+void WebMediaSessionManager::setWebMediaSessionManagerOverride(WebMediaSessionManager* manager)
+{
+    webMediaSessionManagerOverride() = manager;
+}
+
 WebMediaSessionManager::WebMediaSessionManager()
     : m_taskTimer(RunLoop::current(), this, &WebMediaSessionManager::taskTimerFired)
     , m_watchdogTimer(RunLoop::current(), this, &WebMediaSessionManager::watchdogTimerFired)
index 4bb6b9c..cdb080c 100644 (file)
@@ -45,6 +45,9 @@ class WebMediaSessionManager : public MediaPlaybackTargetPicker::Client {
     WTF_MAKE_NONCOPYABLE(WebMediaSessionManager);
 public:
 
+    WEBCORE_EXPORT static WebMediaSessionManager& shared();
+    WEBCORE_EXPORT static void setWebMediaSessionManagerOverride(WebMediaSessionManager*);
+
     WEBCORE_EXPORT uint64_t addPlaybackTargetPickerClient(WebMediaSessionManagerClient&, uint64_t);
     WEBCORE_EXPORT void removePlaybackTargetPickerClient(WebMediaSessionManagerClient&, uint64_t);
     WEBCORE_EXPORT void removeAllPlaybackTargetPickerClients(WebMediaSessionManagerClient&);
@@ -56,6 +59,7 @@ protected:
     virtual ~WebMediaSessionManager();
 
     virtual WebCore::MediaPlaybackTargetPicker& targetPicker() = 0;
+    static WebMediaSessionManager& platformManager();
 
 private:
 
index 8862c6c..5a31775 100644 (file)
@@ -33,7 +33,7 @@
 
 namespace WebCore {
 
-WebMediaSessionManager& WebMediaSessionManagerMac::singleton()
+WebMediaSessionManager& WebMediaSessionManager::platformManager()
 {
     static NeverDestroyed<WebMediaSessionManagerMac> sharedManager;
     return sharedManager;
index 3fc8a00..e779560 100644 (file)
@@ -35,7 +35,6 @@ namespace WebCore {
 class WebMediaSessionManagerMac : public WebMediaSessionManager {
     friend class NeverDestroyed<WebMediaSessionManagerMac>;
 public:
-    WEBCORE_EXPORT static WebMediaSessionManager& singleton();
 
 private:
     WebMediaSessionManagerMac();
index 09b527f..ad91ab1 100644 (file)
@@ -1,3 +1,19 @@
+2015-08-28  Eric Carlson  <eric.carlson@apple.com>
+
+        [Mac] Restructure WebMediaSessionManager for testing
+        https://bugs.webkit.org/show_bug.cgi?id=148593
+
+        Reviewed by Jer Noble.
+
+        * WebView/WebMediaPlaybackTargetPicker.mm:
+        (WebMediaPlaybackTargetPicker::addPlaybackTargetPickerClient): Call WebMediaSessionManager::singleton,
+          not WebMediaSessionManagerMac::singleton.
+        (WebMediaPlaybackTargetPicker::removePlaybackTargetPickerClient): Ditto.
+        (WebMediaPlaybackTargetPicker::showPlaybackTargetPicker): Ditto.
+        (WebMediaPlaybackTargetPicker::playbackTargetPickerClientStateDidChange): Ditto.
+        (WebMediaPlaybackTargetPicker::setPlaybackTarget): Ditto.
+        (WebMediaPlaybackTargetPicker::invalidate): Ditto.
+
 2015-08-28  Jer Noble  <jer.noble@apple.com>
 
         [iOS] Add WebKit/WebKit2 settings to control automatic data loading
index b35c433..b0ba971 100644 (file)
@@ -29,7 +29,7 @@
 
 #import <WebCore/MediaPlaybackTarget.h>
 #import <WebCore/Page.h>
-#import <WebCore/WebMediaSessionManagerMac.h>
+#import <WebCore/WebMediaSessionManager.h>
 
 std::unique_ptr<WebMediaPlaybackTargetPicker> WebMediaPlaybackTargetPicker::create(WebCore::Page& page)
 {
@@ -43,22 +43,22 @@ WebMediaPlaybackTargetPicker::WebMediaPlaybackTargetPicker(WebCore::Page& page)
 
 void WebMediaPlaybackTargetPicker::addPlaybackTargetPickerClient(uint64_t contextId)
 {
-    WebCore::WebMediaSessionManagerMac::singleton().addPlaybackTargetPickerClient(*this, contextId);
+    WebCore::WebMediaSessionManager::shared().addPlaybackTargetPickerClient(*this, contextId);
 }
 
 void WebMediaPlaybackTargetPicker::removePlaybackTargetPickerClient(uint64_t contextId)
 {
-    WebCore::WebMediaSessionManagerMac::singleton().removePlaybackTargetPickerClient(*this, contextId);
+    WebCore::WebMediaSessionManager::shared().removePlaybackTargetPickerClient(*this, contextId);
 }
 
 void WebMediaPlaybackTargetPicker::showPlaybackTargetPicker(uint64_t contextId, const WebCore::FloatRect& rect, bool hasVideo)
 {
-    WebCore::WebMediaSessionManagerMac::singleton().showPlaybackTargetPicker(*this, contextId, WebCore::IntRect(rect), hasVideo);
+    WebCore::WebMediaSessionManager::shared().showPlaybackTargetPicker(*this, contextId, WebCore::IntRect(rect), hasVideo);
 }
 
 void WebMediaPlaybackTargetPicker::playbackTargetPickerClientStateDidChange(uint64_t contextId, WebCore::MediaProducer::MediaStateFlags state)
 {
-    WebCore::WebMediaSessionManagerMac::singleton().clientStateDidChange(*this, contextId, state);
+    WebCore::WebMediaSessionManager::shared().clientStateDidChange(*this, contextId, state);
 }
 
 void WebMediaPlaybackTargetPicker::setPlaybackTarget(uint64_t contextId, Ref<WebCore::MediaPlaybackTarget>&& target)
@@ -88,7 +88,7 @@ void WebMediaPlaybackTargetPicker::setShouldPlayToPlaybackTarget(uint64_t contex
 void WebMediaPlaybackTargetPicker::invalidate()
 {
     m_page = nullptr;
-    WebCore::WebMediaSessionManagerMac::singleton().removeAllPlaybackTargetPickerClients(*this);
+    WebCore::WebMediaSessionManager::shared().removeAllPlaybackTargetPickerClients(*this);
 }
 
 #endif
index efbfbf1..2158870 100644 (file)
@@ -1,3 +1,14 @@
+2015-08-28  Eric Carlson  <eric.carlson@apple.com>
+
+        [Mac] Restructure WebMediaSessionManager for testing
+        https://bugs.webkit.org/show_bug.cgi?id=148593
+
+        Reviewed by Jer Noble.
+
+        * UIProcess/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::mediaSessionManager): Call WebMediaSessionManager::singleton, not
+          WebMediaSessionManagerMac::singleton.
+
 2015-08-28  Jer Noble  <jer.noble@apple.com>
 
         [iOS] Add WebKit/WebKit2 settings to control automatic data loading
index a30f8da..892eddc 100644 (file)
@@ -70,7 +70,7 @@
 #endif
 
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
-#include <WebCore/WebMediaSessionManagerMac.h>
+#include <WebCore/WebMediaSessionManager.h>
 #endif
 
 @interface NSApplication (WebNSApplicationDetails)
@@ -818,7 +818,7 @@ void PageClientImpl::showPlatformContextMenu(NSMenu *menu, IntPoint location)
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
 WebCore::WebMediaSessionManager& PageClientImpl::mediaSessionManager()
 {
-    return WebMediaSessionManagerMac::singleton();
+    return WebMediaSessionManager::shared();
 }
 #endif