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>
47 class FileReaderLoaderClient;
48 class ScriptExecutionContext;
49 class TextResourceDecoder;
50 class ThreadableLoader;
52 class FileReaderLoader : public ThreadableLoaderClient {
61 // If client is given, do the loading asynchronously. Otherwise, load synchronously.
62 FileReaderLoader(ReadType, FileReaderLoaderClient*);
65 void start(ScriptExecutionContext*, Blob*);
68 // ThreadableLoaderClient
69 virtual void didReceiveResponse(unsigned long, const ResourceResponse&);
70 virtual void didReceiveData(const char*, int);
71 virtual void didFinishLoading(unsigned long, double);
72 virtual void didFail(const ResourceError&);
74 String stringResult();
75 PassRefPtr<ArrayBuffer> arrayBufferResult() const;
76 unsigned bytesLoaded() const { return m_bytesLoaded; }
77 unsigned totalBytes() const { return m_totalBytes; }
78 int errorCode() const { return m_errorCode; }
80 void setEncoding(const String&);
81 void setDataType(const String& dataType) { m_dataType = dataType; }
86 void failed(int errorCode);
88 void convertToDataURL();
90 bool isCompleted() const;
92 static FileError::ErrorCode httpStatusCodeToErrorCode(int);
95 FileReaderLoaderClient* m_client;
96 TextEncoding m_encoding;
100 RefPtr<ThreadableLoader> m_loader;
102 RefPtr<ArrayBuffer> m_rawData;
103 bool m_isRawDataConverted;
105 String m_stringResult;
107 // The decoder used to decode the text data.
108 RefPtr<TextResourceDecoder> m_decoder;
110 unsigned m_bytesLoaded;
111 unsigned m_totalBytes;
115 } // namespace WebCore
117 #endif // ENABLE(BLOB)
119 #endif // FileReaderLoader_h