Skip to content

Commit

Permalink
Use Vector<uint8_t> instead of Vector<char> to store bytes in SharedB…
Browse files Browse the repository at this point in the history
…uffer

https://bugs.webkit.org/show_bug.cgi?id=226623

Reviewed by Darin Adler.

Use Vector<uint8_t> instead of Vector<char> to store bytes in SharedBuffer. Also have SharedBuffer::data()
return a `const uint8_t*` instead of `const char*`. This is our preferred type to store bytes.

Source/WebCore:

* Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::consumeFormData):
* Modules/fetch/FetchBodyConsumer.cpp:
(WebCore::packageFormData):
(WebCore::resolveWithTypeAndData):
* Modules/highlight/AppHighlight.h:
(WebCore::AppHighlight::encode const):
* Modules/indexeddb/IDBGetResult.cpp:
(WebCore::IDBGetResult::dataFromBuffer):
* Modules/indexeddb/server/IDBSerialization.cpp:
(WebCore::serializeIDBKeyData):
* Modules/mediastream/RTCDataChannel.cpp:
(WebCore::RTCDataChannel::didReceiveRawData):
* Modules/mediastream/RTCDataChannel.h:
* Modules/mediastream/RTCDataChannelRemoteHandler.cpp:
(WebCore::RTCDataChannelRemoteHandler::didReceiveRawData):
(WebCore::RTCDataChannelRemoteHandler::sendRawData):
* Modules/mediastream/RTCDataChannelRemoteHandler.h:
* Modules/mediastream/RTCDataChannelRemoteSource.h:
(WebCore::RTCDataChannelRemoteSource::sendRawData):
* Modules/mediastream/libwebrtc/LibWebRTCDataChannelHandler.cpp:
(WebCore::LibWebRTCDataChannelHandler::sendRawData):
(WebCore::LibWebRTCDataChannelHandler::OnMessage):
* Modules/mediastream/libwebrtc/LibWebRTCDataChannelHandler.h:
* css/CSSFontFaceSource.cpp:
(WebCore::CSSFontFaceSource::load):
* fileapi/Blob.cpp:
(WebCore::Blob::Blob):
* fileapi/NetworkSendQueue.cpp:
(WebCore::NetworkSendQueue::enqueue):
(WebCore::NetworkSendQueue::processMessages):
* fileapi/NetworkSendQueue.h:
* inspector/NetworkResourcesData.cpp:
(WebCore::NetworkResourcesData::ResourceData::appendData):
(WebCore::NetworkResourcesData::maybeAddResourceData):
* inspector/NetworkResourcesData.h:
* inspector/agents/InspectorNetworkAgent.cpp:
(WebCore::InspectorNetworkAgent::didReceiveData):
* inspector/agents/InspectorPageAgent.cpp:
(WebCore::decodeBuffer):
(WebCore::InspectorPageAgent::dataContent):
* inspector/agents/InspectorPageAgent.h:
* loader/ContentFilter.cpp:
(WebCore::ContentFilter::deliverResourceData):
* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::continueAfterContentPolicy):
(WebCore::DocumentLoader::maybeCreateArchive):
(WebCore::DocumentLoader::maybeFinishLoadingMultipartContent):
* loader/DocumentThreadableLoader.cpp:
(WebCore::DocumentThreadableLoader::didFinishLoading):
(WebCore::DocumentThreadableLoader::loadRequest):
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::loadResourceSynchronously):
* loader/NetscapePlugInStreamLoader.cpp:
(WebCore::NetscapePlugInStreamLoader::didReceiveDataOrBuffer):
* loader/NetscapePlugInStreamLoader.h:
* loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::didReceiveDataOrBuffer):
* loader/SubresourceLoader.cpp:
(WebCore::SubresourceLoader::didReceiveDataOrBuffer):
* loader/TextResourceDecoder.h:
(WebCore::TextResourceDecoder::decode):
(WebCore::TextResourceDecoder::decodeAndFlush):
* loader/TextTrackLoader.cpp:
(WebCore::TextTrackLoader::processNewCueData):
* loader/appcache/ApplicationCacheGroup.cpp:
(WebCore::ApplicationCacheGroup::didFinishLoadingManifest):
* loader/appcache/ApplicationCacheStorage.cpp:
(WebCore::ApplicationCacheStorage::writeDataToUniqueFileInDirectory):
* loader/archive/mhtml/MHTMLArchive.cpp:
(WebCore::MHTMLArchive::generateMHTMLData):
* loader/archive/mhtml/MHTMLParser.cpp:
(WebCore::MHTMLParser::parseNextPart):
* loader/cache/CachedRawResource.cpp:
(WebCore::CachedRawResource::updateBuffer):
(WebCore::CachedRawResource::finishLoading):
(WebCore::CachedRawResource::didAddClient):
* loader/cache/CachedSVGFont.cpp:
(WebCore::CachedSVGFont::ensureCustomFontData):
* platform/SharedBuffer.cpp:
(WebCore::SharedBuffer::SharedBuffer):
(WebCore::SharedBuffer::create):
(WebCore::SharedBuffer::combineIntoOneSegment const):
(WebCore::SharedBuffer::data const):
(WebCore::SharedBuffer::tryCreateArrayBuffer const):
(WebCore::SharedBuffer::append):
(WebCore::SharedBuffer::DataSegment::data const):
(WebCore::SharedBuffer::DataSegment::size const):
(WebCore::SharedBufferDataView::data const):
(WebCore::utf8Buffer):
* platform/SharedBuffer.h:
* platform/encryptedmedia/clearkey/CDMClearKey.cpp:
(WebCore::extractKeyidsLocationFromCencInitData):
(WebCore::extractKeyidsFromCencInitData):
* platform/graphics/Model.h:
(WebCore::Model::encode const):
* platform/graphics/displaylists/DisplayListItemBuffer.cpp:
(WebCore::DisplayList::ItemBuffer::append):
* platform/graphics/gstreamer/eme/CDMThunder.cpp:
(WebCore::CDMInstanceThunder::setServerCertificate):
(WebCore::ParsedResponseMessage::ParsedResponseMessage):
(WebCore::CDMInstanceSessionThunder::errorCallback):
(WebCore::CDMInstanceSessionThunder::requestLicense):
(WebCore::CDMInstanceSessionThunder::updateLicense):
(WebCore::CDMInstanceSessionThunder::loadSession):
* platform/graphics/opentype/OpenTypeTypes.h:
(WebCore::OpenType::TableBase::isValidEnd):
* platform/mediastream/RTCDataChannelHandler.h:
* platform/mediastream/RTCDataChannelHandlerClient.h:
* platform/mediastream/RTCDataChannelRemoteSourceConnection.h:
* platform/mock/RTCDataChannelHandlerMock.cpp:
(WebCore::RTCDataChannelHandlerMock::sendRawData):
* platform/mock/RTCDataChannelHandlerMock.h:
* platform/network/FormData.cpp:
(WebCore::FormData::asSharedBuffer const):
* platform/network/ResourceHandleClient.cpp:
(WebCore::ResourceHandleClient::didReceiveBuffer):
* platform/network/cocoa/RangeResponseGenerator.mm:
(WebCore::RangeResponseGenerator::giveResponseToTaskIfBytesInRangeReceived):
* platform/text/TextEncoding.h:
(WebCore::TextEncoding::decode const):
* svg/graphics/SVGImage.cpp:
(WebCore::SVGImage::dataChanged):
* xml/XSLTProcessorLibxslt.cpp:
(WebCore::docLoaderFunc):
* xml/parser/XMLDocumentParserLibxml2.cpp:
(WebCore::OffsetBuffer::OffsetBuffer):

