Skip to content

Commit

Permalink
Drop SharedBuffer::data() in favor of span()
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=274401

Reviewed by Darin Adler.

* Source/WebCore/Modules/encryptedmedia/InitDataRegistry.cpp:
(WebCore::sanitizeKeyids):
* Source/WebCore/Modules/encryptedmedia/MediaKeyStatusMap.cpp:
(WebCore::keyIdsMatch):
(WebCore::MediaKeyStatusMap::Iterator::next):
* Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp:
(WebCore::FetchBodyConsumer::consumeFormDataAsStream):
* Source/WebCore/bindings/js/WebAssemblyCachedScriptSourceProvider.h:
* Source/WebCore/bindings/js/WebAssemblyScriptBufferSourceProvider.h:
* Source/WebCore/fileapi/FileReaderLoader.cpp:
(WebCore::FileReaderLoader::didReceiveData):
* Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp:
(WebCore::InspectorNetworkAgent::didReceiveData):
* Source/WebCore/loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::dataReceived):
* Source/WebCore/platform/SharedBuffer.cpp:
(WebCore::SharedBufferDataView::createSharedBuffer const):
* Source/WebCore/platform/SharedBuffer.h:
(WebCore::SharedBufferDataView::span const):
(WebCore::SharedBuffer::dataAsCharPtr const): Deleted.
(WebCore::SharedBufferDataView::data const): Deleted.
(WebCore::SharedBufferDataView::dataAsCharPtr const): Deleted.
* Source/WebCore/platform/SharedMemory.h:
(WebCore::SharedMemory::wrapMap):
* Source/WebCore/platform/cocoa/MediaUtilities.cpp:
(WebCore::createAudioFormatDescription):
* Source/WebCore/platform/cocoa/MediaUtilities.h:
(WebCore::createAudioFormatDescription):
* Source/WebCore/platform/cocoa/SharedBufferCocoa.mm:
(-[WebCoreSharedBufferData bytes]):
* Source/WebCore/platform/cocoa/SharedMemoryCocoa.cpp:
(WebCore::SharedMemory::wrapMap):
* Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:
(WebCore::extractKeyidsLocationFromCencInitData):
(WebCore::extractKeyidsFromCencInitData):
(WebCore::extractKeyIdFromWebMInitData):
* Source/WebCore/platform/graphics/ImageBackingStore.h:
(WebCore::ImageBackingStore::setSize):
(WebCore::ImageBackingStore::ImageBackingStore):
* Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm:
(WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::requestLicense):
(WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::didProvideRequests):
* Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp:
(WebCore::ImageDecoderCG::decodeUTI):
* Source/WebCore/platform/graphics/cocoa/CMUtilities.mm:
(WebCore::createAudioFormatDescription):
(WebCore::PacketDurationParser::PacketDurationParser):
* Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.cpp:
(WebCore::WebMParser::VideoTrackData::consumeFrameData):
* Source/WebCore/platform/graphics/opentype/OpenTypeTypes.h:
(WebCore::OpenType::validateTable):
(WebCore::OpenType::TableBase::isValidEnd):
* Source/WebCore/platform/image-decoders/ScalableImageDecoder.cpp:
* Source/WebCore/platform/network/BlobResourceHandle.cpp:
(WebCore::BlobResourceHandle::readDataSync):
* Source/WebCore/workers/ScriptBuffer.cpp:
(WebCore::tryConvertToShareableResourceHandle):
* Source/WebCore/xml/XSLTProcessorLibxslt.cpp:
(WebCore::docLoaderFunc):
* Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp:
(WebKit::RemoteMediaPlayerProxy::mediaPlayerKeyNeeded):
* Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorder.cpp:
(WebKit::RemoteMediaRecorder::fetchData):
* Source/WebKit/NetworkProcess/NetworkDataTaskBlob.cpp:
(WebKit::NetworkDataTaskBlob::readData):
* Source/WebKit/NetworkProcess/storage/BackgroundFetchStoreImpl.cpp:
(WebKit::BackgroundFetchStoreImpl::initializeFetches):
* Source/WebKit/NetworkProcess/storage/CacheStorageDiskStore.cpp:
(WebKit::CacheStorageDiskStore::readRecordFromFileData):
* Source/WebKit/Platform/IPC/SharedBufferReference.cpp:
(IPC::SharedBufferReference::data const):
* Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp:
(API::getData):
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::loadAlternateHTML):
* Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.mm:
(WebKit::PDFPluginBase::streamDidReceiveData):
* Source/WebKit/WebProcess/WebCoreSupport/WebLocalFrameLoaderClient.cpp:
(WebKit::WebLocalFrameLoaderClient::finishedLoading):

