Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/MediaKeySession.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_dom_MediaKeySession_h
8
#define mozilla_dom_MediaKeySession_h
9
10
#include "DecoderDoctorLogger.h"
11
#include "mozilla/Attributes.h"
12
#include "mozilla/ErrorResult.h"
13
#include "nsCycleCollectionParticipant.h"
14
#include "mozilla/DOMEventTargetHelper.h"
15
#include "nsCOMPtr.h"
16
#include "mozilla/dom/TypedArray.h"
17
#include "mozilla/Mutex.h"
18
#include "mozilla/dom/Date.h"
19
#include "mozilla/dom/Promise.h"
20
#include "mozilla/DetailedPromise.h"
21
#include "mozilla/dom/MediaKeySessionBinding.h"
22
#include "mozilla/dom/MediaKeysBinding.h"
23
#include "mozilla/dom/MediaKeyMessageEventBinding.h"
24
25
struct JSContext;
26
27
namespace mozilla {
28
29
namespace dom {
30
class MediaKeySession;
31
} // namespace dom
32
DDLoggedTypeName(dom::MediaKeySession);
33
34
namespace dom {
35
36
class ArrayBufferViewOrArrayBuffer;
37
class MediaKeyError;
38
class MediaKeyStatusMap;
39
40
nsCString
41
ToCString(MediaKeySessionType aType);
42
43
nsString
44
ToString(MediaKeySessionType aType);
45
46
class MediaKeySession final
47
  : public DOMEventTargetHelper
48
  , public DecoderDoctorLifeLogger<MediaKeySession>
49
{
50
public:
51
  NS_DECL_ISUPPORTS_INHERITED
52
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaKeySession,
53
                                           DOMEventTargetHelper)
54
public:
55
  MediaKeySession(JSContext* aCx,
56
                  nsPIDOMWindowInner* aParent,
57
                  MediaKeys* aKeys,
58
                  const nsAString& aKeySystem,
59
                  MediaKeySessionType aSessionType,
60
                  ErrorResult& aRv);
61
62
  void SetSessionId(const nsAString& aSessionId);
63
64
  JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
65
66
  // Mark this as resultNotAddRefed to return raw pointers
67
  MediaKeyError* GetError() const;
68
69
  MediaKeyStatusMap* KeyStatuses() const;
70
71
  void GetSessionId(nsString& aRetval) const;
72
73
  const nsString& GetSessionId() const;
74
75
  // Number of ms since epoch at which expiration occurs, or NaN if unknown.
76
  // TODO: The type of this attribute is still under contention.
77
  // https://www.w3.org/Bugs/Public/show_bug.cgi?id=25902
78
  double Expiration() const;
79
80
  Promise* Closed() const;
81
82
  already_AddRefed<Promise> GenerateRequest(const nsAString& aInitDataType,
83
                                            const ArrayBufferViewOrArrayBuffer& aInitData,
84
                                            ErrorResult& aRv);
85
86
  already_AddRefed<Promise> Load(const nsAString& aSessionId,
87
                                 ErrorResult& aRv);
88
89
  already_AddRefed<Promise> Update(const ArrayBufferViewOrArrayBuffer& response,
90
                                   ErrorResult& aRv);
91
92
  already_AddRefed<Promise> Close(ErrorResult& aRv);
93
94
  already_AddRefed<Promise> Remove(ErrorResult& aRv);
95
96
  void DispatchKeyMessage(MediaKeyMessageType aMessageType,
97
                          const nsTArray<uint8_t>& aMessage);
98
99
  void DispatchKeyError(uint32_t system_code);
100
101
  void DispatchKeyStatusesChange();
102
103
  void OnClosed();
104
105
  bool IsClosed() const;
106
107
  void SetExpiration(double aExpiry);
108
109
  mozilla::dom::EventHandlerNonNull* GetOnkeystatuseschange();
110
  void SetOnkeystatuseschange(mozilla::dom::EventHandlerNonNull* aCallback);
111
112
  mozilla::dom::EventHandlerNonNull* GetOnmessage();
113
  void SetOnmessage(mozilla::dom::EventHandlerNonNull* aCallback);
114
115
  // Process-unique identifier.
116
  uint32_t Token() const;
117
118
private:
119
  ~MediaKeySession();
120
121
  void UpdateKeyStatusMap();
122
123
0
  bool IsCallable() const {
124
0
    // The EME spec sets the "callable value" to true whenever the CDM sets
125
0
    // the sessionId. When the session is initialized, sessionId is empty and
126
0
    // callable is thus false.
127
0
    return !mSessionId.IsEmpty();
128
0
  }
129
130
  already_AddRefed<DetailedPromise> MakePromise(ErrorResult& aRv,
131
                                                const nsACString& aName);
132
133
  RefPtr<DetailedPromise> mClosed;
134
135
  RefPtr<MediaKeyError> mMediaKeyError;
136
  RefPtr<MediaKeys> mKeys;
137
  const nsString mKeySystem;
138
  nsString mSessionId;
139
  const MediaKeySessionType mSessionType;
140
  const uint32_t mToken;
141
  bool mIsClosed;
142
  bool mUninitialized;
143
  RefPtr<MediaKeyStatusMap> mKeyStatusMap;
144
  double mExpiration;
145
};
146
147
} // namespace dom
148
} // namespace mozilla
149
150
#endif