| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 if (!arrayBufferView) | 87 if (!arrayBufferView) |
| 88 return; | 88 return; |
| 89 | 89 |
| 90 appendBytesData(arrayBufferView->baseAddress(), arrayBufferView->byteLength(
)); | 90 appendBytesData(arrayBufferView->baseAddress(), arrayBufferView->byteLength(
)); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void BlobBuilder::append(Blob* blob) | 93 void BlobBuilder::append(Blob* blob) |
| 94 { | 94 { |
| 95 if (!blob) | 95 if (!blob) |
| 96 return; | 96 return; |
| 97 if (blob->isFile()) { | 97 if (blob->isOnFilesystem()) { |
| 98 File* file = toFile(blob); | 98 File* file = toFile(blob); |
| 99 // If the blob is file that is not snapshoted, capture the snapshot now. | 99 // If the blob is file that is not snapshoted, capture the snapshot now. |
| 100 // FIXME: This involves synchronous file operation. We need to figure ou
t how to make it asynchronous. | 100 // FIXME: This involves synchronous file operation. We need to figure ou
t how to make it asynchronous. |
| 101 long long snapshotSize; | 101 long long snapshotSize; |
| 102 double snapshotModificationTime; | 102 double snapshotModificationTime; |
| 103 file->captureSnapshot(snapshotSize, snapshotModificationTime); | 103 file->captureSnapshot(snapshotSize, snapshotModificationTime); |
| 104 | 104 |
| 105 m_size += snapshotSize; | 105 m_size += snapshotSize; |
| 106 if (!file->fileSystemURL().isEmpty()) | 106 if (!file->fileSystemURL().isEmpty()) |
| 107 m_items.append(BlobDataItem(file->fileSystemURL(), 0, snapshotSize,
snapshotModificationTime)); | 107 m_items.append(BlobDataItem(file->fileSystemURL(), 0, snapshotSize,
snapshotModificationTime)); |
| 108 else | 108 else |
| 109 m_items.append(BlobDataItem(file->path(), 0, snapshotSize, snapshotM
odificationTime)); | 109 m_items.append(BlobDataItem(file->path(), 0, snapshotSize, snapshotM
odificationTime)); |
| 110 } else { | 110 } else { |
| 111 long long blobSize = static_cast<long long>(blob->size()); | 111 long long blobSize = static_cast<long long>(blob->size()); |
| 112 m_size += blobSize; | 112 m_size += blobSize; |
| 113 m_items.append(BlobDataItem(blob->blobDataHandle(), 0, blobSize)); | 113 m_items.append(BlobDataItem(blob->blobDataHandle(), 0, blobSize)); |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 void BlobBuilder::appendBytesData(const void* data, size_t length) | 117 void BlobBuilder::appendBytesData(const void* data, size_t length) |
| 118 { | 118 { |
| 119 Vector<char>& buffer = getBuffer(); | 119 Vector<char>& buffer = getBuffer(); |
| 120 size_t oldSize = buffer.size(); | 120 size_t oldSize = buffer.size(); |
| 121 buffer.append(static_cast<const char*>(data), length); | 121 buffer.append(static_cast<const char*>(data), length); |
| 122 m_size += buffer.size() - oldSize; | 122 m_size += buffer.size() - oldSize; |
| 123 } | 123 } |
| 124 | 124 |
| 125 PassRefPtr<Blob> BlobBuilder::getBlob(const String& contentType) | 125 PassRefPtr<Blob> BlobBuilder::createBlob(const String& contentType) |
| 126 { | 126 { |
| 127 OwnPtr<BlobData> blobData = BlobData::create(); | 127 OwnPtr<BlobData> blobData = BlobData::create(); |
| 128 blobData->setContentType(contentType); | 128 blobData->setContentType(contentType); |
| 129 blobData->swapItems(m_items); | 129 blobData->swapItems(m_items); |
| 130 | 130 |
| 131 RefPtr<Blob> blob = Blob::create(BlobDataHandle::create(blobData.release(),
m_size)); | 131 RefPtr<Blob> blob = Blob::create(BlobDataHandle::create(blobData.release(),
m_size)); |
| 132 | 132 |
| 133 // After creating a blob from the current blob data, we do not need to keep
the data around any more. | 133 // After creating a blob from the current blob data, we do not need to keep
the data around any more. |
| 134 // Instead, we only need to keep a reference to the blob data just created. | 134 // Instead, we only need to keep a reference to the blob data just created. |
| 135 m_items.append(BlobDataItem(blob->blobDataHandle(), 0, m_size)); | 135 m_items.append(BlobDataItem(blob->blobDataHandle(), 0, m_size)); |
| 136 | 136 |
| 137 return blob; | 137 return blob.release(); |
| 138 } |
| 139 |
| 140 PassRefPtr<File> BlobBuilder::createFile(const String& contentType, const String
& fileName, double modificationTime) |
| 141 { |
| 142 OwnPtr<BlobData> blobData = BlobData::create(); |
| 143 blobData->setContentType(contentType); |
| 144 blobData->swapItems(m_items); |
| 145 |
| 146 RefPtr<File> file = File::create(fileName, modificationTime, BlobDataHandle:
:create(blobData.release(), m_size)); |
| 147 |
| 148 // After creating a file from the current blob data, we do not need to keep
the data around any more. |
| 149 // Instead, we only need to keep a reference to the blob data just created. |
| 150 m_items.append(BlobDataItem(file->blobDataHandle(), 0, m_size)); |
| 151 |
| 152 return file.release(); |
| 138 } | 153 } |
| 139 | 154 |
| 140 } // namespace WebCore | 155 } // namespace WebCore |
| OLD | NEW |