MediaSessionIPCUtils.h (3200B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef DOM_MEDIA_MEDIASESSION_MEDIASESSIONIPCUTILS_H_ 6 #define DOM_MEDIA_MEDIASESSION_MEDIASESSIONIPCUTILS_H_ 7 8 #include "MediaMetadata.h" 9 #include "ipc/EnumSerializer.h" 10 #include "mozilla/Maybe.h" 11 #include "mozilla/dom/BindingIPCUtils.h" 12 #include "mozilla/dom/MediaSession.h" 13 #include "mozilla/dom/MediaSessionBinding.h" 14 15 namespace mozilla { 16 namespace dom { 17 18 typedef Maybe<MediaMetadataBase> MaybeMediaMetadataBase; 19 20 } // namespace dom 21 } // namespace mozilla 22 23 namespace IPC { 24 25 template <> 26 struct ParamTraits<mozilla::dom::MediaImage> { 27 typedef mozilla::dom::MediaImage paramType; 28 29 static void Write(MessageWriter* aWriter, const paramType& aParam) { 30 WriteParam(aWriter, aParam.mSizes); 31 WriteParam(aWriter, aParam.mSrc); 32 WriteParam(aWriter, aParam.mType); 33 } 34 35 static bool Read(MessageReader* aReader, paramType* aResult) { 36 if (!ReadParam(aReader, &(aResult->mSizes)) || 37 !ReadParam(aReader, &(aResult->mSrc)) || 38 !ReadParam(aReader, &(aResult->mType))) { 39 return false; 40 } 41 return true; 42 } 43 }; 44 45 template <> 46 struct ParamTraits<mozilla::dom::MediaMetadataBase> { 47 typedef mozilla::dom::MediaMetadataBase paramType; 48 49 static void Write(MessageWriter* aWriter, const paramType& aParam) { 50 WriteParam(aWriter, aParam.mTitle); 51 WriteParam(aWriter, aParam.mArtist); 52 WriteParam(aWriter, aParam.mAlbum); 53 WriteParam(aWriter, aParam.mUrl); 54 WriteParam(aWriter, aParam.mArtwork); 55 } 56 57 static bool Read(MessageReader* aReader, paramType* aResult) { 58 if (!ReadParam(aReader, &(aResult->mTitle)) || 59 !ReadParam(aReader, &(aResult->mArtist)) || 60 !ReadParam(aReader, &(aResult->mAlbum)) || 61 !ReadParam(aReader, &(aResult->mUrl)) || 62 !ReadParam(aReader, &(aResult->mArtwork))) { 63 return false; 64 } 65 return true; 66 } 67 }; 68 69 template <> 70 struct ParamTraits<mozilla::dom::PositionState> { 71 typedef mozilla::dom::PositionState paramType; 72 73 static void Write(MessageWriter* aWriter, const paramType& aParam) { 74 WriteParam(aWriter, aParam.mDuration); 75 WriteParam(aWriter, aParam.mPlaybackRate); 76 WriteParam(aWriter, aParam.mLastReportedPlaybackPosition); 77 WriteParam(aWriter, aParam.mPositionUpdatedTime); 78 } 79 80 static bool Read(MessageReader* aReader, paramType* aResult) { 81 if (!ReadParam(aReader, &(aResult->mDuration)) || 82 !ReadParam(aReader, &(aResult->mPlaybackRate)) || 83 !ReadParam(aReader, &(aResult->mLastReportedPlaybackPosition)) || 84 !ReadParam(aReader, &(aResult->mPositionUpdatedTime))) { 85 return false; 86 } 87 return true; 88 } 89 }; 90 91 template <> 92 struct ParamTraits<mozilla::dom::MediaSessionPlaybackState> 93 : public mozilla::dom::WebIDLEnumSerializer< 94 mozilla::dom::MediaSessionPlaybackState> {}; 95 96 template <> 97 struct ParamTraits<mozilla::dom::MediaSessionAction> 98 : public mozilla::dom::WebIDLEnumSerializer< 99 mozilla::dom::MediaSessionAction> {}; 100 101 } // namespace IPC 102 103 #endif // DOM_MEDIA_MEDIASESSION_MEDIASESSIONIPCUTILS_H_