[iOS] Show external device name/type in placeholder
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Mar 2014 21:37:38 +0000 (21:37 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Mar 2014 21:37:38 +0000 (21:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=129723

Reviewed by Jer Noble.

Source/WebCore:

Make the name and type of the external device available to the JS based controls.
* Modules/mediacontrols/MediaControlsHost.cpp:
(WebCore::MediaControlsHost::externalDeviceDisplayName):
(WebCore::MediaControlsHost::externalDeviceType):
* Modules/mediacontrols/MediaControlsHost.h:
* Modules/mediacontrols/MediaControlsHost.idl:

* Modules/mediacontrols/mediaControlsiOS.js:
(ControllerIOS.prototype.updateWirelessPlaybackStatus): Display device type-specific infomation
    in the placeholder image.

* WebCore.exp.in: Export new WebKitSystemInterface functions.

* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::wirelessPlaybackTargetName): Added.
(WebCore::MediaPlayer::wirelessPlaybackTargetType): Ditto.
* platform/graphics/MediaPlayer.h:
* platform/graphics/MediaPlayerPrivate.h:

* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::wirelessPlaybackTargetType): Added.
(WebCore::MediaPlayerPrivateAVFoundationObjC::wirelessPlaybackTargetName): Ditto.

* platform/ios/WebCoreSystemInterfaceIOS.mm:
* platform/mac/WebCoreSystemInterface.h:
* platform/mac/WebCoreSystemInterface.mm:

Source/WebKit/mac:

* WebCoreSupport/WebSystemInterface.mm:
(InitWebCoreSystemInterface):

WebKitLibraries:

* WebKitSystemInterface.h:
* libWebKitSystemInterfaceLion.a:
* libWebKitSystemInterfaceMavericks.a:
* libWebKitSystemInterfaceMountainLion.a:

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

21 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp
Source/WebCore/Modules/mediacontrols/MediaControlsHost.h
Source/WebCore/Modules/mediacontrols/MediaControlsHost.idl
Source/WebCore/Modules/mediacontrols/mediaControlsiOS.js
Source/WebCore/WebCore.exp.in
Source/WebCore/platform/graphics/MediaPlayer.cpp
Source/WebCore/platform/graphics/MediaPlayer.h
Source/WebCore/platform/graphics/MediaPlayerPrivate.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm
Source/WebCore/platform/ios/WebCoreSystemInterfaceIOS.mm
Source/WebCore/platform/mac/WebCoreSystemInterface.h
Source/WebCore/platform/mac/WebCoreSystemInterface.mm
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm
WebKitLibraries/ChangeLog
WebKitLibraries/WebKitSystemInterface.h
WebKitLibraries/libWebKitSystemInterfaceLion.a
WebKitLibraries/libWebKitSystemInterfaceMavericks.a
WebKitLibraries/libWebKitSystemInterfaceMountainLion.a

index 098c97e3a8394accf8c7116360b087690b681756..27dd1ec002a17f8634f2f64d0446408b055e4165 100644 (file)
@@ -1,3 +1,38 @@
+2014-03-05  Eric Carlson  <eric.carlson@apple.com>
+
+        [iOS] Show external device name/type in placeholder
+        https://bugs.webkit.org/show_bug.cgi?id=129723
+
+        Reviewed by Jer Noble.
+
+        Make the name and type of the external device available to the JS based controls.
+        * Modules/mediacontrols/MediaControlsHost.cpp:
+        (WebCore::MediaControlsHost::externalDeviceDisplayName):
+        (WebCore::MediaControlsHost::externalDeviceType):
+        * Modules/mediacontrols/MediaControlsHost.h:
+        * Modules/mediacontrols/MediaControlsHost.idl:
+
+        * Modules/mediacontrols/mediaControlsiOS.js:
+        (ControllerIOS.prototype.updateWirelessPlaybackStatus): Display device type-specific infomation
+            in the placeholder image.
+
+        * WebCore.exp.in: Export new WebKitSystemInterface functions.
+
+        * platform/graphics/MediaPlayer.cpp:
+        (WebCore::MediaPlayer::wirelessPlaybackTargetName): Added.
+        (WebCore::MediaPlayer::wirelessPlaybackTargetType): Ditto.
+        * platform/graphics/MediaPlayer.h:
+        * platform/graphics/MediaPlayerPrivate.h:
+
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::wirelessPlaybackTargetType): Added.
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::wirelessPlaybackTargetName): Ditto.
+
+        * platform/ios/WebCoreSystemInterfaceIOS.mm:
+        * platform/mac/WebCoreSystemInterface.h:
+        * platform/mac/WebCoreSystemInterface.mm:
+
 2014-03-05  Benjamin Poulain  <bpoulain@apple.com>
 
         [iOS] Rename the various VisibleExtent variations to exposedContentRect
