Make BlobData use ThreadSafeSharedBuffer instead of RawData.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 Mar 2016 01:21:04 +0000 (01:21 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 Mar 2016 01:21:04 +0000 (01:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=156041

Reviewed by Alex Christensen.

Source/WebCore:

No new tests (No change in behavior).

* Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::consumeText):
(WebCore::FetchBody::extractFromText):
(WebCore::blobFromArrayBuffer):
* Modules/fetch/FetchBody.h:
* Modules/websockets/ThreadableWebSocketChannelClientWrapper.cpp:
(WebCore::ThreadableWebSocketChannelClientWrapper::didReceiveBinaryData):
* Modules/websockets/ThreadableWebSocketChannelClientWrapper.h:
* Modules/websockets/WebSocket.cpp:
(WebCore::WebSocket::didReceiveBinaryData):
* Modules/websockets/WebSocket.h:
* Modules/websockets/WebSocketChannel.cpp:
(WebCore::WebSocketChannel::processFrame):
* Modules/websockets/WebSocketChannel.h:
* Modules/websockets/WebSocketChannelClient.h:
(WebCore::WebSocketChannelClient::didReceiveBinaryData):
* Modules/websockets/WorkerThreadableWebSocketChannel.cpp:
(WebCore::WorkerThreadableWebSocketChannel::Peer::didReceiveBinaryData):
* Modules/websockets/WorkerThreadableWebSocketChannel.h:
* fileapi/Blob.cpp:
(WebCore::Blob::Blob):
* fileapi/Blob.h:
(WebCore::Blob::create):
* fileapi/WebKitBlobBuilder.h:
* platform/network/BlobData.cpp:
(WebCore::BlobData::BlobData):
(WebCore::BlobDataItem::length):
(WebCore::BlobData::appendData):
(WebCore::BlobData::setContentType): Deleted.
* platform/network/BlobData.h:
(WebCore::BlobDataItem::type):
(WebCore::BlobDataItem::data):
(WebCore::BlobDataItem::file):
(WebCore::BlobDataItem::BlobDataItem):
(WebCore::BlobData::create):
(WebCore::RawData::create): Deleted.
(WebCore::RawData::data): Deleted.
(WebCore::RawData::length): Deleted.
(WebCore::RawData::RawData): Deleted.
* platform/network/BlobPart.h:
(WebCore::BlobPart::BlobPart):
(WebCore::BlobPart::data):
(WebCore::BlobPart::moveData):
* platform/network/BlobRegistryImpl.cpp:
(WebCore::BlobRegistryImpl::appendStorageItems):
(WebCore::BlobRegistryImpl::registerFileBlobURL):
(WebCore::BlobRegistryImpl::registerBlobURL):
(WebCore::BlobRegistryImpl::registerBlobURLForSlice):
* platform/network/BlobResourceHandle.cpp:
(WebCore::BlobResourceHandle::getSizeForNext):
(WebCore::BlobResourceHandle::readSync):
(WebCore::BlobResourceHandle::readDataSync):
(WebCore::BlobResourceHandle::readFileSync):
(WebCore::BlobResourceHandle::readAsync):
(WebCore::BlobResourceHandle::readDataAsync):
(WebCore::BlobResourceHandle::readFileAsync):
* platform/network/BlobResourceHandle.h:
* platform/network/FormData.cpp:
(WebCore::appendBlobResolved):
* platform/network/soup/ResourceHandleSoup.cpp:
(WebCore::blobIsOutOfDate):
(WebCore::addEncodedBlobItemToSoupMessageBody):
* platform/text/LineEnding.cpp:
(WebCore::normalizeToCROrLF):
(WebCore::normalizeLineEndingsToNative):
(WebCore::normalizeLineEndingsToCR): Deleted.
(WebCore::normalizeLineEndingsToLF): Deleted.
* platform/text/LineEnding.h:
* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::responseBlob):

Source/WebKit2:

* NetworkProcess/FileAPI/NetworkBlobRegistry.cpp:
(WebKit::NetworkBlobRegistry::filesInBlob):
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<BlobPart>::decode):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@198869 268f45cc-cd09-0410-ab3c-d52691b4dbfc

29 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/fetch/FetchBody.cpp
Source/WebCore/Modules/fetch/FetchBody.h
Source/WebCore/Modules/websockets/ThreadableWebSocketChannelClientWrapper.cpp
Source/WebCore/Modules/websockets/ThreadableWebSocketChannelClientWrapper.h
Source/WebCore/Modules/websockets/WebSocket.cpp
Source/WebCore/Modules/websockets/WebSocket.h
Source/WebCore/Modules/websockets/WebSocketChannel.cpp
Source/WebCore/Modules/websockets/WebSocketChannel.h
Source/WebCore/Modules/websockets/WebSocketChannelClient.h
Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.cpp
Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.h
Source/WebCore/fileapi/Blob.cpp
Source/WebCore/fileapi/Blob.h
Source/WebCore/fileapi/WebKitBlobBuilder.h
Source/WebCore/platform/network/BlobData.cpp
Source/WebCore/platform/network/BlobData.h
Source/WebCore/platform/network/BlobPart.h
Source/WebCore/platform/network/BlobRegistryImpl.cpp
Source/WebCore/platform/network/BlobResourceHandle.cpp
Source/WebCore/platform/network/BlobResourceHandle.h
Source/WebCore/platform/network/FormData.cpp
Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp
Source/WebCore/platform/text/LineEnding.cpp
Source/WebCore/platform/text/LineEnding.h
Source/WebCore/xml/XMLHttpRequest.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.cpp
Source/WebKit2/Shared/WebCoreArgumentCoders.cpp

