Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: WebCore/platform/network/FormData.cpp

Issue 11192017: ********** WebCore blob hacking (Closed) Base URL: http://svn.webkit.org/repository/webkit/trunk/Source/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2006, 2008, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2008, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) 4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
11 * This library is distributed in the hope that it will be useful, 11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details. 14 * Library General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU Library General Public License 16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to 17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA. 19 * Boston, MA 02110-1301, USA.
20 */ 20 */
21 21
22 #include "config.h" 22 #include "config.h"
23 23
24 #include "FormData.h" 24 #include "FormData.h"
25 25
26 #include "BlobData.h"
27 #include "BlobRegistryImpl.h"
28 #include "BlobURL.h"
29 #include "Chrome.h" 26 #include "Chrome.h"
30 #include "ChromeClient.h" 27 #include "ChromeClient.h"
31 #include "Document.h" 28 #include "Document.h"
32 #include "File.h" 29 #include "File.h"
33 #include "FileSystem.h" 30 #include "FileSystem.h"
34 #include "FormDataBuilder.h" 31 #include "FormDataBuilder.h"
35 #include "FormDataList.h" 32 #include "FormDataList.h"
36 #include "MIMETypeRegistry.h" 33 #include "MIMETypeRegistry.h"
37 #include "Page.h" 34 #include "Page.h"
38 #include "PlatformMemoryInstrumentation.h" 35 #include "PlatformMemoryInstrumentation.h"
39 #include "TextEncoding.h" 36 #include "TextEncoding.h"
40 #include <wtf/Decoder.h> 37 #include <wtf/Decoder.h>
41 #include <wtf/Encoder.h> 38 #include <wtf/Encoder.h>
42 #include <wtf/MemoryInstrumentationVector.h> 39 #include <wtf/MemoryInstrumentationVector.h>
43 40
41 #if PLATFORM(CHROMIUM)
42 // Chromium doesn't store blob data in renderer processes.
43 #else
44 #include "BlobRegistryImpl.h"
45 #endif
46
44 namespace WebCore { 47 namespace WebCore {
45 48
46 inline FormData::FormData() 49 inline FormData::FormData()
47 : m_identifier(0) 50 : m_identifier(0)
48 , m_hasGeneratedFiles(false) 51 , m_hasGeneratedFiles(false)
49 , m_alwaysStream(false) 52 , m_alwaysStream(false)
50 , m_containsPasswordData(false) 53 , m_containsPasswordData(false)
51 { 54 {
52 } 55 }
53 56
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 break; 143 break;
141 case FormDataElement::encodedFile: 144 case FormDataElement::encodedFile:
142 #if ENABLE(BLOB) 145 #if ENABLE(BLOB)
143 formData->m_elements.append(FormDataElement(e.m_filename, e.m_fileSt art, e.m_fileLength, e.m_expectedFileModificationTime, e.m_shouldGenerateFile)); 146 formData->m_elements.append(FormDataElement(e.m_filename, e.m_fileSt art, e.m_fileLength, e.m_expectedFileModificationTime, e.m_shouldGenerateFile));
144 #else 147 #else
145 formData->m_elements.append(FormDataElement(e.m_filename, e.m_should GenerateFile)); 148 formData->m_elements.append(FormDataElement(e.m_filename, e.m_should GenerateFile));
146 #endif 149 #endif
147 break; 150 break;
148 #if ENABLE(BLOB) 151 #if ENABLE(BLOB)
149 case FormDataElement::encodedBlob: 152 case FormDataElement::encodedBlob:
150 formData->m_elements.append(FormDataElement(e.m_url)); 153 formData->m_elements.append(FormDataElement(e.m_blobUUID, e.m_option alBlobDataHandle));
151 break; 154 break;
152 #endif 155 #endif
153 #if ENABLE(FILE_SYSTEM) 156 #if ENABLE(FILE_SYSTEM)
154 case FormDataElement::encodedURL: 157 case FormDataElement::encodedFileSystemURL:
155 formData->m_elements.append(FormDataElement(e.m_url, e.m_fileStart, e.m_fileLength, e.m_expectedFileModificationTime)); 158 formData->m_elements.append(FormDataElement(e.m_fileSystemURL, e.m_f ileStart, e.m_fileLength, e.m_expectedFileModificationTime));
156 break; 159 break;
157 #endif 160 #endif
158 } 161 }
159 } 162 }
160 return formData.release(); 163 return formData.release();
161 } 164 }
162 165
163 void FormData::appendData(const void* data, size_t size) 166 void FormData::appendData(const void* data, size_t size)
164 { 167 {
165 if (m_elements.isEmpty() || m_elements.last().m_type != FormDataElement::dat a) 168 if (m_elements.isEmpty() || m_elements.last().m_type != FormDataElement::dat a)
(...skipping 12 matching lines...) Expand all
178 m_elements.append(FormDataElement(filename, shouldGenerateFile)); 181 m_elements.append(FormDataElement(filename, shouldGenerateFile));
179 #endif 182 #endif
180 } 183 }
181 184
182 #if ENABLE(BLOB) 185 #if ENABLE(BLOB)
183 void FormData::appendFileRange(const String& filename, long long start, long lon g length, double expectedModificationTime, bool shouldGenerateFile) 186 void FormData::appendFileRange(const String& filename, long long start, long lon g length, double expectedModificationTime, bool shouldGenerateFile)
184 { 187 {
185 m_elements.append(FormDataElement(filename, start, length, expectedModificat ionTime, shouldGenerateFile)); 188 m_elements.append(FormDataElement(filename, start, length, expectedModificat ionTime, shouldGenerateFile));
186 } 189 }
187 190
188 void FormData::appendBlob(const KURL& blobURL) 191 void FormData::appendBlob(const String& blobUUID, PassRefPtr<BlobDataHandle> opt ionalBlobDataHandle)
189 { 192 {
190 m_elements.append(FormDataElement(blobURL)); 193 m_elements.append(FormDataElement(blobUUID, optionalBlobDataHandle));
191 } 194 }
192 #endif 195 #endif
193 #if ENABLE(FILE_SYSTEM) 196 #if ENABLE(FILE_SYSTEM)
194 void FormData::appendURL(const KURL& url) 197 void FormData::appendURL(const KURL& url)
195 { 198 {
196 m_elements.append(FormDataElement(url, 0, BlobDataItem::toEndOfFile, invalid FileTime())); 199 m_elements.append(FormDataElement(url, 0, BlobDataItem::toEndOfFile, invalid FileTime()));
197 } 200 }
198 201
199 void FormData::appendURLRange(const KURL& url, long long start, long long length , double expectedModificationTime) 202 void FormData::appendURLRange(const KURL& url, long long start, long long length , double expectedModificationTime)
200 { 203 {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 // Do not add the file if the path is empty. 275 // Do not add the file if the path is empty.
273 if (!file->path().isEmpty()) 276 if (!file->path().isEmpty())
274 appendFile(file->path(), shouldGenerateFile); 277 appendFile(file->path(), shouldGenerateFile);
275 #if ENABLE(FILE_SYSTEM) 278 #if ENABLE(FILE_SYSTEM)
276 if (!file->fileSystemURL().isEmpty()) 279 if (!file->fileSystemURL().isEmpty())
277 appendURL(file->fileSystemURL()); 280 appendURL(file->fileSystemURL());
278 #endif 281 #endif
279 } 282 }
280 #if ENABLE(BLOB) 283 #if ENABLE(BLOB)
281 else 284 else
282 appendBlob(value.blob()->url()); 285 appendBlob(value.blob()->uuid(), value.blob()->blobDataHandl e());
283 #endif 286 #endif
284 } else 287 } else
285 appendData(value.data().data(), value.data().length()); 288 appendData(value.data().data(), value.data().length());
286 appendData("\r\n", 2); 289 appendData("\r\n", 2);
287 } else { 290 } else {
288 // Omit the name "isindex" if it's the first form data element. 291 // Omit the name "isindex" if it's the first form data element.
289 // FIXME: Why is this a good rule? Is this obsolete now? 292 // FIXME: Why is this a good rule? Is this obsolete now?
290 if (encodedData.isEmpty() && key.data() == "isindex") 293 if (encodedData.isEmpty() && key.data() == "isindex")
291 FormDataBuilder::encodeStringAsFormData(encodedData, value.data( )); 294 FormDataBuilder::encodeStringAsFormData(encodedData, value.data( ));
292 else 295 else
(...skipping 20 matching lines...) Expand all
313 } 316 }
314 317
315 String FormData::flattenToString() const 318 String FormData::flattenToString() const
316 { 319 {
317 Vector<char> bytes; 320 Vector<char> bytes;
318 flatten(bytes); 321 flatten(bytes);
319 return Latin1Encoding().decode(reinterpret_cast<const char*>(bytes.data()), bytes.size()); 322 return Latin1Encoding().decode(reinterpret_cast<const char*>(bytes.data()), bytes.size());
320 } 323 }
321 324
322 #if ENABLE(BLOB) 325 #if ENABLE(BLOB)
323 static void appendBlobResolved(FormData* formData, const KURL& url) 326 #if PLATFORM(CHROMIUM)
327 // Chromium doesn't store blob data in renderer processes.
328 #else
329 static void appendBlobResolved(FormData* formData, const String& blobUUID)
324 { 330 {
325 RefPtr<BlobStorageData> blobData = static_cast<BlobRegistryImpl&>(blobRegist ry()).getBlobDataFromURL(KURL(ParsedURLString, url)); 331 RefPtr<BlobStorageData> blobData = static_cast<BlobRegistryImpl&>(blobRegist ry()).getBlobDataFromUUID(blobUUID);
326 if (!blobData) 332 if (!blobData)
327 return; 333 return;
328 334
329 BlobDataItemList::const_iterator it = blobData->items().begin(); 335 BlobDataItemList::const_iterator it = blobData->items().begin();
330 const BlobDataItemList::const_iterator itend = blobData->items().end(); 336 const BlobDataItemList::const_iterator itend = blobData->items().end();
331 for (; it != itend; ++it) { 337 for (; it != itend; ++it) {
332 const BlobDataItem& blobItem = *it; 338 const BlobDataItem& blobItem = *it;
333 if (blobItem.type == BlobDataItem::Data) 339 if (blobItem.type == BlobDataItem::Data)
334 formData->appendData(blobItem.data->data() + static_cast<int>(blobIt em.offset), static_cast<int>(blobItem.length)); 340 formData->appendData(blobItem.data->data() + static_cast<int>(blobIt em.offset), static_cast<int>(blobItem.length));
335 else if (blobItem.type == BlobDataItem::File) 341 else if (blobItem.type == BlobDataItem::File)
336 formData->appendFileRange(blobItem.path, blobItem.offset, blobItem.l ength, blobItem.expectedModificationTime); 342 formData->appendFileRange(blobItem.path, blobItem.offset, blobItem.l ength, blobItem.expectedModificationTime);
337 else if (blobItem.type == BlobDataItem::Blob) 343 else if (blobItem.type == BlobDataItem::Blob)
338 appendBlobResolved(formData, blobItem.url); 344 appendBlobResolved(formData, blobItem.blobDataHandle->uuid());
339 else 345 else
340 ASSERT_NOT_REACHED(); 346 ASSERT_NOT_REACHED();
341 } 347 }
342 } 348 }
343 349
344 PassRefPtr<FormData> FormData::resolveBlobReferences() 350 PassRefPtr<FormData> FormData::resolveBlobReferences()
345 { 351 {
346 // First check if any blobs needs to be resolved, or we can take the fast pa th. 352 // First check if any blobs needs to be resolved, or we can take the fast pa th.
347 bool hasBlob = false; 353 bool hasBlob = false;
348 Vector<FormDataElement>::const_iterator it = elements().begin(); 354 Vector<FormDataElement>::const_iterator it = elements().begin();
(...skipping 13 matching lines...) Expand all
362 newFormData->setAlwaysStream(alwaysStream()); 368 newFormData->setAlwaysStream(alwaysStream());
363 newFormData->setIdentifier(identifier()); 369 newFormData->setIdentifier(identifier());
364 it = elements().begin(); 370 it = elements().begin();
365 for (; it != itend; ++it) { 371 for (; it != itend; ++it) {
366 const FormDataElement& element = *it; 372 const FormDataElement& element = *it;
367 if (element.m_type == FormDataElement::data) 373 if (element.m_type == FormDataElement::data)
368 newFormData->appendData(element.m_data.data(), element.m_data.size() ); 374 newFormData->appendData(element.m_data.data(), element.m_data.size() );
369 else if (element.m_type == FormDataElement::encodedFile) 375 else if (element.m_type == FormDataElement::encodedFile)
370 newFormData->appendFileRange(element.m_filename, element.m_fileStart , element.m_fileLength, element.m_expectedFileModificationTime, element.m_should GenerateFile); 376 newFormData->appendFileRange(element.m_filename, element.m_fileStart , element.m_fileLength, element.m_expectedFileModificationTime, element.m_should GenerateFile);
371 else if (element.m_type == FormDataElement::encodedBlob) 377 else if (element.m_type == FormDataElement::encodedBlob)
372 appendBlobResolved(newFormData.get(), element.m_url); 378 appendBlobResolved(newFormData.get(), element.m_blobUUID);
373 else 379 else
374 ASSERT_NOT_REACHED(); 380 ASSERT_NOT_REACHED();
375 } 381 }
376 return newFormData.release(); 382 return newFormData.release();
377 } 383 }
378 #endif 384 #endif // CHROMIUM
385 #endif // BLOB
379 386
380 void FormData::generateFiles(Document* document) 387 void FormData::generateFiles(Document* document)
381 { 388 {
382 ASSERT(!m_hasGeneratedFiles); 389 ASSERT(!m_hasGeneratedFiles);
383 390
384 if (m_hasGeneratedFiles) 391 if (m_hasGeneratedFiles)
385 return; 392 return;
386 393
387 Page* page = document->page(); 394 Page* page = document->page();
388 if (!page) 395 if (!page)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 info.addMember(m_boundary); 431 info.addMember(m_boundary);
425 info.addMember(m_elements); 432 info.addMember(m_elements);
426 } 433 }
427 434
428 void FormDataElement::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) cons t 435 void FormDataElement::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) cons t
429 { 436 {
430 MemoryClassInfo info(memoryObjectInfo, this, PlatformMemoryTypes::Loader); 437 MemoryClassInfo info(memoryObjectInfo, this, PlatformMemoryTypes::Loader);
431 info.addMember(m_data); 438 info.addMember(m_data);
432 info.addMember(m_filename); 439 info.addMember(m_filename);
433 #if ENABLE(BLOB) 440 #if ENABLE(BLOB)
434 info.addMember(m_url); 441 info.addMember(m_blobUUID);
435 #endif 442 #endif
436 info.addMember(m_generatedFilename); 443 info.addMember(m_generatedFilename);
437 } 444 }
438 445
439 static void encodeElement(Encoder& encoder, const FormDataElement& element) 446 static void encodeElement(Encoder& encoder, const FormDataElement& element)
440 { 447 {
441 encoder.encodeUInt32(element.m_type); 448 encoder.encodeUInt32(element.m_type);
442 449
443 switch (element.m_type) { 450 switch (element.m_type) {
444 case FormDataElement::data: 451 case FormDataElement::data:
(...skipping 10 matching lines...) Expand all
455 encoder.encodeDouble(element.m_expectedFileModificationTime); 462 encoder.encodeDouble(element.m_expectedFileModificationTime);
456 #else 463 #else
457 encoder.encodeInt64(0); 464 encoder.encodeInt64(0);
458 encoder.encodeInt64(0); 465 encoder.encodeInt64(0);
459 encoder.encodeDouble(invalidFileTime()); 466 encoder.encodeDouble(invalidFileTime());
460 #endif 467 #endif
461 return; 468 return;
462 469
463 #if ENABLE(BLOB) 470 #if ENABLE(BLOB)
464 case FormDataElement::encodedBlob: 471 case FormDataElement::encodedBlob:
465 encoder.encodeString(element.m_url.string()); 472 encoder.encodeString(element.m_blobUUID);
466 return; 473 return;
467 #endif 474 #endif
468 475
469 #if ENABLE(FILE_SYSTEM) 476 #if ENABLE(FILE_SYSTEM)
470 case FormDataElement::encodedURL: 477 case FormDataElement::encodedFileSystemURL:
471 encoder.encodeString(element.m_url.string()); 478 encoder.encodeString(element.m_fileSystemURL.string());
472 encoder.encodeInt64(element.m_fileStart); 479 encoder.encodeInt64(element.m_fileStart);
473 encoder.encodeInt64(element.m_fileLength); 480 encoder.encodeInt64(element.m_fileLength);
474 encoder.encodeDouble(element.m_expectedFileModificationTime); 481 encoder.encodeDouble(element.m_expectedFileModificationTime);
475 return; 482 return;
476 #endif 483 #endif
477 } 484 }
478 485
479 ASSERT_NOT_REACHED(); 486 ASSERT_NOT_REACHED();
480 } 487 }
481 488
(...skipping 10 matching lines...) Expand all
492 if (!decoder.decodeBytes(data)) 499 if (!decoder.decodeBytes(data))
493 return false; 500 return false;
494 size_t size = data.size(); 501 size_t size = data.size();
495 element.m_data.resize(size); 502 element.m_data.resize(size);
496 memcpy(element.m_data.data(), data.data(), size); 503 memcpy(element.m_data.data(), data.data(), size);
497 return true; 504 return true;
498 } 505 }
499 506
500 case FormDataElement::encodedFile: 507 case FormDataElement::encodedFile:
501 #if ENABLE(FILE_SYSTEM) 508 #if ENABLE(FILE_SYSTEM)
502 case FormDataElement::encodedURL: 509 case FormDataElement::encodedFileSystemURL:
503 #endif 510 #endif
504 { 511 {
505 element.m_type = static_cast<FormDataElement::Type>(type); 512 element.m_type = static_cast<FormDataElement::Type>(type);
506 String filenameOrURL; 513 String filenameOrURL;
507 if (!decoder.decodeString(filenameOrURL)) 514 if (!decoder.decodeString(filenameOrURL))
508 return false; 515 return false;
509 if (type == FormDataElement::encodedFile) { 516 if (type == FormDataElement::encodedFile) {
510 if (!decoder.decodeString(element.m_generatedFilename)) 517 if (!decoder.decodeString(element.m_generatedFilename))
511 return false; 518 return false;
512 if (!decoder.decodeBool(element.m_shouldGenerateFile)) 519 if (!decoder.decodeBool(element.m_shouldGenerateFile))
513 return false; 520 return false;
514 } 521 }
515 int64_t fileStart; 522 int64_t fileStart;
516 if (!decoder.decodeInt64(fileStart)) 523 if (!decoder.decodeInt64(fileStart))
517 return false; 524 return false;
518 if (fileStart < 0) 525 if (fileStart < 0)
519 return false; 526 return false;
520 int64_t fileLength; 527 int64_t fileLength;
521 if (!decoder.decodeInt64(fileLength)) 528 if (!decoder.decodeInt64(fileLength))
522 return false; 529 return false;
523 if (fileLength != BlobDataItem::toEndOfFile && fileLength < fileStart) 530 if (fileLength != BlobDataItem::toEndOfFile && fileLength < fileStart)
524 return false; 531 return false;
525 double expectedFileModificationTime; 532 double expectedFileModificationTime;
526 if (!decoder.decodeDouble(expectedFileModificationTime)) 533 if (!decoder.decodeDouble(expectedFileModificationTime))
527 return false; 534 return false;
528 535
529 #if ENABLE(FILE_SYSTEM) 536 #if ENABLE(FILE_SYSTEM)
530 if (type == FormDataElement::encodedURL) 537 if (type == FormDataElement::encodedFileSystemURL)
531 element.m_url = KURL(KURL(), filenameOrURL); 538 element.m_fileSystemURL = KURL(KURL(), filenameOrURL);
532 else 539 else
533 #endif 540 #endif
534 element.m_filename = filenameOrURL; 541 element.m_filename = filenameOrURL;
535 542
536 #if ENABLE(BLOB) 543 #if ENABLE(BLOB)
537 element.m_fileStart = fileStart; 544 element.m_fileStart = fileStart;
538 element.m_fileLength = fileLength; 545 element.m_fileLength = fileLength;
539 element.m_expectedFileModificationTime = expectedFileModificationTime; 546 element.m_expectedFileModificationTime = expectedFileModificationTime;
540 #endif 547 #endif
541 return true; 548 return true;
542 } 549 }
543 550
544 #if ENABLE(BLOB) 551 #if ENABLE(BLOB)
545 case FormDataElement::encodedBlob: 552 case FormDataElement::encodedBlob:
546 element.m_type = FormDataElement::encodedBlob; 553 element.m_type = FormDataElement::encodedBlob;
547 String blobURLString; 554 String blobUUID;
548 if (!decoder.decodeString(blobURLString)) 555 if (!decoder.decodeString(blobUUID))
549 return false; 556 return false;
550 element.m_url = KURL(KURL(), blobURLString); 557 element.m_blobUUID = blobUUID;
558 // Note we're not setting the optionalBlobDataHandle here.
551 return true; 559 return true;
552 #endif 560 #endif
553 561
554 } 562 }
555 563
556 return false; 564 return false;
557 } 565 }
558 566
559 void FormData::encode(Encoder& encoder) const 567 void FormData::encode(Encoder& encoder) const
560 { 568 {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 if (!decoder.decodeBool(data->m_hasGeneratedFiles)) 607 if (!decoder.decodeBool(data->m_hasGeneratedFiles))
600 return 0; 608 return 0;
601 609
602 if (!decoder.decodeInt64(data->m_identifier)) 610 if (!decoder.decodeInt64(data->m_identifier))
603 return 0; 611 return 0;
604 612
605 return data.release(); 613 return data.release();
606 } 614 }
607 615
608 } // namespace WebCore 616 } // namespace WebCore
OLDNEW
« no previous file with comments | « WebCore/platform/network/FormData.h ('k') | WebCore/platform/network/chromium/BlobRegistryProxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698