| 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 25 matching lines...) Expand all Loading... |
| 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/ResourceRequest.h" | 43 #include "platform/network/ResourceRequest.h" |
| 44 #include "platform/network/ResourceResponse.h" | 44 #include "platform/network/ResourceResponse.h" |
| 45 #include "public/platform/WebURLRequest.h" | 45 #include "public/platform/WebURLRequest.h" |
| 46 #include "wtf/PassOwnPtr.h" |
| 46 #include "wtf/PassRefPtr.h" | 47 #include "wtf/PassRefPtr.h" |
| 47 #include "wtf/PtrUtil.h" | |
| 48 #include "wtf/RefPtr.h" | 48 #include "wtf/RefPtr.h" |
| 49 #include "wtf/Vector.h" | 49 #include "wtf/Vector.h" |
| 50 #include "wtf/text/Base64.h" | 50 #include "wtf/text/Base64.h" |
| 51 #include "wtf/text/StringBuilder.h" | 51 #include "wtf/text/StringBuilder.h" |
| 52 #include <memory> | |
| 53 | 52 |
| 54 namespace blink { | 53 namespace blink { |
| 55 | 54 |
| 56 FileReaderLoader::FileReaderLoader(ReadType readType, FileReaderLoaderClient* cl
ient) | 55 FileReaderLoader::FileReaderLoader(ReadType readType, FileReaderLoaderClient* cl
ient) |
| 57 : m_readType(readType) | 56 : m_readType(readType) |
| 58 , m_client(client) | 57 , m_client(client) |
| 59 , m_urlForReadingIsStream(false) | 58 , m_urlForReadingIsStream(false) |
| 60 , m_isRawDataConverted(false) | 59 , m_isRawDataConverted(false) |
| 61 , m_stringResult("") | 60 , m_stringResult("") |
| 62 , m_finishedLoading(false) | 61 , m_finishedLoading(false) |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 166 |
| 168 // If we get any error, we do not need to keep a buffer around. | 167 // If we get any error, we do not need to keep a buffer around. |
| 169 if (m_errorCode) { | 168 if (m_errorCode) { |
| 170 m_rawData.reset(); | 169 m_rawData.reset(); |
| 171 m_stringResult = ""; | 170 m_stringResult = ""; |
| 172 m_isRawDataConverted = true; | 171 m_isRawDataConverted = true; |
| 173 m_decoder.reset(); | 172 m_decoder.reset(); |
| 174 } | 173 } |
| 175 } | 174 } |
| 176 | 175 |
| 177 void FileReaderLoader::didReceiveResponse(unsigned long, const ResourceResponse&
response, std::unique_ptr<WebDataConsumerHandle> handle) | 176 void FileReaderLoader::didReceiveResponse(unsigned long, const ResourceResponse&
response, PassOwnPtr<WebDataConsumerHandle> handle) |
| 178 { | 177 { |
| 179 ASSERT_UNUSED(handle, !handle); | 178 ASSERT_UNUSED(handle, !handle); |
| 180 if (response.httpStatusCode() != 200) { | 179 if (response.httpStatusCode() != 200) { |
| 181 failed(httpStatusCodeToErrorCode(response.httpStatusCode())); | 180 failed(httpStatusCodeToErrorCode(response.httpStatusCode())); |
| 182 return; | 181 return; |
| 183 } | 182 } |
| 184 | 183 |
| 185 // A negative value means that the content length wasn't specified. | 184 // A negative value means that the content length wasn't specified. |
| 186 m_totalBytes = response.expectedContentLength(); | 185 m_totalBytes = response.expectedContentLength(); |
| 187 | 186 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 205 if (m_readType != ReadByClient) { | 204 if (m_readType != ReadByClient) { |
| 206 // Check that we can cast to unsigned since we have to do | 205 // Check that we can cast to unsigned since we have to do |
| 207 // so to call ArrayBuffer's create function. | 206 // so to call ArrayBuffer's create function. |
| 208 // FIXME: Support reading more than the current size limit of ArrayBuffe
r. | 207 // FIXME: Support reading more than the current size limit of ArrayBuffe
r. |
| 209 if (initialBufferLength > std::numeric_limits<unsigned>::max()) { | 208 if (initialBufferLength > std::numeric_limits<unsigned>::max()) { |
| 210 failed(FileError::NOT_READABLE_ERR); | 209 failed(FileError::NOT_READABLE_ERR); |
| 211 return; | 210 return; |
| 212 } | 211 } |
| 213 | 212 |
| 214 if (initialBufferLength < 0) | 213 if (initialBufferLength < 0) |
| 215 m_rawData = wrapUnique(new ArrayBufferBuilder()); | 214 m_rawData = adoptPtr(new ArrayBufferBuilder()); |
| 216 else | 215 else |
| 217 m_rawData = wrapUnique(new ArrayBufferBuilder(static_cast<unsigned>(
initialBufferLength))); | 216 m_rawData = adoptPtr(new ArrayBufferBuilder(static_cast<unsigned>(in
itialBufferLength))); |
| 218 | 217 |
| 219 if (!m_rawData || !m_rawData->isValid()) { | 218 if (!m_rawData || !m_rawData->isValid()) { |
| 220 failed(FileError::NOT_READABLE_ERR); | 219 failed(FileError::NOT_READABLE_ERR); |
| 221 return; | 220 return; |
| 222 } | 221 } |
| 223 | 222 |
| 224 if (initialBufferLength >= 0) { | 223 if (initialBufferLength >= 0) { |
| 225 // Total size is known. Set m_rawData to ignore overflowed data. | 224 // Total size is known. Set m_rawData to ignore overflowed data. |
| 226 m_rawData->setVariableCapacity(false); | 225 m_rawData->setVariableCapacity(false); |
| 227 } | 226 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 m_stringResult = builder.toString(); | 402 m_stringResult = builder.toString(); |
| 404 } | 403 } |
| 405 | 404 |
| 406 void FileReaderLoader::setEncoding(const String& encoding) | 405 void FileReaderLoader::setEncoding(const String& encoding) |
| 407 { | 406 { |
| 408 if (!encoding.isEmpty()) | 407 if (!encoding.isEmpty()) |
| 409 m_encoding = WTF::TextEncoding(encoding); | 408 m_encoding = WTF::TextEncoding(encoding); |
| 410 } | 409 } |
| 411 | 410 |
| 412 } // namespace blink | 411 } // namespace blink |
| OLD | NEW |