index c189e6c..4a0ff11 100644 (file)
@@ -1,3 +1,83 @@
+2016-03-30  Brady Eidson  <beidson@apple.com>
+
+        Make BlobData use ThreadSafeSharedBuffer instead of RawData.
+        https://bugs.webkit.org/show_bug.cgi?id=156041
+
+        Reviewed by Alex Christensen.
+
+        No new tests (No change in behavior).
+
+        * Modules/fetch/FetchBody.cpp:
+        (WebCore::FetchBody::consumeText):
+        (WebCore::FetchBody::extractFromText):
+        (WebCore::blobFromArrayBuffer):
+        * Modules/fetch/FetchBody.h:
+        * Modules/websockets/ThreadableWebSocketChannelClientWrapper.cpp:
+        (WebCore::ThreadableWebSocketChannelClientWrapper::didReceiveBinaryData):
+        * Modules/websockets/ThreadableWebSocketChannelClientWrapper.h:
+        * Modules/websockets/WebSocket.cpp:
+        (WebCore::WebSocket::didReceiveBinaryData):
+        * Modules/websockets/WebSocket.h:
+        * Modules/websockets/WebSocketChannel.cpp:
+        (WebCore::WebSocketChannel::processFrame):
+        * Modules/websockets/WebSocketChannel.h:
+        * Modules/websockets/WebSocketChannelClient.h:
+        (WebCore::WebSocketChannelClient::didReceiveBinaryData):
+        * Modules/websockets/WorkerThreadableWebSocketChannel.cpp:
+        (WebCore::WorkerThreadableWebSocketChannel::Peer::didReceiveBinaryData):
+        * Modules/websockets/WorkerThreadableWebSocketChannel.h:
+        * fileapi/Blob.cpp:
+        (WebCore::Blob::Blob):
+        * fileapi/Blob.h:
+        (WebCore::Blob::create):
+        * fileapi/WebKitBlobBuilder.h:
+        * platform/network/BlobData.cpp:
+        (WebCore::BlobData::BlobData):
+        (WebCore::BlobDataItem::length):
+        (WebCore::BlobData::appendData):
+        (WebCore::BlobData::setContentType): Deleted.
+        * platform/network/BlobData.h:
+        (WebCore::BlobDataItem::type):
+        (WebCore::BlobDataItem::data):
+        (WebCore::BlobDataItem::file):
+        (WebCore::BlobDataItem::BlobDataItem):
+        (WebCore::BlobData::create):
+        (WebCore::RawData::create): Deleted.
+        (WebCore::RawData::data): Deleted.
+        (WebCore::RawData::length): Deleted.
+        (WebCore::RawData::RawData): Deleted.
+        * platform/network/BlobPart.h:
+        (WebCore::BlobPart::BlobPart):
+        (WebCore::BlobPart::data):
+        (WebCore::BlobPart::moveData):
+        * platform/network/BlobRegistryImpl.cpp:
+        (WebCore::BlobRegistryImpl::appendStorageItems):
+        (WebCore::BlobRegistryImpl::registerFileBlobURL):
+        (WebCore::BlobRegistryImpl::registerBlobURL):
+        (WebCore::BlobRegistryImpl::registerBlobURLForSlice):
+        * platform/network/BlobResourceHandle.cpp:
+        (WebCore::BlobResourceHandle::getSizeForNext):
+        (WebCore::BlobResourceHandle::readSync):
+        (WebCore::BlobResourceHandle::readDataSync):
+        (WebCore::BlobResourceHandle::readFileSync):
+        (WebCore::BlobResourceHandle::readAsync):
+        (WebCore::BlobResourceHandle::readDataAsync):
+        (WebCore::BlobResourceHandle::readFileAsync):
+        * platform/network/BlobResourceHandle.h:
+        * platform/network/FormData.cpp:
+        (WebCore::appendBlobResolved):
+        * platform/network/soup/ResourceHandleSoup.cpp:
+        (WebCore::blobIsOutOfDate):
+        (WebCore::addEncodedBlobItemToSoupMessageBody):
+        * platform/text/LineEnding.cpp:
+        (WebCore::normalizeToCROrLF):
+        (WebCore::normalizeLineEndingsToNative):
+        (WebCore::normalizeLineEndingsToCR): Deleted.
+        (WebCore::normalizeLineEndingsToLF): Deleted.
+        * platform/text/LineEnding.h:
+        * xml/XMLHttpRequest.cpp:
+        (WebCore::XMLHttpRequest::responseBlob):
+
 2016-03-30  Enrica Casucci  <enrica@apple.com>
 
         Add a style for Data Detectors links.
index dacc2d8..ca50547 100644 (file)
@@ -201,7 +201,7 @@ void FetchBody::consumeText(Consumer::Type type, DeferredWrapper& promise)
     ASSERT(type == Consumer::Type::ArrayBuffer || type == Consumer::Type::Blob);
 
     if (type == Consumer::Type::ArrayBuffer) {
-        Vector<char> data = extractFromText();
+        Vector<uint8_t> data = extractFromText();
         fulfillPromiseWithArrayBuffer(promise, data.data(), data.size());
         return;
     }
@@ -232,12 +232,12 @@ void FetchBody::consumeBlob(FetchBodyOwner& owner, Consumer::Type type, Deferred
     owner.loadBlob(*m_blob, loadingType(type));
 }
 
