Changeset 27189 in webkit
- Timestamp:
- Oct 28, 2007 2:09:42 PM (16 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r27188 r27189 1 2007-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 1 19 2007-10-28 Alp Toker <alp@atoker.com> 2 20 -
trunk/WebCore/platform/Base64.cpp
r26182 r27189 127 127 { 128 128 out.clear(); 129 if (in.isEmpty())130 return true;131 129 132 130 // If the input string is pathologically large, just return nothing. … … 134 132 return false; 135 133 136 unsigned len = in.size(); 137 const char* data = in.data(); 134 return base64Decode(in.data(), in.size(), out); 135 } 136 137 bool base64Decode(const char* data, unsigned len, Vector<char>& out) 138 { 139 out.clear(); 140 if (len == 0) 141 return true; 138 142 139 143 while (len && data[len-1] == '=') -
trunk/WebCore/platform/Base64.h
r18186 r27189 35 35 // this decoder is not general purpose - it returns an error if it encounters a linefeed, as needed for window.atob 36 36 bool base64Decode(const Vector<char>&, Vector<char>&); 37 bool base64Decode(const char*, unsigned, Vector<char>&); 37 38 38 39 } -
trunk/WebCore/platform/network/curl/ResourceHandleManager.cpp
r27188 r27189 36 36 #include "ResourceHandleInternal.h" 37 37 #include "HTTPParsers.h" 38 #include "Base64.h" 38 39 39 40 #include <wtf/Vector.h> … … 342 343 } 343 344 345 static 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 344 396 void ResourceHandleManager::startJob(ResourceHandle* job) 345 397 { 398 KURL kurl = job->request().url(); 399 String protocol = kurl.protocol(); 400 401 if (equalIgnoringCase(protocol, "data")) { 402 parseDataUrl(job); 403 return; 404 } 405 346 406 ResourceHandleInternal* d = job->getInternal(); 347 DeprecatedString url = job->request().url().url();407 DeprecatedString url = kurl.url(); 348 408 d->m_handle = curl_easy_init(); 349 409 #ifndef NDEBUG
Note: See TracChangeset
for help on using the changeset viewer.