Changeset 69183 in webkit


Ignore:
Timestamp:
Oct 6, 2010 3:59:43 AM (14 years ago)
Author:
Patrick Gansterer
Message:

2010-10-06 Patrick Gansterer <Patrick Gansterer>

Reviewed by Darin Adler.

Move parseDataUrl() from CURL into own file
https://bugs.webkit.org/show_bug.cgi?id=41462

Move the data URL parsing algorithm into a new file to use it in ResourceHandleWin too.

  • CMakeLists.txt:
  • WebCore.gypi:
  • WebCore.vcproj/WebCore.vcproj:
  • platform/network/DataURL.cpp: Added. (WebCore::handleDataURL):
  • platform/network/DataURL.h: Added.
  • platform/network/curl/ResourceHandleManager.cpp: (WebCore::ResourceHandleManager::dispatchSynchronousJob): (WebCore::ResourceHandleManager::startJob):
  • platform/network/win/ResourceHandleWin.cpp: (WebCore::ResourceHandle::start): (WebCore::ResourceHandle::fileLoadTimer):
Location:
trunk/WebCore
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/CMakeLists.txt

    r69178 r69183  
    13391339    platform/network/BlobResourceHandle.cpp
    13401340    platform/network/Credential.cpp
     1341    platform/network/DataURL.cpp
    13411342    platform/network/FormDataBuilder.cpp
    13421343    platform/network/FormData.cpp
  • trunk/WebCore/ChangeLog

    r69181 r69183  
     12010-10-06  Patrick Gansterer  <paroga@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Move parseDataUrl() from CURL into own file
     6        https://bugs.webkit.org/show_bug.cgi?id=41462
     7
     8        Move the data URL parsing algorithm into a new file to use it in ResourceHandleWin too.
     9
     10        * CMakeLists.txt:
     11        * WebCore.gypi:
     12        * WebCore.vcproj/WebCore.vcproj:
     13        * platform/network/DataURL.cpp: Added.
     14        (WebCore::handleDataURL):
     15        * platform/network/DataURL.h: Added.
     16        * platform/network/curl/ResourceHandleManager.cpp:
     17        (WebCore::ResourceHandleManager::dispatchSynchronousJob):
     18        (WebCore::ResourceHandleManager::startJob):
     19        * platform/network/win/ResourceHandleWin.cpp:
     20        (WebCore::ResourceHandle::start):
     21        (WebCore::ResourceHandle::fileLoadTimer):
     22
    1232010-10-06  Dirk Schulze  <krit@webkit.org>
    224
  • trunk/WebCore/WebCore.gypi

    r69178 r69183  
    30073007            'platform/network/Credential.h',
    30083008            'platform/network/DNS.h',
     3009            'platform/network/DataURL.cpp',
     3010            'platform/network/DataURL.h',
    30093011            'platform/network/FormData.cpp',
    30103012            'platform/network/FormData.h',
  • trunk/WebCore/WebCore.vcproj/WebCore.vcproj

    r69178 r69183  
    2742727427                                </File>
    2742827428                                <File
     27429                                        RelativePath="..\platform\network\DataURL.cpp"
     27430                                        >
     27431                                </File>
     27432                                <File
     27433                                        RelativePath="..\platform\network\DataURL.h"
     27434                                        >
     27435                                </File>
     27436                                <File
    2742927437                                        RelativePath="..\platform\network\FormData.cpp"
    2743027438                                        >
  • trunk/WebCore/platform/network/curl/ResourceHandleManager.cpp

    r68679 r69183  
    3535#include "ResourceHandleManager.h"
    3636
    37 #include "Base64.h"
     37#include "DataURL.h"
    3838#include "HTTPParsers.h"
    3939#include "MIMETypeRegistry.h"
     
    4242#include "ResourceHandle.h"
    4343#include "ResourceHandleInternal.h"
    44 #include "TextEncoding.h"
    4544
    4645#include <errno.h>
     
    574573}
    575574
    576 static void parseDataUrl(ResourceHandle* handle)
    577 {
    578     ResourceHandleClient* client = handle->client();
    579 
    580     ASSERT(client);
    581     if (!client)
    582         return;
    583 
    584     String url = handle->firstRequest().url().string();
    585     ASSERT(url.startsWith("data:", false));
    586 
    587     int index = url.find(',');
    588     if (index == -1) {
    589         client->cannotShowURL(handle);
    590         return;
    591     }
    592 
    593     String mediaType = url.substring(5, index - 5);
    594     String data = url.substring(index + 1);
    595 
    596     bool base64 = mediaType.endsWith(";base64", false);
    597     if (base64)
    598         mediaType = mediaType.left(mediaType.length() - 7);
    599 
    600     if (mediaType.isEmpty())
    601         mediaType = "text/plain;charset=US-ASCII";
    602 
    603     String mimeType = extractMIMETypeFromMediaType(mediaType);
    604     String charset = extractCharsetFromMediaType(mediaType);
    605 
    606     ResourceResponse response;
    607     response.setMimeType(mimeType);
    608 
    609     if (base64) {
    610         data = decodeURLEscapeSequences(data);
    611         response.setTextEncodingName(charset);
    612         client->didReceiveResponse(handle, response);
    613 
    614         // WebCore's decoder fails on Acid3 test 97 (whitespace).
    615         Vector<char> out;
    616         CString latin1 = data.latin1();
    617         if (base64Decode(latin1.data(), latin1.length(), out) && out.size() > 0)
    618             client->didReceiveData(handle, out.data(), out.size(), 0);
    619     } else {
    620         // We have to convert to UTF-16 early due to limitations in KURL
    621         data = decodeURLEscapeSequences(data, TextEncoding(charset));
    622         response.setTextEncodingName("UTF-16");
    623         client->didReceiveResponse(handle, response);
    624         if (data.length() > 0)
    625             client->didReceiveData(handle, reinterpret_cast<const char*>(data.characters()), data.length() * sizeof(UChar), 0);
    626     }
    627 
    628     client->didFinishLoading(handle, 0);
    629 }
    630 
    631575void ResourceHandleManager::dispatchSynchronousJob(ResourceHandle* job)
    632576{
     
    634578
    635579    if (kurl.protocolIs("data")) {
    636         parseDataUrl(job);
     580        handleDataURL(job);
    637581        return;
    638582    }
     
    665609
    666610    if (kurl.protocolIs("data")) {
    667         parseDataUrl(job);
     611        handleDataURL(job);
    668612        return;
    669613    }
  • trunk/WebCore/platform/network/win/ResourceHandleWin.cpp

    r68371 r69183  
    2828#include "ResourceHandle.h"
    2929
     30#include "DataURL.h"
    3031#include "HTTPParsers.h"
    3132#include "MIMETypeRegistry.h"
     
    260261bool ResourceHandle::start(NetworkingContext* context)
    261262{
    262     if (request().url().isLocalFile()) {
     263    if (firstRequest().url().isLocalFile() || firstRequest().url().protocolIs("data")) {
    263264        ref(); // balanced by deref in fileLoadTimer
    264265        if (d->m_loadSynchronously)
     
    349350    RefPtr<ResourceHandle> protector(this);
    350351    deref(); // balances ref in start
     352
     353    if (firstRequest().url().protocolIs("data")) {
     354        handleDataURL(this);
     355        return;
     356    }
    351357
    352358    String fileName = firstRequest().url().fileSystemPath();
Note: See TracChangeset for help on using the changeset viewer.