-Vector<char> FetchBody::extractFromText() const
+Vector<uint8_t> FetchBody::extractFromText() const
 {
     ASSERT(m_type == Type::Text);
     // FIXME: This double allocation is not efficient. Might want to fix that at WTFString level.
     CString data = m_text.utf8();
-    Vector<char> value(data.length());
+    Vector<uint8_t> value(data.length());
     memcpy(value.data(), data.data(), data.length());
     return value;
 }
@@ -245,10 +245,10 @@ Vector<char> FetchBody::extractFromText() const
 static inline RefPtr<Blob> blobFromArrayBuffer(ArrayBuffer* buffer, const String& contentType)
 {
     if (!buffer)
-        return Blob::create(Vector<char>(), contentType);
+        return Blob::create(Vector<uint8_t>(), contentType);
 
     // FIXME: We should try to move buffer to Blob without doing this copy.
-    Vector<char> value(buffer->byteLength());
+    Vector<uint8_t> value(buffer->byteLength());
     memcpy(value.data(), buffer->data(), buffer->byteLength());
     return Blob::create(WTFMove(value), contentType);
 }
index f7ac6d7..bbbcd07 100644 (file)
@@ -87,7 +87,7 @@ private:
     };
     void consume(FetchBodyOwner&, Consumer::Type, DeferredWrapper&&);
 
-    Vector<char> extractFromText() const;
+    Vector<uint8_t> extractFromText() const;
     bool processIfEmptyOrDisturbed(Consumer::Type, DeferredWrapper&);
     void consumeArrayBuffer(Consumer::Type, DeferredWrapper&);
     void consumeText(Consumer::Type, DeferredWrapper&);
index 660fe78..1224805 100644 (file)
@@ -180,10 +180,10 @@ void ThreadableWebSocketChannelClientWrapper::didReceiveMessage(const String& me
         processPendingTasks();
 }
 
