summaryrefslogtreecommitdiffstats
path: root/dom/media/mediasession/MediaSessionIPCUtils.h
blob: 610b123b6cb916021dd19c1e9920242f2e3e4ae6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef DOM_MEDIA_MEDIASESSION_MEDIASESSIONIPCUTILS_H_
#define DOM_MEDIA_MEDIASESSION_MEDIASESSIONIPCUTILS_H_

#include "ipc/EnumSerializer.h"
#include "mozilla/dom/BindingIPCUtils.h"
#include "MediaMetadata.h"
#include "mozilla/dom/MediaSession.h"
#include "mozilla/dom/MediaSessionBinding.h"
#include "mozilla/Maybe.h"

namespace mozilla {
namespace dom {

typedef Maybe<MediaMetadataBase> MaybeMediaMetadataBase;

}  // namespace dom
}  // namespace mozilla

namespace IPC {

template <>
struct ParamTraits<mozilla::dom::MediaImage> {
  typedef mozilla::dom::MediaImage paramType;

  static void Write(MessageWriter* aWriter, const paramType& aParam) {
    WriteParam(aWriter, aParam.mSizes);
    WriteParam(aWriter, aParam.mSrc);
    WriteParam(aWriter, aParam.mType);
  }

  static bool Read(MessageReader* aReader, paramType* aResult) {
    if (!ReadParam(aReader, &(aResult->mSizes)) ||
        !ReadParam(aReader, &(aResult->mSrc)) ||
        !ReadParam(aReader, &(aResult->mType))) {
      return false;
    }
    return true;
  }
};

template <>
struct ParamTraits<mozilla::dom::MediaMetadataBase> {
  typedef mozilla::dom::MediaMetadataBase paramType;

  static void Write(MessageWriter* aWriter, const paramType& aParam) {
    WriteParam(aWriter, aParam.mTitle);
    WriteParam(aWriter, aParam.mArtist);
    WriteParam(aWriter, aParam.mAlbum);
    WriteParam(aWriter, aParam.mArtwork);
  }

  static bool Read(MessageReader* aReader, paramType* aResult) {
    if (!ReadParam(aReader, &(aResult->mTitle)) ||
        !ReadParam(aReader, &(aResult->mArtist)) ||
        !ReadParam(aReader, &(aResult->mAlbum)) ||
        !ReadParam(aReader, &(aResult->mArtwork))) {
      return false;
    }
    return true;
  }
};

template <>
struct ParamTraits<mozilla::dom::PositionState> {
  typedef mozilla::dom::PositionState paramType;

  static void Write(MessageWriter* aWriter, const paramType& aParam) {
    WriteParam(aWriter, aParam.mDuration);
    WriteParam(aWriter, aParam.mPlaybackRate);
    WriteParam(aWriter, aParam.mLastReportedPlaybackPosition);
    WriteParam(aWriter, aParam.mPositionUpdatedTime);
  }

  static bool Read(MessageReader* aReader, paramType* aResult) {
    if (!ReadParam(aReader, &(aResult->mDuration)) ||
        !ReadParam(aReader, &(aResult->mPlaybackRate)) ||
        !ReadParam(aReader, &(aResult->mLastReportedPlaybackPosition)) ||
        !ReadParam(aReader, &(aResult->mPositionUpdatedTime))) {
      return false;
    }
    return true;
  }
};

template <>
struct ParamTraits<mozilla::dom::MediaSessionPlaybackState>
    : public mozilla::dom::WebIDLEnumSerializer<
          mozilla::dom::MediaSessionPlaybackState> {};

template <>
struct ParamTraits<mozilla::dom::MediaSessionAction>
    : public mozilla::dom::WebIDLEnumSerializer<
          mozilla::dom::MediaSessionAction> {};

}  // namespace IPC

#endif  // DOM_MEDIA_MEDIASESSION_MEDIASESSIONIPCUTILS_H_