Move size computation for Blob constructor into BlobRegistryImpl
authorap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 May 2014 23:09:27 +0000 (23:09 +0000)
committerap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 May 2014 23:09:27 +0000 (23:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=132439

Reviewed by Sam Weinig.

Source/WebCore:
* Modules/websockets/WebSocket.cpp: (WebCore::WebSocket::didReceiveBinaryData):
Don't pass the size, anyone who cares can get it from BlobData.

* bindings/js/JSBlobCustom.cpp: (WebCore::JSBlobConstructor::constructJSBlob):
Updated for BlobBuilder changes.

* fileapi/Blob.cpp: (WebCore::Blob::Blob):
* fileapi/Blob.h: (WebCore::Blob::create):
No longer take a precomputed size with BlobData, BlobRegistry will compute it as
part of registration.

* fileapi/File.h:
* fileapi/File.cpp:
(WebCore::File::File): Don't pass a size (that's unknown anyway).
(WebCore::File::captureSnapshot): Deleted. Finally, only the registry is responsible
for snapshot tracking now (I doubt that either new or old code is particularly compliant).

* fileapi/ThreadableBlobRegistry.cpp:
(WebCore::ThreadableBlobRegistry::registerBlobURL):
* fileapi/ThreadableBlobRegistry.h:
Plumbing to make this version of registerBlobURL return a size. I may make size
calculation lazy and the function async later, but this is needed to move the behavior
to the right place first.

* fileapi/WebKitBlobBuilder.h:
* fileapi/WebKitBlobBuilder.cpp:
(WebCore::BlobBuilder::BlobBuilder):
(WebCore::BlobBuilder::append):
(WebCore::BlobBuilder::appendBytesData):
(WebCore::BlobBuilder::finalize):
(WebCore::BlobBuilder::getBlob): Deleted.
Don't track sizes or modification times, registry will do that with appropriate laziness.
Cleaned up the API - now that BlobBuilder is not exposed to JS as an object, it
does not need to be reusable.

* platform/network/BlobRegistry.h: Made this version of registerBlobURL return a size.
* platform/network/BlobRegistryImpl.h:
* platform/network/BlobRegistryImpl.cpp:
(WebCore::BlobRegistryImpl::appendStorageItems): Assert that length computations are accurate.
(WebCore::BlobRegistryImpl::registerBlobURL): Compute a size to return, and record
modification time as necessary.

* xml/XMLHttpRequest.cpp: (WebCore::XMLHttpRequest::responseBlob): Don't pass the
size, which can be computed from data. Soon, I want to add a constructor that doesn't
require wrapping a single Vector as BlobData to construct a Blob.

Source/WebKit2:
Plumbing to make this version of registerBlobURL synchronous for now.
I expect to make it async again when data structures on client side are simplified.

* NetworkProcess/FileAPI/NetworkBlobRegistry.cpp:
(WebKit::NetworkBlobRegistry::registerBlobURL):
* NetworkProcess/FileAPI/NetworkBlobRegistry.h:
* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::registerBlobURL):
* NetworkProcess/NetworkConnectionToWebProcess.h:
* NetworkProcess/NetworkConnectionToWebProcess.messages.in:
* WebProcess/FileAPI/BlobRegistryProxy.cpp:
(WebKit::BlobRegistryProxy::registerBlobURL):
* WebProcess/FileAPI/BlobRegistryProxy.h:

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

23 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/websockets/WebSocket.cpp
Source/WebCore/bindings/js/JSBlobCustom.cpp
Source/WebCore/fileapi/Blob.cpp
Source/WebCore/fileapi/Blob.h
Source/WebCore/fileapi/File.cpp
Source/WebCore/fileapi/File.h
Source/WebCore/fileapi/ThreadableBlobRegistry.cpp
Source/WebCore/fileapi/ThreadableBlobRegistry.h
Source/WebCore/fileapi/WebKitBlobBuilder.cpp
Source/WebCore/fileapi/WebKitBlobBuilder.h
Source/WebCore/platform/network/BlobRegistry.h
Source/WebCore/platform/network/BlobRegistryImpl.cpp
Source/WebCore/platform/network/BlobRegistryImpl.h
Source/WebCore/xml/XMLHttpRequest.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.cpp
Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.h
Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp
Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.h
Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.messages.in
Source/WebKit2/WebProcess/FileAPI/BlobRegistryProxy.cpp
Source/WebKit2/WebProcess/FileAPI/BlobRegistryProxy.h

