| 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 28 matching lines...) Expand all Loading... |
| 39 #include "core/fileapi/File.h" | 39 #include "core/fileapi/File.h" |
| 40 #include "platform/Logging.h" | 40 #include "platform/Logging.h" |
| 41 #include "wtf/ArrayBuffer.h" | 41 #include "wtf/ArrayBuffer.h" |
| 42 #include "wtf/CurrentTime.h" | 42 #include "wtf/CurrentTime.h" |
| 43 #include "wtf/text/CString.h" | 43 #include "wtf/text/CString.h" |
| 44 | 44 |
| 45 namespace WebCore { | 45 namespace WebCore { |
| 46 | 46 |
| 47 namespace { | 47 namespace { |
| 48 | 48 |
| 49 const CString utf8BlobURL(Blob* blob) | 49 const CString utf8BlobUUID(Blob* blob) |
| 50 { | 50 { |
| 51 return blob->url().string().utf8(); | 51 return blob->uuid().utf8(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 const CString utf8FilePath(Blob* blob) | 54 const CString utf8FilePath(Blob* blob) |
| 55 { | 55 { |
| 56 return blob->isFile() ? toFile(blob)->path().utf8() : ""; | 56 return blob->isFile() ? toFile(blob)->path().utf8() : ""; |
| 57 } | 57 } |
| 58 | 58 |
| 59 } // namespace | 59 } // namespace |
| 60 | 60 |
| 61 static const double progressNotificationIntervalMS = 50; | 61 static const double progressNotificationIntervalMS = 50; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 void FileReader::stop() | 96 void FileReader::stop() |
| 97 { | 97 { |
| 98 terminate(); | 98 terminate(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void FileReader::readAsArrayBuffer(Blob* blob, ExceptionState& es) | 101 void FileReader::readAsArrayBuffer(Blob* blob, ExceptionState& es) |
| 102 { | 102 { |
| 103 if (!blob) | 103 if (!blob) |
| 104 return; | 104 return; |
| 105 | 105 |
| 106 LOG(FileAPI, "FileReader: reading as array buffer: %s %s\n", utf8BlobURL(blo
b).data(), utf8FilePath(blob).data()); | 106 LOG(FileAPI, "FileReader: reading as array buffer: %s %s\n", utf8BlobUUID(bl
ob).data(), utf8FilePath(blob).data()); |
| 107 | 107 |
| 108 readInternal(blob, FileReaderLoader::ReadAsArrayBuffer, es); | 108 readInternal(blob, FileReaderLoader::ReadAsArrayBuffer, es); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void FileReader::readAsBinaryString(Blob* blob, ExceptionState& es) | 111 void FileReader::readAsBinaryString(Blob* blob, ExceptionState& es) |
| 112 { | 112 { |
| 113 if (!blob) | 113 if (!blob) |
| 114 return; | 114 return; |
| 115 | 115 |
| 116 LOG(FileAPI, "FileReader: reading as binary: %s %s\n", utf8BlobURL(blob).dat
a(), utf8FilePath(blob).data()); | 116 LOG(FileAPI, "FileReader: reading as binary: %s %s\n", utf8BlobUUID(blob).da
ta(), utf8FilePath(blob).data()); |
| 117 | 117 |
| 118 readInternal(blob, FileReaderLoader::ReadAsBinaryString, es); | 118 readInternal(blob, FileReaderLoader::ReadAsBinaryString, es); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void FileReader::readAsText(Blob* blob, const String& encoding, ExceptionState&
es) | 121 void FileReader::readAsText(Blob* blob, const String& encoding, ExceptionState&
es) |
| 122 { | 122 { |
| 123 if (!blob) | 123 if (!blob) |
| 124 return; | 124 return; |
| 125 | 125 |
| 126 LOG(FileAPI, "FileReader: reading as text: %s %s\n", utf8BlobURL(blob).data(
), utf8FilePath(blob).data()); | 126 LOG(FileAPI, "FileReader: reading as text: %s %s\n", utf8BlobUUID(blob).data
(), utf8FilePath(blob).data()); |
| 127 | 127 |
| 128 m_encoding = encoding; | 128 m_encoding = encoding; |
| 129 readInternal(blob, FileReaderLoader::ReadAsText, es); | 129 readInternal(blob, FileReaderLoader::ReadAsText, es); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void FileReader::readAsText(Blob* blob, ExceptionState& es) | 132 void FileReader::readAsText(Blob* blob, ExceptionState& es) |
| 133 { | 133 { |
| 134 readAsText(blob, String(), es); | 134 readAsText(blob, String(), es); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void FileReader::readAsDataURL(Blob* blob, ExceptionState& es) | 137 void FileReader::readAsDataURL(Blob* blob, ExceptionState& es) |
| 138 { | 138 { |
| 139 if (!blob) | 139 if (!blob) |
| 140 return; | 140 return; |
| 141 | 141 |
| 142 LOG(FileAPI, "FileReader: reading as data URL: %s %s\n", utf8BlobURL(blob).d
ata(), utf8FilePath(blob).data()); | 142 LOG(FileAPI, "FileReader: reading as data URL: %s %s\n", utf8BlobUUID(blob).
data(), utf8FilePath(blob).data()); |
| 143 | 143 |
| 144 readInternal(blob, FileReaderLoader::ReadAsDataURL, es); | 144 readInternal(blob, FileReaderLoader::ReadAsDataURL, es); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void FileReader::readInternal(Blob* blob, FileReaderLoader::ReadType type, Excep
tionState& es) | 147 void FileReader::readInternal(Blob* blob, FileReaderLoader::ReadType type, Excep
tionState& es) |
| 148 { | 148 { |
| 149 // If multiple concurrent read methods are called on the same FileReader, In
validStateError should be thrown when the state is LOADING. | 149 // If multiple concurrent read methods are called on the same FileReader, In
validStateError should be thrown when the state is LOADING. |
| 150 if (m_state == LOADING) { | 150 if (m_state == LOADING) { |
| 151 es.throwUninformativeAndGenericDOMException(InvalidStateError); | 151 es.throwUninformativeAndGenericDOMException(InvalidStateError); |
| 152 return; | 152 return; |
| 153 } | 153 } |
| 154 | 154 |
| 155 setPendingActivity(this); | 155 setPendingActivity(this); |
| 156 | 156 |
| 157 m_blob = blob; | 157 m_blob = blob; |
| 158 m_readType = type; | 158 m_readType = type; |
| 159 m_state = LOADING; | 159 m_state = LOADING; |
| 160 m_loadingState = LoadingStateLoading; | 160 m_loadingState = LoadingStateLoading; |
| 161 m_error = 0; | 161 m_error = 0; |
| 162 | 162 |
| 163 m_loader = adoptPtr(new FileReaderLoader(m_readType, this)); | 163 m_loader = adoptPtr(new FileReaderLoader(m_readType, this)); |
| 164 m_loader->setEncoding(m_encoding); | 164 m_loader->setEncoding(m_encoding); |
| 165 m_loader->setDataType(m_blob->type()); | 165 m_loader->setDataType(m_blob->type()); |
| 166 m_loader->start(scriptExecutionContext(), *m_blob); | 166 m_loader->start(scriptExecutionContext(), m_blob->blobDataHandle()); |
| 167 } | 167 } |
| 168 | 168 |
| 169 static void delayedAbort(ScriptExecutionContext*, FileReader* reader) | 169 static void delayedAbort(ScriptExecutionContext*, FileReader* reader) |
| 170 { | 170 { |
| 171 reader->doAbort(); | 171 reader->doAbort(); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void FileReader::abort() | 174 void FileReader::abort() |
| 175 { | 175 { |
| 176 LOG(FileAPI, "FileReader: aborting\n"); | 176 LOG(FileAPI, "FileReader: aborting\n"); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 } | 281 } |
| 282 | 282 |
| 283 String FileReader::stringResult() | 283 String FileReader::stringResult() |
| 284 { | 284 { |
| 285 if (!m_loader || m_error) | 285 if (!m_loader || m_error) |
| 286 return String(); | 286 return String(); |
| 287 return m_loader->stringResult(); | 287 return m_loader->stringResult(); |
| 288 } | 288 } |
| 289 | 289 |
| 290 } // namespace WebCore | 290 } // namespace WebCore |
| OLD | NEW |