index a0131ddffbc92aaf5669c095b9b06a523fef6db5..54080d0836c555f33bc4ebd8466264cca8e2cdae 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -32,6 +32,7 @@
 #include "CaptionUserPreferences.h"
 #include "Element.h"
 #include "HTMLMediaElement.h"
+#include "Logging.h"
 #include "MediaControlElements.h"
 #include "Page.h"
 #include "PageGroup.h"
@@ -163,6 +164,57 @@ bool MediaControlsHost::userGestureRequired() const
     return !m_mediaElement->mediaSession().playbackPermitted(*m_mediaElement);
 }
 
+String MediaControlsHost::externalDeviceDisplayName() const
+{
+#if ENABLE(IOS_AIRPLAY)
+    MediaPlayer* player = m_mediaElement->player();
+    if (!player) {
+        LOG(Media, "MediaControlsHost::externalDeviceDisplayName - returning \"\" because player is NULL");
+        return emptyString();
+    }
+    
+    String name = player->wirelessPlaybackTargetName();
+    LOG(Media, "MediaControlsHost::externalDeviceDisplayName - returning \"%s\"", name.utf8().data());
+    
+    return name;
+#else
+    return emptyString();
+#endif
+}
+
+String MediaControlsHost::externalDeviceType() const
+{
+    DEFINE_STATIC_LOCAL(String, none, (ASCIILiteral("none")));
+    String type = none;
+    
+#if ENABLE(IOS_AIRPLAY)
+    DEFINE_STATIC_LOCAL(String, airplay, (ASCIILiteral("airplay")));
+    DEFINE_STATIC_LOCAL(String, tvout, (ASCIILiteral("tvout")));
+    
+    MediaPlayer* player = m_mediaElement->player();
+    if (!player) {
+        LOG(Media, "MediaControlsHost::externalDeviceType - returning \"none\" because player is NULL");
+        return none;
+    }
+    
+    switch (player->wirelessPlaybackTargetType()) {
+    case MediaPlayer::TargetTypeNone:
+        type = none;
+        break;
+    case MediaPlayer::TargetTypeAirPlay:
+        type = airplay;
+        break;
+    case MediaPlayer::TargetTypeTVOut:
+        type = tvout;
+        break;
+    }
+#endif
+    
+    LOG(Media, "MediaControlsHost::externalDeviceType - returning \"%s\"", type.utf8().data());
+    
+    return type;
+}
+    
 }
 
 #endif
index c7b72483f71753d0bdd993c76c5bb39339150bef..e3f14a562a22df4086edf45f138e7d54f210ef86 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -62,6 +62,9 @@ public:
     bool supportsFullscreen();
     bool userGestureRequired() const;
 
+    String externalDeviceDisplayName() const;
+    String externalDeviceType() const;
+
 private:
     MediaControlsHost(HTMLMediaElement*);
 
index 22e7fff738338d3782da838adf4bb659cf810015..5b9ea665ed081a7bbaa354f66c175afdb3199dad 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
+enum DeviceType {
+    "none",
+    "airplay",
+    "tvout"
+};
+
 [
     NoInterfaceObject,
     Conditional=MEDIA_CONTROLS_SCRIPT,
@@ -39,4 +45,7 @@
     readonly attribute boolean mediaPlaybackAllowsInline;
     readonly attribute boolean supportsFullscreen;
     readonly attribute boolean userGestureRequired;
+
+    readonly attribute DOMString externalDeviceDisplayName;
+    readonly attribute DeviceType externalDeviceType;
 };