index caaa38d..91e14a4 100644 (file)
@@ -1,3 +1,56 @@
+2014-05-01  Alexey Proskuryakov  <ap@apple.com>
+
+        Move size computation for Blob constructor into BlobRegistryImpl
+        https://bugs.webkit.org/show_bug.cgi?id=132439
+
+        Reviewed by Sam Weinig.
+
+        * Modules/websockets/WebSocket.cpp: (WebCore::WebSocket::didReceiveBinaryData):
+        Don't pass the size, anyone who cares can get it from BlobData.
+
+        * bindings/js/JSBlobCustom.cpp: (WebCore::JSBlobConstructor::constructJSBlob):
+        Updated for BlobBuilder changes.
+
+        * fileapi/Blob.cpp: (WebCore::Blob::Blob):
+        * fileapi/Blob.h: (WebCore::Blob::create):
+        No longer take a precomputed size with BlobData, BlobRegistry will compute it as
+        part of registration.
+
+        * fileapi/File.h:
+        * fileapi/File.cpp:
+        (WebCore::File::File): Don't pass a size (that's unknown anyway).
+        (WebCore::File::captureSnapshot): Deleted. Finally, only the registry is responsible
+        for snapshot tracking now (I doubt that either new or old code is particularly compliant).
+
+        * fileapi/ThreadableBlobRegistry.cpp:
+        (WebCore::ThreadableBlobRegistry::registerBlobURL):
+        * fileapi/ThreadableBlobRegistry.h:
+        Plumbing to make this version of registerBlobURL return a size. I may make size
+        calculation lazy and the function async later, but this is needed to move the behavior
+        to the right place first.
+
+        * fileapi/WebKitBlobBuilder.h:
+        * fileapi/WebKitBlobBuilder.cpp:
+        (WebCore::BlobBuilder::BlobBuilder):
+        (WebCore::BlobBuilder::append):
+        (WebCore::BlobBuilder::appendBytesData):
+        (WebCore::BlobBuilder::finalize):
+        (WebCore::BlobBuilder::getBlob): Deleted.
+        Don't track sizes or modification times, registry will do that with appropriate laziness.
+        Cleaned up the API - now that BlobBuilder is not exposed to JS as an object, it
+        does not need to be reusable.
+
+        * platform/network/BlobRegistry.h: Made this version of registerBlobURL return a size.
+        * platform/network/BlobRegistryImpl.h:
+        * platform/network/BlobRegistryImpl.cpp:
+        (WebCore::BlobRegistryImpl::appendStorageItems): Assert that length computations are accurate.
+        (WebCore::BlobRegistryImpl::registerBlobURL): Compute a size to return, and record
+        modification time as necessary.
+
+        * xml/XMLHttpRequest.cpp: (WebCore::XMLHttpRequest::responseBlob): Don't pass the
+        size, which can be computed from data. Soon, I want to add a constructor that doesn't
+        require wrapping a single Vector as BlobData to construct a Blob.
+
 2014-05-01  Eric Carlson  <eric.carlson@apple.com>
 
         [iOS] audio and video should automatically play to active external device
index 33e9a3f..cbb529d 100644 (file)
@@ -521,10 +521,10 @@ void WebSocket::didReceiveBinaryData(PassOwnPtr<Vector<char>> binaryData)
     LOG(Network, "WebSocket %p didReceiveBinaryData() %lu byte binary message", this, static_cast<unsigned long>(binaryData->size()));
     switch (m_binaryType) {
     case BinaryTypeBlob: {
-        size_t size = binaryData->size();
+        // FIXME: We just received the data from NetworkProcess, and are sending it back. This is inefficient.
         auto blobData = std::make_unique<BlobData>();
         blobData->appendData(RawData::create(std::move(*binaryData)), 0, BlobDataItem::toEndOfFile);
-        RefPtr<Blob> blob = Blob::create(std::move(blobData), size);
+        RefPtr<Blob> blob = Blob::create(std::move(blobData));
         dispatchEvent(MessageEvent::create(blob.release(), SecurityOrigin::create(m_url)->toString()));
         break;
     }
index d65d380..f2389cb 100644 (file)
@@ -134,7 +134,13 @@ EncodedJSValue JSC_HOST_CALL JSBlobConstructor::constructJSBlob(ExecState* exec)
         }
     }
 
