#ifndef File_h
#define File_h
#include "core/fileapi/Blob.h"
#include "heap/Handle.h"
#include "wtf/PassRefPtr.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
class ExceptionState;
class ExecutionContext;
struct FileMetadata;
class KURL;
class File FINAL : public Blob {
public:
enum ContentTypeLookupPolicy {
WellKnownContentTypes,
AllContentTypes,
};
static PassRefPtrWillBeRawPtr<File> create(const String& path, ContentTypeLookupPolicy policy = WellKnownContentTypes)
{
return adoptRefWillBeNoop(new File(path, policy));
}
static PassRefPtrWillBeRawPtr<File> create(const String& name, double modificationTime, PassRefPtr<BlobDataHandle> blobDataHandle)
{
return adoptRefWillBeNoop(new File(name, modificationTime, blobDataHandle));
}
static PassRefPtrWillBeRawPtr<File> create(const String& path, const String& name, const String& relativePath, bool hasSnaphotData, uint64_t size, double lastModified, PassRefPtr<BlobDataHandle> blobDataHandle)
{
return adoptRefWillBeNoop(new File(path, name, relativePath, hasSnaphotData, size, lastModified, blobDataHandle));
}
static PassRefPtrWillBeRawPtr<File> createWithRelativePath(const String& path, const String& relativePath);
static PassRefPtrWillBeRawPtr<File> createForFileSystemFile(const String& name, const FileMetadata& metadata)
{
return adoptRefWillBeNoop(new File(name, metadata));
}
static PassRefPtrWillBeRawPtr<File> createForFileSystemFile(const KURL& url, const FileMetadata& metadata)
{
return adoptRefWillBeNoop(new File(url, metadata));
}
KURL fileSystemURL() const { ASSERT(hasValidFileSystemURL()); return m_fileSystemURL; }
static PassRefPtrWillBeRawPtr<File> createWithName(const String& path, const String& name, ContentTypeLookupPolicy policy = WellKnownContentTypes)
{
if (name.isEmpty())
return adoptRefWillBeNoop(new File(path, policy));
return adoptRefWillBeNoop(new File(path, name, policy));
}
virtual unsigned long long size() const OVERRIDE;
virtual PassRefPtrWillBeRawPtr<Blob> slice(long long start, long long end, const String& contentType, ExceptionState&) const OVERRIDE;
virtual void close(ExecutionContext*, ExceptionState&) OVERRIDE;
virtual bool isFile() const OVERRIDE { return true; }
virtual bool hasBackingFile() const OVERRIDE { return m_hasBackingFile; }
virtual void appendTo(BlobData&) const OVERRIDE;
const String& path() const { ASSERT(hasValidFilePath()); return m_path; }
const String name() const { return m_name; }
double lastModifiedDate() const;
const String& webkitRelativePath() const { return m_relativePath; }
void captureSnapshot(long long& snapshotSize, double& snapshotModificationTime) const;
bool hasValidSnapshotMetadata() const { return m_snapshotSize >= 0; }
private:
File(const String& path, ContentTypeLookupPolicy);
File(const String& path, const String& name, ContentTypeLookupPolicy);
File(const String& path, const String& name, const String& relativePath, bool hasSnaphotData, uint64_t size, double lastModified, PassRefPtr<BlobDataHandle>);
File(const String& name, double modificationTime, PassRefPtr<BlobDataHandle>);
File(const String& name, const FileMetadata&);
File(const KURL& fileSystemURL, const FileMetadata&);
void invalidateSnapshotMetadata() { m_snapshotSize = -1; }
#ifndef NDEBUG
bool hasValidFileSystemURL() const { return hasBackingFile(); }
bool hasValidFilePath() const { return hasBackingFile() || m_path.isEmpty(); }
#endif
bool m_hasBackingFile;
String m_path;
String m_name;
KURL m_fileSystemURL;
long long m_snapshotSize;
const double m_snapshotModificationTime;
String m_relativePath;
};
DEFINE_TYPE_CASTS(File, Blob, blob, blob->isFile(), blob.isFile());
}
#endif