| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 if (m_urlForReadingIsStream) | 75 if (m_urlForReadingIsStream) |
| 76 BlobRegistry::unregisterStreamURL(m_urlForReading); | 76 BlobRegistry::unregisterStreamURL(m_urlForReading); |
| 77 else | 77 else |
| 78 BlobRegistry::revokePublicBlobURL(m_urlForReading); | 78 BlobRegistry::revokePublicBlobURL(m_urlForReading); |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 void FileReaderLoader::startInternal(ExecutionContext& executionContext, | 82 void FileReaderLoader::startInternal(ExecutionContext& executionContext, |
| 83 const Stream* stream, | 83 const Stream* stream, |
| 84 PassRefPtr<BlobDataHandle> blobData) { | 84 PassRefPtr<BlobDataHandle> blobData) { |
| 85 // The blob is read by routing through the request handling layer given a temp
orary public url. | 85 // The blob is read by routing through the request handling layer given a |
| 86 // temporary public url. |
| 86 m_urlForReading = | 87 m_urlForReading = |
| 87 BlobURL::createPublicURL(executionContext.getSecurityOrigin()); | 88 BlobURL::createPublicURL(executionContext.getSecurityOrigin()); |
| 88 if (m_urlForReading.isEmpty()) { | 89 if (m_urlForReading.isEmpty()) { |
| 89 failed(FileError::kSecurityErr); | 90 failed(FileError::kSecurityErr); |
| 90 return; | 91 return; |
| 91 } | 92 } |
| 92 | 93 |
| 93 if (blobData) { | 94 if (blobData) { |
| 94 ASSERT(!stream); | 95 ASSERT(!stream); |
| 95 BlobRegistry::registerPublicBlobURL(executionContext.getSecurityOrigin(), | 96 BlobRegistry::registerPublicBlobURL(executionContext.getSecurityOrigin(), |
| 96 m_urlForReading, std::move(blobData)); | 97 m_urlForReading, std::move(blobData)); |
| 97 } else { | 98 } else { |
| 98 ASSERT(stream); | 99 ASSERT(stream); |
| 99 BlobRegistry::registerStreamURL(executionContext.getSecurityOrigin(), | 100 BlobRegistry::registerStreamURL(executionContext.getSecurityOrigin(), |
| 100 m_urlForReading, stream->url()); | 101 m_urlForReading, stream->url()); |
| 101 } | 102 } |
| 102 | 103 |
| 103 // Construct and load the request. | 104 // Construct and load the request. |
| 104 ResourceRequest request(m_urlForReading); | 105 ResourceRequest request(m_urlForReading); |
| 105 request.setExternalRequestStateFromRequestorAddressSpace( | 106 request.setExternalRequestStateFromRequestorAddressSpace( |
| 106 executionContext.securityContext().addressSpace()); | 107 executionContext.securityContext().addressSpace()); |
| 107 | 108 |
| 108 // FIXME: Should this really be 'internal'? Do we know anything about the actu
al request that generated this fetch? | 109 // FIXME: Should this really be 'internal'? Do we know anything about the |
| 110 // actual request that generated this fetch? |
| 109 request.setRequestContext(WebURLRequest::RequestContextInternal); | 111 request.setRequestContext(WebURLRequest::RequestContextInternal); |
| 110 | 112 |
| 111 request.setHTTPMethod(HTTPNames::GET); | 113 request.setHTTPMethod(HTTPNames::GET); |
| 112 if (m_hasRange) | 114 if (m_hasRange) |
| 113 request.setHTTPHeaderField( | 115 request.setHTTPHeaderField( |
| 114 HTTPNames::Range, | 116 HTTPNames::Range, |
| 115 AtomicString(String::format("bytes=%d-%d", m_rangeStart, m_rangeEnd))); | 117 AtomicString(String::format("bytes=%d-%d", m_rangeStart, m_rangeEnd))); |
| 116 | 118 |
| 117 ThreadableLoaderOptions options; | 119 ThreadableLoaderOptions options; |
| 118 options.preflightPolicy = ConsiderPreflight; | 120 options.preflightPolicy = ConsiderPreflight; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 m_finishedLoading = true; | 281 m_finishedLoading = true; |
| 280 | 282 |
| 281 cleanup(); | 283 cleanup(); |
| 282 if (m_client) | 284 if (m_client) |
| 283 m_client->didFinishLoading(); | 285 m_client->didFinishLoading(); |
| 284 } | 286 } |
| 285 | 287 |
| 286 void FileReaderLoader::didFail(const ResourceError& error) { | 288 void FileReaderLoader::didFail(const ResourceError& error) { |
| 287 if (error.isCancellation()) | 289 if (error.isCancellation()) |
| 288 return; | 290 return; |
| 289 // If we're aborting, do not proceed with normal error handling since it is co
vered in aborting code. | 291 // If we're aborting, do not proceed with normal error handling since it is |
| 292 // covered in aborting code. |
| 290 if (m_errorCode == FileError::kAbortErr) | 293 if (m_errorCode == FileError::kAbortErr) |
| 291 return; | 294 return; |
| 292 | 295 |
| 293 failed(FileError::kNotReadableErr); | 296 failed(FileError::kNotReadableErr); |
| 294 } | 297 } |
| 295 | 298 |
| 296 void FileReaderLoader::failed(FileError::ErrorCode errorCode) { | 299 void FileReaderLoader::failed(FileError::ErrorCode errorCode) { |
| 297 m_errorCode = errorCode; | 300 m_errorCode = errorCode; |
| 298 cleanup(); | 301 cleanup(); |
| 299 if (m_client) | 302 if (m_client) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 | 368 |
| 366 void FileReaderLoader::convertToText() { | 369 void FileReaderLoader::convertToText() { |
| 367 m_isRawDataConverted = true; | 370 m_isRawDataConverted = true; |
| 368 | 371 |
| 369 if (!m_bytesLoaded) { | 372 if (!m_bytesLoaded) { |
| 370 m_stringResult = ""; | 373 m_stringResult = ""; |
| 371 return; | 374 return; |
| 372 } | 375 } |
| 373 | 376 |
| 374 // Decode the data. | 377 // Decode the data. |
| 375 // The File API spec says that we should use the supplied encoding if it is va
lid. However, we choose to ignore this | 378 // The File API spec says that we should use the supplied encoding if it is |
| 376 // requirement in order to be consistent with how WebKit decodes the web conte
nt: always has the BOM override the | 379 // valid. However, we choose to ignore this requirement in order to be |
| 377 // provided encoding. | 380 // consistent with how WebKit decodes the web content: always has the BOM |
| 381 // override the provided encoding. |
| 378 // FIXME: consider supporting incremental decoding to improve the perf. | 382 // FIXME: consider supporting incremental decoding to improve the perf. |
| 379 StringBuilder builder; | 383 StringBuilder builder; |
| 380 if (!m_decoder) | 384 if (!m_decoder) |
| 381 m_decoder = TextResourceDecoder::create( | 385 m_decoder = TextResourceDecoder::create( |
| 382 "text/plain", m_encoding.isValid() ? m_encoding : UTF8Encoding()); | 386 "text/plain", m_encoding.isValid() ? m_encoding : UTF8Encoding()); |
| 383 builder.append(m_decoder->decode(static_cast<const char*>(m_rawData->data()), | 387 builder.append(m_decoder->decode(static_cast<const char*>(m_rawData->data()), |
| 384 m_rawData->byteLength())); | 388 m_rawData->byteLength())); |
| 385 | 389 |
| 386 if (m_finishedLoading) | 390 if (m_finishedLoading) |
| 387 builder.append(m_decoder->flush()); | 391 builder.append(m_decoder->flush()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 411 | 415 |
| 412 m_stringResult = builder.toString(); | 416 m_stringResult = builder.toString(); |
| 413 } | 417 } |
| 414 | 418 |
| 415 void FileReaderLoader::setEncoding(const String& encoding) { | 419 void FileReaderLoader::setEncoding(const String& encoding) { |
| 416 if (!encoding.isEmpty()) | 420 if (!encoding.isEmpty()) |
| 417 m_encoding = WTF::TextEncoding(encoding); | 421 m_encoding = WTF::TextEncoding(encoding); |
| 418 } | 422 } |
| 419 | 423 |
| 420 } // namespace blink | 424 } // namespace blink |
| OLD | NEW |