Changeset 97219 in webkit


Ignore:
Timestamp:
Oct 11, 2011 7:26:45 PM (13 years ago)
Author:
Martin Robinson
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.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r97209 r97219  
     12011-10-11  Martin Robinson  <mrobinson@igalia.com>
     2
     3        [Soup] ResourceHandleSoup does not handle encodedBlobData
     4        https://bugs.webkit.org/show_bug.cgi?id=52092
     5
     6        Reviewed by Gustavo Noronha Silva.
     7
     8        * platform/gtk/Skipped: Unskip tests which are now passing.
     9
    1102011-10-11  Ryosuke Niwa  <rniwa@webkit.org>
    211
  • trunk/LayoutTests/platform/gtk/Skipped

    r97159 r97219  
    191191# This test crashes whatever test follows it. Perhaps it's related to the previous failure.
    192192fast/dom/gc-10.html
    193 
    194 # https://bugs.webkit.org/show_bug.cgi?id=54234
    195 fast/files/apply-blob-url-to-xhr.html
    196193
    197194# https://bugs.webkit.org/show_bug.cgi?id=50744
     
    392389fast/filesystem
    393390http/tests/filesystem
    394 http/tests/local/fileapi
    395391http/tests/security/filesystem-iframe-from-remote.html
    396 http/tests/websocket/tests/hybi/send-file-blob.html
    397 http/tests/websocket/tests/hybi/send-file-blob-fail.html
    398392
    399393# Requires WebP support.
     
    13161310fast/files/workers/worker-apply-blob-url-to-xhr.html
    13171311
    1318 # [Soup] ResourceHandleSoup does not handle encodedBlobData
    1319 # https://bugs.webkit.org/show_bug.cgi?id=52092
    1320 http/tests/local/blob/send-data-blob.html
    1321 http/tests/local/blob/send-hybrid-blob.html
    1322 http/tests/local/blob/send-sliced-data-blob.html
    1323 http/tests/local/formdata/send-form-data-with-sliced-file.html
    1324 
    13251312# [GTK] Dragging images and links results in a DataTransfer object containing a non-empty files array
    13261313# https://bugs.webkit.org/show_bug.cgi?id=52094
     
    16901677# https://bugs.webkit.org/show_bug.cgi?id=69587
    16911678editing/pasteboard/smart-paste-008.html
     1679
     1680# Some tests fail with  "FAIL Unexpected response data received: Wrong method: GET"
     1681# https://bugs.webkit.org/show_bug.cgi?id=69219
     1682http/tests/local/fileapi/send-sliced-dragged-file.html 
     1683http/tests/local/blob/send-hybrid-blob.html
  • trunk/Source/WebCore/ChangeLog

    r97214 r97219  
     12011-10-11  Martin Robinson  <mrobinson@igalia.com>
     2
     3        [Soup] ResourceHandleSoup does not handle encodedBlobData
     4        https://bugs.webkit.org/show_bug.cgi?id=52092
     5
     6        Reviewed by Gustavo Noronha Silva.
     7
     8        Add support for sending encoded blob data during requests.
     9
     10        * platform/network/soup/ResourceHandleSoup.cpp:
     11        (WebCore::addFileToSoupMessageBody): Added this helper.
     12        (WebCore::blobIsOutOfDate): Ditto.
     13        (WebCore::addEncodedBlobItemToSoupMessageBody): Ditto.
     14        (WebCore::addEncodedBlobToSoupMessageBody): Ditto.
     15        (WebCore::addFormElementsToSoupMessage): No longer flatten form data, as we
     16        cannot do this in the case where the form data contains blobs. Now handle
     17        the blob case.
     18        (WebCore::loadResourceSynchronously): Add blob support for synchronous loading.
     19
    1202011-10-11  Chris Rogers  <crogers@google.com>
    221
  • trunk/Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp

    r96715 r97219  
    5959#include <wtf/text/CString.h>
    6060
     61#if ENABLE(BLOB)
     62#include "BlobData.h"
     63#include "BlobRegistryImpl.h"
     64#include "BlobStorageData.h"
     65#endif
     66
    6167namespace WebCore {
    6268
     
    515521}
    516522
     523static bool addFileToSoupMessageBody(SoupMessage* message, const String& fileNameString, size_t offset, size_t lengthToSend, unsigned long& totalBodySize)
     524{
     525    GOwnPtr<GError> error;
     526    CString fileName = fileSystemRepresentation(fileNameString);
     527    GMappedFile* fileMapping = g_mapped_file_new(fileName.data(), false, &error.outPtr());
     528    if (error)
     529        return false;
     530
     531    gsize bufferLength = lengthToSend;
     532    if (!lengthToSend)
     533        bufferLength = g_mapped_file_get_length(fileMapping);
     534    totalBodySize += bufferLength;
     535
     536    SoupBuffer* soupBuffer = soup_buffer_new_with_owner(g_mapped_file_get_contents(fileMapping) + offset,
     537                                                        bufferLength,
     538                                                        fileMapping,
     539                                                        reinterpret_cast<GDestroyNotify>(g_mapped_file_unref));
     540    soup_message_body_append_buffer(message->request_body, soupBuffer);
     541    soup_buffer_free(soupBuffer);
     542    return true;
     543}
     544
     545#if ENABLE(BLOB)
     546static bool blobIsOutOfDate(const BlobDataItem& blobItem)
     547{
     548    ASSERT(blobItem.type == BlobDataItem::File);
     549    if (blobItem.expectedModificationTime == BlobDataItem::doNotCheckFileChange)
     550        return false;
     551
     552    time_t fileModificationTime;
     553    if (!getFileModificationTime(blobItem.path, fileModificationTime))
     554        return true;
     555
     556    return fileModificationTime != static_cast<time_t>(blobItem.expectedModificationTime);
     557}
     558
     559static bool addEncodedBlobItemToSoupMessageBody(SoupMessage* message, const BlobDataItem& blobItem, unsigned long& totalBodySize)
     560{
     561    if (blobItem.type == BlobDataItem::Data) {
     562        totalBodySize += blobItem.length;
     563        soup_message_body_append(message->request_body, SOUP_MEMORY_TEMPORARY,
     564                                 blobItem.data->data() + blobItem.offset, blobItem.length);
     565        return true;
     566    }
     567
     568    ASSERT(blobItem.type == BlobDataItem::File);
     569    if (blobIsOutOfDate(blobItem))
     570        return false;
     571
     572    return addFileToSoupMessageBody(message,
     573                                    blobItem.path,
     574                                    blobItem.offset,
     575                                    blobItem.length == BlobDataItem::toEndOfFile ? 0 : blobItem.length,
     576                                    totalBodySize);
     577}
     578
     579static bool addEncodedBlobToSoupMessageBody(SoupMessage* message, const FormDataElement& element, unsigned long& totalBodySize)
     580{
     581    RefPtr<BlobStorageData> blobData = static_cast<BlobRegistryImpl&>(blobRegistry()).getBlobDataFromURL(KURL(ParsedURLString, element.m_blobURL));
     582    if (!blobData)
     583        return true;
     584
     585    for (size_t i = 0; i < blobData->items().size(); ++i)
     586        if (!addEncodedBlobItemToSoupMessageBody(message, blobData->items()[i], totalBodySize))
     587            return false;
     588
     589    return true;
     590}
     591#endif // ENABLE(BLOB)
     592
    517593static bool addFormElementsToSoupMessage(SoupMessage* message, const char* contentType, FormData* httpBody, unsigned long& totalBodySize)
    518594{
     595    soup_message_body_set_accumulate(message->request_body, FALSE);
    519596    size_t numElements = httpBody->elements().size();
    520     if (numElements < 2) { // No file upload is the most common case.
    521         Vector<char> body;
    522         httpBody->flatten(body);
    523         totalBodySize = body.size();
    524         soup_message_set_request(message, contentType, SOUP_MEMORY_COPY, body.data(), body.size());
    525         return true;
    526     }
    527 
    528     // We have more than one element to upload, and some may be large files,
    529     // which we will want to mmap instead of copying into memory
    530     soup_message_body_set_accumulate(message->request_body, FALSE);
    531597    for (size_t i = 0; i < numElements; i++) {
    532598        const FormDataElement& element = httpBody->elements()[i];
     
    539605        }
    540606
    541         // This technique is inspired by libsoup's simple-httpd test.
    542         GOwnPtr<GError> error;
    543         CString fileName = fileSystemRepresentation(element.m_filename);
    544         GMappedFile* fileMapping = g_mapped_file_new(fileName.data(), false, &error.outPtr());
    545         if (error)
     607        if (element.m_type == FormDataElement::encodedFile) {
     608            if (!addFileToSoupMessageBody(message ,
     609                                         element.m_filename,
     610                                         0 /* offset */,
     611                                         0 /* lengthToSend */,
     612                                         totalBodySize))
     613                return false;
     614            continue;
     615        }
     616
     617#if ENABLE(BLOB)
     618        ASSERT(element.m_type == FormDataElement::encodedBlob);
     619        if (!addEncodedBlobToSoupMessageBody(message, element, totalBodySize))
    546620            return false;
    547 
    548         gsize mappedFileSize = g_mapped_file_get_length(fileMapping);
    549         totalBodySize += mappedFileSize;
    550         SoupBuffer* soupBuffer = soup_buffer_new_with_owner(g_mapped_file_get_contents(fileMapping),
    551                                                             mappedFileSize, fileMapping,
    552                                                             reinterpret_cast<GDestroyNotify>(g_mapped_file_unref));
    553         soup_message_body_append_buffer(message->request_body, soupBuffer);
    554         soup_buffer_free(soupBuffer);
    555     }
    556 
     621#endif
     622    }
    557623    return true;
    558624}
     
    731797void ResourceHandle::loadResourceSynchronously(NetworkingContext* context, const ResourceRequest& request, StoredCredentials /*storedCredentials*/, ResourceError& error, ResourceResponse& response, Vector<char>& data)
    732798{
     799#if ENABLE(BLOB)
     800    if (request.url().protocolIs("blob")) {
     801        blobRegistry().loadResourceSynchronously(request, error, response, data);
     802        return;
     803    }
     804#endif
     805
    733806    WebCoreSynchronousLoader syncLoader(error, response, data);
    734807    RefPtr<ResourceHandle> handle = create(context, request, &syncLoader, false /*defersLoading*/, false /*shouldContentSniff*/);
Note: See TracChangeset for help on using the changeset viewer.