FileReaderLoader.h [plain text]
#pragma once
#include "BlobResourceHandle.h"
#include "FileError.h"
#include "URL.h"
#include "TextEncoding.h"
#include "ThreadableLoaderClient.h"
#include <wtf/Forward.h>
#include <wtf/text/WTFString.h>
namespace JSC {
class ArrayBuffer;
}
namespace WebCore {
class Blob;
class FileReaderLoaderClient;
class ScriptExecutionContext;
class TextResourceDecoder;
class ThreadableLoader;
class FileReaderLoader : public ThreadableLoaderClient {
public:
enum ReadType {
ReadAsArrayBuffer,
ReadAsBinaryString,
ReadAsBlob,
ReadAsText,
ReadAsDataURL
};
FileReaderLoader(ReadType, FileReaderLoaderClient*);
~FileReaderLoader();
void start(ScriptExecutionContext*, Blob&);
void cancel();
void didReceiveResponse(unsigned long, const ResourceResponse&) override;
void didReceiveData(const char*, int) override;
void didFinishLoading(unsigned long) override;
void didFail(const ResourceError&) override;
String stringResult();
RefPtr<JSC::ArrayBuffer> arrayBufferResult() const;
unsigned bytesLoaded() const { return m_bytesLoaded; }
unsigned totalBytes() const { return m_totalBytes; }
int errorCode() const { return m_errorCode; }
void setEncoding(const String&);
void setDataType(const String& dataType) { m_dataType = dataType; }
private:
void terminate();
void cleanup();
void failed(int errorCode);
void convertToText();
void convertToDataURL();
bool isCompleted() const;
static FileError::ErrorCode httpStatusCodeToErrorCode(int);
static FileError::ErrorCode toErrorCode(BlobResourceHandle::Error);
ReadType m_readType;
FileReaderLoaderClient* m_client;
TextEncoding m_encoding;
String m_dataType;
URL m_urlForReading;
RefPtr<ThreadableLoader> m_loader;
RefPtr<JSC::ArrayBuffer> m_rawData;
bool m_isRawDataConverted;
String m_stringResult;
RefPtr<Blob> m_blobResult;
RefPtr<TextResourceDecoder> m_decoder;
bool m_variableLength;
unsigned m_bytesLoaded;
unsigned m_totalBytes;
int m_errorCode;
};
}