Changeset 254650 in webkit


Ignore:
Timestamp:
Jan 15, 2020 3:25:12 PM (4 years ago)
Author:
Alan Coon
Message:

Revert r254537. 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

    r254570 r254650  
     12020-01-15  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Revert r254537. rdar://problem/58542040
     4
    152020-01-15  Alan Coon  <alancoon@apple.com>
    26
  • branches/safari-610.1.1-branch/Source/WebCore/platform/SharedBuffer.cpp

    r254537 r254650  
    3030
    3131#include <algorithm>
     32#include <wtf/HexNumber.h>
    3233#include <wtf/persistence/PersistentCoders.h>
     34#include <wtf/text/StringBuilder.h>
    3335#include <wtf/unicode/UTF8Conversion.h>
    3436
     
    131133    element--; // std::upper_bound gives a pointer to the element that is greater than position. We want the element just before that.
    132134    return { element->segment.copyRef(), position - element->beginPosition };
     135}
     136
     137String 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();
    133145}
    134146
  • branches/safari-610.1.1-branch/Source/WebCore/platform/SharedBuffer.h

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

    r254537 r254650  
    3535#include "CDMRestrictions.h"
    3636#include "CDMSessionType.h"
     37#include "Logging.h"
    3738#include "SharedBuffer.h"
    3839#include <wtf/JSONValues.h>
     
    538539}
    539540
     541String CDMInstanceClearKey::Key::keyIDAsString() const
     542{
     543    return makeString("[", keyIDData->toHexString(), "]");
     544}
     545
     546String CDMInstanceClearKey::Key::keyValueAsString() const
     547{
     548    return makeString("[", keyValueData->toHexString(), "]");
     549}
     550
     551bool 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
     559bool 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
    540570void CDMInstanceSessionClearKey::requestLicense(LicenseType, const AtomString& initDataType, Ref<SharedBuffer>&& initData, LicenseCallback&& callback)
    541571{
     
    573603        };
    574604
    575     // Parse the response buffer as an JSON object.
    576605    RefPtr<JSON::Object> root = parseJSONObject(response);
    577606    if (!root) {
     
    580609    }
    581610
    582     // Parse the response using 'license' formatting, if possible.
     611    LOG(EME, "EME - ClearKey - updating license for session %s", sessionId.utf8().data());
     612
    583613    if (auto decodedKeys = parseLicenseFormat(*root)) {
    584614        // Retrieve the target Vector of Key objects for this session.
    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.
     615        // FIXME: Refactor this state management code.
     616        Vector<CDMInstanceClearKey::Key>& keyVector = ClearKeyState::singleton().keys().ensure(sessionId, [] { return Vector<CDMInstanceClearKey::Key> { }; }).iterator->value;
     617
    590618        bool keysChanged = false;
    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());
     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;
    596624                });
    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);
     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);
    604631                    keysChanged = true;
    605632                }
    606633            } else {
    607                 // In case a Key for this key ID doesn't exist yet, append the new one to keyVector.
    608                 keyVector.append(WTFMove(key));
     634                LOG(EME, "EME - ClearKey - This is a new key");
     635                keyVector.append(WTFMove(decodedKey));
    609636                keysChanged = true;
    610637            }
    611638        }
    612639
    613         // In case of changed keys, we have to provide a KeyStatusVector of all the keys for
    614         // this session.
     640        LOG(EME, "EME - ClearKey - Update has provided %zu keys", keyVector.size());
     641
    615642        Optional<KeyStatusVector> changedKeys;
    616643        if (keysChanged) {
    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.
     644            // Sort by key IDs.
     645            std::sort(keyVector.begin(), keyVector.end());
     646
    637647            KeyStatusVector keyStatusVector;
    638             keyStatusVector.reserveInitialCapacity(keys.size());
    639             for (auto& it : keys)
    640                 keyStatusVector.uncheckedAppend(std::pair<Ref<SharedBuffer>, KeyStatus> { *it.first, it.second });
     648            keyStatusVector.reserveInitialCapacity(keyVector.size());
     649            for (auto& key : keyVector)
     650                keyStatusVector.uncheckedAppend(std::pair<Ref<SharedBuffer>, KeyStatus> { *key.keyIDData, key.status });
    641651
    642652            changedKeys = WTFMove(keyStatusVector);
     
    647657    }
    648658
    649     // Parse the response using 'license release acknowledgement' formatting, if possible.
    650659    if (parseLicenseReleaseAcknowledgementFormat(*root)) {
    651660        // 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

    r254537 r254650  
    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); }
    113133    };
    114134
  • branches/safari-610.1.1-branch/Tools/ChangeLog

    r254537 r254650  
     12020-01-15  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Revert r254537. rdar://problem/58542040
     4
    152020-01-14  Kocsen Chung  <kocsen_chung@apple.com>
    26
  • branches/safari-610.1.1-branch/Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp

    r254537 r254650  
    218218}
    219219
    220 }
     220TEST_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}
Note: See TracChangeset for help on using the changeset viewer.