Title: [97219] trunk
Revision
97219
Author
[email protected]
Date
2011-10-11 19:26:45 -0700 (Tue, 11 Oct 2011)

Log Message

[Soup] ResourceHandleSoup does not handle encodedBlobData
https://bugs.webkit.org/show_bug.cgi?id=52092

Reviewed by Gustavo Noronha Silva.

Source/WebCore:

Add support for sending encoded blob data during requests.

* platform/network/soup/ResourceHandleSoup.cpp:
(WebCore::addFileToSoupMessageBody): Added this helper.
(WebCore::blobIsOutOfDate): Ditto.
(WebCore::addEncodedBlobItemToSoupMessageBody): Ditto.
(WebCore::addEncodedBlobToSoupMessageBody): Ditto.
(WebCore::addFormElementsToSoupMessage): No longer flatten form data, as we
cannot do this in the case where the form data contains blobs. Now handle
the blob case.
(WebCore::loadResourceSynchronously): Add blob support for synchronous loading.

LayoutTests:

* platform/gtk/Skipped: Unskip tests which are now passing.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (97218 => 97219)


--- trunk/LayoutTests/ChangeLog	2011-10-12 02:05:53 UTC (rev 97218)
+++ trunk/LayoutTests/ChangeLog	2011-10-12 02:26:45 UTC (rev 97219)
@@ -1,3 +1,12 @@
+2011-10-11  Martin Robinson  <[email protected]>
+
+        [Soup] ResourceHandleSoup does not handle encodedBlobData
+        https://bugs.webkit.org/show_bug.cgi?id=52092
+
+        Reviewed by Gustavo Noronha Silva.
+
+        * platform/gtk/Skipped: Unskip tests which are now passing.
+
 2011-10-11  Ryosuke Niwa  <[email protected]>
 
         Fix Chromium test expectations.

Modified: trunk/LayoutTests/platform/gtk/Skipped (97218 => 97219)


--- trunk/LayoutTests/platform/gtk/Skipped	2011-10-12 02:05:53 UTC (rev 97218)
+++ trunk/LayoutTests/platform/gtk/Skipped	2011-10-12 02:26:45 UTC (rev 97219)
@@ -191,9 +191,6 @@
 # This test crashes whatever test follows it. Perhaps it's related to the previous failure.
 fast/dom/gc-10.html
 
-# https://bugs.webkit.org/show_bug.cgi?id=54234 
-fast/files/apply-blob-url-to-xhr.html
-
 # https://bugs.webkit.org/show_bug.cgi?id=50744
 inspector/debugger/open-close-open.html
 
@@ -391,10 +388,7 @@
 # FileSystem API is not supported.
 fast/filesystem
 http/tests/filesystem
-http/tests/local/fileapi
 http/tests/security/filesystem-iframe-from-remote.html
-http/tests/websocket/tests/hybi/send-file-blob.html
-http/tests/websocket/tests/hybi/send-file-blob-fail.html
 
 # Requires WebP support.
 fast/images/webp-image-decoding.html
@@ -1315,13 +1309,6 @@
 # Should recheck it when the above bug is fixed.
 fast/files/workers/worker-apply-blob-url-to-xhr.html
 
-# [Soup] ResourceHandleSoup does not handle encodedBlobData
-# https://bugs.webkit.org/show_bug.cgi?id=52092
-http/tests/local/blob/send-data-blob.html
-http/tests/local/blob/send-hybrid-blob.html
-http/tests/local/blob/send-sliced-data-blob.html
-http/tests/local/formdata/send-form-data-with-sliced-file.html
-
 # [GTK] Dragging images and links results in a DataTransfer object containing a non-empty files array
 # https://bugs.webkit.org/show_bug.cgi?id=52094
 editing/pasteboard/files-during-page-drags.html
@@ -1689,3 +1676,8 @@
 # REGRESSION(r96870): editing/pasteboard/smart-paste-008.html fails on non-Mac
 # https://bugs.webkit.org/show_bug.cgi?id=69587
 editing/pasteboard/smart-paste-008.html
+
+# Some tests fail with  "FAIL Unexpected response data received: Wrong method: GET"
+# https://bugs.webkit.org/show_bug.cgi?id=69219
+http/tests/local/fileapi/send-sliced-dragged-file.html  
+http/tests/local/blob/send-hybrid-blob.html

