| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 , m_client(client) | 59 , m_client(client) |
| 60 , m_urlForReadingIsStream(false) | 60 , m_urlForReadingIsStream(false) |
| 61 , m_isRawDataConverted(false) | 61 , m_isRawDataConverted(false) |
| 62 , m_stringResult("") | 62 , m_stringResult("") |
| 63 , m_finishedLoading(false) | 63 , m_finishedLoading(false) |
| 64 , m_bytesLoaded(0) | 64 , m_bytesLoaded(0) |
| 65 , m_totalBytes(-1) | 65 , m_totalBytes(-1) |
| 66 , m_hasRange(false) | 66 , m_hasRange(false) |
| 67 , m_rangeStart(0) | 67 , m_rangeStart(0) |
| 68 , m_rangeEnd(0) | 68 , m_rangeEnd(0) |
| 69 , m_errorCode(FileError::OK) | 69 , m_errorCode(FileError::kOK) |
| 70 { | 70 { |
| 71 } | 71 } |
| 72 | 72 |
| 73 FileReaderLoader::~FileReaderLoader() | 73 FileReaderLoader::~FileReaderLoader() |
| 74 { | 74 { |
| 75 cleanup(); | 75 cleanup(); |
| 76 if (!m_urlForReading.isEmpty()) { | 76 if (!m_urlForReading.isEmpty()) { |
| 77 if (m_urlForReadingIsStream) | 77 if (m_urlForReadingIsStream) |
| 78 BlobRegistry::unregisterStreamURL(m_urlForReading); | 78 BlobRegistry::unregisterStreamURL(m_urlForReading); |
| 79 else | 79 else |
| 80 BlobRegistry::revokePublicBlobURL(m_urlForReading); | 80 BlobRegistry::revokePublicBlobURL(m_urlForReading); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 | 83 |
| 84 void FileReaderLoader::startInternal(ExecutionContext& executionContext, const S
tream* stream, PassRefPtr<BlobDataHandle> blobData) | 84 void FileReaderLoader::startInternal(ExecutionContext& executionContext, const S
tream* stream, PassRefPtr<BlobDataHandle> blobData) |
| 85 { | 85 { |
| 86 // The blob is read by routing through the request handling layer given a te
mporary public url. | 86 // The blob is read by routing through the request handling layer given a te
mporary public url. |
| 87 m_urlForReading = BlobURL::createPublicURL(executionContext.getSecurityOrigi
n()); | 87 m_urlForReading = BlobURL::createPublicURL(executionContext.getSecurityOrigi
n()); |
| 88 if (m_urlForReading.isEmpty()) { | 88 if (m_urlForReading.isEmpty()) { |
| 89 failed(FileError::SECURITY_ERR); | 89 failed(FileError::kSecurityErr); |
| 90 return; | 90 return; |
| 91 } | 91 } |
| 92 | 92 |
| 93 if (blobData) { | 93 if (blobData) { |
| 94 ASSERT(!stream); | 94 ASSERT(!stream); |
| 95 BlobRegistry::registerPublicBlobURL(executionContext.getSecurityOrigin()
, m_urlForReading, blobData); | 95 BlobRegistry::registerPublicBlobURL(executionContext.getSecurityOrigin()
, m_urlForReading, blobData); |
| 96 } else { | 96 } else { |
| 97 ASSERT(stream); | 97 ASSERT(stream); |
| 98 BlobRegistry::registerStreamURL(executionContext.getSecurityOrigin(), m_
urlForReading, stream->url()); | 98 BlobRegistry::registerStreamURL(executionContext.getSecurityOrigin(), m_
urlForReading, stream->url()); |
| 99 } | 99 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 m_rangeStart = 0; | 143 m_rangeStart = 0; |
| 144 m_rangeEnd = readSize - 1; // End is inclusive so (0,0) is a 1-byte read
. | 144 m_rangeEnd = readSize - 1; // End is inclusive so (0,0) is a 1-byte read
. |
| 145 } | 145 } |
| 146 | 146 |
| 147 m_urlForReadingIsStream = true; | 147 m_urlForReadingIsStream = true; |
| 148 startInternal(*executionContext, &stream, nullptr); | 148 startInternal(*executionContext, &stream, nullptr); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void FileReaderLoader::cancel() | 151 void FileReaderLoader::cancel() |
| 152 { | 152 { |
| 153 m_errorCode = FileError::ABORT_ERR; | 153 m_errorCode = FileError::kAbortErr; |
| 154 cleanup(); | 154 cleanup(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void FileReaderLoader::cleanup() | 157 void FileReaderLoader::cleanup() |
| 158 { | 158 { |
| 159 if (m_loader) { | 159 if (m_loader) { |
| 160 m_loader->cancel(); | 160 m_loader->cancel(); |
| 161 m_loader = nullptr; | 161 m_loader = nullptr; |
| 162 } | 162 } |
| 163 | 163 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 m_totalBytes = -1; | 196 m_totalBytes = -1; |
| 197 } | 197 } |
| 198 | 198 |
| 199 ASSERT(!m_rawData); | 199 ASSERT(!m_rawData); |
| 200 | 200 |
| 201 if (m_readType != ReadByClient) { | 201 if (m_readType != ReadByClient) { |
| 202 // Check that we can cast to unsigned since we have to do | 202 // Check that we can cast to unsigned since we have to do |
| 203 // so to call ArrayBuffer's create function. | 203 // so to call ArrayBuffer's create function. |
| 204 // FIXME: Support reading more than the current size limit of ArrayBuffe
r. | 204 // FIXME: Support reading more than the current size limit of ArrayBuffe
r. |
| 205 if (initialBufferLength > std::numeric_limits<unsigned>::max()) { | 205 if (initialBufferLength > std::numeric_limits<unsigned>::max()) { |
| 206 failed(FileError::NOT_READABLE_ERR); | 206 failed(FileError::kNotReadableErr); |
| 207 return; | 207 return; |
| 208 } | 208 } |
| 209 | 209 |
| 210 if (initialBufferLength < 0) | 210 if (initialBufferLength < 0) |
| 211 m_rawData = wrapUnique(new ArrayBufferBuilder()); | 211 m_rawData = wrapUnique(new ArrayBufferBuilder()); |
| 212 else | 212 else |
| 213 m_rawData = wrapUnique(new ArrayBufferBuilder(static_cast<unsigned>(
initialBufferLength))); | 213 m_rawData = wrapUnique(new ArrayBufferBuilder(static_cast<unsigned>(
initialBufferLength))); |
| 214 | 214 |
| 215 if (!m_rawData || !m_rawData->isValid()) { | 215 if (!m_rawData || !m_rawData->isValid()) { |
| 216 failed(FileError::NOT_READABLE_ERR); | 216 failed(FileError::kNotReadableErr); |
| 217 return; | 217 return; |
| 218 } | 218 } |
| 219 | 219 |
| 220 if (initialBufferLength >= 0) { | 220 if (initialBufferLength >= 0) { |
| 221 // Total size is known. Set m_rawData to ignore overflowed data. | 221 // Total size is known. Set m_rawData to ignore overflowed data. |
| 222 m_rawData->setVariableCapacity(false); | 222 m_rawData->setVariableCapacity(false); |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 | 225 |
| 226 if (m_client) | 226 if (m_client) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 240 | 240 |
| 241 if (m_client) | 241 if (m_client) |
| 242 m_client->didReceiveDataForClient(data, dataLength); | 242 m_client->didReceiveDataForClient(data, dataLength); |
| 243 return; | 243 return; |
| 244 } | 244 } |
| 245 | 245 |
| 246 unsigned bytesAppended = m_rawData->append(data, dataLength); | 246 unsigned bytesAppended = m_rawData->append(data, dataLength); |
| 247 if (!bytesAppended) { | 247 if (!bytesAppended) { |
| 248 m_rawData.reset(); | 248 m_rawData.reset(); |
| 249 m_bytesLoaded = 0; | 249 m_bytesLoaded = 0; |
| 250 failed(FileError::NOT_READABLE_ERR); | 250 failed(FileError::kNotReadableErr); |
| 251 return; | 251 return; |
| 252 } | 252 } |
| 253 m_bytesLoaded += bytesAppended; | 253 m_bytesLoaded += bytesAppended; |
| 254 m_isRawDataConverted = false; | 254 m_isRawDataConverted = false; |
| 255 | 255 |
| 256 if (m_client) | 256 if (m_client) |
| 257 m_client->didReceiveData(); | 257 m_client->didReceiveData(); |
| 258 } | 258 } |
| 259 | 259 |
| 260 void FileReaderLoader::didFinishLoading(unsigned long, double) | 260 void FileReaderLoader::didFinishLoading(unsigned long, double) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 274 cleanup(); | 274 cleanup(); |
| 275 if (m_client) | 275 if (m_client) |
| 276 m_client->didFinishLoading(); | 276 m_client->didFinishLoading(); |
| 277 } | 277 } |
| 278 | 278 |
| 279 void FileReaderLoader::didFail(const ResourceError& error) | 279 void FileReaderLoader::didFail(const ResourceError& error) |
| 280 { | 280 { |
| 281 if (error.isCancellation()) | 281 if (error.isCancellation()) |
| 282 return; | 282 return; |
| 283 // If we're aborting, do not proceed with normal error handling since it is
covered in aborting code. | 283 // If we're aborting, do not proceed with normal error handling since it is
covered in aborting code. |
| 284 if (m_errorCode == FileError::ABORT_ERR) | 284 if (m_errorCode == FileError::kAbortErr) |
| 285 return; | 285 return; |
| 286 | 286 |
| 287 failed(FileError::NOT_READABLE_ERR); | 287 failed(FileError::kNotReadableErr); |
| 288 } | 288 } |
| 289 | 289 |
| 290 void FileReaderLoader::failed(FileError::ErrorCode errorCode) | 290 void FileReaderLoader::failed(FileError::ErrorCode errorCode) |
| 291 { | 291 { |
| 292 m_errorCode = errorCode; | 292 m_errorCode = errorCode; |
| 293 cleanup(); | 293 cleanup(); |
| 294 if (m_client) | 294 if (m_client) |
| 295 m_client->didFail(m_errorCode); | 295 m_client->didFail(m_errorCode); |
| 296 } | 296 } |
| 297 | 297 |
| 298 FileError::ErrorCode FileReaderLoader::httpStatusCodeToErrorCode(int httpStatusC
ode) | 298 FileError::ErrorCode FileReaderLoader::httpStatusCodeToErrorCode(int httpStatusC
ode) |
| 299 { | 299 { |
| 300 switch (httpStatusCode) { | 300 switch (httpStatusCode) { |
| 301 case 403: | 301 case 403: |
| 302 return FileError::SECURITY_ERR; | 302 return FileError::kSecurityErr; |
| 303 case 404: | 303 case 404: |
| 304 return FileError::NOT_FOUND_ERR; | 304 return FileError::kNotFoundErr; |
| 305 default: | 305 default: |
| 306 return FileError::NOT_READABLE_ERR; | 306 return FileError::kNotReadableErr; |
| 307 } | 307 } |
| 308 } | 308 } |
| 309 | 309 |
| 310 DOMArrayBuffer* FileReaderLoader::arrayBufferResult() const | 310 DOMArrayBuffer* FileReaderLoader::arrayBufferResult() const |
| 311 { | 311 { |
| 312 ASSERT(m_readType == ReadAsArrayBuffer); | 312 ASSERT(m_readType == ReadAsArrayBuffer); |
| 313 | 313 |
| 314 // If the loading is not started or an error occurs, return an empty result. | 314 // If the loading is not started or an error occurs, return an empty result. |
| 315 if (!m_rawData || m_errorCode) | 315 if (!m_rawData || m_errorCode) |
| 316 return nullptr; | 316 return nullptr; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 m_stringResult = builder.toString(); | 401 m_stringResult = builder.toString(); |
| 402 } | 402 } |
| 403 | 403 |
| 404 void FileReaderLoader::setEncoding(const String& encoding) | 404 void FileReaderLoader::setEncoding(const String& encoding) |
| 405 { | 405 { |
| 406 if (!encoding.isEmpty()) | 406 if (!encoding.isEmpty()) |
| 407 m_encoding = WTF::TextEncoding(encoding); | 407 m_encoding = WTF::TextEncoding(encoding); |
| 408 } | 408 } |
| 409 | 409 |
| 410 } // namespace blink | 410 } // namespace blink |
| OLD | NEW |