Changeset 254537 in webkit


Ignore:
Timestamp:
Jan 14, 2020 2:35:09 PM (4 years ago)
Author:
Alan Coon
Message:

Revert r254334. rdar://problem/58542040

Location:
branches/safari-610.1.1-branch
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-610.1.1-branch/Source/WebCore/ChangeLog

    r254410 r254537  
     12020-01-14  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Revert r254334. rdar://problem/58542040
     4
    152020-01-11  Zalan Bujtas  <zalan@apple.com>
    26
  • branches/safari-610.1.1-branch/Source/WebCore/platform/SharedBuffer.cpp

    r254334 r254537  
    3030
    3131#include <algorithm>
    32 #include <wtf/HexNumber.h>
    3332#include <wtf/persistence/PersistentCoders.h>
    34 #include <wtf/text/StringBuilder.h>
    3533#include <wtf/unicode/UTF8Conversion.h>
    3634
     
    133131    element--; // std::upper_bound gives a pointer to the element that is greater than position. We want the element just before that.
    134132    return { element->segment.copyRef(), position - element->beginPosition };
    135 }
    136 
    137 String SharedBuffer::toHexString() const
    138 {
    139     StringBuilder stringBuilder;
    140     for (unsigned byteOffset = 0; byteOffset < size(); byteOffset++) {
    141         const uint8_t byte = data()[byteOffset];
    142         stringBuilder.append(pad('0', 2, hex(byte)));
    143     }
    144     return stringBuilder.toString();
    145133}
    146134
  • branches/safari-610.1.1-branch/Source/WebCore/platform/SharedBuffer.h

    r254334 r254537  
    199199    SharedBufferDataView getSomeData(size_t position) const;
    200200
    201     String toHexString() const;
    202 
    203201    void hintMemoryNotNeededSoon() const;
    204202
  • branches/safari-610.1.1-branch/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp

    r254334 r254537  
    3535#include "CDMRestrictions.h"
    3636#include "CDMSessionType.h"
    37 #include "Logging.h"
    3837#include "SharedBuffer.h"
    3938#include <wtf/JSONValues.h>
     
    539538}
    540539
    541 String CDMInstanceClearKey::Key::keyIDAsString() const
    542 {
    543     return makeString("[", keyIDData->toHexString(), "]");
    544 }
    545 
    546 String CDMInstanceClearKey::Key::keyValueAsString() const
    547 {
    548     return makeString("[", keyValueData->toHexString(), "]");
    549 }
    550 
    551 bool operator==(const CDMInstanceClearKey::Key& k1, const CDMInstanceClearKey::Key& k2)
    552 {
    553     ASSERT(k1.keyIDData);
    554     ASSERT(k2.keyIDData);
    555 
    556     return *k1.keyIDData == *k2.keyIDData;
    557 }
    558 
    559 bool operator<(const CDMInstanceClearKey::Key& k1, const CDMInstanceClearKey::Key& k2)
    560 {
    561     ASSERT(k1.keyIDData);
    562     ASSERT(k2.keyIDData);
    563 
    564     if (k1.keyIDData->size() != k2.keyIDData->size())
    565         return k1.keyIDData->size() < k2.keyIDData->size();
    566 
    567     return memcmp(k1.keyIDData->data(), k2.keyIDData->data(), k1.keyIDData->size());
    568 }
    569 
    570540void CDMInstanceSessionClearKey::requestLicense(LicenseType, const AtomString& initDataType, Ref<SharedBuffer>&& initData, LicenseCallback&& callback)
    571541{
     
    603573        };
    604574
     575    // Parse the response buffer as an JSON object.
    605576    RefPtr<JSON::Object> root = parseJSONObject(response);
    606577    if (!root) {
     
    609580    }
    610581
    611     LOG(EME, "EME - ClearKey - updating license for session %s", sessionId.utf8().data());
    612 
     582    // Parse the response using 'license' formatting, if possible.
    613583    if (auto decodedKeys = parseLicenseFormat(*root)) {
    614584        // Retrieve the target Vector of Key objects for this session.
    615         // FIXME: Refactor this state management code.
    616         Vector<CDMInstanceClearKey::Key>& keyVector = ClearKeyState::singleton().keys().ensure(sessionId, [] { return Vector<CDMInstanceClearKey::Key> { }; }).iterator->value;
    617 
     585        auto& keyVector = ClearKeyState::singleton().keys().ensure(sessionId, [] { return Vector<CDMInstanceClearKey::Key> { }; }).iterator->value;
     586
     587        // For each decoded key, find an existing item for the decoded key's ID. If none exist,
     588        // the key is decoded. Otherwise, the key is updated in case there's a mismatch between
     589        // the size or data of the existing and proposed key.
    618590        bool keysChanged = false;
    619         for (auto& decodedKey : *decodedKeys) {
    620             LOG(EME, "EME - ClearKey - Decoded a key with ID %s and key data %s", decodedKey.keyIDAsString().utf8().data(), decodedKey.keyValueAsString().utf8().data());
    621             auto keyWithMatchingKeyID = std::find_if(keyVector.begin(), keyVector.end(),
    622                 [&decodedKey] (const CDMInstanceClearKey::Key& containedKey) {
    623                     return containedKey == decodedKey;
     591        for (auto& key : *decodedKeys) {
     592            auto it = std::find_if(keyVector.begin(), keyVector.end(),
     593                [&key] (const CDMInstanceClearKey::Key& containedKey) {
     594                    return containedKey.keyIDData->size() == key.keyIDData->size()
     595                        && !std::memcmp(containedKey.keyIDData->data(), key.keyIDData->data(), containedKey.keyIDData->size());
    624596                });
    625             if (keyWithMatchingKeyID != keyVector.end()) {
    626                 LOG(EME, "EME - ClearKey - Existing key found with data %s", keyWithMatchingKeyID->keyValueAsString().utf8().data());
    627 
    628                 if (!keyWithMatchingKeyID->hasSameKeyValue(decodedKey)) {
    629                     LOG(EME, "EME - ClearKey - Updating key since the data are different");
    630                     *keyWithMatchingKeyID = WTFMove(decodedKey);
     597            if (it != keyVector.end()) {
     598                auto& existingKey = it->keyValueData;
     599                auto& proposedKey = key.keyValueData;
     600
     601                // Update the existing Key if it differs from the proposed key in key value.
     602                if (existingKey->size() != proposedKey->size() || std::memcmp(existingKey->data(), proposedKey->data(), existingKey->size())) {
     603                    *it = WTFMove(key);
    631604                    keysChanged = true;
    632605                }
    633606            } else {
    634                 LOG(EME, "EME - ClearKey - This is a new key");
    635                 keyVector.append(WTFMove(decodedKey));
     607                // In case a Key for this key ID doesn't exist yet, append the new one to keyVector.
     608                keyVector.append(WTFMove(key));
    636609                keysChanged = true;
    637610            }
    638611        }
    639612
    640         LOG(EME, "EME - ClearKey - Update has provided %zu keys", keyVector.size());
    641 
     613        // In case of changed keys, we have to provide a KeyStatusVector of all the keys for
     614        // this session.
    642615        Optional<KeyStatusVector> changedKeys;
    643616        if (keysChanged) {
    644             // Sort by key IDs.
    645             std::sort(keyVector.begin(), keyVector.end());
    646 
     617            // First a helper Vector is constructed, cotaining pairs of SharedBuffer RefPtrs
     618            // representint key ID data, and the corresponding key statuses.
     619            // We can't use KeyStatusVector here because this Vector has to be sorted, which
     620            // is not possible to do on Ref<> objects.
     621            Vector<std::pair<RefPtr<SharedBuffer>, KeyStatus>> keys;
     622            keys.reserveInitialCapacity(keyVector.size());
     623            for (auto& it : keyVector)
     624                keys.uncheckedAppend(std::pair<RefPtr<SharedBuffer>, KeyStatus> { it.keyIDData, it.status });
     625
     626            // Sort first by size, second by data.
     627            std::sort(keys.begin(), keys.end(),
     628                [] (const auto& a, const auto& b) {
     629                    if (a.first->size() != b.first->size())
     630                        return a.first->size() < b.first->size();
     631
     632                    return std::memcmp(a.first->data(), b.first->data(), a.first->size()) < 0;
     633                });
     634
     635            // Finally construct the mirroring KeyStatusVector object and move it into the
     636            // Optional<> object that will be passed to the callback.
    647637            KeyStatusVector keyStatusVector;
    648             keyStatusVector.reserveInitialCapacity(keyVector.size());
    649             for (auto& key : keyVector)
    650                 keyStatusVector.uncheckedAppend(std::pair<Ref<SharedBuffer>, KeyStatus> { *key.keyIDData, key.status });
     638            keyStatusVector.reserveInitialCapacity(keys.size());
     639            for (auto& it : keys)
     640                keyStatusVector.uncheckedAppend(std::pair<Ref<SharedBuffer>, KeyStatus> { *it.first, it.second });
    651641
    652642            changedKeys = WTFMove(keyStatusVector);
     
    657647    }
    658648
     649    // Parse the response using 'license release acknowledgement' formatting, if possible.
    659650    if (parseLicenseReleaseAcknowledgementFormat(*root)) {
    660651        // FIXME: Retrieve the key ID information and use it to validate the keys for this sessionId.
  • branches/safari-610.1.1-branch/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.h

    r254334 r254537  
    111111        RefPtr<SharedBuffer> keyIDData;
    112112        RefPtr<SharedBuffer> keyValueData;
    113 
    114         String keyIDAsString() const;
    115         String keyValueAsString() const;
    116 
    117         bool hasSameKeyValue(const Key &other)
    118         {
    119             ASSERT(keyValueData);
    120             ASSERT(other.keyValueData);
    121             return *keyValueData == *other.keyValueData;
    122         }
    123 
    124         // Two keys are equal if they have the same ID, ignoring key value and status.
    125         friend bool operator==(const Key &k1, const Key &k2);
    126         // Key's are ordered by their IDs, first by size, then by contents.
    127         friend bool operator<(const Key &k1, const Key &k2);
    128 
    129         friend bool operator!=(const Key &k1, const Key &k2) { return !(operator==(k1, k2)); }
    130         friend bool operator>(const Key &k1, const Key &k2) { return !operator==(k1, k2) && !operator<(k1, k2); }
    131         friend bool operator<=(const Key &k1, const Key &k2) { return !operator>(k1, k2); }
    132         friend bool operator>=(const Key &k1, const Key &k2) { return !operator<(k1, k2); }
    133113    };
    134114
  • branches/safari-610.1.1-branch/Tools/ChangeLog

    r254409 r254537  
     12020-01-14  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Revert r254334. rdar://problem/58542040
     4
    152020-01-11  Alex Christensen  <achristensen@webkit.org>
    26
  • branches/safari-610.1.1-branch/Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp

    r254334 r254537  
    218218}
    219219
    220 TEST_F(SharedBufferTest, toHexString)
    221 {
    222     Vector<char> t1 = {0x11, 0x5, 0x12};
    223     auto buffer = SharedBuffer::create();
    224     buffer->append(WTFMove(t1));
    225     String result = buffer->toHexString();
    226     EXPECT_EQ(result, "110512");
    227     buffer->clear();
    228     EXPECT_EQ(buffer->toHexString(), "");
    229 }
    230 
    231 }
     220}
Note: See TracChangeset for help on using the changeset viewer.