#ifndef Blob_h
#define Blob_h
#include "BlobPart.h"
#include "ScriptWrappable.h"
#include "URLRegistry.h"
#include <wtf/RefCounted.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
class ScriptExecutionContext;
class Blob : public ScriptWrappable, public URLRegistrable, public RefCounted<Blob> {
public:
static Ref<Blob> create()
{
return adoptRef(*new Blob);
}
static Ref<Blob> create(Vector<uint8_t> data, const String& contentType)
{
return adoptRef(*new Blob(WTFMove(data), contentType));
}
static Ref<Blob> create(Vector<BlobPart> blobParts, const String& contentType)
{
return adoptRef(*new Blob(WTFMove(blobParts), contentType));
}
static Ref<Blob> deserialize(const URL& srcURL, const String& type, long long size, const String& fileBackedPath)
{
ASSERT(Blob::isNormalizedContentType(type));
return adoptRef(*new Blob(deserializationContructor, srcURL, type, size, fileBackedPath));
}
virtual ~Blob();
const URL& url() const { return m_internalURL; }
const String& type() const { return m_type; }
unsigned long long size() const;
virtual bool isFile() const { return false; }
static bool isValidContentType(const String&);
static String normalizedContentType(const String&);
#if !ASSERT_DISABLED
static bool isNormalizedContentType(const String&);
static bool isNormalizedContentType(const CString&);
#endif
URLRegistry& registry() const override;
Ref<Blob> slice(long long start = 0, long long end = std::numeric_limits<long long>::max(), const String& contentType = String()) const
{
return adoptRef(*new Blob(m_internalURL, start, end, contentType));
}
protected:
Blob();
Blob(Vector<uint8_t>, const String& contentType);
Blob(Vector<BlobPart>, const String& contentType);
enum UninitializedContructor { uninitializedContructor };
Blob(UninitializedContructor);
enum DeserializationContructor { deserializationContructor };
Blob(DeserializationContructor, const URL& srcURL, const String& type, long long size, const String& fileBackedPath);
Blob(const URL& srcURL, long long start, long long end, const String& contentType);
URL m_internalURL;
String m_type;
mutable long long m_size;
};
}
#endif // Blob_h