[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 098c97e..27dd1ec 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 a0131dd..54080d0 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 c7b7248..e3f14a5 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 22e7fff..5b9ea66 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 0fcecb4..dd9014e 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 922b0d7..9e3fbc8 100644 (file)
@@ -1970,6 +1970,8 @@ _wkCreatePrivateStorageSession
 _wkDeleteAllHTTPCookies
 _wkDeleteHTTPCookie
 _wkDestroyRenderingResources
+_wkExernalDeviceDisplayNameForPlayer
+_wkExernalDeviceTypeForPlayer
 _wkGetCFURLResponseHTTPResponse
 _wkGetCFURLResponseMIMEType
 _wkGetCFURLResponseURL
index eb52063..aa77a81 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 7402404..2915f47 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 a2d985e..ca2530e 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 4c16135..285f1d8 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 b1f4a4f..676f477 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 988d773..5079aaa 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 3c5e3c9..f0fd643 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 76c82bd..39c44ca 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 2a11464..f2bc5b1 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 45daa64..53e9cec 100644 (file)
@@ -244,5 +244,8 @@ void InitWebCoreSystemInterface(void)
     INIT(CachePartitionKey);
 #endif
 
+    INIT(ExernalDeviceTypeForPlayer);
+    INIT(ExernalDeviceDisplayNameForPlayer);
+
     didInit = true;
 }
index 250f004..0ae2447 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 2d82e08..d307c4a 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 4198335..9b1d1c4 100644 (file)
Binary files a/WebKitLibraries/libWebKitSystemInterfaceLion.a and b/WebKitLibraries/libWebKitSystemInterfaceLion.a differ
index 96a6cb2..c816542 100644 (file)
Binary files a/WebKitLibraries/libWebKitSystemInterfaceMavericks.a and b/WebKitLibraries/libWebKitSystemInterfaceMavericks.a differ
index aa9ff99..2f7530f 100644 (file)
Binary files a/WebKitLibraries/libWebKitSystemInterfaceMountainLion.a and b/WebKitLibraries/libWebKitSystemInterfaceMountainLion.a differ