-void ThreadableWebSocketChannelClientWrapper::didReceiveBinaryData(Vector<char>&& binaryData)
+void ThreadableWebSocketChannelClientWrapper::didReceiveBinaryData(Vector<uint8_t>&& binaryData)
 {
     ref();
-    Vector<char>* capturedData = new Vector<char>(WTFMove(binaryData));
+    Vector<uint8_t>* capturedData = new Vector<uint8_t>(WTFMove(binaryData));
     m_pendingTasks.append(std::make_unique<ScriptExecutionContext::Task>([this, capturedData] (ScriptExecutionContext&) {
         if (m_client)
             m_client->didReceiveBinaryData(WTFMove(*capturedData));
index a3894c9..7f5fc72 100644 (file)
@@ -79,7 +79,7 @@ public:
 
     void didConnect();
     void didReceiveMessage(const String& message);
-    void didReceiveBinaryData(Vector<char>&&);
+    void didReceiveBinaryData(Vector<uint8_t>&&);
     void didUpdateBufferedAmount(unsigned long bufferedAmount);
     void didStartClosingHandshake();
     void didClose(unsigned long unhandledBufferedAmount, WebSocketChannelClient::ClosingHandshakeCompletionStatus, unsigned short code, const String& reason);
index bd51e9e..cfbe679 100644 (file)
@@ -561,7 +561,7 @@ void WebSocket::didReceiveMessage(const String& msg)
     dispatchEvent(MessageEvent::create(msg, SecurityOrigin::create(m_url)->toString()));
 }
 
-void WebSocket::didReceiveBinaryData(Vector<char>&& binaryData)
+void WebSocket::didReceiveBinaryData(Vector<uint8_t>&& binaryData)
 {
     LOG(Network, "WebSocket %p didReceiveBinaryData() %lu byte binary message", this, static_cast<unsigned long>(binaryData.size()));
     switch (m_binaryType) {
index 50085e0..076266b 100644 (file)
@@ -100,7 +100,7 @@ public:
     // WebSocketChannelClient functions.
     void didConnect() override;
     void didReceiveMessage(const String& message) override;
-    void didReceiveBinaryData(Vector<char>&&) override;
+    void didReceiveBinaryData(Vector<uint8_t>&&) override;
     void didReceiveMessageError() override;
     void didUpdateBufferedAmount(unsigned long bufferedAmount) override;
     void didStartClosingHandshake() override;
index 94c3f36..1a1e974 100644 (file)
@@ -586,7 +586,7 @@ bool WebSocketChannel::processFrame()
             // so we should pretend that we have finished to read this frame and
             // make sure that the member variables are in a consistent state before
             // the handler is invoked.
-            Vector<char> continuousFrameData = WTFMove(m_continuousFrameData);
+            Vector<uint8_t> continuousFrameData = WTFMove(m_continuousFrameData);
             m_hasContinuousFrame = false;
             if (m_continuousFrameOpCode == WebSocketFrame::OpCodeText) {
                 String message;
@@ -626,7 +626,7 @@ bool WebSocketChannel::processFrame()
 
     case WebSocketFrame::OpCodeBinary:
         if (frame.final) {
-            Vector<char> binaryData(frame.payloadLength);
+            Vector<uint8_t> binaryData(frame.payloadLength);
             memcpy(binaryData.data(), frame.payload, frame.payloadLength);
             skipBuffer(frameEnd - m_buffer.data());
             m_client->didReceiveBinaryData(WTFMove(binaryData));
index 3ae72d9..3b6a528 100644 (file)
@@ -204,7 +204,7 @@ private:
     // Private members only for hybi-10 protocol.
     bool m_hasContinuousFrame;
     WebSocketFrame::OpCode m_continuousFrameOpCode;
-    Vector<char> m_continuousFrameData;
+    Vector<uint8_t> m_continuousFrameData;
     unsigned short m_closeEventCode;
     String m_closeEventReason;
 
index da7928f..bd988b2 100644 (file)
@@ -43,7 +43,7 @@ namespace WebCore {
         virtual ~WebSocketChannelClient() { }
         virtual void didConnect() { }
         virtual void didReceiveMessage(const String&) { }
-        virtual void didReceiveBinaryData(Vector<char>&&) { }
+        virtual void didReceiveBinaryData(Vector<uint8_t>&&) { }
         virtual void didReceiveMessageError() { }
         virtual void didUpdateBufferedAmount(unsigned long /* bufferedAmount */) { }
         virtual void didStartClosingHandshake() { }
index 79e2072..29f1d46 100644 (file)
@@ -288,12 +288,12 @@ void WorkerThreadableWebSocketChannel::Peer::didReceiveMessage(const String& mes
     }, m_taskMode);
 }
 
-void WorkerThreadableWebSocketChannel::Peer::didReceiveBinaryData(Vector<char>&& binaryData)
+void WorkerThreadableWebSocketChannel::Peer::didReceiveBinaryData(Vector<uint8_t>&& binaryData)
 {
     ASSERT(isMainThread());
 
     RefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper = m_workerClientWrapper;
-    Vector<char>* capturedData = new Vector<char>(WTFMove(binaryData));
+    Vector<uint8_t>* capturedData = new Vector<uint8_t>(WTFMove(binaryData));
     m_loaderProxy.postTaskForModeToWorkerGlobalScope([workerClientWrapper, capturedData] (ScriptExecutionContext& context) {
         ASSERT_UNUSED(context, context.isWorkerGlobalScope());
         workerClientWrapper->didReceiveBinaryData(WTFMove(*capturedData));
index bc8392e..c4c09ae 100644 (file)
@@ -100,7 +100,7 @@ public:
         // WebSocketChannelClient functions.
         void didConnect() override;
         void didReceiveMessage(const String& message) override;
-        void didReceiveBinaryData(Vector<char>&&) override;
+        void didReceiveBinaryData(Vector<uint8_t>&&) override;
         void didUpdateBufferedAmount(unsigned long bufferedAmount) override;
         void didStartClosingHandshake() override;
         void didClose(unsigned long unhandledBufferedAmount, ClosingHandshakeCompletionStatus, unsigned short code, const String& reason) override;
index 052fb86..b2f2282 100644 (file)
@@ -77,7 +77,7 @@ Blob::Blob()
     ThreadableBlobRegistry::registerBlobURL(m_internalURL, Vector<BlobPart>(), String());
 }
 
-Blob::Blob(Vector<char> data, const String& contentType)
+Blob::Blob(Vector<uint8_t> data, const String& contentType)
     : m_type(contentType)
     , m_size(data.size())
 {
index 90498e0..93333dc 100644 (file)
@@ -48,7 +48,7 @@ public:
         return adoptRef(*new Blob);
     }
 
-    static Ref<Blob> create(Vector<char> data, const String& contentType)
+    static Ref<Blob> create(Vector<uint8_t> data, const String& contentType)
     {
         return adoptRef(*new Blob(WTFMove(data), contentType));
     }
@@ -91,7 +91,7 @@ public:
 
 protected:
     Blob();
-    Blob(Vector<char>, const String& contentType);
+    Blob(Vector<uint8_t>, const String& contentType);
     Blob(Vector<BlobPart>, const String& contentType);
 
     enum UninitializedContructor { uninitializedContructor };
index a16c0c3..ba87b3d 100644 (file)
@@ -55,7 +55,7 @@ public:
 
 private:
     Vector<BlobPart> m_items;
-    Vector<char> m_appendableData;
+    Vector<uint8_t> m_appendableData;
 };
 
 } // namespace WebCore
index 362c72b..acd5826 100644 (file)
 
 namespace WebCore {
 
+BlobData::BlobData(const String& contentType)
+    : m_contentType(contentType)
+{
+    ASSERT(Blob::isNormalizedContentType(contentType));
+}
+
 const long long BlobDataItem::toEndOfFile = -1;
 
 long long BlobDataItem::length() const
@@ -46,31 +52,25 @@ long long BlobDataItem::length() const
     if (m_length != toEndOfFile)
         return m_length;
 
-    switch (type) {
-    case Data:
+    switch (m_type) {
+    case Type::Data:
         ASSERT_NOT_REACHED();
         return m_length;
-    case File:
-        return file->size();
+    case Type::File:
+        return m_file->size();
     }
 
     ASSERT_NOT_REACHED();
     return m_length;
 }
 
-void BlobData::setContentType(const String& contentType)
-{
-    ASSERT(Blob::isNormalizedContentType(contentType));
-    m_contentType = contentType;
-}
-
-void BlobData::appendData(PassRefPtr<RawData> data)
+void BlobData::appendData(const ThreadSafeDataBuffer& data)
 {
-    size_t dataSize = data->length();
+    size_t dataSize = data.data() ? data.data()->size() : 0;
     appendData(data, 0, dataSize);
 }
 
-void BlobData::appendData(PassRefPtr<RawData> data, long long offset, long long length)
+void BlobData::appendData(const ThreadSafeDataBuffer& data, long long offset, long long length)
 {
     m_items.append(BlobDataItem(data, offset, length));
 }
index 143c5ed..21dbdf7 100644 (file)
 #define BlobData_h
 
 #include "BlobDataFileReference.h"
+#include "ThreadSafeDataBuffer.h"
 #include "URL.h"
 #include <wtf/Forward.h>
 #include <wtf/RefCounted.h>
+#include <wtf/ThreadSafeRefCounted.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
-class RawData : public RefCounted<RawData> {
+class BlobDataItem {
 public:
-    static Ref<RawData> create(Vector<char>&& data)
-    {
-        return adoptRef(*new RawData(WTFMove(data)));
-    }
-
-    static Ref<RawData> create(const char* data, size_t size)
-    {
-        Vector<char> dataVector(size);
-        memcpy(dataVector.data(), data, size);
-        return adoptRef(*new RawData(WTFMove(dataVector)));
-    }
-
-    const char* data() const { return m_data.data(); }
-    size_t length() const { return m_data.size(); }
-
-private:
-    RawData(Vector<char>&& data)
-        : m_data(WTFMove(data))
-    {
-    }
-
-    Vector<char> m_data;
-};
-
-struct BlobDataItem {
     WEBCORE_EXPORT static const long long toEndOfFile;
 
-    enum {
+    enum class Type {
         Data,
         File
-    } type;
+    };
+
+    Type type() const { return m_type; }
 
     // For Data type.
-    RefPtr<RawData> data;
+    const ThreadSafeDataBuffer& data() const { return m_data; }
 
     // For File type.
-    RefPtr<BlobDataFileReference> file;
+    BlobDataFileReference* file() const { return m_file.get(); }
 
     long long offset() const { return m_offset; }
     long long length() const; // Computes file length if it's not known yet.
@@ -86,55 +65,59 @@ private:
     friend class BlobData;
 
     explicit BlobDataItem(PassRefPtr<BlobDataFileReference> file)
-        : type(File)
-        , file(file)
+        : m_type(Type::File)
+        , m_file(file)
         , m_offset(0)
         , m_length(toEndOfFile)
     {
     }
 
-    BlobDataItem(PassRefPtr<RawData> data, long long offset, long long length)
-        : type(Data)
-        , data(data)
+    BlobDataItem(ThreadSafeDataBuffer data, long long offset, long long length)
+        : m_type(Type::Data)
+        , m_data(data)
         , m_offset(offset)
         , m_length(length)
     {
     }
 
     BlobDataItem(BlobDataFileReference* file, long long offset, long long length)
-        : type(File)
-        , file(file)
+        : m_type(Type::File)
+        , m_file(file)
         , m_offset(offset)
         , m_length(length)
     {
     }
 
+    Type m_type;
+    ThreadSafeDataBuffer m_data;
+    RefPtr<BlobDataFileReference> m_file;
+
     long long m_offset;
     long long m_length;
 };
 
 typedef Vector<BlobDataItem> BlobDataItemList;
 
-class BlobData : public RefCounted<BlobData> {
+class BlobData : public ThreadSafeRefCounted<BlobData> {
 public:
-    static Ref<BlobData> create()
+    static Ref<BlobData> create(const String& contentType)
     {
-        return adoptRef(*new BlobData);
+        return adoptRef(*new BlobData(contentType));
     }
 
     const String& contentType() const { return m_contentType; }
-    WEBCORE_EXPORT void setContentType(const String&);
 
     const BlobDataItemList& items() const { return m_items; }
     void swapItems(BlobDataItemList&);
 
-    void appendData(PassRefPtr<RawData>);
+    void appendData(const ThreadSafeDataBuffer&);
     void appendFile(PassRefPtr<BlobDataFileReference>);
 
 private:
     friend class BlobRegistryImpl;
+    BlobData(const String& contentType);
 
-    void appendData(PassRefPtr<RawData>, long long offset, long long length);
+    void appendData(const ThreadSafeDataBuffer&, long long offset, long long length);
     void appendFile(BlobDataFileReference*, long long offset, long long length);
 
     String m_contentType;
index 55f49c3..ba19c3c 100644 (file)
@@ -42,7 +42,7 @@ public:
     {
     }
 
-    BlobPart(Vector<char> data)
+    BlobPart(Vector<uint8_t> data)
         : m_type(Data)
         , m_data(WTFMove(data))
     {
@@ -56,13 +56,13 @@ public:
 
     Type type() const { return m_type; }
 
-    const Vector<char>& data() const
+    const Vector<uint8_t>& data() const
     {
         ASSERT(m_type == Data);
         return m_data;
     }
 
-    Vector<char> moveData()
+    Vector<uint8_t> moveData()
     {
         ASSERT(m_type == Data);
         return WTFMove(m_data);
@@ -81,7 +81,7 @@ public:
 
 private:
     Type m_type;
-    Vector<char> m_data;
+    Vector<uint8_t> m_data;
     URL m_url;
 };
 
index cc04bb9..88b0f14 100644 (file)
@@ -98,11 +98,11 @@ void BlobRegistryImpl::appendStorageItems(BlobData* blobData, const BlobDataItem
     for (; iter != items.end() && length > 0; ++iter) {
         long long currentLength = iter->length() - offset;
         long long newLength = currentLength > length ? length : currentLength;
-        if (iter->type == BlobDataItem::Data)
-            blobData->appendData(iter->data, iter->offset() + offset, newLength);
+        if (iter->type() == BlobDataItem::Type::Data)
+            blobData->appendData(iter->data(), iter->offset() + offset, newLength);
         else {
-            ASSERT(iter->type == BlobDataItem::File);
-            blobData->appendFile(iter->file.get(), iter->offset() + offset, newLength);
+            ASSERT(iter->type() == BlobDataItem::Type::File);
+            blobData->appendFile(iter->file(), iter->offset() + offset, newLength);
         }
         length -= newLength;
         offset = 0;
@@ -115,8 +115,7 @@ void BlobRegistryImpl::registerFileBlobURL(const URL& url, RefPtr<BlobDataFileRe
     ASSERT(isMainThread());
     registerBlobResourceHandleConstructor();
 
-    RefPtr<BlobData> blobData = BlobData::create();
-    blobData->setContentType(contentType);
+    RefPtr<BlobData> blobData = BlobData::create(contentType);
 
     blobData->appendFile(file);
     m_blobs.set(url.string(), blobData.release());
@@ -127,8 +126,7 @@ void BlobRegistryImpl::registerBlobURL(const URL& url, Vector<BlobPart> blobPart
     ASSERT(isMainThread());
     registerBlobResourceHandleConstructor();
 
-    RefPtr<BlobData> blobData = BlobData::create();
-    blobData->setContentType(contentType);
+    RefPtr<BlobData> blobData = BlobData::create(contentType);
 
     // The blob data is stored in the "canonical" way. That is, it only contains a list of Data and File items.
     // 1) The Data item is denoted by the raw data and the range.
@@ -139,8 +137,9 @@ void BlobRegistryImpl::registerBlobURL(const URL& url, Vector<BlobPart> blobPart
     for (BlobPart& part : blobParts) {
         switch (part.type()) {
         case BlobPart::Data: {
-            RefPtr<RawData> rawData = RawData::create(part.moveData());
-            blobData->appendData(rawData.release());
+            auto movedData = part.moveData();
+            auto data = ThreadSafeDataBuffer::adoptVector(movedData);
+            blobData->appendData(data);
             break;
         }
         case BlobPart::Blob: {
@@ -196,8 +195,7 @@ void BlobRegistryImpl::registerBlobURLForSlice(const URL& url, const URL& srcURL
         end = originalSize;
 
     unsigned long long newLength = end - start;
-    RefPtr<BlobData> newData = BlobData::create();
-    newData->setContentType(originalData->contentType());
+    RefPtr<BlobData> newData = BlobData::create(originalData->contentType());
 
     appendStorageItems(newData.get(), originalData->items(), start, newLength);
 
index 61f2334..cfae233 100644 (file)
@@ -253,16 +253,16 @@ void BlobResourceHandle::getSizeForNext()
     }
 
     const BlobDataItem& item = m_blobData->items().at(m_sizeItemCount);
-    switch (item.type) {
-    case BlobDataItem::Data:
+    switch (item.type()) {
+    case BlobDataItem::Type::Data:
         didGetSize(item.length());
         break;
-    case BlobDataItem::File:
+    case BlobDataItem::Type::File:
         // Files know their sizes, but asking the stream to verify that the file wasn't modified.
         if (m_async)
-            m_asyncStream->getSize(item.file->path(), item.file->expectedModificationTime());
+            m_asyncStream->getSize(item.file()->path(), item.file()->expectedModificationTime());
         else
-            didGetSize(m_stream->getSize(item.file->path(), item.file->expectedModificationTime()));
+            didGetSize(m_stream->getSize(item.file()->path(), item.file()->expectedModificationTime()));
         break;
     default:
         ASSERT_NOT_REACHED();
@@ -351,9 +351,9 @@ int BlobResourceHandle::readSync(char* buf, int length)
         
         const BlobDataItem& item = m_blobData->items().at(m_readItemCount);
         int bytesRead = 0;
-        if (item.type == BlobDataItem::Data)
+        if (item.type() == BlobDataItem::Type::Data)
             bytesRead = readDataSync(item, buf + offset, remaining);
-        else if (item.type == BlobDataItem::File)
+        else if (item.type() == BlobDataItem::Type::File)
             bytesRead = readFileSync(item, buf + offset, remaining);
         else
             ASSERT_NOT_REACHED();
@@ -389,7 +389,7 @@ int BlobResourceHandle::readDataSync(const BlobDataItem& item, char* buf, int le
     int bytesToRead = (length > remaining) ? static_cast<int>(remaining) : length;
     if (bytesToRead > m_totalRemainingSize)
         bytesToRead = static_cast<int>(m_totalRemainingSize);
-    memcpy(buf, item.data->data() + item.offset() + m_currentItemReadSize, bytesToRead);
+    memcpy(buf, item.data().data() + item.offset() + m_currentItemReadSize, bytesToRead);
     m_totalRemainingSize -= bytesToRead;
 
     m_currentItemReadSize += bytesToRead;
@@ -411,7 +411,7 @@ int BlobResourceHandle::readFileSync(const BlobDataItem& item, char* buf, int le
         long long bytesToRead = m_itemLengthList[m_readItemCount] - m_currentItemReadSize;
         if (bytesToRead > m_totalRemainingSize)
             bytesToRead = m_totalRemainingSize;
-        bool success = m_stream->openForRead(item.file->path(), item.offset() + m_currentItemReadSize, bytesToRead);
+        bool success = m_stream->openForRead(item.file()->path(), item.offset() + m_currentItemReadSize, bytesToRead);
         m_currentItemReadSize = 0;
         if (!success) {
             m_errorCode = notReadableError;
@@ -452,9 +452,9 @@ void BlobResourceHandle::readAsync()
     }
 
     const BlobDataItem& item = m_blobData->items().at(m_readItemCount);
-    if (item.type == BlobDataItem::Data)
+    if (item.type() == BlobDataItem::Type::Data)
         readDataAsync(item);
-    else if (item.type == BlobDataItem::File)
+    else if (item.type() == BlobDataItem::Type::File)
         readFileAsync(item);
     else
         ASSERT_NOT_REACHED();
@@ -464,12 +464,14 @@ void BlobResourceHandle::readDataAsync(const BlobDataItem& item)
 {
     ASSERT(isMainThread());
     ASSERT(m_async);
+    ASSERT(item.data().data());
+
     Ref<BlobResourceHandle> protect(*this);
 
     long long bytesToRead = item.length() - m_currentItemReadSize;
     if (bytesToRead > m_totalRemainingSize)
         bytesToRead = m_totalRemainingSize;
-    consumeData(item.data->data() + item.offset() + m_currentItemReadSize, static_cast<int>(bytesToRead));
+    consumeData(reinterpret_cast<const char*>(item.data().data()->data()) + item.offset() + m_currentItemReadSize, static_cast<int>(bytesToRead));
     m_currentItemReadSize = 0;
 }
 
@@ -486,7 +488,7 @@ void BlobResourceHandle::readFileAsync(const BlobDataItem& item)
     long long bytesToRead = m_itemLengthList[m_readItemCount] - m_currentItemReadSize;
     if (bytesToRead > m_totalRemainingSize)
         bytesToRead = static_cast<int>(m_totalRemainingSize);
-    m_asyncStream->openForRead(item.file->path(), item.offset() + m_currentItemReadSize, bytesToRead);
+    m_asyncStream->openForRead(item.file()->path(), item.offset() + m_currentItemReadSize, bytesToRead);
     m_fileOpened = true;
     m_currentItemReadSize = 0;
 }
index 1aea615..ce86968 100644 (file)
@@ -44,7 +44,7 @@ class BlobData;
 class FileStream;
 class ResourceHandleClient;
 class ResourceRequest;
-struct BlobDataItem;
+class BlobDataItem;
 
 class BlobResourceHandle final : public FileStreamClient, public ResourceHandle  {
 public:
index 80335d8..885a981 100644 (file)
@@ -293,10 +293,11 @@ static void appendBlobResolved(FormData* formData, const URL& url)
     const BlobDataItemList::const_iterator itend = blobData->items().end();
     for (; it != itend; ++it) {
         const BlobDataItem& blobItem = *it;
-        if (blobItem.type == BlobDataItem::Data)
-            formData->appendData(blobItem.data->data() + static_cast<int>(blobItem.offset()), static_cast<int>(blobItem.length()));
-        else if (blobItem.type == BlobDataItem::File)
-            formData->appendFileRange(blobItem.file->path(), blobItem.offset(), blobItem.length(), blobItem.file->expectedModificationTime());
+        if (blobItem.type() == BlobDataItem::Type::Data) {
+            ASSERT(blobItem.data().data());
+            formData->appendData(blobItem.data().data()->data() + static_cast<int>(blobItem.offset()), static_cast<int>(blobItem.length()));
+        } else if (blobItem.type() == BlobDataItem::Type::File)
+            formData->appendFileRange(blobItem.file()->path(), blobItem.offset(), blobItem.length(), blobItem.file()->expectedModificationTime());
         else
             ASSERT_NOT_REACHED();
     }
index da1005c..2350507 100644 (file)
@@ -769,30 +769,30 @@ static bool addFileToSoupMessageBody(SoupMessage* message, const String& fileNam
 
 static bool blobIsOutOfDate(const BlobDataItem& blobItem)
 {
-    ASSERT(blobItem.type == BlobDataItem::File);
-    if (!isValidFileTime(blobItem.file->expectedModificationTime()))
+    ASSERT(blobItem.type == BlobDataItem::Type::File);
+    if (!isValidFileTime(blobItem.file()->expectedModificationTime()))
         return false;
 
     time_t fileModificationTime;
-    if (!getFileModificationTime(blobItem.file->path(), fileModificationTime))
+    if (!getFileModificationTime(blobItem.file()->path(), fileModificationTime))
         return true;
 
-    return fileModificationTime != static_cast<time_t>(blobItem.file->expectedModificationTime());
+    return fileModificationTime != static_cast<time_t>(blobItem.file()->expectedModificationTime());
 }
 
 static void addEncodedBlobItemToSoupMessageBody(SoupMessage* message, const BlobDataItem& blobItem, unsigned long& totalBodySize)
 {
-    if (blobItem.type == BlobDataItem::Data) {
+    if (blobItem.type() == BlobDataItem::Type::Data) {
         totalBodySize += blobItem.length();
-        soup_message_body_append(message->request_body, SOUP_MEMORY_TEMPORARY, blobItem.data->data() + blobItem.offset(), blobItem.length());
+        soup_message_body_append(message->request_body, SOUP_MEMORY_TEMPORARY, blobItem.data().data()->data() + blobItem.offset(), blobItem.length());
         return;
     }
 
-    ASSERT(blobItem.type == BlobDataItem::File);
+    ASSERT(blobItem.type == BlobDataItem::Type::File);
     if (blobIsOutOfDate(blobItem))
         return;
 
-    addFileToSoupMessageBody(message, blobItem.file->path(), blobItem.offset(), blobItem.length() == BlobDataItem::toEndOfFile ? 0 : blobItem.length(),  totalBodySize);
+    addFileToSoupMessageBody(message, blobItem.file()->path(), blobItem.offset(), blobItem.length() == BlobDataItem::toEndOfFile ? 0 : blobItem.length(),  totalBodySize);
 }
 
 static void addEncodedBlobToSoupMessageBody(SoupMessage* message, const FormDataElement& element, unsigned long& totalBodySize)
index c0b0765..4257428 100644 (file)
@@ -153,10 +153,8 @@ void internalNormalizeLineEndingsToCRLF(const CString& from, OutputBuffer& buffe
 
 namespace WebCore {
 
-void normalizeToCROrLF(const CString& from, Vector<char>& result, bool toCR);
-
 // Normalize all line-endings to CR or LF.
-void normalizeToCROrLF(const CString& from, Vector<char>& result, bool toCR)
+static void normalizeToCROrLF(const CString& from, Vector<uint8_t>& result, bool toCR)
 {
     // Compute the new length.
     size_t newLen = 0;
@@ -181,7 +179,7 @@ void normalizeToCROrLF(const CString& from, Vector<char>& result, bool toCR)
     p = from.data();
     size_t oldResultSize = result.size();
     result.grow(oldResultSize + newLen);
-    char* q = result.data() + oldResultSize;
+    uint8_t* q = result.data() + oldResultSize;
 
     // If no need to fix the string, just copy the string over.
     if (!needFix) {
@@ -214,23 +212,13 @@ CString normalizeLineEndingsToCRLF(const CString& from)
     return buffer.buffer();
 }
 
-void normalizeLineEndingsToCR(const CString& from, Vector<char>& result)
-{
-    normalizeToCROrLF(from, result, true);
-}
-
-void normalizeLineEndingsToLF(const CString& from, Vector<char>& result)
-{
-    normalizeToCROrLF(from, result, false);
-}
-
-void normalizeLineEndingsToNative(const CString& from, Vector<char>& result)
+void normalizeLineEndingsToNative(const CString& from, Vector<uint8_t>& result)
 {
 #if OS(WINDOWS)
     VectorCharAppendBuffer buffer(result);
     internalNormalizeLineEndingsToCRLF(from, buffer);
 #else
-    normalizeLineEndingsToLF(from, result);
+    normalizeToCROrLF(from, result, false);
 #endif
 }
 
index 4306ce8..a41cb80 100644 (file)
@@ -40,15 +40,9 @@ namespace WebCore {
 // Normalize all line-endings in the given string to CRLF.
 CString normalizeLineEndingsToCRLF(const CString& from);
 
-// Normalize all line-endings in the given string to CR and append the result to the given buffer.
-void normalizeLineEndingsToCR(const CString& from, Vector<char>& result);
-
-// Normalize all line-endings in the given string to LF and append the result to the given buffer.
-void normalizeLineEndingsToLF(const CString& from, Vector<char>& result);
-
 // Normalize all line-endings in the given string to the native line-endings and append the result to the given buffer.
 // (Normalize to CRLF on Windows and normalize to LF on all other platforms.)
-void normalizeLineEndingsToNative(const CString& from, Vector<char>& result);
+void normalizeLineEndingsToNative(const CString& from, Vector<uint8_t>& result);
 
 } // namespace WebCore
 
index 004143e..d0763f5 100644 (file)
@@ -238,7 +238,7 @@ Blob* XMLHttpRequest::responseBlob()
     if (!m_responseBlob) {
         if (m_binaryResponseBuilder) {
             // FIXME: We just received the data from NetworkProcess, and are sending it back. This is inefficient.
-            Vector<char> data;
+            Vector<uint8_t> data;
             data.append(m_binaryResponseBuilder->data(), m_binaryResponseBuilder->size());
             String normalizedContentType = Blob::normalizedContentType(responseMIMEType()); // responseMIMEType defaults to text/xml which may be incorrect.
             m_responseBlob = Blob::create(WTFMove(data), normalizedContentType);
index d260f25..07803ab 100644 (file)
@@ -1,3 +1,15 @@
+2016-03-30  Brady Eidson  <beidson@apple.com>
+
+        Make BlobData use ThreadSafeSharedBuffer instead of RawData.
+        https://bugs.webkit.org/show_bug.cgi?id=156041
+
+        Reviewed by Alex Christensen.
+
+        * NetworkProcess/FileAPI/NetworkBlobRegistry.cpp:
+        (WebKit::NetworkBlobRegistry::filesInBlob):
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<BlobPart>::decode):
+
 2016-03-30  Daniel Bates  <dabates@apple.com>
 
         Unreviewed, rolling out r198856.
index e99d7cf..025e2fc 100644 (file)
@@ -141,8 +141,8 @@ Vector<RefPtr<BlobDataFileReference>> NetworkBlobRegistry::filesInBlob(NetworkCo
 
     Vector<RefPtr<BlobDataFileReference>> result;
     for (const BlobDataItem& item : blobData->items()) {
-        if (item.type == BlobDataItem::File)
-            result.append(item.file);
+        if (item.type() == BlobDataItem::Type::File)
+            result.append(item.file());
     }
 
     return result;
index 7c2cf32..0490fef 100644 (file)
@@ -1861,7 +1861,7 @@ bool ArgumentCoder<BlobPart>::decode(ArgumentDecoder& decoder, BlobPart& blobPar
 
     switch (type) {
     case BlobPart::Data: {
-        Vector<char> data;
+        Vector<uint8_t> data;
         if (!decoder.decode(data))
             return false;
         blobPart = BlobPart(WTFMove(data));