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

Diff

Modified: branches/safari-610.1.1-branch/Source/WebCore/ChangeLog (254536 => 254537)


--- branches/safari-610.1.1-branch/Source/WebCore/ChangeLog	2020-01-14 22:35:05 UTC (rev 254536)
+++ branches/safari-610.1.1-branch/Source/WebCore/ChangeLog	2020-01-14 22:35:09 UTC (rev 254537)
@@ -1,3 +1,7 @@
+2020-01-14  Kocsen Chung  <[email protected]>
+
+        Revert r254334. rdar://problem/58542040
+
 2020-01-11  Zalan Bujtas  <[email protected]>
 
         [LFC] Introduce the concept of independent formatting context

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


--- branches/safari-610.1.1-branch/Source/WebCore/platform/SharedBuffer.cpp	2020-01-14 22:35:05 UTC (rev 254536)
+++ branches/safari-610.1.1-branch/Source/WebCore/platform/SharedBuffer.cpp	2020-01-14 22:35:09 UTC (rev 254537)
@@ -29,9 +29,7 @@
 #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 {
@@ -134,16 +132,6 @@
     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 (254536 => 254537)


--- branches/safari-610.1.1-branch/Source/WebCore/platform/SharedBuffer.h	2020-01-14 22:35:05 UTC (rev 254536)
+++ branches/safari-610.1.1-branch/Source/WebCore/platform/SharedBuffer.h	2020-01-14 22:35:09 UTC (rev 254537)
@@ -198,8 +198,6 @@
     // 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 (254536 => 254537)


--- branches/safari-610.1.1-branch/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp	2020-01-14 22:35:05 UTC (rev 254536)
+++ branches/safari-610.1.1-branch/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp	2020-01-14 22:35:09 UTC (rev 254537)
@@ -34,7 +34,6 @@
 #include "CDMKeySystemConfiguration.h"
 #include "CDMRestrictions.h"
 #include "CDMSessionType.h"
-#include "Logging.h"
 #include "SharedBuffer.h"
 #include <wtf/JSONValues.h>
 #include <wtf/MainThread.h>
@@ -538,35 +537,6 @@
     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;
@@ -602,6 +572,7 @@
                 });
         };
 
+    // Parse the response buffer as an JSON object.
     RefPtr<JSON::Object> root = parseJSONObject(response);
     if (!root) {
         dispatchCallback(false, WTF::nullopt, SuccessValue::Failed);
@@ -608,46 +579,65 @@
         return;
     }
 
-    LOG(EME, "EME - ClearKey - updating license for session %s", sessionId.utf8().data());
-
+    // Parse the response using 'license' formatting, if possible.
     if (auto decodedKeys = parseLicenseFormat(*root)) {
         // Retrieve the target Vector of Key objects for this session.
-        // FIXME: Refactor this state management code.
-        Vector<CDMInstanceClearKey::Key>& keyVector = ClearKeyState::singleton().keys().ensure(sessionId, [] { return Vector<CDMInstanceClearKey::Key> { }; }).iterator->value;
+        auto& 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& 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;
+        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());
                 });
-            if (keyWithMatchingKeyID != keyVector.end()) {
-                LOG(EME, "EME - ClearKey - Existing key found with data %s", keyWithMatchingKeyID->keyValueAsString().utf8().data());
+            if (it != keyVector.end()) {
+                auto& existingKey = it->keyValueData;
+                auto& proposedKey = key.keyValueData;
 
-                if (!keyWithMatchingKeyID->hasSameKeyValue(decodedKey)) {
-                    LOG(EME, "EME - ClearKey - Updating key since the data are different");
-                    *keyWithMatchingKeyID = WTFMove(decodedKey);
+                // 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);
                     keysChanged = true;
                 }
             } else {
-                LOG(EME, "EME - ClearKey - This is a new key");
-                keyVector.append(WTFMove(decodedKey));
+                // In case a Key for this key ID doesn't exist yet, append the new one to keyVector.
+                keyVector.append(WTFMove(key));
                 keysChanged = true;
             }
         }
 
-        LOG(EME, "EME - ClearKey - Update has provided %zu keys", keyVector.size());
-
+        // In case of changed keys, we have to provide a KeyStatusVector of all the keys for
+        // this session.
         Optional<KeyStatusVector> changedKeys;
         if (keysChanged) {
-            // Sort by key IDs.
-            std::sort(keyVector.begin(), keyVector.end());
+            // 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 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(keyVector.size());
-            for (auto& key : keyVector)
-                keyStatusVector.uncheckedAppend(std::pair<Ref<SharedBuffer>, KeyStatus> { *key.keyIDData, key.status });
+            keyStatusVector.reserveInitialCapacity(keys.size());
+            for (auto& it : keys)
+                keyStatusVector.uncheckedAppend(std::pair<Ref<SharedBuffer>, KeyStatus> { *it.first, it.second });
 
             changedKeys = WTFMove(keyStatusVector);
         }
@@ -656,6 +646,7 @@
         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 (254536 => 254537)


--- branches/safari-610.1.1-branch/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.h	2020-01-14 22:35:05 UTC (rev 254536)
+++ branches/safari-610.1.1-branch/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.h	2020-01-14 22:35:09 UTC (rev 254537)
@@ -110,26 +110,6 @@
         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 (254536 => 254537)


--- branches/safari-610.1.1-branch/Tools/ChangeLog	2020-01-14 22:35:05 UTC (rev 254536)
+++ branches/safari-610.1.1-branch/Tools/ChangeLog	2020-01-14 22:35:09 UTC (rev 254537)
@@ -1,3 +1,7 @@
+2020-01-14  Kocsen Chung  <[email protected]>
+
+        Revert r254334. rdar://problem/58542040
+
 2020-01-11  Alex Christensen  <[email protected]>
 
         Expose frame information on _WKResourceLoadInfo

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


--- branches/safari-610.1.1-branch/Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp	2020-01-14 22:35:05 UTC (rev 254536)
+++ branches/safari-610.1.1-branch/Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp	2020-01-14 22:35:09 UTC (rev 254537)
@@ -217,15 +217,4 @@
     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
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to