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.
31 #ifndef FileReaderLoader_h
32 #define FileReaderLoader_h
36 #include "FileError.h"
38 #include "TextEncoding.h"
39 #include "ThreadableLoaderClient.h"
40 #include <wtf/Forward.h>
41 #include <wtf/text/WTFString.h>
46 class FileReaderLoaderClient;
47 class ScriptExecutionContext;
48 class TextResourceDecoder;
49 class ThreadableLoader;
51 class FileReaderLoader : public ThreadableLoaderClient {
60 // If client is given, do the loading asynchronously. Otherwise, load synchronously.
61 FileReaderLoader(ReadType, FileReaderLoaderClient*);
64 void start(ScriptExecutionContext*, Blob*);
67 // ThreadableLoaderClient
68 virtual void didReceiveResponse(unsigned long, const ResourceResponse&);
69 virtual void didReceiveData(const char*, int);
70 virtual void didFinishLoading(unsigned long, double);
71 virtual void didFail(const ResourceError&);
73 String stringResult();
74 PassRefPtr<ArrayBuffer> arrayBufferResult() const;
75 unsigned bytesLoaded() const { return m_bytesLoaded; }
76 unsigned totalBytes() const { return m_totalBytes; }
77 int errorCode() const { return m_errorCode; }
79 void setEncoding(const String&);
80 void setDataType(const String& dataType) { m_dataType = dataType; }
85 void failed(int errorCode);
87 void convertToDataURL();
89 bool isCompleted() const;
91 static FileError::ErrorCode httpStatusCodeToErrorCode(int);
94 FileReaderLoaderClient* m_client;
95 TextEncoding m_encoding;
99 RefPtr<ThreadableLoader> m_loader;
101 RefPtr<ArrayBuffer> m_rawData;
102 bool m_isRawDataConverted;
104 String m_stringResult;
106 // The decoder used to decode the text data.
107 RefPtr<TextResourceDecoder> m_decoder;
109 unsigned m_bytesLoaded;
110 unsigned m_totalBytes;
114 } // namespace WebCore
116 #endif // ENABLE(BLOB)
118 #endif // FileReaderLoader_h