27 std::shared_ptr<ImplementationFactory> factory,
28 std::shared_ptr<Implementation> implementation)
29 : closed(
Promise::PendingPromise()),
30 mutex_(
"MediaKeySession"),
32 implementation_(implementation),
34 closed_promise_(closed, false) {
40 MediaKeySession::~MediaKeySession() {}
45 EventTarget::Trace(tracer);
50 std::unique_lock<Mutex> lock(mutex_);
55 const std::string session_id =
SessionId();
56 if (session_id.empty())
60 if (!implementation_->GetExpiration(session_id, &expiration)) {
63 return expiration < 0 ? NAN : expiration;
67 std::vector<KeyStatusInfo> statuses;
68 const std::string session_id =
SessionId();
69 if (!session_id.empty() &&
70 !implementation_->GetKeyStatuses(session_id, &statuses)) {
75 for (
auto& status : statuses) {
76 LocalVar<JsValue> key(
78 LocalVar<JsValue> value(
ToJsValue(status.status));
90 if (init_data.
size() == 0) {
94 if (!factory_->SupportsInitDataType(init_data_type)) {
97 "CDM implementation doesn't support this initialization data type"));
100 auto cb = [
this](
const std::string& session_id) {
101 std::unique_lock<Mutex> lock(mutex_);
102 CHECK(session_id_.empty()) <<
"Cannot call set_session_id() twice.";
103 session_id_ = session_id;
106 implementation_->CreateSessionAndGenerateRequest(
107 EmePromise(ret,
false), cb, type_, init_data_type,
117 if (session_id.empty()) {
120 if (type_ != MediaKeySessionType::PersistentLicense) {
122 "Cannot load a persistent license in a temporary session"));
126 implementation_->Load(session_id,
EmePromise(ret,
true));
128 session_id_ = session_id;
133 const std::string session_id =
SessionId();
134 if (session_id.empty()) {
138 if (response.
size() == 0) {
143 implementation_->Update(session_id,
EmePromise(ret,
false),
149 const std::string session_id =
SessionId();
150 if (session_id.empty()) {
154 implementation_->Close(session_id, closed_promise_);
159 const std::string session_id =
SessionId();
160 if (session_id.empty()) {
166 implementation_->Remove(session_id,
EmePromise(ret,
false));
ReturnVal< JsValue > ToJsValue(T &&source)
ReturnVal< JsValue > RawToJsValue(Handle< T > source)
void Trace(const Traceable *ptr)
static Promise Rejected(const js::JsError &error)
ReturnVal< JsMap > CreateMap()
void SetMapValue(Handle< JsMap > map, Handle< JsValue > key, Handle< JsValue > value)
static Promise PendingPromise()
static JsError TypeError(const std::string &message)
static JsError DOMException(ExceptionCode code)
static Promise Resolved()
void AddListenerField(EventType type, Listener *on_field)