index 0fcecb4ea2aab4bc16be15207d7aceb68d414fad..dd9014e24d3582519d8263ea833802010c3b09d3 100644 (file)
@@ -68,8 +68,11 @@ ControllerIOS.prototype = {
     },
     localizedStrings: {
         // FIXME: Move localization to ext strings file <http://webkit.org/b/120956>
-        '##DEVICE_TYPE##': 'AirPlay',
-        '##DEVICE_NAME##': 'This video is playing on "##DEVICE_NAME##".',
+        '##AIRPLAY_DEVICE_TYPE##': 'AirPlay',
+        '##AIRPLAY_DEVICE_NAME##': 'This video is playing on "##DEVICE_NAME##".',
+
+        '##TVOUT_DEVICE_TYPE##': 'TV Connected',
+        '##TVOUT_DEVICE_NAME##': 'This video is playing on the TV.',
     },
 
     shouldHaveStartPlaybackButton: function() {
@@ -112,12 +115,18 @@ ControllerIOS.prototype = {
         if (this.currentPlaybackTargetIsWireless()) {
             var backgroundImageSVG = "url('" + ControllerIOS.gWirelessImage + "')";
 
-            var deviceType = this.UIString('##DEVICE_TYPE##');
+            var deviceName = "";
+            var deviceType = "";
+            var type = this.host.externalDeviceType;
+            if (type == "airplay") {
+                deviceType = this.UIString('##AIRPLAY_DEVICE_TYPE##');
+                deviceName = this.UIString('##AIRPLAY_DEVICE_NAME##').replace('##DEVICE_NAME##', this.host.externalDeviceDisplayName);
+            } else if (type == "tvout") {
+                deviceType = this.UIString('##TVOUT_DEVICE_TYPE##');
+                deviceName = this.UIString('##TVOUT_DEVICE_NAME##');
+            }
+            
             backgroundImageSVG = backgroundImageSVG.replace('##DEVICE_TYPE##', deviceType);
-
-            // FIXME: Get the device type and name from the host.
-            var deviceName = "unknown";
-            var deviceName = this.UIString('##DEVICE_NAME##').replace('##DEVICE_NAME##', deviceName);;
             backgroundImageSVG = backgroundImageSVG.replace('##DEVICE_NAME##', deviceName);
 
             this.controls.wirelessPlaybackStatus.style.backgroundImage = backgroundImageSVG;
index 922b0d7490aa1248dcb35ee08744c432ada295eb..9e3fbc8657fa01b9e25b810f9e077078769d24b5 100644 (file)
@@ -1970,6 +1970,8 @@ _wkCreatePrivateStorageSession
 _wkDeleteAllHTTPCookies
 _wkDeleteHTTPCookie
 _wkDestroyRenderingResources
+_wkExernalDeviceDisplayNameForPlayer
+_wkExernalDeviceTypeForPlayer
 _wkGetCFURLResponseHTTPResponse
 _wkGetCFURLResponseMIMEType
 _wkGetCFURLResponseURL
index eb520634713236f383e15ba4579e0d540af926c1..aa77a81c567a3cae138c92930f922836cd684d56 100644 (file)
@@ -851,6 +851,16 @@ bool MediaPlayer::isCurrentPlaybackTargetWireless() const
     return m_private->isCurrentPlaybackTargetWireless();
 }
 
+String MediaPlayer::wirelessPlaybackTargetName() const
+{
+    return m_private->wirelessPlaybackTargetName();
+}
+
+MediaPlayer::WirelessPlaybackTargetType MediaPlayer::wirelessPlaybackTargetType() const
+{
+    return m_private->wirelessPlaybackTargetType();
+}
+
 void MediaPlayer::showPlaybackTargetPicker()
 {
     m_private->showPlaybackTargetPicker();
index 74024046c647b8d07b81a5eddf6feec14672efcf..2915f47869b59f8d98418e33a15270e447bed694 100644 (file)
@@ -449,6 +449,12 @@ public:
 
 #if ENABLE(IOS_AIRPLAY)
     bool isCurrentPlaybackTargetWireless() const;
+
+    enum WirelessPlaybackTargetType { TargetTypeNone, TargetTypeAirPlay, TargetTypeTVOut };
+    WirelessPlaybackTargetType wirelessPlaybackTargetType() const;
+
+    String wirelessPlaybackTargetName() const;
+
     void showPlaybackTargetPicker();
 
     bool hasWirelessPlaybackTargets() const;
index a2d985ef58913fac8fe31ce8df3718f7a9ef756c..ca2530e5c7fe37f6150f03869dce4ab0c0e4505c 100644 (file)
@@ -145,6 +145,10 @@ public:
 
 #if ENABLE(IOS_AIRPLAY)
     virtual bool isCurrentPlaybackTargetWireless() const { return false; }
+
+    virtual String wirelessPlaybackTargetName() const { return emptyString(); }
+    virtual MediaPlayer::WirelessPlaybackTargetType wirelessPlaybackTargetType() const { return MediaPlayer::TargetTypeNone; }
+
     virtual void showPlaybackTargetPicker() { }
 
     virtual bool hasWirelessPlaybackTargets() const { return false; }
index 4c16135f7afd99f4288861e02aea9b27f366503c..285f1d83501d33b2c8fa8319598efc011f8179d5 100644 (file)
@@ -228,6 +228,8 @@ private:
 
 #if ENABLE(IOS_AIRPLAY)
     virtual bool isCurrentPlaybackTargetWireless() const override;
+    virtual String wirelessPlaybackTargetName() const override;
+    virtual MediaPlayer::WirelessPlaybackTargetType wirelessPlaybackTargetType() const override;
     virtual bool wirelessVideoPlaybackDisabled() const override;
     virtual void setWirelessVideoPlaybackDisabled(bool) override;
 #endif
index b1f4a4f3c52fa629390910fa0344c9ef8ed57713..676f477e8eed095ee1b65a1829599b8ad1d8f69a 100644 (file)
@@ -87,7 +87,6 @@
 @end
 #endif
 
-
 SOFT_LINK_FRAMEWORK_OPTIONAL(AVFoundation)
 SOFT_LINK_FRAMEWORK_OPTIONAL(CoreMedia)
 SOFT_LINK_FRAMEWORK_OPTIONAL(CoreImage)
@@ -1917,6 +1916,35 @@ bool MediaPlayerPrivateAVFoundationObjC::isCurrentPlaybackTargetWireless() const
     return wirelessTarget;
 }
 
+MediaPlayer::WirelessPlaybackTargetType MediaPlayerPrivateAVFoundationObjC::wirelessPlaybackTargetType() const
+{
+    if (!m_avPlayer)
+        return MediaPlayer::TargetTypeNone;
+
+    switch (wkExernalDeviceTypeForPlayer(m_avPlayer.get())) {
+    case wkExternalPlaybackTypeNone:
+        return MediaPlayer::TargetTypeNone;
+    case wkExternalPlaybackTypeAirPlay:
+        return MediaPlayer::TargetTypeAirPlay;
+    case wkExternalPlaybackTypeTVOut:
+        return MediaPlayer::TargetTypeTVOut;
+    }
+
+    ASSERT_NOT_REACHED();
+    return MediaPlayer::TargetTypeNone;
+}
+
+String MediaPlayerPrivateAVFoundationObjC::wirelessPlaybackTargetName() const
+{
+    if (!m_avPlayer)
+        return emptyString();
+    
+    String wirelessTargetName = wkExernalDeviceDisplayNameForPlayer(m_avPlayer.get());
+    LOG(Media, "MediaPlayerPrivateAVFoundationObjC::wirelessPlaybackTargetName(%p) - returning %s", this, wirelessTargetName.utf8().data());
+
+    return wirelessTargetName;
+}
+
 bool MediaPlayerPrivateAVFoundationObjC::wirelessVideoPlaybackDisabled() const
 {
     if (!m_avPlayer)
index 988d773c5ed6939b5e3af88c0acbdf3a5baa9543..5079aaa91b6c97fc8d0c1f898ecf9a8e4f4a128b 100644 (file)
@@ -147,3 +147,6 @@ CFStringRef (*wkGetDeviceName)(void);
 CFStringRef (*wkGetOSNameForUserAgent)(void);
 CFStringRef (*wkGetPlatformNameForNavigator)(void);
 CFStringRef (*wkGetVendorNameForNavigator)(void);
+
+int (*wkExernalDeviceTypeForPlayer)(AVPlayer *);
+NSString *(*wkExernalDeviceDisplayNameForPlayer)(AVPlayer *);
index 3c5e3c974c4f33fda19b68901cb6fce955d3b357..f0fd643a77eefe19f43921af16e1b9a4b749f98b 100644 (file)
@@ -94,6 +94,7 @@ typedef const struct _CFURLRequest* CFURLRequestRef;
 #endif
 
 OBJC_CLASS AVAsset;
+OBJC_CLASS AVPlayer;
 OBJC_CLASS CALayer;
 OBJC_CLASS NSArray;
 OBJC_CLASS NSButtonCell;
@@ -369,6 +370,15 @@ extern bool (*wkIsPublicSuffix)(NSString *host);
 #if ENABLE(CACHE_PARTITIONING)
 extern CFStringRef (*wkCachePartitionKey)(void);
 #endif
+
+typedef enum {
+    wkExternalPlaybackTypeNone,
+    wkExternalPlaybackTypeAirPlay,
+    wkExternalPlaybackTypeTVOut,
+} wkExternalPlaybackType;
+extern int (*wkExernalDeviceTypeForPlayer)(AVPlayer *);
+extern NSString *(*wkExernalDeviceDisplayNameForPlayer)(AVPlayer *);
+
 }
 
 #endif
index 76c82bdeefec372c887fc7cc3235cacf95736add..39c44ca9ae74260ab1ae176958f1cdbb50fe066d 100644 (file)
@@ -212,3 +212,6 @@ bool (*wkIsPublicSuffix)(NSString *host);
 #if ENABLE(CACHE_PARTITIONING)
 CFStringRef (*wkCachePartitionKey)(void);
 #endif
+
+int (*wkExernalDeviceTypeForPlayer)(AVPlayer *);
+NSString *(*wkExernalDeviceDisplayNameForPlayer)(AVPlayer *);
index 2a11464acf82ae4a37e5d82b88cb62d61529f28a..f2bc5b1d9b7dabf06c7f3574f81fe76d08d51e30 100644 (file)
@@ -1,3 +1,13 @@
+2014-03-05  Eric Carlson  <eric.carlson@apple.com>
+
+        [iOS] Show external device name/type in placeholder
+        https://bugs.webkit.org/show_bug.cgi?id=129723
+
+        Reviewed by Jer Noble.
+
+        * WebCoreSupport/WebSystemInterface.mm:
+        (InitWebCoreSystemInterface):
+
 2014-03-05  Simon Fraser  <simon.fraser@apple.com>
 
         ObjC exception when dropping files into a WKView: drag and drop uses code from WebKit.framework
index 45daa645ca3e558b426ef575e9b0f899e1cb35f3..53e9cecf8b057cf12ec4ceb53b8bef3d48fccebc 100644 (file)
@@ -244,5 +244,8 @@ void InitWebCoreSystemInterface(void)
     INIT(CachePartitionKey);
 #endif
 
+    INIT(ExernalDeviceTypeForPlayer);
+    INIT(ExernalDeviceDisplayNameForPlayer);
+
     didInit = true;
 }
index 250f0047b0142e86245bad19d26f6b151102e719..0ae2447138bc150ffdce99c930cd80082cc27101 100644 (file)
@@ -1,3 +1,15 @@
+2014-03-05  Eric Carlson  <eric.carlson@apple.com>
+
+        [iOS] Show external device name/type in placeholder
+        https://bugs.webkit.org/show_bug.cgi?id=129723
+
+        Reviewed by Jer Noble.
+
+        * WebKitSystemInterface.h:
+        * libWebKitSystemInterfaceLion.a:
+        * libWebKitSystemInterfaceMavericks.a:
+        * libWebKitSystemInterfaceMountainLion.a:
+
 2014-02-21  Jeffrey Pfau  <jpfau@apple.com>
 
         [Mac] Cache callbacks for cache partitioning may be passed null
index 2d82e08a86864e159107d16258dde7e0fac6b8f2..d307c4a56fac95ea4d4c45da09ffbaadb5913d58 100644 (file)
@@ -21,6 +21,7 @@
 #endif
 
 @class AVAsset;
+@class AVPlayer;
 @class QTMovie;
 @class QTMovieView;
 
@@ -548,6 +549,15 @@ CFStringRef WKCachePartitionKey(void);
 void WKCFURLCacheCopyAllPartitionNames(CFURLCacheCopyAllPartitionNamesResultsNotification resultsBlock);
 #endif
 
+typedef enum {
+    WKExternalPlaybackTypeNone,
+    WKExternalPlaybackTypeAirPlay,
+    WKExternalPlaybackTypeTVOut,
+} WKExternalPlaybackType;
+
+int WKExernalDeviceTypeForPlayer(AVPlayer *);
+NSString *WKExernalDeviceDisplayNameForPlayer(AVPlayer *);
+
 #ifdef __cplusplus
 }
 #endif
index 41983358f172b7e48ace383bd4e6d36ed7dc984f..9b1d1c4697563a99cc76ad6a5ac2efe8d298742b 100644 (file)
Binary files a/WebKitLibraries/libWebKitSystemInterfaceLion.a and b/WebKitLibraries/libWebKitSystemInterfaceLion.a differ
index 96a6cb29e6b54cc32bdd26e31bdf765d3635fd0d..c816542d0cef9eace3a197309ac91179ca7fc9d3 100644 (file)
Binary files a/WebKitLibraries/libWebKitSystemInterfaceMavericks.a and b/WebKitLibraries/libWebKitSystemInterfaceMavericks.a differ
index aa9ff99e26d607390d54e67b8ae082caddf6b120..2f7530f1ef7261385f6c78db3beb7ddfe11f9157 100644 (file)
Binary files a/WebKitLibraries/libWebKitSystemInterfaceMountainLion.a and b/WebKitLibraries/libWebKitSystemInterfaceMountainLion.a differ