| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 #include "wtf/text/WTFString.h" | 42 #include "wtf/text/WTFString.h" |
| 43 #include "wtf/typed_arrays/ArrayBufferBuilder.h" | 43 #include "wtf/typed_arrays/ArrayBufferBuilder.h" |
| 44 #include <memory> | 44 #include <memory> |
| 45 | 45 |
| 46 namespace blink { | 46 namespace blink { |
| 47 | 47 |
| 48 class BlobDataHandle; | 48 class BlobDataHandle; |
| 49 class DOMArrayBuffer; | 49 class DOMArrayBuffer; |
| 50 class ExecutionContext; | 50 class ExecutionContext; |
| 51 class FileReaderLoaderClient; | 51 class FileReaderLoaderClient; |
| 52 class Stream; | |
| 53 class TextResourceDecoder; | 52 class TextResourceDecoder; |
| 54 class ThreadableLoader; | 53 class ThreadableLoader; |
| 55 | 54 |
| 56 class CORE_EXPORT FileReaderLoader final : public ThreadableLoaderClient { | 55 class CORE_EXPORT FileReaderLoader final : public ThreadableLoaderClient { |
| 57 USING_FAST_MALLOC(FileReaderLoader); | 56 USING_FAST_MALLOC(FileReaderLoader); |
| 58 | 57 |
| 59 public: | 58 public: |
| 60 enum ReadType { | 59 enum ReadType { |
| 61 ReadAsArrayBuffer, | 60 ReadAsArrayBuffer, |
| 62 ReadAsBinaryString, | 61 ReadAsBinaryString, |
| 63 ReadAsText, | 62 ReadAsText, |
| 64 ReadAsDataURL, | 63 ReadAsDataURL, |
| 65 ReadByClient | 64 ReadByClient |
| 66 }; | 65 }; |
| 67 | 66 |
| 68 // If client is given, do the loading asynchronously. Otherwise, load | 67 // If client is given, do the loading asynchronously. Otherwise, load |
| 69 // synchronously. | 68 // synchronously. |
| 70 static std::unique_ptr<FileReaderLoader> create( | 69 static std::unique_ptr<FileReaderLoader> create( |
| 71 ReadType readType, | 70 ReadType readType, |
| 72 FileReaderLoaderClient* client) { | 71 FileReaderLoaderClient* client) { |
| 73 return WTF::wrapUnique(new FileReaderLoader(readType, client)); | 72 return WTF::wrapUnique(new FileReaderLoader(readType, client)); |
| 74 } | 73 } |
| 75 | 74 |
| 76 ~FileReaderLoader() override; | 75 ~FileReaderLoader() override; |
| 77 | 76 |
| 78 void start(ExecutionContext*, PassRefPtr<BlobDataHandle>); | 77 void start(ExecutionContext*, PassRefPtr<BlobDataHandle>); |
| 79 void start(ExecutionContext*, const Stream&, unsigned readSize); | |
| 80 void cancel(); | 78 void cancel(); |
| 81 | 79 |
| 82 // ThreadableLoaderClient | 80 // ThreadableLoaderClient |
| 83 void didReceiveResponse(unsigned long, | 81 void didReceiveResponse(unsigned long, |
| 84 const ResourceResponse&, | 82 const ResourceResponse&, |
| 85 std::unique_ptr<WebDataConsumerHandle>) override; | 83 std::unique_ptr<WebDataConsumerHandle>) override; |
| 86 void didReceiveData(const char*, unsigned) override; | 84 void didReceiveData(const char*, unsigned) override; |
| 87 void didFinishLoading(unsigned long, double) override; | 85 void didFinishLoading(unsigned long, double) override; |
| 88 void didFail(const ResourceError&) override; | 86 void didFail(const ResourceError&) override; |
| 89 | 87 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 106 long long totalBytes() const { return m_totalBytes; } | 104 long long totalBytes() const { return m_totalBytes; } |
| 107 | 105 |
| 108 FileError::ErrorCode errorCode() const { return m_errorCode; } | 106 FileError::ErrorCode errorCode() const { return m_errorCode; } |
| 109 | 107 |
| 110 void setEncoding(const String&); | 108 void setEncoding(const String&); |
| 111 void setDataType(const String& dataType) { m_dataType = dataType; } | 109 void setDataType(const String& dataType) { m_dataType = dataType; } |
| 112 | 110 |
| 113 private: | 111 private: |
| 114 FileReaderLoader(ReadType, FileReaderLoaderClient*); | 112 FileReaderLoader(ReadType, FileReaderLoaderClient*); |
| 115 | 113 |
| 116 void startInternal(ExecutionContext&, | |
| 117 const Stream*, | |
| 118 PassRefPtr<BlobDataHandle>); | |
| 119 void cleanup(); | 114 void cleanup(); |
| 120 | 115 |
| 121 void failed(FileError::ErrorCode); | 116 void failed(FileError::ErrorCode); |
| 122 void convertToText(); | 117 void convertToText(); |
| 123 void convertToDataURL(); | 118 void convertToDataURL(); |
| 124 | 119 |
| 125 static FileError::ErrorCode httpStatusCodeToErrorCode(int); | 120 static FileError::ErrorCode httpStatusCodeToErrorCode(int); |
| 126 | 121 |
| 127 ReadType m_readType; | 122 ReadType m_readType; |
| 128 FileReaderLoaderClient* m_client; | 123 FileReaderLoaderClient* m_client; |
| 129 WTF::TextEncoding m_encoding; | 124 WTF::TextEncoding m_encoding; |
| 130 String m_dataType; | 125 String m_dataType; |
| 131 | 126 |
| 132 KURL m_urlForReading; | 127 KURL m_urlForReading; |
| 133 bool m_urlForReadingIsStream; | |
| 134 Persistent<ThreadableLoader> m_loader; | 128 Persistent<ThreadableLoader> m_loader; |
| 135 | 129 |
| 136 std::unique_ptr<ArrayBufferBuilder> m_rawData; | 130 std::unique_ptr<ArrayBufferBuilder> m_rawData; |
| 137 bool m_isRawDataConverted; | 131 bool m_isRawDataConverted; |
| 138 | 132 |
| 139 Persistent<DOMArrayBuffer> m_arrayBufferResult; | 133 Persistent<DOMArrayBuffer> m_arrayBufferResult; |
| 140 String m_stringResult; | 134 String m_stringResult; |
| 141 | 135 |
| 142 // The decoder used to decode the text data. | 136 // The decoder used to decode the text data. |
| 143 std::unique_ptr<TextResourceDecoder> m_decoder; | 137 std::unique_ptr<TextResourceDecoder> m_decoder; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 154 bool m_hasRange; | 148 bool m_hasRange; |
| 155 unsigned m_rangeStart; | 149 unsigned m_rangeStart; |
| 156 unsigned m_rangeEnd; | 150 unsigned m_rangeEnd; |
| 157 | 151 |
| 158 FileError::ErrorCode m_errorCode; | 152 FileError::ErrorCode m_errorCode; |
| 159 }; | 153 }; |
| 160 | 154 |
| 161 } // namespace blink | 155 } // namespace blink |
| 162 | 156 |
| 163 #endif // FileReaderLoader_h | 157 #endif // FileReaderLoader_h |
| OLD | NEW |