Add LogArgument template for PlatformMediaSession::RemoteControlCommandType
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Aug 2018 18:10:59 +0000 (18:10 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Aug 2018 18:10:59 +0000 (18:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=188314

Reviewed by Alex Christensen.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::didReceiveRemoteControlCommand): Don't coerce to int for logging.

* platform/audio/PlatformMediaSession.cpp:
(WebCore::convertEnumerationToString): New.
(WebCore::PlatformMediaSession::didReceiveRemoteControlCommand): Log command.
* platform/audio/PlatformMediaSession.h:
(WTF::LogArgument<WebCore::PlatformMediaSession::RemoteControlCommandType>::toString):

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

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/platform/audio/PlatformMediaSession.cpp
Source/WebCore/platform/audio/PlatformMediaSession.h

index 10657f3..385adbe 100644 (file)
@@ -1,3 +1,19 @@
+2018-08-08  Eric Carlson  <eric.carlson@apple.com>
+
+        Add LogArgument template for PlatformMediaSession::RemoteControlCommandType
+        https://bugs.webkit.org/show_bug.cgi?id=188314
+
+        Reviewed by Alex Christensen.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::didReceiveRemoteControlCommand): Don't coerce to int for logging.
+
+        * platform/audio/PlatformMediaSession.cpp:
+        (WebCore::convertEnumerationToString): New.
+        (WebCore::PlatformMediaSession::didReceiveRemoteControlCommand): Log command.
+        * platform/audio/PlatformMediaSession.h:
+        (WTF::LogArgument<WebCore::PlatformMediaSession::RemoteControlCommandType>::toString):
+
 2018-08-08  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: XHR content sometimes shows as error even though load succeeded
index 8fbcb82..90d34d0 100644 (file)
@@ -7521,7 +7521,7 @@ uint64_t HTMLMediaElement::mediaSessionUniqueIdentifier() const
 
 void HTMLMediaElement::didReceiveRemoteControlCommand(PlatformMediaSession::RemoteControlCommandType command, const PlatformMediaSession::RemoteCommandArgument* argument)
 {
-    INFO_LOG(LOGIDENTIFIER, static_cast<int>(command));
+    INFO_LOG(LOGIDENTIFIER, command);
 
     UserGestureIndicator remoteControlUserGesture(ProcessingUserGesture, &document());
     switch (command) {
index fa99fee..3e561fe 100644 (file)
@@ -54,10 +54,10 @@ String convertEnumerationToString(PlatformMediaSession::State state)
         MAKE_STATIC_STRING_IMPL("Interrupted"),
     };
     static_assert(!static_cast<size_t>(PlatformMediaSession::Idle), "PlatformMediaSession::Idle is not 0 as expected");
-    static_assert(static_cast<size_t>(PlatformMediaSession::Autoplaying == 1), "PlatformMediaSession::Autoplaying is not 1 as expected");
-    static_assert(static_cast<size_t>(PlatformMediaSession::Playing == 2), "PlatformMediaSession::Playing is not 2 as expected");
-    static_assert(static_cast<size_t>(PlatformMediaSession::Paused == 3), "PlatformMediaSession::Paused is not 3 as expected");
-    static_assert(static_cast<size_t>(PlatformMediaSession::Interrupted == 4), "PlatformMediaSession::Interrupted is not 4 as expected");
+    static_assert(static_cast<size_t>(PlatformMediaSession::Autoplaying) == 1, "PlatformMediaSession::Autoplaying is not 1 as expected");
+    static_assert(static_cast<size_t>(PlatformMediaSession::Playing) == 2, "PlatformMediaSession::Playing is not 2 as expected");
+    static_assert(static_cast<size_t>(PlatformMediaSession::Paused) == 3, "PlatformMediaSession::Paused is not 3 as expected");
+    static_assert(static_cast<size_t>(PlatformMediaSession::Interrupted) == 4, "PlatformMediaSession::Interrupted is not 4 as expected");
     ASSERT(static_cast<size_t>(state) < WTF_ARRAY_LENGTH(values));
     return values[static_cast<size_t>(state)];
 }
@@ -74,16 +74,44 @@ String convertEnumerationToString(PlatformMediaSession::InterruptionType type)
         MAKE_STATIC_STRING_IMPL("ProcessInactive"),
     };
     static_assert(!static_cast<size_t>(PlatformMediaSession::NoInterruption), "PlatformMediaSession::NoInterruption is not 0 as expected");
