Title: [254650] branches/safari-610.1.1-branch

Diff

Modified: branches/safari-610.1.1-branch/Source/WebCore/ChangeLog (254649 => 254650)


--- branches/safari-610.1.1-branch/Source/WebCore/ChangeLog	2020-01-15 23:07:43 UTC (rev 254649)
+++ branches/safari-610.1.1-branch/Source/WebCore/ChangeLog	2020-01-15 23:25:12 UTC (rev 254650)
@@ -1,3 +1,7 @@
+2020-01-15  Kocsen Chung  <kocsen_ch...@apple.com>
+
+        Revert r254537. rdar://problem/58542040
+
 2020-01-15  Alan Coon  <alanc...@apple.com>
 
         Cherry-pick r254551. rdar://problem/58508705

Modified: branches/safari-610.1.1-branch/Source/WebCore/platform/SharedBuffer.cpp (254649 => 254650)


--- branches/safari-610.1.1-branch/Source/WebCore/platform/SharedBuffer.cpp	2020-01-15 23:07:43 UTC (rev 254649)
+++ branches/safari-610.1.1-branch/Source/WebCore/platform/SharedBuffer.cpp	2020-01-15 23:25:12 UTC (rev 254650)
@@ -29,7 +29,9 @@
 #include "SharedBuffer.h"
 
 #include <algorithm>
+#include <wtf/HexNumber.h>
 #include <wtf/persistence/PersistentCoders.h>
+#include <wtf/text/StringBuilder.h>
 #include <wtf/unicode/UTF8Conversion.h>
 
 namespace WebCore {
@@ -132,6 +134,16 @@
     return { element->segment.copyRef(), position - element->beginPosition };
 }
 
+String SharedBuffer::toHexString() const
+{
+    StringBuilder stringBuilder;
+    for (unsigned byteOffset = 0; byteOffset < size(); byteOffset++) {
+        const uint8_t byte = data()[byteOffset];
+        stringBuilder.append(pad('0', 2, hex(byte)));
+    }
+    return stringBuilder.toString();
+}
+
 RefPtr<ArrayBuffer> SharedBuffer::tryCreateArrayBuffer() const
 {
     auto arrayBuffer = ArrayBuffer::tryCreateUninitialized(static_cast<unsigned>(size()), sizeof(char));

Modified: branches/safari-610.1.1-branch/Source/WebCore/platform/SharedBuffer.h (254649 => 254650)


--- branches/safari-610.1.1-branch/Source/WebCore/platform/SharedBuffer.h	2020-01-15 23:07:43 UTC (rev 254649)
+++ branches/safari-610.1.1-branch/Source/WebCore/platform/SharedBuffer.h	2020-01-15 23:25:12 UTC (rev 254650)
@@ -198,6 +198,8 @@
     // begin and end take O(1) time, this takes O(log(N)) time.
     SharedBufferDataView getSomeData(size_t position) const;
 
+    String toHexString() const;
+
     void hintMemoryNotNeededSoon() const;
 
     WTF::Persistence::Decoder decoder() const;

Modified: branches/safari-610.1.1-branch/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp (254649 => 254650)


--- branches/safari-610.1.1-branch/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp	2020-01-15 23:07:43 UTC (rev 254649)
+++ branches/safari-610.1.1-branch/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp	2020-01-15 23:25:12 UTC (rev 254650)
@@ -34,6 +34,7 @@
 #include "CDMKeySystemConfiguration.h"
 #include "CDMRestrictions.h"
 #include "CDMSessionType.h"
+#include "Logging.h"
 #include "SharedBuffer.h"
 #include <wtf/JSONValues.h>
 #include <wtf/MainThread.h>
@@ -537,6 +538,35 @@
     return adoptRef(new CDMInstanceSessionClearKey());
 }
 
+String CDMInstanceClearKey::Key::keyIDAsString() const
+{
+    return makeString("[", keyIDData->toHexString(), "]");
+}
+
+String CDMInstanceClearKey::Key::keyValueAsString() const
+{
+    return makeString("[", keyValueData->toHexString(), "]");
+}
+
+bool operator==(const CDMInstanceClearKey::Key& k1, const CDMInstanceClearKey::Key& k2)
+{
+    ASSERT(k1.keyIDData);
+    ASSERT(k2.keyIDData);
+
+    return *k1.keyIDData == *k2.keyIDData;
+}
+
+bool operator<(const CDMInstanceClearKey::Key& k1, const CDMInstanceClearKey::Key& k2)
+{
+    ASSERT(k1.keyIDData);
+    ASSERT(k2.keyIDData);
+
+    if (k1.keyIDData->size() != k2.keyIDData->size())
+        return k1.keyIDData->size() < k2.keyIDData->size();
+
+    return memcmp(k1.keyIDData->data(), k2.keyIDData->data(), k1.keyIDData->size());
+}
+
 void CDMInstanceSessionClearKey::requestLicense(LicenseType, const AtomString& initDataType, Ref<SharedBuffer>&& initData, LicenseCallback&& callback)
 {
     static uint32_t s_sessionIdValue = 0;
@@ -572,7 +602,6 @@
                 });
         };
 
