| 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 11 matching lines...) Expand all Loading... |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 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 "config.h" | 31 #include "config.h" |
| 32 | |
| 33 #include "core/fileapi/FileReaderSync.h" | 32 #include "core/fileapi/FileReaderSync.h" |
| 34 | 33 |
| 34 #include "core/dom/ExceptionCode.h" |
| 35 #include "core/fileapi/Blob.h" | 35 #include "core/fileapi/Blob.h" |
| 36 #include "core/fileapi/FileException.h" | |
| 37 #include "core/fileapi/FileReaderLoader.h" | 36 #include "core/fileapi/FileReaderLoader.h" |
| 38 #include <wtf/ArrayBuffer.h> | 37 #include <wtf/ArrayBuffer.h> |
| 39 #include <wtf/PassRefPtr.h> | 38 #include <wtf/PassRefPtr.h> |
| 40 | 39 |
| 41 namespace WebCore { | 40 namespace WebCore { |
| 42 | 41 |
| 43 FileReaderSync::FileReaderSync() | 42 FileReaderSync::FileReaderSync() |
| 44 { | 43 { |
| 45 ScriptWrappable::init(this); | 44 ScriptWrappable::init(this); |
| 46 } | 45 } |
| 47 | 46 |
| 48 PassRefPtr<ArrayBuffer> FileReaderSync::readAsArrayBuffer(ScriptExecutionContext
* scriptExecutionContext, Blob* blob, ExceptionCode& ec) | 47 PassRefPtr<ArrayBuffer> FileReaderSync::readAsArrayBuffer(ScriptExecutionContext
* scriptExecutionContext, Blob* blob, ExceptionCode& ec) |
| 49 { | 48 { |
| 50 if (!blob) { | 49 if (!blob) { |
| 51 ec = NOT_FOUND_ERR; | 50 ec = FSNotFoundError; |
| 52 return 0; | 51 return 0; |
| 53 } | 52 } |
| 54 | 53 |
| 55 FileReaderLoader loader(FileReaderLoader::ReadAsArrayBuffer, 0); | 54 FileReaderLoader loader(FileReaderLoader::ReadAsArrayBuffer, 0); |
| 56 startLoading(scriptExecutionContext, loader, blob, ec); | 55 startLoading(scriptExecutionContext, loader, blob, ec); |
| 57 | 56 |
| 58 return loader.arrayBufferResult(); | 57 return loader.arrayBufferResult(); |
| 59 } | 58 } |
| 60 | 59 |
| 61 String FileReaderSync::readAsBinaryString(ScriptExecutionContext* scriptExecutio
nContext, Blob* blob, ExceptionCode& ec) | 60 String FileReaderSync::readAsBinaryString(ScriptExecutionContext* scriptExecutio
nContext, Blob* blob, ExceptionCode& ec) |
| 62 { | 61 { |
| 63 if (!blob) { | 62 if (!blob) { |
| 64 ec = NOT_FOUND_ERR; | 63 ec = FSNotFoundError; |
| 65 return String(); | 64 return String(); |
| 66 } | 65 } |
| 67 | 66 |
| 68 FileReaderLoader loader(FileReaderLoader::ReadAsBinaryString, 0); | 67 FileReaderLoader loader(FileReaderLoader::ReadAsBinaryString, 0); |
| 69 startLoading(scriptExecutionContext, loader, blob, ec); | 68 startLoading(scriptExecutionContext, loader, blob, ec); |
| 70 return loader.stringResult(); | 69 return loader.stringResult(); |
| 71 } | 70 } |
| 72 | 71 |
| 73 String FileReaderSync::readAsText(ScriptExecutionContext* scriptExecutionContext
, Blob* blob, const String& encoding, ExceptionCode& ec) | 72 String FileReaderSync::readAsText(ScriptExecutionContext* scriptExecutionContext
, Blob* blob, const String& encoding, ExceptionCode& ec) |
| 74 { | 73 { |
| 75 if (!blob) { | 74 if (!blob) { |
| 76 ec = NOT_FOUND_ERR; | 75 ec = FSNotFoundError; |
| 77 return String(); | 76 return String(); |
| 78 } | 77 } |
| 79 | 78 |
| 80 FileReaderLoader loader(FileReaderLoader::ReadAsText, 0); | 79 FileReaderLoader loader(FileReaderLoader::ReadAsText, 0); |
| 81 loader.setEncoding(encoding); | 80 loader.setEncoding(encoding); |
| 82 startLoading(scriptExecutionContext, loader, blob, ec); | 81 startLoading(scriptExecutionContext, loader, blob, ec); |
| 83 return loader.stringResult(); | 82 return loader.stringResult(); |
| 84 } | 83 } |
| 85 | 84 |
| 86 String FileReaderSync::readAsDataURL(ScriptExecutionContext* scriptExecutionCont
ext, Blob* blob, ExceptionCode& ec) | 85 String FileReaderSync::readAsDataURL(ScriptExecutionContext* scriptExecutionCont
ext, Blob* blob, ExceptionCode& ec) |
| 87 { | 86 { |
| 88 if (!blob) { | 87 if (!blob) { |
| 89 ec = NOT_FOUND_ERR; | 88 ec = FSNotFoundError; |
| 90 return String(); | 89 return String(); |
| 91 } | 90 } |
| 92 | 91 |
| 93 FileReaderLoader loader(FileReaderLoader::ReadAsDataURL, 0); | 92 FileReaderLoader loader(FileReaderLoader::ReadAsDataURL, 0); |
| 94 loader.setDataType(blob->type()); | 93 loader.setDataType(blob->type()); |
| 95 startLoading(scriptExecutionContext, loader, blob, ec); | 94 startLoading(scriptExecutionContext, loader, blob, ec); |
| 96 return loader.stringResult(); | 95 return loader.stringResult(); |
| 97 } | 96 } |
| 98 | 97 |
| 99 void FileReaderSync::startLoading(ScriptExecutionContext* scriptExecutionContext
, FileReaderLoader& loader, Blob* blob, ExceptionCode& ec) | 98 void FileReaderSync::startLoading(ScriptExecutionContext* scriptExecutionContext
, FileReaderLoader& loader, Blob* blob, ExceptionCode& ec) |
| 100 { | 99 { |
| 101 loader.start(scriptExecutionContext, blob); | 100 loader.start(scriptExecutionContext, blob); |
| 102 ec = FileException::ErrorCodeToExceptionCode(loader.errorCode()); | 101 ec = FileError::ErrorCodeToExceptionCode(loader.errorCode()); |
| 103 } | 102 } |
| 104 | 103 |
| 105 } // namespace WebCore | 104 } // namespace WebCore |
| OLD | NEW |