1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "ClearKeyDecryptionManager.h"
6 #include "ClearKeySession.h"
7 #include "ClearKeyUtils.h"
8 #include "ClearKeyStorage.h"
9 #include "gmp-task-utils.h"
11 #include "gmp-api/gmp-decryption.h"
12 #include "mozilla/Endian.h"
14 using namespace mozilla
;
16 ClearKeySession::ClearKeySession(const std::string
& aSessionId
,
17 GMPDecryptorCallback
* aCallback
,
18 GMPSessionType aSessionType
)
19 : mSessionId(aSessionId
)
20 , mCallback(aCallback
)
21 , mSessionType(aSessionType
)
23 CK_LOGD("ClearKeySession ctor %p", this);
26 ClearKeySession::~ClearKeySession()
28 CK_LOGD("ClearKeySession dtor %p", this);
30 auto& keyIds
= GetKeyIds();
31 for (auto it
= keyIds
.begin(); it
!= keyIds
.end(); it
++) {
32 MOZ_ASSERT(ClearKeyDecryptionManager::Get()->HasKeyForKeyId(*it
));
34 ClearKeyDecryptionManager::Get()->ReleaseKeyId(*it
);
35 mCallback
->KeyStatusChanged(&mSessionId
[0], mSessionId
.size(),
36 &(*it
)[0], it
->size(),
42 ClearKeySession::Init(uint32_t aCreateSessionToken
,
44 const uint8_t* aInitData
, uint32_t aInitDataSize
)
46 CK_LOGD("ClearKeySession::Init");
48 ClearKeyUtils::ParseInitData(aInitData
, aInitDataSize
, mKeyIds
);
49 if (!mKeyIds
.size()) {
50 const char message
[] = "Couldn't parse cenc key init data";
51 mCallback
->RejectPromise(aPromiseId
, kGMPAbortError
, message
, strlen(message
));
55 mCallback
->SetSessionId(aCreateSessionToken
, &mSessionId
[0], mSessionId
.length());
57 mCallback
->ResolvePromise(aPromiseId
);
61 ClearKeySession::Type() const
67 ClearKeySession::AddKeyId(const KeyId
& aKeyId
)
69 mKeyIds
.push_back(aKeyId
);