Modified: trunk/Source/WebCore/ChangeLog (97218 => 97219)


--- trunk/Source/WebCore/ChangeLog	2011-10-12 02:05:53 UTC (rev 97218)
+++ trunk/Source/WebCore/ChangeLog	2011-10-12 02:26:45 UTC (rev 97219)
@@ -1,3 +1,22 @@
+2011-10-11  Martin Robinson  <[email protected]>
+
+        [Soup] ResourceHandleSoup does not handle encodedBlobData
+        https://bugs.webkit.org/show_bug.cgi?id=52092
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Add support for sending encoded blob data during requests.
+
+        * platform/network/soup/ResourceHandleSoup.cpp:
+        (WebCore::addFileToSoupMessageBody): Added this helper.
+        (WebCore::blobIsOutOfDate): Ditto.
+        (WebCore::addEncodedBlobItemToSoupMessageBody): Ditto.
+        (WebCore::addEncodedBlobToSoupMessageBody): Ditto.
+        (WebCore::addFormElementsToSoupMessage): No longer flatten form data, as we
+        cannot do this in the case where the form data contains blobs. Now handle
+        the blob case.
+        (WebCore::loadResourceSynchronously): Add blob support for synchronous loading.
+
 2011-10-11  Chris Rogers  <[email protected]>
 
         Heap buffer overflow in Webaudio FFTFrame::doFFT

Modified: trunk/Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp (97218 => 97219)


--- trunk/Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp	2011-10-12 02:05:53 UTC (rev 97218)
+++ trunk/Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp	2011-10-12 02:26:45 UTC (rev 97219)
@@ -58,6 +58,12 @@
 #include <unistd.h>
 #include <wtf/text/CString.h>
 
+#if ENABLE(BLOB)
+#include "BlobData.h"
+#include "BlobRegistryImpl.h"
+#include "BlobStorageData.h"
+#endif
+
 namespace WebCore {
 
 #define READ_BUFFER_SIZE 8192
@@ -514,20 +520,80 @@
                               G_PRIORITY_DEFAULT, d->m_cancellable.get(), readCallback, 0);
 }
 