-    static_assert(static_cast<size_t>(PlatformMediaSession::SystemSleep == 1), "PlatformMediaSession::SystemSleep is not 1 as expected");
-    static_assert(static_cast<size_t>(PlatformMediaSession::EnteringBackground == 2), "PlatformMediaSession::EnteringBackground is not 2 as expected");
-    static_assert(static_cast<size_t>(PlatformMediaSession::SystemInterruption == 3), "PlatformMediaSession::SystemInterruption is not 3 as expected");
-    static_assert(static_cast<size_t>(PlatformMediaSession::SuspendedUnderLock == 4), "PlatformMediaSession::SuspendedUnderLock is not 4 as expected");
-    static_assert(static_cast<size_t>(PlatformMediaSession::InvisibleAutoplay == 5), "PlatformMediaSession::InvisibleAutoplay is not 5 as expected");
-    static_assert(static_cast<size_t>(PlatformMediaSession::ProcessInactive == 6), "PlatformMediaSession::ProcessInactive is not 6 as expected");
+    static_assert(static_cast<size_t>(PlatformMediaSession::SystemSleep) == 1, "PlatformMediaSession::SystemSleep is not 1 as expected");
+    static_assert(static_cast<size_t>(PlatformMediaSession::EnteringBackground) == 2, "PlatformMediaSession::EnteringBackground is not 2 as expected");
+    static_assert(static_cast<size_t>(PlatformMediaSession::SystemInterruption) == 3, "PlatformMediaSession::SystemInterruption is not 3 as expected");
+    static_assert(static_cast<size_t>(PlatformMediaSession::SuspendedUnderLock) == 4, "PlatformMediaSession::SuspendedUnderLock is not 4 as expected");
+    static_assert(static_cast<size_t>(PlatformMediaSession::InvisibleAutoplay) == 5, "PlatformMediaSession::InvisibleAutoplay is not 5 as expected");
+    static_assert(static_cast<size_t>(PlatformMediaSession::ProcessInactive) == 6, "PlatformMediaSession::ProcessInactive is not 6 as expected");
     ASSERT(static_cast<size_t>(type) < WTF_ARRAY_LENGTH(values));
     return values[static_cast<size_t>(type)];
 }
 
+String convertEnumerationToString(PlatformMediaSession::RemoteControlCommandType command)
+{
+    static const NeverDestroyed<String> values[] = {
+        MAKE_STATIC_STRING_IMPL("NoCommand"),
+        MAKE_STATIC_STRING_IMPL("PlayCommand"),
+        MAKE_STATIC_STRING_IMPL("PauseCommand"),
+        MAKE_STATIC_STRING_IMPL("StopCommand"),
+        MAKE_STATIC_STRING_IMPL("TogglePlayPauseCommand"),
+        MAKE_STATIC_STRING_IMPL("BeginSeekingBackwardCommand"),
+        MAKE_STATIC_STRING_IMPL("EndSeekingBackwardCommand"),
+        MAKE_STATIC_STRING_IMPL("BeginSeekingForwardCommand"),
+        MAKE_STATIC_STRING_IMPL("EndSeekingForwardCommand"),
+        MAKE_STATIC_STRING_IMPL("SeekToPlaybackPositionCommand"),
+    };
+    static_assert(!static_cast<size_t>(PlatformMediaSession::NoCommand), "PlatformMediaSession::NoCommand is not 0 as expected");
+    static_assert(static_cast<size_t>(PlatformMediaSession::PlayCommand) == 1, "PlatformMediaSession::PlayCommand is not 1 as expected");
+    static_assert(static_cast<size_t>(PlatformMediaSession::PauseCommand) == 2, "PlatformMediaSession::PauseCommand is not 2 as expected");
+    static_assert(static_cast<size_t>(PlatformMediaSession::StopCommand) == 3, "PlatformMediaSession::StopCommand is not 3 as expected");
+    static_assert(static_cast<size_t>(PlatformMediaSession::TogglePlayPauseCommand) == 4, "PlatformMediaSession::TogglePlayPauseCommand is not 4 as expected");
+    static_assert(static_cast<size_t>(PlatformMediaSession::BeginSeekingBackwardCommand) == 5, "PlatformMediaSession::BeginSeekingBackwardCommand is not 5 as expected");
+    static_assert(static_cast<size_t>(PlatformMediaSession::EndSeekingBackwardCommand) == 6, "PlatformMediaSession::EndSeekingBackwardCommand is not 6 as expected");
+    static_assert(static_cast<size_t>(PlatformMediaSession::BeginSeekingForwardCommand) == 7, "PlatformMediaSession::BeginSeekingForwardCommand is not 7 as expected");
+    static_assert(static_cast<size_t>(PlatformMediaSession::EndSeekingForwardCommand) == 8, "PlatformMediaSession::EndSeekingForwardCommand is not 8 as expected");
+    static_assert(static_cast<size_t>(PlatformMediaSession::SeekToPlaybackPositionCommand) == 9, "PlatformMediaSession::SeekToPlaybackPositionCommand is not 9 as expected");
+    ASSERT(static_cast<size_t>(command) < WTF_ARRAY_LENGTH(values));
+    return values[static_cast<size_t>(command)];
+}
+
 #endif
 
 std::unique_ptr<PlatformMediaSession> PlatformMediaSession::create(PlatformMediaSessionClient& client)
@@ -277,6 +305,8 @@ bool PlatformMediaSession::canReceiveRemoteControlCommands() const
 
 void PlatformMediaSession::didReceiveRemoteControlCommand(RemoteControlCommandType command, const PlatformMediaSession::RemoteCommandArgument* argument)
 {
+    INFO_LOG(LOGIDENTIFIER, command);
+
     m_client.didReceiveRemoteControlCommand(command, argument);
 }
 
index d97679d..11f7aac 100644 (file)
@@ -255,7 +255,7 @@ protected:
 
 String convertEnumerationToString(PlatformMediaSession::State);
 String convertEnumerationToString(PlatformMediaSession::InterruptionType);
-
+String convertEnumerationToString(PlatformMediaSession::RemoteControlCommandType);
 }
 
 namespace WTF {
@@ -279,6 +279,14 @@ struct LogArgument<WebCore::PlatformMediaSession::InterruptionType> {
     }
 };
 
+template <>
+struct LogArgument<WebCore::PlatformMediaSession::RemoteControlCommandType> {
+    static String toString(const WebCore::PlatformMediaSession::RemoteControlCommandType command)
+    {
+        return convertEnumerationToString(command);
+    }
+};
+
 } // namespace WTF
 
 #endif // PlatformMediaSession_h