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 18 matching lines...) Expand all Loading... |
29 */ | 29 */ |
30 | 30 |
31 #ifndef FileReaderLoader_h | 31 #ifndef FileReaderLoader_h |
32 #define FileReaderLoader_h | 32 #define FileReaderLoader_h |
33 | 33 |
34 #include "core/CoreExport.h" | 34 #include "core/CoreExport.h" |
35 #include "core/fileapi/FileError.h" | 35 #include "core/fileapi/FileError.h" |
36 #include "core/loader/ThreadableLoaderClient.h" | 36 #include "core/loader/ThreadableLoaderClient.h" |
37 #include "platform/weborigin/KURL.h" | 37 #include "platform/weborigin/KURL.h" |
38 #include "wtf/Forward.h" | 38 #include "wtf/Forward.h" |
39 #include "wtf/PtrUtil.h" | 39 #include "wtf/OwnPtr.h" |
40 #include "wtf/text/TextEncoding.h" | 40 #include "wtf/text/TextEncoding.h" |
41 #include "wtf/text/WTFString.h" | 41 #include "wtf/text/WTFString.h" |
42 #include "wtf/typed_arrays/ArrayBufferBuilder.h" | 42 #include "wtf/typed_arrays/ArrayBufferBuilder.h" |
43 #include <memory> | |
44 | 43 |
45 namespace blink { | 44 namespace blink { |
46 | 45 |
47 class BlobDataHandle; | 46 class BlobDataHandle; |
48 class DOMArrayBuffer; | 47 class DOMArrayBuffer; |
49 class ExecutionContext; | 48 class ExecutionContext; |
50 class FileReaderLoaderClient; | 49 class FileReaderLoaderClient; |
51 class Stream; | 50 class Stream; |
52 class TextResourceDecoder; | 51 class TextResourceDecoder; |
53 class ThreadableLoader; | 52 class ThreadableLoader; |
54 | 53 |
55 class CORE_EXPORT FileReaderLoader final : public ThreadableLoaderClient { | 54 class CORE_EXPORT FileReaderLoader final : public ThreadableLoaderClient { |
56 USING_FAST_MALLOC(FileReaderLoader); | 55 USING_FAST_MALLOC(FileReaderLoader); |
57 public: | 56 public: |
58 enum ReadType { | 57 enum ReadType { |
59 ReadAsArrayBuffer, | 58 ReadAsArrayBuffer, |
60 ReadAsBinaryString, | 59 ReadAsBinaryString, |
61 ReadAsText, | 60 ReadAsText, |
62 ReadAsDataURL, | 61 ReadAsDataURL, |
63 ReadByClient | 62 ReadByClient |
64 }; | 63 }; |
65 | 64 |
66 // If client is given, do the loading asynchronously. Otherwise, load synchr
onously. | 65 // If client is given, do the loading asynchronously. Otherwise, load synchr
onously. |
67 static std::unique_ptr<FileReaderLoader> create(ReadType readType, FileReade
rLoaderClient* client) | 66 static PassOwnPtr<FileReaderLoader> create(ReadType readType, FileReaderLoad
erClient* client) |
68 { | 67 { |
69 return wrapUnique(new FileReaderLoader(readType, client)); | 68 return adoptPtr(new FileReaderLoader(readType, client)); |
70 } | 69 } |
71 | 70 |
72 FileReaderLoader(ReadType, FileReaderLoaderClient*); | 71 FileReaderLoader(ReadType, FileReaderLoaderClient*); |
73 ~FileReaderLoader() override; | 72 ~FileReaderLoader() override; |
74 | 73 |
75 void start(ExecutionContext*, PassRefPtr<BlobDataHandle>); | 74 void start(ExecutionContext*, PassRefPtr<BlobDataHandle>); |
76 void start(ExecutionContext*, const Stream&, unsigned readSize); | 75 void start(ExecutionContext*, const Stream&, unsigned readSize); |
77 void cancel(); | 76 void cancel(); |
78 | 77 |
79 // ThreadableLoaderClient | 78 // ThreadableLoaderClient |
80 void didReceiveResponse(unsigned long, const ResourceResponse&, std::unique_
ptr<WebDataConsumerHandle>) override; | 79 void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<W
ebDataConsumerHandle>) override; |
81 void didReceiveData(const char*, unsigned) override; | 80 void didReceiveData(const char*, unsigned) override; |
82 void didFinishLoading(unsigned long, double) override; | 81 void didFinishLoading(unsigned long, double) override; |
83 void didFail(const ResourceError&) override; | 82 void didFail(const ResourceError&) override; |
84 | 83 |
85 String stringResult(); | 84 String stringResult(); |
86 DOMArrayBuffer* arrayBufferResult() const; | 85 DOMArrayBuffer* arrayBufferResult() const; |
87 | 86 |
88 // Returns the total bytes received. Bytes ignored by m_rawData won't be | 87 // Returns the total bytes received. Bytes ignored by m_rawData won't be |
89 // counted. | 88 // counted. |
90 // | 89 // |
(...skipping 25 matching lines...) Expand all Loading... |
116 | 115 |
117 static FileError::ErrorCode httpStatusCodeToErrorCode(int); | 116 static FileError::ErrorCode httpStatusCodeToErrorCode(int); |
118 | 117 |
119 ReadType m_readType; | 118 ReadType m_readType; |
120 FileReaderLoaderClient* m_client; | 119 FileReaderLoaderClient* m_client; |
121 WTF::TextEncoding m_encoding; | 120 WTF::TextEncoding m_encoding; |
122 String m_dataType; | 121 String m_dataType; |
123 | 122 |
124 KURL m_urlForReading; | 123 KURL m_urlForReading; |
125 bool m_urlForReadingIsStream; | 124 bool m_urlForReadingIsStream; |
126 std::unique_ptr<ThreadableLoader> m_loader; | 125 OwnPtr<ThreadableLoader> m_loader; |
127 | 126 |
128 std::unique_ptr<ArrayBufferBuilder> m_rawData; | 127 OwnPtr<ArrayBufferBuilder> m_rawData; |
129 bool m_isRawDataConverted; | 128 bool m_isRawDataConverted; |
130 | 129 |
131 String m_stringResult; | 130 String m_stringResult; |
132 | 131 |
133 // The decoder used to decode the text data. | 132 // The decoder used to decode the text data. |
134 std::unique_ptr<TextResourceDecoder> m_decoder; | 133 OwnPtr<TextResourceDecoder> m_decoder; |
135 | 134 |
136 bool m_finishedLoading; | 135 bool m_finishedLoading; |
137 long long m_bytesLoaded; | 136 long long m_bytesLoaded; |
138 // If the total size of the resource is unknown, m_totalBytes is set to -1 | 137 // If the total size of the resource is unknown, m_totalBytes is set to -1 |
139 // until completion of loading, and the buffer for receiving data is set to | 138 // until completion of loading, and the buffer for receiving data is set to |
140 // dynamically grow. Otherwise, m_totalBytes is set to the total size and | 139 // dynamically grow. Otherwise, m_totalBytes is set to the total size and |
141 // the buffer for receiving data of m_totalBytes is allocated and never grow | 140 // the buffer for receiving data of m_totalBytes is allocated and never grow |
142 // even when extra data is appeneded. | 141 // even when extra data is appeneded. |
143 long long m_totalBytes; | 142 long long m_totalBytes; |
144 | 143 |
145 bool m_hasRange; | 144 bool m_hasRange; |
146 unsigned m_rangeStart; | 145 unsigned m_rangeStart; |
147 unsigned m_rangeEnd; | 146 unsigned m_rangeEnd; |
148 | 147 |
149 FileError::ErrorCode m_errorCode; | 148 FileError::ErrorCode m_errorCode; |
150 }; | 149 }; |
151 | 150 |
152 } // namespace blink | 151 } // namespace blink |
153 | 152 |
154 #endif // FileReaderLoader_h | 153 #endif // FileReaderLoader_h |
OLD | NEW |