Source/WebKit:

* Platform/IPC/SharedBufferCopy.h:
(IPC::SharedBufferCopy::data const):
* PluginProcess/PluginControllerProxy.cpp:
(WebKit::PluginControllerProxy::streamDidReceiveData):
(WebKit::PluginControllerProxy::manualStreamDidReceiveData):
* Shared/PersistencyUtils.cpp:
(WebKit::writeToDisk):
* Shared/WebCoreArgumentCoders.cpp:
(IPC::tryConvertToShareableResourceHandle):
* UIProcess/WebURLSchemeTask.cpp:
(WebKit::WebURLSchemeTask::didComplete):
* WebProcess/Network/WebResourceLoader.cpp:
(WebKit::WebResourceLoader::didReceiveData):
* WebProcess/Network/WebSocketChannel.cpp:
(WebKit::WebSocketChannel::createMessageQueue):
* WebProcess/Network/webrtc/RTCDataChannelRemoteManager.cpp:
(WebKit::RTCDataChannelRemoteManager::sendData):
(WebKit::RTCDataChannelRemoteManager::receiveData):
(WebKit::RTCDataChannelRemoteManager::RemoteSourceConnection::didReceiveRawData):
* WebProcess/Network/webrtc/RTCDataChannelRemoteManager.h:
* WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp:
(WebKit::parsePostBuffer):
* WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
(WebKit::NetscapePlugin::streamDidReceiveData):
(WebKit::NetscapePlugin::manualStreamDidReceiveData):
* WebProcess/Plugins/Netscape/NetscapePlugin.h:
* WebProcess/Plugins/Netscape/NetscapePluginStream.cpp:
(WebKit::NetscapePluginStream::didReceiveData):
(WebKit::NetscapePluginStream::sendJavaScriptStream):
(WebKit::NetscapePluginStream::deliverData):
(WebKit::NetscapePluginStream::deliverDataToFile):
* WebProcess/Plugins/Netscape/NetscapePluginStream.h:
* WebProcess/Plugins/PDF/PDFPlugin.h:
* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::PDFPluginStreamLoaderClient::didReceiveData):
(WebKit::PDFPlugin::streamDidReceiveData):
(WebKit::PDFPlugin::manualStreamDidReceiveData):
* WebProcess/Plugins/Plugin.h:
* WebProcess/Plugins/PluginProxy.cpp:
(WebKit::PluginProxy::streamDidReceiveData):
(WebKit::PluginProxy::manualStreamDidReceiveData):
* WebProcess/Plugins/PluginProxy.h:
* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::Stream::didReceiveData):
(WebKit::PluginView::manualLoadDidReceiveData):
* WebProcess/Plugins/PluginView.h:
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::committedLoad):
* WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
(WebKit::WebPlatformStrategies::bufferForType):

