Index: Source/core/fileapi/FileReader.cpp |
diff --git a/Source/core/fileapi/FileReader.cpp b/Source/core/fileapi/FileReader.cpp |
index a6189a78464fac8f2df6f7dc085d7c8d226cf2d2..614039a7586d1cc4e03587e6bd8d11f17ff8f4e8 100644 |
--- a/Source/core/fileapi/FileReader.cpp |
+++ b/Source/core/fileapi/FileReader.cpp |
@@ -55,6 +55,11 @@ const CString utf8FilePath(Blob* blob) |
return blob->isFile() ? toFile(blob)->path().utf8() : ""; |
} |
+const CString utf8BlobURL(Stream* stream) |
+{ |
+ return stream->url().string().utf8(); |
+} |
+ |
} // namespace |
static const double progressNotificationIntervalMS = 50; |
@@ -102,9 +107,9 @@ void FileReader::readAsArrayBuffer(Blob* blob, ExceptionCode& ec) |
if (!blob) |
return; |
- LOG(FileAPI, "FileReader: reading as array buffer: %s %s\n", utf8BlobURL(blob).data(), utf8FilePath(blob).data()); |
+ LOG(FileAPI, "FileReader: reading Blob as array buffer: %s %s\n", utf8BlobURL(blob).data(), utf8FilePath(blob).data()); |
- readInternal(blob, FileReaderLoader::ReadAsArrayBuffer, ec); |
+ readInternal(blob, 0, FileReaderLoader::ReadAsArrayBuffer, ec); |
} |
void FileReader::readAsBinaryString(Blob* blob, ExceptionCode& ec) |
@@ -112,9 +117,9 @@ void FileReader::readAsBinaryString(Blob* blob, ExceptionCode& ec) |
if (!blob) |
return; |
- LOG(FileAPI, "FileReader: reading as binary: %s %s\n", utf8BlobURL(blob).data(), utf8FilePath(blob).data()); |
+ LOG(FileAPI, "FileReader: reading Blob as binary: %s %s\n", utf8BlobURL(blob).data(), utf8FilePath(blob).data()); |
- readInternal(blob, FileReaderLoader::ReadAsBinaryString, ec); |
+ readInternal(blob, 0, FileReaderLoader::ReadAsBinaryString, ec); |
} |
void FileReader::readAsText(Blob* blob, const String& encoding, ExceptionCode& ec) |
@@ -122,10 +127,10 @@ void FileReader::readAsText(Blob* blob, const String& encoding, ExceptionCode& e |
if (!blob) |
return; |
- LOG(FileAPI, "FileReader: reading as text: %s %s\n", utf8BlobURL(blob).data(), utf8FilePath(blob).data()); |
+ LOG(FileAPI, "FileReader: reading Blob as text: %s %s\n", utf8BlobURL(blob).data(), utf8FilePath(blob).data()); |
m_encoding = encoding; |
- readInternal(blob, FileReaderLoader::ReadAsText, ec); |
+ readInternal(blob, 0, FileReaderLoader::ReadAsText, ec); |
} |
void FileReader::readAsText(Blob* blob, ExceptionCode& ec) |
@@ -138,12 +143,22 @@ void FileReader::readAsDataURL(Blob* blob, ExceptionCode& ec) |
if (!blob) |
return; |
- LOG(FileAPI, "FileReader: reading as data URL: %s %s\n", utf8BlobURL(blob).data(), utf8FilePath(blob).data()); |
+ LOG(FileAPI, "FileReader: reading Blob as data URL: %s %s\n", utf8BlobURL(blob).data(), utf8FilePath(blob).data()); |
+ |
+ readInternal(blob, 0, FileReaderLoader::ReadAsDataURL, ec); |
+} |
+ |
+void FileReader::readAsArrayBuffer(Stream* stream, ExceptionCode& ec) |
+{ |
+ if (!stream) |
+ return; |
+ |
+ LOG(FileAPI, "FileReader: reading Stream as array buffer: %s\n", utf8BlobURL(stream).data()); |
- readInternal(blob, FileReaderLoader::ReadAsDataURL, ec); |
+ readInternal(0, stream, FileReaderLoader::ReadAsArrayBuffer, ec); |
} |
-void FileReader::readInternal(Blob* blob, FileReaderLoader::ReadType type, ExceptionCode& ec) |
+void FileReader::readInternal(Blob* blob, Stream* stream, FileReaderLoader::ReadType type, ExceptionCode& ec) |
{ |
// If multiple concurrent read methods are called on the same FileReader, InvalidStateError should be thrown when the state is LOADING. |
if (m_state == LOADING) { |
@@ -154,14 +169,25 @@ void FileReader::readInternal(Blob* blob, FileReaderLoader::ReadType type, Excep |
setPendingActivity(this); |
m_blob = blob; |
+ m_stream = stream; |
m_readType = type; |
m_state = LOADING; |
m_error = 0; |
m_loader = adoptPtr(new FileReaderLoader(m_readType, this)); |
m_loader->setEncoding(m_encoding); |
- m_loader->setDataType(m_blob->type()); |
- m_loader->start(scriptExecutionContext(), *m_blob); |
+ if (m_blob) { |
+ m_loader->setDataType(m_blob->type()); |
+ m_loader->start(scriptExecutionContext(), m_blob.get()); |
+ } else if (m_stream) { |
+ if (m_stream->isNeutered()) { |
+ ec = InvalidStateError; |
+ return; |
+ } |
+ stream->neuter(); |
+ m_loader->setDataType(m_stream->type()); |
+ m_loader->start(scriptExecutionContext(), m_stream.get()); |
+ } |
} |
static void delayedAbort(ScriptExecutionContext*, FileReader* reader) |
@@ -217,6 +243,9 @@ void FileReader::didReceiveData() |
{ |
// Fire the progress event at least every 50ms. |
double now = currentTimeMS(); |
+ |
+ LOG(FileAPI, "FileReader::didReceiveData %f", now); |
+ |
if (!m_lastProgressNotificationTimeMS) |
m_lastProgressNotificationTimeMS = now; |
else if (now - m_lastProgressNotificationTimeMS > progressNotificationIntervalMS) { |