-static bool addFormElementsToSoupMessage(SoupMessage* message, const char* contentType, FormData* httpBody, unsigned long& totalBodySize)
+static bool addFileToSoupMessageBody(SoupMessage* message, const String& fileNameString, size_t offset, size_t lengthToSend, unsigned long& totalBodySize)
 {
-    size_t numElements = httpBody->elements().size();
-    if (numElements < 2) { // No file upload is the most common case.
-        Vector<char> body;
-        httpBody->flatten(body);
-        totalBodySize = body.size();
-        soup_message_set_request(message, contentType, SOUP_MEMORY_COPY, body.data(), body.size());
+    GOwnPtr<GError> error;
+    CString fileName = fileSystemRepresentation(fileNameString);
+    GMappedFile* fileMapping = g_mapped_file_new(fileName.data(), false, &error.outPtr());
+    if (error)
+        return false;
+
+    gsize bufferLength = lengthToSend;
+    if (!lengthToSend)
+        bufferLength = g_mapped_file_get_length(fileMapping);
+    totalBodySize += bufferLength;
+
+    SoupBuffer* soupBuffer = soup_buffer_new_with_owner(g_mapped_file_get_contents(fileMapping) + offset,
+                                                        bufferLength,
+                                                        fileMapping,
+                                                        reinterpret_cast<GDestroyNotify>(g_mapped_file_unref));
+    soup_message_body_append_buffer(message->request_body, soupBuffer);
+    soup_buffer_free(soupBuffer);
+    return true;
+}
+
+#if ENABLE(BLOB)
+static bool blobIsOutOfDate(const BlobDataItem& blobItem)
+{
+    ASSERT(blobItem.type == BlobDataItem::File);
+    if (blobItem.expectedModificationTime == BlobDataItem::doNotCheckFileChange)
+        return false;
+
+    time_t fileModificationTime;
+    if (!getFileModificationTime(blobItem.path, fileModificationTime))
         return true;
+
+    return fileModificationTime != static_cast<time_t>(blobItem.expectedModificationTime);
+}
+
+static bool addEncodedBlobItemToSoupMessageBody(SoupMessage* message, const BlobDataItem& blobItem, unsigned long& totalBodySize)
+{
+    if (blobItem.type == BlobDataItem::Data) {
+        totalBodySize += blobItem.length;
+        soup_message_body_append(message->request_body, SOUP_MEMORY_TEMPORARY,
+                                 blobItem.data->data() + blobItem.offset, blobItem.length);
+        return true;
     }
 
-    // We have more than one element to upload, and some may be large files,
-    // which we will want to mmap instead of copying into memory
+    ASSERT(blobItem.type == BlobDataItem::File);
+    if (blobIsOutOfDate(blobItem))
+        return false;
+
+    return addFileToSoupMessageBody(message,
+                                    blobItem.path,
+                                    blobItem.offset,
+                                    blobItem.length == BlobDataItem::toEndOfFile ? 0 : blobItem.length,
+                                    totalBodySize);
+}
+
+static bool addEncodedBlobToSoupMessageBody(SoupMessage* message, const FormDataElement& element, unsigned long& totalBodySize)
+{
+    RefPtr<BlobStorageData> blobData = static_cast<BlobRegistryImpl&>(blobRegistry()).getBlobDataFromURL(KURL(ParsedURLString, element.m_blobURL));
+    if (!blobData)
+        return true;
+
+    for (size_t i = 0; i < blobData->items().size(); ++i)
+        if (!addEncodedBlobItemToSoupMessageBody(message, blobData->items()[i], totalBodySize))
+            return false;
+
+    return true;
+}
+#endif // ENABLE(BLOB)
+
+static bool addFormElementsToSoupMessage(SoupMessage* message, const char* contentType, FormData* httpBody, unsigned long& totalBodySize)
+{
     soup_message_body_set_accumulate(message->request_body, FALSE);
+    size_t numElements = httpBody->elements().size();
     for (size_t i = 0; i < numElements; i++) {
         const FormDataElement& element = httpBody->elements()[i];
 
@@ -538,22 +604,22 @@
             continue;
         }
 
-        // This technique is inspired by libsoup's simple-httpd test.
-        GOwnPtr<GError> error;
-        CString fileName = fileSystemRepresentation(element.m_filename);
-        GMappedFile* fileMapping = g_mapped_file_new(fileName.data(), false, &error.outPtr());
-        if (error)
+        if (element.m_type == FormDataElement::encodedFile) {
+            if (!addFileToSoupMessageBody(message ,
+                                         element.m_filename,
+                                         0 /* offset */,
+                                         0 /* lengthToSend */,
+                                         totalBodySize))
+                return false;
+            continue;
+        }
+
+#if ENABLE(BLOB)
+        ASSERT(element.m_type == FormDataElement::encodedBlob);
+        if (!addEncodedBlobToSoupMessageBody(message, element, totalBodySize))
             return false;
-
-        gsize mappedFileSize = g_mapped_file_get_length(fileMapping);
-        totalBodySize += mappedFileSize;
-        SoupBuffer* soupBuffer = soup_buffer_new_with_owner(g_mapped_file_get_contents(fileMapping),
-                                                            mappedFileSize, fileMapping,
-                                                            reinterpret_cast<GDestroyNotify>(g_mapped_file_unref));
-        soup_message_body_append_buffer(message->request_body, soupBuffer);
-        soup_buffer_free(soupBuffer);
+#endif
     }
-
     return true;
 }
 
@@ -730,6 +796,13 @@
 
 void ResourceHandle::loadResourceSynchronously(NetworkingContext* context, const ResourceRequest& request, StoredCredentials /*storedCredentials*/, ResourceError& error, ResourceResponse& response, Vector<char>& data)
 {
+#if ENABLE(BLOB)
+    if (request.url().protocolIs("blob")) {
+        blobRegistry().loadResourceSynchronously(request, error, response, data);
+        return;
+    }
+#endif
+
     WebCoreSynchronousLoader syncLoader(error, response, data);
     RefPtr<ResourceHandle> handle = create(context, request, &syncLoader, false /*defersLoading*/, false /*shouldContentSniff*/);
     if (!handle)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to