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/. */
7 #ifndef mozilla_dom_MediaKeySession_h
8 #define mozilla_dom_MediaKeySession_h
10 #include "DecoderDoctorLogger.h"
11 #include "mozilla/Attributes.h"
12 #include "nsCycleCollectionParticipant.h"
13 #include "mozilla/DOMEventTargetHelper.h"
15 #include "mozilla/dom/TypedArray.h"
16 #include "mozilla/Mutex.h"
17 #include "mozilla/dom/Promise.h"
18 #include "mozilla/DetailedPromise.h"
19 #include "mozilla/dom/MediaKeySessionBinding.h"
20 #include "mozilla/dom/MediaKeysBinding.h"
21 #include "mozilla/dom/MediaKeyMessageEventBinding.h"
29 class MediaKeySession
;
31 DDLoggedTypeName(dom::MediaKeySession
);
35 class ArrayBufferViewOrArrayBuffer
;
37 class MediaKeyStatusMap
;
39 nsCString
ToCString(MediaKeySessionType aType
);
41 nsString
ToString(MediaKeySessionType aType
);
43 class MediaKeySession final
: public DOMEventTargetHelper
,
44 public DecoderDoctorLifeLogger
<MediaKeySession
> {
46 NS_DECL_ISUPPORTS_INHERITED
47 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaKeySession
,
50 MediaKeySession(nsPIDOMWindowInner
* aParent
, MediaKeys
* aKeys
,
51 const nsAString
& aKeySystem
, MediaKeySessionType aSessionType
,
54 void SetSessionId(const nsAString
& aSessionId
);
56 JSObject
* WrapObject(JSContext
* aCx
,
57 JS::Handle
<JSObject
*> aGivenProto
) override
;
59 // Mark this as resultNotAddRefed to return raw pointers
60 MediaKeyError
* GetError() const;
62 MediaKeyStatusMap
* KeyStatuses() const;
64 void GetSessionId(nsString
& aRetval
) const;
66 const nsString
& GetSessionId() const;
68 // Number of ms since epoch at which expiration occurs, or NaN if unknown.
69 // TODO: The type of this attribute is still under contention.
70 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=25902
71 double Expiration() const;
73 Promise
* Closed() const;
75 already_AddRefed
<Promise
> GenerateRequest(
76 const nsAString
& aInitDataType
,
77 const ArrayBufferViewOrArrayBuffer
& aInitData
, ErrorResult
& aRv
);
79 already_AddRefed
<Promise
> Load(const nsAString
& aSessionId
, ErrorResult
& aRv
);
81 already_AddRefed
<Promise
> Update(const ArrayBufferViewOrArrayBuffer
& response
,
84 already_AddRefed
<Promise
> Close(ErrorResult
& aRv
);
86 already_AddRefed
<Promise
> Remove(ErrorResult
& aRv
);
88 void DispatchKeyMessage(MediaKeyMessageType aMessageType
,
89 const nsTArray
<uint8_t>& aMessage
);
91 void DispatchKeyError(uint32_t system_code
);
93 void DispatchKeyStatusesChange();
97 bool IsClosed() const;
99 void SetExpiration(double aExpiry
);
101 mozilla::dom::EventHandlerNonNull
* GetOnkeystatuseschange();
102 void SetOnkeystatuseschange(mozilla::dom::EventHandlerNonNull
* aCallback
);
104 mozilla::dom::EventHandlerNonNull
* GetOnmessage();
105 void SetOnmessage(mozilla::dom::EventHandlerNonNull
* aCallback
);
107 // Process-unique identifier.
108 uint32_t Token() const;
113 void UpdateKeyStatusMap();
115 bool IsCallable() const {
116 // The EME spec sets the "callable value" to true whenever the CDM sets
117 // the sessionId. When the session is initialized, sessionId is empty and
118 // callable is thus false.
119 return !mSessionId
.IsEmpty();
122 already_AddRefed
<DetailedPromise
> MakePromise(ErrorResult
& aRv
,
123 const nsACString
& aName
);
125 RefPtr
<DetailedPromise
> mClosed
;
127 RefPtr
<MediaKeyError
> mMediaKeyError
;
128 RefPtr
<MediaKeys
> mKeys
;
129 const nsString mKeySystem
;
131 const MediaKeySessionType mSessionType
;
132 const uint32_t mToken
;
135 RefPtr
<MediaKeyStatusMap
> mKeyStatusMap
;
140 } // namespace mozilla