Source/WebKitLegacy/mac:

* Plugins/Hosted/HostedNetscapePluginStream.h:
* Plugins/Hosted/HostedNetscapePluginStream.mm:
(WebKit::HostedNetscapePluginStream::didReceiveData):
* Plugins/Hosted/NetscapePluginInstanceProxy.mm:
(WebKit::NetscapePluginInstanceProxy::evaluateJavaScript):
* Plugins/Hosted/WebHostedNetscapePluginView.mm:
(-[WebHostedNetscapePluginView pluginView:receivedData:]):
* Plugins/WebNetscapePluginStream.h:
* Plugins/WebNetscapePluginStream.mm:
(WebNetscapePluginStream::didReceiveData):
* Plugins/WebNetscapePluginView.mm:
(-[WebNetscapePluginView pluginView:receivedData:]):
(-[WebNetscapePluginView evaluateJavaScriptPluginRequest:]):

Tools:

* TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp:
(TestWebKitAPI::TEST_F):
(TestWebKitAPI::checkBuffer):


Canonical link: https://commits.webkit.org/238515@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278516 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed Jun 5, 2021
1 parent c49f48d commit 3194bf4
Show file tree
Hide file tree
Showing 214 changed files with 667 additions and 455 deletions.
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/API/JSScript.mm
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ - (BOOL)writeCache:(String&)error
SHA1 sha1;
sha1.addBytes(m_cachedBytecode->data(), m_cachedBytecode->size());
sha1.computeHash(computedHash);
FileSystem::writeToFile(tempFD, reinterpret_cast<const char*>(&computedHash), sizeof(computedHash));
FileSystem::writeToFile(tempFD, computedHash.data(), sizeof(computedHash));

fsync(tempFD);
rename(tempFileName, cacheFileName);
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/jsc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ class ShellSourceProvider final : public StringSourceProvider {
m_cachedBytecode->commitUpdates([&] (off_t offset, const void* data, size_t size) {
long long result = FileSystem::seekFile(fd, offset, FileSystem::FileSeekOrigin::Beginning);
ASSERT_UNUSED(result, result != -1);
size_t bytesWritten = static_cast<size_t>(FileSystem::writeToFile(fd, static_cast<const char*>(data), size));
size_t bytesWritten = static_cast<size_t>(FileSystem::writeToFile(fd, data, size));
ASSERT_UNUSED(bytesWritten, bytesWritten == size);
});
}
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/runtime/CachedTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class Encoder {
}

