2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "core/dom/ActiveDOMObject.h"
35 #include "core/dom/ExecutionContext.h"
36 #include "core/fileapi/FileError.h"
37 #include "modules/EventTargetModules.h"
38 #include "modules/filesystem/FileWriterBase.h"
39 #include "platform/heap/Handle.h"
40 #include "public/platform/WebFileWriterClient.h"
41 #include "wtf/RefPtr.h"
47 class ExecutionContext;
49 class FileWriter FINAL : public FileWriterBase, public ActiveDOMObject, public EventTargetWithInlineData, public WebFileWriterClient {
50 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<FileWriterBase>);
51 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(FileWriter);
53 static FileWriter* create(ExecutionContext*);
61 void write(Blob*, ExceptionState&);
62 void seek(long long position, ExceptionState&);
63 void truncate(long long length, ExceptionState&);
64 void abort(ExceptionState&);
65 ReadyState readyState() const { return m_readyState; }
66 FileError* error() const { return m_error.get(); }
68 // WebFileWriterClient
69 virtual void didWrite(long long bytes, bool complete) OVERRIDE;
70 virtual void didTruncate() OVERRIDE;
71 virtual void didFail(WebFileError) OVERRIDE;
74 virtual void stop() OVERRIDE;
75 virtual bool hasPendingActivity() const OVERRIDE;
78 virtual const AtomicString& interfaceName() const OVERRIDE;
79 virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveDOMObject::executionContext(); }
81 DEFINE_ATTRIBUTE_EVENT_LISTENER(writestart);
82 DEFINE_ATTRIBUTE_EVENT_LISTENER(progress);
83 DEFINE_ATTRIBUTE_EVENT_LISTENER(write);
84 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
85 DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
86 DEFINE_ATTRIBUTE_EVENT_LISTENER(writeend);
88 virtual void trace(Visitor*) OVERRIDE;
98 FileWriter(ExecutionContext*);
100 virtual ~FileWriter();
102 void completeAbort();
104 void doOperation(Operation);
106 void signalCompletion(FileError::ErrorCode);
108 void fireEvent(const AtomicString& type);
110 void setError(FileError::ErrorCode, ExceptionState&);
112 RefPtrWillBeMember<FileError> m_error;
113 ReadyState m_readyState;
114 Operation m_operationInProgress;
115 Operation m_queuedOperation;
116 long long m_bytesWritten;
117 long long m_bytesToWrite;
118 long long m_truncateLength;
119 long long m_numAborts;
120 long long m_recursionDepth;
121 double m_lastProgressNotificationTimeMS;
122 RefPtrWillBeMember<Blob> m_blobBeingWritten;
123 int m_asyncOperationId;
128 #endif // FileWriter_h