Chromium Code Reviews| 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" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 } | 133 } |
| 134 | 134 |
| 135 size_t MediaKeyStatusMap::indexOf(const DOMArrayPiece& key) const | 135 size_t MediaKeyStatusMap::indexOf(const DOMArrayPiece& key) const |
| 136 { | 136 { |
| 137 for (size_t index = 0; index < m_entries.size(); ++index) { | 137 for (size_t index = 0; index < m_entries.size(); ++index) { |
| 138 const auto& current = m_entries.at(index)->keyId(); | 138 const auto& current = m_entries.at(index)->keyId(); |
| 139 if (key == *current) | 139 if (key == *current) |
| 140 return index; | 140 return index; |
| 141 } | 141 } |
| 142 | 142 |
| 143 // Not found, so return an index outside the valid range. | 143 // Not found, so return an index outside the valid range. |
|
ddorwin
2016/06/14 20:56:05
The caller must ensure this value is not exposed o
jrummell
2016/06/14 22:24:21
Done.
| |
| 144 return m_entries.size(); | 144 return m_entries.size(); |
|
ddorwin
2016/06/14 20:56:05
Unrelated to this CL:
Is this a common pattern? It
jrummell
2016/06/14 22:24:21
Done. There is also WTF::kNotFound.
| |
| 145 } | 145 } |
| 146 | 146 |
| 147 bool MediaKeyStatusMap::has(const ArrayBufferOrArrayBufferView& keyId) | |
| 148 { | |
| 149 size_t index = indexOf(keyId); | |
| 150 return index < m_entries.size(); | |
| 151 } | |
| 152 | |
| 153 ScriptValue MediaKeyStatusMap::get(ScriptState* scriptState, const ArrayBufferOr ArrayBufferView& keyId) | |
| 154 { | |
| 155 size_t index = indexOf(keyId); | |
| 156 if (index >= m_entries.size()) | |
| 157 return ScriptValue(scriptState, v8::Undefined(scriptState->isolate())); | |
| 158 return ScriptValue::from(scriptState, at(index).status()); | |
| 159 } | |
| 160 | |
| 147 PairIterable<ArrayBufferOrArrayBufferView, String>::IterationSource* MediaKeySta tusMap::startIteration(ScriptState*, ExceptionState&) | 161 PairIterable<ArrayBufferOrArrayBufferView, String>::IterationSource* MediaKeySta tusMap::startIteration(ScriptState*, ExceptionState&) |
| 148 { | 162 { |
| 149 return new MapIterationSource(this); | 163 return new MapIterationSource(this); |
| 150 } | 164 } |
| 151 | 165 |
| 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) | 166 DEFINE_TRACE(MediaKeyStatusMap) |
| 163 { | 167 { |
| 164 visitor->trace(m_entries); | 168 visitor->trace(m_entries); |
| 165 } | 169 } |
| 166 | 170 |
| 167 } // namespace blink | 171 } // namespace blink |
| OLD | NEW |