Commit 75ab3a5a authored by alp@webkit.org's avatar alp@webkit.org
Browse files

2008-11-03 Xan Lopez <xan@gnome.org>

        Reviewed by Alp Toker.

        Update parseDataUrl() function in the libsoup http backend with
        the one from the curl backend which has recent correctness and crash
        fixes.

        * platform/network/soup/ResourceHandleSoup.cpp:
        (WebCore::parseDataUrl):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@38075 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ced59bb6
2008-11-03 Xan Lopez <xan@gnome.org>
Reviewed by Alp Toker.
Update parseDataUrl() function in the libsoup http backend with
the one from the curl backend which has recent correctness and crash
fixes.
* platform/network/soup/ResourceHandleSoup.cpp:
(WebCore::parseDataUrl):
2008-11-03 Holger Hans Peter Freyther <zecke@selfish.org>
 
Reviewed by Alp Toker.
......
......@@ -23,6 +23,7 @@
#include "CString.h"
#include "ResourceHandle.h"
#include "Base64.h"
#include "CookieJar.h"
#include "DocLoader.h"
#include "Frame.h"
......@@ -33,11 +34,18 @@
#include "ResourceHandleClient.h"
#include "ResourceHandleInternal.h"
#include "ResourceResponse.h"
#include "TextEncoding.h"
#include <gio/gio.h>
#include <libsoup/soup.h>
#include <libsoup/soup-message.h>
#if PLATFORM(GTK)
#if GLIB_CHECK_VERSION(2,12,0)
#define USE_GLIB_BASE64
#endif
#endif
namespace WebCore {
static SoupSession* session = 0;
......@@ -186,61 +194,68 @@ static void finishedCallback(SoupSession *session, SoupMessage* msg, gpointer da
client->didFinishLoading(handle);
}
// parseDataUrl() is taken from the CURL http backend.
static gboolean parseDataUrl(gpointer callback_data)
{
ResourceHandle* handle = static_cast<ResourceHandle*>(callback_data);
String data = handle->request().url().string();
ASSERT(data.startsWith("data:", false));
String header;
bool base64 = false;
int index = data.find(',');
if (index != -1) {
header = data.substring(5, index - 5).lower();
data = data.substring(index + 1);
ResourceHandleClient* client = handle->client();
if (header.endsWith(";base64")) {
base64 = true;
header = header.left(header.length() - 7);
}
} else
data = String();
ASSERT(client);
if (!client)
return FALSE;
data = decodeURLEscapeSequences(data);
String url = handle->request().url().string();
ASSERT(url.startsWith("data:", false));
size_t outLength = 0;
char* outData = 0;
if (base64 && !data.isEmpty()) {
// Use the GLib Base64 if available, since WebCore's decoder isn't
// general-purpose and fails on Acid3 test 97 (whitespace).
outData = reinterpret_cast<char*>(g_base64_decode(data.utf8().data(), &outLength));
int index = url.find(',');
if (index == -1) {
client->cannotShowURL(handle);
return FALSE;
}
if (header.isEmpty())
header = "text/plain;charset=US-ASCII";
String mediaType = url.substring(5, index - 5);
String data = url.substring(index + 1);
ResourceHandleClient* client = handle->getInternal()->client();
bool base64 = mediaType.endsWith(";base64", false);
if (base64)
mediaType = mediaType.left(mediaType.length() - 7);
ResourceResponse response;
if (mediaType.isEmpty())
mediaType = "text/plain;charset=US-ASCII";
response.setMimeType(extractMIMETypeFromMediaType(header));
response.setTextEncodingName(extractCharsetFromMediaType(header));
if (outData)
response.setExpectedContentLength(outLength);
else
response.setExpectedContentLength(data.length());
response.setHTTPStatusCode(200);
String mimeType = extractMIMETypeFromMediaType(mediaType);
String charset = extractCharsetFromMediaType(mediaType);
client->didReceiveResponse(handle, response);
ResourceResponse response;
response.setMimeType(mimeType);
if (outData)
client->didReceiveData(handle, outData, outLength, 0);
else
client->didReceiveData(handle, data.latin1().data(), data.length(), 0);
if (base64) {
data = decodeURLEscapeSequences(data);
response.setTextEncodingName(charset);
client->didReceiveResponse(handle, response);
g_free(outData);
// Use the GLib Base64 if available, since WebCore's decoder isn't
// general-purpose and fails on Acid3 test 97 (whitespace).
#ifdef USE_GLIB_BASE64
size_t outLength = 0;
char* outData = 0;
outData = reinterpret_cast<char*>(g_base64_decode(data.utf8().data(), &outLength));
if (outData && outLength > 0)
client->didReceiveData(handle, outData, outLength, 0);
g_free(outData);
#else
Vector<char> out;
if (base64Decode(data.latin1().data(), data.latin1().length(), out) && out.size() > 0)
client->didReceiveData(handle, out.data(), out.size(), 0);
#endif
} else {
// We have to convert to UTF-16 early due to limitations in KURL
data = decodeURLEscapeSequences(data, TextEncoding(charset));
response.setTextEncodingName("UTF-16");
client->didReceiveResponse(handle, response);
if (data.length() > 0)
client->didReceiveData(handle, reinterpret_cast<const char*>(data.characters()), data.length() * sizeof(UChar), 0);
}
client->didFinishLoading(handle);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment