Title: [260568] trunk/Source/WebCore
- Revision
- 260568
- Author
- ctur...@igalia.com
- Date
- 2020-04-23 07:50:47 -0700 (Thu, 23 Apr 2020)
Log Message
[EME][CDMProxy] Sort key status array lexicographically by key IDs
https://bugs.webkit.org/show_bug.cgi?id=210659
Reviewed by Xabier Rodriguez-Calvar.
This is required by section 6.1 of
https://www.w3.org/TR/encrypted-media/.
Test: encrypted-media/clearkey-keystatuses.https.html
* platform/encryptedmedia/CDMProxy.cpp:
(WebCore::KeyStore::add): We could use a set here and keep it
sorted by design, but this is more complexity than needed. The
store has for practical purposes an upper limit of 2
items. Sorting such a vector lowers to either a noop or a swap. So
the simple approach here wins over using some kind of self-sorting
set structure. I also considered only sorting on-demand, since it
only has to appear sorted from the perspective of JS, we could
sort the array in convertToJSKeyStatusVector. However, that is
semantically a const method, so sorting here felt too surprising.
* platform/encryptedmedia/CDMProxy.h:
(WebCore::Key::operator<): Add a lexicographic comparator to
Key.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (260567 => 260568)
--- trunk/Source/WebCore/ChangeLog 2020-04-23 14:33:24 UTC (rev 260567)
+++ trunk/Source/WebCore/ChangeLog 2020-04-23 14:50:47 UTC (rev 260568)
@@ -1,3 +1,29 @@
+2020-04-23 Charlie Turner <ctur...@igalia.com>
+
+ [EME][CDMProxy] Sort key status array lexicographically by key IDs
+ https://bugs.webkit.org/show_bug.cgi?id=210659
+
+ Reviewed by Xabier Rodriguez-Calvar.
+
+ This is required by section 6.1 of
+ https://www.w3.org/TR/encrypted-media/.
+
+ Test: encrypted-media/clearkey-keystatuses.https.html
+
+ * platform/encryptedmedia/CDMProxy.cpp:
+ (WebCore::KeyStore::add): We could use a set here and keep it
+ sorted by design, but this is more complexity than needed. The
+ store has for practical purposes an upper limit of 2
+ items. Sorting such a vector lowers to either a noop or a swap. So
+ the simple approach here wins over using some kind of self-sorting
+ set structure. I also considered only sorting on-demand, since it
+ only has to appear sorted from the perspective of JS, we could
+ sort the array in convertToJSKeyStatusVector. However, that is
+ semantically a const method, so sorting here felt too surprising.
+ * platform/encryptedmedia/CDMProxy.h:
+ (WebCore::Key::operator<): Add a lexicographic comparator to
+ Key.
+
2020-04-23 Carlos Garcia Campos <cgar...@igalia.com>
[GTK] excessive wakeups/polling due to gdk_frame_clock_begin_updating
Modified: trunk/Source/WebCore/platform/encryptedmedia/CDMProxy.cpp (260567 => 260568)
--- trunk/Source/WebCore/platform/encryptedmedia/CDMProxy.cpp 2020-04-23 14:33:24 UTC (rev 260567)
+++ trunk/Source/WebCore/platform/encryptedmedia/CDMProxy.cpp 2020-04-23 14:50:47 UTC (rev 260568)
@@ -122,6 +122,16 @@
didStoreChange = true;
}
+ if (didStoreChange) {
+ // Sort the keys lexicographically.
+ // NOTE: This is not as pathological as it may seem, for all
+ // practical purposes the store has a maximum of 2 keys.
+ std::sort(m_keys.begin(), m_keys.end(),
+ [](const RefPtr<Key>& a, const RefPtr<Key>& b) {
+ return *a < *b;
+ });
+ }
+
key->addSessionReference();
return didStoreChange;
}
Modified: trunk/Source/WebCore/platform/encryptedmedia/CDMProxy.h (260567 => 260568)
--- trunk/Source/WebCore/platform/encryptedmedia/CDMProxy.h 2020-04-23 14:33:24 UTC (rev 260567)
+++ trunk/Source/WebCore/platform/encryptedmedia/CDMProxy.h 2020-04-23 14:50:47 UTC (rev 260568)
@@ -61,6 +61,21 @@
friend bool operator==(const Key &k1, const Key &k2) { return k1.m_id == k2.m_id; }
friend bool operator==(const Key &k, const Vector<uint8_t>& keyID) { return k.m_id == keyID; }
friend bool operator==(const Vector<uint8_t>& keyID, const Key &k) { return k == keyID; }
+ friend bool operator<(const Key& k1, const Key& k2)
+ {
+ // Key IDs are compared as follows: For key IDs A of length m and
+ // B of length n, assigned such that m <= n, let A < B if and only
+ // if the m octets of A are less in lexicographical order than the
+ // first m octets of B or those octets are equal and m < n.
+ // 6.1 https://www.w3.org/TR/encrypted-media/
+ int isDifference = memcmp(k1.m_id.data(), k2.m_id.data(), std::min(k1.m_id.size(), k2.m_id.size()));
+ if (isDifference)
+ return isDifference < 0;
+ // The keys are equal to the shared length, the shorter string
+ // is therefore less than the longer one in a lexicographical
+ // ordering.
+ return k1.m_id.size() < k2.m_id.size();
+ }
private:
void addSessionReference() { ASSERT(isMainThread()); m_numSessionReferences++; }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes