| 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 #include "modules/encryptedmedia/MediaKeyStatusMap.h" | 5 #include "modules/encryptedmedia/MediaKeyStatusMap.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ArrayBufferOrArrayBufferView.h" | 7 #include "bindings/core/v8/ArrayBufferOrArrayBufferView.h" |
| 8 #include "core/dom/DOMArrayBuffer.h" | 8 #include "core/dom/DOMArrayBuffer.h" |
| 9 #include "core/dom/DOMArrayPiece.h" | 9 #include "core/dom/DOMArrayPiece.h" |
| 10 #include "public/platform/WebData.h" | 10 #include "public/platform/WebData.h" |
| 11 #include "wtf/text/WTFString.h" | 11 #include "wtf/text/WTFString.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <limits> |
| 14 | 15 |
| 15 namespace blink { | 16 namespace blink { |
| 16 | 17 |
| 17 // Represents the key ID and associated status. | 18 // Represents the key ID and associated status. |
| 18 class MediaKeyStatusMap::MapEntry final : public GarbageCollectedFinalized<Media
KeyStatusMap::MapEntry> { | 19 class MediaKeyStatusMap::MapEntry final : public GarbageCollectedFinalized<Media
KeyStatusMap::MapEntry> { |
| 19 public: | 20 public: |
| 20 static MapEntry* create(WebData keyId, const String& status) | 21 static MapEntry* create(WebData keyId, const String& status) |
| 21 { | 22 { |
| 22 return new MapEntry(keyId, status); | 23 return new MapEntry(keyId, status); |
| 23 } | 24 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } | 134 } |
| 134 | 135 |
| 135 size_t MediaKeyStatusMap::indexOf(const DOMArrayPiece& key) const | 136 size_t MediaKeyStatusMap::indexOf(const DOMArrayPiece& key) const |
| 136 { | 137 { |
| 137 for (size_t index = 0; index < m_entries.size(); ++index) { | 138 for (size_t index = 0; index < m_entries.size(); ++index) { |
| 138 const auto& current = m_entries.at(index)->keyId(); | 139 const auto& current = m_entries.at(index)->keyId(); |
| 139 if (key == *current) | 140 if (key == *current) |
| 140 return index; | 141 return index; |
| 141 } | 142 } |
| 142 | 143 |
| 143 // Not found, so return an index outside the valid range. | 144 // Not found, so return an index outside the valid range. The caller |
| 144 return m_entries.size(); | 145 // must ensure this value is not exposed outside this class. |
| 146 return std::numeric_limits<size_t>::max(); |
| 147 } |
| 148 |
| 149 bool MediaKeyStatusMap::has(const ArrayBufferOrArrayBufferView& keyId) |
| 150 { |
| 151 size_t index = indexOf(keyId); |
| 152 return index < m_entries.size(); |
| 153 } |
| 154 |
| 155 ScriptValue MediaKeyStatusMap::get(ScriptState* scriptState, const ArrayBufferOr
ArrayBufferView& keyId) |
| 156 { |
| 157 size_t index = indexOf(keyId); |
| 158 if (index >= m_entries.size()) |
| 159 return ScriptValue(scriptState, v8::Undefined(scriptState->isolate())); |
| 160 return ScriptValue::from(scriptState, at(index).status()); |
| 145 } | 161 } |
| 146 | 162 |
| 147 PairIterable<ArrayBufferOrArrayBufferView, String>::IterationSource* MediaKeySta
tusMap::startIteration(ScriptState*, ExceptionState&) | 163 PairIterable<ArrayBufferOrArrayBufferView, String>::IterationSource* MediaKeySta
tusMap::startIteration(ScriptState*, ExceptionState&) |
| 148 { | 164 { |
| 149 return new MapIterationSource(this); | 165 return new MapIterationSource(this); |
| 150 } | 166 } |
| 151 | 167 |
| 152 bool MediaKeyStatusMap::getMapEntry(ScriptState*, const ArrayBufferOrArrayBuffer
View& key, String& value, ExceptionState&) | |
| 153 { | |
| 154 size_t index = indexOf(key); | |
| 155 if (index < m_entries.size()) { | |
| 156 value = at(index).status(); | |
| 157 return true; | |
| 158 } | |
| 159 return false; | |
| 160 } | |
| 161 | |
| 162 DEFINE_TRACE(MediaKeyStatusMap) | 168 DEFINE_TRACE(MediaKeyStatusMap) |
| 163 { | 169 { |
| 164 visitor->trace(m_entries); | 170 visitor->trace(m_entries); |
| 165 } | 171 } |
| 166 | 172 |
| 167 } // namespace blink | 173 } // namespace blink |
| OLD | NEW |