Canonical link: https://commits.webkit.org/279097@main
  • Loading branch information
cdumez committed May 22, 2024
1 parent 339bcec commit 24db6e6
Show file tree
Hide file tree
Showing 61 changed files with 180 additions and 162 deletions.
4 changes: 2 additions & 2 deletions Source/WebCore/Modules/encryptedmedia/InitDataRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static RefPtr<SharedBuffer> sanitizeKeyids(const SharedBuffer& buffer)
auto object = JSON::Object::create();
auto kidsArray = JSON::Array::create();
for (auto& buffer : keyIDBuffer.value())
kidsArray->pushString(base64URLEncodeToString(buffer->data(), buffer->size()));
kidsArray->pushString(base64URLEncodeToString(buffer->span()));
object->setArray("kids"_s, WTFMove(kidsArray));

return SharedBuffer::create(object->toJSONString().utf8().span());
Expand Down Expand Up @@ -194,7 +194,7 @@ std::optional<Vector<Ref<SharedBuffer>>> InitDataRegistry::extractKeyIDsCenc(con
#if USE(GSTREAMER)
bool isPlayReadySanitizedInitializationData(const SharedBuffer& buffer)
{
const char* protectionData = buffer.dataAsCharPtr();
auto* protectionData = reinterpret_cast<const char*>(buffer.span().data());
size_t protectionDataLength = buffer.size();

// The protection data starts with a 10-byte PlayReady version
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/Modules/encryptedmedia/MediaKeyStatusMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "JSMediaKeyStatusMap.h"
#include "MediaKeySession.h"
#include "SharedBuffer.h"
#include <wtf/StdLibExtras.h>

namespace WebCore {

Expand All @@ -58,10 +59,9 @@ unsigned long MediaKeyStatusMap::size()

static bool keyIdsMatch(const SharedBuffer& a, const BufferSource& b)
{
auto length = a.size();
if (!length || length != b.length())
if (a.isEmpty())
return false;
return !std::memcmp(a.data(), b.data(), length);
return equalSpans(a.span(), b.span());
}

bool MediaKeyStatusMap::has(const BufferSource& keyId)
Expand Down Expand Up @@ -103,7 +103,7 @@ std::optional<KeyValuePair<BufferSource::VariantType, MediaKeyStatus>> MediaKeyS
return std::nullopt;

auto& pair = statuses[m_index++];
auto buffer = ArrayBuffer::create(pair.first->makeContiguous()->data(), pair.first->size());
auto buffer = ArrayBuffer::create(pair.first->makeContiguous()->span());
return KeyValuePair<BufferSource::VariantType, MediaKeyStatus> { RefPtr<ArrayBuffer>(WTFMove(buffer)), pair.second };
}

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ void FetchBodyConsumer::resolveWithFormData(Ref<DeferredPromise>&& promise, cons
void FetchBodyConsumer::consumeFormDataAsStream(const FormData& formData, FetchBodySource& source, ScriptExecutionContext* context)
{
if (auto sharedBuffer = formData.asSharedBuffer()) {
if (source.enqueue(ArrayBuffer::tryCreate(sharedBuffer->makeContiguous()->data(), sharedBuffer->size())))
if (source.enqueue(ArrayBuffer::tryCreate(sharedBuffer->makeContiguous()->span())))
source.close();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class WebAssemblyCachedScriptSourceProvider final : public JSC::BaseWebAssemblyS
if (!m_buffer->isContiguous())
m_buffer = m_buffer->makeContiguous();

return downcast<SharedBuffer>(*m_buffer).data();
return downcast<SharedBuffer>(*m_buffer).span().data();
}

void lockUnderlyingBuffer() final
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class WebAssemblyScriptBufferSourceProvider final : public JSC::BaseWebAssemblyS
return nullptr;

ASSERT(m_buffer->isContiguous());
return downcast<SharedBuffer>(*m_buffer).data();
return downcast<SharedBuffer>(*m_buffer).span().data();
}

void lockUnderlyingBuffer() final
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/fileapi/FileReaderLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ void FileReaderLoader::didReceiveData(const SharedBuffer& buffer)
if (length <= 0)
return;

memcpy(static_cast<char*>(m_rawData->data()) + m_bytesLoaded, buffer.data(), length);
memcpy(static_cast<char*>(m_rawData->data()) + m_bytesLoaded, buffer.span().data(), length);
m_bytesLoaded += length;

m_isRawDataConverted = false;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ void InspectorNetworkAgent::didReceiveData(ResourceLoaderIdentifier identifier,
// Often the data is text and we would have a decoder, but for non-text we won't have a decoder.
// Sync XHRs may not have a cached resource, while non-sync XHRs usually transfer data over on completion.
if (m_loadingXHRSynchronously && resourceData && !resourceData->hasBufferedData() && !resourceData->cachedResource())
m_resourcesData->setResourceContent(requestId, base64EncodeToString(data->data(), data->size()), true);
m_resourcesData->setResourceContent(requestId, base64EncodeToString(data->span()), true);
}

m_frontendDispatcher->dataReceived(requestId, timestamp(), expectedDataLength, encodedDataLength);
Expand Down
3 changes: 1 addition & 2 deletions Source/WebCore/loader/DocumentLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1375,8 +1375,7 @@ void DocumentLoader::dataReceived(const SharedBuffer& buffer)
return;
#endif

ASSERT(buffer.data());
ASSERT(buffer.size());
ASSERT(!buffer.span().empty());
ASSERT(!m_response.isNull());

// There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred.
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/loader/archive/mhtml/MHTMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ RefPtr<ArchiveResource> MHTMLParser::parseNextPart(const MIMEHeader& mimeHeader,
auto contiguousContent = content.takeAsContiguous();
switch (mimeHeader.contentTransferEncoding()) {
case MIMEHeader::Base64: {
auto decodedData = base64Decode(contiguousContent->data(), contiguousContent->size());
auto decodedData = base64Decode(contiguousContent->span());
if (!decodedData) {
LOG_ERROR("Invalid base64 content for MHTML part.");
return nullptr;
Expand Down
3 changes: 1 addition & 2 deletions Source/WebCore/platform/SharedBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,8 @@ SharedBufferDataView::SharedBufferDataView(const SharedBufferDataView& other, si

Ref<SharedBuffer> SharedBufferDataView::createSharedBuffer() const
{
const Ref<const DataSegment> segment = m_segment;
return SharedBuffer::create(DataSegment::Provider {
[segment, data = data()]() { return data; },
[segment = m_segment, data = span().data()]() { return data; },
[size = size()]() { return size; }
});
}
Expand Down
10 changes: 4 additions & 6 deletions Source/WebCore/platform/SharedBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class SharedMemoryHandle;
// To modify or combine the data, allocate a new DataSegment.
class DataSegment : public ThreadSafeRefCounted<DataSegment> {
public:
WEBCORE_EXPORT const uint8_t* data() const;
WEBCORE_EXPORT size_t size() const;
std::span<const uint8_t> span() const { return std::span { data(), size() }; }

Expand Down Expand Up @@ -116,6 +115,8 @@ class DataSegment : public ThreadSafeRefCounted<DataSegment> {
void iterate(CFDataRef, const Function<void(std::span<const uint8_t>)>& apply) const;
#endif

WEBCORE_EXPORT const uint8_t* data() const;

explicit DataSegment(Vector<uint8_t>&& data)
: m_immutableData(WTFMove(data)) { }
#if USE(CF)
Expand Down Expand Up @@ -306,9 +307,7 @@ class SharedBuffer : public FragmentedSharedBuffer {

WEBCORE_EXPORT static Ref<SharedBuffer> create(Ref<FragmentedSharedBuffer>&&);

WEBCORE_EXPORT const uint8_t* data() const;
WEBCORE_EXPORT const uint8_t& operator[](size_t) const;
const char* dataAsCharPtr() const { return reinterpret_cast<const char*>(data()); }
std::span<const uint8_t> span() const { return std::span(data(), size()); }
WTF::Persistence::Decoder decoder() const;

Expand Down Expand Up @@ -339,6 +338,7 @@ class SharedBuffer : public FragmentedSharedBuffer {
WEBCORE_EXPORT explicit SharedBuffer(Ref<FragmentedSharedBuffer>&&);

WEBCORE_EXPORT static RefPtr<SharedBuffer> createFromReadingFile(const String& filePath);
WEBCORE_EXPORT const uint8_t* data() const;
};

class SharedBufferBuilder {
Expand Down Expand Up @@ -410,9 +410,7 @@ class SharedBufferDataView {
WEBCORE_EXPORT SharedBufferDataView(Ref<const DataSegment>&&, size_t positionWithinSegment, std::optional<size_t> newSize = std::nullopt);
WEBCORE_EXPORT SharedBufferDataView(const SharedBufferDataView&, size_t newSize);
size_t size() const { return m_size; }
const uint8_t* data() const { return m_segment->data() + m_positionWithinSegment; }
const char* dataAsCharPtr() const { return reinterpret_cast<const char*>(data()); }
std::span<const uint8_t> span() const { return { data(), size() }; }
std::span<const uint8_t> span() const { return { m_segment->span().subspan(m_positionWithinSegment, size()) }; }

WEBCORE_EXPORT Ref<SharedBuffer> createSharedBuffer() const;
#if USE(FOUNDATION)
Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/platform/SharedBufferChunkReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ namespace WebCore {
SharedBufferChunkReader::SharedBufferChunkReader(FragmentedSharedBuffer* buffer, const Vector<char>& separator)
: m_iteratorCurrent(buffer->begin())
, m_iteratorEnd(buffer->end())
, m_segment(m_iteratorCurrent != m_iteratorEnd ? m_iteratorCurrent->segment->data() : nullptr)
, m_segment(m_iteratorCurrent != m_iteratorEnd ? m_iteratorCurrent->segment->span().data() : nullptr)
, m_separator(separator)
{
}

SharedBufferChunkReader::SharedBufferChunkReader(FragmentedSharedBuffer* buffer, const char* separator)
: m_iteratorCurrent(buffer->begin())
, m_iteratorEnd(buffer->end())
, m_segment(m_iteratorCurrent != m_iteratorEnd ? m_iteratorCurrent->segment->data() : nullptr)
, m_segment(m_iteratorCurrent != m_iteratorEnd ? m_iteratorCurrent->segment->span().data() : nullptr)
{
setSeparator(separator);
}
Expand Down Expand Up @@ -99,7 +99,7 @@ bool SharedBufferChunkReader::nextChunk(Vector<uint8_t>& chunk, bool includeSepa
chunk.append(std::span { reinterpret_cast<const uint8_t*>(m_separator.data()), m_separatorIndex });
return !chunk.isEmpty();
}
m_segment = m_iteratorCurrent->segment->data();
m_segment = m_iteratorCurrent->segment->span().data();
}

ASSERT_NOT_REACHED();
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/SharedMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class SharedMemory : public ThreadSafeRefCounted<SharedMemory> {
#if USE(UNIX_DOMAIN_SOCKETS)
WEBCORE_EXPORT static RefPtr<SharedMemory> wrapMap(void*, size_t, int fileDescriptor);
#elif OS(DARWIN)
WEBCORE_EXPORT static RefPtr<SharedMemory> wrapMap(void*, size_t, Protection);
WEBCORE_EXPORT static RefPtr<SharedMemory> wrapMap(std::span<const uint8_t>, Protection);
#endif

WEBCORE_EXPORT ~SharedMemory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ RefPtr<PlatformRawAudioData> PlatformRawAudioData::create(std::span<const uint8_
GST_TRACE("Creating raw audio wrapper with caps %" GST_PTR_FORMAT, caps.get());

Ref data = SharedBuffer::create(Vector<uint8_t>(sourceData));
gpointer bufferData = const_cast<void*>(static_cast<const void*>(data->data()));
gpointer bufferData = const_cast<void*>(static_cast<const void*>(data->span().data()));
auto bufferLength = data->size();
auto buffer = adoptGRef(gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY, bufferData, bufferLength, 0, bufferLength, reinterpret_cast<gpointer>(&data.leakRef()), [](gpointer data) {
static_cast<SharedBuffer*>(data)->deref();
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/platform/cocoa/MediaUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@

namespace WebCore {

RetainPtr<CMFormatDescriptionRef> createAudioFormatDescription(const AudioStreamDescription& description, size_t magicCookieSize, const void* magicCookie)
RetainPtr<CMFormatDescriptionRef> createAudioFormatDescription(const AudioStreamDescription& description, std::span<const uint8_t> magicCookie)
{
auto basicDescription = std::get<const AudioStreamBasicDescription*>(description.platformDescription().description);
CMFormatDescriptionRef format = nullptr;
auto error = PAL::CMAudioFormatDescriptionCreate(kCFAllocatorDefault, basicDescription, 0, nullptr, magicCookieSize, magicCookie, nullptr, &format);
auto error = PAL::CMAudioFormatDescriptionCreate(kCFAllocatorDefault, basicDescription, 0, nullptr, magicCookie.size(), magicCookie.data(), nullptr, &format);
if (error) {
LOG_ERROR("createAudioFormatDescription failed with %d", static_cast<int>(error));
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/cocoa/MediaUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace WebCore {
class AudioStreamDescription;
class PlatformAudioData;

RetainPtr<CMFormatDescriptionRef> createAudioFormatDescription(const AudioStreamDescription&, size_t magicCookieSize = 0, const void* magicCookie = nullptr);
RetainPtr<CMFormatDescriptionRef> createAudioFormatDescription(const AudioStreamDescription&, std::span<const uint8_t> magicCookie = { });
RetainPtr<CMSampleBufferRef> createAudioSampleBuffer(const PlatformAudioData&, const AudioStreamDescription&, CMTime, size_t sampleCount);
RetainPtr<CMSampleBufferRef> createVideoSampleBuffer(CVPixelBufferRef, CMTime);

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/cocoa/SharedBufferCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ - (NSUInteger)length

- (const void *)bytes
{
return _dataSegment->data() + _position;
return _dataSegment->span().subspan(_position).data();
}

@end
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/platform/cocoa/SharedMemoryCocoa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,16 @@ static MachSendRight makeMemoryEntry(size_t size, vm_offset_t offset, SharedMemo
return MachSendRight::adopt(port);
}

RefPtr<SharedMemory> SharedMemory::wrapMap(void* data, size_t size, Protection protection)
RefPtr<SharedMemory> SharedMemory::wrapMap(std::span<const uint8_t> data, Protection protection)
{
ASSERT(size);
ASSERT(!data.empty());

auto sendRight = makeMemoryEntry(size, toVMAddress(data), protection, MACH_PORT_NULL);
auto sendRight = makeMemoryEntry(data.size(), toVMAddress(static_cast<void*>(const_cast<uint8_t*>(data.data()))), protection, MACH_PORT_NULL);
if (!sendRight)
return nullptr;

Ref sharedMemory = adoptRef(*new SharedMemory);
sharedMemory->m_size = size;
sharedMemory->m_size = data.size();
sharedMemory->m_data = nullptr;
sharedMemory->m_sendRight = WTFMove(sendRight);
sharedMemory->m_protection = protection;
Expand Down
11 changes: 5 additions & 6 deletions Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ static std::pair<unsigned, unsigned> extractKeyidsLocationFromCencInitData(const
if (initData.isEmpty() || initData.size() > std::numeric_limits<unsigned>::max())
return keyIdsMap;

auto* data = initData.data();
unsigned initDataSize = initData.size();
auto data = initData.span();
unsigned initDataSize = data.size();
unsigned index = 0;
unsigned psshSize = 0;

Expand Down Expand Up @@ -203,7 +203,7 @@ static Ref<SharedBuffer> extractKeyidsFromCencInitData(const SharedBuffer& initD
// Check if initData is a valid CENC initData.
if (!keyIdCount || !index)
return SharedBuffer::create();
auto* data = initData.data();
auto data = initData.span();

auto object = JSON::Object::create();
auto keyIdsArray = JSON::Array::create();
Expand All @@ -220,8 +220,7 @@ static Ref<SharedBuffer> extractKeyidsFromCencInitData(const SharedBuffer& initD
}

object->setArray("kids"_s, WTFMove(keyIdsArray));
CString jsonData = object->toJSONString().utf8();
return SharedBuffer::create(jsonData.span());
return SharedBuffer::create(object->toJSONString().utf8().span());
}

static Ref<SharedBuffer> extractKeyIdFromWebMInitData(const SharedBuffer& initData)
Expand All @@ -239,7 +238,7 @@ static Ref<SharedBuffer> extractKeyIdFromWebMInitData(const SharedBuffer& initDa
// The format is a JSON object containing the following members:
// "kids"
// An array of key IDs. Each element of the array is the base64url encoding of the octet sequence containing the key ID value.
keyIdsArray->pushString(base64URLEncodeToString(initData.data(), initData.size()));
keyIdsArray->pushString(base64URLEncodeToString(initData.span()));

object->setArray("kids"_s, WTFMove(keyIdsArray));
return SharedBuffer::create(object->toJSONString().utf8().span());
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/platform/graphics/ImageBackingStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ImageBackingStore {

buffer.grow(bufferSize);
m_pixels = FragmentedSharedBuffer::DataSegment::create(WTFMove(buffer));
m_pixelsPtr = reinterpret_cast<uint32_t*>(const_cast<uint8_t*>(m_pixels->data()));
m_pixelsPtr = reinterpret_cast<uint32_t*>(const_cast<uint8_t*>(m_pixels->span().data()));
m_size = size;
m_frameRect = IntRect(IntPoint(), m_size);
clear();
Expand Down Expand Up @@ -207,7 +207,7 @@ class ImageBackingStore {
ASSERT(!m_size.isEmpty() && !isOverSize(m_size));
Vector<uint8_t> buffer(other.m_pixels->span());
m_pixels = FragmentedSharedBuffer::DataSegment::create(WTFMove(buffer));
m_pixelsPtr = reinterpret_cast<uint32_t*>(const_cast<uint8_t*>(m_pixels->data()));
m_pixelsPtr = reinterpret_cast<uint32_t*>(const_cast<uint8_t*>(m_pixels->span().data()));
}

bool inBounds(const IntPoint& point) const
Expand Down
13 changes: 6 additions & 7 deletions Source/WebCore/platform/graphics/WOFFFileFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static bool readUInt32(SharedBuffer& buffer, size_t& offset, uint32_t& value)
if (buffer.size() - offset < sizeof(value))
return false;

value = ntohl(*reinterpret_cast_ptr<const uint32_t*>(buffer.data() + offset));
value = ntohl(*reinterpret_cast_ptr<const uint32_t*>(buffer.span().subspan(offset).data()));
offset += sizeof(value);

return true;
Expand All @@ -59,7 +59,7 @@ static bool readUInt16(SharedBuffer& buffer, size_t& offset, uint16_t& value)
if (buffer.size() - offset < sizeof(value))
return false;

value = ntohs(*reinterpret_cast_ptr<const uint16_t*>(buffer.data() + offset));
value = ntohs(*reinterpret_cast_ptr<const uint16_t*>(buffer.span().subspan(offset).data()));
offset += sizeof(value);

return true;
Expand Down Expand Up @@ -145,15 +145,14 @@ bool convertWOFFToSfnt(SharedBuffer& woff, Vector<uint8_t>& sfnt)

#if USE(WOFF2)
if (signature == kWoff2Signature) {
auto* woffData = woff.data();
const size_t woffSize = woff.size();
const size_t sfntSize = woff2::ComputeWOFF2FinalSize(woffData, woffSize);
auto woffData = woff.span();
const size_t sfntSize = woff2::ComputeWOFF2FinalSize(woffData.data(), woffData.size());

if (!sfnt.tryReserveCapacity(sfntSize))
return false;

WOFF2VectorOut out(sfnt);
return woff2::ConvertWOFF2ToTTF(woffData, woffSize, &out);
return woff2::ConvertWOFF2ToTTF(woffData.data(), woffData.size(), &out);
}
#endif

Expand Down Expand Up @@ -273,7 +272,7 @@ bool convertWOFFToSfnt(SharedBuffer& woff, Vector<uint8_t>& sfnt)
return false;
Bytef* dest = reinterpret_cast<Bytef*>(sfnt.end());
sfnt.grow(sfnt.size() + tableOrigLength);
if (uncompress(dest, &destLen, reinterpret_cast<const Bytef*>(woff.data() + tableOffset), tableCompLength) != Z_OK)
if (uncompress(dest, &destLen, reinterpret_cast<const Bytef*>(woff.span().subspan(tableOffset).data()), tableCompLength) != Z_OK)
return false;
if (destLen != tableOrigLength)
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ static Keys keyIDsForRequest(const Request& requests)
identifier = adoptNS([[NSString alloc] initWithData:initData->makeContiguous()->createNSData().get() encoding:NSUTF8StringEncoding]);
#if HAVE(FAIRPLAYSTREAMING_CENC_INITDATA)
else if (initDataType == InitDataRegistry::cencName()) {
auto psshString = base64EncodeToString(initData->makeContiguous()->data(), initData->size());
auto psshString = base64EncodeToString(initData->makeContiguous()->span());
initializationData = [NSJSONSerialization dataWithJSONObject:@{ @"pssh": (NSString*)psshString } options:NSJSONWritingPrettyPrinted error:nil];
}
#endif
Expand Down Expand Up @@ -1289,8 +1289,8 @@ explicit CallbackAggregator(Function<void(RequestsData&&)>&& completionHandler)
auto entry = JSON::Object::create();
auto& keyID = requestData.first;
auto& payload = requestData.second;
entry->setString("keyID"_s, base64EncodeToString(keyID->makeContiguous()->data(), keyID->size()));
entry->setString("payload"_s, base64EncodeToString(payload.get().bytes, payload.get().length));
entry->setString("keyID"_s, base64EncodeToString(keyID->makeContiguous()->span()));
entry->setString("payload"_s, base64EncodeToString(span(payload.get())));
requestJSON->pushObject(WTFMove(entry));
}
auto requestBuffer = utf8Buffer(requestJSON->toJSONString());
Expand Down
Loading

0 comments on commit 24db6e6

Please sign in to comment.