summaryrefslogtreecommitdiff
path: root/Source/WebCore/fileapi
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/fileapi')
-rw-r--r--Source/WebCore/fileapi/AsyncFileWriter.h61
-rw-r--r--Source/WebCore/fileapi/AsyncFileWriterClient.h53
-rw-r--r--Source/WebCore/fileapi/Blob.cpp111
-rw-r--r--Source/WebCore/fileapi/Blob.h86
-rw-r--r--Source/WebCore/fileapi/Blob.idl47
-rw-r--r--Source/WebCore/fileapi/BlobURL.cpp76
-rw-r--r--Source/WebCore/fileapi/BlobURL.h64
-rw-r--r--Source/WebCore/fileapi/DOMFilePath.cpp154
-rw-r--r--Source/WebCore/fileapi/DOMFilePath.h86
-rw-r--r--Source/WebCore/fileapi/DOMFileSystem.cpp161
-rw-r--r--Source/WebCore/fileapi/DOMFileSystem.h109
-rw-r--r--Source/WebCore/fileapi/DOMFileSystem.idl41
-rw-r--r--Source/WebCore/fileapi/DOMFileSystemBase.cpp238
-rw-r--r--Source/WebCore/fileapi/DOMFileSystemBase.h102
-rw-r--r--Source/WebCore/fileapi/DOMFileSystemSync.cpp267
-rw-r--r--Source/WebCore/fileapi/DOMFileSystemSync.h71
-rw-r--r--Source/WebCore/fileapi/DOMFileSystemSync.idl39
-rw-r--r--Source/WebCore/fileapi/DirectoryEntry.cpp77
-rw-r--r--Source/WebCore/fileapi/DirectoryEntry.h71
-rw-r--r--Source/WebCore/fileapi/DirectoryEntry.idl43
-rw-r--r--Source/WebCore/fileapi/DirectoryEntrySync.cpp89
-rw-r--r--Source/WebCore/fileapi/DirectoryEntrySync.h69
-rw-r--r--Source/WebCore/fileapi/DirectoryEntrySync.idl43
-rw-r--r--Source/WebCore/fileapi/DirectoryReader.cpp59
-rw-r--r--Source/WebCore/fileapi/DirectoryReader.h67
-rw-r--r--Source/WebCore/fileapi/DirectoryReader.idl38
-rw-r--r--Source/WebCore/fileapi/DirectoryReaderBase.h68
-rw-r--r--Source/WebCore/fileapi/DirectoryReaderSync.cpp68
-rw-r--r--Source/WebCore/fileapi/DirectoryReaderSync.h64
-rw-r--r--Source/WebCore/fileapi/DirectoryReaderSync.idl38
-rw-r--r--Source/WebCore/fileapi/EntriesCallback.h52
-rw-r--r--Source/WebCore/fileapi/EntriesCallback.idl38
-rw-r--r--Source/WebCore/fileapi/Entry.cpp91
-rw-r--r--Source/WebCore/fileapi/Entry.h68
-rw-r--r--Source/WebCore/fileapi/Entry.idl50
-rw-r--r--Source/WebCore/fileapi/EntryArray.cpp51
-rw-r--r--Source/WebCore/fileapi/EntryArray.h67
-rw-r--r--Source/WebCore/fileapi/EntryArray.idl40
-rw-r--r--Source/WebCore/fileapi/EntryArraySync.cpp63
-rw-r--r--Source/WebCore/fileapi/EntryArraySync.h70
-rw-r--r--Source/WebCore/fileapi/EntryArraySync.idl40
-rw-r--r--Source/WebCore/fileapi/EntryBase.cpp84
-rw-r--r--Source/WebCore/fileapi/EntryBase.h76
-rw-r--r--Source/WebCore/fileapi/EntryCallback.h52
-rw-r--r--Source/WebCore/fileapi/EntryCallback.idl38
-rw-r--r--Source/WebCore/fileapi/EntrySync.cpp112
-rw-r--r--Source/WebCore/fileapi/EntrySync.h69
-rw-r--r--Source/WebCore/fileapi/EntrySync.idl50
-rw-r--r--Source/WebCore/fileapi/ErrorCallback.h52
-rw-r--r--Source/WebCore/fileapi/ErrorCallback.idl38
-rw-r--r--Source/WebCore/fileapi/File.cpp132
-rw-r--r--Source/WebCore/fileapi/File.h100
-rw-r--r--Source/WebCore/fileapi/File.idl46
-rw-r--r--Source/WebCore/fileapi/FileCallback.h51
-rw-r--r--Source/WebCore/fileapi/FileCallback.idl38
-rw-r--r--Source/WebCore/fileapi/FileEntry.cpp61
-rw-r--r--Source/WebCore/fileapi/FileEntry.h64
-rw-r--r--Source/WebCore/fileapi/FileEntry.idl41
-rw-r--r--Source/WebCore/fileapi/FileEntrySync.cpp58
-rw-r--r--Source/WebCore/fileapi/FileEntrySync.h67
-rw-r--r--Source/WebCore/fileapi/FileEntrySync.idl41
-rw-r--r--Source/WebCore/fileapi/FileError.h75
-rw-r--r--Source/WebCore/fileapi/FileError.idl53
-rw-r--r--Source/WebCore/fileapi/FileException.cpp90
-rw-r--r--Source/WebCore/fileapi/FileException.h85
-rw-r--r--Source/WebCore/fileapi/FileException.idl61
-rw-r--r--Source/WebCore/fileapi/FileList.cpp53
-rw-r--r--Source/WebCore/fileapi/FileList.h60
-rw-r--r--Source/WebCore/fileapi/FileList.idl36
-rw-r--r--Source/WebCore/fileapi/FileReader.cpp245
-rw-r--r--Source/WebCore/fileapi/FileReader.h138
-rw-r--r--Source/WebCore/fileapi/FileReader.idl81
-rw-r--r--Source/WebCore/fileapi/FileReaderLoader.cpp327
-rw-r--r--Source/WebCore/fileapi/FileReaderLoader.h118
-rw-r--r--Source/WebCore/fileapi/FileReaderLoaderClient.h52
-rw-r--r--Source/WebCore/fileapi/FileReaderSync.cpp101
-rw-r--r--Source/WebCore/fileapi/FileReaderSync.h76
-rw-r--r--Source/WebCore/fileapi/FileReaderSync.idl46
-rw-r--r--Source/WebCore/fileapi/FileStreamProxy.cpp225
-rw-r--r--Source/WebCore/fileapi/FileStreamProxy.h92
-rw-r--r--Source/WebCore/fileapi/FileSystemCallback.h52
-rw-r--r--Source/WebCore/fileapi/FileSystemCallback.idl38
-rw-r--r--Source/WebCore/fileapi/FileSystemCallbacks.cpp319
-rw-r--r--Source/WebCore/fileapi/FileSystemCallbacks.h173
-rw-r--r--Source/WebCore/fileapi/FileThread.cpp119
-rw-r--r--Source/WebCore/fileapi/FileThread.h89
-rw-r--r--Source/WebCore/fileapi/FileThreadTask.h227
-rw-r--r--Source/WebCore/fileapi/FileWriter.cpp286
-rw-r--r--Source/WebCore/fileapi/FileWriter.h135
-rw-r--r--Source/WebCore/fileapi/FileWriter.idl64
-rw-r--r--Source/WebCore/fileapi/FileWriterBase.cpp76
-rw-r--r--Source/WebCore/fileapi/FileWriterBase.h92
-rw-r--r--Source/WebCore/fileapi/FileWriterBaseCallback.h52
-rw-r--r--Source/WebCore/fileapi/FileWriterCallback.h52
-rw-r--r--Source/WebCore/fileapi/FileWriterCallback.idl38
-rw-r--r--Source/WebCore/fileapi/FileWriterSync.cpp148
-rw-r--r--Source/WebCore/fileapi/FileWriterSync.h79
-rw-r--r--Source/WebCore/fileapi/FileWriterSync.idl43
-rw-r--r--Source/WebCore/fileapi/LocalFileSystem.cpp99
-rw-r--r--Source/WebCore/fileapi/LocalFileSystem.h95
-rw-r--r--Source/WebCore/fileapi/Metadata.h68
-rw-r--r--Source/WebCore/fileapi/Metadata.idl38
-rw-r--r--Source/WebCore/fileapi/MetadataCallback.h52
-rw-r--r--Source/WebCore/fileapi/MetadataCallback.idl38
-rw-r--r--Source/WebCore/fileapi/OperationNotAllowedException.cpp68
-rw-r--r--Source/WebCore/fileapi/OperationNotAllowedException.h67
-rw-r--r--Source/WebCore/fileapi/OperationNotAllowedException.idl48
-rw-r--r--Source/WebCore/fileapi/SyncCallbackHelper.h188
-rw-r--r--Source/WebCore/fileapi/ThreadableBlobRegistry.cpp130
-rw-r--r--Source/WebCore/fileapi/ThreadableBlobRegistry.h50
-rw-r--r--Source/WebCore/fileapi/WebKitBlobBuilder.cpp136
-rw-r--r--Source/WebCore/fileapi/WebKitBlobBuilder.h69
-rw-r--r--Source/WebCore/fileapi/WebKitBlobBuilder.idl48
-rw-r--r--Source/WebCore/fileapi/WebKitFlags.h67
114 files changed, 9817 insertions, 0 deletions
diff --git a/Source/WebCore/fileapi/AsyncFileWriter.h b/Source/WebCore/fileapi/AsyncFileWriter.h
new file mode 100644
index 000000000..d6a28d5eb
--- /dev/null
+++ b/Source/WebCore/fileapi/AsyncFileWriter.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AsyncFileWriter_h
+#define AsyncFileWriter_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "PlatformString.h"
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class Blob;
+
+class AsyncFileWriter {
+public:
+ virtual ~AsyncFileWriter() {}
+
+ virtual void write(long long position, Blob* data) = 0;
+ virtual void truncate(long long length) = 0;
+ virtual void abort() = 0;
+ virtual bool waitForOperationToComplete() // Needed for FileWriterSync only.
+ {
+ return false;
+ }
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // AsyncFileWriter_h
+
diff --git a/Source/WebCore/fileapi/AsyncFileWriterClient.h b/Source/WebCore/fileapi/AsyncFileWriterClient.h
new file mode 100644
index 000000000..929f523fc
--- /dev/null
+++ b/Source/WebCore/fileapi/AsyncFileWriterClient.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AsyncFileWriterClient_h
+#define AsyncFileWriterClient_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "FileError.h"
+
+namespace WebCore {
+
+class AsyncFileWriterClient {
+public:
+ virtual ~AsyncFileWriterClient() {}
+
+ virtual void didWrite(long long bytes, bool complete) = 0;
+ virtual void didTruncate() = 0;
+ virtual void didFail(FileError::ErrorCode) = 0;
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // AsyncFileWriterClient_h
diff --git a/Source/WebCore/fileapi/Blob.cpp b/Source/WebCore/fileapi/Blob.cpp
new file mode 100644
index 000000000..3b33cd66d
--- /dev/null
+++ b/Source/WebCore/fileapi/Blob.cpp
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "Blob.h"
+
+#include "BlobURL.h"
+#include "File.h"
+#include "ThreadableBlobRegistry.h"
+
+namespace WebCore {
+
+Blob::Blob(PassOwnPtr<BlobData> blobData, long long size)
+ : m_type(blobData->contentType())
+ , m_size(size)
+{
+ ASSERT(blobData);
+
+ // Create a new internal URL and register it with the provided blob data.
+ m_internalURL = BlobURL::createInternalURL();
+ ThreadableBlobRegistry::registerBlobURL(m_internalURL, blobData);
+}
+
+Blob::Blob(const KURL& srcURL, const String& type, long long size)
+ : m_type(type)
+ , m_size(size)
+{
+ // Create a new internal URL and register it with the same blob data as the source URL.
+ m_internalURL = BlobURL::createInternalURL();
+ ThreadableBlobRegistry::registerBlobURL(m_internalURL, srcURL);
+}
+
+Blob::~Blob()
+{
+ ThreadableBlobRegistry::unregisterBlobURL(m_internalURL);
+}
+
+#if ENABLE(BLOB)
+PassRefPtr<Blob> Blob::webkitSlice(long long start, long long end, const String& contentType) const
+{
+ // When we slice a file for the first time, we obtain a snapshot of the file by capturing its current size and modification time.
+ // 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())
+ // 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 {
+ ASSERT(m_size != -1);
+ size = m_size;
+ }
+
+ // Convert the negative value that is used to select from the end.
+ if (start < 0)
+ start = start + size;
+ if (end < 0)
+ end = end + size;
+
+ // Clamp the range if it exceeds the size limit.
+ if (start < 0)
+ start = 0;
+ if (end < 0)
+ end = 0;
+ if (start >= size) {
+ start = 0;
+ end = 0;
+ } else if (end < start)
+ end = start;
+ else if (end > size)
+ end = size;
+
+ long long length = end - start;
+ OwnPtr<BlobData> blobData = BlobData::create();
+ blobData->setContentType(contentType);
+ if (isFile())
+ blobData->appendFile(static_cast<const File*>(this)->path(), start, length, modificationTime);
+ else
+ blobData->appendBlob(m_internalURL, start, length);
+
+ return Blob::create(blobData.release(), length);
+}
+#endif
+
+} // namespace WebCore
diff --git a/Source/WebCore/fileapi/Blob.h b/Source/WebCore/fileapi/Blob.h
new file mode 100644
index 000000000..bca939823
--- /dev/null
+++ b/Source/WebCore/fileapi/Blob.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef Blob_h
+#define Blob_h
+
+#include "BlobData.h"
+#include "KURL.h"
+#include "PlatformString.h"
+#include <wtf/PassOwnPtr.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class Blob : public RefCounted<Blob> {
+public:
+ static PassRefPtr<Blob> create(PassOwnPtr<BlobData> blobData, long long size)
+ {
+ return adoptRef(new Blob(blobData, size));
+ }
+
+ // For deserialization.
+ static PassRefPtr<Blob> create(const KURL& srcURL, const String& type, long long size)
+ {
+ return adoptRef(new Blob(srcURL, type, size));
+ }
+
+ virtual ~Blob();
+
+ const KURL& url() const { return m_internalURL; }
+ const String& type() const { return m_type; }
+
+ virtual unsigned long long size() const { return static_cast<unsigned long long>(m_size); }
+ virtual bool isFile() const { return false; }
+
+#if ENABLE(BLOB)
+ PassRefPtr<Blob> webkitSlice(long long start = 0, long long end = std::numeric_limits<long long>::max(), const String& contentType = String()) const;
+#endif
+
+protected:
+ Blob(PassOwnPtr<BlobData>, long long size);
+
+ // For deserialization.
+ Blob(const KURL& srcURL, const String& type, long long size);
+
+ // This is an internal URL referring to the blob data associated with this object. It serves
+ // 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;
+};
+
+} // namespace WebCore
+
+#endif // Blob_h
diff --git a/Source/WebCore/fileapi/Blob.idl b/Source/WebCore/fileapi/Blob.idl
new file mode 100644
index 000000000..e9b795911
--- /dev/null
+++ b/Source/WebCore/fileapi/Blob.idl
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module html {
+
+ interface [
+ GenerateIsReachable=Impl,
+ NoStaticTables
+ ] Blob {
+ readonly attribute unsigned long long size;
+ readonly attribute DOMString type;
+
+#if !defined(LANGUAGE_OBJECTIVE_C)
+#if defined(ENABLE_BLOB) && ENABLE_BLOB
+ Blob webkitSlice(in [Optional] long long start, in [Optional] long long end, in [Optional, ConvertUndefinedOrNullToNullString] DOMString contentType);
+#endif
+#endif
+ };
+
+}
diff --git a/Source/WebCore/fileapi/BlobURL.cpp b/Source/WebCore/fileapi/BlobURL.cpp
new file mode 100644
index 000000000..5d79141a5
--- /dev/null
+++ b/Source/WebCore/fileapi/BlobURL.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "BlobURL.h"
+
+#include "KURL.h"
+#include "PlatformString.h"
+#include "SecurityOrigin.h"
+#include "UUID.h"
+
+namespace WebCore {
+
+const char BlobURL::kBlobProtocol[] = "blob";
+
+KURL BlobURL::createPublicURL(SecurityOrigin* securityOrigin)
+{
+ ASSERT(securityOrigin);
+ return createBlobURL(securityOrigin->toString());
+}
+
+KURL BlobURL::createInternalURL()
+{
+ return createBlobURL("blobinternal://");
+}
+
+String BlobURL::getIdentifier(const KURL& url)
+{
+ ASSERT(url.protocolIs(kBlobProtocol));
+
+ unsigned startIndex = url.pathAfterLastSlash();
+ return url.string().substring(startIndex);
+}
+
+KURL BlobURL::createBlobURL(const String& originString)
+{
+ ASSERT(!originString.isEmpty());
+ if (originString == "null")
+ return KURL();
+ String urlString = kBlobProtocol;
+ urlString += ":";
+ urlString += encodeWithURLEscapeSequences(originString);
+ urlString += "/";
+ urlString += createCanonicalUUIDString();
+ return KURL(ParsedURLString, urlString);
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/fileapi/BlobURL.h b/Source/WebCore/fileapi/BlobURL.h
new file mode 100644
index 000000000..4ea59fefe
--- /dev/null
+++ b/Source/WebCore/fileapi/BlobURL.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BlobURL_h
+#define BlobURL_h
+
+#include "KURL.h"
+
+namespace WebCore {
+
+class SecurityOrigin;
+
+// Blob URLs are of the form
+// blob:%escaped_origin%/%UUID%
+// For public urls, the origin of the host page is encoded in the URL value to
+// allow easy lookup of the origin when security checks need to be performed.
+// When loading blobs via ResourceHandle or when reading blobs via FileReader
+// the loader conducts security checks that examine the origin of host page
+// encoded in the public blob url. The origin baked into internal blob urls
+// is a simple constant value, "blobinternal://", internal urls should not
+// be used with ResourceHandle or FileReader.
+class BlobURL {
+public:
+ static KURL createPublicURL(SecurityOrigin*);
+ static KURL createInternalURL();
+ static String getIdentifier(const KURL&);
+ static const char* blobProtocol() { return kBlobProtocol; }
+
+private:
+ static KURL createBlobURL(const String& originString);
+ static const char kBlobProtocol[];
+ BlobURL() { }
+};
+
+}
+
+#endif // BlobURL_h
diff --git a/Source/WebCore/fileapi/DOMFilePath.cpp b/Source/WebCore/fileapi/DOMFilePath.cpp
new file mode 100644
index 000000000..90412469d
--- /dev/null
+++ b/Source/WebCore/fileapi/DOMFilePath.cpp
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DOMFilePath.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "RegularExpression.h"
+#include <wtf/Vector.h>
+#include <wtf/text/CString.h>
+
+namespace WebCore {
+
+const char DOMFilePath::separator = '/';
+const char DOMFilePath::root[] = "/";
+
+String DOMFilePath::append(const String& base, const String& components)
+{
+ return ensureDirectoryPath(base) + components;
+}
+
+String DOMFilePath::ensureDirectoryPath(const String& path)
+{
+ if (!DOMFilePath::endsWithSeparator(path)) {
+ String newPath = path;
+ newPath.append(DOMFilePath::separator);
+ return newPath;
+ }
+ return path;
+}
+
+String DOMFilePath::getName(const String& path)
+{
+ int index = path.reverseFind(DOMFilePath::separator);
+ if (index != -1)
+ return path.substring(index + 1);
+ return path;
+}
+
+String DOMFilePath::getDirectory(const String& path)
+{
+ int index = path.reverseFind(DOMFilePath::separator);
+ if (index == 0)
+ return DOMFilePath::root;
+ if (index != -1)
+ return path.substring(0, index);
+ return ".";
+}
+
+bool DOMFilePath::isParentOf(const String& parent, const String& mayBeChild)
+{
+ ASSERT(DOMFilePath::isAbsolute(parent));
+ ASSERT(DOMFilePath::isAbsolute(mayBeChild));
+ if (parent == DOMFilePath::root && mayBeChild != DOMFilePath::root)
+ return true;
+ if (parent.length() >= mayBeChild.length() || !mayBeChild.startsWith(parent, false))
+ return false;
+ if (mayBeChild[parent.length()] != DOMFilePath::separator)
+ return false;
+ return true;
+}
+
+String DOMFilePath::removeExtraParentReferences(const String& path)
+{
+ ASSERT(DOMFilePath::isAbsolute(path));
+ Vector<String> components;
+ Vector<String> canonicalized;
+ path.split(DOMFilePath::separator, components);
+ for (size_t i = 0; i < components.size(); ++i) {
+ if (components[i] == ".")
+ continue;
+ if (components[i] == "..") {
+ if (canonicalized.size() > 0)
+ canonicalized.removeLast();
+ continue;
+ }
+ canonicalized.append(components[i]);
+ }
+ if (canonicalized.isEmpty())
+ return DOMFilePath::root;
+ String result;
+ for (size_t i = 0; i < canonicalized.size(); ++i) {
+ result.append(DOMFilePath::separator);
+ result.append(canonicalized[i]);
+ }
+ return result;
+}
+
+bool DOMFilePath::isValidPath(const String& path)
+{
+ if (path.isEmpty() || path == DOMFilePath::root)
+ return true;
+
+ // Embedded NULs are not allowed.
+ if (path.find(static_cast<UChar>(0)) != WTF::notFound)
+ return false;
+
+ // While not [yet] restricted by the spec, '\\' complicates implementation for Chromium.
+ if (path.find('\\') != WTF::notFound)
+ return false;
+
+ // This method is only called on fully-evaluated absolute paths. Any sign of ".." or "." is likely an attempt to break out of the sandbox.
+ Vector<String> components;
+ path.split(DOMFilePath::separator, components);
+ for (size_t i = 0; i < components.size(); ++i) {
+ if (components[i] == ".")
+ return false;
+ if (components[i] == "..")
+ return false;
+ }
+ return true;
+}
+
+bool DOMFilePath::isValidName(const String& name)
+{
+ if (name.isEmpty())
+ return true;
+ // '/' is not allowed in name.
+ if (name.contains('/'))
+ return false;
+ return isValidPath(name);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/DOMFilePath.h b/Source/WebCore/fileapi/DOMFilePath.h
new file mode 100644
index 000000000..2f2bb2338
--- /dev/null
+++ b/Source/WebCore/fileapi/DOMFilePath.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DOMFilePath_h
+#define DOMFilePath_h
+
+#include "PlatformString.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+// DOMFileSystem path utilities. All methods in this class are static.
+class DOMFilePath {
+public:
+ static const char separator;
+ static const char root[];
+
+ // Returns the name part from the given path.
+ static String getName(const String& path);
+
+ // Returns the parent directory path of the given path.
+ static String getDirectory(const String& path);
+
+ // Checks if a given path is a parent of mayBeChild. This method assumes given paths are absolute and do not have extra references to a parent (i.e. "../").
+ static bool isParentOf(const String& path, const String& mayBeChild);
+
+ // Appends the separator at the end of the path if it's not there already.
+ static String ensureDirectoryPath(const String& path);
+
+ // Returns a new path by appending a separator and the supplied path component to the path.
+ static String append(const String& path, const String& component);
+
+ static bool isAbsolute(const String& path)
+ {
+ return path.startsWith(DOMFilePath::root);
+ }
+
+ static bool endsWithSeparator(const String& path)
+ {
+ return path[path.length() - 1] == DOMFilePath::separator;
+ }
+
+ // Evaluates all "../" and "./" segments. Note that "/../" expands to "/", so you can't ever refer to anything above the root directory.
+ static String removeExtraParentReferences(const String& path);
+
+ // Checks if the given path follows the FileSystem API naming restrictions.
+ static bool isValidPath(const String& path);
+
+ // Checks if the given name follows the FileSystem API naming restrictions.
+ static bool isValidName(const String& name);
+
+private:
+ DOMFilePath() { }
+};
+
+} // namespace WebCore
+
+#endif // DOMFilePath_h
diff --git a/Source/WebCore/fileapi/DOMFileSystem.cpp b/Source/WebCore/fileapi/DOMFileSystem.cpp
new file mode 100644
index 000000000..ac386903b
--- /dev/null
+++ b/Source/WebCore/fileapi/DOMFileSystem.cpp
@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DOMFileSystem.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "AsyncFileSystem.h"
+#include "DOMFilePath.h"
+#include "DirectoryEntry.h"
+#include "ErrorCallback.h"
+#include "File.h"
+#include "FileCallback.h"
+#include "FileEntry.h"
+#include "FileMetadata.h"
+#include "FileSystemCallbacks.h"
+#include "FileWriter.h"
+#include "FileWriterBaseCallback.h"
+#include "FileWriterCallback.h"
+#include "InspectorFileSystemInstrumentation.h"
+#include "MetadataCallback.h"
+#include "ScriptExecutionContext.h"
+#include <wtf/OwnPtr.h>
+
+namespace WebCore {
+
+// static
+PassRefPtr<DOMFileSystem> DOMFileSystem::create(ScriptExecutionContext* context, const String& name, PassOwnPtr<AsyncFileSystem> asyncFileSystem)
+{
+ RefPtr<DOMFileSystem> fileSystem(adoptRef(new DOMFileSystem(context, name, asyncFileSystem)));
+ InspectorInstrumentation::didOpenFileSystem(fileSystem.get());
+ return fileSystem;
+}
+
+DOMFileSystem::DOMFileSystem(ScriptExecutionContext* context, const String& name, PassOwnPtr<AsyncFileSystem> asyncFileSystem)
+ : DOMFileSystemBase(context, name, asyncFileSystem)
+ , ActiveDOMObject(context, this)
+{
+}
+
+PassRefPtr<DirectoryEntry> DOMFileSystem::root()
+{
+ return DirectoryEntry::create(this, DOMFilePath::root);
+}
+
+void DOMFileSystem::stop()
+{
+ m_asyncFileSystem->stop();
+}
+
+bool DOMFileSystem::hasPendingActivity() const
+{
+ return m_asyncFileSystem->hasPendingActivity();
+}
+
+void DOMFileSystem::contextDestroyed()
+{
+ m_asyncFileSystem->stop();
+ ActiveDOMObject::contextDestroyed();
+}
+
+namespace {
+
+class ConvertToFileWriterCallback : public FileWriterBaseCallback {
+public:
+ static PassRefPtr<ConvertToFileWriterCallback> create(PassRefPtr<FileWriterCallback> callback)
+ {
+ return adoptRef(new ConvertToFileWriterCallback(callback));
+ }
+
+ bool handleEvent(FileWriterBase* fileWriterBase)
+ {
+ return m_callback->handleEvent(static_cast<FileWriter*>(fileWriterBase));
+ }
+private:
+ ConvertToFileWriterCallback(PassRefPtr<FileWriterCallback> callback)
+ : m_callback(callback)
+ {
+ }
+ RefPtr<FileWriterCallback> m_callback;
+};
+
+}
+
+void DOMFileSystem::createWriter(const FileEntry* fileEntry, PassRefPtr<FileWriterCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ ASSERT(fileEntry);
+
+ RefPtr<FileWriter> fileWriter = FileWriter::create(scriptExecutionContext());
+ RefPtr<FileWriterBaseCallback> conversionCallback = ConvertToFileWriterCallback::create(successCallback);
+ OwnPtr<FileWriterBaseCallbacks> callbacks = FileWriterBaseCallbacks::create(fileWriter, conversionCallback, errorCallback);
+ m_asyncFileSystem->createWriter(fileWriter.get(), fileEntry->fullPath(), callbacks.release());
+}
+
+namespace {
+
+class GetPathCallback : public FileSystemCallbacksBase {
+public:
+ static PassOwnPtr<GetPathCallback> create(PassRefPtr<DOMFileSystem> filesystem, const String& name, PassRefPtr<FileCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+ {
+ return adoptPtr(new GetPathCallback(filesystem, name, successCallback, errorCallback));
+ }
+
+ virtual void didReadMetadata(const FileMetadata& metadata)
+ {
+ ASSERT(!metadata.platformPath.isEmpty());
+ m_filesystem->scheduleCallback(m_successCallback.release(), File::createWithName(metadata.platformPath, m_name));
+ }
+
+private:
+ GetPathCallback(PassRefPtr<DOMFileSystem> filesystem, const String& name, PassRefPtr<FileCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+ : FileSystemCallbacksBase(errorCallback)
+ , m_filesystem(filesystem)
+ , m_name(name)
+ , m_successCallback(successCallback)
+ {
+ }
+
+ RefPtr<DOMFileSystem> m_filesystem;
+ String m_name;
+ RefPtr<FileCallback> m_successCallback;
+};
+
+} // namespace
+
+void DOMFileSystem::createFile(const FileEntry* fileEntry, PassRefPtr<FileCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ m_asyncFileSystem->readMetadata(fileEntry->fullPath(), GetPathCallback::create(this, fileEntry->name(), successCallback, errorCallback));
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/DOMFileSystem.h b/Source/WebCore/fileapi/DOMFileSystem.h
new file mode 100644
index 000000000..74fa9ac18
--- /dev/null
+++ b/Source/WebCore/fileapi/DOMFileSystem.h
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DOMFileSystem_h
+#define DOMFileSystem_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "ActiveDOMObject.h"
+#include "DOMFileSystemBase.h"
+#include "ScriptExecutionContext.h"
+
+namespace WebCore {
+
+class DirectoryEntry;
+class File;
+class FileCallback;
+class FileEntry;
+class FileWriterCallback;
+
+class DOMFileSystem : public DOMFileSystemBase, public ActiveDOMObject {
+public:
+ static PassRefPtr<DOMFileSystem> create(ScriptExecutionContext*, const String& name, PassOwnPtr<AsyncFileSystem>);
+
+ PassRefPtr<DirectoryEntry> root();
+
+ // ActiveDOMObject methods.
+ virtual void stop();
+ virtual bool hasPendingActivity() const;
+ virtual void contextDestroyed();
+
+ void createWriter(const FileEntry*, PassRefPtr<FileWriterCallback>, PassRefPtr<ErrorCallback>);
+ void createFile(const FileEntry*, PassRefPtr<FileCallback>, PassRefPtr<ErrorCallback>);
+
+ // Schedule a callback. This should not cross threads (should be called on the same context thread).
+ // FIXME: move this to a more generic place.
+ template <typename CB, typename CBArg>
+ static void scheduleCallback(ScriptExecutionContext*, PassRefPtr<CB>, PassRefPtr<CBArg>);
+
+ template <typename CB, typename CBArg>
+ void scheduleCallback(PassRefPtr<CB> callback, PassRefPtr<CBArg> callbackArg)
+ {
+ scheduleCallback(scriptExecutionContext(), callback, callbackArg);
+ }
+
+private:
+ DOMFileSystem(ScriptExecutionContext*, const String& name, PassOwnPtr<AsyncFileSystem>);
+
+ // A helper template to schedule a callback task.
+ template <typename CB, typename CBArg>
+ class DispatchCallbackTask : public ScriptExecutionContext::Task {
+ public:
+ DispatchCallbackTask(PassRefPtr<CB> callback, PassRefPtr<CBArg> arg)
+ : m_callback(callback)
+ , m_callbackArg(arg)
+ {
+ }
+
+ virtual void performTask(ScriptExecutionContext*)
+ {
+ m_callback->handleEvent(m_callbackArg.get());
+ }
+
+ private:
+ RefPtr<CB> m_callback;
+ RefPtr<CBArg> m_callbackArg;
+ };
+};
+
+template <typename CB, typename CBArg>
+void DOMFileSystem::scheduleCallback(ScriptExecutionContext* scriptExecutionContext, PassRefPtr<CB> callback, PassRefPtr<CBArg> arg)
+{
+ ASSERT(scriptExecutionContext->isContextThread());
+ if (callback)
+ scriptExecutionContext->postTask(adoptPtr(new DispatchCallbackTask<CB, CBArg>(callback, arg)));
+}
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // DOMFileSystem_h
diff --git a/Source/WebCore/fileapi/DOMFileSystem.idl b/Source/WebCore/fileapi/DOMFileSystem.idl
new file mode 100644
index 000000000..e7cdf7023
--- /dev/null
+++ b/Source/WebCore/fileapi/DOMFileSystem.idl
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module storage {
+ interface [
+ Conditional=FILE_SYSTEM,
+ ActiveDOMObject,
+ NoStaticTables
+ ] DOMFileSystem {
+ readonly attribute DOMString name;
+ readonly attribute DirectoryEntry root;
+ };
+}
diff --git a/Source/WebCore/fileapi/DOMFileSystemBase.cpp b/Source/WebCore/fileapi/DOMFileSystemBase.cpp
new file mode 100644
index 000000000..ec8ef725a
--- /dev/null
+++ b/Source/WebCore/fileapi/DOMFileSystemBase.cpp
@@ -0,0 +1,238 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DOMFileSystemBase.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "DOMFilePath.h"
+#include "DirectoryEntry.h"
+#include "DirectoryReaderBase.h"
+#include "EntriesCallback.h"
+#include "EntryArray.h"
+#include "EntryBase.h"
+#include "EntryCallback.h"
+#include "ErrorCallback.h"
+#include "FileError.h"
+#include "FileSystemCallbacks.h"
+#include "MetadataCallback.h"
+#include "ScriptExecutionContext.h"
+#include "VoidCallback.h"
+#include <wtf/OwnPtr.h>
+
+namespace WebCore {
+
+const char DOMFileSystemBase::kPersistentPathPrefix[] = "persistent";
+const size_t DOMFileSystemBase::kPersistentPathPrefixLength = sizeof(DOMFileSystemBase::kPersistentPathPrefix) - 1;
+const char DOMFileSystemBase::kTemporaryPathPrefix[] = "temporary";
+const size_t DOMFileSystemBase::kTemporaryPathPrefixLength = sizeof(DOMFileSystemBase::kTemporaryPathPrefix) - 1;
+const char DOMFileSystemBase::kExternalPathPrefix[] = "external";
+const size_t DOMFileSystemBase::kExternalPathPrefixLength = sizeof(DOMFileSystemBase::kExternalPathPrefix) - 1;
+
+bool DOMFileSystemBase::crackFileSystemURL(const KURL& url, AsyncFileSystem::Type& type, String& filePath)
+{
+ if (!url.protocolIs("filesystem"))
+ return false;
+
+ KURL originURL(ParsedURLString, url.path());
+ String path = decodeURLEscapeSequences(originURL.path());
+ if (path.isEmpty() || path[0] != '/')
+ return false;
+ path = path.substring(1);
+
+ if (path.startsWith(kTemporaryPathPrefix)) {
+ type = AsyncFileSystem::Temporary;
+ path = path.substring(kTemporaryPathPrefixLength);
+ } else if (path.startsWith(kPersistentPathPrefix)) {
+ type = AsyncFileSystem::Persistent;
+ path = path.substring(kPersistentPathPrefixLength);
+ } else if (path.startsWith(kExternalPathPrefix)) {
+ type = AsyncFileSystem::External;
+ path = path.substring(kExternalPathPrefixLength);
+ } else
+ return false;
+
+ if (path.isEmpty() || path[0] != '/')
+ return false;
+
+ filePath.swap(path);
+ return true;
+}
+
+DOMFileSystemBase::DOMFileSystemBase(ScriptExecutionContext* context, const String& name, PassOwnPtr<AsyncFileSystem> asyncFileSystem)
+ : m_context(context)
+ , m_name(name)
+ , m_asyncFileSystem(asyncFileSystem)
+{
+}
+
+DOMFileSystemBase::~DOMFileSystemBase()
+{
+}
+
+SecurityOrigin* DOMFileSystemBase::securityOrigin() const
+{
+ return m_context->securityOrigin();
+}
+
+bool DOMFileSystemBase::getMetadata(const EntryBase* entry, PassRefPtr<MetadataCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ m_asyncFileSystem->readMetadata(entry->fullPath(), MetadataCallbacks::create(successCallback, errorCallback));
+ return true;
+}
+
+static bool verifyAndGetDestinationPathForCopyOrMove(const EntryBase* source, EntryBase* parent, const String& newName, String& destinationPath)
+{
+ ASSERT(source);
+
+ if (!parent || !parent->isDirectory())
+ return false;
+
+ if (!newName.isEmpty() && !DOMFilePath::isValidName(newName))
+ return false;
+
+ // It is an error to try to copy or move an entry inside itself at any depth if it is a directory.
+ if (source->isDirectory() && DOMFilePath::isParentOf(source->fullPath(), parent->fullPath()))
+ return false;
+
+ // It is an error to copy or move an entry into its parent if a name different from its current one isn't provided.
+ if ((newName.isEmpty() || source->name() == newName) && DOMFilePath::getDirectory(source->fullPath()) == parent->fullPath())
+ return false;
+
+ destinationPath = parent->fullPath();
+ if (!newName.isEmpty())
+ destinationPath = DOMFilePath::append(destinationPath, newName);
+ else
+ destinationPath = DOMFilePath::append(destinationPath, source->name());
+
+ return true;
+}
+
+static bool pathToAbsolutePath(AsyncFileSystem::Type type, const EntryBase* base, String path, String& absolutePath)
+{
+ ASSERT(base);
+
+ if (!DOMFilePath::isAbsolute(path))
+ path = DOMFilePath::append(base->fullPath(), path);
+ absolutePath = DOMFilePath::removeExtraParentReferences(path);
+
+ if ((type == AsyncFileSystem::Temporary || type == AsyncFileSystem::Persistent) && !DOMFilePath::isValidPath(absolutePath))
+ return false;
+ return true;
+}
+
+bool DOMFileSystemBase::move(const EntryBase* source, EntryBase* parent, const String& newName, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ String destinationPath;
+ if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, destinationPath))
+ return false;
+
+ m_asyncFileSystem->move(source->fullPath(), destinationPath, EntryCallbacks::create(successCallback, errorCallback, this, destinationPath, source->isDirectory()));
+ return true;
+}
+
+bool DOMFileSystemBase::copy(const EntryBase* source, EntryBase* parent, const String& newName, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ String destinationPath;
+ if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, destinationPath))
+ return false;
+
+ m_asyncFileSystem->copy(source->fullPath(), destinationPath, EntryCallbacks::create(successCallback, errorCallback, this, destinationPath, source->isDirectory()));
+ return true;
+}
+
+bool DOMFileSystemBase::remove(const EntryBase* entry, PassRefPtr<VoidCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ ASSERT(entry);
+ // We don't allow calling remove() on the root directory.
+ if (entry->fullPath() == String(DOMFilePath::root))
+ return false;
+ m_asyncFileSystem->remove(entry->fullPath(), VoidCallbacks::create(successCallback, errorCallback));
+ return true;
+}
+
+bool DOMFileSystemBase::removeRecursively(const EntryBase* entry, PassRefPtr<VoidCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ ASSERT(entry && entry->isDirectory());
+ // We don't allow calling remove() on the root directory.
+ if (entry->fullPath() == String(DOMFilePath::root))
+ return false;
+ m_asyncFileSystem->removeRecursively(entry->fullPath(), VoidCallbacks::create(successCallback, errorCallback));
+ return true;
+}
+
+bool DOMFileSystemBase::getParent(const EntryBase* entry, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ ASSERT(entry);
+ String path = DOMFilePath::getDirectory(entry->fullPath());
+
+ m_asyncFileSystem->directoryExists(path, EntryCallbacks::create(successCallback, errorCallback, this, path, true));
+ return true;
+}
+
+bool DOMFileSystemBase::getFile(const EntryBase* entry, const String& path, PassRefPtr<WebKitFlags> flags, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ String absolutePath;
+ if (!pathToAbsolutePath(m_asyncFileSystem->type(), entry, path, absolutePath))
+ return false;
+
+ OwnPtr<EntryCallbacks> callbacks = EntryCallbacks::create(successCallback, errorCallback, this, absolutePath, false);
+ if (flags && flags->isCreate())
+ m_asyncFileSystem->createFile(absolutePath, flags->isExclusive(), callbacks.release());
+ else
+ m_asyncFileSystem->fileExists(absolutePath, callbacks.release());
+ return true;
+}
+
+bool DOMFileSystemBase::getDirectory(const EntryBase* entry, const String& path, PassRefPtr<WebKitFlags> flags, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ String absolutePath;
+ if (!pathToAbsolutePath(m_asyncFileSystem->type(), entry, path, absolutePath))
+ return false;
+
+ OwnPtr<EntryCallbacks> callbacks = EntryCallbacks::create(successCallback, errorCallback, this, absolutePath, true);
+ if (flags && flags->isCreate())
+ m_asyncFileSystem->createDirectory(absolutePath, flags->isExclusive(), callbacks.release());
+ else
+ m_asyncFileSystem->directoryExists(absolutePath, callbacks.release());
+ return true;
+}
+
+bool DOMFileSystemBase::readDirectory(PassRefPtr<DirectoryReaderBase> reader, const String& path, PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ ASSERT(DOMFilePath::isAbsolute(path));
+ m_asyncFileSystem->readDirectory(path, EntriesCallbacks::create(successCallback, errorCallback, reader, path));
+ return true;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/DOMFileSystemBase.h b/Source/WebCore/fileapi/DOMFileSystemBase.h
new file mode 100644
index 000000000..8bc0b6579
--- /dev/null
+++ b/Source/WebCore/fileapi/DOMFileSystemBase.h
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DOMFileSystemBase_h
+#define DOMFileSystemBase_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "AsyncFileSystem.h"
+#include "WebKitFlags.h"
+#include "PlatformString.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class DirectoryEntry;
+class DirectoryReaderBase;
+class EntriesCallback;
+class EntryBase;
+class EntryCallback;
+class ErrorCallback;
+class KURL;
+class MetadataCallback;
+class ScriptExecutionContext;
+class SecurityOrigin;
+class VoidCallback;
+
+// A common base class for DOMFileSystem and DOMFileSystemSync.
+class DOMFileSystemBase : public RefCounted<DOMFileSystemBase> {
+public:
+ static PassRefPtr<DOMFileSystemBase> create(ScriptExecutionContext* context, const String& name, PassOwnPtr<AsyncFileSystem> asyncFileSystem)
+ {
+ return adoptRef(new DOMFileSystemBase(context, name, asyncFileSystem));
+ }
+ virtual ~DOMFileSystemBase();
+
+ static const char kPersistentPathPrefix[];
+ static const size_t kPersistentPathPrefixLength;
+ static const char kTemporaryPathPrefix[];
+ static const size_t kTemporaryPathPrefixLength;
+ static const char kExternalPathPrefix[];
+ static const size_t kExternalPathPrefixLength;
+ static bool crackFileSystemURL(const KURL&, AsyncFileSystem::Type&, String& filePath);
+
+ const String& name() const { return m_name; }
+ AsyncFileSystem* asyncFileSystem() const { return m_asyncFileSystem.get(); }
+ SecurityOrigin* securityOrigin() const;
+
+ // Actual FileSystem API implementations. All the validity checks on virtual paths are done at this level.
+ // They return false for immediate errors that don't involve lower AsyncFileSystem layer (e.g. for name validation errors). Otherwise they return true (but later may call back with an runtime error).
+ bool getMetadata(const EntryBase*, PassRefPtr<MetadataCallback>, PassRefPtr<ErrorCallback>);
+ bool move(const EntryBase* source, EntryBase* parent, const String& name, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>);
+ bool copy(const EntryBase* source, EntryBase* parent, const String& name, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>);
+ bool remove(const EntryBase*, PassRefPtr<VoidCallback>, PassRefPtr<ErrorCallback>);
+ bool removeRecursively(const EntryBase*, PassRefPtr<VoidCallback>, PassRefPtr<ErrorCallback>);
+ bool getParent(const EntryBase*, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>);
+ bool getFile(const EntryBase*, const String& path, PassRefPtr<WebKitFlags>, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>);
+ bool getDirectory(const EntryBase*, const String& path, PassRefPtr<WebKitFlags>, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>);
+ bool readDirectory(PassRefPtr<DirectoryReaderBase>, const String& path, PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>);
+
+protected:
+ DOMFileSystemBase(ScriptExecutionContext*, const String& name, PassOwnPtr<AsyncFileSystem>);
+ friend class DOMFileSystemSync;
+
+ ScriptExecutionContext* m_context;
+ String m_name;
+ mutable OwnPtr<AsyncFileSystem> m_asyncFileSystem;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // DOMFileSystemBase_h
diff --git a/Source/WebCore/fileapi/DOMFileSystemSync.cpp b/Source/WebCore/fileapi/DOMFileSystemSync.cpp
new file mode 100644
index 000000000..e7a8ca70b
--- /dev/null
+++ b/Source/WebCore/fileapi/DOMFileSystemSync.cpp
@@ -0,0 +1,267 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DOMFileSystemSync.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "AsyncFileSystem.h"
+#include "AsyncFileWriter.h"
+#include "DOMFilePath.h"
+#include "DirectoryEntrySync.h"
+#include "ErrorCallback.h"
+#include "File.h"
+#include "FileEntrySync.h"
+#include "FileError.h"
+#include "FileException.h"
+#include "FileMetadata.h"
+#include "FileSystemCallbacks.h"
+#include "FileWriterBaseCallback.h"
+#include "FileWriterSync.h"
+
+namespace WebCore {
+
+class FileWriterBase;
+
+PassRefPtr<DOMFileSystemSync> DOMFileSystemSync::create(DOMFileSystemBase* fileSystem)
+{
+ return adoptRef(new DOMFileSystemSync(fileSystem->m_context, fileSystem->m_name, fileSystem->m_asyncFileSystem.release()));
+}
+
+DOMFileSystemSync::DOMFileSystemSync(ScriptExecutionContext* context, const String& name, PassOwnPtr<AsyncFileSystem> asyncFileSystem)
+ : DOMFileSystemBase(context, name, asyncFileSystem)
+{
+}
+
+DOMFileSystemSync::~DOMFileSystemSync()
+{
+}
+
+PassRefPtr<DirectoryEntrySync> DOMFileSystemSync::root()
+{
+ return DirectoryEntrySync::create(this, DOMFilePath::root);
+}
+
+namespace {
+
+class GetPathHelper : public AsyncFileSystemCallbacks {
+public:
+ class GetPathResult : public RefCounted<GetPathResult> {
+ public:
+ static PassRefPtr<GetPathResult> create()
+ {
+ return adoptRef(new GetPathResult());
+ }
+
+ bool m_failed;
+ int m_code;
+ String m_path;
+
+ private:
+ GetPathResult()
+ : m_failed(false)
+ , m_code(0)
+ {
+ }
+
+ ~GetPathResult()
+ {
+ }
+ friend class WTF::RefCounted<GetPathResult>;
+ };
+
+ static PassOwnPtr<GetPathHelper> create(PassRefPtr<GetPathResult> result)
+ {
+ return adoptPtr(new GetPathHelper(result));
+ }
+
+ virtual void didSucceed()
+ {
+ ASSERT_NOT_REACHED();
+ }
+
+ virtual void didOpenFileSystem(const String&, PassOwnPtr<AsyncFileSystem>)
+ {
+ ASSERT_NOT_REACHED();
+ }
+
+ virtual void didReadDirectoryEntry(const String&, bool)
+ {
+ ASSERT_NOT_REACHED();
+ }
+
+ virtual void didReadDirectoryEntries(bool)
+ {
+ ASSERT_NOT_REACHED();
+ }
+
+ virtual void didCreateFileWriter(PassOwnPtr<AsyncFileWriter>, long long)
+ {
+ ASSERT_NOT_REACHED();
+ }
+
+ virtual void didFail(int code)
+ {
+ m_result->m_failed = true;
+ m_result->m_code = code;
+ }
+
+ virtual ~GetPathHelper()
+ {
+ }
+
+ void didReadMetadata(const FileMetadata& metadata)
+ {
+ m_result->m_path = metadata.platformPath;
+ }
+private:
+ GetPathHelper(PassRefPtr<GetPathResult> result)
+ : m_result(result)
+ {
+ }
+
+ RefPtr<GetPathResult> m_result;
+};
+
+} // namespace
+
+PassRefPtr<File> DOMFileSystemSync::createFile(const FileEntrySync* fileEntry, ExceptionCode& ec)
+{
+ ec = 0;
+ RefPtr<GetPathHelper::GetPathResult> result(GetPathHelper::GetPathResult::create());
+ m_asyncFileSystem->readMetadata(fileEntry->fullPath(), GetPathHelper::create(result));
+ if (!m_asyncFileSystem->waitForOperationToComplete()) {
+ ec = FileException::ABORT_ERR;
+ return 0;
+ }
+ if (result->m_failed) {
+ ec = result->m_code;
+ return 0;
+ }
+ ASSERT(!result->m_path.isEmpty());
+ return File::createWithName(result->m_path, fileEntry->name());
+}
+
+namespace {
+
+class ReceiveFileWriterCallback : public FileWriterBaseCallback {
+public:
+ static PassRefPtr<ReceiveFileWriterCallback> create()
+ {
+ return adoptRef(new ReceiveFileWriterCallback());
+ }
+
+ bool handleEvent(FileWriterBase* fileWriterBase)
+ {
+#ifndef NDEBUG
+ m_fileWriterBase = fileWriterBase;
+#else
+ ASSERT_UNUSED(fileWriterBase, fileWriterBase);
+#endif
+ return true;
+ }
+
+#ifndef NDEBUG
+ FileWriterBase* fileWriterBase()
+ {
+ return m_fileWriterBase;
+ }
+#endif
+
+private:
+ ReceiveFileWriterCallback()
+#ifndef NDEBUG
+ : m_fileWriterBase(0)
+#endif
+ {
+ }
+
+#ifndef NDEBUG
+ FileWriterBase* m_fileWriterBase;
+#endif
+};
+
+class LocalErrorCallback : public ErrorCallback {
+public:
+ static PassRefPtr<LocalErrorCallback> create()
+ {
+ return adoptRef(new LocalErrorCallback());
+ }
+
+ bool handleEvent(FileError* error)
+ {
+ m_error = error;
+ return true;
+ }
+
+ FileError* error()
+ {
+ return m_error.get();
+ }
+
+private:
+ LocalErrorCallback()
+ {
+ }
+ RefPtr<FileError> m_error;
+};
+
+}
+
+PassRefPtr<FileWriterSync> DOMFileSystemSync::createWriter(const FileEntrySync* fileEntry, ExceptionCode& ec)
+{
+ ASSERT(fileEntry);
+ ec = 0;
+
+
+ RefPtr<FileWriterSync> fileWriter = FileWriterSync::create();
+ RefPtr<ReceiveFileWriterCallback> successCallback = ReceiveFileWriterCallback::create();
+ RefPtr<LocalErrorCallback> errorCallback = LocalErrorCallback::create();
+
+ OwnPtr<FileWriterBaseCallbacks> callbacks = FileWriterBaseCallbacks::create(fileWriter, successCallback, errorCallback);
+ m_asyncFileSystem->createWriter(fileWriter.get(), fileEntry->fullPath(), callbacks.release());
+ if (!m_asyncFileSystem->waitForOperationToComplete()) {
+ ec = FileException::ABORT_ERR;
+ return 0;
+ }
+ if (errorCallback->error()) {
+ ASSERT(!successCallback->fileWriterBase());
+ ec = FileException::ErrorCodeToExceptionCode(errorCallback->error()->code());
+ return 0;
+ }
+ ASSERT(successCallback->fileWriterBase());
+ ASSERT(static_cast<FileWriterSync*>(successCallback->fileWriterBase()) == fileWriter.get());
+ return fileWriter;
+}
+
+}
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/DOMFileSystemSync.h b/Source/WebCore/fileapi/DOMFileSystemSync.h
new file mode 100644
index 000000000..0120fb058
--- /dev/null
+++ b/Source/WebCore/fileapi/DOMFileSystemSync.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DOMFileSystemSync_h
+#define DOMFileSystemSync_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "DOMFileSystemBase.h"
+
+namespace WebCore {
+
+class DirectoryEntrySync;
+class File;
+class FileEntrySync;
+class FileWriterSync;
+
+typedef int ExceptionCode;
+
+class DOMFileSystemSync : public DOMFileSystemBase {
+public:
+ static PassRefPtr<DOMFileSystemSync> create(ScriptExecutionContext* context, const String& name, PassOwnPtr<AsyncFileSystem> asyncFileSystem)
+ {
+ return adoptRef(new DOMFileSystemSync(context, name, asyncFileSystem));
+ }
+
+ static PassRefPtr<DOMFileSystemSync> create(DOMFileSystemBase*);
+
+ virtual ~DOMFileSystemSync();
+
+ PassRefPtr<DirectoryEntrySync> root();
+
+ PassRefPtr<File> createFile(const FileEntrySync*, ExceptionCode&);
+ PassRefPtr<FileWriterSync> createWriter(const FileEntrySync*, ExceptionCode&);
+
+private:
+ DOMFileSystemSync(ScriptExecutionContext*, const String& name, PassOwnPtr<AsyncFileSystem>);
+};
+
+}
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // DOMFileSystemSync_h
diff --git a/Source/WebCore/fileapi/DOMFileSystemSync.idl b/Source/WebCore/fileapi/DOMFileSystemSync.idl
new file mode 100644
index 000000000..b51d8ccd6
--- /dev/null
+++ b/Source/WebCore/fileapi/DOMFileSystemSync.idl
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module storage {
+ interface [
+ Conditional=FILE_SYSTEM,
+ NoStaticTables
+ ] DOMFileSystemSync {
+ readonly attribute DOMString name;
+ readonly attribute DirectoryEntrySync root;
+ };
+}
diff --git a/Source/WebCore/fileapi/DirectoryEntry.cpp b/Source/WebCore/fileapi/DirectoryEntry.cpp
new file mode 100644
index 000000000..0f6e49f44
--- /dev/null
+++ b/Source/WebCore/fileapi/DirectoryEntry.cpp
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DirectoryEntry.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "DirectoryReader.h"
+#include "EntryCallback.h"
+#include "ErrorCallback.h"
+#include "FileError.h"
+#include "VoidCallback.h"
+
+namespace WebCore {
+
+DirectoryEntry::DirectoryEntry(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath)
+ : Entry(fileSystem, fullPath)
+{
+}
+
+PassRefPtr<DirectoryReader> DirectoryEntry::createReader()
+{
+ return DirectoryReader::create(m_fileSystem, m_fullPath);
+}
+
+void DirectoryEntry::getFile(const String& path, PassRefPtr<WebKitFlags> flags, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef)
+{
+ RefPtr<ErrorCallback> errorCallback(errorCallbackRef);
+ if (!m_fileSystem->getFile(this, path, flags, successCallback, errorCallback))
+ filesystem()->scheduleCallback(errorCallback.release(), FileError::create(FileError::INVALID_MODIFICATION_ERR));
+}
+
+void DirectoryEntry::getDirectory(const String& path, PassRefPtr<WebKitFlags> flags, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef)
+{
+ RefPtr<ErrorCallback> errorCallback(errorCallbackRef);
+ if (!m_fileSystem->getDirectory(this, path, flags, successCallback, errorCallback))
+ filesystem()->scheduleCallback(errorCallback.release(), FileError::create(FileError::INVALID_MODIFICATION_ERR));
+}
+
+void DirectoryEntry::removeRecursively(PassRefPtr<VoidCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef) const
+{
+ RefPtr<ErrorCallback> errorCallback(errorCallbackRef);
+ if (!m_fileSystem->removeRecursively(this, successCallback, errorCallback))
+ filesystem()->scheduleCallback(errorCallback.release(), FileError::create(FileError::INVALID_MODIFICATION_ERR));
+}
+
+}
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/DirectoryEntry.h b/Source/WebCore/fileapi/DirectoryEntry.h
new file mode 100644
index 000000000..822704713
--- /dev/null
+++ b/Source/WebCore/fileapi/DirectoryEntry.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DirectoryEntry_h
+#define DirectoryEntry_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "Entry.h"
+#include "WebKitFlags.h"
+#include "PlatformString.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class DOMFileSystemBase;
+class DirectoryReader;
+class EntryCallback;
+class ErrorCallback;
+class VoidCallback;
+
+class DirectoryEntry : public Entry {
+public:
+ static PassRefPtr<DirectoryEntry> create(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath)
+ {
+ return adoptRef(new DirectoryEntry(fileSystem, fullPath));
+ }
+ virtual bool isDirectory() const { return true; }
+
+ PassRefPtr<DirectoryReader> createReader();
+ void getFile(const String& path, PassRefPtr<WebKitFlags> = 0, PassRefPtr<EntryCallback> = 0, PassRefPtr<ErrorCallback> = 0);
+ void getDirectory(const String& path, PassRefPtr<WebKitFlags> = 0, PassRefPtr<EntryCallback> = 0, PassRefPtr<ErrorCallback> = 0);
+ void removeRecursively(PassRefPtr<VoidCallback> successCallback = 0, PassRefPtr<ErrorCallback> = 0) const;
+
+private:
+ DirectoryEntry(PassRefPtr<DOMFileSystemBase>, const String& fullPath);
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // DirectoryEntry_h
diff --git a/Source/WebCore/fileapi/DirectoryEntry.idl b/Source/WebCore/fileapi/DirectoryEntry.idl
new file mode 100644
index 000000000..ac345e7dc
--- /dev/null
+++ b/Source/WebCore/fileapi/DirectoryEntry.idl
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module storage {
+ interface [
+ Conditional=FILE_SYSTEM,
+ GenerateNativeConverter,
+ GenerateToJS,
+ NoStaticTables
+ ] DirectoryEntry : Entry {
+ DirectoryReader createReader();
+ [Custom] void getFile(in [ConvertUndefinedOrNullToNullString] DOMString path, in [Optional] WebKitFlags flags, in [Optional, Callback] EntryCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback);
+ [Custom] void getDirectory(in [ConvertUndefinedOrNullToNullString] DOMString path, in [Optional] WebKitFlags flags, in [Optional, Callback] EntryCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback);
+ void removeRecursively(in [Callback] VoidCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback);
+ };
+}
diff --git a/Source/WebCore/fileapi/DirectoryEntrySync.cpp b/Source/WebCore/fileapi/DirectoryEntrySync.cpp
new file mode 100644
index 000000000..10deaceb0
--- /dev/null
+++ b/Source/WebCore/fileapi/DirectoryEntrySync.cpp
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DirectoryEntrySync.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "DirectoryReaderSync.h"
+#include "EntrySync.h"
+#include "FileEntrySync.h"
+#include "FileException.h"
+#include "SyncCallbackHelper.h"
+
+namespace WebCore {
+
+DirectoryEntrySync::DirectoryEntrySync(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath)
+ : EntrySync(fileSystem, fullPath)
+{
+}
+
+PassRefPtr<DirectoryReaderSync> DirectoryEntrySync::createReader(ExceptionCode&)
+{
+ return DirectoryReaderSync::create(m_fileSystem, m_fullPath);
+}
+
+PassRefPtr<FileEntrySync> DirectoryEntrySync::getFile(const String& path, PassRefPtr<WebKitFlags> flags, ExceptionCode& ec)
+{
+ ec = 0;
+ EntrySyncCallbackHelper helper(m_fileSystem->asyncFileSystem());
+ if (!m_fileSystem->getFile(this, path, flags, helper.successCallback(), helper.errorCallback())) {
+ ec = FileException::INVALID_MODIFICATION_ERR;
+ return 0;
+ }
+ return static_pointer_cast<FileEntrySync>(helper.getResult(ec));
+}
+
+PassRefPtr<DirectoryEntrySync> DirectoryEntrySync::getDirectory(const String& path, PassRefPtr<WebKitFlags> flags, ExceptionCode& ec)
+{
+ ec = 0;
+ EntrySyncCallbackHelper helper(m_fileSystem->asyncFileSystem());
+ if (!m_fileSystem->getDirectory(this, path, flags, helper.successCallback(), helper.errorCallback())) {
+ ec = FileException::INVALID_MODIFICATION_ERR;
+ return 0;
+ }
+ return static_pointer_cast<DirectoryEntrySync>(helper.getResult(ec));
+}
+
+void DirectoryEntrySync::removeRecursively(ExceptionCode& ec)
+{
+ ec = 0;
+ VoidSyncCallbackHelper helper(m_fileSystem->asyncFileSystem());
+ if (!m_fileSystem->removeRecursively(this, helper.successCallback(), helper.errorCallback())) {
+ ec = FileException::INVALID_MODIFICATION_ERR;
+ return;
+ }
+ helper.getResult(ec);
+}
+
+}
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/DirectoryEntrySync.h b/Source/WebCore/fileapi/DirectoryEntrySync.h
new file mode 100644
index 000000000..62b481a87
--- /dev/null
+++ b/Source/WebCore/fileapi/DirectoryEntrySync.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DirectoryEntrySync_h
+#define DirectoryEntrySync_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "EntrySync.h"
+#include "WebKitFlags.h"
+#include "PlatformString.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class DirectoryReaderSync;
+class FileEntrySync;
+
+class DirectoryEntrySync : public EntrySync {
+public:
+ static PassRefPtr<DirectoryEntrySync> create(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath)
+ {
+ return adoptRef(new DirectoryEntrySync(fileSystem, fullPath));
+ }
+ virtual bool isDirectory() const { return true; }
+
+ PassRefPtr<DirectoryReaderSync> createReader(ExceptionCode&);
+ PassRefPtr<FileEntrySync> getFile(const String& path, PassRefPtr<WebKitFlags>, ExceptionCode&);
+ PassRefPtr<DirectoryEntrySync> getDirectory(const String& path, PassRefPtr<WebKitFlags>, ExceptionCode&);
+ void removeRecursively(ExceptionCode&);
+
+private:
+ friend class EntrySync;
+ DirectoryEntrySync(PassRefPtr<DOMFileSystemBase>, const String& fullPath);
+};
+
+}
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // DirectoryEntrySync_h
diff --git a/Source/WebCore/fileapi/DirectoryEntrySync.idl b/Source/WebCore/fileapi/DirectoryEntrySync.idl
new file mode 100644
index 000000000..b0ab178ff
--- /dev/null
+++ b/Source/WebCore/fileapi/DirectoryEntrySync.idl
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module storage {
+ interface [
+ Conditional=FILE_SYSTEM,
+ GenerateNativeConverter,
+ GenerateToJS,
+ NoStaticTables
+ ] DirectoryEntrySync : EntrySync {
+ DirectoryReaderSync createReader() raises (FileException);
+ [Custom] FileEntrySync getFile(in [ConvertUndefinedOrNullToNullString] DOMString path, in WebKitFlags flags) raises (FileException);
+ [Custom] DirectoryEntrySync getDirectory(in [ConvertUndefinedOrNullToNullString] DOMString path, in WebKitFlags flags) raises (FileException);
+ void removeRecursively() raises (FileException);
+ };
+}
diff --git a/Source/WebCore/fileapi/DirectoryReader.cpp b/Source/WebCore/fileapi/DirectoryReader.cpp
new file mode 100644
index 000000000..fe2d99f44
--- /dev/null
+++ b/Source/WebCore/fileapi/DirectoryReader.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DirectoryReader.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "EntriesCallback.h"
+#include "EntryArray.h"
+#include "ErrorCallback.h"
+#include "FileError.h"
+
+namespace WebCore {
+
+DirectoryReader::DirectoryReader(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath)
+ : DirectoryReaderBase(fileSystem, fullPath)
+{
+}
+
+void DirectoryReader::readEntries(PassRefPtr<EntriesCallback> entriesCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ if (!m_hasMoreEntries) {
+ filesystem()->scheduleCallback(entriesCallback, EntryArray::create());
+ return;
+ }
+ filesystem()->readDirectory(this, m_fullPath, entriesCallback, errorCallback);
+}
+
+}
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/DirectoryReader.h b/Source/WebCore/fileapi/DirectoryReader.h
new file mode 100644
index 000000000..bc8985894
--- /dev/null
+++ b/Source/WebCore/fileapi/DirectoryReader.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DirectoryReader_h
+#define DirectoryReader_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "DOMFileSystem.h"
+#include "DirectoryReaderBase.h"
+#include "PlatformString.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class EntriesCallback;
+class EntriesCallbacks;
+class ErrorCallback;
+
+class DirectoryReader : public DirectoryReaderBase {
+public:
+ static PassRefPtr<DirectoryReader> create(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath)
+ {
+ return adoptRef(new DirectoryReader(fileSystem, fullPath));
+ }
+
+ void readEntries(PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback> = 0);
+
+ DOMFileSystem* filesystem() const { return static_cast<DOMFileSystem*>(m_fileSystem.get()); }
+
+private:
+ DirectoryReader(PassRefPtr<DOMFileSystemBase>, const String& fullPath);
+};
+
+}
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // DirectoryReader_h
diff --git a/Source/WebCore/fileapi/DirectoryReader.idl b/Source/WebCore/fileapi/DirectoryReader.idl
new file mode 100644
index 000000000..831fb05bc
--- /dev/null
+++ b/Source/WebCore/fileapi/DirectoryReader.idl
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module storage {
+ interface [
+ Conditional=FILE_SYSTEM,
+ NoStaticTables
+ ] DirectoryReader {
+ void readEntries(in [Callback] EntriesCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback);
+ };
+}
diff --git a/Source/WebCore/fileapi/DirectoryReaderBase.h b/Source/WebCore/fileapi/DirectoryReaderBase.h
new file mode 100644
index 000000000..4096fe8a2
--- /dev/null
+++ b/Source/WebCore/fileapi/DirectoryReaderBase.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DirectoryReaderBase_h
+#define DirectoryReaderBase_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "DOMFileSystemBase.h"
+#include "PlatformString.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class DirectoryReaderBase : public RefCounted<DirectoryReaderBase> {
+public:
+ DOMFileSystemBase* filesystem() const { return m_fileSystem.get(); }
+ void setHasMoreEntries(bool hasMoreEntries) { m_hasMoreEntries = hasMoreEntries; }
+
+protected:
+ DirectoryReaderBase(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath)
+ : m_fileSystem(fileSystem)
+ , m_fullPath(fullPath)
+ , m_hasMoreEntries(true)
+ {
+ }
+
+ RefPtr<DOMFileSystemBase> m_fileSystem;
+
+ // This is a virtual path.
+ String m_fullPath;
+
+ bool m_hasMoreEntries;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // DirectoryReaderBase_h
diff --git a/Source/WebCore/fileapi/DirectoryReaderSync.cpp b/Source/WebCore/fileapi/DirectoryReaderSync.cpp
new file mode 100644
index 000000000..014478e7b
--- /dev/null
+++ b/Source/WebCore/fileapi/DirectoryReaderSync.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DirectoryReaderSync.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "DirectoryEntry.h"
+#include "DirectoryEntrySync.h"
+#include "EntryArraySync.h"
+#include "EntrySync.h"
+#include "FileEntrySync.h"
+#include "FileException.h"
+#include "SyncCallbackHelper.h"
+
+namespace WebCore {
+
+DirectoryReaderSync::DirectoryReaderSync(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath)
+ : DirectoryReaderBase(fileSystem, fullPath)
+{
+}
+
+PassRefPtr<EntryArraySync> DirectoryReaderSync::readEntries(ExceptionCode& ec)
+{
+ ec = 0;
+ if (!m_hasMoreEntries)
+ return EntryArraySync::create();
+
+ EntriesSyncCallbackHelper helper(m_fileSystem->asyncFileSystem());
+ if (!m_fileSystem->readDirectory(this, m_fullPath, helper.successCallback(), helper.errorCallback())) {
+ ec = FileException::INVALID_MODIFICATION_ERR;
+ setHasMoreEntries(false);
+ return 0;
+ }
+ return helper.getResult(ec);
+}
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/DirectoryReaderSync.h b/Source/WebCore/fileapi/DirectoryReaderSync.h
new file mode 100644
index 000000000..b1d1282c2
--- /dev/null
+++ b/Source/WebCore/fileapi/DirectoryReaderSync.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DirectoryReaderSync_h
+#define DirectoryReaderSync_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "DirectoryReaderBase.h"
+#include "PlatformString.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class EntryArraySync;
+
+typedef int ExceptionCode;
+
+class DirectoryReaderSync : public DirectoryReaderBase {
+public:
+ static PassRefPtr<DirectoryReaderSync> create(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath)
+ {
+ return adoptRef(new DirectoryReaderSync(fileSystem, fullPath));
+ }
+
+ PassRefPtr<EntryArraySync> readEntries(ExceptionCode&);
+
+private:
+ DirectoryReaderSync(PassRefPtr<DOMFileSystemBase>, const String& fullPath);
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // DirectoryReaderSync_h
diff --git a/Source/WebCore/fileapi/DirectoryReaderSync.idl b/Source/WebCore/fileapi/DirectoryReaderSync.idl
new file mode 100644
index 000000000..aa3992832
--- /dev/null
+++ b/Source/WebCore/fileapi/DirectoryReaderSync.idl
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module storage {
+ interface [
+ Conditional=FILE_SYSTEM,
+ NoStaticTables
+ ] DirectoryReaderSync {
+ EntryArraySync readEntries() raises (FileException);
+ };
+}
diff --git a/Source/WebCore/fileapi/EntriesCallback.h b/Source/WebCore/fileapi/EntriesCallback.h
new file mode 100644
index 000000000..9f812e978
--- /dev/null
+++ b/Source/WebCore/fileapi/EntriesCallback.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef EntriesCallback_h
+#define EntriesCallback_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class EntryArray;
+
+class EntriesCallback : public RefCounted<EntriesCallback> {
+public:
+ virtual ~EntriesCallback() { }
+ virtual bool handleEvent(EntryArray*) = 0;
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // EntriesCallback_h
diff --git a/Source/WebCore/fileapi/EntriesCallback.idl b/Source/WebCore/fileapi/EntriesCallback.idl
new file mode 100644
index 000000000..73b374d79
--- /dev/null
+++ b/Source/WebCore/fileapi/EntriesCallback.idl
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module storage {
+ interface [
+ Conditional=FILE_SYSTEM,
+ Callback
+ ] EntriesCallback {
+ boolean handleEvent(in EntryArray entries);
+ };
+}
diff --git a/Source/WebCore/fileapi/Entry.cpp b/Source/WebCore/fileapi/Entry.cpp
new file mode 100644
index 000000000..8b0f6ac1d
--- /dev/null
+++ b/Source/WebCore/fileapi/Entry.cpp
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "config.h"
+#include "Entry.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "AsyncFileSystem.h"
+#include "DirectoryEntry.h"
+#include "EntryCallback.h"
+#include "ErrorCallback.h"
+#include "FileError.h"
+#include "FileSystemCallbacks.h"
+#include "MetadataCallback.h"
+#include "ScriptExecutionContext.h"
+#include "SecurityOrigin.h"
+#include "VoidCallback.h"
+#include <wtf/text/StringBuilder.h>
+
+namespace WebCore {
+
+Entry::Entry(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath)
+ : EntryBase(fileSystem, fullPath)
+{
+}
+
+void Entry::getMetadata(PassRefPtr<MetadataCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef)
+{
+ RefPtr<ErrorCallback> errorCallback(errorCallbackRef);
+ if (!m_fileSystem->getMetadata(this, successCallback, errorCallback))
+ filesystem()->scheduleCallback(errorCallback.release(), FileError::create(FileError::INVALID_MODIFICATION_ERR));
+}
+
+void Entry::moveTo(PassRefPtr<DirectoryEntry> parent, const String& name, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef) const
+{
+ RefPtr<ErrorCallback> errorCallback(errorCallbackRef);
+ if (!m_fileSystem->move(this, parent.get(), name, successCallback, errorCallback))
+ filesystem()->scheduleCallback(errorCallback.release(), FileError::create(FileError::INVALID_MODIFICATION_ERR));
+}
+
+void Entry::copyTo(PassRefPtr<DirectoryEntry> parent, const String& name, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef) const
+{
+ RefPtr<ErrorCallback> errorCallback(errorCallbackRef);
+ if (!m_fileSystem->copy(this, parent.get(), name, successCallback, errorCallback))
+ filesystem()->scheduleCallback(errorCallback.release(), FileError::create(FileError::INVALID_MODIFICATION_ERR));
+}
+
+void Entry::remove(PassRefPtr<VoidCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef) const
+{
+ RefPtr<ErrorCallback> errorCallback(errorCallbackRef);
+ if (!m_fileSystem->remove(this, successCallback, errorCallback))
+ filesystem()->scheduleCallback(errorCallback.release(), FileError::create(FileError::INVALID_MODIFICATION_ERR));
+}
+
+void Entry::getParent(PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef) const
+{
+ RefPtr<ErrorCallback> errorCallback(errorCallbackRef);
+ if (!m_fileSystem->getParent(this, successCallback, errorCallback))
+ filesystem()->scheduleCallback(errorCallback.release(), FileError::create(FileError::INVALID_MODIFICATION_ERR));
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/Entry.h b/Source/WebCore/fileapi/Entry.h
new file mode 100644
index 000000000..09cc964eb
--- /dev/null
+++ b/Source/WebCore/fileapi/Entry.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef Entry_h
+#define Entry_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "DOMFileSystem.h"
+#include "EntryBase.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class DirectoryEntry;
+class EntryCallback;
+class EntrySync;
+class ErrorCallback;
+class MetadataCallback;
+class VoidCallback;
+
+class Entry : public EntryBase {
+public:
+ DOMFileSystem* filesystem() const { return static_cast<DOMFileSystem*>(m_fileSystem.get()); }
+
+ void getMetadata(PassRefPtr<MetadataCallback> successCallback = 0, PassRefPtr<ErrorCallback> errorCallback = 0);
+ void moveTo(PassRefPtr<DirectoryEntry> parent, const String& name = String(), PassRefPtr<EntryCallback> successCallback = 0, PassRefPtr<ErrorCallback> errorCallback = 0) const;
+ void copyTo(PassRefPtr<DirectoryEntry> parent, const String& name = String(), PassRefPtr<EntryCallback> successCallback = 0, PassRefPtr<ErrorCallback> errorCallback = 0) const;
+ void remove(PassRefPtr<VoidCallback> successCallback = 0, PassRefPtr<ErrorCallback> errorCallback = 0) const;
+ void getParent(PassRefPtr<EntryCallback> successCallback = 0, PassRefPtr<ErrorCallback> errorCallback = 0) const;
+
+protected:
+ Entry(PassRefPtr<DOMFileSystemBase>, const String& fullPath);
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // Entry_h
diff --git a/Source/WebCore/fileapi/Entry.idl b/Source/WebCore/fileapi/Entry.idl
new file mode 100644
index 000000000..d6d280ba8
--- /dev/null
+++ b/Source/WebCore/fileapi/Entry.idl
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module storage {
+ interface [
+ Conditional=FILE_SYSTEM,
+ CustomToJS,
+ NoStaticTables
+ ] Entry {
+ readonly attribute boolean isFile;
+ readonly attribute boolean isDirectory;
+ readonly attribute DOMString name;
+ readonly attribute DOMString fullPath;
+ readonly attribute DOMFileSystem filesystem;
+
+ void getMetadata(in [Callback] MetadataCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback);
+ void moveTo(in DirectoryEntry parent, in [Optional, ConvertUndefinedOrNullToNullString] DOMString name, in [Optional, Callback] EntryCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback);
+ void copyTo(in DirectoryEntry parent, in [Optional, ConvertUndefinedOrNullToNullString] DOMString name, in [Optional, Callback] EntryCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback);
+ DOMString toURL();
+ void remove(in [Callback] VoidCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback);
+ void getParent(in [Optional, Callback] EntryCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback);
+ };
+}
diff --git a/Source/WebCore/fileapi/EntryArray.cpp b/Source/WebCore/fileapi/EntryArray.cpp
new file mode 100644
index 000000000..6c4f74fb5
--- /dev/null
+++ b/Source/WebCore/fileapi/EntryArray.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "EntryArray.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+namespace WebCore {
+
+EntryArray::EntryArray()
+{
+}
+
+Entry* EntryArray::item(unsigned index) const
+{
+ if (index >= m_entries.size())
+ return 0;
+ return m_entries[index].get();
+}
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/EntryArray.h b/Source/WebCore/fileapi/EntryArray.h
new file mode 100644
index 000000000..e5957abd1
--- /dev/null
+++ b/Source/WebCore/fileapi/EntryArray.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef EntryArray_h
+#define EntryArray_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "Entry.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class EntryArray : public RefCounted<EntryArray> {
+public:
+ static PassRefPtr<EntryArray> create()
+ {
+ return adoptRef(new EntryArray());
+ }
+
+ unsigned length() const { return m_entries.size(); }
+ Entry* item(unsigned index) const;
+ void set(unsigned index, PassRefPtr<Entry> entry);
+
+ bool isEmpty() const { return m_entries.isEmpty(); }
+ void clear() { m_entries.clear(); }
+ void append(PassRefPtr<Entry> entry) { m_entries.append(entry); }
+
+private:
+ EntryArray();
+
+ Vector<RefPtr<Entry> > m_entries;
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // EntryArray_h
diff --git a/Source/WebCore/fileapi/EntryArray.idl b/Source/WebCore/fileapi/EntryArray.idl
new file mode 100644
index 000000000..dca782743
--- /dev/null
+++ b/Source/WebCore/fileapi/EntryArray.idl
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module storage {
+ interface [
+ Conditional=FILE_SYSTEM,
+ HasIndexGetter,
+ NoStaticTables
+ ] EntryArray {
+ readonly attribute unsigned long length;
+ Entry item(in [IsIndex] unsigned long index);
+ };
+}
diff --git a/Source/WebCore/fileapi/EntryArraySync.cpp b/Source/WebCore/fileapi/EntryArraySync.cpp
new file mode 100644
index 000000000..1e2fa9151
--- /dev/null
+++ b/Source/WebCore/fileapi/EntryArraySync.cpp
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "EntryArraySync.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "EntryArray.h"
+
+namespace WebCore {
+
+PassRefPtr<EntryArraySync> EntryArraySync::create(EntryArray* entries)
+{
+ RefPtr<EntryArraySync> entriesSync = adoptRef(new EntryArraySync());
+ if (entries) {
+ for (unsigned i = 0; i < entries->length(); ++i)
+ entriesSync->append(EntrySync::create(entries->item(i)));
+ }
+ return entriesSync.release();
+}
+
+EntryArraySync::EntryArraySync()
+{
+}
+
+EntrySync* EntryArraySync::item(unsigned index) const
+{
+ if (index >= m_entries.size())
+ return 0;
+ return m_entries[index].get();
+}
+
+}
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/EntryArraySync.h b/Source/WebCore/fileapi/EntryArraySync.h
new file mode 100644
index 000000000..46cf40911
--- /dev/null
+++ b/Source/WebCore/fileapi/EntryArraySync.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef EntryArraySync_h
+#define EntryArraySync_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "EntrySync.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class EntryArray;
+
+class EntryArraySync : public RefCounted<EntryArraySync> {
+public:
+ static PassRefPtr<EntryArraySync> create()
+ {
+ return adoptRef(new EntryArraySync());
+ }
+
+ static PassRefPtr<EntryArraySync> create(EntryArray*);
+
+ unsigned length() const { return m_entries.size(); }
+ EntrySync* item(unsigned index) const;
+
+ bool isEmpty() const { return m_entries.isEmpty(); }
+ void clear() { m_entries.clear(); }
+ void append(PassRefPtr<EntrySync> entry) { m_entries.append(entry); }
+
+private:
+ EntryArraySync();
+
+ Vector<RefPtr<EntrySync> > m_entries;
+};
+
+}
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // EntryArraySync_h
diff --git a/Source/WebCore/fileapi/EntryArraySync.idl b/Source/WebCore/fileapi/EntryArraySync.idl
new file mode 100644
index 000000000..bd54f33ee
--- /dev/null
+++ b/Source/WebCore/fileapi/EntryArraySync.idl
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module storage {
+ interface [
+ Conditional=FILE_SYSTEM,
+ HasIndexGetter,
+ NoStaticTables
+ ] EntryArraySync {
+ readonly attribute unsigned long length;
+ EntrySync item(in [IsIndex] unsigned long index);
+ };
+}
diff --git a/Source/WebCore/fileapi/EntryBase.cpp b/Source/WebCore/fileapi/EntryBase.cpp
new file mode 100644
index 000000000..39453f61c
--- /dev/null
+++ b/Source/WebCore/fileapi/EntryBase.cpp
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "EntryBase.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "AsyncFileSystem.h"
+#include "DOMFilePath.h"
+#include "DOMFileSystemBase.h"
+#include "PlatformString.h"
+#include "SecurityOrigin.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/text/StringBuilder.h>
+
+namespace WebCore {
+
+EntryBase::EntryBase(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath)
+ : m_fileSystem(fileSystem)
+ , m_fullPath(fullPath)
+ , m_name(DOMFilePath::getName(fullPath))
+{
+}
+
+EntryBase::~EntryBase()
+{
+}
+
+String EntryBase::toURL()
+{
+ String originString = m_fileSystem->securityOrigin()->toString();
+ ASSERT(!originString.isEmpty());
+ if (originString == "null")
+ return String();
+ StringBuilder result;
+ result.append("filesystem:");
+ result.append(originString);
+ result.append("/");
+ switch (m_fileSystem->asyncFileSystem()->type()) {
+ case AsyncFileSystem::Temporary:
+ result.append(DOMFileSystemBase::kTemporaryPathPrefix);
+ break;
+ case AsyncFileSystem::Persistent:
+ result.append(DOMFileSystemBase::kPersistentPathPrefix);
+ break;
+ case AsyncFileSystem::External:
+ result.append(DOMFileSystemBase::kExternalPathPrefix);
+ break;
+ }
+ result.append(m_fullPath);
+ return result.toString();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/EntryBase.h b/Source/WebCore/fileapi/EntryBase.h
new file mode 100644
index 000000000..a34a914f1
--- /dev/null
+++ b/Source/WebCore/fileapi/EntryBase.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef EntryBase_h
+#define EntryBase_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "PlatformString.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class DOMFileSystemBase;
+class EntrySync;
+
+// A common base class for Entry and EntrySync.
+class EntryBase : public RefCounted<EntryBase> {
+public:
+ virtual ~EntryBase();
+
+ DOMFileSystemBase* filesystem() const { return m_fileSystem.get(); }
+
+ virtual bool isFile() const { return false; }
+ virtual bool isDirectory() const { return false; }
+
+ const String& fullPath() const { return m_fullPath; }
+ const String& name() const { return m_name; }
+
+ String toURL();
+
+protected:
+ EntryBase(PassRefPtr<DOMFileSystemBase>, const String& fullPath);
+ friend class EntrySync;
+
+ RefPtr<DOMFileSystemBase> m_fileSystem;
+
+ // This is a virtual path.
+ String m_fullPath;
+
+ String m_name;
+};
+
+}
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // EntryBase_h
diff --git a/Source/WebCore/fileapi/EntryCallback.h b/Source/WebCore/fileapi/EntryCallback.h
new file mode 100644
index 000000000..9580eda88
--- /dev/null
+++ b/Source/WebCore/fileapi/EntryCallback.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef EntryCallback_h
+#define EntryCallback_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class Entry;
+
+class EntryCallback : public RefCounted<EntryCallback> {
+public:
+ virtual ~EntryCallback() { }
+ virtual bool handleEvent(Entry*) = 0;
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // EntryCallback_h
diff --git a/Source/WebCore/fileapi/EntryCallback.idl b/Source/WebCore/fileapi/EntryCallback.idl
new file mode 100644
index 000000000..bea3fd147
--- /dev/null
+++ b/Source/WebCore/fileapi/EntryCallback.idl
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module storage {
+ interface [
+ Conditional=FILE_SYSTEM,
+ Callback
+ ] EntryCallback {
+ boolean handleEvent(in Entry entry);
+ };
+}
diff --git a/Source/WebCore/fileapi/EntrySync.cpp b/Source/WebCore/fileapi/EntrySync.cpp
new file mode 100644
index 000000000..299aeda36
--- /dev/null
+++ b/Source/WebCore/fileapi/EntrySync.cpp
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "EntrySync.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "DOMFilePath.h"
+#include "DOMFileSystemSync.h"
+#include "DirectoryEntry.h"
+#include "DirectoryEntrySync.h"
+#include "FileEntrySync.h"
+#include "FileException.h"
+#include "Metadata.h"
+#include "SyncCallbackHelper.h"
+
+namespace WebCore {
+
+PassRefPtr<EntrySync> EntrySync::create(EntryBase* entry)
+{
+ if (entry->isFile())
+ return adoptRef(new FileEntrySync(entry->m_fileSystem, entry->m_fullPath));
+ return adoptRef(new DirectoryEntrySync(entry->m_fileSystem, entry->m_fullPath));
+}
+
+PassRefPtr<Metadata> EntrySync::getMetadata(ExceptionCode& ec)
+{
+ ec = 0;
+ MetadataSyncCallbackHelper helper(m_fileSystem->asyncFileSystem());
+ if (!m_fileSystem->getMetadata(this, helper.successCallback(), helper.errorCallback())) {
+ ec = FileException::INVALID_MODIFICATION_ERR;
+ return 0;
+ }
+ return helper.getResult(ec);
+}
+
+PassRefPtr<EntrySync> EntrySync::moveTo(PassRefPtr<DirectoryEntrySync> parent, const String& name, ExceptionCode& ec) const
+{
+ ec = 0;
+ EntrySyncCallbackHelper helper(m_fileSystem->asyncFileSystem());
+ if (!m_fileSystem->move(this, parent.get(), name, helper.successCallback(), helper.errorCallback())) {
+ ec = FileException::INVALID_MODIFICATION_ERR;
+ return 0;
+ }
+ return helper.getResult(ec);
+}
+
+PassRefPtr<EntrySync> EntrySync::copyTo(PassRefPtr<DirectoryEntrySync> parent, const String& name, ExceptionCode& ec) const
+{
+ ec = 0;
+ EntrySyncCallbackHelper helper(m_fileSystem->asyncFileSystem());
+ if (!m_fileSystem->copy(this, parent.get(), name, helper.successCallback(), helper.errorCallback())) {
+ ec = FileException::INVALID_MODIFICATION_ERR;
+ return 0;
+ }
+ return helper.getResult(ec);
+}
+
+void EntrySync::remove(ExceptionCode& ec) const
+{
+ ec = 0;
+ VoidSyncCallbackHelper helper(m_fileSystem->asyncFileSystem());
+ if (!m_fileSystem->remove(this, helper.successCallback(), helper.errorCallback())) {
+ ec = FileException::INVALID_MODIFICATION_ERR;
+ return;
+ }
+ helper.getResult(ec);
+}
+
+PassRefPtr<EntrySync> EntrySync::getParent() const
+{
+ // Sync verion of getParent doesn't throw exceptions.
+ String parentPath = DOMFilePath::getDirectory(fullPath());
+ return DirectoryEntrySync::create(m_fileSystem, parentPath);
+}
+
+EntrySync::EntrySync(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath)
+ : EntryBase(fileSystem, fullPath)
+{
+}
+
+}
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/EntrySync.h b/Source/WebCore/fileapi/EntrySync.h
new file mode 100644
index 000000000..644ad7171
--- /dev/null
+++ b/Source/WebCore/fileapi/EntrySync.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef EntrySync_h
+#define EntrySync_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "DOMFileSystemSync.h"
+#include "EntryBase.h"
+#include "PlatformString.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class DirectoryEntrySync;
+class Metadata;
+
+typedef int ExceptionCode;
+
+class EntrySync : public EntryBase {
+public:
+ static PassRefPtr<EntrySync> create(EntryBase*);
+
+ DOMFileSystemSync* filesystem() const { return static_cast<DOMFileSystemSync*>(m_fileSystem.get()); }
+
+ PassRefPtr<Metadata> getMetadata(ExceptionCode&);
+ PassRefPtr<EntrySync> moveTo(PassRefPtr<DirectoryEntrySync> parent, const String& name, ExceptionCode&) const;
+ PassRefPtr<EntrySync> copyTo(PassRefPtr<DirectoryEntrySync> parent, const String& name, ExceptionCode&) const;
+ void remove(ExceptionCode&) const;
+ PassRefPtr<EntrySync> getParent() const;
+
+protected:
+ EntrySync(PassRefPtr<DOMFileSystemBase>, const String& fullPath);
+};
+
+}
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // EntrySync_h
diff --git a/Source/WebCore/fileapi/EntrySync.idl b/Source/WebCore/fileapi/EntrySync.idl
new file mode 100644
index 000000000..459a01441
--- /dev/null
+++ b/Source/WebCore/fileapi/EntrySync.idl
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module storage {
+ interface [
+ Conditional=FILE_SYSTEM,
+ CustomToJS,
+ NoStaticTables
+ ] EntrySync {
+ readonly attribute boolean isFile;
+ readonly attribute boolean isDirectory;
+ readonly attribute DOMString name;
+ readonly attribute DOMString fullPath;
+ readonly attribute DOMFileSystemSync filesystem;
+
+ Metadata getMetadata() raises (FileException);
+ EntrySync moveTo(in DirectoryEntrySync parent, in [ConvertUndefinedOrNullToNullString] DOMString name) raises (FileException);
+ EntrySync copyTo(in DirectoryEntrySync parent, in [ConvertUndefinedOrNullToNullString] DOMString name) raises (FileException);
+ DOMString toURL();
+ void remove() raises (FileException);
+ DirectoryEntrySync getParent();
+ };
+}
diff --git a/Source/WebCore/fileapi/ErrorCallback.h b/Source/WebCore/fileapi/ErrorCallback.h
new file mode 100644
index 000000000..cceb354fc
--- /dev/null
+++ b/Source/WebCore/fileapi/ErrorCallback.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ErrorCallback_h
+#define ErrorCallback_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class FileError;
+
+class ErrorCallback : public RefCounted<ErrorCallback> {
+public:
+ virtual ~ErrorCallback() { }
+ virtual bool handleEvent(FileError*) = 0;
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // ErrorCallback_h
diff --git a/Source/WebCore/fileapi/ErrorCallback.idl b/Source/WebCore/fileapi/ErrorCallback.idl
new file mode 100644
index 000000000..fc7fa85c4
--- /dev/null
+++ b/Source/WebCore/fileapi/ErrorCallback.idl
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module storage {
+ interface [
+ Conditional=FILE_SYSTEM,
+ Callback
+ ] ErrorCallback {
+ boolean handleEvent(in FileError error);
+ };
+}
diff --git a/Source/WebCore/fileapi/File.cpp b/Source/WebCore/fileapi/File.cpp
new file mode 100644
index 000000000..d409b9719
--- /dev/null
+++ b/Source/WebCore/fileapi/File.cpp
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "File.h"
+
+#include "FileSystem.h"
+#include "MIMETypeRegistry.h"
+#include <wtf/CurrentTime.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+static PassOwnPtr<BlobData> createBlobDataForFileWithType(const String& path, const String& contentType)
+{
+ OwnPtr<BlobData> blobData = BlobData::create();
+ blobData->setContentType(contentType);
+ blobData->appendFile(path);
+ return blobData.release();
+}
+
+static PassOwnPtr<BlobData> createBlobDataForFile(const String& path)
+{
+ String type;
+ int index = path.reverseFind('.');
+ if (index != -1)
+ type = MIMETypeRegistry::getMIMETypeForExtension(path.substring(index + 1));
+ return createBlobDataForFileWithType(path, type);
+}
+
+#if ENABLE(FILE_SYSTEM)
+static PassOwnPtr<BlobData> createBlobDataForFileSystemFile(const String& path, const String& fileSystemName)
+{
+ String type;
+ int index = fileSystemName.reverseFind('.');
+ if (index != -1)
+ type = MIMETypeRegistry::getWellKnownMIMETypeForExtension(fileSystemName.substring(index + 1));
+ return createBlobDataForFileWithType(path, type);
+}
+#endif
+
+#if ENABLE(DIRECTORY_UPLOAD)
+PassRefPtr<File> File::createWithRelativePath(const String& path, const String& relativePath)
+{
+ RefPtr<File> file = adoptRef(new File(path));
+ file->m_relativePath = relativePath;
+ return file.release();
+}
+#endif
+
+File::File(const String& path)
+ : Blob(createBlobDataForFile(path), -1)
+ , m_path(path)
+ , m_name(pathGetFileName(path))
+{
+}
+
+File::File(const String& path, const KURL& url, const String& type)
+ : Blob(url, type, -1)
+ , m_path(path)
+{
+ m_name = pathGetFileName(path);
+ // FIXME: File object serialization/deserialization does not include
+ // newer file object data members: m_name and m_relativePath.
+ // See SerializedScriptValue.cpp for js and v8.
+}
+
+#if ENABLE(FILE_SYSTEM)
+File::File(const String& path, const String& name)
+ : Blob(createBlobDataForFileSystemFile(path, name), -1)
+ , m_path(path)
+ , m_name(name)
+{
+}
+#endif
+
+double File::lastModifiedDate() const
+{
+ time_t modificationTime;
+ if (!getFileModificationTime(m_path, modificationTime))
+ return 0;
+
+ // Needs to return epoch time in milliseconds for Date.
+ return modificationTime * 1000.0;
+}
+
+unsigned long long File::size() const
+{
+ // FIXME: JavaScript cannot represent sizes as large as unsigned long long, we need to
+ // come up with an exception to throw if file size is not representable.
+ long long size;
+ if (!getFileSize(m_path, size))
+ return 0;
+ return static_cast<unsigned long long>(size);
+}
+
+void File::captureSnapshot(long long& snapshotSize, double& snapshotModificationTime) const
+{
+ // 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)) {
+ snapshotSize = 0;
+ snapshotModificationTime = 0;
+ } else
+ snapshotModificationTime = modificationTime;
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/fileapi/File.h b/Source/WebCore/fileapi/File.h
new file mode 100644
index 000000000..13a91fe3e
--- /dev/null
+++ b/Source/WebCore/fileapi/File.h
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef File_h
+#define File_h
+
+#include "Blob.h"
+#include "PlatformString.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class KURL;
+
+class File : public Blob {
+public:
+ static PassRefPtr<File> create(const String& path)
+ {
+ return adoptRef(new File(path));
+ }
+
+ // For deserialization.
+ static PassRefPtr<File> create(const String& path, const KURL& srcURL, const String& type)
+ {
+ return adoptRef(new File(path, srcURL, type));
+ }
+
+#if ENABLE(DIRECTORY_UPLOAD)
+ static PassRefPtr<File> createWithRelativePath(const String& path, const String& relativePath);
+#endif
+
+#if ENABLE(FILE_SYSTEM)
+ // Create a file with a name exposed to the author (via File.name and associated DOM properties) that differs from the one provided in the path.
+ static PassRefPtr<File> createWithName(const String& path, const String& name)
+ {
+ return adoptRef(new File(path, name));
+ }
+#endif
+
+ virtual unsigned long long size() const;
+ virtual bool isFile() const { return true; }
+
+ const String& path() const { return m_path; }
+ const String& name() const { return m_name; }
+ double lastModifiedDate() const;
+#if ENABLE(DIRECTORY_UPLOAD)
+ // Returns the relative path of this file in the context of a directory selection.
+ const String& webkitRelativePath() const { return m_relativePath; }
+#endif
+
+ // Note that this involves synchronous file operation. Think twice before calling this function.
+ void captureSnapshot(long long& snapshotSize, double& snapshotModificationTime) const;
+
+ // FIXME: obsolete attributes. To be removed.
+ const String& fileName() const { return name(); }
+ unsigned long long fileSize() const { return size(); }
+
+private:
+ File(const String& path);
+
+ // For deserialization.
+ File(const String& path, const KURL& srcURL, const String& type);
+
+#if ENABLE(FILE_SYSTEM)
+ File(const String& path, const String& name);
+#endif
+
+ String m_path;
+ String m_name;
+#if ENABLE(DIRECTORY_UPLOAD)
+ String m_relativePath;
+#endif
+};
+
+} // namespace WebCore
+
+#endif // File_h
diff --git a/Source/WebCore/fileapi/File.idl b/Source/WebCore/fileapi/File.idl
new file mode 100644
index 000000000..74a6f769f
--- /dev/null
+++ b/Source/WebCore/fileapi/File.idl
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module html {
+
+ interface [
+ GenerateNativeConverter,
+ GenerateToJS,
+ NoStaticTables
+ ] File : Blob {
+ readonly attribute DOMString name;
+#if !defined(LANGUAGE_GOBJECT) || !LANGUAGE_GOBJECT
+ readonly attribute Date lastModifiedDate;
+#endif
+#if defined(ENABLE_DIRECTORY_UPLOAD) && ENABLE_DIRECTORY_UPLOAD
+ readonly attribute DOMString webkitRelativePath;
+#endif
+
+ // FIXME: obsolete attributes. To be removed.
+ readonly attribute DOMString fileName;
+ readonly attribute unsigned long long fileSize;
+ };
+
+}
diff --git a/Source/WebCore/fileapi/FileCallback.h b/Source/WebCore/fileapi/FileCallback.h
new file mode 100644
index 000000000..6f5ca3d14
--- /dev/null
+++ b/Source/WebCore/fileapi/FileCallback.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileCallback_h
+#define FileCallback_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "File.h"
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class FileCallback : public RefCounted<FileCallback> {
+public:
+ virtual ~FileCallback() { }
+ virtual bool handleEvent(File*) = 0;
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // FileCallback_h
diff --git a/Source/WebCore/fileapi/FileCallback.idl b/Source/WebCore/fileapi/FileCallback.idl
new file mode 100644
index 000000000..0ab814fed
--- /dev/null
+++ b/Source/WebCore/fileapi/FileCallback.idl
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module fileapi {
+ interface [
+ Conditional=FILE_SYSTEM,
+ Callback
+ ] FileCallback {
+ boolean handleEvent(in File file);
+ };
+}
diff --git a/Source/WebCore/fileapi/FileEntry.cpp b/Source/WebCore/fileapi/FileEntry.cpp
new file mode 100644
index 000000000..a5ecff578
--- /dev/null
+++ b/Source/WebCore/fileapi/FileEntry.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "FileEntry.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "DOMFileSystem.h"
+#include "ErrorCallback.h"
+#include "File.h"
+#include "FileCallback.h"
+#include "FileWriterCallback.h"
+
+namespace WebCore {
+
+FileEntry::FileEntry(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath)
+ : Entry(fileSystem, fullPath)
+{
+}
+
+void FileEntry::createWriter(PassRefPtr<FileWriterCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ filesystem()->createWriter(this, successCallback, errorCallback);
+}
+
+void FileEntry::file(PassRefPtr<FileCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ filesystem()->createFile(this, successCallback, errorCallback);
+}
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/FileEntry.h b/Source/WebCore/fileapi/FileEntry.h
new file mode 100644
index 000000000..f9cc85631
--- /dev/null
+++ b/Source/WebCore/fileapi/FileEntry.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileEntry_h
+#define FileEntry_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "Entry.h"
+
+namespace WebCore {
+
+class DOMFileSystemBase;
+class FileCallback;
+class FileWriterCallback;
+
+class FileEntry : public Entry {
+public:
+ static PassRefPtr<FileEntry> create(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath)
+ {
+ return adoptRef(new FileEntry(fileSystem, fullPath));
+ }
+
+ void createWriter(PassRefPtr<FileWriterCallback>, PassRefPtr<ErrorCallback> = 0);
+ void file(PassRefPtr<FileCallback>, PassRefPtr<ErrorCallback> = 0);
+
+ virtual bool isFile() const { return true; }
+
+private:
+ FileEntry(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath);
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // FileEntry_h
diff --git a/Source/WebCore/fileapi/FileEntry.idl b/Source/WebCore/fileapi/FileEntry.idl
new file mode 100644
index 000000000..73ef89563
--- /dev/null
+++ b/Source/WebCore/fileapi/FileEntry.idl
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module storage {
+ interface [
+ Conditional=FILE_SYSTEM,
+ GenerateNativeConverter,
+ GenerateToJS,
+ NoStaticTables
+ ] FileEntry : Entry {
+ void createWriter(in [Callback] FileWriterCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback);
+ void file(in [Callback] FileCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback);
+ };
+}
diff --git a/Source/WebCore/fileapi/FileEntrySync.cpp b/Source/WebCore/fileapi/FileEntrySync.cpp
new file mode 100644
index 000000000..d899de786
--- /dev/null
+++ b/Source/WebCore/fileapi/FileEntrySync.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "FileEntrySync.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "File.h"
+#include "FileWriterSync.h"
+
+namespace WebCore {
+
+FileEntrySync::FileEntrySync(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath)
+ : EntrySync(fileSystem, fullPath)
+{
+}
+
+PassRefPtr<File> FileEntrySync::file(ExceptionCode& ec)
+{
+ return filesystem()->createFile(this, ec);
+}
+
+PassRefPtr<FileWriterSync> FileEntrySync::createWriter(ExceptionCode& ec)
+{
+ return filesystem()->createWriter(this, ec);
+}
+
+}
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/FileEntrySync.h b/Source/WebCore/fileapi/FileEntrySync.h
new file mode 100644
index 000000000..615a604bf
--- /dev/null
+++ b/Source/WebCore/fileapi/FileEntrySync.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileEntrySync_h
+#define FileEntrySync_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "EntrySync.h"
+#include "PlatformString.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class File;
+class FileWriterSync;
+
+class FileEntrySync : public EntrySync {
+public:
+ static PassRefPtr<FileEntrySync> create(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath)
+ {
+ return adoptRef(new FileEntrySync(fileSystem, fullPath));
+ }
+
+ virtual bool isFile() const { return true; }
+
+ PassRefPtr<File> file(ExceptionCode&);
+ PassRefPtr<FileWriterSync> createWriter(ExceptionCode&);
+
+private:
+ friend class EntrySync;
+ FileEntrySync(PassRefPtr<DOMFileSystemBase>, const String& fullPath);
+};
+
+}
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // FileEntrySync_h
diff --git a/Source/WebCore/fileapi/FileEntrySync.idl b/Source/WebCore/fileapi/FileEntrySync.idl
new file mode 100644
index 000000000..c56983959
--- /dev/null
+++ b/Source/WebCore/fileapi/FileEntrySync.idl
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module storage {
+ interface [
+ Conditional=FILE_SYSTEM,
+ GenerateNativeConverter,
+ GenerateToJS,
+ NoStaticTables
+ ] FileEntrySync : EntrySync {
+ File file() raises (FileException);
+ FileWriterSync createWriter() raises (FileException);
+ };
+}
diff --git a/Source/WebCore/fileapi/FileError.h b/Source/WebCore/fileapi/FileError.h
new file mode 100644
index 000000000..0597633e7
--- /dev/null
+++ b/Source/WebCore/fileapi/FileError.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileError_h
+#define FileError_h
+
+#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class FileError : public RefCounted<FileError> {
+public:
+ enum ErrorCode {
+ OK = 0,
+ NOT_FOUND_ERR = 1,
+ SECURITY_ERR = 2,
+ ABORT_ERR = 3,
+ NOT_READABLE_ERR = 4,
+ ENCODING_ERR = 5,
+ NO_MODIFICATION_ALLOWED_ERR = 6,
+ INVALID_STATE_ERR = 7,
+ SYNTAX_ERR = 8,
+ INVALID_MODIFICATION_ERR = 9,
+ QUOTA_EXCEEDED_ERR = 10,
+ TYPE_MISMATCH_ERR = 11,
+ PATH_EXISTS_ERR = 12,
+ };
+
+ static PassRefPtr<FileError> create(ErrorCode code) { return adoptRef(new FileError(code)); }
+
+ ErrorCode code() const { return m_code; }
+
+private:
+ FileError(ErrorCode code)
+ : m_code(code)
+ { }
+
+ ErrorCode m_code;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
+
+#endif // FileError_h
diff --git a/Source/WebCore/fileapi/FileError.idl b/Source/WebCore/fileapi/FileError.idl
new file mode 100644
index 000000000..bab815ad6
--- /dev/null
+++ b/Source/WebCore/fileapi/FileError.idl
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module html {
+ interface [
+ Conditional=BLOB|FILE_SYSTEM,
+ NoStaticTables
+ ] FileError {
+#if !defined(LANGUAGE_OBJECTIVE_C)
+ // FIXME: Some of constant names are already defined in DOMException.h for Objective-C binding and we cannot have the same names here (they are translated into a enum in the same namespace).
+ const unsigned short NOT_FOUND_ERR = 1;
+ const unsigned short SECURITY_ERR = 2;
+ const unsigned short ABORT_ERR = 3;
+ const unsigned short NOT_READABLE_ERR = 4;
+ const unsigned short ENCODING_ERR = 5;
+ const unsigned short NO_MODIFICATION_ALLOWED_ERR = 6;
+ const unsigned short INVALID_STATE_ERR = 7;
+ const unsigned short SYNTAX_ERR = 8;
+ const unsigned short INVALID_MODIFICATION_ERR = 9;
+ const unsigned short QUOTA_EXCEEDED_ERR = 10;
+ const unsigned short TYPE_MISMATCH_ERR = 11;
+ const unsigned short PATH_EXISTS_ERR = 12;
+#endif
+ readonly attribute unsigned short code;
+ };
+}
diff --git a/Source/WebCore/fileapi/FileException.cpp b/Source/WebCore/fileapi/FileException.cpp
new file mode 100644
index 000000000..656b16386
--- /dev/null
+++ b/Source/WebCore/fileapi/FileException.cpp
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GOOGLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
+
+#include "FileException.h"
+
+namespace WebCore {
+
+// FIXME: This should be an array of structs to pair the names and descriptions.
+static const char* const exceptionNames[] = {
+ "NOT_FOUND_ERR",
+ "SECURITY_ERR",
+ "ABORT_ERR",
+ "NOT_READABLE_ERR",
+ "ENCODING_ERR",
+ "NO_MODIFICATION_ALLOWED_ERR",
+ "INVALID_STATE_ERR",
+ "SYNTAX_ERR",
+ "INVALID_MODIFICATION_ERR",
+ "QUOTA_EXCEEDED_ERR",
+ "TYPE_MISMATCH_ERR",
+ "PATH_EXISTS_ERR"
+};
+
+static const char* const exceptionDescriptions[] = {
+ "A requested file or directory could not be found at the time an operation was processed.",
+ "It was determined that certain files are unsafe for access within a Web application, or that too many calls are being made on file resources.",
+ "An ongoing operation was aborted, typically with a call to abort().",
+ "The requested file could not be read, typically due to permission problems that have occured after a reference to a file was acquired.",
+ "A URI supplied to the API was malformed, or the resulting Data URL has exceeded the URL length limitations for Data URLs.",
+ "An attempt was made to write to a file or directory which could not be modified due to the state of the underlying filesystem.",
+ "An operation that depends on state cached in an interface object was made but the state had changed since it was read from disk.",
+ "An invalid or unsupported argument was given, like an invalid line ending specifier.",
+ "The modification request was illegal.",
+ "The operation failed because it would cause the application to exceed its storage quota.",
+ "The path supplied exists, but was not an entry of requested type.",
+ "An attempt was made to create a file or directory where an element already exists."
+};
+
+COMPILE_ASSERT(WTF_ARRAY_LENGTH(exceptionNames) == WTF_ARRAY_LENGTH(exceptionDescriptions), FileExceptionTablesMustMatch);
+
+bool FileException::initializeDescription(ExceptionCode ec, ExceptionCodeDescription* description)
+{
+ if (ec < FileExceptionOffset || ec > FileExceptionMax)
+ return false;
+
+ description->typeName = "DOM File";
+ description->code = ec - FileExceptionOffset;
+ description->type = FileExceptionType;
+
+ size_t tableSize = WTF_ARRAY_LENGTH(exceptionNames);
+ size_t tableIndex = ec - NOT_FOUND_ERR;
+
+ description->name = tableIndex < tableSize ? exceptionNames[tableIndex] : 0;
+ description->description = tableIndex < tableSize ? exceptionDescriptions[tableIndex] : 0;
+
+ return true;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/FileException.h b/Source/WebCore/fileapi/FileException.h
new file mode 100644
index 000000000..38f1ed4ae
--- /dev/null
+++ b/Source/WebCore/fileapi/FileException.h
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileException_h
+#define FileException_h
+
+#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
+
+#include "ExceptionBase.h"
+
+namespace WebCore {
+
+class FileException : public ExceptionBase {
+public:
+ static PassRefPtr<FileException> create(const ExceptionCodeDescription& description)
+ {
+ return adoptRef(new FileException(description));
+ }
+
+ static const int FileExceptionOffset = 1100;
+ static const int FileExceptionMax = 1199;
+
+ enum FileExceptionCode {
+ NOT_FOUND_ERR = FileExceptionOffset + 1,
+ SECURITY_ERR = FileExceptionOffset + 2,
+ ABORT_ERR = FileExceptionOffset + 3,
+ NOT_READABLE_ERR = FileExceptionOffset + 4,
+ ENCODING_ERR = FileExceptionOffset + 5,
+ NO_MODIFICATION_ALLOWED_ERR = FileExceptionOffset + 6,
+ INVALID_STATE_ERR = FileExceptionOffset + 7,
+ SYNTAX_ERR = FileExceptionOffset + 8,
+ INVALID_MODIFICATION_ERR = FileExceptionOffset + 9,
+ QUOTA_EXCEEDED_ERR = FileExceptionOffset + 10,
+ TYPE_MISMATCH_ERR = FileExceptionOffset + 11,
+ PATH_EXISTS_ERR = FileExceptionOffset + 12,
+ };
+
+ static int ErrorCodeToExceptionCode(int errorCode)
+ {
+ if (!errorCode)
+ return 0;
+ return errorCode + FileExceptionOffset;
+ }
+
+ static bool initializeDescription(ExceptionCode, ExceptionCodeDescription*);
+
+private:
+ FileException(const ExceptionCodeDescription& description)
+ : ExceptionBase(description)
+ {
+ }
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
+
+#endif // FileException_h
diff --git a/Source/WebCore/fileapi/FileException.idl b/Source/WebCore/fileapi/FileException.idl
new file mode 100644
index 000000000..10bd15177
--- /dev/null
+++ b/Source/WebCore/fileapi/FileException.idl
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module html {
+ interface [
+ Conditional=BLOB|FILE_SYSTEM,
+ DontCheckEnums,
+ NoStaticTables
+ ] FileException {
+
+ readonly attribute unsigned short code;
+ readonly attribute DOMString name;
+ readonly attribute DOMString message;
+
+#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
+ // Override in a Mozilla compatible format
+ [DontEnum] DOMString toString();
+#endif
+
+ // FileExceptionCode
+ const unsigned short NOT_FOUND_ERR = 1;
+ const unsigned short SECURITY_ERR = 2;
+ const unsigned short ABORT_ERR = 3;
+ const unsigned short NOT_READABLE_ERR = 4;
+ const unsigned short ENCODING_ERR = 5;
+ const unsigned short NO_MODIFICATION_ALLOWED_ERR = 6;
+ const unsigned short INVALID_STATE_ERR = 7;
+ const unsigned short SYNTAX_ERR = 8;
+ const unsigned short INVALID_MODIFICATION_ERR = 9;
+ const unsigned short QUOTA_EXCEEDED_ERR = 10;
+ const unsigned short TYPE_MISMATCH_ERR = 11;
+ const unsigned short PATH_EXISTS_ERR = 12;
+ };
+}
diff --git a/Source/WebCore/fileapi/FileList.cpp b/Source/WebCore/fileapi/FileList.cpp
new file mode 100644
index 000000000..809e25359
--- /dev/null
+++ b/Source/WebCore/fileapi/FileList.cpp
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "FileList.h"
+
+#include "File.h"
+
+namespace WebCore {
+
+FileList::FileList()
+{
+}
+
+File* FileList::item(unsigned index) const
+{
+ if (index >= m_files.size())
+ return 0;
+ return m_files[index].get();
+}
+
+Vector<String> FileList::paths() const
+{
+ Vector<String> paths;
+ for (unsigned i = 0; i < m_files.size(); ++i)
+ paths.append(m_files[i]->path());
+
+ return paths;
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/fileapi/FileList.h b/Source/WebCore/fileapi/FileList.h
new file mode 100644
index 000000000..928981f85
--- /dev/null
+++ b/Source/WebCore/fileapi/FileList.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileList_h
+#define FileList_h
+
+#include "File.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+ class FileList : public RefCounted<FileList> {
+ public:
+ static PassRefPtr<FileList> create()
+ {
+ return adoptRef(new FileList);
+ }
+
+ unsigned length() const { return m_files.size(); }
+ File* item(unsigned index) const;
+
+ bool isEmpty() const { return m_files.isEmpty(); }
+ void clear() { m_files.clear(); }
+ void append(PassRefPtr<File> file) { m_files.append(file); }
+ Vector<String> paths() const;
+
+ private:
+ FileList();
+
+ Vector<RefPtr<File> > m_files;
+ };
+
+} // namespace WebCore
+
+#endif // FileList_h
diff --git a/Source/WebCore/fileapi/FileList.idl b/Source/WebCore/fileapi/FileList.idl
new file mode 100644
index 000000000..0d0b046c3
--- /dev/null
+++ b/Source/WebCore/fileapi/FileList.idl
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module html {
+
+ interface [
+ HasIndexGetter,
+ NoStaticTables
+ ] FileList {
+ readonly attribute unsigned long length;
+ File item(in [IsIndex] unsigned long index);
+ };
+
+}
diff --git a/Source/WebCore/fileapi/FileReader.cpp b/Source/WebCore/fileapi/FileReader.cpp
new file mode 100644
index 000000000..29c598470
--- /dev/null
+++ b/Source/WebCore/fileapi/FileReader.cpp
@@ -0,0 +1,245 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(BLOB)
+
+#include "FileReader.h"
+
+#include "CrossThreadTask.h"
+#include "File.h"
+#include "Logging.h"
+#include "OperationNotAllowedException.h"
+#include "ProgressEvent.h"
+#include "ScriptExecutionContext.h"
+#include <wtf/ArrayBuffer.h>
+#include <wtf/CurrentTime.h>
+#include <wtf/text/CString.h>
+
+namespace WebCore {
+
+static const double progressNotificationIntervalMS = 50;
+
+FileReader::FileReader(ScriptExecutionContext* context)
+ : ActiveDOMObject(context, this)
+ , m_state(EMPTY)
+ , m_aborting(false)
+ , m_readType(FileReaderLoader::ReadAsBinaryString)
+ , m_lastProgressNotificationTimeMS(0)
+{
+}
+
+FileReader::~FileReader()
+{
+ terminate();
+}
+
+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.
+ return false;
+}
+
+void FileReader::stop()
+{
+ terminate();
+}
+
+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() : "");
+
+ readInternal(blob, FileReaderLoader::ReadAsArrayBuffer, ec);
+}
+
+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() : "");
+
+ readInternal(blob, FileReaderLoader::ReadAsBinaryString, ec);
+}
+
+void FileReader::readAsText(Blob* blob, const String& encoding, ExceptionCode& ec)
+{
+ 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() : "");
+
+ m_encoding = encoding;
+ readInternal(blob, FileReaderLoader::ReadAsText, ec);
+}
+
+void FileReader::readAsText(Blob* blob, ExceptionCode& ec)
+{
+ readAsText(blob, String(), ec);
+}
+
+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() : "");
+
+ readInternal(blob, FileReaderLoader::ReadAsDataURL, ec);
+}
+
+void FileReader::readInternal(Blob* blob, FileReaderLoader::ReadType type, ExceptionCode& ec)
+{
+ // If multiple concurrent read methods are called on the same FileReader, OperationNotAllowedException should be thrown when the state is LOADING.
+ if (m_state == LOADING) {
+ ec = OperationNotAllowedException::NOT_ALLOWED_ERR;
+ return;
+ }
+
+ m_blob = blob;
+ 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.get());
+}
+
+static void delayedAbort(ScriptExecutionContext*, FileReader* reader)
+{
+ reader->doAbort();
+}
+
+void FileReader::abort()
+{
+ LOG(FileAPI, "FileReader: aborting\n");
+
+ if (m_aborting)
+ return;
+ m_aborting = true;
+
+ // Schedule to have the abort done later since abort() might be called from the event handler and we do not want the resource loading code to be in the stack.
+ scriptExecutionContext()->postTask(
+ createCallbackTask(&delayedAbort, AllowAccessLater(this)));
+}
+
+void FileReader::doAbort()
+{
+ terminate();
+ m_aborting = false;
+
+ m_error = FileError::create(FileError::ABORT_ERR);
+
+ fireEvent(eventNames().errorEvent);
+ fireEvent(eventNames().abortEvent);
+ fireEvent(eventNames().loadendEvent);
+}
+
+void FileReader::terminate()
+{
+ if (m_loader) {
+ m_loader->cancel();
+ m_loader = nullptr;
+ }
+ m_state = DONE;
+}
+
+void FileReader::didStartLoading()
+{
+ fireEvent(eventNames().loadstartEvent);
+}
+
+void FileReader::didReceiveData()
+{
+ // Fire the progress event at least every 50ms.
+ double now = currentTimeMS();
+ if (!m_lastProgressNotificationTimeMS)
+ m_lastProgressNotificationTimeMS = now;
+ else if (now - m_lastProgressNotificationTimeMS > progressNotificationIntervalMS) {
+ fireEvent(eventNames().progressEvent);
+ m_lastProgressNotificationTimeMS = now;
+ }
+}
+
+void FileReader::didFinishLoading()
+{
+ m_state = DONE;
+
+ fireEvent(eventNames().loadEvent);
+ fireEvent(eventNames().loadendEvent);
+}
+
+void FileReader::didFail(int errorCode)
+{
+ // If we're aborting, do not proceed with normal error handling since it is covered in aborting code.
+ if (m_aborting)
+ return;
+
+ m_state = DONE;
+
+ m_error = FileError::create(static_cast<FileError::ErrorCode>(errorCode));
+ fireEvent(eventNames().errorEvent);
+ fireEvent(eventNames().loadendEvent);
+}
+
+void FileReader::fireEvent(const AtomicString& type)
+{
+ dispatchEvent(ProgressEvent::create(type, true, m_loader ? m_loader->bytesLoaded() : 0, m_loader ? m_loader->totalBytes() : 0));
+}
+
+PassRefPtr<ArrayBuffer> FileReader::arrayBufferResult() const
+{
+ return m_loader ? m_loader->arrayBufferResult() : 0;
+}
+
+String FileReader::stringResult()
+{
+ return m_loader ? m_loader->stringResult() : "";
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(BLOB)
diff --git a/Source/WebCore/fileapi/FileReader.h b/Source/WebCore/fileapi/FileReader.h
new file mode 100644
index 000000000..804dd291b
--- /dev/null
+++ b/Source/WebCore/fileapi/FileReader.h
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileReader_h
+#define FileReader_h
+
+#if ENABLE(BLOB)
+
+#include "ActiveDOMObject.h"
+#include "EventTarget.h"
+#include "FileError.h"
+#include "FileReaderLoader.h"
+#include "FileReaderLoaderClient.h"
+#include <wtf/Forward.h>
+#include <wtf/RefCounted.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class Blob;
+class ScriptExecutionContext;
+
+typedef int ExceptionCode;
+
+class FileReader : public RefCounted<FileReader>, public ActiveDOMObject, public EventTarget, public FileReaderLoaderClient {
+public:
+ static PassRefPtr<FileReader> create(ScriptExecutionContext* context)
+ {
+ return adoptRef(new FileReader(context));
+ }
+
+ virtual ~FileReader();
+
+ enum ReadyState {
+ EMPTY = 0,
+ LOADING = 1,
+ DONE = 2
+ };
+
+ void readAsArrayBuffer(Blob*, ExceptionCode&);
+ void readAsBinaryString(Blob*, ExceptionCode&);
+ void readAsText(Blob*, const String& encoding, ExceptionCode&);
+ void readAsText(Blob*, ExceptionCode&);
+ void readAsDataURL(Blob*, ExceptionCode&);
+ void abort();
+
+ void doAbort();
+
+ ReadyState readyState() const { return m_state; }
+ PassRefPtr<FileError> error() { return m_error; }
+ FileReaderLoader::ReadType readType() const { return m_readType; }
+ PassRefPtr<ArrayBuffer> arrayBufferResult() const;
+ String stringResult();
+
+ // ActiveDOMObject
+ virtual bool canSuspend() const;
+ virtual void stop();
+ virtual bool hasPendingActivity() const;
+
+ // EventTarget
+ virtual const AtomicString& interfaceName() const;
+ virtual ScriptExecutionContext* scriptExecutionContext() const { return ActiveDOMObject::scriptExecutionContext(); }
+
+ // FileReaderLoaderClient
+ virtual void didStartLoading();
+ virtual void didReceiveData();
+ virtual void didFinishLoading();
+ virtual void didFail(int errorCode);
+
+ using RefCounted<FileReader>::ref;
+ using RefCounted<FileReader>::deref;
+
+ DEFINE_ATTRIBUTE_EVENT_LISTENER(loadstart);
+ DEFINE_ATTRIBUTE_EVENT_LISTENER(progress);
+ DEFINE_ATTRIBUTE_EVENT_LISTENER(load);
+ DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
+ DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
+ DEFINE_ATTRIBUTE_EVENT_LISTENER(loadend);
+
+private:
+ FileReader(ScriptExecutionContext*);
+
+ // EventTarget
+ virtual void refEventTarget() { ref(); }
+ virtual void derefEventTarget() { deref(); }
+ virtual EventTargetData* eventTargetData() { return &m_eventTargetData; }
+ virtual EventTargetData* ensureEventTargetData() { return &m_eventTargetData; }
+
+ void terminate();
+ void readInternal(Blob*, FileReaderLoader::ReadType, ExceptionCode&);
+ void fireErrorEvent(int httpStatusCode);
+ void fireEvent(const AtomicString& type);
+
+ ReadyState m_state;
+ bool m_aborting;
+ EventTargetData m_eventTargetData;
+
+ RefPtr<Blob> m_blob;
+ FileReaderLoader::ReadType m_readType;
+ String m_encoding;
+
+ OwnPtr<FileReaderLoader> m_loader;
+ RefPtr<FileError> m_error;
+ double m_lastProgressNotificationTimeMS;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(BLOB)
+
+#endif // FileReader_h
diff --git a/Source/WebCore/fileapi/FileReader.idl b/Source/WebCore/fileapi/FileReader.idl
new file mode 100644
index 000000000..7407c11c6
--- /dev/null
+++ b/Source/WebCore/fileapi/FileReader.idl
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module html {
+ interface [
+ Conditional=BLOB,
+ ActiveDOMObject,
+ Constructor,
+ CallWith=ScriptExecutionContext,
+ EventTarget,
+ NoStaticTables
+ ] FileReader {
+ // ready states
+ const unsigned short EMPTY = 0;
+ const unsigned short LOADING = 1;
+ const unsigned short DONE = 2;
+ readonly attribute unsigned short readyState;
+
+ // async read methods
+ void readAsArrayBuffer(in Blob blob)
+ raises(OperationNotAllowedException);
+ void readAsBinaryString(in Blob blob)
+ raises(OperationNotAllowedException);
+ void readAsText(in Blob blob, in [Optional] DOMString encoding)
+ raises(OperationNotAllowedException);
+ void readAsDataURL(in Blob blob)
+ raises(OperationNotAllowedException);
+
+ void abort();
+
+ // file data
+ readonly attribute [Custom] DOMObject result;
+
+ readonly attribute FileError error;
+
+ // EventTarget interface
+ void addEventListener(in DOMString type,
+ in EventListener listener,
+ in [Optional] boolean useCapture);
+ void removeEventListener(in DOMString type,
+ in EventListener listener,
+ in [Optional] boolean useCapture);
+ boolean dispatchEvent(in Event evt)
+ raises(EventException);
+
+ attribute EventListener onloadstart;
+ attribute EventListener onprogress;
+ attribute EventListener onload;
+ attribute EventListener onabort;
+ attribute EventListener onerror;
+ attribute EventListener onloadend;
+ };
+}
diff --git a/Source/WebCore/fileapi/FileReaderLoader.cpp b/Source/WebCore/fileapi/FileReaderLoader.cpp
new file mode 100644
index 000000000..5fb6061c0
--- /dev/null
+++ b/Source/WebCore/fileapi/FileReaderLoader.cpp
@@ -0,0 +1,327 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(BLOB)
+
+#include "FileReaderLoader.h"
+
+#include "Base64.h"
+#include "Blob.h"
+#include "BlobURL.h"
+#include "FileReaderLoaderClient.h"
+#include "ResourceRequest.h"
+#include "ResourceResponse.h"
+#include "ScriptExecutionContext.h"
+#include "TextResourceDecoder.h"
+#include "ThreadableBlobRegistry.h"
+#include "ThreadableLoader.h"
+#include <wtf/ArrayBuffer.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+#include <wtf/Vector.h>
+#include <wtf/text/StringBuilder.h>
+
+using namespace std;
+
+namespace WebCore {
+
+FileReaderLoader::FileReaderLoader(ReadType readType, FileReaderLoaderClient* client)
+ : m_readType(readType)
+ , m_client(client)
+ , m_isRawDataConverted(false)
+ , m_stringResult("")
+ , m_bytesLoaded(0)
+ , m_totalBytes(0)
+ , m_errorCode(0)
+{
+}
+
+FileReaderLoader::~FileReaderLoader()
+{
+ terminate();
+ ThreadableBlobRegistry::unregisterBlobURL(m_urlForReading);
+}
+
+void FileReaderLoader::start(ScriptExecutionContext* scriptExecutionContext, Blob* blob)
+{
+ // The blob is read by routing through the request handling layer given a temporary public url.
+ m_urlForReading = BlobURL::createPublicURL(scriptExecutionContext->securityOrigin());
+ if (m_urlForReading.isEmpty()) {
+ failed(FileError::SECURITY_ERR);
+ return;
+ }
+ ThreadableBlobRegistry::registerBlobURL(m_urlForReading, blob->url());
+
+ // Construct and load the request.
+ ResourceRequest request(m_urlForReading);
+ request.setHTTPMethod("GET");
+
+ ThreadableLoaderOptions options;
+ options.sendLoadCallbacks = SendCallbacks;
+ options.sniffContent = DoNotSniffContent;
+ options.preflightPolicy = ConsiderPreflight;
+ options.allowCredentials = AllowStoredCredentials;
+ options.crossOriginRequestPolicy = DenyCrossOriginRequests;
+
+ if (m_client)
+ m_loader = ThreadableLoader::create(scriptExecutionContext, this, request, options);
+ else
+ ThreadableLoader::loadResourceSynchronously(scriptExecutionContext, request, *this, options);
+}
+
+void FileReaderLoader::cancel()
+{
+ m_errorCode = FileError::ABORT_ERR;
+ terminate();
+}
+
+void FileReaderLoader::terminate()
+{
+ if (m_loader) {
+ m_loader->cancel();
+ cleanup();
+ }
+}
+
+void FileReaderLoader::cleanup()
+{
+ m_loader = 0;
+
+ // If we get any error, we do not need to keep a buffer around.
+ if (m_errorCode) {
+ m_rawData = 0;
+ m_stringResult = "";
+ }
+}
+
+void FileReaderLoader::didReceiveResponse(unsigned long, const ResourceResponse& response)
+{
+ if (response.httpStatusCode() != 200) {
+ failed(httpStatusCodeToErrorCode(response.httpStatusCode()));
+ return;
+ }
+
+ unsigned long long length = response.expectedContentLength();
+
+ // Check that we can cast to unsigned since we have to do
+ // so to call ArrayBuffer's create function.
+ // FIXME: Support reading more than the current size limit of ArrayBuffer.
+ if (length > numeric_limits<unsigned>::max()) {
+ failed(FileError::NOT_READABLE_ERR);
+ return;
+ }
+
+ ASSERT(!m_rawData);
+ m_rawData = ArrayBuffer::create(static_cast<unsigned>(length), 1);
+
+ if (!m_rawData) {
+ failed(FileError::NOT_READABLE_ERR);
+ return;
+ }
+
+ m_totalBytes = static_cast<unsigned>(length);
+
+ if (m_client)
+ m_client->didStartLoading();
+}
+
+void FileReaderLoader::didReceiveData(const char* data, int dataLength)
+{
+ ASSERT(data);
+ ASSERT(dataLength > 0);
+
+ // Bail out if we already encountered an error.
+ if (m_errorCode)
+ return;
+
+ int length = dataLength;
+ unsigned remainingBufferSpace = m_totalBytes - m_bytesLoaded;
+ if (length > static_cast<long long>(remainingBufferSpace))
+ length = static_cast<int>(remainingBufferSpace);
+
+ if (length <= 0)
+ return;
+
+ memcpy(static_cast<char*>(m_rawData->data()) + m_bytesLoaded, data, length);
+ m_bytesLoaded += length;
+
+ m_isRawDataConverted = false;
+
+ if (m_client)
+ m_client->didReceiveData();
+}
+
+void FileReaderLoader::didFinishLoading(unsigned long, double)
+{
+ cleanup();
+ if (m_client)
+ m_client->didFinishLoading();
+}
+
+void FileReaderLoader::didFail(const ResourceError&)
+{
+ // If we're aborting, do not proceed with normal error handling since it is covered in aborting code.
+ if (m_errorCode == FileError::ABORT_ERR)
+ return;
+
+ failed(FileError::NOT_READABLE_ERR);
+}
+
+void FileReaderLoader::failed(int errorCode)
+{
+ m_errorCode = errorCode;
+ cleanup();
+ if (m_client)
+ m_client->didFail(m_errorCode);
+}
+
+FileError::ErrorCode FileReaderLoader::httpStatusCodeToErrorCode(int httpStatusCode)
+{
+ switch (httpStatusCode) {
+ case 403:
+ return FileError::SECURITY_ERR;
+ case 404:
+ return FileError::NOT_FOUND_ERR;
+ default:
+ return FileError::NOT_READABLE_ERR;
+ }
+}
+
+PassRefPtr<ArrayBuffer> FileReaderLoader::arrayBufferResult() const
+{
+ ASSERT(m_readType == ReadAsArrayBuffer);
+
+ // If the loading is not started or an error occurs, return an empty result.
+ if (!m_rawData || m_errorCode)
+ return 0;
+
+ // If completed, we can simply return our buffer.
+ if (isCompleted())
+ return m_rawData;
+
+ // Otherwise, return a copy.
+ return ArrayBuffer::create(m_rawData.get());
+}
+
+String FileReaderLoader::stringResult()
+{
+ ASSERT(m_readType != ReadAsArrayBuffer);
+
+ // If the loading is not started or an error occurs, return an empty result.
+ if (!m_rawData || m_errorCode)
+ return m_stringResult;
+
+ // If already converted from the raw data, return the result now.
+ if (m_isRawDataConverted)
+ return m_stringResult;
+
+ switch (m_readType) {
+ case ReadAsArrayBuffer:
+ // No conversion is needed.
+ break;
+ case ReadAsBinaryString:
+ m_stringResult = String(static_cast<const char*>(m_rawData->data()), m_bytesLoaded);
+ break;
+ case ReadAsText:
+ convertToText();
+ break;
+ case ReadAsDataURL:
+ // Partial data is not supported when reading as data URL.
+ if (isCompleted())
+ convertToDataURL();
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+
+ return m_stringResult;
+}
+
+void FileReaderLoader::convertToText()
+{
+ if (!m_bytesLoaded)
+ return;
+
+ // Decode the data.
+ // The File API spec says that we should use the supplied encoding if it is valid. However, we choose to ignore this
+ // requirement in order to be consistent with how WebKit decodes the web content: always has the BOM override the
+ // provided encoding.
+ // FIXME: consider supporting incremental decoding to improve the perf.
+ StringBuilder builder;
+ if (!m_decoder)
+ m_decoder = TextResourceDecoder::create("text/plain", m_encoding.isValid() ? m_encoding : UTF8Encoding());
+ builder.append(m_decoder->decode(static_cast<const char*>(m_rawData->data()), m_bytesLoaded));
+
+ if (isCompleted())
+ builder.append(m_decoder->flush());
+
+ m_stringResult = builder.toString();
+}
+
+void FileReaderLoader::convertToDataURL()
+{
+ StringBuilder builder;
+ builder.append("data:");
+
+ if (!m_bytesLoaded) {
+ m_stringResult = builder.toString();
+ return;
+ }
+
+ if (!m_dataType.isEmpty()) {
+ builder.append(m_dataType);
+ builder.append(";base64,");
+ } else
+ builder.append("base64,");
+
+ Vector<char> out;
+ base64Encode(static_cast<const char*>(m_rawData->data()), m_bytesLoaded, out);
+ out.append('\0');
+ builder.append(out.data());
+
+ m_stringResult = builder.toString();
+}
+
+bool FileReaderLoader::isCompleted() const
+{
+ return m_bytesLoaded == m_totalBytes;
+}
+
+void FileReaderLoader::setEncoding(const String& encoding)
+{
+ if (!encoding.isEmpty())
+ m_encoding = TextEncoding(encoding);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(BLOB)
diff --git a/Source/WebCore/fileapi/FileReaderLoader.h b/Source/WebCore/fileapi/FileReaderLoader.h
new file mode 100644
index 000000000..34f54387b
--- /dev/null
+++ b/Source/WebCore/fileapi/FileReaderLoader.h
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileReaderLoader_h
+#define FileReaderLoader_h
+
+#if ENABLE(BLOB)
+
+#include "FileError.h"
+#include "KURL.h"
+#include "TextEncoding.h"
+#include "ThreadableLoaderClient.h"
+#include <wtf/Forward.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class Blob;
+class FileReaderLoaderClient;
+class ScriptExecutionContext;
+class TextResourceDecoder;
+class ThreadableLoader;
+
+class FileReaderLoader : public ThreadableLoaderClient {
+public:
+ enum ReadType {
+ ReadAsArrayBuffer,
+ ReadAsBinaryString,
+ ReadAsText,
+ ReadAsDataURL
+ };
+
+ // If client is given, do the loading asynchronously. Otherwise, load synchronously.
+ FileReaderLoader(ReadType, FileReaderLoaderClient*);
+ ~FileReaderLoader();
+
+ void start(ScriptExecutionContext*, Blob*);
+ void cancel();
+
+ // ThreadableLoaderClient
+ virtual void didReceiveResponse(unsigned long, const ResourceResponse&);
+ virtual void didReceiveData(const char*, int);
+ virtual void didFinishLoading(unsigned long, double);
+ virtual void didFail(const ResourceError&);
+
+ String stringResult();
+ PassRefPtr<ArrayBuffer> arrayBufferResult() const;
+ unsigned bytesLoaded() const { return m_bytesLoaded; }
+ unsigned totalBytes() const { return m_totalBytes; }
+ int errorCode() const { return m_errorCode; }
+
+ void setEncoding(const String&);
+ void setDataType(const String& dataType) { m_dataType = dataType; }
+
+private:
+ void terminate();
+ void cleanup();
+ void failed(int errorCode);
+ void convertToText();
+ void convertToDataURL();
+
+ bool isCompleted() const;
+
+ static FileError::ErrorCode httpStatusCodeToErrorCode(int);
+
+ ReadType m_readType;
+ FileReaderLoaderClient* m_client;
+ TextEncoding m_encoding;
+ String m_dataType;
+
+ KURL m_urlForReading;
+ RefPtr<ThreadableLoader> m_loader;
+
+ RefPtr<ArrayBuffer> m_rawData;
+ bool m_isRawDataConverted;
+
+ String m_stringResult;
+
+ // The decoder used to decode the text data.
+ RefPtr<TextResourceDecoder> m_decoder;
+
+ unsigned m_bytesLoaded;
+ unsigned m_totalBytes;
+ int m_errorCode;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(BLOB)
+
+#endif // FileReaderLoader_h
diff --git a/Source/WebCore/fileapi/FileReaderLoaderClient.h b/Source/WebCore/fileapi/FileReaderLoaderClient.h
new file mode 100644
index 000000000..4acb8ad3a
--- /dev/null
+++ b/Source/WebCore/fileapi/FileReaderLoaderClient.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileReaderLoaderClient_h
+#define FileReaderLoaderClient_h
+
+#if ENABLE(BLOB)
+
+namespace WebCore {
+
+class FileReaderLoaderClient {
+public:
+ virtual ~FileReaderLoaderClient() {}
+
+ virtual void didStartLoading() = 0;
+ virtual void didReceiveData() = 0;
+ virtual void didFinishLoading() = 0;
+ virtual void didFail(int errorCode) = 0;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(BLOB)
+
+#endif // FileReaderLoaderClient_h
diff --git a/Source/WebCore/fileapi/FileReaderSync.cpp b/Source/WebCore/fileapi/FileReaderSync.cpp
new file mode 100644
index 000000000..1fe5c7f73
--- /dev/null
+++ b/Source/WebCore/fileapi/FileReaderSync.cpp
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(BLOB)
+
+#include "FileReaderSync.h"
+
+#include "Blob.h"
+#include "BlobURL.h"
+#include "FileException.h"
+#include "FileReaderLoader.h"
+#include <wtf/ArrayBuffer.h>
+#include <wtf/PassRefPtr.h>
+
+namespace WebCore {
+
+FileReaderSync::FileReaderSync()
+{
+}
+
+PassRefPtr<ArrayBuffer> FileReaderSync::readAsArrayBuffer(ScriptExecutionContext* scriptExecutionContext, Blob* blob, ExceptionCode& ec)
+{
+ if (!blob)
+ return 0;
+
+ FileReaderLoader loader(FileReaderLoader::ReadAsArrayBuffer, 0);
+ startLoading(scriptExecutionContext, loader, blob, ec);
+
+ return loader.arrayBufferResult();
+}
+
+String FileReaderSync::readAsBinaryString(ScriptExecutionContext* scriptExecutionContext, Blob* blob, ExceptionCode& ec)
+{
+ if (!blob)
+ return String();
+
+ FileReaderLoader loader(FileReaderLoader::ReadAsBinaryString, 0);
+ startLoading(scriptExecutionContext, loader, blob, ec);
+ return loader.stringResult();
+}
+
+String FileReaderSync::readAsText(ScriptExecutionContext* scriptExecutionContext, Blob* blob, const String& encoding, ExceptionCode& ec)
+{
+ if (!blob)
+ return String();
+
+ FileReaderLoader loader(FileReaderLoader::ReadAsText, 0);
+ loader.setEncoding(encoding);
+ startLoading(scriptExecutionContext, loader, blob, ec);
+ return loader.stringResult();
+}
+
+String FileReaderSync::readAsDataURL(ScriptExecutionContext* scriptExecutionContext, Blob* blob, ExceptionCode& ec)
+{
+ if (!blob)
+ return String();
+
+ FileReaderLoader loader(FileReaderLoader::ReadAsDataURL, 0);
+ loader.setDataType(blob->type());
+ startLoading(scriptExecutionContext, loader, blob, ec);
+ return loader.stringResult();
+}
+
+void FileReaderSync::startLoading(ScriptExecutionContext* scriptExecutionContext, FileReaderLoader& loader, Blob* blob, ExceptionCode& ec)
+{
+ loader.start(scriptExecutionContext, blob);
+ ec = FileException::ErrorCodeToExceptionCode(loader.errorCode());
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(BLOB)
diff --git a/Source/WebCore/fileapi/FileReaderSync.h b/Source/WebCore/fileapi/FileReaderSync.h
new file mode 100644
index 000000000..9fe5c3003
--- /dev/null
+++ b/Source/WebCore/fileapi/FileReaderSync.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileReaderSync_h
+#define FileReaderSync_h
+
+#if ENABLE(BLOB)
+
+#include <wtf/Forward.h>
+#include <wtf/RefCounted.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class Blob;
+class FileReaderLoader;
+class ScriptExecutionContext;
+
+typedef int ExceptionCode;
+
+class FileReaderSync : public RefCounted<FileReaderSync> {
+public:
+ static PassRefPtr<FileReaderSync> create()
+ {
+ return adoptRef(new FileReaderSync());
+ }
+
+ virtual ~FileReaderSync() { }
+
+ PassRefPtr<ArrayBuffer> readAsArrayBuffer(ScriptExecutionContext*, Blob*, ExceptionCode&);
+ String readAsBinaryString(ScriptExecutionContext*, Blob*, ExceptionCode&);
+ String readAsText(ScriptExecutionContext* scriptExecutionContext, Blob* blob, ExceptionCode& ec)
+ {
+ return readAsText(scriptExecutionContext, blob, "", ec);
+ }
+ String readAsText(ScriptExecutionContext*, Blob*, const String& encoding, ExceptionCode&);
+ String readAsDataURL(ScriptExecutionContext*, Blob*, ExceptionCode&);
+
+private:
+ FileReaderSync();
+
+ void startLoading(ScriptExecutionContext*, FileReaderLoader&, Blob*, ExceptionCode&);
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(BLOB)
+
+#endif // FileReaderSync_h
diff --git a/Source/WebCore/fileapi/FileReaderSync.idl b/Source/WebCore/fileapi/FileReaderSync.idl
new file mode 100644
index 000000000..62242f15a
--- /dev/null
+++ b/Source/WebCore/fileapi/FileReaderSync.idl
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module html {
+ interface [
+ Conditional=BLOB,
+ Constructor,
+ NoStaticTables
+ ] FileReaderSync {
+ [CallWith=ScriptExecutionContext] ArrayBuffer readAsArrayBuffer(in Blob blob)
+ raises(FileException);
+ [CallWith=ScriptExecutionContext, ConvertScriptString] DOMString readAsBinaryString(in Blob blob)
+ raises(FileException);
+ [CallWith=ScriptExecutionContext, ConvertScriptString] DOMString readAsText(in Blob blob, in [Optional] DOMString encoding)
+ raises(FileException);
+ [CallWith=ScriptExecutionContext, ConvertScriptString] DOMString readAsDataURL(in Blob blob)
+ raises(FileException);
+ };
+}
diff --git a/Source/WebCore/fileapi/FileStreamProxy.cpp b/Source/WebCore/fileapi/FileStreamProxy.cpp
new file mode 100644
index 000000000..d43506566
--- /dev/null
+++ b/Source/WebCore/fileapi/FileStreamProxy.cpp
@@ -0,0 +1,225 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
+
+#include "FileStreamProxy.h"
+
+#include "Blob.h"
+#include "CrossThreadTask.h"
+#include "FileStream.h"
+#include "FileThread.h"
+#include "FileThreadTask.h"
+#include "PlatformString.h"
+#include "ScriptExecutionContext.h"
+
+namespace WebCore {
+
+inline FileStreamProxy::FileStreamProxy(ScriptExecutionContext* context, FileStreamClient* client)
+ : AsyncFileStream(client)
+ , m_context(context)
+ , m_stream(FileStream::create())
+{
+}
+
+PassRefPtr<FileStreamProxy> FileStreamProxy::create(ScriptExecutionContext* context, FileStreamClient* client)
+{
+ RefPtr<FileStreamProxy> proxy = adoptRef(new FileStreamProxy(context, client));
+
+ // Hold an ref so that the instance will not get deleted while there are tasks on the file thread.
+ // This is balanced by the deref in derefProxyOnContext below.
+ proxy->ref();
+
+ proxy->fileThread()->postTask(createFileThreadTask(proxy.get(), &FileStreamProxy::startOnFileThread));
+
+ return proxy.release();
+}
+
+FileStreamProxy::~FileStreamProxy()
+{
+}
+
+FileThread* FileStreamProxy::fileThread()
+{
+ ASSERT(m_context->isContextThread());
+ ASSERT(m_context->fileThread());
+ return m_context->fileThread();
+}
+
+static void didStart(ScriptExecutionContext*, FileStreamProxy* proxy)
+{
+ if (proxy->client())
+ proxy->client()->didStart();
+}
+
+void FileStreamProxy::startOnFileThread()
+{
+ if (!client())
+ return;
+ m_stream->start();
+ m_context->postTask(createCallbackTask(&didStart, AllowCrossThreadAccess(this)));
+}
+
+void FileStreamProxy::stop()
+{
+ // Clear the client so that we won't be calling callbacks on the client.
+ setClient(0);
+
+ fileThread()->unscheduleTasks(m_stream.get());
+ fileThread()->postTask(createFileThreadTask(this, &FileStreamProxy::stopOnFileThread));
+}
+
+static void derefProxyOnContext(ScriptExecutionContext*, FileStreamProxy* proxy)
+{
+ ASSERT(proxy->hasOneRef());
+ proxy->deref();
+}
+
+void FileStreamProxy::stopOnFileThread()
+{
+ m_stream->stop();
+ m_context->postTask(createCallbackTask(&derefProxyOnContext, AllowCrossThreadAccess(this)));
+}
+
+static void didGetSize(ScriptExecutionContext*, FileStreamProxy* proxy, long long size)
+{
+ if (proxy->client())
+ proxy->client()->didGetSize(size);
+}
+
+void FileStreamProxy::getSize(const String& path, double expectedModificationTime)
+{
+ fileThread()->postTask(createFileThreadTask(this, &FileStreamProxy::getSizeOnFileThread, path, expectedModificationTime));
+}
+
+void FileStreamProxy::getSizeOnFileThread(const String& path, double expectedModificationTime)
+{
+ long long size = m_stream->getSize(path, expectedModificationTime);
+ m_context->postTask(createCallbackTask(&didGetSize, AllowCrossThreadAccess(this), size));
+}
+
+static void didOpen(ScriptExecutionContext*, FileStreamProxy* proxy, bool success)
+{
+ if (proxy->client())
+ proxy->client()->didOpen(success);
+}
+
+void FileStreamProxy::openForRead(const String& path, long long offset, long long length)
+{
+ fileThread()->postTask(createFileThreadTask(this, &FileStreamProxy::openForReadOnFileThread, path, offset, length));
+}
+
+void FileStreamProxy::openForReadOnFileThread(const String& path, long long offset, long long length)
+{
+ bool success = m_stream->openForRead(path, offset, length);
+ m_context->postTask(createCallbackTask(&didOpen, AllowCrossThreadAccess(this), success));
+}
+
+void FileStreamProxy::openForWrite(const String& path)
+{
+ fileThread()->postTask(
+ createFileThreadTask(this,
+ &FileStreamProxy::openForWriteOnFileThread, path));
+}
+
+void FileStreamProxy::openForWriteOnFileThread(const String& path)
+{
+ bool success = m_stream->openForWrite(path);
+ m_context->postTask(createCallbackTask(&didOpen, AllowCrossThreadAccess(this), success));
+}
+
+void FileStreamProxy::close()
+{
+ fileThread()->postTask(createFileThreadTask(this, &FileStreamProxy::closeOnFileThread));
+}
+
+void FileStreamProxy::closeOnFileThread()
+{
+ m_stream->close();
+}
+
+static void didRead(ScriptExecutionContext*, FileStreamProxy* proxy, int bytesRead)
+{
+ if (proxy->client())
+ proxy->client()->didRead(bytesRead);
+}
+
+void FileStreamProxy::read(char* buffer, int length)
+{
+ fileThread()->postTask(
+ createFileThreadTask(this, &FileStreamProxy::readOnFileThread,
+ AllowCrossThreadAccess(buffer), length));
+}
+
+void FileStreamProxy::readOnFileThread(char* buffer, int length)
+{
+ int bytesRead = m_stream->read(buffer, length);
+ m_context->postTask(createCallbackTask(&didRead, AllowCrossThreadAccess(this), bytesRead));
+}
+
+static void didWrite(ScriptExecutionContext*, FileStreamProxy* proxy, int bytesWritten)
+{
+ if (proxy->client())
+ proxy->client()->didWrite(bytesWritten);
+}
+
+void FileStreamProxy::write(const KURL& blobURL, long long position, int length)
+{
+ fileThread()->postTask(createFileThreadTask(this, &FileStreamProxy::writeOnFileThread, blobURL, position, length));
+}
+
+void FileStreamProxy::writeOnFileThread(const KURL& blobURL, long long position, int length)
+{
+ int bytesWritten = m_stream->write(blobURL, position, length);
+ m_context->postTask(createCallbackTask(&didWrite, AllowCrossThreadAccess(this), bytesWritten));
+}
+
+static void didTruncate(ScriptExecutionContext*, FileStreamProxy* proxy, bool success)
+{
+ if (proxy->client())
+ proxy->client()->didTruncate(success);
+}
+
+void FileStreamProxy::truncate(long long position)
+{
+ fileThread()->postTask(createFileThreadTask(this, &FileStreamProxy::truncateOnFileThread, position));
+}
+
+void FileStreamProxy::truncateOnFileThread(long long position)
+{
+ bool success = m_stream->truncate(position);
+ m_context->postTask(createCallbackTask(&didTruncate, AllowCrossThreadAccess(this), success));
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/FileStreamProxy.h b/Source/WebCore/fileapi/FileStreamProxy.h
new file mode 100644
index 000000000..ce9a1054c
--- /dev/null
+++ b/Source/WebCore/fileapi/FileStreamProxy.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileStreamProxy_h
+#define FileStreamProxy_h
+
+#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
+
+#include "AsyncFileStream.h"
+#include <wtf/Forward.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class FileStream;
+class FileThread;
+class KURL;
+class ScriptExecutionContext;
+
+// A proxy module that asynchronously calls corresponding FileStream methods on the file thread. Note: you must call stop() first and then release the reference to destruct the FileStreamProxy instance.
+class FileStreamProxy : public AsyncFileStream {
+public:
+ static PassRefPtr<FileStreamProxy> create(ScriptExecutionContext*, FileStreamClient*);
+ virtual ~FileStreamProxy();
+
+ virtual void getSize(const String& path, double expectedModificationTime);
+ virtual void openForRead(const String& path, long long offset, long long length);
+ virtual void openForWrite(const String& path);
+ virtual void close();
+ virtual void read(char* buffer, int length);
+ virtual void write(const KURL& blobURL, long long position, int length);
+ virtual void truncate(long long position);
+
+ // Stops the proxy and scedules it to be destructed. All the pending tasks will be aborted and the file stream will be closed.
+ // Note: the caller should deref the instance immediately after calling stop().
+ virtual void stop();
+
+private:
+ FileStreamProxy(ScriptExecutionContext*, FileStreamClient*);
+
+ FileThread* fileThread();
+
+ // Called on File thread.
+ void startOnFileThread();
+ void stopOnFileThread();
+ void getSizeOnFileThread(const String& path, double expectedModificationTime);
+ void openForReadOnFileThread(const String& path, long long offset, long long length);
+ void openForWriteOnFileThread(const String& path);
+ void closeOnFileThread();
+ void readOnFileThread(char* buffer, int length);
+ void writeOnFileThread(const KURL& blobURL, long long position, int length);
+ void truncateOnFileThread(long long position);
+
+ RefPtr<ScriptExecutionContext> m_context;
+ RefPtr<FileStream> m_stream;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
+
+#endif // FileStreamProxy_h
diff --git a/Source/WebCore/fileapi/FileSystemCallback.h b/Source/WebCore/fileapi/FileSystemCallback.h
new file mode 100644
index 000000000..63f8416d3
--- /dev/null
+++ b/Source/WebCore/fileapi/FileSystemCallback.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileSystemCallback_h
+#define FileSystemCallback_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class DOMFileSystem;
+
+class FileSystemCallback : public RefCounted<FileSystemCallback> {
+public:
+ virtual ~FileSystemCallback() { }
+ virtual bool handleEvent(DOMFileSystem*) = 0;
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // FileSystemCallback_h
diff --git a/Source/WebCore/fileapi/FileSystemCallback.idl b/Source/WebCore/fileapi/FileSystemCallback.idl
new file mode 100644
index 000000000..cf686ff1b
--- /dev/null
+++ b/Source/WebCore/fileapi/FileSystemCallback.idl
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module storage {
+ interface [
+ Conditional=FILE_SYSTEM,
+ Callback
+ ] FileSystemCallback {
+ boolean handleEvent(in DOMFileSystem fileSystem);
+ };
+}
diff --git a/Source/WebCore/fileapi/FileSystemCallbacks.cpp b/Source/WebCore/fileapi/FileSystemCallbacks.cpp
new file mode 100644
index 000000000..06f3b9383
--- /dev/null
+++ b/Source/WebCore/fileapi/FileSystemCallbacks.cpp
@@ -0,0 +1,319 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "FileSystemCallbacks.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "AsyncFileSystem.h"
+#include "AsyncFileWriter.h"
+#include "DOMFilePath.h"
+#include "DOMFileSystemBase.h"
+#include "DirectoryEntry.h"
+#include "DirectoryReader.h"
+#include "EntriesCallback.h"
+#include "EntryArray.h"
+#include "EntryCallback.h"
+#include "ErrorCallback.h"
+#include "FileEntry.h"
+#include "FileError.h"
+#include "FileMetadata.h"
+#include "FileSystemCallback.h"
+#include "FileWriterBase.h"
+#include "FileWriterBaseCallback.h"
+#include "Metadata.h"
+#include "MetadataCallback.h"
+#include "ScriptExecutionContext.h"
+#include "VoidCallback.h"
+
+namespace WebCore {
+
+FileSystemCallbacksBase::FileSystemCallbacksBase(PassRefPtr<ErrorCallback> errorCallback)
+ : m_errorCallback(errorCallback)
+{
+}
+
+FileSystemCallbacksBase::~FileSystemCallbacksBase()
+{
+}
+
+void FileSystemCallbacksBase::didSucceed()
+{
+ // Each subclass must implement an appropriate one.
+ ASSERT_NOT_REACHED();
+}
+
+void FileSystemCallbacksBase::didOpenFileSystem(const String&, PassOwnPtr<AsyncFileSystem>)
+{
+ // Each subclass must implement an appropriate one.
+ ASSERT_NOT_REACHED();
+}
+
+void FileSystemCallbacksBase::didReadMetadata(const FileMetadata&)
+{
+ // Each subclass must implement an appropriate one.
+ ASSERT_NOT_REACHED();
+}
+
+void FileSystemCallbacksBase::didReadDirectoryEntries(bool)
+{
+ // Each subclass must implement an appropriate one.
+ ASSERT_NOT_REACHED();
+}
+
+void FileSystemCallbacksBase::didReadDirectoryEntry(const String&, bool)
+{
+ // Each subclass must implement an appropriate one.
+ ASSERT_NOT_REACHED();
+}
+
+void FileSystemCallbacksBase::didCreateFileWriter(PassOwnPtr<AsyncFileWriter>, long long)
+{
+ // Each subclass must implement an appropriate one.
+ ASSERT_NOT_REACHED();
+}
+
+void FileSystemCallbacksBase::didFail(int code)
+{
+ if (m_errorCallback) {
+ m_errorCallback->handleEvent(FileError::create(static_cast<FileError::ErrorCode>(code)).get());
+ m_errorCallback.clear();
+ }
+}
+
+// EntryCallbacks -------------------------------------------------------------
+
+PassOwnPtr<EntryCallbacks> EntryCallbacks::create(PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, PassRefPtr<DOMFileSystemBase> fileSystem, const String& expectedPath, bool isDirectory)
+{
+ return adoptPtr(new EntryCallbacks(successCallback, errorCallback, fileSystem, expectedPath, isDirectory));
+}
+
+EntryCallbacks::EntryCallbacks(PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, PassRefPtr<DOMFileSystemBase> fileSystem, const String& expectedPath, bool isDirectory)
+ : FileSystemCallbacksBase(errorCallback)
+ , m_successCallback(successCallback)
+ , m_fileSystem(fileSystem)
+ , m_expectedPath(expectedPath)
+ , m_isDirectory(isDirectory)
+{
+}
+
+void EntryCallbacks::didSucceed()
+{
+ if (m_successCallback) {
+ if (m_isDirectory)
+ m_successCallback->handleEvent(DirectoryEntry::create(m_fileSystem, m_expectedPath).get());
+ else
+ m_successCallback->handleEvent(FileEntry::create(m_fileSystem, m_expectedPath).get());
+ }
+ m_successCallback.clear();
+}
+
+// EntriesCallbacks -----------------------------------------------------------
+
+PassOwnPtr<EntriesCallbacks> EntriesCallbacks::create(PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, PassRefPtr<DirectoryReaderBase> directoryReader, const String& basePath)
+{
+ return adoptPtr(new EntriesCallbacks(successCallback, errorCallback, directoryReader, basePath));
+}
+
+EntriesCallbacks::EntriesCallbacks(PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, PassRefPtr<DirectoryReaderBase> directoryReader, const String& basePath)
+ : FileSystemCallbacksBase(errorCallback)
+ , m_successCallback(successCallback)
+ , m_directoryReader(directoryReader)
+ , m_basePath(basePath)
+ , m_entries(EntryArray::create())
+{
+ ASSERT(m_directoryReader);
+}
+
+void EntriesCallbacks::didReadDirectoryEntry(const String& name, bool isDirectory)
+{
+ if (isDirectory)
+ m_entries->append(DirectoryEntry::create(m_directoryReader->filesystem(), DOMFilePath::append(m_basePath, name)));
+ else
+ m_entries->append(FileEntry::create(m_directoryReader->filesystem(), DOMFilePath::append(m_basePath, name)));
+}
+
+void EntriesCallbacks::didReadDirectoryEntries(bool hasMore)
+{
+ m_directoryReader->setHasMoreEntries(hasMore);
+ if (m_successCallback)
+ m_successCallback->handleEvent(m_entries.get());
+}
+
+// FileSystemCallbacks --------------------------------------------------------
+
+PassOwnPtr<FileSystemCallbacks> FileSystemCallbacks::create(PassRefPtr<FileSystemCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, ScriptExecutionContext* scriptExecutionContext)
+{
+ return adoptPtr(new FileSystemCallbacks(successCallback, errorCallback, scriptExecutionContext));
+}
+
+FileSystemCallbacks::FileSystemCallbacks(PassRefPtr<FileSystemCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, ScriptExecutionContext* context)
+ : FileSystemCallbacksBase(errorCallback)
+ , m_successCallback(successCallback)
+ , m_scriptExecutionContext(context)
+{
+}
+
+void FileSystemCallbacks::didOpenFileSystem(const String& name, PassOwnPtr<AsyncFileSystem> asyncFileSystem)
+{
+ if (m_successCallback) {
+ ASSERT(asyncFileSystem);
+ RefPtr<DOMFileSystem> fileSystem = DOMFileSystem::create(m_scriptExecutionContext.get(), name, asyncFileSystem);
+ m_successCallback->handleEvent(fileSystem.get());
+ m_scriptExecutionContext.clear();
+ }
+ m_successCallback.clear();
+}
+
+// ResolveURICallbacks --------------------------------------------------------
+
+namespace {
+
+class ErrorCallbackWrapper : public ErrorCallback {
+public:
+ static PassRefPtr<ErrorCallbackWrapper> create(PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, PassRefPtr<DirectoryEntry> root, const String& filePath)
+ {
+ return adoptRef(new ErrorCallbackWrapper(successCallback, errorCallback, root, filePath));
+ }
+
+ virtual bool handleEvent(FileError* error)
+ {
+ ASSERT(error);
+ if (error->code() == FileError::TYPE_MISMATCH_ERR)
+ m_root->getFile(m_filePath, 0, m_successCallback, m_errorCallback);
+ else if (m_errorCallback)
+ m_errorCallback->handleEvent(error);
+ return true;
+ }
+
+private:
+ ErrorCallbackWrapper(PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, PassRefPtr<DirectoryEntry> root, const String& filePath)
+ : m_successCallback(successCallback)
+ , m_errorCallback(errorCallback)
+ , m_root(root)
+ , m_filePath(filePath)
+ {
+ ASSERT(m_root);
+ }
+
+ RefPtr<EntryCallback> m_successCallback;
+ RefPtr<ErrorCallback> m_errorCallback;
+ RefPtr<DirectoryEntry> m_root;
+ String m_filePath;
+};
+
+} // namespace
+
+PassOwnPtr<ResolveURICallbacks> ResolveURICallbacks::create(PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, ScriptExecutionContext* scriptExecutionContext, const String& filePath)
+{
+ return adoptPtr(new ResolveURICallbacks(successCallback, errorCallback, scriptExecutionContext, filePath));
+}
+
+ResolveURICallbacks::ResolveURICallbacks(PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, ScriptExecutionContext* context, const String& filePath)
+ : FileSystemCallbacksBase(errorCallback)
+ , m_successCallback(successCallback)
+ , m_scriptExecutionContext(context)
+ , m_filePath(filePath)
+{
+}
+
+void ResolveURICallbacks::didOpenFileSystem(const String& name, PassOwnPtr<AsyncFileSystem> asyncFileSystem)
+{
+ ASSERT(asyncFileSystem);
+ RefPtr<DirectoryEntry> root = DOMFileSystem::create(m_scriptExecutionContext.get(), name, asyncFileSystem)->root();
+ root->getDirectory(m_filePath, 0, m_successCallback, ErrorCallbackWrapper::create(m_successCallback, m_errorCallback, root, m_filePath));
+}
+
+// MetadataCallbacks ----------------------------------------------------------
+
+PassOwnPtr<MetadataCallbacks> MetadataCallbacks::create(PassRefPtr<MetadataCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ return adoptPtr(new MetadataCallbacks(successCallback, errorCallback));
+}
+
+MetadataCallbacks::MetadataCallbacks(PassRefPtr<MetadataCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+ : FileSystemCallbacksBase(errorCallback)
+ , m_successCallback(successCallback)
+{
+}
+
+void MetadataCallbacks::didReadMetadata(const FileMetadata& metadata)
+{
+ if (m_successCallback)
+ m_successCallback->handleEvent(Metadata::create(metadata.modificationTime).get());
+ m_successCallback.clear();
+}
+
+// FileWriterBaseCallbacks ----------------------------------------------------------
+
+PassOwnPtr<FileWriterBaseCallbacks> FileWriterBaseCallbacks::create(PassRefPtr<FileWriterBase> fileWriter, PassRefPtr<FileWriterBaseCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ return adoptPtr(new FileWriterBaseCallbacks(fileWriter, successCallback, errorCallback));
+}
+
+FileWriterBaseCallbacks::FileWriterBaseCallbacks(PassRefPtr<FileWriterBase> fileWriter, PassRefPtr<FileWriterBaseCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+ : FileSystemCallbacksBase(errorCallback)
+ , m_fileWriter(fileWriter)
+ , m_successCallback(successCallback)
+{
+}
+
+void FileWriterBaseCallbacks::didCreateFileWriter(PassOwnPtr<AsyncFileWriter> asyncFileWriter, long long length)
+{
+ m_fileWriter->initialize(asyncFileWriter, length);
+ if (m_successCallback)
+ m_successCallback->handleEvent(m_fileWriter.release().get());
+ m_successCallback.clear();
+}
+
+// VoidCallbacks --------------------------------------------------------------
+
+PassOwnPtr<VoidCallbacks> VoidCallbacks::create(PassRefPtr<VoidCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ return adoptPtr(new VoidCallbacks(successCallback, errorCallback));
+}
+
+VoidCallbacks::VoidCallbacks(PassRefPtr<VoidCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+ : FileSystemCallbacksBase(errorCallback)
+ , m_successCallback(successCallback)
+{
+}
+
+void VoidCallbacks::didSucceed()
+{
+ if (m_successCallback)
+ m_successCallback->handleEvent();
+ m_successCallback.clear();
+}
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/FileSystemCallbacks.h b/Source/WebCore/fileapi/FileSystemCallbacks.h
new file mode 100644
index 000000000..7f68625ac
--- /dev/null
+++ b/Source/WebCore/fileapi/FileSystemCallbacks.h
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileSystemCallbacks_h
+#define FileSystemCallbacks_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "AsyncFileSystemCallbacks.h"
+#include "PlatformString.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class AsyncFileWriter;
+class DOMFileSystemBase;
+class DirectoryReaderBase;
+class EntriesCallback;
+class EntryArray;
+class EntryCallback;
+class ErrorCallback;
+struct FileMetadata;
+class FileSystemCallback;
+class FileWriterBase;
+class FileWriterBaseCallback;
+class MetadataCallback;
+class ScriptExecutionContext;
+class VoidCallback;
+
+class FileSystemCallbacksBase : public AsyncFileSystemCallbacks {
+public:
+ virtual ~FileSystemCallbacksBase();
+
+ // For EntryCallbacks and VoidCallbacks.
+ virtual void didSucceed();
+
+ // For FileSystemCallbacks.
+ virtual void didOpenFileSystem(const String& name, PassOwnPtr<AsyncFileSystem>);
+
+ // For MetadataCallbacks.
+ virtual void didReadMetadata(const FileMetadata&);
+
+ // For EntriesCallbacks. didReadDirectoryEntry is called each time the API reads an entry, and didReadDirectoryDone is called when a chunk of entries have been read (i.e. good time to call back to the application). If hasMore is true there can be more chunks.
+ virtual void didReadDirectoryEntry(const String& name, bool isDirectory);
+ virtual void didReadDirectoryEntries(bool hasMore);
+
+ // For createFileWriter.
+ virtual void didCreateFileWriter(PassOwnPtr<AsyncFileWriter>, long long length);
+
+ // For ErrorCallback.
+ virtual void didFail(int code);
+
+protected:
+ FileSystemCallbacksBase(PassRefPtr<ErrorCallback> errorCallback);
+ RefPtr<ErrorCallback> m_errorCallback;
+};
+
+// Subclasses ----------------------------------------------------------------
+
+class EntryCallbacks : public FileSystemCallbacksBase {
+public:
+ static PassOwnPtr<EntryCallbacks> create(PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, PassRefPtr<DOMFileSystemBase>, const String& expectedPath, bool isDirectory);
+ virtual void didSucceed();
+
+private:
+ EntryCallbacks(PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, PassRefPtr<DOMFileSystemBase>, const String& expectedPath, bool isDirectory);
+ RefPtr<EntryCallback> m_successCallback;
+ RefPtr<DOMFileSystemBase> m_fileSystem;
+ String m_expectedPath;
+ bool m_isDirectory;
+};
+
+class EntriesCallbacks : public FileSystemCallbacksBase {
+public:
+ static PassOwnPtr<EntriesCallbacks> create(PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>, PassRefPtr<DirectoryReaderBase>, const String& basePath);
+ virtual void didReadDirectoryEntry(const String& name, bool isDirectory);
+ virtual void didReadDirectoryEntries(bool hasMore);
+
+private:
+ EntriesCallbacks(PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>, PassRefPtr<DirectoryReaderBase>, const String& basePath);
+ RefPtr<EntriesCallback> m_successCallback;
+ RefPtr<DirectoryReaderBase> m_directoryReader;
+ String m_basePath;
+ RefPtr<EntryArray> m_entries;
+};
+
+class FileSystemCallbacks : public FileSystemCallbacksBase {
+public:
+ static PassOwnPtr<FileSystemCallbacks> create(PassRefPtr<FileSystemCallback>, PassRefPtr<ErrorCallback>, ScriptExecutionContext*);
+ virtual void didOpenFileSystem(const String& name, PassOwnPtr<AsyncFileSystem>);
+
+private:
+ FileSystemCallbacks(PassRefPtr<FileSystemCallback>, PassRefPtr<ErrorCallback>, ScriptExecutionContext*);
+ RefPtr<FileSystemCallback> m_successCallback;
+ RefPtr<ScriptExecutionContext> m_scriptExecutionContext;
+};
+
+class ResolveURICallbacks : public FileSystemCallbacksBase {
+public:
+ static PassOwnPtr<ResolveURICallbacks> create(PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, ScriptExecutionContext*, const String& filePath);
+ virtual void didOpenFileSystem(const String& name, PassOwnPtr<AsyncFileSystem>);
+
+private:
+ ResolveURICallbacks(PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, ScriptExecutionContext*, const String& filePath);
+ RefPtr<EntryCallback> m_successCallback;
+ RefPtr<ScriptExecutionContext> m_scriptExecutionContext;
+ String m_filePath;
+};
+
+class MetadataCallbacks : public FileSystemCallbacksBase {
+public:
+ static PassOwnPtr<MetadataCallbacks> create(PassRefPtr<MetadataCallback>, PassRefPtr<ErrorCallback>);
+ virtual void didReadMetadata(const FileMetadata&);
+
+private:
+ MetadataCallbacks(PassRefPtr<MetadataCallback>, PassRefPtr<ErrorCallback>);
+ RefPtr<MetadataCallback> m_successCallback;
+};
+
+class FileWriterBaseCallbacks : public FileSystemCallbacksBase {
+public:
+ static PassOwnPtr<FileWriterBaseCallbacks> create(PassRefPtr<FileWriterBase>, PassRefPtr<FileWriterBaseCallback>, PassRefPtr<ErrorCallback>);
+ virtual void didCreateFileWriter(PassOwnPtr<AsyncFileWriter>, long long length);
+
+private:
+ FileWriterBaseCallbacks(PassRefPtr<FileWriterBase>, PassRefPtr<FileWriterBaseCallback>, PassRefPtr<ErrorCallback>);
+ RefPtr<FileWriterBase> m_fileWriter;
+ RefPtr<FileWriterBaseCallback> m_successCallback;
+};
+
+class VoidCallbacks : public FileSystemCallbacksBase {
+public:
+ static PassOwnPtr<VoidCallbacks> create(PassRefPtr<VoidCallback>, PassRefPtr<ErrorCallback>);
+ virtual void didSucceed();
+
+private:
+ VoidCallbacks(PassRefPtr<VoidCallback>, PassRefPtr<ErrorCallback>);
+ RefPtr<VoidCallback> m_successCallback;
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // FileSystemCallbacks_h
diff --git a/Source/WebCore/fileapi/FileThread.cpp b/Source/WebCore/fileapi/FileThread.cpp
new file mode 100644
index 000000000..4d55630e4
--- /dev/null
+++ b/Source/WebCore/fileapi/FileThread.cpp
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
+
+#include "FileThread.h"
+
+#include "AutodrainedPool.h"
+#include "Logging.h"
+
+namespace WebCore {
+
+FileThread::FileThread()
+ : m_threadID(0)
+{
+ m_selfRef = this;
+}
+
+FileThread::~FileThread()
+{
+ ASSERT(m_queue.killed());
+}
+
+bool FileThread::start()
+{
+ MutexLocker lock(m_threadCreationMutex);
+ if (m_threadID)
+ return true;
+ m_threadID = createThread(FileThread::fileThreadStart, this, "WebCore: File");
+ return m_threadID;
+}
+
+void FileThread::stop()
+{
+ m_queue.kill();
+}
+
+void FileThread::postTask(PassOwnPtr<Task> task)
+{
+ m_queue.append(task);
+}
+
+class SameInstancePredicate {
+public:
+ SameInstancePredicate(const void* instance) : m_instance(instance) { }
+ bool operator()(FileThread::Task* task) const { return task->instance() == m_instance; }
+private:
+ const void* m_instance;
+};
+
+void FileThread::unscheduleTasks(const void* instance)
+{
+ SameInstancePredicate predicate(instance);
+ m_queue.removeIf(predicate);
+}
+
+void* FileThread::fileThreadStart(void* arg)
+{
+ FileThread* fileThread = static_cast<FileThread*>(arg);
+ return fileThread->runLoop();
+}
+
+void* FileThread::runLoop()
+{
+ {
+ // Wait for FileThread::start() to complete to have m_threadID
+ // established before starting the main loop.
+ MutexLocker lock(m_threadCreationMutex);
+ LOG(FileAPI, "Started FileThread %p", this);
+ }
+
+ AutodrainedPool pool;
+ while (OwnPtr<Task> task = m_queue.waitForMessage()) {
+ task->performTask();
+ pool.cycle();
+ }
+
+ LOG(FileAPI, "About to detach thread %i and clear the ref to FileThread %p, which currently has %i ref(s)", m_threadID, this, refCount());
+
+ detachThread(m_threadID);
+
+ // Clear the self refptr, possibly resulting in deletion
+ m_selfRef = 0;
+
+ return 0;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/FileThread.h b/Source/WebCore/fileapi/FileThread.h
new file mode 100644
index 000000000..9c1d267b3
--- /dev/null
+++ b/Source/WebCore/fileapi/FileThread.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileThread_h
+#define FileThread_h
+
+#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
+
+#include <wtf/MessageQueue.h>
+#include <wtf/PassOwnPtr.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/Threading.h>
+
+namespace WebCore {
+
+class FileStream;
+
+class FileThread : public ThreadSafeRefCounted<FileThread> {
+public:
+ static PassRefPtr<FileThread> create()
+ {
+ return adoptRef(new FileThread());
+ }
+
+ ~FileThread();
+
+ bool start();
+ void stop();
+
+ class Task {
+ WTF_MAKE_NONCOPYABLE(Task);
+ public:
+ virtual ~Task() { }
+ virtual void performTask() = 0;
+ void* instance() const { return m_instance; }
+ protected:
+ Task(void* instance) : m_instance(instance) { }
+ void* m_instance;
+ };
+
+ void postTask(PassOwnPtr<Task> task);
+
+ void unscheduleTasks(const void* instance);
+
+private:
+ FileThread();
+
+ static void* fileThreadStart(void*);
+ void* runLoop();
+
+ ThreadIdentifier m_threadID;
+ RefPtr<FileThread> m_selfRef;
+ MessageQueue<Task> m_queue;
+
+ Mutex m_threadCreationMutex;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
+
+#endif // FileThread_h
diff --git a/Source/WebCore/fileapi/FileThreadTask.h b/Source/WebCore/fileapi/FileThreadTask.h
new file mode 100644
index 000000000..8a8ffcb7b
--- /dev/null
+++ b/Source/WebCore/fileapi/FileThreadTask.h
@@ -0,0 +1,227 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileThreadTask_h
+#define FileThreadTask_h
+
+#include "CrossThreadCopier.h"
+#include "CrossThreadTask.h"
+#include "FileThread.h"
+#include <wtf/PassOwnPtr.h>
+#include <wtf/PassRefPtr.h>
+
+namespace WebCore {
+
+template<typename T>
+class FileThreadTask0 : public FileThread::Task {
+public:
+ typedef void (T::*Method)();
+ typedef FileThreadTask0<T> FileThreadTaskImpl;
+
+ static PassOwnPtr<FileThreadTaskImpl> create(T* instance, Method method)
+ {
+ return adoptPtr(new FileThreadTaskImpl(instance, method));
+ }
+
+private:
+ FileThreadTask0(T* instance, Method method)
+ : FileThread::Task(instance)
+ , m_method(method)
+ {
+ }
+
+ virtual void performTask()
+ {
+ (*static_cast<T*>(instance()).*m_method)();
+ }
+
+private:
+ Method m_method;
+};
+
+template<typename T, typename P1, typename MP1>
+class FileThreadTask1 : public FileThread::Task {
+public:
+ typedef void (T::*Method)(MP1);
+ typedef FileThreadTask1<T, P1, MP1> FileThreadTaskImpl;
+ typedef typename CrossThreadTaskTraits<P1>::ParamType Param1;
+
+ static PassOwnPtr<FileThreadTaskImpl> create(T* instance, Method method, Param1 parameter1)
+ {
+ return adoptPtr(new FileThreadTaskImpl(instance, method, parameter1));
+ }
+
+private:
+ FileThreadTask1(T* instance, Method method, Param1 parameter1)
+ : FileThread::Task(instance)
+ , m_method(method)
+ , m_parameter1(parameter1)
+ {
+ }
+
+ virtual void performTask()
+ {
+ (*static_cast<T*>(instance()).*m_method)(m_parameter1);
+ }
+
+private:
+ Method m_method;
+ P1 m_parameter1;
+};
+
+template<typename T, typename P1, typename MP1, typename P2, typename MP2>
+class FileThreadTask2 : public FileThread::Task {
+public:
+ typedef void (T::*Method)(MP1, MP2);
+ typedef FileThreadTask2<T, P1, MP1, P2, MP2> FileThreadTaskImpl;
+ typedef typename CrossThreadTaskTraits<P1>::ParamType Param1;
+ typedef typename CrossThreadTaskTraits<P2>::ParamType Param2;
+
+ static PassOwnPtr<FileThreadTaskImpl> create(T* instance, Method method, Param1 parameter1, Param2 parameter2)
+ {
+ return adoptPtr(new FileThreadTaskImpl(instance, method, parameter1, parameter2));
+ }
+
+private:
+ FileThreadTask2(T* instance, Method method, Param1 parameter1, Param2 parameter2)
+ : FileThread::Task(instance)
+ , m_method(method)
+ , m_parameter1(parameter1)
+ , m_parameter2(parameter2)
+ {
+ }
+
+ virtual void performTask()
+ {
+ (*static_cast<T*>(instance()).*m_method)(m_parameter1, m_parameter2);
+ }
+
+private:
+ Method m_method;
+ P1 m_parameter1;
+ P2 m_parameter2;
+};
+
+template<typename T, typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3>
+class FileThreadTask3 : public FileThread::Task {
+public:
+ typedef void (T::*Method)(MP1, MP2, MP3);
+ typedef FileThreadTask3<T, P1, MP1, P2, MP2, P3, MP3> FileThreadTaskImpl;
+ typedef typename CrossThreadTaskTraits<P1>::ParamType Param1;
+ typedef typename CrossThreadTaskTraits<P2>::ParamType Param2;
+ typedef typename CrossThreadTaskTraits<P3>::ParamType Param3;
+
+ static PassOwnPtr<FileThreadTaskImpl> create(T* instance, Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3)
+ {
+ return adoptPtr(new FileThreadTaskImpl(instance, method, parameter1, parameter2, parameter3));
+ }
+
+private:
+ FileThreadTask3(T* instance, Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3)
+ : FileThread::Task(instance)
+ , m_method(method)
+ , m_parameter1(parameter1)
+ , m_parameter2(parameter2)
+ , m_parameter3(parameter3)
+ {
+ }
+
+ virtual void performTask()
+ {
+ (*static_cast<T*>(instance()).*m_method)(m_parameter1, m_parameter2, m_parameter3);
+ }
+
+private:
+ Method m_method;
+ P1 m_parameter1;
+ P2 m_parameter2;
+ P3 m_parameter3;
+};
+
+template<typename T>
+PassOwnPtr<FileThread::Task> createFileThreadTask(
+ T* const callee,
+ void (T::*method)());
+
+template<typename T>
+PassOwnPtr<FileThread::Task> createFileThreadTask(
+ T* const callee,
+ void (T::*method)())
+{
+ return FileThreadTask0<T>::create(
+ callee,
+ method);
+}
+
+template<typename T, typename P1, typename MP1>
+PassOwnPtr<FileThread::Task> createFileThreadTask(
+ T* const callee,
+ void (T::*method)(MP1),
+ const P1& parameter1)
+{
+ return FileThreadTask1<T, typename CrossThreadCopier<P1>::Type, MP1>::create(
+ callee,
+ method,
+ CrossThreadCopier<P1>::copy(parameter1));
+}
+
+template<typename T, typename P1, typename MP1, typename P2, typename MP2>
+PassOwnPtr<FileThread::Task> createFileThreadTask(
+ T* const callee,
+ void (T::*method)(MP1, MP2),
+ const P1& parameter1,
+ const P2& parameter2)
+{
+ return FileThreadTask2<T, typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2>::create(
+ callee,
+ method,
+ CrossThreadCopier<P1>::copy(parameter1),
+ CrossThreadCopier<P2>::copy(parameter2));
+}
+
+template<typename T, typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3>
+PassOwnPtr<FileThread::Task> createFileThreadTask(
+ T* const callee,
+ void (T::*method)(MP1, MP2, MP3),
+ const P1& parameter1,
+ const P2& parameter2,
+ const P3& parameter3)
+{
+ return FileThreadTask3<T, typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3>::create(
+ callee,
+ method,
+ CrossThreadCopier<P1>::copy(parameter1),
+ CrossThreadCopier<P2>::copy(parameter2),
+ CrossThreadCopier<P3>::copy(parameter3));
+}
+
+} // namespace WebCore
+
+#endif // FileThreadTask_h
diff --git a/Source/WebCore/fileapi/FileWriter.cpp b/Source/WebCore/fileapi/FileWriter.cpp
new file mode 100644
index 000000000..2b25cfaf9
--- /dev/null
+++ b/Source/WebCore/fileapi/FileWriter.cpp
@@ -0,0 +1,286 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "FileWriter.h"
+
+#include "AsyncFileWriter.h"
+#include "Blob.h"
+#include "ExceptionCode.h"
+#include "FileError.h"
+#include "FileException.h"
+#include "ProgressEvent.h"
+
+namespace WebCore {
+
+static const int kMaxRecursionDepth = 3;
+
+FileWriter::FileWriter(ScriptExecutionContext* context)
+ : ActiveDOMObject(context, this)
+ , m_readyState(INIT)
+ , m_isOperationInProgress(false)
+ , m_queuedOperation(OperationNone)
+ , m_bytesWritten(0)
+ , m_bytesToWrite(0)
+ , m_truncateLength(-1)
+ , m_numAborts(0)
+ , m_recursionDepth(0)
+{
+}
+
+FileWriter::~FileWriter()
+{
+ ASSERT(!m_recursionDepth);
+ if (m_readyState == WRITING)
+ stop();
+}
+
+const AtomicString& FileWriter::interfaceName() const
+{
+ return eventNames().interfaceForFileWriter;
+}
+
+bool FileWriter::hasPendingActivity() const
+{
+ return m_readyState == WRITING || ActiveDOMObject::hasPendingActivity();
+}
+
+bool FileWriter::canSuspend() const
+{
+ // FIXME: It is not currently possible to suspend a FileWriter, so pages with FileWriter can not go into page cache.
+ return false;
+}
+
+void FileWriter::stop()
+{
+ // Make sure we've actually got something to stop, and haven't already called abort().
+ if (writer() && m_readyState == WRITING && m_isOperationInProgress && m_queuedOperation == OperationNone)
+ writer()->abort();
+ m_blobBeingWritten.clear();
+ m_readyState = DONE;
+}
+
+void FileWriter::write(Blob* data, ExceptionCode& ec)
+{
+ ASSERT(writer());
+ ASSERT(data);
+ ASSERT(m_truncateLength == -1);
+ if (m_readyState == WRITING) {
+ setError(FileError::INVALID_STATE_ERR, ec);
+ return;
+ }
+ if (!data) {
+ setError(FileError::TYPE_MISMATCH_ERR, ec);
+ return;
+ }
+ if (m_recursionDepth > kMaxRecursionDepth) {
+ setError(FileError::SECURITY_ERR, ec);
+ return;
+ }
+ m_blobBeingWritten = data;
+ m_readyState = WRITING;
+ m_bytesWritten = 0;
+ m_bytesToWrite = data->size();
+ ASSERT(m_queuedOperation == OperationNone);
+ if (m_isOperationInProgress) // We must be waiting for an abort to complete, since m_readyState wasn't WRITING.
+ m_queuedOperation = OperationWrite;
+ else
+ writer()->write(position(), m_blobBeingWritten.get());
+ m_isOperationInProgress = true;
+ fireEvent(eventNames().writestartEvent);
+}
+
+void FileWriter::seek(long long position, ExceptionCode& ec)
+{
+ ASSERT(writer());
+ if (m_readyState == WRITING) {
+ setError(FileError::INVALID_STATE_ERR, ec);
+ return;
+ }
+
+ ASSERT(m_truncateLength == -1);
+ ASSERT(m_queuedOperation == OperationNone);
+ seekInternal(position);
+}
+
+void FileWriter::truncate(long long position, ExceptionCode& ec)
+{
+ ASSERT(writer());
+ ASSERT(m_truncateLength == -1);
+ if (m_readyState == WRITING || position < 0) {
+ setError(FileError::INVALID_STATE_ERR, ec);
+ return;
+ }
+ if (m_recursionDepth > kMaxRecursionDepth) {
+ setError(FileError::SECURITY_ERR, ec);
+ return;
+ }
+ m_readyState = WRITING;
+ m_bytesWritten = 0;
+ m_bytesToWrite = 0;
+ m_truncateLength = position;
+ ASSERT(m_queuedOperation == OperationNone);
+ if (m_isOperationInProgress) // We must be waiting for an abort to complete.
+ m_queuedOperation = OperationTruncate;
+ else
+ writer()->truncate(m_truncateLength);
+ m_isOperationInProgress = true;
+ fireEvent(eventNames().writestartEvent);
+}
+
+void FileWriter::abort(ExceptionCode& ec)
+{
+ ASSERT(writer());
+ if (m_readyState != WRITING) {
+ return;
+ }
+ ++m_numAborts;
+
+ if (m_isOperationInProgress)
+ writer()->abort();
+ m_queuedOperation = OperationNone;
+ m_blobBeingWritten.clear();
+ m_truncateLength = -1;
+ signalCompletion(FileError::ABORT_ERR);
+}
+
+void FileWriter::didWrite(long long bytes, bool complete)
+{
+ ASSERT(m_readyState == WRITING);
+ ASSERT(m_truncateLength == -1);
+ ASSERT(m_isOperationInProgress);
+ ASSERT(bytes + m_bytesWritten > 0);
+ ASSERT(bytes + m_bytesWritten <= m_bytesToWrite);
+ m_bytesWritten += bytes;
+ ASSERT((m_bytesWritten == m_bytesToWrite) || !complete);
+ setPosition(position() + bytes);
+ if (position() > length())
+ setLength(position());
+ // TODO: Throttle to no more frequently than every 50ms.
+ int numAborts = m_numAborts;
+ fireEvent(eventNames().progressEvent);
+ // We could get an abort in the handler for this event. If we do, it's
+ // already handled the cleanup and signalCompletion call.
+ if (complete && numAborts == m_numAborts) {
+ m_blobBeingWritten.clear();
+ m_isOperationInProgress = false;
+ signalCompletion(FileError::OK);
+ }
+}
+
+void FileWriter::didTruncate()
+{
+ ASSERT(m_truncateLength >= 0);
+ setLength(m_truncateLength);
+ if (position() > length())
+ setPosition(length());
+ m_isOperationInProgress = false;
+ signalCompletion(FileError::OK);
+}
+
+void FileWriter::didFail(FileError::ErrorCode code)
+{
+ ASSERT(m_isOperationInProgress);
+ m_isOperationInProgress = false;
+ ASSERT(code != FileError::OK);
+ if (code == FileError::ABORT_ERR) {
+ Operation operation = m_queuedOperation;
+ m_queuedOperation = OperationNone;
+ doOperation(operation);
+ } else {
+ ASSERT(m_queuedOperation == OperationNone);
+ ASSERT(m_readyState == WRITING);
+ m_blobBeingWritten.clear();
+ signalCompletion(code);
+ }
+}
+
+void FileWriter::doOperation(Operation operation)
+{
+ ASSERT(m_queuedOperation == OperationNone);
+ ASSERT(!m_isOperationInProgress);
+ ASSERT(operation == OperationNone || operation == OperationWrite || operation == OperationTruncate);
+ switch (operation) {
+ case OperationWrite:
+ ASSERT(m_truncateLength == -1);
+ ASSERT(m_blobBeingWritten.get());
+ ASSERT(m_readyState == WRITING);
+ writer()->write(position(), m_blobBeingWritten.get());
+ m_isOperationInProgress = true;
+ break;
+ case OperationTruncate:
+ ASSERT(m_truncateLength >= 0);
+ ASSERT(m_readyState == WRITING);
+ writer()->truncate(m_truncateLength);
+ m_isOperationInProgress = true;
+ break;
+ case OperationNone:
+ ASSERT(m_truncateLength == -1);
+ ASSERT(!m_blobBeingWritten.get());
+ ASSERT(m_readyState == DONE);
+ break;
+ }
+}
+
+void FileWriter::signalCompletion(FileError::ErrorCode code)
+{
+ m_readyState = DONE;
+ m_truncateLength = -1;
+ if (FileError::OK != code) {
+ m_error = FileError::create(code);
+ if (FileError::ABORT_ERR == code)
+ fireEvent(eventNames().abortEvent);
+ else
+ fireEvent(eventNames().errorEvent);
+ } else
+ fireEvent(eventNames().writeEvent);
+ fireEvent(eventNames().writeendEvent);
+}
+
+void FileWriter::fireEvent(const AtomicString& type)
+{
+ ++m_recursionDepth;
+ dispatchEvent(ProgressEvent::create(type, true, m_bytesWritten, m_bytesToWrite));
+ --m_recursionDepth;
+ ASSERT(m_recursionDepth >= 0);
+}
+
+void FileWriter::setError(FileError::ErrorCode errorCode, ExceptionCode& ec)
+{
+ ec = FileException::ErrorCodeToExceptionCode(errorCode);
+ m_error = FileError::create(errorCode);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/FileWriter.h b/Source/WebCore/fileapi/FileWriter.h
new file mode 100644
index 000000000..2b597a188
--- /dev/null
+++ b/Source/WebCore/fileapi/FileWriter.h
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileWriter_h
+#define FileWriter_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "ActiveDOMObject.h"
+#include "AsyncFileWriterClient.h"
+#include "EventTarget.h"
+#include "FileWriterBase.h"
+#include "ScriptExecutionContext.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class Blob;
+class ScriptExecutionContext;
+
+class FileWriter : public FileWriterBase, public ActiveDOMObject, public EventTarget, public AsyncFileWriterClient {
+public:
+ static PassRefPtr<FileWriter> create(ScriptExecutionContext* context)
+ {
+ return adoptRef(new FileWriter(context));
+ }
+
+ enum ReadyState {
+ INIT = 0,
+ WRITING = 1,
+ DONE = 2
+ };
+
+ void write(Blob*, ExceptionCode&);
+ void seek(long long position, ExceptionCode&);
+ void truncate(long long length, ExceptionCode&);
+ void abort(ExceptionCode&);
+ ReadyState readyState() const { return m_readyState; }
+ FileError* error() const { return m_error.get(); }
+
+ // AsyncFileWriterClient
+ void didWrite(long long bytes, bool complete);
+ void didTruncate();
+ void didFail(FileError::ErrorCode);
+
+ // ActiveDOMObject
+ virtual bool canSuspend() const;
+ virtual bool hasPendingActivity() const;
+ virtual void stop();
+
+ // EventTarget
+ virtual const AtomicString& interfaceName() const;
+ virtual ScriptExecutionContext* scriptExecutionContext() const { return ActiveDOMObject::scriptExecutionContext(); }
+
+ using RefCounted<FileWriterBase>::ref;
+ using RefCounted<FileWriterBase>::deref;
+
+ DEFINE_ATTRIBUTE_EVENT_LISTENER(writestart);
+ DEFINE_ATTRIBUTE_EVENT_LISTENER(progress);
+ DEFINE_ATTRIBUTE_EVENT_LISTENER(write);
+ DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
+ DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
+ DEFINE_ATTRIBUTE_EVENT_LISTENER(writeend);
+
+private:
+ enum Operation {
+ OperationNone,
+ OperationWrite,
+ OperationTruncate
+ };
+
+ FileWriter(ScriptExecutionContext*);
+
+ virtual ~FileWriter();
+
+ // EventTarget
+ virtual void refEventTarget() { ref(); }
+ virtual void derefEventTarget() { deref(); }
+ virtual EventTargetData* eventTargetData() { return &m_eventTargetData; }
+ virtual EventTargetData* ensureEventTargetData() { return &m_eventTargetData; }
+
+ void doOperation(Operation);
+
+ void signalCompletion(FileError::ErrorCode);
+
+ void fireEvent(const AtomicString& type);
+
+ void setError(FileError::ErrorCode, ExceptionCode&);
+
+ RefPtr<FileError> m_error;
+ EventTargetData m_eventTargetData;
+ ReadyState m_readyState;
+ bool m_isOperationInProgress;
+ Operation m_queuedOperation;
+ long long m_bytesWritten;
+ long long m_bytesToWrite;
+ long long m_truncateLength;
+ long long m_numAborts;
+ long long m_recursionDepth;
+ RefPtr<Blob> m_blobBeingWritten;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // FileWriter_h
diff --git a/Source/WebCore/fileapi/FileWriter.idl b/Source/WebCore/fileapi/FileWriter.idl
new file mode 100644
index 000000000..4de2c9fdb
--- /dev/null
+++ b/Source/WebCore/fileapi/FileWriter.idl
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module html {
+ interface [
+ Conditional=FILE_SYSTEM,
+ ActiveDOMObject,
+ CallWith=ScriptExecutionContext,
+ EventTarget,
+ NoStaticTables
+ ] FileWriter {
+ // ready states
+ const unsigned short INIT = 0;
+ const unsigned short WRITING = 1;
+ const unsigned short DONE = 2;
+ readonly attribute unsigned short readyState;
+
+ // async write/modify methods
+ void write(in Blob data) raises (FileException);
+ void seek(in long long position) raises (FileException);
+ void truncate(in long long size) raises (FileException);
+
+ void abort() raises (FileException);
+
+ readonly attribute FileError error;
+ readonly attribute long long position;
+ readonly attribute long long length;
+
+ attribute EventListener onwritestart;
+ attribute EventListener onprogress;
+ attribute EventListener onwrite;
+ attribute EventListener onabort;
+ attribute EventListener onerror;
+ attribute EventListener onwriteend;
+ };
+}
diff --git a/Source/WebCore/fileapi/FileWriterBase.cpp b/Source/WebCore/fileapi/FileWriterBase.cpp
new file mode 100644
index 000000000..dc55bb871
--- /dev/null
+++ b/Source/WebCore/fileapi/FileWriterBase.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "FileWriterBase.h"
+
+#include "AsyncFileWriter.h"
+#include "Blob.h"
+#include "ExceptionCode.h"
+#include "FileError.h"
+#include "FileException.h"
+#include "ProgressEvent.h"
+
+namespace WebCore {
+
+FileWriterBase::~FileWriterBase()
+{
+}
+
+void FileWriterBase::initialize(PassOwnPtr<AsyncFileWriter> writer, long long length)
+{
+ ASSERT(!m_writer);
+ ASSERT(length >= 0);
+ m_writer = writer;
+ m_length = length;
+}
+
+FileWriterBase::FileWriterBase()
+ : m_position(0)
+{
+}
+
+void FileWriterBase::seekInternal(long long position)
+{
+ if (position > m_length)
+ position = m_length;
+ else if (position < 0)
+ position = m_length + position;
+ if (position < 0)
+ position = 0;
+ m_position = position;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/FileWriterBase.h b/Source/WebCore/fileapi/FileWriterBase.h
new file mode 100644
index 000000000..3e913abcf
--- /dev/null
+++ b/Source/WebCore/fileapi/FileWriterBase.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileWriterBase_h
+#define FileWriterBase_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include <wtf/OwnPtr.h>
+#include <wtf/PassOwnPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class AsyncFileWriter;
+
+typedef int ExceptionCode;
+
+class FileWriterBase : public RefCounted<FileWriterBase> {
+public:
+ virtual ~FileWriterBase();
+ void initialize(PassOwnPtr<AsyncFileWriter>, long long length);
+
+ long long position() const
+ {
+ return m_position;
+ }
+ long long length() const
+ {
+ return m_length;
+ }
+
+protected:
+ FileWriterBase();
+
+ AsyncFileWriter* writer()
+ {
+ return m_writer.get();
+ }
+
+ void setPosition(long long position)
+ {
+ m_position = position;
+ }
+
+ void setLength(long long length)
+ {
+ m_length = length;
+ }
+
+ void seekInternal(long long position);
+
+private:
+ friend class WTF::RefCounted<FileWriterBase>;
+
+ OwnPtr<AsyncFileWriter> m_writer;
+ long long m_position;
+ long long m_length;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // FileWriterBase_h
diff --git a/Source/WebCore/fileapi/FileWriterBaseCallback.h b/Source/WebCore/fileapi/FileWriterBaseCallback.h
new file mode 100644
index 000000000..51e8ab7a0
--- /dev/null
+++ b/Source/WebCore/fileapi/FileWriterBaseCallback.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileWriterBaseCallback_h
+#define FileWriterBaseCallback_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class FileWriterBase;
+
+class FileWriterBaseCallback : public RefCounted<FileWriterBaseCallback> {
+public:
+ virtual ~FileWriterBaseCallback() { }
+ virtual bool handleEvent(FileWriterBase*) = 0;
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // FileWriterBaseCallback_h
diff --git a/Source/WebCore/fileapi/FileWriterCallback.h b/Source/WebCore/fileapi/FileWriterCallback.h
new file mode 100644
index 000000000..3f9e746fa
--- /dev/null
+++ b/Source/WebCore/fileapi/FileWriterCallback.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileWriterCallback_h
+#define FileWriterCallback_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class FileWriter;
+
+class FileWriterCallback : public RefCounted<FileWriterCallback> {
+public:
+ virtual ~FileWriterCallback() { }
+ virtual bool handleEvent(FileWriter*) = 0;
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // FileWriterCallback_h
diff --git a/Source/WebCore/fileapi/FileWriterCallback.idl b/Source/WebCore/fileapi/FileWriterCallback.idl
new file mode 100644
index 000000000..df82fed8d
--- /dev/null
+++ b/Source/WebCore/fileapi/FileWriterCallback.idl
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module fileapi {
+ interface [
+ Conditional=FILE_SYSTEM,
+ Callback
+ ] FileWriterCallback {
+ boolean handleEvent(in FileWriter fileWriter);
+ };
+}
diff --git a/Source/WebCore/fileapi/FileWriterSync.cpp b/Source/WebCore/fileapi/FileWriterSync.cpp
new file mode 100644
index 000000000..28a68f818
--- /dev/null
+++ b/Source/WebCore/fileapi/FileWriterSync.cpp
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "FileWriterSync.h"
+
+#include "AsyncFileWriter.h"
+#include "Blob.h"
+#include "FileException.h"
+
+namespace WebCore {
+
+void FileWriterSync::write(Blob* data, ExceptionCode& ec)
+{
+ ASSERT(writer());
+ ASSERT(m_complete);
+ ec = 0;
+ if (!data) {
+ ec = FileException::TYPE_MISMATCH_ERR;
+ return;
+ }
+
+ prepareForWrite();
+ writer()->write(position(), data);
+ writer()->waitForOperationToComplete();
+ ASSERT(m_complete);
+ ec = FileException::ErrorCodeToExceptionCode(m_error);
+ if (ec)
+ return;
+ setPosition(position() + data->size());
+ if (position() > length())
+ setLength(position());
+}
+
+void FileWriterSync::seek(long long position, ExceptionCode& ec)
+{
+ ASSERT(writer());
+ ASSERT(m_complete);
+ ec = 0;
+ seekInternal(position);
+}
+
+void FileWriterSync::truncate(long long offset, ExceptionCode& ec)
+{
+ ASSERT(writer());
+ ASSERT(m_complete);
+ ec = 0;
+ if (offset < 0) {
+ ec = FileException::INVALID_STATE_ERR;
+ return;
+ }
+ prepareForWrite();
+ writer()->truncate(offset);
+ writer()->waitForOperationToComplete();
+ ASSERT(m_complete);
+ ec = FileException::ErrorCodeToExceptionCode(m_error);
+ if (ec)
+ return;
+ if (offset < position())
+ setPosition(offset);
+ setLength(offset);
+}
+
+void FileWriterSync::didWrite(long long bytes, bool complete)
+{
+ ASSERT(m_error == FileError::OK);
+ ASSERT(!m_complete);
+#ifndef NDEBUG
+ m_complete = complete;
+#else
+ ASSERT_UNUSED(complete, complete);
+#endif
+}
+
+void FileWriterSync::didTruncate()
+{
+ ASSERT(m_error == FileError::OK);
+ ASSERT(!m_complete);
+#ifndef NDEBUG
+ m_complete = true;
+#endif
+}
+
+void FileWriterSync::didFail(FileError::ErrorCode error)
+{
+ ASSERT(m_error == FileError::OK);
+ m_error = error;
+ ASSERT(!m_complete);
+#ifndef NDEBUG
+ m_complete = true;
+#endif
+}
+
+FileWriterSync::FileWriterSync()
+ : m_error(FileError::OK)
+#ifndef NDEBUG
+ , m_complete(true)
+#endif
+{
+}
+
+void FileWriterSync::prepareForWrite()
+{
+ ASSERT(m_complete);
+ m_error = FileError::OK;
+#ifndef NDEBUG
+ m_complete = false;
+#endif
+}
+
+FileWriterSync::~FileWriterSync()
+{
+}
+
+
+} // namespace WebCore
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/FileWriterSync.h b/Source/WebCore/fileapi/FileWriterSync.h
new file mode 100644
index 000000000..d9abefb80
--- /dev/null
+++ b/Source/WebCore/fileapi/FileWriterSync.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileWriterSync_h
+#define FileWriterSync_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "AsyncFileWriterClient.h"
+#include "FileError.h"
+#include "FileWriterBase.h"
+#include <wtf/PassRefPtr.h>
+
+namespace WebCore {
+
+class Blob;
+
+typedef int ExceptionCode;
+
+class FileWriterSync : public FileWriterBase, public AsyncFileWriterClient {
+public:
+ static PassRefPtr<FileWriterSync> create()
+ {
+ return adoptRef(new FileWriterSync());
+ }
+ virtual ~FileWriterSync();
+
+ // FileWriterBase
+ void write(Blob*, ExceptionCode&);
+ void seek(long long position, ExceptionCode&);
+ void truncate(long long length, ExceptionCode&);
+
+ // AsyncFileWriterClient, via FileWriterBase
+ void didWrite(long long bytes, bool complete);
+ void didTruncate();
+ void didFail(FileError::ErrorCode);
+
+private:
+ FileWriterSync();
+ void prepareForWrite();
+
+ FileError::ErrorCode m_error;
+#ifndef NDEBUG
+ bool m_complete;
+#endif
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // FileWriter_h
diff --git a/Source/WebCore/fileapi/FileWriterSync.idl b/Source/WebCore/fileapi/FileWriterSync.idl
new file mode 100644
index 000000000..c561bb43b
--- /dev/null
+++ b/Source/WebCore/fileapi/FileWriterSync.idl
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module html {
+ interface [
+ Conditional=FILE_SYSTEM,
+ ] FileWriterSync {
+ // synchronous write/modify methods
+ void write(in Blob data) raises (FileException);
+ void seek(in long long position) raises (FileException);
+ void truncate(in long long size) raises (FileException);
+
+ readonly attribute long long position;
+ readonly attribute long long length;
+ };
+}
diff --git a/Source/WebCore/fileapi/LocalFileSystem.cpp b/Source/WebCore/fileapi/LocalFileSystem.cpp
new file mode 100644
index 000000000..8f0169eea
--- /dev/null
+++ b/Source/WebCore/fileapi/LocalFileSystem.cpp
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LocalFileSystem.h"
+
+#if PLATFORM(CHROMIUM)
+#error "Chromium should not compile this file and instead define its own version of these factories."
+#endif
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "CrossThreadTask.h"
+#include "DOMFileSystem.h"
+#include "ErrorCallback.h"
+#include "ExceptionCode.h"
+#include "FileError.h"
+#include "FileSystemCallback.h"
+#include "FileSystemCallbacks.h"
+#include "ScriptExecutionContext.h"
+#include "SecurityOrigin.h"
+#include <wtf/MainThread.h>
+#include <wtf/PassRefPtr.h>
+
+namespace WebCore {
+
+LocalFileSystem* LocalFileSystem::s_instance = 0;
+
+void LocalFileSystem::initializeLocalFileSystem(const String& basePath)
+{
+ // FIXME: Should initialize the quota settings as well.
+ ASSERT(isMainThread());
+ ASSERT(!s_instance);
+ if (s_instance)
+ return;
+
+ OwnPtr<LocalFileSystem> localFileSystem = adoptPtr(new LocalFileSystem(basePath));
+ s_instance = localFileSystem.leakPtr();
+}
+
+LocalFileSystem& LocalFileSystem::localFileSystem()
+{
+ // initializeLocalFileSystem must be called prior calling this.
+ ASSERT(s_instance);
+ return *s_instance;
+}
+
+String LocalFileSystem::fileSystemBasePath() const
+{
+ return m_basePath;
+}
+
+static void openFileSystem(ScriptExecutionContext*, const String& basePath, const String& identifier, AsyncFileSystem::Type type, bool create, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
+{
+ AsyncFileSystem::openFileSystem(basePath, identifier, type, create, callbacks);
+}
+
+void LocalFileSystem::readFileSystem(ScriptExecutionContext* context, AsyncFileSystem::Type type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks, bool)
+{
+ // AsyncFileSystem::openFileSystem calls callbacks synchronously, so the method needs to be called asynchronously.
+ context->postTask(createCallbackTask(&openFileSystem, fileSystemBasePath(), context->securityOrigin()->databaseIdentifier(), type, false, callbacks));
+}
+
+void LocalFileSystem::requestFileSystem(ScriptExecutionContext* context, AsyncFileSystem::Type type, long long, PassOwnPtr<AsyncFileSystemCallbacks> callbacks, bool)
+{
+ // AsyncFileSystem::openFileSystem calls callbacks synchronously, so the method needs to be called asynchronously.
+ context->postTask(createCallbackTask(&openFileSystem, fileSystemBasePath(), context->securityOrigin()->databaseIdentifier(), type, true, callbacks));
+}
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/LocalFileSystem.h b/Source/WebCore/fileapi/LocalFileSystem.h
new file mode 100644
index 000000000..247bb2cdf
--- /dev/null
+++ b/Source/WebCore/fileapi/LocalFileSystem.h
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef LocalFileSystem_h
+#define LocalFileSystem_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "AsyncFileSystem.h"
+#include "PlatformString.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class ErrorCallback;
+class FileSystemCallback;
+class ScriptExecutionContext;
+
+// Keeps per-process information and provides an entry point to open a file system.
+class LocalFileSystem {
+ WTF_MAKE_NONCOPYABLE(LocalFileSystem);
+public:
+ // Returns a per-process instance of LocalFileSystem.
+ // Note that LocalFileSystem::initializeLocalFileSystem must be called before
+ // calling this one.
+ static LocalFileSystem& localFileSystem();
+
+ // Does not create the root path for file system, just reads it if available.
+ void readFileSystem(ScriptExecutionContext*, AsyncFileSystem::Type, PassOwnPtr<AsyncFileSystemCallbacks>, bool synchronous = false);
+
+ void requestFileSystem(ScriptExecutionContext*, AsyncFileSystem::Type, long long size, PassOwnPtr<AsyncFileSystemCallbacks>, bool synchronous = false);
+
+#if !PLATFORM(CHROMIUM)
+ // This call is not thread-safe; must be called before any worker threads are created.
+ void initializeLocalFileSystem(const String&);
+
+ String fileSystemBasePath() const;
+#endif
+
+private:
+ LocalFileSystem(const String& basePath)
+ : m_basePath(basePath)
+ {
+ }
+
+ static LocalFileSystem* s_instance;
+
+ // An inner class that enforces thread-safe string access.
+ class SystemBasePath {
+ public:
+ explicit SystemBasePath(const String& path) : m_value(path) { }
+ operator String() const
+ {
+ return m_value.isolatedCopy();
+ }
+ private:
+ String m_value;
+ };
+
+ SystemBasePath m_basePath;
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // LocalFileSystem_h
diff --git a/Source/WebCore/fileapi/Metadata.h b/Source/WebCore/fileapi/Metadata.h
new file mode 100644
index 000000000..b70806b09
--- /dev/null
+++ b/Source/WebCore/fileapi/Metadata.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef Metadata_h
+#define Metadata_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class Metadata : public RefCounted<Metadata> {
+public:
+ static PassRefPtr<Metadata> create(double modificationTime)
+ {
+ return adoptRef(new Metadata(modificationTime));
+ }
+
+ static PassRefPtr<Metadata> create(Metadata* metadata)
+ {
+ return adoptRef(new Metadata(metadata->m_modificationTime));
+ }
+
+ // Needs to return epoch time in milliseconds for Date.
+ double modificationTime() const { return m_modificationTime * 1000.0; }
+
+private:
+ Metadata(double modificationTime)
+ : m_modificationTime(modificationTime)
+ {
+ }
+
+ double m_modificationTime;
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // Metadata_h
diff --git a/Source/WebCore/fileapi/Metadata.idl b/Source/WebCore/fileapi/Metadata.idl
new file mode 100644
index 000000000..df50b66d7
--- /dev/null
+++ b/Source/WebCore/fileapi/Metadata.idl
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module storage {
+ interface [
+ Conditional=FILE_SYSTEM,
+ NoStaticTables
+ ] Metadata {
+ readonly attribute Date modificationTime;
+ };
+}
diff --git a/Source/WebCore/fileapi/MetadataCallback.h b/Source/WebCore/fileapi/MetadataCallback.h
new file mode 100644
index 000000000..725a0c18f
--- /dev/null
+++ b/Source/WebCore/fileapi/MetadataCallback.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef MetadataCallback_h
+#define MetadataCallback_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class Metadata;
+
+class MetadataCallback : public RefCounted<MetadataCallback> {
+public:
+ virtual ~MetadataCallback() { }
+ virtual bool handleEvent(Metadata*) = 0;
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // MetadataCallback_h
diff --git a/Source/WebCore/fileapi/MetadataCallback.idl b/Source/WebCore/fileapi/MetadataCallback.idl
new file mode 100644
index 000000000..44ca18054
--- /dev/null
+++ b/Source/WebCore/fileapi/MetadataCallback.idl
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module storage {
+ interface [
+ Conditional=FILE_SYSTEM,
+ Callback
+ ] MetadataCallback {
+ boolean handleEvent(in Metadata metadata);
+ };
+}
diff --git a/Source/WebCore/fileapi/OperationNotAllowedException.cpp b/Source/WebCore/fileapi/OperationNotAllowedException.cpp
new file mode 100644
index 000000000..e97cfa035
--- /dev/null
+++ b/Source/WebCore/fileapi/OperationNotAllowedException.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GOOGLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
+
+#include "OperationNotAllowedException.h"
+
+namespace WebCore {
+
+// FIXME: This should be an array of structs to pair the names and descriptions.
+static const char* const exceptionNames[] = {
+ "NOT_ALLOWED_ERR"
+};
+
+static const char* const exceptionDescriptions[] = {
+ "A read method was called while the object was in the LOADING state due to a previous read call."
+};
+
+COMPILE_ASSERT(WTF_ARRAY_LENGTH(exceptionNames) == WTF_ARRAY_LENGTH(exceptionDescriptions), OperationNotAllowedExceptionTablesMustMatch);
+
+bool OperationNotAllowedException::initializeDescription(ExceptionCode ec, ExceptionCodeDescription* description)
+{
+ if (ec < OperationNotAllowedExceptionOffset || ec > OperationNotAllowedExceptionMax)
+ return false;
+
+ description->typeName = "DOM OperationNotAllowed";
+ description->code = ec - OperationNotAllowedExceptionOffset;
+ description->type = OperationNotAllowedExceptionType;
+
+ size_t tableSize = WTF_ARRAY_LENGTH(exceptionNames);
+ size_t tableIndex = ec - NOT_ALLOWED_ERR;
+
+ description->name = tableIndex < tableSize ? exceptionNames[tableIndex] : 0;
+ description->description = tableIndex < tableSize ? exceptionDescriptions[tableIndex] : 0;
+
+ return true;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/OperationNotAllowedException.h b/Source/WebCore/fileapi/OperationNotAllowedException.h
new file mode 100644
index 000000000..c3e95595e
--- /dev/null
+++ b/Source/WebCore/fileapi/OperationNotAllowedException.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef OperationNotAllowedException_h
+#define OperationNotAllowedException_h
+
+#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
+
+#include "ExceptionBase.h"
+
+namespace WebCore {
+
+class OperationNotAllowedException : public ExceptionBase {
+public:
+ static PassRefPtr<OperationNotAllowedException> create(const ExceptionCodeDescription& description)
+ {
+ return adoptRef(new OperationNotAllowedException(description));
+ }
+
+ static const int OperationNotAllowedExceptionOffset = 1300;
+ static const int OperationNotAllowedExceptionMax = 1399;
+
+ enum OperationNotAllowedExceptionCode {
+ NOT_ALLOWED_ERR = OperationNotAllowedExceptionOffset + 1,
+ };
+
+ static bool initializeDescription(ExceptionCode, ExceptionCodeDescription*);
+
+private:
+ OperationNotAllowedException(const ExceptionCodeDescription& description)
+ : ExceptionBase(description)
+ {
+ }
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
+
+#endif // OperationNotAllowedException_h
diff --git a/Source/WebCore/fileapi/OperationNotAllowedException.idl b/Source/WebCore/fileapi/OperationNotAllowedException.idl
new file mode 100644
index 000000000..215cbc436
--- /dev/null
+++ b/Source/WebCore/fileapi/OperationNotAllowedException.idl
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module html {
+ interface [
+ Conditional=BLOB|FILE_SYSTEM,
+ DontCheckEnums,
+ NoStaticTables
+ ] OperationNotAllowedException {
+ readonly attribute unsigned short code;
+ readonly attribute DOMString name;
+ readonly attribute DOMString message;
+
+#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
+ // Override in a Mozilla compatible format
+ [DontEnum] DOMString toString();
+#endif
+
+ const unsigned short NOT_ALLOWED_ERR = 1;
+ };
+}
diff --git a/Source/WebCore/fileapi/SyncCallbackHelper.h b/Source/WebCore/fileapi/SyncCallbackHelper.h
new file mode 100644
index 000000000..950adf470
--- /dev/null
+++ b/Source/WebCore/fileapi/SyncCallbackHelper.h
@@ -0,0 +1,188 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SyncCallbackHelper_h
+#define SyncCallbackHelper_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "DirectoryEntry.h"
+#include "EntriesCallback.h"
+#include "EntryArraySync.h"
+#include "EntryCallback.h"
+#include "ErrorCallback.h"
+#include "FileEntry.h"
+#include "FileError.h"
+#include "FileException.h"
+#include "FileSystemCallback.h"
+#include "MetadataCallback.h"
+#include "VoidCallback.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class AsyncFileSystem;
+class DirectoryEntrySync;
+class EntryArraySync;
+class EntrySync;
+class FileEntrySync;
+
+typedef int ExceptionCode;
+
+// A helper template for FileSystemSync implementation.
+template <typename SuccessCallback, typename ObserverType, typename CallbackArg, typename ResultType>
+class SyncCallbackHelper {
+ WTF_MAKE_NONCOPYABLE(SyncCallbackHelper);
+public:
+ typedef SyncCallbackHelper<SuccessCallback, ObserverType, CallbackArg, ResultType> HelperType;
+ SyncCallbackHelper(ObserverType* observer = 0)
+ : m_observer(observer)
+ , m_successCallback(SuccessCallbackImpl::create(this))
+ , m_errorCallback(ErrorCallbackImpl::create(this))
+ , m_exceptionCode(0)
+ , m_completed(false)
+ {
+ }
+
+ PassRefPtr<ResultType> getResult(ExceptionCode& ec)
+ {
+ if (m_observer) {
+ while (!m_completed) {
+ if (!m_observer->waitForOperationToComplete()) {
+ m_exceptionCode = FileException::ABORT_ERR;
+ break;
+ }
+ }
+ }
+ ec = m_exceptionCode;
+ return m_result.release();
+ }
+
+ PassRefPtr<SuccessCallback> successCallback() { return m_successCallback; }
+ PassRefPtr<ErrorCallback> errorCallback() { return m_errorCallback; }
+
+private:
+ class SuccessCallbackImpl : public SuccessCallback {
+ public:
+ static PassRefPtr<SuccessCallbackImpl> create(HelperType* helper)
+ {
+ return adoptRef(new SuccessCallbackImpl(helper));
+ }
+
+ virtual void handleEvent()
+ {
+ m_helper->setError(0);
+ }
+
+ virtual bool handleEvent(CallbackArg* arg)
+ {
+ m_helper->setResult(ResultType::create(arg));
+ return true;
+ }
+
+ private:
+ SuccessCallbackImpl(HelperType* helper)
+ : m_helper(helper)
+ {
+ }
+ HelperType* m_helper;
+ };
+
+ class ErrorCallbackImpl : public ErrorCallback {
+ public:
+ static PassRefPtr<ErrorCallbackImpl> create(HelperType* helper)
+ {
+ return adoptRef(new ErrorCallbackImpl(helper));
+ }
+
+ virtual bool handleEvent(FileError* error)
+ {
+ ASSERT(error);
+ m_helper->setError(error->code());
+ return true;
+ }
+
+ private:
+ ErrorCallbackImpl(HelperType* helper)
+ : m_helper(helper)
+ {
+ }
+ HelperType* m_helper;
+ };
+
+ friend class SuccessCallbackImpl;
+ friend class ErrorCallbackImpl;
+
+ void setError(int code)
+ {
+ m_exceptionCode = FileException::ErrorCodeToExceptionCode(code);
+ m_completed = true;
+ }
+
+ void setResult(PassRefPtr<ResultType> result)
+ {
+ m_result = result;
+ m_completed = true;
+ }
+
+ ObserverType* m_observer;
+ RefPtr<SuccessCallbackImpl> m_successCallback;
+ RefPtr<ErrorCallbackImpl> m_errorCallback;
+ RefPtr<ResultType> m_result;
+ ExceptionCode m_exceptionCode;
+ bool m_completed;
+};
+
+struct EmptyType : public RefCounted<EmptyType> {
+ static PassRefPtr<EmptyType> create(EmptyType*)
+ {
+ return 0;
+ }
+};
+
+struct EmptyObserverType {
+ bool waitForOperationToComplete()
+ {
+ return false;
+ }
+};
+
+typedef SyncCallbackHelper<EntryCallback, AsyncFileSystem, Entry, EntrySync> EntrySyncCallbackHelper;
+typedef SyncCallbackHelper<EntriesCallback, AsyncFileSystem, EntryArray, EntryArraySync> EntriesSyncCallbackHelper;
+typedef SyncCallbackHelper<MetadataCallback, AsyncFileSystem, Metadata, Metadata> MetadataSyncCallbackHelper;
+typedef SyncCallbackHelper<VoidCallback, AsyncFileSystem, EmptyType, EmptyType> VoidSyncCallbackHelper;
+typedef SyncCallbackHelper<FileSystemCallback, EmptyObserverType, DOMFileSystem, DOMFileSystemSync> FileSystemSyncCallbackHelper;
+
+} // namespace WebCore
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // SyncCallbackHelper_h
diff --git a/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp b/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp
new file mode 100644
index 000000000..2ec421bac
--- /dev/null
+++ b/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "ThreadableBlobRegistry.h"
+
+#include "BlobData.h"
+#include "BlobRegistry.h"
+#include <wtf/MainThread.h>
+
+namespace WebCore {
+
+struct BlobRegistryContext {
+ BlobRegistryContext(const KURL& url, PassOwnPtr<BlobData> blobData)
+ : url(url.copy())
+ , blobData(blobData)
+ {
+ this->blobData->detachFromCurrentThread();
+ }
+
+ BlobRegistryContext(const KURL& url, const KURL& srcURL)
+ : url(url.copy())
+ , srcURL(srcURL.copy())
+ {
+ }
+
+ BlobRegistryContext(const KURL& url)
+ : url(url.copy())
+ {
+ }
+
+ KURL url;
+ KURL srcURL;
+ OwnPtr<BlobData> blobData;
+};
+
+#if ENABLE(BLOB)
+
+static void registerBlobURLTask(void* context)
+{
+ OwnPtr<BlobRegistryContext> blobRegistryContext = adoptPtr(static_cast<BlobRegistryContext*>(context));
+ blobRegistry().registerBlobURL(blobRegistryContext->url, blobRegistryContext->blobData.release());
+}
+
+void ThreadableBlobRegistry::registerBlobURL(const KURL& url, PassOwnPtr<BlobData> blobData)
+{
+ if (isMainThread())
+ blobRegistry().registerBlobURL(url, blobData);
+ else {
+ OwnPtr<BlobRegistryContext> context = adoptPtr(new BlobRegistryContext(url, blobData));
+ callOnMainThread(&registerBlobURLTask, context.leakPtr());
+ }
+}
+
+static void registerBlobURLFromTask(void* context)
+{
+ OwnPtr<BlobRegistryContext> blobRegistryContext = adoptPtr(static_cast<BlobRegistryContext*>(context));
+ blobRegistry().registerBlobURL(blobRegistryContext->url, blobRegistryContext->srcURL);
+}
+
+void ThreadableBlobRegistry::registerBlobURL(const KURL& url, const KURL& srcURL)
+{
+ if (isMainThread())
+ blobRegistry().registerBlobURL(url, srcURL);
+ else {
+ OwnPtr<BlobRegistryContext> context = adoptPtr(new BlobRegistryContext(url, srcURL));
+ callOnMainThread(&registerBlobURLFromTask, context.leakPtr());
+ }
+}
+
+static void unregisterBlobURLTask(void* context)
+{
+ OwnPtr<BlobRegistryContext> blobRegistryContext = adoptPtr(static_cast<BlobRegistryContext*>(context));
+ blobRegistry().unregisterBlobURL(blobRegistryContext->url);
+}
+
+void ThreadableBlobRegistry::unregisterBlobURL(const KURL& url)
+{
+ if (isMainThread())
+ blobRegistry().unregisterBlobURL(url);
+ else {
+ OwnPtr<BlobRegistryContext> context = adoptPtr(new BlobRegistryContext(url));
+ callOnMainThread(&unregisterBlobURLTask, context.leakPtr());
+ }
+}
+
+#else
+
+void ThreadableBlobRegistry::registerBlobURL(const KURL&, PassOwnPtr<BlobData>)
+{
+}
+
+void ThreadableBlobRegistry::registerBlobURL(const KURL&, const KURL&)
+{
+}
+
+void ThreadableBlobRegistry::unregisterBlobURL(const KURL&)
+{
+}
+#endif // ENABL(BLOB)
+
+} // namespace WebCore
diff --git a/Source/WebCore/fileapi/ThreadableBlobRegistry.h b/Source/WebCore/fileapi/ThreadableBlobRegistry.h
new file mode 100644
index 000000000..fe7df7f4f
--- /dev/null
+++ b/Source/WebCore/fileapi/ThreadableBlobRegistry.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ThreadableBlobRegistry_h
+#define ThreadableBlobRegistry_h
+
+#include <wtf/PassOwnPtr.h>
+
+namespace WebCore {
+
+class BlobData;
+class KURL;
+
+class ThreadableBlobRegistry {
+public:
+ static void registerBlobURL(const KURL&, PassOwnPtr<BlobData>);
+ static void registerBlobURL(const KURL&, const KURL& srcURL);
+ static void unregisterBlobURL(const KURL&);
+};
+
+} // namespace WebCore
+
+#endif // ThreadableBlobRegistry_h
diff --git a/Source/WebCore/fileapi/WebKitBlobBuilder.cpp b/Source/WebCore/fileapi/WebKitBlobBuilder.cpp
new file mode 100644
index 000000000..a810ad8f5
--- /dev/null
+++ b/Source/WebCore/fileapi/WebKitBlobBuilder.cpp
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "WebKitBlobBuilder.h"
+
+#include "Blob.h"
+#include "ExceptionCode.h"
+#include "File.h"
+#include "LineEnding.h"
+#include "TextEncoding.h"
+#include <wtf/ArrayBuffer.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/Vector.h>
+#include <wtf/text/AtomicString.h>
+#include <wtf/text/CString.h>
+
+namespace WebCore {
+
+WebKitBlobBuilder::WebKitBlobBuilder()
+ : m_size(0)
+{
+}
+
+Vector<char>& WebKitBlobBuilder::getBuffer()
+{
+ // If the last item is not a data item, create one. Otherwise, we simply append the new string to the last data item.
+ if (m_items.isEmpty() || m_items[m_items.size() - 1].type != BlobDataItem::Data)
+ m_items.append(BlobDataItem(RawData::create()));
+
+ return *m_items[m_items.size() - 1].data->mutableData();
+}
+
+void WebKitBlobBuilder::append(const String& text, const String& endingType, ExceptionCode& ec)
+{
+ bool isEndingTypeTransparent = endingType == "transparent";
+ bool isEndingTypeNative = endingType == "native";
+ if (!endingType.isEmpty() && !isEndingTypeTransparent && !isEndingTypeNative) {
+ ec = SYNTAX_ERR;
+ return;
+ }
+
+ CString utf8Text = UTF8Encoding().encode(text.characters(), text.length(), EntitiesForUnencodables);
+
+ Vector<char>& buffer = getBuffer();
+ size_t oldSize = buffer.size();
+
+ if (isEndingTypeNative)
+ normalizeLineEndingsToNative(utf8Text, buffer);
+ else
+ buffer.append(utf8Text.data(), utf8Text.length());
+ m_size += buffer.size() - oldSize;
+}
+
+void WebKitBlobBuilder::append(const String& text, ExceptionCode& ec)
+{
+ append(text, String(), ec);
+}
+
+#if ENABLE(BLOB)
+void WebKitBlobBuilder::append(ArrayBuffer* arrayBuffer)
+{
+ if (!arrayBuffer)
+ return;
+ Vector<char>& buffer = getBuffer();
+ size_t oldSize = buffer.size();
+ buffer.append(static_cast<const char*>(arrayBuffer->data()), arrayBuffer->byteLength());
+ m_size += buffer.size() - oldSize;
+}
+#endif
+
+void WebKitBlobBuilder::append(Blob* blob)
+{
+ if (!blob)
+ return;
+ if (blob->isFile()) {
+ // 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);
+
+ m_size += snapshotSize;
+ m_items.append(BlobDataItem(file->path(), 0, snapshotSize, snapshotModificationTime));
+ } else {
+ long long blobSize = static_cast<long long>(blob->size());
+ m_size += blobSize;
+ m_items.append(BlobDataItem(blob->url(), 0, blobSize));
+ }
+}
+
+PassRefPtr<Blob> WebKitBlobBuilder::getBlob(const String& contentType)
+{
+ OwnPtr<BlobData> blobData = BlobData::create();
+ blobData->setContentType(contentType);
+ blobData->swapItems(m_items);
+
+ RefPtr<Blob> blob = Blob::create(blobData.release(), m_size);
+
+ // After creating a blob from the current blob data, we do not need to keep the data around any more. Instead, we only
+ // need to keep a reference to the URL of the blob just created.
+ m_items.append(BlobDataItem(blob->url(), 0, m_size));
+
+ return blob;
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/fileapi/WebKitBlobBuilder.h b/Source/WebCore/fileapi/WebKitBlobBuilder.h
new file mode 100644
index 000000000..76b90beab
--- /dev/null
+++ b/Source/WebCore/fileapi/WebKitBlobBuilder.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebKitBlobBuilder_h
+#define WebKitBlobBuilder_h
+
+#include "BlobData.h"
+#include <wtf/Forward.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class Blob;
+class TextEncoding;
+
+typedef int ExceptionCode;
+
+class WebKitBlobBuilder : public RefCounted<WebKitBlobBuilder> {
+public:
+ static PassRefPtr<WebKitBlobBuilder> create() { return adoptRef(new WebKitBlobBuilder()); }
+
+ void append(Blob*);
+ void append(const String& text, ExceptionCode&);
+ void append(const String& text, const String& ending, ExceptionCode&);
+#if ENABLE(BLOB)
+ void append(ArrayBuffer*);
+#endif
+
+ PassRefPtr<Blob> getBlob(const String& contentType = String());
+
+private:
+ WebKitBlobBuilder();
+
+ Vector<char>& getBuffer();
+
+ long long m_size;
+ BlobDataItemList m_items;
+};
+
+} // namespace WebCore
+
+#endif // WebKitBlobBuilder_h
diff --git a/Source/WebCore/fileapi/WebKitBlobBuilder.idl b/Source/WebCore/fileapi/WebKitBlobBuilder.idl
new file mode 100644
index 000000000..4563613e9
--- /dev/null
+++ b/Source/WebCore/fileapi/WebKitBlobBuilder.idl
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module html {
+ interface [
+ Constructor,
+ GenerateNativeConverter,
+ NoStaticTables
+ ] WebKitBlobBuilder {
+#if !defined(LANGUAGE_OBJECTIVE_C)
+ Blob getBlob(in [Optional, ConvertUndefinedOrNullToNullString] DOMString contentType);
+#endif
+ void append(in Blob blob);
+#if defined(ENABLE_BLOB) && ENABLE_BLOB
+ void append(in ArrayBuffer arrayBuffer);
+#endif
+ void append(in DOMString value, in [Optional, ConvertUndefinedOrNullToNullString] DOMString endings) raises (DOMException);
+ };
+
+}
+
diff --git a/Source/WebCore/fileapi/WebKitFlags.h b/Source/WebCore/fileapi/WebKitFlags.h
new file mode 100644
index 000000000..a75b47230
--- /dev/null
+++ b/Source/WebCore/fileapi/WebKitFlags.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebKitFlags_h
+#define WebKitFlags_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class WebKitFlags : public RefCounted<WebKitFlags> {
+public:
+ static PassRefPtr<WebKitFlags> create(bool create = false, bool exclusive = false)
+ {
+ return adoptRef(new WebKitFlags(create, exclusive));
+ }
+
+ bool isCreate() const { return m_create; }
+ void setCreate(bool create) { m_create = create; }
+ bool isExclusive() const { return m_exclusive; }
+ void setExclusive(bool exclusive) { m_exclusive = exclusive; }
+
+private:
+ WebKitFlags(bool create, bool exclusive)
+ : m_create(create)
+ , m_exclusive(exclusive)
+ {
+ }
+ bool m_create;
+ bool m_exclusive;
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // WebKitFlags_h