PassRefPtr<FormData> FormData::resolveBlobReferences() { // First check if any blobs needs to be resolved, or we can take the fast path. bool hasBlob = false; Vector<FormDataElement>::const_iterator it = elements().begin(); const Vector<FormDataElement>::const_iterator itend = elements().end(); for (; it != itend; ++it) { if (it->m_type == FormDataElement::Type::EncodedBlob) { hasBlob = true; break; } } if (!hasBlob) return this; // Create a copy to append the result into. RefPtr<FormData> newFormData = FormData::create(); newFormData->setAlwaysStream(alwaysStream()); newFormData->setIdentifier(identifier()); it = elements().begin(); for (; it != itend; ++it) { const FormDataElement& element = *it; if (element.m_type == FormDataElement::Type::Data) newFormData->appendData(element.m_data.data(), element.m_data.size()); else if (element.m_type == FormDataElement::Type::EncodedFile) newFormData->appendFileRange(element.m_filename, element.m_fileStart, element.m_fileLength, element.m_expectedFileModificationTime, element.m_shouldGenerateFile); else if (element.m_type == FormDataElement::Type::EncodedBlob) appendBlobResolved(newFormData.get(), element.m_url); else ASSERT_NOT_REACHED(); } return newFormData.release(); }
static void appendBlobResolved(FormData* formData, const URL& url) { if (!blobRegistry().isBlobRegistryImpl()) { LOG_ERROR("Tried to resolve a blob without a usable registry"); return; } BlobStorageData* blobData = static_cast<BlobRegistryImpl&>(blobRegistry()).getBlobDataFromURL(URL(ParsedURLString, url)); if (!blobData) { LOG_ERROR("Could not get blob data from a registry"); return; } BlobDataItemList::const_iterator it = blobData->items().begin(); const BlobDataItemList::const_iterator itend = blobData->items().end(); for (; it != itend; ++it) { const BlobDataItem& blobItem = *it; if (blobItem.type == BlobDataItem::Data) formData->appendData(blobItem.data->data() + static_cast<int>(blobItem.offset), static_cast<int>(blobItem.length)); else if (blobItem.type == BlobDataItem::File) formData->appendFileRange(blobItem.path, blobItem.offset, blobItem.length, blobItem.expectedModificationTime); else if (blobItem.type == BlobDataItem::Blob) appendBlobResolved(formData, blobItem.url); else ASSERT_NOT_REACHED(); } }