| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MediaKeyStatusMap_h | 5 #ifndef MediaKeyStatusMap_h |
| 6 #define MediaKeyStatusMap_h | 6 #define MediaKeyStatusMap_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/Maplike.h" | 8 #include "bindings/core/v8/Iterable.h" |
| 9 #include "bindings/core/v8/ScriptWrappable.h" | 9 #include "bindings/core/v8/ScriptWrappable.h" |
| 10 #include "bindings/core/v8/UnionTypesCore.h" | 10 #include "bindings/core/v8/UnionTypesCore.h" |
| 11 #include "core/dom/DOMArrayPiece.h" | 11 #include "core/dom/DOMArrayPiece.h" |
| 12 #include "platform/heap/Heap.h" | 12 #include "platform/heap/Heap.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 class ExceptionState; | 16 class ExceptionState; |
| 17 class Iterator; | 17 class Iterator; |
| 18 class ScriptState; | 18 class ScriptState; |
| 19 class WebData; | 19 class WebData; |
| 20 | 20 |
| 21 // Represents a read-only map (to JavaScript) of key IDs and their current | 21 // Represents a read-only map (to JavaScript) of key IDs and their current |
| 22 // status known to a particular session. Since it can be updated any time there | 22 // status known to a particular session. Since it can be updated any time there |
| 23 // is a keychange event, iteration order and completeness is not guaranteed | 23 // is a keychange event, iteration order and completeness is not guaranteed |
| 24 // if the event loop runs. | 24 // if the event loop runs. |
| 25 class MediaKeyStatusMap final : public GarbageCollected<MediaKeyStatusMap>, publ
ic ScriptWrappable, public Maplike<ArrayBufferOrArrayBufferView, String> { | 25 class MediaKeyStatusMap final : public GarbageCollected<MediaKeyStatusMap>, publ
ic ScriptWrappable, public PairIterable<ArrayBufferOrArrayBufferView, String> { |
| 26 DEFINE_WRAPPERTYPEINFO(); | 26 DEFINE_WRAPPERTYPEINFO(); |
| 27 private: | 27 private: |
| 28 // MapEntry holds the keyId (DOMArrayBuffer) and status (MediaKeyStatus as | 28 // MapEntry holds the keyId (DOMArrayBuffer) and status (MediaKeyStatus as |
| 29 // String) for each entry. | 29 // String) for each entry. |
| 30 class MapEntry; | 30 class MapEntry; |
| 31 | 31 |
| 32 // As the number of keys per session should be small, the key ids and | 32 // The key ids and their status are kept in a list, as order is important. |
| 33 // their status are kept in a list rather than a proper map. | 33 typedef HeapVector<Member<MapEntry>> MediaKeyStatusMapType; |
| 34 typedef HeapVector<Member<MapEntry>> MapType; | |
| 35 | 34 |
| 36 public: | 35 public: |
| 37 MediaKeyStatusMap() { } | 36 MediaKeyStatusMap() { } |
| 38 | 37 |
| 39 void clear(); | 38 void clear(); |
| 40 void addEntry(WebData source, const String& status); | 39 void addEntry(WebData keyId, const String& status); |
| 41 const MapEntry& at(size_t) const; | 40 const MapEntry& at(size_t) const; |
| 42 | 41 |
| 43 // IDL attributes / methods | 42 // IDL attributes / methods |
| 44 size_t size() const { return m_entries.size(); } | 43 size_t size() const { return m_entries.size(); } |
| 44 bool has(const ArrayBufferOrArrayBufferView& keyId); |
| 45 String get(const ArrayBufferOrArrayBufferView& keyId); |
| 45 | 46 |
| 46 DECLARE_VIRTUAL_TRACE(); | 47 DECLARE_VIRTUAL_TRACE(); |
| 47 | 48 |
| 48 private: | 49 private: |
| 50 // PairIterable<> implementation. |
| 49 IterationSource* startIteration(ScriptState*, ExceptionState&) override; | 51 IterationSource* startIteration(ScriptState*, ExceptionState&) override; |
| 50 bool getMapEntry(ScriptState*, const ArrayBufferOrArrayBufferView&, String&,
ExceptionState&) override; | |
| 51 | 52 |
| 52 size_t indexOf(const DOMArrayPiece& key) const; | 53 size_t indexOf(const DOMArrayPiece& keyId) const; |
| 53 | 54 |
| 54 MapType m_entries; | 55 MediaKeyStatusMapType m_entries; |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 } // namespace blink | 58 } // namespace blink |
| 58 | 59 |
| 59 #endif // MediaKeyStatusMap_h | 60 #endif // MediaKeyStatusMap_h |
| OLD | NEW |