| 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 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/fileapi/FileReaderSync.h" | 31 #include "core/fileapi/FileReaderSync.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/ExceptionState.h" | 33 #include "bindings/core/v8/ExceptionState.h" |
| 34 #include "bindings/core/v8/ScriptState.h" |
| 34 #include "core/dom/DOMArrayBuffer.h" | 35 #include "core/dom/DOMArrayBuffer.h" |
| 35 #include "core/fileapi/Blob.h" | 36 #include "core/fileapi/Blob.h" |
| 36 #include "core/fileapi/FileError.h" | 37 #include "core/fileapi/FileError.h" |
| 37 #include "core/fileapi/FileReaderLoader.h" | 38 #include "core/fileapi/FileReaderLoader.h" |
| 38 | 39 |
| 39 namespace blink { | 40 namespace blink { |
| 40 | 41 |
| 41 FileReaderSync::FileReaderSync() {} | 42 FileReaderSync::FileReaderSync() {} |
| 42 | 43 |
| 43 DOMArrayBuffer* FileReaderSync::readAsArrayBuffer( | 44 DOMArrayBuffer* FileReaderSync::readAsArrayBuffer( |
| 44 ExecutionContext* executionContext, | 45 ScriptState* scriptState, |
| 45 Blob* blob, | 46 Blob* blob, |
| 46 ExceptionState& exceptionState) { | 47 ExceptionState& exceptionState) { |
| 47 ASSERT(blob); | 48 ASSERT(blob); |
| 48 | 49 |
| 49 std::unique_ptr<FileReaderLoader> loader = | 50 std::unique_ptr<FileReaderLoader> loader = |
| 50 FileReaderLoader::create(FileReaderLoader::ReadAsArrayBuffer, nullptr); | 51 FileReaderLoader::create(FileReaderLoader::ReadAsArrayBuffer, nullptr); |
| 51 startLoading(executionContext, *loader, *blob, exceptionState); | 52 startLoading(scriptState->getExecutionContext(), *loader, *blob, |
| 53 exceptionState); |
| 52 | 54 |
| 53 return loader->arrayBufferResult(); | 55 return loader->arrayBufferResult(); |
| 54 } | 56 } |
| 55 | 57 |
| 56 String FileReaderSync::readAsBinaryString(ExecutionContext* executionContext, | 58 String FileReaderSync::readAsBinaryString(ScriptState* scriptState, |
| 57 Blob* blob, | 59 Blob* blob, |
| 58 ExceptionState& exceptionState) { | 60 ExceptionState& exceptionState) { |
| 59 ASSERT(blob); | 61 ASSERT(blob); |
| 60 | 62 |
| 61 std::unique_ptr<FileReaderLoader> loader = | 63 std::unique_ptr<FileReaderLoader> loader = |
| 62 FileReaderLoader::create(FileReaderLoader::ReadAsBinaryString, nullptr); | 64 FileReaderLoader::create(FileReaderLoader::ReadAsBinaryString, nullptr); |
| 63 startLoading(executionContext, *loader, *blob, exceptionState); | 65 startLoading(scriptState->getExecutionContext(), *loader, *blob, |
| 66 exceptionState); |
| 64 return loader->stringResult(); | 67 return loader->stringResult(); |
| 65 } | 68 } |
| 66 | 69 |
| 67 String FileReaderSync::readAsText(ExecutionContext* executionContext, | 70 String FileReaderSync::readAsText(ScriptState* scriptState, |
| 68 Blob* blob, | 71 Blob* blob, |
| 69 const String& encoding, | 72 const String& encoding, |
| 70 ExceptionState& exceptionState) { | 73 ExceptionState& exceptionState) { |
| 71 ASSERT(blob); | 74 ASSERT(blob); |
| 72 | 75 |
| 73 std::unique_ptr<FileReaderLoader> loader = | 76 std::unique_ptr<FileReaderLoader> loader = |
| 74 FileReaderLoader::create(FileReaderLoader::ReadAsText, nullptr); | 77 FileReaderLoader::create(FileReaderLoader::ReadAsText, nullptr); |
| 75 loader->setEncoding(encoding); | 78 loader->setEncoding(encoding); |
| 76 startLoading(executionContext, *loader, *blob, exceptionState); | 79 startLoading(scriptState->getExecutionContext(), *loader, *blob, |
| 80 exceptionState); |
| 77 return loader->stringResult(); | 81 return loader->stringResult(); |
| 78 } | 82 } |
| 79 | 83 |
| 80 String FileReaderSync::readAsDataURL(ExecutionContext* executionContext, | 84 String FileReaderSync::readAsDataURL(ScriptState* scriptState, |
| 81 Blob* blob, | 85 Blob* blob, |
| 82 ExceptionState& exceptionState) { | 86 ExceptionState& exceptionState) { |
| 83 ASSERT(blob); | 87 ASSERT(blob); |
| 84 | 88 |
| 85 std::unique_ptr<FileReaderLoader> loader = | 89 std::unique_ptr<FileReaderLoader> loader = |
| 86 FileReaderLoader::create(FileReaderLoader::ReadAsDataURL, nullptr); | 90 FileReaderLoader::create(FileReaderLoader::ReadAsDataURL, nullptr); |
| 87 loader->setDataType(blob->type()); | 91 loader->setDataType(blob->type()); |
| 88 startLoading(executionContext, *loader, *blob, exceptionState); | 92 startLoading(scriptState->getExecutionContext(), *loader, *blob, |
| 93 exceptionState); |
| 89 return loader->stringResult(); | 94 return loader->stringResult(); |
| 90 } | 95 } |
| 91 | 96 |
| 92 void FileReaderSync::startLoading(ExecutionContext* executionContext, | 97 void FileReaderSync::startLoading(ExecutionContext* executionContext, |
| 93 FileReaderLoader& loader, | 98 FileReaderLoader& loader, |
| 94 const Blob& blob, | 99 const Blob& blob, |
| 95 ExceptionState& exceptionState) { | 100 ExceptionState& exceptionState) { |
| 96 loader.start(executionContext, blob.blobDataHandle()); | 101 loader.start(executionContext, blob.blobDataHandle()); |
| 97 if (loader.errorCode()) | 102 if (loader.errorCode()) |
| 98 FileError::throwDOMException(exceptionState, loader.errorCode()); | 103 FileError::throwDOMException(exceptionState, loader.errorCode()); |
| 99 } | 104 } |
| 100 | 105 |
| 101 } // namespace blink | 106 } // namespace blink |
| OLD | NEW |