#ifndef FileWriter_h
#define FileWriter_h
#include "bindings/v8/ScriptWrappable.h"
#include "core/dom/ActiveDOMObject.h"
#include "core/dom/ExecutionContext.h"
#include "core/events/EventTarget.h"
#include "core/fileapi/FileError.h"
#include "heap/Handle.h"
#include "modules/filesystem/FileWriterBase.h"
#include "public/platform/WebFileWriterClient.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefPtr.h"
namespace WebCore {
class Blob;
class ExceptionState;
class ExecutionContext;
class FileWriter FINAL : public FileWriterBase, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithInlineData, public blink::WebFileWriterClient {
DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedWillBeRefCountedGarbageCollected<FileWriterBase>);
public:
static PassRefPtrWillBeRawPtr<FileWriter> create(ExecutionContext*);
enum ReadyState {
INIT = 0,
WRITING = 1,
DONE = 2
};
void write(Blob*, ExceptionState&);
void seek(long long position, ExceptionState&);
void truncate(long long length, ExceptionState&);
void abort(ExceptionState&);
ReadyState readyState() const { return m_readyState; }
FileError* error() const { return m_error.get(); }
virtual void didWrite(long long bytes, bool complete) OVERRIDE;
virtual void didTruncate() OVERRIDE;
virtual void didFail(blink::WebFileError) OVERRIDE;
virtual void stop() OVERRIDE;
virtual const AtomicString& interfaceName() const OVERRIDE;
virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveDOMObject::executionContext(); }
DEFINE_ATTRIBUTE_EVENT_LISTENER(writestart);
DEFINE_ATTRIBUTE_EVENT_LISTENER(progress);
DEFINE_ATTRIBUTE_EVENT_LISTENER(write);
DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
DEFINE_ATTRIBUTE_EVENT_LISTENER(writeend);
virtual void trace(Visitor*) OVERRIDE;
private:
enum Operation {
OperationNone,
OperationWrite,
OperationTruncate,
OperationAbort
};
FileWriter(ExecutionContext*);
virtual ~FileWriter();
void completeAbort();
void doOperation(Operation);
void signalCompletion(FileError::ErrorCode);
void fireEvent(const AtomicString& type);
void setError(FileError::ErrorCode, ExceptionState&);
RefPtrWillBeMember<FileError> m_error;
ReadyState m_readyState;
Operation m_operationInProgress;
Operation m_queuedOperation;
long long m_bytesWritten;
long long m_bytesToWrite;
long long m_truncateLength;
long long m_numAborts;
long long m_recursionDepth;
double m_lastProgressNotificationTimeMS;
RefPtrWillBeMember<Blob> m_blobBeingWritten;
};
}
#endif