Fix the incorrect behavior touch sound on single tap event.
[framework/web/webkit-efl.git] / Source / WebCore / fileapi / FileReaderLoader.h
1 /*
2  * Copyright (C) 2010 Google Inc.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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
13  * distribution.
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.
17  *
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.
29  */
30
31 #ifndef FileReaderLoader_h
32 #define FileReaderLoader_h
33
34 #if ENABLE(BLOB)
35
36 #include "FileError.h"
37 #include "KURL.h"
38 #include "TextEncoding.h"
39 #include "ThreadableLoaderClient.h"
40 #include <wtf/Forward.h>
41 #include <wtf/text/WTFString.h>
42
43 namespace WebCore {
44
45 class Blob;
46 class FileReaderLoaderClient;
47 class ScriptExecutionContext;
48 class TextResourceDecoder;
49 class ThreadableLoader;
50
51 class FileReaderLoader : public ThreadableLoaderClient {
52 public:
53     enum ReadType {
54         ReadAsArrayBuffer,
55         ReadAsBinaryString,
56         ReadAsText,
57         ReadAsDataURL
58     };
59
60     // If client is given, do the loading asynchronously. Otherwise, load synchronously.
61     FileReaderLoader(ReadType, FileReaderLoaderClient*);
62     ~FileReaderLoader();
63
64     void start(ScriptExecutionContext*, Blob*);
65     void cancel();
66
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&);
72
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; }
78
79     void setEncoding(const String&);
80     void setDataType(const String& dataType) { m_dataType = dataType; }
81     
82 private:
83     void terminate();
84     void cleanup();
85     void failed(int errorCode);
86     void convertToText();
87     void convertToDataURL();
88
89     bool isCompleted() const;
90
91     static FileError::ErrorCode httpStatusCodeToErrorCode(int);
92
93     ReadType m_readType;
94     FileReaderLoaderClient* m_client;
95     TextEncoding m_encoding;
96     String m_dataType;
97
98     KURL m_urlForReading;
99     RefPtr<ThreadableLoader> m_loader;
100
101     RefPtr<ArrayBuffer> m_rawData;
102     bool m_isRawDataConverted;
103
104     String m_stringResult;
105
106     // The decoder used to decode the text data.
107     RefPtr<TextResourceDecoder> m_decoder;
108
109     unsigned m_bytesLoaded;
110     unsigned m_totalBytes;
111     int m_errorCode;
112 };
113
114 } // namespace WebCore
115
116 #endif // ENABLE(BLOB)
117
118 #endif // FileReaderLoader_h