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