#ifndef BlobData_h
#define BlobData_h
#include "platform/FileMetadata.h"
#include "platform/weborigin/KURL.h"
#include "wtf/Forward.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/ThreadSafeRefCounted.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
class BlobDataHandle;
class PLATFORM_EXPORT RawData : public ThreadSafeRefCounted<RawData> {
public:
static PassRefPtr<RawData> create()
{
return adoptRef(new RawData());
}
void detachFromCurrentThread();
const char* data() const { return m_data.data(); }
size_t length() const { return m_data.size(); }
Vector<char>* mutableData() { return &m_data; }
private:
RawData();
Vector<char> m_data;
};
struct PLATFORM_EXPORT BlobDataItem {
static const long long toEndOfFile;
BlobDataItem()
: type(Data)
, offset(0)
, length(toEndOfFile)
, expectedModificationTime(invalidFileTime())
{
}
explicit BlobDataItem(PassRefPtr<RawData> data)
: type(Data)
, data(data)
, offset(0)
, length(toEndOfFile)
, expectedModificationTime(invalidFileTime())
{
}
explicit BlobDataItem(const String& path)
: type(File)
, path(path)
, offset(0)
, length(toEndOfFile)
, expectedModificationTime(invalidFileTime())
{
}
BlobDataItem(const String& path, long long offset, long long length, double expectedModificationTime)
: type(File)
, path(path)
, offset(offset)
, length(length)
, expectedModificationTime(expectedModificationTime)
{
}
BlobDataItem(PassRefPtr<BlobDataHandle> blobDataHandle, long long offset, long long length)
: type(Blob)
, blobDataHandle(blobDataHandle)
, offset(offset)
, length(length)
, expectedModificationTime(invalidFileTime())
{
}
BlobDataItem(const KURL& fileSystemURL, long long offset, long long length, double expectedModificationTime)
: type(FileSystemURL)
, fileSystemURL(fileSystemURL)
, offset(offset)
, length(length)
, expectedModificationTime(expectedModificationTime)
{
}
void detachFromCurrentThread();
const enum {
Data,
File,
Blob,
FileSystemURL
} type;
RefPtr<RawData> data;
String path;
KURL fileSystemURL;
RefPtr<BlobDataHandle> blobDataHandle;
long long offset;
long long length;
double expectedModificationTime;
private:
friend class BlobData;
BlobDataItem(PassRefPtr<RawData> data, long long offset, long long length)
: type(Data)
, data(data)
, offset(offset)
, length(length)
, expectedModificationTime(invalidFileTime())
{
}
};
typedef Vector<BlobDataItem> BlobDataItemList;
class PLATFORM_EXPORT BlobData {
WTF_MAKE_FAST_ALLOCATED;
public:
static PassOwnPtr<BlobData> create();
void detachFromCurrentThread();
const String& contentType() const { return m_contentType; }
void setContentType(const String& contentType) { m_contentType = contentType; }
const String& contentDisposition() const { return m_contentDisposition; }
void setContentDisposition(const String& contentDisposition) { m_contentDisposition = contentDisposition; }
const BlobDataItemList& items() const { return m_items; }
void swapItems(BlobDataItemList&);
void appendData(PassRefPtr<RawData>, long long offset, long long length);
void appendFile(const String& path);
void appendFile(const String& path, long long offset, long long length, double expectedModificationTime);
void appendBlob(PassRefPtr<BlobDataHandle>, long long offset, long long length);
void appendFileSystemURL(const KURL&, long long offset, long long length, double expectedModificationTime);
void appendText(const String&, bool normalizeLineEndingsToNative);
void appendArrayBuffer(const ArrayBuffer*);
void appendArrayBufferView(const ArrayBufferView*);
long long length() const;
private:
friend class BlobRegistryImpl;
friend class BlobStorageData;
void appendBytes(const void*, long long length);
BlobData() { }
String m_contentType;
String m_contentDisposition;
BlobDataItemList m_items;
};
class PLATFORM_EXPORT BlobDataHandle : public ThreadSafeRefCounted<BlobDataHandle> {
public:
static PassRefPtr<BlobDataHandle> create()
{
return adoptRef(new BlobDataHandle());
}
static PassRefPtr<BlobDataHandle> create(PassOwnPtr<BlobData> data, long long size)
{
return adoptRef(new BlobDataHandle(data, size));
}
static PassRefPtr<BlobDataHandle> create(const String& uuid, const String& type, long long size)
{
return adoptRef(new BlobDataHandle(uuid, type, size));
}
String uuid() const { return m_uuid.isolatedCopy(); }
String type() const { return m_type.isolatedCopy(); }
unsigned long long size() { return m_size; }
~BlobDataHandle();
private:
BlobDataHandle();
BlobDataHandle(PassOwnPtr<BlobData>, long long size);
BlobDataHandle(const String& uuid, const String& type, long long size);
const String m_uuid;
const String m_type;
const long long m_size;
};
}
#endif