Index: WebCore/html/Blob.cpp |
diff --git a/WebCore/html/Blob.cpp b/WebCore/html/Blob.cpp |
index 83bbdc0c526484542688192621684b6282024bf4..0546f1c3c0882da2208a9e6a0a762db4359bee4a 100644 |
--- a/WebCore/html/Blob.cpp |
+++ b/WebCore/html/Blob.cpp |
@@ -31,88 +31,65 @@ |
#include "config.h" |
#include "Blob.h" |
+#include "BlobItem.h" |
#include "FileSystem.h" |
namespace WebCore { |
-#if ENABLE(BLOB_SLICE) |
-const int Blob::toEndOfFile = -1; |
-const double Blob::doNotCheckFileChange = 0; |
-#endif |
- |
Blob::Blob(const String& path) |
- : m_path(path) |
-#if ENABLE(BLOB_SLICE) |
- , m_start(0) |
- , m_length(toEndOfFile) |
- , m_snapshotCaptured(false) |
- , m_snapshotSize(0) |
- , m_snapshotModificationTime(doNotCheckFileChange) |
-#endif |
-{ |
-} |
- |
-#if ENABLE(BLOB_SLICE) |
-Blob::Blob(const String& path, long long start, long long length, long long snapshotSize, double snapshotModificationTime) |
- : m_path(path) |
- , m_start(start) |
- , m_length(length) |
- , m_snapshotCaptured(true) |
- , m_snapshotSize(snapshotSize) |
- , m_snapshotModificationTime(snapshotModificationTime) |
{ |
- ASSERT(start >= 0 && length >= 0 && start + length <= snapshotSize && snapshotModificationTime); |
+ // Note: this doesn't initialize the type unlike File(path). |
+ append(FileBlobItem::create(path)); |
} |
-#endif |
unsigned long long Blob::size() const |
{ |
// FIXME: JavaScript cannot represent sizes as large as unsigned long long, we need to |
// come up with an exception to throw if file size is not represetable. |
-#if ENABLE(BLOB_SLICE) |
- if (m_snapshotCaptured) |
- return m_length; |
-#endif |
- long long size; |
- if (!getFileSize(m_path, size)) |
- return 0; |
- return static_cast<unsigned long long>(size); |
+ unsigned long long size = 0; |
+ for (size_t i = 0; i < m_items.size(); ++i) |
+ size += m_items[i]->size(); |
+ return size; |
+} |
+ |
+const String& Blob::path() const |
+{ |
+ ASSERT(m_items.size() == 1 && m_items[0]->toFileBlobItem()); |
+ return m_items[0]->toFileBlobItem()->path(); |
+} |
+ |
+void Blob::append(PassRefPtr<BlobItem> item) |
+{ |
+ m_items.append(item); |
} |
#if ENABLE(BLOB_SLICE) |
PassRefPtr<Blob> Blob::slice(long long start, long long length) const |
{ |
- // When we slice a file for the first time, we obtain a snapshot of the file by capturing its current size and modification time. |
- // The modification time will be used to verify if the file has been changed or not, when the underlying data are accessed. |
- long long snapshotSize; |
- double snapshotModificationTime; |
- if (m_snapshotCaptured) { |
- snapshotSize = m_snapshotSize; |
- snapshotModificationTime = m_snapshotModificationTime; |
- } else { |
- // If we fail to retrieve the size or modification time, probably due to that the file has been deleted, an empty blob will be returned. |
- time_t modificationTime; |
- if (!getFileSize(m_path, snapshotSize) || !getFileModificationTime(m_path, modificationTime)) { |
- snapshotSize = 0; |
- snapshotModificationTime = 0; |
- } else |
- snapshotModificationTime = modificationTime; |
- } |
- |
- // Clamp the range if it exceeds the size limit. |
if (start < 0) |
start = 0; |
if (length < 0) |
length = 0; |
- if (start > snapshotSize) { |
+ // Clamp the range if it exceeds the size limit. |
+ unsigned long long totalSize = size(); |
+ if (static_cast<unsigned long long>(start) > totalSize) { |
start = 0; |
length = 0; |
- } else if (start + length > snapshotSize) |
- length = snapshotSize - start; |
+ } else if (static_cast<unsigned long long>(start + length) > totalSize) |
+ length = totalSize - start; |
- return adoptRef(new Blob(m_path, m_start + start, length, snapshotSize, snapshotModificationTime)); |
+ size_t i = 0; |
+ RefPtr<Blob> blob = Blob::create(); |
+ for (; i < m_items.size() && static_cast<unsigned long long>(start) >= m_items[i]->size(); ++i) |
+ start -= m_items[i]->size(); |
+ for (; length > 0 && i < m_items.size(); ++i) { |
+ blob->m_items.append(m_items[i]->slice(start, length)); |
+ length -= blob->m_items.last()->size(); |
+ start = 0; |
+ } |
+ return blob.release(); |
} |
-#endif |
+#endif // ENABLE(BLOB_SLICE) |
} // namespace WebCore |