#ifndef FileReader_h
#define FileReader_h
#if ENABLE(BLOB)
#include "ActiveDOMObject.h"
#include "EventTarget.h"
#include "FileError.h"
#include "FileReaderLoader.h"
#include "FileReaderLoaderClient.h"
#include <wtf/Forward.h>
#include <wtf/RefCounted.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
class ArrayBuffer;
class Blob;
class ScriptExecutionContext;
class FileReader : public RefCounted<FileReader>, public ActiveDOMObject, public EventTarget, public FileReaderLoaderClient {
public:
static PassRefPtr<FileReader> create(ScriptExecutionContext* context)
{
return adoptRef(new FileReader(context));
}
virtual ~FileReader();
enum ReadyState {
EMPTY = 0,
LOADING = 1,
DONE = 2
};
void readAsArrayBuffer(Blob*);
void readAsBinaryString(Blob*);
void readAsText(Blob*, const String& encoding = "");
void readAsDataURL(Blob*);
void abort();
void start();
void doAbort();
ReadyState readyState() const;
PassRefPtr<FileError> error() { return m_error; }
FileReaderLoader::ReadType readType() const { return m_readType; }
PassRefPtr<ArrayBuffer> arrayBufferResult() const;
String stringResult();
virtual bool canSuspend() const;
virtual void stop();
virtual bool hasPendingActivity() const;
virtual FileReader* toFileReader() { return this; }
virtual ScriptExecutionContext* scriptExecutionContext() const { return ActiveDOMObject::scriptExecutionContext(); }
virtual void didStartLoading();
virtual void didReceiveData();
virtual void didFinishLoading();
virtual void didFail(int errorCode);
using RefCounted<FileReader>::ref;
using RefCounted<FileReader>::deref;
DEFINE_ATTRIBUTE_EVENT_LISTENER(loadstart);
DEFINE_ATTRIBUTE_EVENT_LISTENER(progress);
DEFINE_ATTRIBUTE_EVENT_LISTENER(load);
DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
DEFINE_ATTRIBUTE_EVENT_LISTENER(loadend);
private:
enum InternalState {
None,
Starting,
Opening,
Reading,
Aborting,
Completed
};
FileReader(ScriptExecutionContext*);
virtual void refEventTarget() { ref(); }
virtual void derefEventTarget() { deref(); }
virtual EventTargetData* eventTargetData() { return &m_eventTargetData; }
virtual EventTargetData* ensureEventTargetData() { return &m_eventTargetData; }
void terminate();
void readInternal(Blob*, FileReaderLoader::ReadType);
void fireErrorEvent(int httpStatusCode);
void fireEvent(const AtomicString& type);
InternalState m_state;
EventTargetData m_eventTargetData;
RefPtr<Blob> m_blob;
FileReaderLoader::ReadType m_readType;
String m_encoding;
OwnPtr<FileReaderLoader> m_loader;
RefPtr<FileError> m_error;
double m_lastProgressNotificationTimeMS;
};
}
#endif // ENABLE(BLOB)
#endif // FileReader_h