-    RefPtr<Blob> blob = blobBuilder.getBlob(type);
+    BlobDataItemList items = blobBuilder.finalize();
+    auto blobData = std::make_unique<BlobData>();
+    blobData->setContentType(Blob::normalizedContentType(type));
+    blobData->swapItems(items);
+
+    RefPtr<Blob> blob = Blob::create(std::move(blobData));
+
     return JSValue::encode(CREATE_DOM_WRAPPER(jsConstructor->globalObject(), Blob, blob.get()));
 }
 
index e7fb875..40cc54a 100644 (file)
@@ -77,15 +77,14 @@ Blob::Blob()
     ThreadableBlobRegistry::registerBlobURL(m_internalURL, std::move(blobData));
 }
 
-Blob::Blob(std::unique_ptr<BlobData> blobData, long long size)
+Blob::Blob(std::unique_ptr<BlobData> blobData)
     : m_type(blobData->contentType())
-    , m_size(size)
 {
     ASSERT(blobData);
 
     // Create a new internal URL and register it with the provided blob data.
     m_internalURL = BlobURL::createInternalURL();
-    ThreadableBlobRegistry::registerBlobURL(m_internalURL, std::move(blobData));
+    m_size = ThreadableBlobRegistry::registerBlobURL(m_internalURL, std::move(blobData));
 }
 
 Blob::Blob(const URL& srcURL, const String& type, long long size)
index 98e50af..5dde3dd 100644 (file)
@@ -50,9 +50,9 @@ public:
         return adoptRef(new Blob);
     }
 
-    static PassRefPtr<Blob> create(std::unique_ptr<BlobData> blobData, long long size)
+    static PassRefPtr<Blob> create(std::unique_ptr<BlobData> blobData)
     {
-        return adoptRef(new Blob(std::move(blobData), size));
+        return adoptRef(new Blob(std::move(blobData)));
     }
 
     // For deserialization.
@@ -90,7 +90,7 @@ public:
 
 protected:
     Blob();
-    Blob(std::unique_ptr<BlobData>, long long size);
+    Blob(std::unique_ptr<BlobData>);
 
     // For deserialization.
     Blob(const URL& srcURL, const String& type, long long size);
index 5fe1f2d..9de40e6 100644 (file)
@@ -55,7 +55,7 @@ static std::unique_ptr<BlobData> createBlobDataForFileWithName(const String& pat
 }
 
 File::File(const String& path, ContentTypeLookupPolicy policy)
-    : Blob(createBlobDataForFile(path, policy), -1)
+    : Blob(createBlobDataForFile(path, policy))
     , m_path(path)
     , m_name(pathGetFileName(path))
 {
@@ -72,7 +72,7 @@ File::File(const String& path, const URL& url, const String& type)
 }
 
 File::File(const String& path, const String& name, ContentTypeLookupPolicy policy)
-    : Blob(createBlobDataForFileWithName(path, name, policy), -1)
+    : Blob(createBlobDataForFileWithName(path, name, policy))
     , m_path(path)
     , m_name(name)
 {
@@ -97,21 +97,6 @@ unsigned long long File::size() const
     return static_cast<unsigned long long>(size);
 }
 
-void File::captureSnapshot(long long& snapshotSize, double& snapshotModificationTime) const
-{
-    // Obtains a snapshot of the file by capturing its current size and modification time. This is used when we slice a file for the first time.
-    // If we fail to retrieve the size or modification time, probably due to that the file has been deleted, 0 size is returned.
-    FileMetadata metadata;
-    if (!getFileMetadata(m_path, metadata)) {
-        snapshotSize = 0;
-        snapshotModificationTime = invalidFileTime();
-        return;
-    }
-
-    snapshotSize = metadata.length;
-    snapshotModificationTime = metadata.modificationTime;
-}
-
 String File::contentTypeFromFilePath(const String& name, File::ContentTypeLookupPolicy policy)
 {
     String type;
index 51df4b0..590c3b4 100644 (file)
@@ -72,9 +72,6 @@ public:
     // This returns the current date and time if the file's last modifiecation date is not known (per spec: http://www.w3.org/TR/FileAPI/#dfn-lastModifiedDate).
     double lastModifiedDate() const;
 
-    // Note that this involves synchronous file operation. Think twice before calling this function.
-    void captureSnapshot(long long& snapshotSize, double& snapshotModificationTime) const;
-
     static String contentTypeFromFilePath(const String&, ContentTypeLookupPolicy);
 
 private:
index cc04b2d..001b4b3 100644 (file)
@@ -88,18 +88,23 @@ static ThreadSpecific<BlobUrlOriginMap>& originMap()
     return *map;
 }
 