for (const auto& page : m_pages) {
int bytesWritten = FileSystem::writeToFile(m_fd, reinterpret_cast<char*>(page.buffer()), page.size());
int bytesWritten = FileSystem::writeToFile(m_fd, page.buffer(), page.size());
if (bytesWritten == -1) {
error = BytecodeCacheError::StandardError(errno);
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion Source/WTF/wtf/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ std::optional<Salt> readOrMakeSalt(const String& path)
if (!FileSystem::isHandleValid(file))
return { };

bool success = static_cast<std::size_t>(FileSystem::writeToFile(file, reinterpret_cast<char*>(salt.data()), salt.size())) == salt.size();
bool success = static_cast<std::size_t>(FileSystem::writeToFile(file, salt.data(), salt.size())) == salt.size();
FileSystem::closeFile(file);
if (!success)
return { };
Expand Down
4 changes: 2 additions & 2 deletions Source/WTF/wtf/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ WTF_EXPORT_PRIVATE void closeFile(PlatformFileHandle&);
WTF_EXPORT_PRIVATE long long seekFile(PlatformFileHandle, long long offset, FileSeekOrigin);
WTF_EXPORT_PRIVATE bool truncateFile(PlatformFileHandle, long long offset);
// Returns number of bytes actually read if successful, -1 otherwise.
WTF_EXPORT_PRIVATE int writeToFile(PlatformFileHandle, const char* data, int length);
WTF_EXPORT_PRIVATE int writeToFile(PlatformFileHandle, const void* data, int length);
// Returns number of bytes actually written if successful, -1 otherwise.
WTF_EXPORT_PRIVATE int readFromFile(PlatformFileHandle, char* data, int length);
WTF_EXPORT_PRIVATE int readFromFile(PlatformFileHandle, char* data, int length); // FIXME: Should use `void*`.

WTF_EXPORT_PRIVATE PlatformFileHandle openAndLockFile(const String&, FileOpenMode, OptionSet<FileLockMode> = FileLockMode::Exclusive);
WTF_EXPORT_PRIVATE void unlockAndCloseFile(PlatformFileHandle);
Expand Down
2 changes: 1 addition & 1 deletion Source/WTF/wtf/glib/FileSystemGlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ bool truncateFile(PlatformFileHandle handle, long long offset)
return g_seekable_truncate(G_SEEKABLE(g_io_stream_get_output_stream(G_IO_STREAM(handle))), offset, nullptr, nullptr);
}

int writeToFile(PlatformFileHandle handle, const char* data, int length)
int writeToFile(PlatformFileHandle handle, const void* data, int length)
{
if (!length)
return 0;
Expand Down
2 changes: 1 addition & 1 deletion Source/WTF/wtf/posix/FileSystemPOSIX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ bool truncateFile(PlatformFileHandle handle, long long offset)
return !ftruncate(handle, offset);
}

int writeToFile(PlatformFileHandle handle, const char* data, int length)
int writeToFile(PlatformFileHandle handle, const void* data, int length)
{
do {
int bytesWritten = write(handle, data, static_cast<size_t>(length));
Expand Down
2 changes: 1 addition & 1 deletion Source/WTF/wtf/win/FileSystemWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ bool truncateFile(PlatformFileHandle handle, long long offset)
return SetFileInformationByHandle(handle, FileEndOfFileInfo, &eofInfo, sizeof(FILE_END_OF_FILE_INFO));
}

int writeToFile(PlatformFileHandle handle, const char* data, int length)
int writeToFile(PlatformFileHandle handle, const void* data, int length)
{
if (!isHandleValid(handle))
return -1;
Expand Down
138 changes: 138 additions & 0 deletions Source/WebCore/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,141 @@
2021-06-04 Chris Dumez <cdumez@apple.com>

Use Vector<uint8_t> instead of Vector<char> to store bytes in SharedBuffer
https://bugs.webkit.org/show_bug.cgi?id=226623

Reviewed by Darin Adler.

Use Vector<uint8_t> instead of Vector<char> to store bytes in SharedBuffer. Also have SharedBuffer::data()
return a `const uint8_t*` instead of `const char*`. This is our preferred type to store bytes.

* Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::consumeFormData):
* Modules/fetch/FetchBodyConsumer.cpp:
(WebCore::packageFormData):
(WebCore::resolveWithTypeAndData):
* Modules/highlight/AppHighlight.h:
(WebCore::AppHighlight::encode const):
* Modules/indexeddb/IDBGetResult.cpp:
(WebCore::IDBGetResult::dataFromBuffer):
* Modules/indexeddb/server/IDBSerialization.cpp:
(WebCore::serializeIDBKeyData):
* Modules/mediastream/RTCDataChannel.cpp:
(WebCore::RTCDataChannel::didReceiveRawData):
* Modules/mediastream/RTCDataChannel.h:
* Modules/mediastream/RTCDataChannelRemoteHandler.cpp:
(WebCore::RTCDataChannelRemoteHandler::didReceiveRawData):
(WebCore::RTCDataChannelRemoteHandler::sendRawData):
* Modules/mediastream/RTCDataChannelRemoteHandler.h:
* Modules/mediastream/RTCDataChannelRemoteSource.h:
(WebCore::RTCDataChannelRemoteSource::sendRawData):
* Modules/mediastream/libwebrtc/LibWebRTCDataChannelHandler.cpp:
(WebCore::LibWebRTCDataChannelHandler::sendRawData):
(WebCore::LibWebRTCDataChannelHandler::OnMessage):
* Modules/mediastream/libwebrtc/LibWebRTCDataChannelHandler.h:
* css/CSSFontFaceSource.cpp:
(WebCore::CSSFontFaceSource::load):
* fileapi/Blob.cpp:
(WebCore::Blob::Blob):
* fileapi/NetworkSendQueue.cpp:
(WebCore::NetworkSendQueue::enqueue):
(WebCore::NetworkSendQueue::processMessages):
* fileapi/NetworkSendQueue.h:
* inspector/NetworkResourcesData.cpp:
(WebCore::NetworkResourcesData::ResourceData::appendData):
(WebCore::NetworkResourcesData::maybeAddResourceData):
* inspector/NetworkResourcesData.h:
* inspector/agents/InspectorNetworkAgent.cpp:
(WebCore::InspectorNetworkAgent::didReceiveData):
* inspector/agents/InspectorPageAgent.cpp:
(WebCore::decodeBuffer):
(WebCore::InspectorPageAgent::dataContent):
* inspector/agents/InspectorPageAgent.h:
* loader/ContentFilter.cpp:
(WebCore::ContentFilter::deliverResourceData):
* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::continueAfterContentPolicy):
(WebCore::DocumentLoader::maybeCreateArchive):
(WebCore::DocumentLoader::maybeFinishLoadingMultipartContent):
* loader/DocumentThreadableLoader.cpp:
(WebCore::DocumentThreadableLoader::didFinishLoading):
(WebCore::DocumentThreadableLoader::loadRequest):
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::loadResourceSynchronously):
* loader/NetscapePlugInStreamLoader.cpp:
(WebCore::NetscapePlugInStreamLoader::didReceiveDataOrBuffer):
* loader/NetscapePlugInStreamLoader.h:
* loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::didReceiveDataOrBuffer):
* loader/SubresourceLoader.cpp:
(WebCore::SubresourceLoader::didReceiveDataOrBuffer):
* loader/TextResourceDecoder.h:
(WebCore::TextResourceDecoder::decode):
(WebCore::TextResourceDecoder::decodeAndFlush):
* loader/TextTrackLoader.cpp:
(WebCore::TextTrackLoader::processNewCueData):
* loader/appcache/ApplicationCacheGroup.cpp:
(WebCore::ApplicationCacheGroup::didFinishLoadingManifest):
* loader/appcache/ApplicationCacheStorage.cpp:
(WebCore::ApplicationCacheStorage::writeDataToUniqueFileInDirectory):
* loader/archive/mhtml/MHTMLArchive.cpp:
(WebCore::MHTMLArchive::generateMHTMLData):
* loader/archive/mhtml/MHTMLParser.cpp:
(WebCore::MHTMLParser::parseNextPart):
* loader/cache/CachedRawResource.cpp:
(WebCore::CachedRawResource::updateBuffer):
(WebCore::CachedRawResource::finishLoading):
(WebCore::CachedRawResource::didAddClient):
* loader/cache/CachedSVGFont.cpp:
(WebCore::CachedSVGFont::ensureCustomFontData):
* platform/SharedBuffer.cpp:
(WebCore::SharedBuffer::SharedBuffer):
(WebCore::SharedBuffer::create):
(WebCore::SharedBuffer::combineIntoOneSegment const):
(WebCore::SharedBuffer::data const):
(WebCore::SharedBuffer::tryCreateArrayBuffer const):
(WebCore::SharedBuffer::append):
(WebCore::SharedBuffer::DataSegment::data const):
(WebCore::SharedBuffer::DataSegment::size const):
(WebCore::SharedBufferDataView::data const):
(WebCore::utf8Buffer):
* platform/SharedBuffer.h:
* platform/encryptedmedia/clearkey/CDMClearKey.cpp:
(WebCore::extractKeyidsLocationFromCencInitData):
(WebCore::extractKeyidsFromCencInitData):
* platform/graphics/Model.h:
(WebCore::Model::encode const):
* platform/graphics/displaylists/DisplayListItemBuffer.cpp:
(WebCore::DisplayList::ItemBuffer::append):
* platform/graphics/gstreamer/eme/CDMThunder.cpp:
(WebCore::CDMInstanceThunder::setServerCertificate):
(WebCore::ParsedResponseMessage::ParsedResponseMessage):
(WebCore::CDMInstanceSessionThunder::errorCallback):
(WebCore::CDMInstanceSessionThunder::requestLicense):
(WebCore::CDMInstanceSessionThunder::updateLicense):
(WebCore::CDMInstanceSessionThunder::loadSession):
* platform/graphics/opentype/OpenTypeTypes.h:
(WebCore::OpenType::TableBase::isValidEnd):
* platform/mediastream/RTCDataChannelHandler.h:
* platform/mediastream/RTCDataChannelHandlerClient.h:
* platform/mediastream/RTCDataChannelRemoteSourceConnection.h:
* platform/mock/RTCDataChannelHandlerMock.cpp:
(WebCore::RTCDataChannelHandlerMock::sendRawData):
* platform/mock/RTCDataChannelHandlerMock.h:
* platform/network/FormData.cpp:
(WebCore::FormData::asSharedBuffer const):
* platform/network/ResourceHandleClient.cpp:
(WebCore::ResourceHandleClient::didReceiveBuffer):
* platform/network/cocoa/RangeResponseGenerator.mm:
(WebCore::RangeResponseGenerator::giveResponseToTaskIfBytesInRangeReceived):
* platform/text/TextEncoding.h:
(WebCore::TextEncoding::decode const):
* svg/graphics/SVGImage.cpp:
(WebCore::SVGImage::dataChanged):
* xml/XSLTProcessorLibxslt.cpp:
(WebCore::docLoaderFunc):
* xml/parser/XMLDocumentParserLibxml2.cpp:
(WebCore::OffsetBuffer::OffsetBuffer):

