/work/obj-fuzz/dist/include/mozilla/dom/MediaKeyStatusMap.h
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 | | #ifndef mozilla_dom_MediaKeyStatuses_h |
8 | | #define mozilla_dom_MediaKeyStatuses_h |
9 | | |
10 | | #include "mozilla/ErrorResult.h" |
11 | | #include "mozilla/Attributes.h" |
12 | | #include "nsCycleCollectionParticipant.h" |
13 | | #include "nsWrapperCache.h" |
14 | | |
15 | | #include "mozilla/dom/TypedArray.h" |
16 | | #include "mozilla/dom/MediaKeyStatusMapBinding.h" |
17 | | #include "mozilla/CDMCaps.h" |
18 | | |
19 | | class nsPIDOMWindowInner; |
20 | | |
21 | | namespace mozilla { |
22 | | namespace dom { |
23 | | |
24 | | class ArrayBufferViewOrArrayBuffer; |
25 | | |
26 | | // The MediaKeyStatusMap WebIDL interface; maps a keyId to its status. |
27 | | // Note that the underlying "map" is stored in an array, since we assume |
28 | | // that a MediaKeySession won't have many key statuses to report. |
29 | | class MediaKeyStatusMap final : public nsISupports, |
30 | | public nsWrapperCache |
31 | | { |
32 | | public: |
33 | | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
34 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaKeyStatusMap) |
35 | | |
36 | | public: |
37 | | explicit MediaKeyStatusMap(nsPIDOMWindowInner* aParent); |
38 | | |
39 | | protected: |
40 | | ~MediaKeyStatusMap(); |
41 | | |
42 | | public: |
43 | | nsPIDOMWindowInner* GetParentObject() const; |
44 | | |
45 | | JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
46 | | |
47 | | void Get(JSContext* aCx, |
48 | | const ArrayBufferViewOrArrayBuffer& aKey, |
49 | | JS::MutableHandle<JS::Value> aOutValue, |
50 | | ErrorResult& aOutRv) const; |
51 | | bool Has(const ArrayBufferViewOrArrayBuffer& aKey) const; |
52 | | uint32_t Size() const; |
53 | | |
54 | | uint32_t GetIterableLength() const; |
55 | | TypedArrayCreator<ArrayBuffer> GetKeyAtIndex(uint32_t aIndex) const; |
56 | | nsString GetKeyIDAsHexString(uint32_t aIndex) const; |
57 | | MediaKeyStatus GetValueAtIndex(uint32_t aIndex) const; |
58 | | |
59 | | void Update(const nsTArray<CDMCaps::KeyStatus>& keys); |
60 | | |
61 | | private: |
62 | | |
63 | | nsCOMPtr<nsPIDOMWindowInner> mParent; |
64 | | |
65 | | struct KeyStatus { |
66 | | KeyStatus(const nsTArray<uint8_t>& aKeyId, |
67 | | MediaKeyStatus aStatus) |
68 | | : mKeyId(aKeyId) |
69 | | , mStatus(aStatus) |
70 | 0 | { |
71 | 0 | } |
72 | 0 | bool operator== (const KeyStatus& aOther) const { |
73 | 0 | return aOther.mKeyId == mKeyId; |
74 | 0 | } |
75 | 0 | bool operator<(const KeyStatus& aOther) const { |
76 | 0 | // Copy chromium and compare keys' bytes. |
77 | 0 | // Update once https://github.com/w3c/encrypted-media/issues/69 |
78 | 0 | // is resolved. |
79 | 0 | const nsTArray<uint8_t>& other = aOther.mKeyId; |
80 | 0 | const nsTArray<uint8_t>& self = mKeyId; |
81 | 0 | size_t length = std::min<size_t>(other.Length(), self.Length()); |
82 | 0 | int cmp = memcmp(self.Elements(), other.Elements(), length); |
83 | 0 | if (cmp != 0) { |
84 | 0 | return cmp < 0; |
85 | 0 | } |
86 | 0 | return self.Length() <= other.Length(); |
87 | 0 | } |
88 | | nsTArray<uint8_t> mKeyId; |
89 | | MediaKeyStatus mStatus; |
90 | | }; |
91 | | |
92 | | nsTArray<KeyStatus> mStatuses; |
93 | | }; |
94 | | |
95 | | } // namespace dom |
96 | | } // namespace mozilla |
97 | | |
98 | | #endif |