summaryrefslogtreecommitdiff
path: root/Source/WebCore/fileapi
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-05-25 15:09:11 +0200
committerSimon Hausmann <simon.hausmann@nokia.com>2012-05-25 15:09:11 +0200
commita89b2ebb8e192c5e8cea21079bda2ee2c0c7dddd (patch)
treeb7abd9f49ae1d4d2e426a5883bfccd42b8e2ee12 /Source/WebCore/fileapi
parent8d473cf9743f1d30a16a27114e93bd5af5648d23 (diff)
downloadqtwebkit-a89b2ebb8e192c5e8cea21079bda2ee2c0c7dddd.tar.gz
Imported WebKit commit eb5c1b8fe4d4b1b90b5137433fc58a91da0e6878 (http://svn.webkit.org/repository/webkit/trunk@118516)
Diffstat (limited to 'Source/WebCore/fileapi')
-rw-r--r--Source/WebCore/fileapi/Blob.cpp8
-rw-r--r--Source/WebCore/fileapi/Blob.h2
-rw-r--r--Source/WebCore/fileapi/File.cpp12
-rw-r--r--Source/WebCore/fileapi/File.h12
-rw-r--r--Source/WebCore/fileapi/FileReader.cpp28
-rw-r--r--Source/WebCore/fileapi/FileReader.h1
-rw-r--r--Source/WebCore/fileapi/WebKitBlobBuilder.cpp2
7 files changed, 44 insertions, 21 deletions
diff --git a/Source/WebCore/fileapi/Blob.cpp b/Source/WebCore/fileapi/Blob.cpp
index 197a2618f..2385ec7d1 100644
--- a/Source/WebCore/fileapi/Blob.cpp
+++ b/Source/WebCore/fileapi/Blob.cpp
@@ -79,10 +79,10 @@ PassRefPtr<Blob> Blob::webkitSlice(long long start, long long end, const String&
// The modification time will be used to verify if the file has been changed or not, when the underlying data are accessed.
long long size;
double modificationTime;
- if (isFile())
+ if (isFile()) {
// FIXME: This involves synchronous file operation. We need to figure out how to make it asynchronous.
- static_cast<const File*>(this)->captureSnapshot(size, modificationTime);
- else {
+ toFile(this)->captureSnapshot(size, modificationTime);
+ } else {
ASSERT(m_size != -1);
size = m_size;
}
@@ -110,7 +110,7 @@ PassRefPtr<Blob> Blob::webkitSlice(long long start, long long end, const String&
OwnPtr<BlobData> blobData = BlobData::create();
blobData->setContentType(contentType);
if (isFile())
- blobData->appendFile(static_cast<const File*>(this)->path(), start, length, modificationTime);
+ blobData->appendFile(toFile(this)->path(), start, length, modificationTime);
else
blobData->appendBlob(m_internalURL, start, length);
diff --git a/Source/WebCore/fileapi/Blob.h b/Source/WebCore/fileapi/Blob.h
index f5f1852f8..9bc6234ac 100644
--- a/Source/WebCore/fileapi/Blob.h
+++ b/Source/WebCore/fileapi/Blob.h
@@ -82,7 +82,7 @@ protected:
// as an identifier for this blob. The internal URL is never used to source the blob's content
// into an HTML or for FileRead'ing, public blob URLs must be used for those purposes.
KURL m_internalURL;
-
+
String m_type;
long long m_size;
};
diff --git a/Source/WebCore/fileapi/File.cpp b/Source/WebCore/fileapi/File.cpp
index f2afa3454..098084807 100644
--- a/Source/WebCore/fileapi/File.cpp
+++ b/Source/WebCore/fileapi/File.cpp
@@ -169,13 +169,15 @@ void File::captureSnapshot(long long& snapshotSize, double& snapshotModification
// Obtains a snapshot of the file by capturing its current size and modification time. This is used when we slice a file for the first time.
// If we fail to retrieve the size or modification time, probably due to that the file has been deleted, 0 size is returned.
- // FIXME: Combine getFileSize and getFileModificationTime into one file system call.
- time_t modificationTime;
- if (!getFileSize(m_path, snapshotSize) || !getFileModificationTime(m_path, modificationTime)) {
+ FileMetadata metadata;
+ if (!getFileMetadata(m_path, metadata)) {
snapshotSize = 0;
snapshotModificationTime = 0;
- } else
- snapshotModificationTime = modificationTime;
+ return;
+ }
+
+ snapshotSize = metadata.length;
+ snapshotModificationTime = metadata.modificationTime;
}
} // namespace WebCore
diff --git a/Source/WebCore/fileapi/File.h b/Source/WebCore/fileapi/File.h
index 6331a2d49..e852c6adf 100644
--- a/Source/WebCore/fileapi/File.h
+++ b/Source/WebCore/fileapi/File.h
@@ -111,6 +111,18 @@ private:
#endif
};
+inline File* toFile(Blob* blob)
+{
+ ASSERT(!blob || blob->isFile());
+ return static_cast<File*>(blob);
+}
+
+inline const File* toFile(const Blob* blob)
+{
+ ASSERT(!blob || blob->isFile());
+ return static_cast<const File*>(blob);
+}
+
} // namespace WebCore
#endif // File_h
diff --git a/Source/WebCore/fileapi/FileReader.cpp b/Source/WebCore/fileapi/FileReader.cpp
index 07c4b6746..e05b1d971 100644
--- a/Source/WebCore/fileapi/FileReader.cpp
+++ b/Source/WebCore/fileapi/FileReader.cpp
@@ -74,11 +74,6 @@ const AtomicString& FileReader::interfaceName() const
return eventNames().interfaceForFileReader;
}
-bool FileReader::hasPendingActivity() const
-{
- return m_state == LOADING || ActiveDOMObject::hasPendingActivity();
-}
-
bool FileReader::canSuspend() const
{
// FIXME: It is not currently possible to suspend a FileReader, so pages with FileReader can not go into page cache.
@@ -95,7 +90,7 @@ void FileReader::readAsArrayBuffer(Blob* blob, ExceptionCode& ec)
if (!blob)
return;
- LOG(FileAPI, "FileReader: reading as array buffer: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? static_cast<File*>(blob)->path().utf8().data() : "");
+ LOG(FileAPI, "FileReader: reading as array buffer: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? toFile(blob)->path().utf8().data() : "");
readInternal(blob, FileReaderLoader::ReadAsArrayBuffer, ec);
}
@@ -105,7 +100,7 @@ void FileReader::readAsBinaryString(Blob* blob, ExceptionCode& ec)
if (!blob)
return;
- LOG(FileAPI, "FileReader: reading as binary: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? static_cast<File*>(blob)->path().utf8().data() : "");
+ LOG(FileAPI, "FileReader: reading as binary: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? toFile(blob)->path().utf8().data() : "");
readInternal(blob, FileReaderLoader::ReadAsBinaryString, ec);
}
@@ -115,7 +110,7 @@ void FileReader::readAsText(Blob* blob, const String& encoding, ExceptionCode& e
if (!blob)
return;
- LOG(FileAPI, "FileReader: reading as text: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? static_cast<File*>(blob)->path().utf8().data() : "");
+ LOG(FileAPI, "FileReader: reading as text: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? toFile(blob)->path().utf8().data() : "");
m_encoding = encoding;
readInternal(blob, FileReaderLoader::ReadAsText, ec);
@@ -131,7 +126,7 @@ void FileReader::readAsDataURL(Blob* blob, ExceptionCode& ec)
if (!blob)
return;
- LOG(FileAPI, "FileReader: reading as data URL: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? static_cast<File*>(blob)->path().utf8().data() : "");
+ LOG(FileAPI, "FileReader: reading as data URL: %s %s\n", blob->url().string().utf8().data(), blob->isFile() ? toFile(blob)->path().utf8().data() : "");
readInternal(blob, FileReaderLoader::ReadAsDataURL, ec);
}
@@ -144,6 +139,8 @@ void FileReader::readInternal(Blob* blob, FileReaderLoader::ReadType type, Excep
return;
}
+ setPendingActivity(this);
+
m_blob = blob;
m_readType = type;
m_state = LOADING;
@@ -175,6 +172,8 @@ void FileReader::abort()
void FileReader::doAbort()
{
+ ASSERT(m_state != DONE);
+
terminate();
m_aborting = false;
@@ -183,6 +182,9 @@ void FileReader::doAbort()
fireEvent(eventNames().errorEvent);
fireEvent(eventNames().abortEvent);
fireEvent(eventNames().loadendEvent);
+
+ // All possible events have fired and we're done, no more pending activity.
+ unsetPendingActivity(this);
}
void FileReader::terminate()
@@ -213,10 +215,14 @@ void FileReader::didReceiveData()
void FileReader::didFinishLoading()
{
+ ASSERT(m_state != DONE);
m_state = DONE;
fireEvent(eventNames().loadEvent);
fireEvent(eventNames().loadendEvent);
+
+ // All possible events have fired and we're done, no more pending activity.
+ unsetPendingActivity(this);
}
void FileReader::didFail(int errorCode)
@@ -225,11 +231,15 @@ void FileReader::didFail(int errorCode)
if (m_aborting)
return;
+ ASSERT(m_state != DONE);
m_state = DONE;
m_error = FileError::create(static_cast<FileError::ErrorCode>(errorCode));
fireEvent(eventNames().errorEvent);
fireEvent(eventNames().loadendEvent);
+
+ // All possible events have fired and we're done, no more pending activity.
+ unsetPendingActivity(this);
}
void FileReader::fireEvent(const AtomicString& type)
diff --git a/Source/WebCore/fileapi/FileReader.h b/Source/WebCore/fileapi/FileReader.h
index ecdd4856c..165c89278 100644
--- a/Source/WebCore/fileapi/FileReader.h
+++ b/Source/WebCore/fileapi/FileReader.h
@@ -79,7 +79,6 @@ public:
// ActiveDOMObject
virtual bool canSuspend() const;
virtual void stop();
- virtual bool hasPendingActivity() const;
// EventTarget
virtual const AtomicString& interfaceName() const;
diff --git a/Source/WebCore/fileapi/WebKitBlobBuilder.cpp b/Source/WebCore/fileapi/WebKitBlobBuilder.cpp
index a810ad8f5..e87bfe555 100644
--- a/Source/WebCore/fileapi/WebKitBlobBuilder.cpp
+++ b/Source/WebCore/fileapi/WebKitBlobBuilder.cpp
@@ -102,9 +102,9 @@ void WebKitBlobBuilder::append(Blob* blob)
if (!blob)
return;
if (blob->isFile()) {
+ File* file = toFile(blob);
// If the blob is file that is not snapshoted, capture the snapshot now.
// FIXME: This involves synchronous file operation. We need to figure out how to make it asynchronous.
- File* file = static_cast<File*>(blob);
long long snapshotSize;
double snapshotModificationTime;
file->captureSnapshot(snapshotSize, snapshotModificationTime);