Changeset 27189 in webkit


Ignore:
Timestamp:
Oct 28, 2007 2:09:42 PM (16 years ago)
Author:
alp
Message:

Reviewed by Anders Carlsson.

http://bugs.webkit.org/show_bug.cgi?id=14124
[CURL] Support data URLs

Add data URL support (both Base64 and percent-encoded formats).

Inspired by code from the Qt port.

Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r27188 r27189  
     12007-10-28  Alp Toker  <alp@atoker.com>
     2
     3        Reviewed by Anders Carlsson.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=14124
     6        [CURL] Support data URLs
     7
     8        Add data URL support (both Base64 and percent-encoded formats).
     9
     10        Inspired by code from the Qt port.
     11
     12        * platform/Base64.cpp:
     13        (WebCore::base64Decode):
     14        * platform/Base64.h:
     15        * platform/network/curl/ResourceHandleManager.cpp:
     16        (WebCore::ResourceHandleManager::startScheduledJobs):
     17        (WebCore::parseDataUrl):
     18
    1192007-10-28  Alp Toker  <alp@atoker.com>
    220
  • trunk/WebCore/platform/Base64.cpp

    r26182 r27189  
    127127{
    128128    out.clear();
    129     if (in.isEmpty())
    130         return true;
    131129
    132130    // If the input string is pathologically large, just return nothing.
     
    134132        return false;
    135133
    136     unsigned len = in.size();
    137     const char* data = in.data();
     134    return base64Decode(in.data(), in.size(), out);
     135}
     136
     137bool base64Decode(const char* data, unsigned len, Vector<char>& out)
     138{
     139    out.clear();
     140    if (len == 0)
     141        return true;
    138142
    139143    while (len && data[len-1] == '=')
  • trunk/WebCore/platform/Base64.h

    r18186 r27189  
    3535// this decoder is not general purpose - it returns an error if it encounters a linefeed, as needed for window.atob
    3636bool base64Decode(const Vector<char>&, Vector<char>&);
     37bool base64Decode(const char*, unsigned, Vector<char>&);
    3738
    3839}
  • trunk/WebCore/platform/network/curl/ResourceHandleManager.cpp

    r27188 r27189  
    3636#include "ResourceHandleInternal.h"
    3737#include "HTTPParsers.h"
     38#include "Base64.h"
    3839
    3940#include <wtf/Vector.h>
     
    342343}
    343344
     345static void parseDataUrl(ResourceHandle* handle)
     346{
     347    DeprecatedString data = handle->request().url().url();
     348
     349    ASSERT(data.startsWith("data:", false));
     350
     351    DeprecatedString header;
     352    bool base64 = false;
     353
     354    int index = data.find(',');
     355    if (index != -1) {
     356        header = data.mid(5, index - 5).lower();
     357        data = data.mid(index + 1);
     358
     359        if (header.endsWith(";base64")) {
     360            base64 = true;
     361            header = header.left(header.length() - 7);
     362        }
     363    } else
     364        data = DeprecatedString();
     365
     366    data = KURL::decode_string(data);
     367
     368    if (base64) {
     369        Vector<char> out;
     370        if (base64Decode(data.ascii(), data.length(), out))
     371            data = DeprecatedString(out.data(), out.size());
     372        else
     373            data = DeprecatedString();
     374    }
     375
     376    if (header.isEmpty())
     377        header = "text/plain;charset=US-ASCII";
     378
     379    ResourceHandleClient* client = handle->getInternal()->client();
     380
     381    ResourceResponse response;
     382
     383    response.setMimeType(extractMIMETypeFromMediaType(header));
     384    response.setTextEncodingName(extractCharsetFromMediaType(header));
     385    response.setExpectedContentLength(data.length());
     386    response.setHTTPStatusCode(200);
     387
     388    client->didReceiveResponse(handle, response);
     389
     390    if (!data.isEmpty())
     391        client->didReceiveData(handle, data.ascii(), data.length(), 0);
     392
     393    client->didFinishLoading(handle);
     394}
     395
    344396void ResourceHandleManager::startJob(ResourceHandle* job)
    345397{
     398    KURL kurl = job->request().url();
     399    String protocol = kurl.protocol();
     400
     401    if (equalIgnoringCase(protocol, "data")) {
     402        parseDataUrl(job);
     403        return;
     404    }
     405
    346406    ResourceHandleInternal* d = job->getInternal();
    347     DeprecatedString url = job->request().url().url();
     407    DeprecatedString url = kurl.url();
    348408    d->m_handle = curl_easy_init();
    349409#ifndef NDEBUG
Note: See TracChangeset for help on using the changeset viewer.