-    // Parse the response buffer as an JSON object.
     RefPtr<JSON::Object> root = parseJSONObject(response);
     if (!root) {
         dispatchCallback(false, WTF::nullopt, SuccessValue::Failed);
@@ -579,65 +608,46 @@
         return;
     }
 
-    // Parse the response using 'license' formatting, if possible.
+    LOG(EME, "EME - ClearKey - updating license for session %s", sessionId.utf8().data());
+
     if (auto decodedKeys = parseLicenseFormat(*root)) {
         // Retrieve the target Vector of Key objects for this session.
-        auto& keyVector = ClearKeyState::singleton().keys().ensure(sessionId, [] { return Vector<CDMInstanceClearKey::Key> { }; }).iterator->value;
+        // FIXME: Refactor this state management code.
+        Vector<CDMInstanceClearKey::Key>& keyVector = ClearKeyState::singleton().keys().ensure(sessionId, [] { return Vector<CDMInstanceClearKey::Key> { }; }).iterator->value;
 
-        // For each decoded key, find an existing item for the decoded key's ID. If none exist,
-        // the key is decoded. Otherwise, the key is updated in case there's a mismatch between
-        // the size or data of the existing and proposed key.
         bool keysChanged = false;
-        for (auto& key : *decodedKeys) {
-            auto it = std::find_if(keyVector.begin(), keyVector.end(),
-                [&key] (const CDMInstanceClearKey::Key& containedKey) {
-                    return containedKey.keyIDData->size() == key.keyIDData->size()
-                        && !std::memcmp(containedKey.keyIDData->data(), key.keyIDData->data(), containedKey.keyIDData->size());
+        for (auto& decodedKey : *decodedKeys) {
+            LOG(EME, "EME - ClearKey - Decoded a key with ID %s and key data %s", decodedKey.keyIDAsString().utf8().data(), decodedKey.keyValueAsString().utf8().data());
+            auto keyWithMatchingKeyID = std::find_if(keyVector.begin(), keyVector.end(),
+                [&decodedKey] (const CDMInstanceClearKey::Key& containedKey) {
+                    return containedKey == decodedKey;
                 });
-            if (it != keyVector.end()) {
-                auto& existingKey = it->keyValueData;
-                auto& proposedKey = key.keyValueData;
+            if (keyWithMatchingKeyID != keyVector.end()) {
+                LOG(EME, "EME - ClearKey - Existing key found with data %s", keyWithMatchingKeyID->keyValueAsString().utf8().data());
 
-                // Update the existing Key if it differs from the proposed key in key value.
-                if (existingKey->size() != proposedKey->size() || std::memcmp(existingKey->data(), proposedKey->data(), existingKey->size())) {
-                    *it = WTFMove(key);
+                if (!keyWithMatchingKeyID->hasSameKeyValue(decodedKey)) {
+                    LOG(EME, "EME - ClearKey - Updating key since the data are different");
+                    *keyWithMatchingKeyID = WTFMove(decodedKey);
                     keysChanged = true;
                 }
             } else {
-                // In case a Key for this key ID doesn't exist yet, append the new one to keyVector.
-                keyVector.append(WTFMove(key));
+                LOG(EME, "EME - ClearKey - This is a new key");
+                keyVector.append(WTFMove(decodedKey));
                 keysChanged = true;
             }
         }
 
-        // In case of changed keys, we have to provide a KeyStatusVector of all the keys for
-        // this session.
+        LOG(EME, "EME - ClearKey - Update has provided %zu keys", keyVector.size());
+
         Optional<KeyStatusVector> changedKeys;
         if (keysChanged) {
-            // First a helper Vector is constructed, cotaining pairs of SharedBuffer RefPtrs
-            // representint key ID data, and the corresponding key statuses.
-            // We can't use KeyStatusVector here because this Vector has to be sorted, which
-            // is not possible to do on Ref<> objects.
-            Vector<std::pair<RefPtr<SharedBuffer>, KeyStatus>> keys;
-            keys.reserveInitialCapacity(keyVector.size());
-            for (auto& it : keyVector)
-                keys.uncheckedAppend(std::pair<RefPtr<SharedBuffer>, KeyStatus> { it.keyIDData, it.status });
+            // Sort by key IDs.
+            std::sort(keyVector.begin(), keyVector.end());
 
-            // Sort first by size, second by data.
-            std::sort(keys.begin(), keys.end(),
-                [] (const auto& a, const auto& b) {
-                    if (a.first->size() != b.first->size())
-                        return a.first->size() < b.first->size();
-
-                    return std::memcmp(a.first->data(), b.first->data(), a.first->size()) < 0;
-                });
-
-            // Finally construct the mirroring KeyStatusVector object and move it into the
-            // Optional<> object that will be passed to the callback.
             KeyStatusVector keyStatusVector;
-            keyStatusVector.reserveInitialCapacity(keys.size());
-            for (auto& it : keys)
-                keyStatusVector.uncheckedAppend(std::pair<Ref<SharedBuffer>, KeyStatus> { *it.first, it.second });
+            keyStatusVector.reserveInitialCapacity(keyVector.size());
+            for (auto& key : keyVector)
+                keyStatusVector.uncheckedAppend(std::pair<Ref<SharedBuffer>, KeyStatus> { *key.keyIDData, key.status });
 
             changedKeys = WTFMove(keyStatusVector);
         }
@@ -646,7 +656,6 @@
         return;
     }
 
-    // Parse the response using 'license release acknowledgement' formatting, if possible.
     if (parseLicenseReleaseAcknowledgementFormat(*root)) {
         // FIXME: Retrieve the key ID information and use it to validate the keys for this sessionId.
         ClearKeyState::singleton().keys().remove(sessionId);

Modified: branches/safari-610.1.1-branch/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.h (254649 => 254650)


--- branches/safari-610.1.1-branch/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.h	2020-01-15 23:07:43 UTC (rev 254649)
+++ branches/safari-610.1.1-branch/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.h	2020-01-15 23:25:12 UTC (rev 254650)
@@ -110,6 +110,26 @@
         CDMInstanceSession::KeyStatus status;
         RefPtr<SharedBuffer> keyIDData;
         RefPtr<SharedBuffer> keyValueData;
+
+        String keyIDAsString() const;
+        String keyValueAsString() const;
+
+        bool hasSameKeyValue(const Key &other)
+        {
+            ASSERT(keyValueData);
+            ASSERT(other.keyValueData);
+            return *keyValueData == *other.keyValueData;
+        }
+
+        // Two keys are equal if they have the same ID, ignoring key value and status.
+        friend bool operator==(const Key &k1, const Key &k2);
+        // Key's are ordered by their IDs, first by size, then by contents.
+        friend bool operator<(const Key &k1, const Key &k2);
+
+        friend bool operator!=(const Key &k1, const Key &k2) { return !(operator==(k1, k2)); }
+        friend bool operator>(const Key &k1, const Key &k2) { return !operator==(k1, k2) && !operator<(k1, k2); }
+        friend bool operator<=(const Key &k1, const Key &k2) { return !operator>(k1, k2); }
+        friend bool operator>=(const Key &k1, const Key &k2) { return !operator<(k1, k2); }
     };
 
     RefPtr<ProxyCDM> proxyCDM() const final { return m_proxyCDM; }

Modified: branches/safari-610.1.1-branch/Tools/ChangeLog (254649 => 254650)


--- branches/safari-610.1.1-branch/Tools/ChangeLog	2020-01-15 23:07:43 UTC (rev 254649)
+++ branches/safari-610.1.1-branch/Tools/ChangeLog	2020-01-15 23:25:12 UTC (rev 254650)
@@ -1,3 +1,7 @@
+2020-01-15  Kocsen Chung  <kocsen_ch...@apple.com>
+
+        Revert r254537. rdar://problem/58542040
+
 2020-01-14  Kocsen Chung  <kocsen_ch...@apple.com>
 
         Revert r254334. rdar://problem/58542040

Modified: branches/safari-610.1.1-branch/Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp (254649 => 254650)


--- branches/safari-610.1.1-branch/Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp	2020-01-15 23:07:43 UTC (rev 254649)
+++ branches/safari-610.1.1-branch/Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp	2020-01-15 23:25:12 UTC (rev 254650)
@@ -217,4 +217,15 @@
     EXPECT_NE(makeBuffer({{'a'}, {'b'}}), makeBuffer({{'a'}, {'a'}}));
 }
 
+TEST_F(SharedBufferTest, toHexString)
+{
+    Vector<char> t1 = {0x11, 0x5, 0x12};
+    auto buffer = SharedBuffer::create();
+    buffer->append(WTFMove(t1));
+    String result = buffer->toHexString();
+    EXPECT_EQ(result, "110512");
+    buffer->clear();
+    EXPECT_EQ(buffer->toHexString(), "");
 }
+
+}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to