Bug 1858921 - Part 6: Remove unused default template arguments r=sfink
[gecko.git] / dom / media / eme / MediaKeySession.h
blobe19488c311b18370c89c6f3a4065fea42f6753da
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"
14 #include "nsCOMPtr.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"
23 struct JSContext;
25 namespace mozilla {
26 class ErrorResult;
28 namespace dom {
29 class MediaKeySession;
30 } // namespace dom
31 DDLoggedTypeName(dom::MediaKeySession);
33 namespace dom {
35 class ArrayBufferViewOrArrayBuffer;
36 class MediaKeyError;
37 class MediaKeyStatusMap;
39 nsCString ToCString(MediaKeySessionType aType);
41 nsString ToString(MediaKeySessionType aType);
43 class MediaKeySession final : public DOMEventTargetHelper,
44 public DecoderDoctorLifeLogger<MediaKeySession> {
45 public:
46 NS_DECL_ISUPPORTS_INHERITED
47 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaKeySession,
48 DOMEventTargetHelper)
49 public:
50 MediaKeySession(nsPIDOMWindowInner* aParent, MediaKeys* aKeys,
51 const nsAString& aKeySystem, MediaKeySessionType aSessionType,
52 ErrorResult& aRv);
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,
82 ErrorResult& aRv);
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();
95 void OnClosed();
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;
110 private:
111 ~MediaKeySession();
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;
130 nsString mSessionId;
131 const MediaKeySessionType mSessionType;
132 const uint32_t mToken;
133 bool mIsClosed;
134 bool mUninitialized;
135 RefPtr<MediaKeyStatusMap> mKeyStatusMap;
136 double mExpiration;
139 } // namespace dom
140 } // namespace mozilla
142 #endif