/src/mozilla-central/dom/media/eme/MediaKeyStatusMap.cpp
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 | | #include "mozilla/dom/MediaKeyStatusMap.h" |
8 | | #include "nsPIDOMWindow.h" |
9 | | #include "mozilla/dom/UnionTypes.h" |
10 | | #include "mozilla/dom/ToJSValue.h" |
11 | | #include "mozilla/EMEUtils.h" |
12 | | #include "GMPUtils.h" |
13 | | |
14 | | namespace mozilla { |
15 | | namespace dom { |
16 | | |
17 | | NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaKeyStatusMap) |
18 | | NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaKeyStatusMap) |
19 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaKeyStatusMap) |
20 | 0 | NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
21 | 0 | NS_INTERFACE_MAP_ENTRY(nsISupports) |
22 | 0 | NS_INTERFACE_MAP_END |
23 | | NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(MediaKeyStatusMap, mParent) |
24 | | |
25 | | MediaKeyStatusMap::MediaKeyStatusMap(nsPIDOMWindowInner* aParent) |
26 | | : mParent(aParent) |
27 | 0 | { |
28 | 0 | } |
29 | | |
30 | | MediaKeyStatusMap::~MediaKeyStatusMap() |
31 | 0 | { |
32 | 0 | } |
33 | | |
34 | | JSObject* |
35 | | MediaKeyStatusMap::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
36 | 0 | { |
37 | 0 | return MediaKeyStatusMap_Binding::Wrap(aCx, this, aGivenProto); |
38 | 0 | } |
39 | | |
40 | | nsPIDOMWindowInner* |
41 | | MediaKeyStatusMap::GetParentObject() const |
42 | 0 | { |
43 | 0 | return mParent; |
44 | 0 | } |
45 | | |
46 | | void |
47 | | MediaKeyStatusMap::Get(JSContext* aCx, |
48 | | const ArrayBufferViewOrArrayBuffer& aKey, |
49 | | JS::MutableHandle<JS::Value> aOutValue, |
50 | | ErrorResult& aOutRv) const |
51 | 0 | { |
52 | 0 | ArrayData keyId = GetArrayBufferViewOrArrayBufferData(aKey); |
53 | 0 | if (!keyId.IsValid()) { |
54 | 0 | aOutValue.setUndefined(); |
55 | 0 | return; |
56 | 0 | } |
57 | 0 | for (const KeyStatus& status : mStatuses) { |
58 | 0 | if (keyId == status.mKeyId) { |
59 | 0 | bool ok = ToJSValue(aCx, status.mStatus, aOutValue); |
60 | 0 | if (!ok) { |
61 | 0 | aOutRv.NoteJSContextException(aCx); |
62 | 0 | } |
63 | 0 | return; |
64 | 0 | } |
65 | 0 | } |
66 | 0 | aOutValue.setUndefined(); |
67 | 0 | } |
68 | | |
69 | | bool |
70 | | MediaKeyStatusMap::Has(const ArrayBufferViewOrArrayBuffer& aKey) const |
71 | 0 | { |
72 | 0 | ArrayData keyId = GetArrayBufferViewOrArrayBufferData(aKey); |
73 | 0 | if (!keyId.IsValid()) { |
74 | 0 | return false; |
75 | 0 | } |
76 | 0 | |
77 | 0 | for (const KeyStatus& status : mStatuses) { |
78 | 0 | if (keyId == status.mKeyId) { |
79 | 0 | return true; |
80 | 0 | } |
81 | 0 | } |
82 | 0 |
|
83 | 0 | return false; |
84 | 0 | } |
85 | | |
86 | | uint32_t |
87 | | MediaKeyStatusMap::GetIterableLength() const |
88 | 0 | { |
89 | 0 | return mStatuses.Length(); |
90 | 0 | } |
91 | | |
92 | | TypedArrayCreator<ArrayBuffer> |
93 | | MediaKeyStatusMap::GetKeyAtIndex(uint32_t aIndex) const |
94 | 0 | { |
95 | 0 | MOZ_ASSERT(aIndex < GetIterableLength()); |
96 | 0 | return TypedArrayCreator<ArrayBuffer>(mStatuses[aIndex].mKeyId); |
97 | 0 | } |
98 | | |
99 | | nsString |
100 | | MediaKeyStatusMap::GetKeyIDAsHexString(uint32_t aIndex) const |
101 | 0 | { |
102 | 0 | MOZ_ASSERT(aIndex < GetIterableLength()); |
103 | 0 | return NS_ConvertUTF8toUTF16(ToHexString(mStatuses[aIndex].mKeyId)); |
104 | 0 | } |
105 | | |
106 | | MediaKeyStatus |
107 | | MediaKeyStatusMap::GetValueAtIndex(uint32_t aIndex) const |
108 | 0 | { |
109 | 0 | MOZ_ASSERT(aIndex < GetIterableLength()); |
110 | 0 | return mStatuses[aIndex].mStatus; |
111 | 0 | } |
112 | | |
113 | | uint32_t |
114 | | MediaKeyStatusMap::Size() const |
115 | 0 | { |
116 | 0 | return mStatuses.Length(); |
117 | 0 | } |
118 | | |
119 | | void |
120 | | MediaKeyStatusMap::Update(const nsTArray<CDMCaps::KeyStatus>& aKeys) |
121 | 0 | { |
122 | 0 | mStatuses.Clear(); |
123 | 0 | for (const auto& key : aKeys) { |
124 | 0 | mStatuses.InsertElementSorted(KeyStatus(key.mId, key.mStatus)); |
125 | 0 | } |
126 | 0 | } |
127 | | |
128 | | } // namespace dom |
129 | | } // namespace mozilla |