| 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 22 matching lines...) Expand all Loading... |
| 33 #include "core/dom/DOMArrayBuffer.h" | 33 #include "core/dom/DOMArrayBuffer.h" |
| 34 #include "core/dom/ExecutionContext.h" | 34 #include "core/dom/ExecutionContext.h" |
| 35 #include "core/fetch/FetchInitiatorTypeNames.h" | 35 #include "core/fetch/FetchInitiatorTypeNames.h" |
| 36 #include "core/fileapi/Blob.h" | 36 #include "core/fileapi/Blob.h" |
| 37 #include "core/fileapi/FileReaderLoaderClient.h" | 37 #include "core/fileapi/FileReaderLoaderClient.h" |
| 38 #include "core/html/parser/TextResourceDecoder.h" | 38 #include "core/html/parser/TextResourceDecoder.h" |
| 39 #include "core/loader/ThreadableLoader.h" | 39 #include "core/loader/ThreadableLoader.h" |
| 40 #include "core/streams/Stream.h" | 40 #include "core/streams/Stream.h" |
| 41 #include "platform/blob/BlobRegistry.h" | 41 #include "platform/blob/BlobRegistry.h" |
| 42 #include "platform/blob/BlobURL.h" | 42 #include "platform/blob/BlobURL.h" |
| 43 #include "platform/network/ResourceError.h" |
| 43 #include "platform/network/ResourceRequest.h" | 44 #include "platform/network/ResourceRequest.h" |
| 44 #include "platform/network/ResourceResponse.h" | 45 #include "platform/network/ResourceResponse.h" |
| 45 #include "public/platform/WebURLRequest.h" | 46 #include "public/platform/WebURLRequest.h" |
| 46 #include "wtf/PassRefPtr.h" | 47 #include "wtf/PassRefPtr.h" |
| 47 #include "wtf/PtrUtil.h" | 48 #include "wtf/PtrUtil.h" |
| 48 #include "wtf/RefPtr.h" | 49 #include "wtf/RefPtr.h" |
| 49 #include "wtf/Vector.h" | 50 #include "wtf/Vector.h" |
| 50 #include "wtf/text/Base64.h" | 51 #include "wtf/text/Base64.h" |
| 51 #include "wtf/text/StringBuilder.h" | 52 #include "wtf/text/StringBuilder.h" |
| 52 #include <memory> | 53 #include <memory> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 64 , m_totalBytes(-1) | 65 , m_totalBytes(-1) |
| 65 , m_hasRange(false) | 66 , m_hasRange(false) |
| 66 , m_rangeStart(0) | 67 , m_rangeStart(0) |
| 67 , m_rangeEnd(0) | 68 , m_rangeEnd(0) |
| 68 , m_errorCode(FileError::OK) | 69 , m_errorCode(FileError::OK) |
| 69 { | 70 { |
| 70 } | 71 } |
| 71 | 72 |
| 72 FileReaderLoader::~FileReaderLoader() | 73 FileReaderLoader::~FileReaderLoader() |
| 73 { | 74 { |
| 74 terminate(); | 75 cleanup(); |
| 75 if (!m_urlForReading.isEmpty()) { | 76 if (!m_urlForReading.isEmpty()) { |
| 76 if (m_urlForReadingIsStream) | 77 if (m_urlForReadingIsStream) |
| 77 BlobRegistry::unregisterStreamURL(m_urlForReading); | 78 BlobRegistry::unregisterStreamURL(m_urlForReading); |
| 78 else | 79 else |
| 79 BlobRegistry::revokePublicBlobURL(m_urlForReading); | 80 BlobRegistry::revokePublicBlobURL(m_urlForReading); |
| 80 } | 81 } |
| 81 } | 82 } |
| 82 | 83 |
| 83 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) |
| 84 { | 85 { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 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
. |
| 144 } | 145 } |
| 145 | 146 |
| 146 m_urlForReadingIsStream = true; | 147 m_urlForReadingIsStream = true; |
| 147 startInternal(*executionContext, &stream, nullptr); | 148 startInternal(*executionContext, &stream, nullptr); |
| 148 } | 149 } |
| 149 | 150 |
| 150 void FileReaderLoader::cancel() | 151 void FileReaderLoader::cancel() |
| 151 { | 152 { |
| 152 m_errorCode = FileError::ABORT_ERR; | 153 m_errorCode = FileError::ABORT_ERR; |
| 153 terminate(); | 154 cleanup(); |
| 154 } | |
| 155 | |
| 156 void FileReaderLoader::terminate() | |
| 157 { | |
| 158 if (m_loader) { | |
| 159 m_loader->cancel(); | |
| 160 cleanup(); | |
| 161 } | |
| 162 } | 155 } |
| 163 | 156 |
| 164 void FileReaderLoader::cleanup() | 157 void FileReaderLoader::cleanup() |
| 165 { | 158 { |
| 166 m_loader = nullptr; | 159 if (m_loader) { |
| 160 m_loader->cancel(); |
| 161 m_loader = nullptr; |
| 162 } |
| 167 | 163 |
| 168 // If we get any error, we do not need to keep a buffer around. | 164 // If we get any error, we do not need to keep a buffer around. |
| 169 if (m_errorCode) { | 165 if (m_errorCode) { |
| 170 m_rawData.reset(); | 166 m_rawData.reset(); |
| 171 m_stringResult = ""; | 167 m_stringResult = ""; |
| 172 m_isRawDataConverted = true; | 168 m_isRawDataConverted = true; |
| 173 m_decoder.reset(); | 169 m_decoder.reset(); |
| 174 } | 170 } |
| 175 } | 171 } |
| 176 | 172 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 m_totalBytes = m_bytesLoaded; | 269 m_totalBytes = m_bytesLoaded; |
| 274 } | 270 } |
| 275 | 271 |
| 276 m_finishedLoading = true; | 272 m_finishedLoading = true; |
| 277 | 273 |
| 278 cleanup(); | 274 cleanup(); |
| 279 if (m_client) | 275 if (m_client) |
| 280 m_client->didFinishLoading(); | 276 m_client->didFinishLoading(); |
| 281 } | 277 } |
| 282 | 278 |
| 283 void FileReaderLoader::didFail(const ResourceError&) | 279 void FileReaderLoader::didFail(const ResourceError& error) |
| 284 { | 280 { |
| 281 if (error.isCancellation()) |
| 282 return; |
| 285 // 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. |
| 286 if (m_errorCode == FileError::ABORT_ERR) | 284 if (m_errorCode == FileError::ABORT_ERR) |
| 287 return; | 285 return; |
| 288 | 286 |
| 289 failed(FileError::NOT_READABLE_ERR); | 287 failed(FileError::NOT_READABLE_ERR); |
| 290 } | 288 } |
| 291 | 289 |
| 292 void FileReaderLoader::failed(FileError::ErrorCode errorCode) | 290 void FileReaderLoader::failed(FileError::ErrorCode errorCode) |
| 293 { | 291 { |
| 294 m_errorCode = errorCode; | 292 m_errorCode = errorCode; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 m_stringResult = builder.toString(); | 401 m_stringResult = builder.toString(); |
| 404 } | 402 } |
| 405 | 403 |
| 406 void FileReaderLoader::setEncoding(const String& encoding) | 404 void FileReaderLoader::setEncoding(const String& encoding) |
| 407 { | 405 { |
| 408 if (!encoding.isEmpty()) | 406 if (!encoding.isEmpty()) |
| 409 m_encoding = WTF::TextEncoding(encoding); | 407 m_encoding = WTF::TextEncoding(encoding); |
| 410 } | 408 } |
| 411 | 409 |
| 412 } // namespace blink | 410 } // namespace blink |
| OLD | NEW |