#pragma once
#include "Blob.h"
#include <wtf/Optional.h>
#include <wtf/Ref.h>
#include <wtf/TypeCasts.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
class URL;
class File final : public Blob {
public:
struct PropertyBag : BlobPropertyBag {
std::optional<long long> lastModified;
};
static Ref<File> create(const String& path)
{
return adoptRef(*new File(path));
}
static Ref<File> create(Vector<BlobPartVariant>&& blobPartVariants, const String& filename, const PropertyBag& propertyBag)
{
return adoptRef(*new File(WTFMove(blobPartVariants), filename, propertyBag));
}
static Ref<File> deserialize(const String& path, const URL& srcURL, const String& type, const String& name)
{
return adoptRef(*new File(deserializationContructor, path, srcURL, type, name));
}
static Ref<File> createWithName(const String& path, const String& nameOverride)
{
if (nameOverride.isEmpty())
return adoptRef(*new File(path));
return adoptRef(*new File(path, nameOverride));
}
bool isFile() const override { return true; }
const String& path() const { return m_path; }
const String& name() const { return m_name; }
WEBCORE_EXPORT double lastModified() const;
static String contentTypeForFile(const String& path);
#if ENABLE(FILE_REPLACEMENT)
static bool shouldReplaceFile(const String& path);
#endif
private:
WEBCORE_EXPORT explicit File(const String& path);
File(const String& path, const String& nameOverride);
File(Vector<BlobPartVariant>&& blobPartVariants, const String& filename, const PropertyBag&);
File(DeserializationContructor, const String& path, const URL& srcURL, const String& type, const String& name);
static void computeNameAndContentType(const String& path, const String& nameOverride, String& effectiveName, String& effectiveContentType);
#if ENABLE(FILE_REPLACEMENT)
static void computeNameAndContentTypeForReplacedFile(const String& path, const String& nameOverride, String& effectiveName, String& effectiveContentType);
#endif
String m_path;
String m_name;
std::optional<int64_t> m_overrideLastModifiedDate;
};
}
SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::File)
static bool isType(const WebCore::Blob& blob) { return blob.isFile(); }
SPECIALIZE_TYPE_TRAITS_END()