-void ThreadableBlobRegistry::registerBlobURL(const URL& url, std::unique_ptr<BlobData> blobData)
+unsigned long long ThreadableBlobRegistry::registerBlobURL(const URL& url, std::unique_ptr<BlobData> blobData)
 {
+    unsigned long long resultSize;
     if (isMainThread())
-        blobRegistry().registerBlobURL(url, std::move(blobData));
+        resultSize = blobRegistry().registerBlobURL(url, std::move(blobData));
     else {
         // BlobRegistryContext performs an isolated copy of data.
         BlobRegistryContext* context = new BlobRegistryContext(url, std::move(blobData));
-        callOnMainThread([context] {
+        BinarySemaphore semaphore;
+        callOnMainThread([context, &semaphore, &resultSize] {
             std::unique_ptr<BlobRegistryContext> blobRegistryContext(context);
-            blobRegistry().registerBlobURL(blobRegistryContext->url, std::move(blobRegistryContext->blobData));
+            resultSize = blobRegistry().registerBlobURL(blobRegistryContext->url, std::move(blobRegistryContext->blobData));
+            semaphore.signal();
         });
+        semaphore.wait(std::numeric_limits<double>::max());
     }
+    return resultSize;
 }
 
 void ThreadableBlobRegistry::registerBlobURL(SecurityOrigin* origin, const URL& url, const URL& srcURL)
@@ -163,7 +168,7 @@ PassRefPtr<SecurityOrigin> ThreadableBlobRegistry::getCachedOrigin(const URL& ur
 
 #else
 
-void ThreadableBlobRegistry::registerBlobURL(const URL&, std::unique_ptr<BlobData>)
+unsigned long long ThreadableBlobRegistry::registerBlobURL(const URL&, std::unique_ptr<BlobData>)
 {
 }
 
@@ -171,6 +176,10 @@ void ThreadableBlobRegistry::registerBlobURL(SecurityOrigin*, const URL&, const
 {
 }
 
+unsigned long long ThreadableBlobRegistry::registerBlobURLForSlice(const URL&, const URL&, long long, long long)
+{
+}
+
 void ThreadableBlobRegistry::unregisterBlobURL(const URL&)
 {
 }
index bcc896c..a1302f1 100644 (file)
@@ -41,7 +41,7 @@ class SecurityOrigin;
 
 class ThreadableBlobRegistry {
 public:
-    static void registerBlobURL(const URL&, std::unique_ptr<BlobData>);
+    static unsigned long long registerBlobURL(const URL&, std::unique_ptr<BlobData>);
     static void registerBlobURL(SecurityOrigin*, const URL&, const URL& srcURL);
     static void unregisterBlobURL(const URL&);
 
index 2505e31..35a43f4 100644 (file)
@@ -55,7 +55,6 @@ enum BlobConstructorArrayBufferOrView {
 };
 
 BlobBuilder::BlobBuilder()
-    : m_size(0)
 {
 }
 
@@ -63,15 +62,12 @@ void BlobBuilder::append(const String& text, const String& endingType)
 {
     CString utf8Text = UTF8Encoding().encode(text, EntitiesForUnencodables);
 
-    size_t oldSize = m_appendableData.size();
-
     if (endingType == "native")
         normalizeLineEndingsToNative(utf8Text, m_appendableData);
     else {
         ASSERT(endingType == "transparent");
         m_appendableData.append(utf8Text.data(), utf8Text.length());
     }
-    m_size += m_appendableData.size() - oldSize;
 }
 
 #if ENABLE(BLOB)
@@ -104,44 +100,23 @@ void BlobBuilder::append(Blob* blob)
         m_items.append(BlobDataItem(RawData::create(std::move(m_appendableData))));
     if (blob->isFile()) {
         File* file = toFile(blob);
-        // If the blob is file that is not snapshoted, capture the snapshot now.
-        // FIXME: This involves synchronous file operation. We need to figure out how to make it asynchronous.
-        long long snapshotSize;
-        double snapshotModificationTime;
-        file->captureSnapshot(snapshotSize, snapshotModificationTime);
-
-        m_size += snapshotSize;
-        m_items.append(BlobDataItem(file->path(), 0, snapshotSize, snapshotModificationTime));
+        m_items.append(BlobDataItem(file->path(), 0, BlobDataItem::toEndOfFile, invalidFileTime()));
     } else {
         long long blobSize = static_cast<long long>(blob->size());
-        m_size += blobSize;
         m_items.append(BlobDataItem(blob->url(), 0, blobSize));
     }
 }
 
 void BlobBuilder::appendBytesData(const void* data, size_t length)
 {
-    size_t oldSize = m_appendableData.size();
     m_appendableData.append(static_cast<const char*>(data), length);
-    m_size += m_appendableData.size() - oldSize;
 }
 
-PassRefPtr<Blob> BlobBuilder::getBlob(const String& contentType)
+BlobDataItemList BlobBuilder::finalize()
 {
     if (!m_appendableData.isEmpty())
         m_items.append(BlobDataItem(RawData::create(std::move(m_appendableData))));
-
-    auto blobData = std::make_unique<BlobData>();
-    blobData->setContentType(Blob::normalizedContentType(contentType));
-    blobData->swapItems(m_items);
-
-    RefPtr<Blob> blob = Blob::create(std::move(blobData), m_size);
-
-    // After creating a blob from the current blob data, we do not need to keep the data around any more. Instead, we only
-    // need to keep a reference to the URL of the blob just created.
-    m_items.append(BlobDataItem(blob->url(), 0, m_size));
-
-    return blob;
+    return std::move(m_items);
 }
 
 } // namespace WebCore
index 15c3488..70f6e78 100644 (file)
@@ -42,9 +42,6 @@ class ArrayBufferView;
 namespace WebCore {
 
 class Blob;
-class TextEncoding;
-
-typedef int ExceptionCode;
 
 class BlobBuilder {
 public:
@@ -57,12 +54,11 @@ public:
     void append(PassRefPtr<JSC::ArrayBufferView>);
 #endif
 
-    PassRefPtr<Blob> getBlob(const String& contentType);
+    BlobDataItemList finalize();
 
 private:
     void appendBytesData(const void*, size_t);
 
-    long long m_size;
     BlobDataItemList m_items;
     Vector<char> m_appendableData;
 };
index 5cf7e14..5e75816 100644 (file)
@@ -46,7 +46,7 @@ BlobRegistry& blobRegistry();
 class BlobRegistry {
 public:
     // Registers a blob URL referring to the specified blob data.
-    virtual void registerBlobURL(const URL&, std::unique_ptr<BlobData>) = 0;
+    virtual unsigned long long registerBlobURL(const URL&, std::unique_ptr<BlobData>) = 0;
     
     // Registers a new blob URL referring to the blob data identified by the specified srcURL.
     virtual void registerBlobURL(const URL&, const URL& srcURL) = 0;
index 3042d7b..387d881 100644 (file)
@@ -113,9 +113,10 @@ void BlobRegistryImpl::appendStorageItems(BlobStorageData* blobStorageData, cons
         length -= newLength;
         offset = 0;
     }
+    ASSERT(!length);
 }
 
-void BlobRegistryImpl::registerBlobURL(const URL& url, std::unique_ptr<BlobData> blobData)
+unsigned long long BlobRegistryImpl::registerBlobURL(const URL& url, std::unique_ptr<BlobData> blobData)
 {
     ASSERT(isMainThread());
     registerBlobResourceHandleConstructor();
@@ -128,22 +129,42 @@ void BlobRegistryImpl::registerBlobURL(const URL& url, std::unique_ptr<BlobData>
     // 3) The URL item is denoted by the URL, the range and the expected modification time.
     // All the Blob items in the passing blob data are resolved and expanded into a set of Data and File items.
 
-    for (BlobDataItemList::const_iterator iter = blobData->items().begin(); iter != blobData->items().end(); ++iter) {
-        switch (iter->type) {
+    // FIXME: BlobDataItems contain a lot of information that we do not expect to be present when registering a new blob,
+    // these data members are only used inside the registry. Use a more appropriate type than BlobData.
+
+    unsigned long long size = 0;
+    for (const BlobDataItem& item : blobData->items()) {
+        switch (item.type) {
         case BlobDataItem::Data:
-            blobStorageData->m_data.appendData(iter->data, 0, iter->data->length());
+            blobStorageData->m_data.appendData(item.data, 0, item.data->length());
+            size += item.data->length();
             break;
-        case BlobDataItem::File:
-            blobStorageData->m_data.appendFile(iter->path, iter->offset, iter->length, iter->expectedModificationTime);
+        case BlobDataItem::File: {
+            ASSERT(!item.offset);
+            ASSERT(item.length == BlobDataItem::toEndOfFile);
+            ASSERT(!isValidFileTime(item.expectedModificationTime));
+
+            // FIXME: Factor out size and modification tracking for a cleaner implementation.
+            FileMetadata metadata;
+            if (!getFileMetadata(item.path, metadata))
+                return 0;
+
+            blobStorageData->m_data.appendFile(item.path, 0, metadata.length, metadata.modificationTime);
+            size += metadata.length;
             break;
+        }
         case BlobDataItem::Blob:
-            if (m_blobs.contains(iter->url.string()))
-                appendStorageItems(blobStorageData.get(), m_blobs.get(iter->url.string())->items(), iter->offset, iter->length);
+            if (!m_blobs.contains(item.url.string()))
+                return 0;
+            size += blobSize(item.url); // As a side effect, this calculates sizes of all files in the blob.
+            ASSERT(blobSize(item.url) == static_cast<unsigned long long>(item.length));
+            appendStorageItems(blobStorageData.get(), m_blobs.get(item.url.string())->items(), item.offset, item.length);
             break;
         }
     }
 
     m_blobs.set(url.string(), blobStorageData);
+    return size;
 }
 
 void BlobRegistryImpl::registerBlobURL(const URL& url, const URL& srcURL)
@@ -152,7 +173,6 @@ void BlobRegistryImpl::registerBlobURL(const URL& url, const URL& srcURL)
     registerBlobResourceHandleConstructor();
 
     RefPtr<BlobStorageData> src = m_blobs.get(srcURL.string());
-    ASSERT(src);
     if (!src)
         return;
 
index 65f744c..1106b85 100644 (file)
@@ -57,7 +57,7 @@ public:
 private:
     void appendStorageItems(BlobStorageData*, const BlobDataItemList&, long long offset, long long length);
 
-    virtual void registerBlobURL(const URL&, std::unique_ptr<BlobData>) override;
+    virtual unsigned long long registerBlobURL(const URL&, std::unique_ptr<BlobData>) override;
     virtual void registerBlobURL(const URL&, const URL& srcURL) override;
     virtual unsigned long long registerBlobURLForSlice(const URL&, const URL& srcURL, long long start, long long end) override;
     virtual void unregisterBlobURL(const URL&) override;
index 948d6c1..6387a79 100644 (file)
@@ -296,7 +296,7 @@ Blob* XMLHttpRequest::responseBlob()
             String normalizedContentType = Blob::normalizedContentType(responseMIMEType());
             blobData->setContentType(normalizedContentType); // responseMIMEType defaults to text/xml which may be incorrect.
             m_binaryResponseBuilder.clear();
-            m_responseBlob = Blob::create(std::move(blobData), size);
+            m_responseBlob = Blob::create(std::move(blobData));
         } else {
             // If we errored out or got no data, we still return a blob, just an empty one.
             m_responseBlob = Blob::create();
index 7e92967..aca35b9 100644 (file)
@@ -1,3 +1,24 @@
+2014-05-01  Alexey Proskuryakov  <ap@apple.com>
+
+        Move size computation for Blob constructor into BlobRegistryImpl
+        https://bugs.webkit.org/show_bug.cgi?id=132439
+
+        Reviewed by Sam Weinig.
+
+        Plumbing to make this version of registerBlobURL synchronous for now.
+        I expect to make it async again when data structures on client side are simplified.
+
+        * NetworkProcess/FileAPI/NetworkBlobRegistry.cpp:
+        (WebKit::NetworkBlobRegistry::registerBlobURL):
+        * NetworkProcess/FileAPI/NetworkBlobRegistry.h:
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::NetworkConnectionToWebProcess::registerBlobURL):
+        * NetworkProcess/NetworkConnectionToWebProcess.h:
+        * NetworkProcess/NetworkConnectionToWebProcess.messages.in:
+        * WebProcess/FileAPI/BlobRegistryProxy.cpp:
+        (WebKit::BlobRegistryProxy::registerBlobURL):
+        * WebProcess/FileAPI/BlobRegistryProxy.h:
+
 2014-05-01  Beth Dakin  <bdakin@apple.com>
 
         REGRESSION(168053): Repro crash navigating to another page after selecting phone 
index db0859d..6a0904a 100644 (file)
@@ -48,7 +48,7 @@ NetworkBlobRegistry::NetworkBlobRegistry()
 {
 }
 
-void NetworkBlobRegistry::registerBlobURL(NetworkConnectionToWebProcess* connection, const URL& url, std::unique_ptr<BlobData> data, const Vector<RefPtr<SandboxExtension>>& newSandboxExtensions)
+uint64_t NetworkBlobRegistry::registerBlobURL(NetworkConnectionToWebProcess* connection, const URL& url, std::unique_ptr<BlobData> data, const Vector<RefPtr<SandboxExtension>>& newSandboxExtensions)
 {
     ASSERT(!m_sandboxExtensions.contains(url.string()));
 
@@ -60,7 +60,7 @@ void NetworkBlobRegistry::registerBlobURL(NetworkConnectionToWebProcess* connect
             sandboxExtensions.appendVector(m_sandboxExtensions.get(items[i].url.string()));
     }
 
-    blobRegistry().registerBlobURL(url, std::move(data));
+    uint64_t resultSize = blobRegistry().registerBlobURL(url, std::move(data));
 
     if (!sandboxExtensions.isEmpty())
         m_sandboxExtensions.add(url.string(), sandboxExtensions);
@@ -70,6 +70,8 @@ void NetworkBlobRegistry::registerBlobURL(NetworkConnectionToWebProcess* connect
     if (mapIterator == m_blobsForConnection.end())
         mapIterator = m_blobsForConnection.add(connection, HashSet<URL>()).iterator;
     mapIterator->value.add(url);
+
+    return resultSize;
 }
 
 void NetworkBlobRegistry::registerBlobURL(NetworkConnectionToWebProcess* connection, const WebCore::URL& url, const WebCore::URL& srcURL)
index ee5bb0a..714c755 100644 (file)
@@ -47,7 +47,7 @@ public:
     NetworkBlobRegistry();
     static NetworkBlobRegistry& shared();
 
-    void registerBlobURL(NetworkConnectionToWebProcess*, const WebCore::URL&, std::unique_ptr<WebCore::BlobData>, const Vector<RefPtr<SandboxExtension>>&);
+    uint64_t registerBlobURL(NetworkConnectionToWebProcess*, const WebCore::URL&, std::unique_ptr<WebCore::BlobData>, const Vector<RefPtr<SandboxExtension>>&);
     void registerBlobURL(NetworkConnectionToWebProcess*, const WebCore::URL&, const WebCore::URL& srcURL);
     uint64_t registerBlobURLForSlice(NetworkConnectionToWebProcess*, const WebCore::URL&, const WebCore::URL& srcURL, int64_t start, int64_t end);
     void unregisterBlobURL(NetworkConnectionToWebProcess*, const WebCore::URL&);
index 087da05..516ff73 100644 (file)
@@ -225,7 +225,7 @@ void NetworkConnectionToWebProcess::deleteCookie(SessionID sessionID, const URL&
 }
 
 #if ENABLE(BLOB)
-void NetworkConnectionToWebProcess::registerBlobURL(const URL& url, const BlobRegistrationData& data)
+void NetworkConnectionToWebProcess::registerBlobURL(const URL& url, const BlobRegistrationData& data, uint64_t& resultSize)
 {
     Vector<RefPtr<SandboxExtension>> extensions;
     for (size_t i = 0, count = data.sandboxExtensions().size(); i < count; ++i) {
@@ -233,7 +233,7 @@ void NetworkConnectionToWebProcess::registerBlobURL(const URL& url, const BlobRe
             extensions.append(extension);
     }
 
-    NetworkBlobRegistry::shared().registerBlobURL(this, url, data.releaseData(), extensions);
+    resultSize = NetworkBlobRegistry::shared().registerBlobURL(this, url, data.releaseData(), extensions);
 }
 
 void NetworkConnectionToWebProcess::registerBlobURLFromURL(const URL& url, const URL& srcURL)
index 34379b2..699cc43 100644 (file)
@@ -88,7 +88,7 @@ private:
     void deleteCookie(WebCore::SessionID, const WebCore::URL&, const String& cookieName);
 
 #if ENABLE(BLOB)
-    void registerBlobURL(const WebCore::URL&, const BlobRegistrationData&);
+    void registerBlobURL(const WebCore::URL&, const BlobRegistrationData&, uint64_t& resultSize);
     void registerBlobURLFromURL(const WebCore::URL&, const WebCore::URL& srcURL);
     void registerBlobURLForSlice(const WebCore::URL&, const WebCore::URL& srcURL, int64_t start, int64_t end, uint64_t& resultSize);
     void unregisterBlobURL(const WebCore::URL&);
index 0f18e49..72e451a 100644 (file)
@@ -44,7 +44,7 @@ messages -> NetworkConnectionToWebProcess LegacyReceiver {
     DeleteCookie(WebCore::SessionID sessionID, WebCore::URL url, String cookieName)
 
 #if ENABLE(BLOB)
-    RegisterBlobURL(WebCore::URL url, WebKit::BlobRegistrationData data)
+    RegisterBlobURL(WebCore::URL url, WebKit::BlobRegistrationData data) -> (uint64_t resultSize)
     RegisterBlobURLFromURL(WebCore::URL url, WebCore::URL srcURL)
     RegisterBlobURLForSlice(WebCore::URL url, WebCore::URL srcURL, int64_t start, int64_t end) -> (uint64_t resultSize)
     UnregisterBlobURL(WebCore::URL url)
index 51ce5a0..5596cce 100644 (file)
@@ -39,11 +39,14 @@ using namespace WebCore;
 
 namespace WebKit {
 
-void BlobRegistryProxy::registerBlobURL(const URL& url, std::unique_ptr<BlobData> blobData)
+unsigned long long BlobRegistryProxy::registerBlobURL(const URL& url, std::unique_ptr<BlobData> blobData)
 {
     ASSERT(WebProcess::shared().usesNetworkProcess());
 
-    WebProcess::shared().networkConnection()->connection()->send(Messages::NetworkConnectionToWebProcess::RegisterBlobURL(url, BlobRegistrationData(std::move(blobData))), 0);
+    uint64_t resultSize;
+    if (!WebProcess::shared().networkConnection()->connection()->sendSync(Messages::NetworkConnectionToWebProcess::RegisterBlobURL(url, BlobRegistrationData(std::move(blobData))), Messages::NetworkConnectionToWebProcess::RegisterBlobURL::Reply(resultSize), 0))
+        return 0;
+    return resultSize;
 }
 
 void BlobRegistryProxy::registerBlobURL(const URL& url, const URL& srcURL)
index 3bfa6d5..037fb3e 100644 (file)
@@ -34,7 +34,7 @@ namespace WebKit {
 
 class BlobRegistryProxy : public WebCore::BlobRegistry {
 public:
-    virtual void registerBlobURL(const WebCore::URL&, std::unique_ptr<WebCore::BlobData>) override;
+    virtual unsigned long long registerBlobURL(const WebCore::URL&, std::unique_ptr<WebCore::BlobData>) override;
     virtual void registerBlobURL(const WebCore::URL&, const WebCore::URL& srcURL) override;
     virtual void unregisterBlobURL(const WebCore::URL&) override;
     virtual unsigned long long registerBlobURLForSlice(const WebCore::URL&, const WebCore::URL& srcURL, long long start, long long end) override;