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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 | 153 |
154 void FileReader::stop() | 154 void FileReader::stop() |
155 { | 155 { |
156 if (m_loadingState == LoadingStateLoading || m_loadingState == LoadingStateP
ending) | 156 if (m_loadingState == LoadingStateLoading || m_loadingState == LoadingStateP
ending) |
157 throttlingController()->removeReader(this); | 157 throttlingController()->removeReader(this); |
158 terminate(); | 158 terminate(); |
159 } | 159 } |
160 | 160 |
161 void FileReader::readAsArrayBuffer(Blob* blob, ExceptionState& exceptionState) | 161 void FileReader::readAsArrayBuffer(Blob* blob, ExceptionState& exceptionState) |
162 { | 162 { |
163 if (!blob) | 163 if (!blob) { |
| 164 exceptionState.throwTypeError("The argument is not a Blob."); |
164 return; | 165 return; |
| 166 } |
165 | 167 |
166 WTF_LOG(FileAPI, "FileReader: reading as array buffer: %s %s\n", utf8BlobUUI
D(blob).data(), utf8FilePath(blob).data()); | 168 WTF_LOG(FileAPI, "FileReader: reading as array buffer: %s %s\n", utf8BlobUUI
D(blob).data(), utf8FilePath(blob).data()); |
167 | 169 |
168 readInternal(blob, FileReaderLoader::ReadAsArrayBuffer, exceptionState); | 170 readInternal(blob, FileReaderLoader::ReadAsArrayBuffer, exceptionState); |
169 } | 171 } |
170 | 172 |
171 void FileReader::readAsBinaryString(Blob* blob, ExceptionState& exceptionState) | 173 void FileReader::readAsBinaryString(Blob* blob, ExceptionState& exceptionState) |
172 { | 174 { |
173 if (!blob) | 175 if (!blob) { |
| 176 exceptionState.throwTypeError("The argument is not a Blob."); |
174 return; | 177 return; |
| 178 } |
175 | 179 |
176 WTF_LOG(FileAPI, "FileReader: reading as binary: %s %s\n", utf8BlobUUID(blob
).data(), utf8FilePath(blob).data()); | 180 WTF_LOG(FileAPI, "FileReader: reading as binary: %s %s\n", utf8BlobUUID(blob
).data(), utf8FilePath(blob).data()); |
177 | 181 |
178 readInternal(blob, FileReaderLoader::ReadAsBinaryString, exceptionState); | 182 readInternal(blob, FileReaderLoader::ReadAsBinaryString, exceptionState); |
179 } | 183 } |
180 | 184 |
181 void FileReader::readAsText(Blob* blob, const String& encoding, ExceptionState&
exceptionState) | 185 void FileReader::readAsText(Blob* blob, const String& encoding, ExceptionState&
exceptionState) |
182 { | 186 { |
183 if (!blob) | 187 if (!blob) { |
| 188 exceptionState.throwTypeError("The argument is not a Blob."); |
184 return; | 189 return; |
| 190 } |
185 | 191 |
186 WTF_LOG(FileAPI, "FileReader: reading as text: %s %s\n", utf8BlobUUID(blob).
data(), utf8FilePath(blob).data()); | 192 WTF_LOG(FileAPI, "FileReader: reading as text: %s %s\n", utf8BlobUUID(blob).
data(), utf8FilePath(blob).data()); |
187 | 193 |
188 m_encoding = encoding; | 194 m_encoding = encoding; |
189 readInternal(blob, FileReaderLoader::ReadAsText, exceptionState); | 195 readInternal(blob, FileReaderLoader::ReadAsText, exceptionState); |
190 } | 196 } |
191 | 197 |
192 void FileReader::readAsText(Blob* blob, ExceptionState& exceptionState) | 198 void FileReader::readAsText(Blob* blob, ExceptionState& exceptionState) |
193 { | 199 { |
194 readAsText(blob, String(), exceptionState); | 200 readAsText(blob, String(), exceptionState); |
195 } | 201 } |
196 | 202 |
197 void FileReader::readAsDataURL(Blob* blob, ExceptionState& exceptionState) | 203 void FileReader::readAsDataURL(Blob* blob, ExceptionState& exceptionState) |
198 { | 204 { |
199 if (!blob) | 205 if (!blob) { |
| 206 exceptionState.throwTypeError("The argument is not a Blob."); |
200 return; | 207 return; |
| 208 } |
201 | 209 |
202 WTF_LOG(FileAPI, "FileReader: reading as data URL: %s %s\n", utf8BlobUUID(bl
ob).data(), utf8FilePath(blob).data()); | 210 WTF_LOG(FileAPI, "FileReader: reading as data URL: %s %s\n", utf8BlobUUID(bl
ob).data(), utf8FilePath(blob).data()); |
203 | 211 |
204 readInternal(blob, FileReaderLoader::ReadAsDataURL, exceptionState); | 212 readInternal(blob, FileReaderLoader::ReadAsDataURL, exceptionState); |
205 } | 213 } |
206 | 214 |
207 void FileReader::readInternal(Blob* blob, FileReaderLoader::ReadType type, Excep
tionState& exceptionState) | 215 void FileReader::readInternal(Blob* blob, FileReaderLoader::ReadType type, Excep
tionState& exceptionState) |
208 { | 216 { |
209 // If multiple concurrent read methods are called on the same FileReader, In
validStateError should be thrown when the state is LOADING. | 217 // If multiple concurrent read methods are called on the same FileReader, In
validStateError should be thrown when the state is LOADING. |
210 if (m_state == LOADING) { | 218 if (m_state == LOADING) { |
211 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateErro
r); | 219 exceptionState.throwDOMException(InvalidStateError, "The object is alrea
dy busy reading Blobs."); |
212 return; | 220 return; |
213 } | 221 } |
214 | 222 |
215 m_blob = blob; | 223 m_blob = blob; |
216 m_readType = type; | 224 m_readType = type; |
217 m_state = LOADING; | 225 m_state = LOADING; |
218 m_loadingState = LoadingStatePending; | 226 m_loadingState = LoadingStatePending; |
219 m_error = 0; | 227 m_error = 0; |
220 throttlingController()->pushReader(this); | 228 throttlingController()->pushReader(this); |
221 } | 229 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 } | 370 } |
363 | 371 |
364 String FileReader::stringResult() | 372 String FileReader::stringResult() |
365 { | 373 { |
366 if (!m_loader || m_error) | 374 if (!m_loader || m_error) |
367 return String(); | 375 return String(); |
368 return m_loader->stringResult(); | 376 return m_loader->stringResult(); |
369 } | 377 } |
370 | 378 |
371 } // namespace WebCore | 379 } // namespace WebCore |
OLD | NEW |