2021-06-04 Brady Eidson <beidson@apple.com>

Enforce a quota in window.sessionStorage
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/fetch/FetchBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void FetchBody::consumeBlob(FetchBodyOwner& owner, Ref<DeferredPromise>&& promis
void FetchBody::consumeFormData(FetchBodyOwner& owner, Ref<DeferredPromise>&& promise)
{
if (auto sharedBuffer = formDataBody().asSharedBuffer()) {
m_consumer.resolveWithData(WTFMove(promise), owner.contentType(), sharedBuffer->dataAsUInt8Ptr(), sharedBuffer->size());
m_consumer.resolveWithData(WTFMove(promise), owner.contentType(), sharedBuffer->data(), sharedBuffer->size());
m_data = nullptr;
} else {
// FIXME: If the form data contains blobs, load them like we do other blobs.
Expand Down
18 changes: 9 additions & 9 deletions Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ static std::optional<MimeType> parseMIMEType(const String& contentType)
}

// https://fetch.spec.whatwg.org/#concept-body-package-data
static RefPtr<DOMFormData> packageFormData(ScriptExecutionContext* context, const String& contentType, const char* data, size_t length)
static RefPtr<DOMFormData> packageFormData(ScriptExecutionContext* context, const String& contentType, const uint8_t* data, size_t length)
{
auto parseMultipartPart = [context] (const char* part, size_t partLength, DOMFormData& form) -> bool {
const char* headerEnd = static_cast<const char*>(memmem(part, partLength, "\r\n\r\n", 4));
auto parseMultipartPart = [context] (const uint8_t* part, size_t partLength, DOMFormData& form) -> bool {
const uint8_t* headerEnd = static_cast<const uint8_t*>(memmem(part, partLength, "\r\n\r\n", 4));
if (!headerEnd)
return false;
const char* headerBegin = part;
const uint8_t* headerBegin = part;
size_t headerLength = headerEnd - headerBegin;

const char* bodyBegin = headerEnd + strlen("\r\n\r\n");
const uint8_t* bodyBegin = headerEnd + strlen("\r\n\r\n");
size_t bodyLength = partLength - (bodyBegin - headerBegin);

String header = String::fromUTF8(headerBegin, headerLength);
Expand Down Expand Up @@ -191,16 +191,16 @@ static RefPtr<DOMFormData> packageFormData(ScriptExecutionContext* context, cons
CString boundary = boundaryWithDashes.utf8();
size_t boundaryLength = boundary.length();

const char* currentBoundary = static_cast<const char*>(memmem(data, length, boundary.data(), boundaryLength));
const uint8_t* currentBoundary = static_cast<const uint8_t*>(memmem(data, length, boundary.data(), boundaryLength));
if (!currentBoundary)
return nullptr;
const char* nextBoundary = static_cast<const char*>(memmem(currentBoundary + boundaryLength, length - (currentBoundary + boundaryLength - data), boundary.data(), boundaryLength));
const uint8_t* nextBoundary = static_cast<const uint8_t*>(memmem(currentBoundary + boundaryLength, length - (currentBoundary + boundaryLength - data), boundary.data(), boundaryLength));
if (!nextBoundary)
return nullptr;
while (nextBoundary) {
parseMultipartPart(currentBoundary + boundaryLength, nextBoundary - currentBoundary - boundaryLength - strlen("\r\n"), form.get());
currentBoundary = nextBoundary;
nextBoundary = static_cast<const char*>(memmem(nextBoundary + boundaryLength, length - (nextBoundary + boundaryLength - data), boundary.data(), boundaryLength));
nextBoundary = static_cast<const uint8_t*>(memmem(nextBoundary + boundaryLength, length - (nextBoundary + boundaryLength - data), boundary.data(), boundaryLength));
}
} else if (mimeType && equalIgnoringASCIICase(mimeType->type, "application") && equalIgnoringASCIICase(mimeType->subtype, "x-www-form-urlencoded")) {
auto dataString = String::fromUTF8(data, length);
Expand Down Expand Up @@ -232,7 +232,7 @@ static void resolveWithTypeAndData(Ref<DeferredPromise>&& promise, FetchBodyCons
promise->resolve<IDLDOMString>(TextResourceDecoder::textFromUTF8(data, length));
return;
case FetchBodyConsumer::Type::FormData:
if (auto formData = packageFormData(context, contentType, reinterpret_cast<const char*>(data), length))
if (auto formData = packageFormData(context, contentType, data, length))
promise->resolve<IDLInterface<DOMFormData>>(*formData);
else
promise->reject(TypeError);
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/fetch/FetchBodyOwner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ void FetchBodyOwner::blobLoadingFailed()
finishBlobLoading();
}

void FetchBodyOwner::blobChunk(const char* data, size_t size)
void FetchBodyOwner::blobChunk(const uint8_t* data, size_t size)
{
ASSERT(data);
ASSERT(m_readableStreamSource);
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/Modules/fetch/FetchBodyOwner.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class FetchBodyOwner : public RefCounted<FetchBodyOwner>, public ActiveDOMObject

private:
// Blob loading routines
void blobChunk(const char*, size_t);
void blobChunk(const uint8_t*, size_t);
void blobLoadingSucceeded();
void blobLoadingFailed();
void finishBlobLoading();
Expand All @@ -112,7 +112,7 @@ class FetchBodyOwner : public RefCounted<FetchBodyOwner>, public ActiveDOMObject

// FetchLoaderClient API
void didReceiveResponse(const ResourceResponse&) final;
void didReceiveData(const char* data, size_t size) final { owner.blobChunk(data, size); }
void didReceiveData(const uint8_t* data, size_t size) final { owner.blobChunk(data, size); }
void didFail(const ResourceError&) final;
void didSucceed() final { owner.blobLoadingSucceeded(); }

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/fetch/FetchLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void FetchLoader::didReceiveResponse(unsigned long, const ResourceResponse& resp
m_client.didReceiveResponse(response);
}

void FetchLoader::didReceiveData(const char* value, int size)
void FetchLoader::didReceiveData(const uint8_t* value, int size)
{
if (!m_consumer) {
m_client.didReceiveData(value, size);
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/fetch/FetchLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class FetchLoader final : public ThreadableLoaderClient {
private:
// ThreadableLoaderClient API.
void didReceiveResponse(unsigned long, const ResourceResponse&) final;
void didReceiveData(const char*, int) final;
void didReceiveData(const uint8_t*, int) final;
void didFinishLoading(unsigned long) final;
void didFail(const ResourceError&) final;

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/fetch/FetchLoaderClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class FetchLoaderClient {

virtual void didReceiveResponse(const ResourceResponse&) { }

virtual void didReceiveData(const char*, size_t) { }
virtual void didReceiveData(const uint8_t*, size_t) { }

virtual void didSucceed() = 0;
virtual void didFail(const ResourceError&) = 0;
Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/Modules/fetch/FetchResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,12 @@ void FetchResponse::BodyLoader::didReceiveResponse(const ResourceResponse& resou
responseCallback(m_response);
}

void FetchResponse::BodyLoader::didReceiveData(const char* data, size_t size)
void FetchResponse::BodyLoader::didReceiveData(const uint8_t* data, size_t size)
{
ASSERT(m_response.m_readableStreamSource || m_consumeDataCallback);

if (m_consumeDataCallback) {
ReadableStreamChunk chunk { reinterpret_cast<const uint8_t*>(data), size };
ReadableStreamChunk chunk { data, size };
m_consumeDataCallback(&chunk);
return;
}
Expand Down Expand Up @@ -400,7 +400,7 @@ void FetchResponse::BodyLoader::consumeDataByChunk(ConsumeDataByChunkCallback&&
if (!data)
return;

ReadableStreamChunk chunk { reinterpret_cast<const uint8_t*>(data->data()), data->size() };
ReadableStreamChunk chunk { data->data(), data->size() };
m_consumeDataCallback(&chunk);
}

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/fetch/FetchResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class FetchResponse final : public FetchBodyOwner, public CanMakeWeakPtr<FetchRe
void didSucceed() final;
void didFail(const ResourceError&) final;
void didReceiveResponse(const ResourceResponse&) final;
void didReceiveData(const char*, size_t) final;
void didReceiveData(const uint8_t*, size_t) final;

FetchResponse& m_response;
NotificationCallback m_responseCallback;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/highlight/AppHighlight.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ template<class Encoder>
void AppHighlight::encode(Encoder& encoder) const
{
encoder << static_cast<size_t>(highlight->size());
encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(highlight->dataAsUInt8Ptr()), highlight->size(), 1);
encoder.encodeFixedLengthData(highlight->data(), highlight->size(), 1);

encoder << text;

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/indexeddb/IDBGetResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ WTF_MAKE_ISO_ALLOCATED_IMPL(IDBGetResult);

void IDBGetResult::dataFromBuffer(SharedBuffer& buffer)
{
m_value = ThreadSafeDataBuffer::create({ buffer.dataAsUInt8Ptr(), buffer.size() });
m_value = ThreadSafeDataBuffer::create({ buffer.data(), buffer.size() });
}

IDBGetResult::IDBGetResult(const IDBGetResult& that, IsolatedCopyTag)
Expand Down

0 comments on commit 3194bf4

Please sign in to comment.