OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 #include "core/fileapi/FileError.h" | 34 #include "core/fileapi/FileError.h" |
35 #include "core/loader/ThreadableLoaderClient.h" | 35 #include "core/loader/ThreadableLoaderClient.h" |
36 #include "weborigin/KURL.h" | 36 #include "weborigin/KURL.h" |
37 #include "wtf/Forward.h" | 37 #include "wtf/Forward.h" |
38 #include "wtf/text/TextEncoding.h" | 38 #include "wtf/text/TextEncoding.h" |
39 #include "wtf/text/WTFString.h" | 39 #include "wtf/text/WTFString.h" |
40 | 40 |
41 namespace WebCore { | 41 namespace WebCore { |
42 | 42 |
43 class Blob; | 43 class BlobDataHandle; |
44 class FileReaderLoaderClient; | 44 class FileReaderLoaderClient; |
45 class ExecutionContext; | 45 class ExecutionContext; |
46 class Stream; | 46 class Stream; |
47 class TextResourceDecoder; | 47 class TextResourceDecoder; |
48 class ThreadableLoader; | 48 class ThreadableLoader; |
49 | 49 |
50 class FileReaderLoader : public ThreadableLoaderClient { | 50 class FileReaderLoader : public ThreadableLoaderClient { |
51 public: | 51 public: |
52 enum ReadType { | 52 enum ReadType { |
53 ReadAsArrayBuffer, | 53 ReadAsArrayBuffer, |
54 ReadAsBinaryString, | 54 ReadAsBinaryString, |
55 ReadAsBlob, | 55 ReadAsBlob, |
56 ReadAsText, | 56 ReadAsText, |
57 ReadAsDataURL, | 57 ReadAsDataURL, |
58 ReadByClient | 58 ReadByClient |
59 }; | 59 }; |
60 | 60 |
61 // If client is given, do the loading asynchronously. Otherwise, load synchr
onously. | 61 // If client is given, do the loading asynchronously. Otherwise, load synchr
onously. |
62 FileReaderLoader(ReadType, FileReaderLoaderClient*); | 62 FileReaderLoader(ReadType, FileReaderLoaderClient*); |
63 ~FileReaderLoader(); | 63 ~FileReaderLoader(); |
64 | 64 |
65 void start(ExecutionContext*, const Blob&); | 65 void start(ExecutionContext*, PassRefPtr<BlobDataHandle>); |
66 void start(ExecutionContext*, const Stream&, unsigned readSize); | 66 void start(ExecutionContext*, const Stream&, unsigned readSize); |
67 void cancel(); | 67 void cancel(); |
68 | 68 |
69 // ThreadableLoaderClient | 69 // ThreadableLoaderClient |
70 virtual void didReceiveResponse(unsigned long, const ResourceResponse&); | 70 virtual void didReceiveResponse(unsigned long, const ResourceResponse&); |
71 virtual void didReceiveData(const char*, int); | 71 virtual void didReceiveData(const char*, int); |
72 virtual void didFinishLoading(unsigned long, double); | 72 virtual void didFinishLoading(unsigned long, double); |
73 virtual void didFail(const ResourceError&); | 73 virtual void didFail(const ResourceError&); |
74 | 74 |
75 String stringResult(); | 75 String stringResult(); |
76 PassRefPtr<ArrayBuffer> arrayBufferResult() const; | 76 PassRefPtr<ArrayBuffer> arrayBufferResult() const; |
77 unsigned bytesLoaded() const { return m_bytesLoaded; } | 77 unsigned bytesLoaded() const { return m_bytesLoaded; } |
78 unsigned totalBytes() const { return m_totalBytes; } | 78 unsigned totalBytes() const { return m_totalBytes; } |
79 FileError::ErrorCode errorCode() const { return m_errorCode; } | 79 FileError::ErrorCode errorCode() const { return m_errorCode; } |
80 | 80 |
81 void setEncoding(const String&); | 81 void setEncoding(const String&); |
82 void setDataType(const String& dataType) { m_dataType = dataType; } | 82 void setDataType(const String& dataType) { m_dataType = dataType; } |
83 | 83 |
84 private: | 84 private: |
85 // We have start() methods for Blob and Stream instead of exposing this | 85 void startInternal(ExecutionContext*, const Stream*, PassRefPtr<BlobDataHand
le>); |
86 // method so that users don't misuse this by calling with non Blob/Stream | |
87 // URL. | |
88 void startForURL(ExecutionContext*, const KURL&); | |
89 void terminate(); | 86 void terminate(); |
90 void cleanup(); | 87 void cleanup(); |
91 void failed(FileError::ErrorCode); | 88 void failed(FileError::ErrorCode); |
92 void convertToText(); | 89 void convertToText(); |
93 void convertToDataURL(); | 90 void convertToDataURL(); |
94 | 91 |
95 static FileError::ErrorCode httpStatusCodeToErrorCode(int); | 92 static FileError::ErrorCode httpStatusCodeToErrorCode(int); |
96 | 93 |
97 ReadType m_readType; | 94 ReadType m_readType; |
98 FileReaderLoaderClient* m_client; | 95 FileReaderLoaderClient* m_client; |
99 WTF::TextEncoding m_encoding; | 96 WTF::TextEncoding m_encoding; |
100 String m_dataType; | 97 String m_dataType; |
101 | 98 |
102 KURL m_urlForReading; | 99 KURL m_urlForReading; |
103 bool m_urlForReadingIsStream; | 100 bool m_urlForReadingIsStream; |
104 RefPtr<ThreadableLoader> m_loader; | 101 RefPtr<ThreadableLoader> m_loader; |
105 | 102 |
106 RefPtr<ArrayBuffer> m_rawData; | 103 RefPtr<ArrayBuffer> m_rawData; |
107 bool m_isRawDataConverted; | 104 bool m_isRawDataConverted; |
108 | 105 |
109 String m_stringResult; | 106 String m_stringResult; |
110 RefPtr<Blob> m_blobResult; | |
111 | 107 |
112 // The decoder used to decode the text data. | 108 // The decoder used to decode the text data. |
113 RefPtr<TextResourceDecoder> m_decoder; | 109 RefPtr<TextResourceDecoder> m_decoder; |
114 | 110 |
115 bool m_variableLength; | 111 bool m_variableLength; |
116 bool m_finishedLoading; | 112 bool m_finishedLoading; |
117 unsigned m_bytesLoaded; | 113 unsigned m_bytesLoaded; |
118 unsigned m_totalBytes; | 114 unsigned m_totalBytes; |
119 | 115 |
120 bool m_hasRange; | 116 bool m_hasRange; |
121 unsigned m_rangeStart; | 117 unsigned m_rangeStart; |
122 unsigned m_rangeEnd; | 118 unsigned m_rangeEnd; |
123 | 119 |
124 FileError::ErrorCode m_errorCode; | 120 FileError::ErrorCode m_errorCode; |
125 }; | 121 }; |
126 | 122 |
127 } // namespace WebCore | 123 } // namespace WebCore |
128 | 124 |
129 #endif // FileReaderLoader_h | 125 #endif // FileReaderLoader_h |
OLD | NEW |