| Index: Source/modules/encryptedmedia/MediaKeyStatusMap.cpp
|
| diff --git a/Source/modules/encryptedmedia/MediaKeyStatusMap.cpp b/Source/modules/encryptedmedia/MediaKeyStatusMap.cpp
|
| index 69d14c6c227595b076623af81f3fc69ff43e6038..a2d0d5e117839fea017db18e1d8886dfe2e85e3c 100644
|
| --- a/Source/modules/encryptedmedia/MediaKeyStatusMap.cpp
|
| +++ b/Source/modules/encryptedmedia/MediaKeyStatusMap.cpp
|
| @@ -10,6 +10,8 @@
|
| #include "public/platform/WebData.h"
|
| #include "wtf/text/WTFString.h"
|
|
|
| +#include <algorithm>
|
| +
|
| namespace blink {
|
|
|
| // Represents the key ID and associated status.
|
| @@ -32,6 +34,29 @@ public:
|
| return m_status;
|
| }
|
|
|
| + static bool compareLessThan(MapEntry* a, MapEntry* b)
|
| + {
|
| + // Compare the keyIds of 2 different MapEntries. Assume that |a| and |b|
|
| + // are not null. KeyIds are compared byte by byte.
|
| +
|
| + // Handle null cases first (which shouldn't happen).
|
| + // |aKeyId| |bKeyId| result
|
| + // null null == (false)
|
| + // null not-null < (true)
|
| + // not-null null > (false)
|
| + if (!a->keyId() || !b->keyId())
|
| + return b->keyId();
|
| +
|
| + // Compare the bytes.
|
| + int result = memcmp(a->keyId()->data(), b->keyId()->data(),
|
| + std::min(a->keyId()->byteLength(), b->keyId()->byteLength()));
|
| + if (result != 0)
|
| + return result < 0;
|
| +
|
| + // KeyIds are equal to the shared length, so the shorter string is <.
|
| + return a->keyId()->byteLength() <= b->keyId()->byteLength();
|
| + }
|
| +
|
| DEFINE_INLINE_VIRTUAL_TRACE()
|
| {
|
| }
|
| @@ -90,6 +115,13 @@ void MediaKeyStatusMap::clear()
|
| void MediaKeyStatusMap::addEntry(WebData keyId, const String& status)
|
| {
|
| m_entries.append(MapEntry::create(keyId, status));
|
| +
|
| + // No need to do any sorting for the first entry.
|
| + if (m_entries.size() == 1)
|
| + return;
|
| +
|
| + // Sort the entries.
|
| + std::sort(m_entries.begin(), m_entries.end(), MapEntry::compareLessThan);
|
| }
|
|
|
| const MediaKeyStatusMap::MapEntry& MediaKeyStatusMap::at(size_t index) const
|
| @@ -110,19 +142,23 @@ size_t MediaKeyStatusMap::indexOf(const DOMArrayPiece& key) const
|
| return m_entries.size();
|
| }
|
|
|
| -PairIterable<ArrayBufferOrArrayBufferView, String>::IterationSource* MediaKeyStatusMap::startIteration(ScriptState*, ExceptionState&)
|
| +bool MediaKeyStatusMap::has(const ArrayBufferOrArrayBufferView& keyId)
|
| {
|
| - return new MapIterationSource(this);
|
| + size_t index = indexOf(keyId);
|
| + return index < m_entries.size();
|
| }
|
|
|
| -bool MediaKeyStatusMap::getMapEntry(ScriptState*, const ArrayBufferOrArrayBufferView& key, String& value, ExceptionState&)
|
| +String MediaKeyStatusMap::get(const ArrayBufferOrArrayBufferView& keyId)
|
| {
|
| - size_t index = indexOf(key);
|
| - if (index < m_entries.size()) {
|
| - value = at(index).status();
|
| - return true;
|
| - }
|
| - return false;
|
| + size_t index = indexOf(keyId);
|
| + if (index >= m_entries.size())
|
| + return String();
|
| + return at(index).status();
|
| +}
|
| +
|
| +PairIterable<ArrayBufferOrArrayBufferView, String>::IterationSource* MediaKeyStatusMap::startIteration(ScriptState*, ExceptionState&)
|
| +{
|
| + return new MapIterationSource(this);
|
| }
|
|
|
| DEFINE_TRACE(MediaKeyStatusMap)
|
|
|