summaryrefslogtreecommitdiffstats
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.cpp103
-rw-r--r--Source/WebCore/fileapi/Blob.h86
-rw-r--r--Source/WebCore/fileapi/Blob.idl46
-rw-r--r--Source/WebCore/fileapi/BlobBuilder.cpp132
-rw-r--r--Source/WebCore/fileapi/BlobBuilder.h70
-rw-r--r--Source/WebCore/fileapi/BlobBuilder.idl48
-rw-r--r--Source/WebCore/fileapi/BlobURL.cpp83
-rw-r--r--Source/WebCore/fileapi/BlobURL.h65
-rw-r--r--Source/WebCore/fileapi/DOMFilePath.cpp166
-rw-r--r--Source/WebCore/fileapi/DOMFilePath.h86
-rw-r--r--Source/WebCore/fileapi/DOMFileSystem.cpp122
-rw-r--r--Source/WebCore/fileapi/DOMFileSystem.h112
-rw-r--r--Source/WebCore/fileapi/DOMFileSystem.idl39
-rw-r--r--Source/WebCore/fileapi/DOMFileSystemBase.cpp204
-rw-r--r--Source/WebCore/fileapi/DOMFileSystemBase.h89
-rw-r--r--Source/WebCore/fileapi/DOMFileSystemSync.cpp172
-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.cpp69
-rw-r--r--Source/WebCore/fileapi/DirectoryReaderSync.h61
-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.cpp94
-rw-r--r--Source/WebCore/fileapi/Entry.h70
-rw-r--r--Source/WebCore/fileapi/Entry.idl49
-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.h81
-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.h68
-rw-r--r--Source/WebCore/fileapi/EntrySync.idl49
-rw-r--r--Source/WebCore/fileapi/ErrorCallback.h52
-rw-r--r--Source/WebCore/fileapi/ErrorCallback.idl38
-rw-r--r--Source/WebCore/fileapi/File.cpp106
-rw-r--r--Source/WebCore/fileapi/File.h95
-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.h83
-rw-r--r--Source/WebCore/fileapi/FileException.idl61
-rw-r--r--Source/WebCore/fileapi/FileList.cpp44
-rw-r--r--Source/WebCore/fileapi/FileList.h59
-rw-r--r--Source/WebCore/fileapi/FileList.idl36
-rw-r--r--Source/WebCore/fileapi/FileReader.cpp259
-rw-r--r--Source/WebCore/fileapi/FileReader.h145
-rw-r--r--Source/WebCore/fileapi/FileReader.idl66
-rw-r--r--Source/WebCore/fileapi/FileReaderLoader.cpp323
-rw-r--r--Source/WebCore/fileapi/FileReaderLoader.h119
-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.cpp219
-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.cpp259
-rw-r--r--Source/WebCore/fileapi/FileSystemCallbacks.h161
-rw-r--r--Source/WebCore/fileapi/FileThread.cpp119
-rw-r--r--Source/WebCore/fileapi/FileThread.h88
-rw-r--r--Source/WebCore/fileapi/FileThreadTask.h227
-rw-r--r--Source/WebCore/fileapi/FileWriter.cpp200
-rw-r--r--Source/WebCore/fileapi/FileWriter.h119
-rw-r--r--Source/WebCore/fileapi/FileWriter.idl62
-rw-r--r--Source/WebCore/fileapi/FileWriterBase.cpp76
-rw-r--r--Source/WebCore/fileapi/FileWriterBase.h94
-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/Flags.h67
-rw-r--r--Source/WebCore/fileapi/Flags.idl40
-rw-r--r--Source/WebCore/fileapi/LocalFileSystem.cpp98
-rw-r--r--Source/WebCore/fileapi/LocalFileSystem.h94
-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/SyncCallbackHelper.h186
-rw-r--r--Source/WebCore/fileapi/ThreadableBlobRegistry.cpp130
-rw-r--r--Source/WebCore/fileapi/ThreadableBlobRegistry.h50
110 files changed, 9108 insertions, 0 deletions
diff --git a/Source/WebCore/fileapi/AsyncFileWriter.h b/Source/WebCore/fileapi/AsyncFileWriter.h
new file mode 100644
index 0000000..d6a28d5
--- /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 0000000..929f523
--- /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 0000000..90df3c4
--- /dev/null
+++ b/Source/WebCore/fileapi/Blob.cpp
@@ -0,0 +1,103 @@
+/*
+ * 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::slice(long long start, long long length, 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;
+ }
+
+ // Clamp the range if it exceeds the size limit.
+ if (start < 0)
+ start = 0;
+ if (length < 0)
+ length = 0;
+
+ if (start >= size) {
+ start = 0;
+ length = 0;
+ } else if (start + length > size || length > std::numeric_limits<long long>::max() - start)
+ length = size - 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 0000000..2690ff5
--- /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> slice(long long start, long long length, 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 0000000..297d039
--- /dev/null
+++ b/Source/WebCore/fileapi/Blob.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 [
+ NoStaticTables
+ ] Blob {
+ readonly attribute unsigned long long size;
+ readonly attribute DOMString type;
+
+#if !defined(LANGUAGE_OBJECTIVE_C)
+#if defined(ENABLE_BLOB) && ENABLE_BLOB
+ Blob slice(in long long start, in long long length, in [Optional, ConvertUndefinedOrNullToNullString] DOMString contentType);
+#endif
+#endif
+ };
+
+}
diff --git a/Source/WebCore/fileapi/BlobBuilder.cpp b/Source/WebCore/fileapi/BlobBuilder.cpp
new file mode 100644
index 0000000..9406899
--- /dev/null
+++ b/Source/WebCore/fileapi/BlobBuilder.cpp
@@ -0,0 +1,132 @@
+/*
+ * 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 "BlobBuilder.h"
+
+#include "ArrayBuffer.h"
+#include "Blob.h"
+#include "ExceptionCode.h"
+#include "File.h"
+#include "LineEnding.h"
+#include "TextEncoding.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/Vector.h>
+#include <wtf/text/AtomicString.h>
+#include <wtf/text/CString.h>
+
+namespace WebCore {
+
+BlobBuilder::BlobBuilder()
+ : m_size(0)
+{
+}
+
+Vector<char>& BlobBuilder::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 BlobBuilder::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 BlobBuilder::append(const String& text, ExceptionCode& ec)
+{
+ append(text, String(), ec);
+}
+
+#if ENABLE(BLOB)
+void BlobBuilder::append(ArrayBuffer* arrayBuffer)
+{
+ 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 BlobBuilder::append(Blob* blob)
+{
+ 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> BlobBuilder::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/BlobBuilder.h b/Source/WebCore/fileapi/BlobBuilder.h
new file mode 100644
index 0000000..db46591
--- /dev/null
+++ b/Source/WebCore/fileapi/BlobBuilder.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 BlobBuilder_h
+#define BlobBuilder_h
+
+#include "BlobData.h"
+#include <wtf/Forward.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class ArrayBuffer;
+class Blob;
+class TextEncoding;
+
+typedef int ExceptionCode;
+
+class BlobBuilder : public RefCounted<BlobBuilder> {
+public:
+ static PassRefPtr<BlobBuilder> create() { return adoptRef(new BlobBuilder()); }
+
+ 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:
+ BlobBuilder();
+
+ Vector<char>& getBuffer();
+
+ long long m_size;
+ BlobDataItemList m_items;
+};
+
+} // namespace WebCore
+
+#endif // BlobBuilder_h
diff --git a/Source/WebCore/fileapi/BlobBuilder.idl b/Source/WebCore/fileapi/BlobBuilder.idl
new file mode 100644
index 0000000..8f5049f
--- /dev/null
+++ b/Source/WebCore/fileapi/BlobBuilder.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 [
+ CanBeConstructed,
+ GenerateNativeConverter,
+ NoStaticTables
+ ] BlobBuilder {
+#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/BlobURL.cpp b/Source/WebCore/fileapi/BlobURL.cpp
new file mode 100644
index 0000000..47ebe8d
--- /dev/null
+++ b/Source/WebCore/fileapi/BlobURL.cpp
@@ -0,0 +1,83 @@
+/*
+ * 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://");
+}
+
+KURL BlobURL::getOrigin(const KURL& url)
+{
+ ASSERT(url.protocolIs(kBlobProtocol));
+
+ unsigned startIndex = url.pathStart();
+ unsigned afterEndIndex = url.pathAfterLastSlash();
+ String origin = url.string().substring(startIndex, afterEndIndex - startIndex);
+ return KURL(ParsedURLString, decodeURLEscapeSequences(origin));
+}
+
+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)
+{
+ 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 0000000..4526e63
--- /dev/null
+++ b/Source/WebCore/fileapi/BlobURL.h
@@ -0,0 +1,65 @@
+/*
+ * 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 KURL getOrigin(const KURL&);
+ 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 0000000..1e0d788
--- /dev/null
+++ b/Source/WebCore/fileapi/DOMFilePath.cpp
@@ -0,0 +1,166 @@
+/*
+ * 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;
+}
+
+// Check the naming restrictions defined in FileSystem API 8.3.
+// http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#naming-restrictions
+bool DOMFilePath::isValidPath(const String& path)
+{
+ if (path.isEmpty() || path == DOMFilePath::root)
+ return true;
+
+ // Chars 0-31 in UTF-8 prepresentation are not allowed.
+ for (size_t i = 0; i < path.length(); ++i)
+ if (path[i] < 32)
+ return false;
+
+ // Unallowed names.
+ DEFINE_STATIC_LOCAL(RegularExpression, unallowedNamesRegExp1, ("(/|^)(CON|PRN|AUX|NUL)([\\./]|$)", TextCaseInsensitive));
+ DEFINE_STATIC_LOCAL(RegularExpression, unallowedNamesRegExp2, ("(/|^)(COM|LPT)[1-9]([\\./]|$)", TextCaseInsensitive));
+
+ if (unallowedNamesRegExp1.match(path) >= 0)
+ return false;
+ if (unallowedNamesRegExp2.match(path) >= 0)
+ return false;
+
+ // Names must not end with period or whitespace.
+ DEFINE_STATIC_LOCAL(RegularExpression, endingRegExp, ("[\\.\\s](/|$)", TextCaseInsensitive));
+
+ if (endingRegExp.match(path) >= 0)
+ return false;
+
+ // Unallowed chars: '\', '<', '>', ':', '?', '*', '"', '|'
+ // (We don't check '/' here as this method takes paths as its argument.)
+ DEFINE_STATIC_LOCAL(RegularExpression, unallowedCharsRegExp, ("[\\\\<>:\\?\\*\"|]", TextCaseInsensitive));
+
+ if (unallowedCharsRegExp.match(path) >= 0)
+ 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 0000000..2f2bb23
--- /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 0000000..f4ebe7c
--- /dev/null
+++ b/Source/WebCore/fileapi/DOMFileSystem.cpp
@@ -0,0 +1,122 @@
+/*
+ * 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 "FileEntry.h"
+#include "FileSystemCallbacks.h"
+#include "FileWriter.h"
+#include "FileWriterBaseCallback.h"
+#include "FileWriterCallback.h"
+#include "MetadataCallback.h"
+#include "ScriptExecutionContext.h"
+#include <wtf/OwnPtr.h>
+
+namespace WebCore {
+
+DOMFileSystem::DOMFileSystem(ScriptExecutionContext* context, const String& name, PassOwnPtr<AsyncFileSystem> asyncFileSystem)
+ : DOMFileSystemBase(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);
+
+ String platformPath = m_asyncFileSystem->virtualToPlatformPath(fileEntry->fullPath());
+
+ 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(), platformPath, callbacks.release());
+}
+
+void DOMFileSystem::createFile(const FileEntry* fileEntry, PassRefPtr<FileCallback> successCallback, PassRefPtr<ErrorCallback>)
+{
+ String platformPath = m_asyncFileSystem->virtualToPlatformPath(fileEntry->fullPath());
+ scheduleCallback(successCallback, File::create(platformPath));
+}
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
diff --git a/Source/WebCore/fileapi/DOMFileSystem.h b/Source/WebCore/fileapi/DOMFileSystem.h
new file mode 100644
index 0000000..1d820f1
--- /dev/null
+++ b/Source/WebCore/fileapi/DOMFileSystem.h
@@ -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.
+ */
+
+#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* context, const String& name, PassOwnPtr<AsyncFileSystem> asyncFileSystem)
+ {
+ return adoptRef(new DOMFileSystem(context, name, 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());
+ ASSERT(callback);
+ scriptExecutionContext->postTask(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 0000000..037770b
--- /dev/null
+++ b/Source/WebCore/fileapi/DOMFileSystem.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
+ ] 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 0000000..c462c3c
--- /dev/null
+++ b/Source/WebCore/fileapi/DOMFileSystemBase.cpp
@@ -0,0 +1,204 @@
+/*
+ * 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 "VoidCallback.h"
+#include <wtf/OwnPtr.h>
+
+namespace WebCore {
+
+DOMFileSystemBase::DOMFileSystemBase(const String& name, PassOwnPtr<AsyncFileSystem> asyncFileSystem)
+ : m_name(name)
+ , m_asyncFileSystem(asyncFileSystem)
+{
+}
+
+DOMFileSystemBase::~DOMFileSystemBase()
+{
+}
+
+bool DOMFileSystemBase::getMetadata(const EntryBase* entry, PassRefPtr<MetadataCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ String platformPath = m_asyncFileSystem->virtualToPlatformPath(entry->fullPath());
+ m_asyncFileSystem->readMetadata(platformPath, 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(const EntryBase* base, String path, String& absolutePath)
+{
+ ASSERT(base);
+
+ if (!DOMFilePath::isAbsolute(path))
+ path = DOMFilePath::append(base->fullPath(), path);
+ absolutePath = DOMFilePath::removeExtraParentReferences(path);
+
+ if (!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;
+
+ String sourcePlatformPath = m_asyncFileSystem->virtualToPlatformPath(source->fullPath());
+ String destinationPlatformPath = parent->filesystem()->asyncFileSystem()->virtualToPlatformPath(destinationPath);
+ m_asyncFileSystem->move(sourcePlatformPath, destinationPlatformPath, 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;
+
+ String sourcePlatformPath = m_asyncFileSystem->virtualToPlatformPath(source->fullPath());
+ String destinationPlatformPath = parent->filesystem()->asyncFileSystem()->virtualToPlatformPath(destinationPath);
+ m_asyncFileSystem->copy(sourcePlatformPath, destinationPlatformPath, 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;
+ String platformPath = m_asyncFileSystem->virtualToPlatformPath(entry->fullPath());
+ m_asyncFileSystem->remove(platformPath, 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;
+ String platformPath = m_asyncFileSystem->virtualToPlatformPath(entry->fullPath());
+ m_asyncFileSystem->removeRecursively(platformPath, 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());
+ String platformPath = m_asyncFileSystem->virtualToPlatformPath(path);
+ m_asyncFileSystem->directoryExists(platformPath, EntryCallbacks::create(successCallback, errorCallback, this, path, true));
+ return true;
+}
+
+bool DOMFileSystemBase::getFile(const EntryBase* base, const String& path, PassRefPtr<Flags> flags, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ String absolutePath;
+ if (!pathToAbsolutePath(base, path, absolutePath))
+ return false;
+
+ String platformPath = m_asyncFileSystem->virtualToPlatformPath(absolutePath);
+ OwnPtr<EntryCallbacks> callbacks = EntryCallbacks::create(successCallback, errorCallback, this, absolutePath, false);
+ if (flags && flags->isCreate())
+ m_asyncFileSystem->createFile(platformPath, flags->isExclusive(), callbacks.release());
+ else
+ m_asyncFileSystem->fileExists(platformPath, callbacks.release());
+ return true;
+}
+
+bool DOMFileSystemBase::getDirectory(const EntryBase* base, const String& path, PassRefPtr<Flags> flags, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ String absolutePath;
+ if (!pathToAbsolutePath(base, path, absolutePath))
+ return false;
+
+ String platformPath = m_asyncFileSystem->virtualToPlatformPath(absolutePath);
+ OwnPtr<EntryCallbacks> callbacks = EntryCallbacks::create(successCallback, errorCallback, this, absolutePath, true);
+ if (flags && flags->isCreate())
+ m_asyncFileSystem->createDirectory(platformPath, flags->isExclusive(), callbacks.release());
+ else
+ m_asyncFileSystem->directoryExists(platformPath, callbacks.release());
+ return true;
+}
+
+bool DOMFileSystemBase::readDirectory(PassRefPtr<DirectoryReaderBase> reader, const String& path, PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ ASSERT(DOMFilePath::isAbsolute(path));
+ String platformPath = m_asyncFileSystem->virtualToPlatformPath(path);
+ m_asyncFileSystem->readDirectory(platformPath, 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 0000000..66f1331
--- /dev/null
+++ b/Source/WebCore/fileapi/DOMFileSystemBase.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 DOMFileSystemBase_h
+#define DOMFileSystemBase_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "AsyncFileSystem.h"
+#include "Flags.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 MetadataCallback;
+class VoidCallback;
+
+// A common base class for DOMFileSystem and DOMFileSystemSync.
+class DOMFileSystemBase : public RefCounted<DOMFileSystemBase> {
+public:
+ static PassRefPtr<DOMFileSystemBase> create(const String& name, PassOwnPtr<AsyncFileSystem> asyncFileSystem)
+ {
+ return adoptRef(new DOMFileSystemBase(name, asyncFileSystem));
+ }
+ virtual ~DOMFileSystemBase();
+
+ const String& name() const { return m_name; }
+ AsyncFileSystem* asyncFileSystem() const { return m_asyncFileSystem.get(); }
+
+ // 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<Flags>, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>);
+ bool getDirectory(const EntryBase*, const String& path, PassRefPtr<Flags>, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>);
+ bool readDirectory(PassRefPtr<DirectoryReaderBase>, const String& path, PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>);
+
+protected:
+ DOMFileSystemBase(const String& name, PassOwnPtr<AsyncFileSystem>);
+ friend class DOMFileSystemSync;
+
+ 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 0000000..dcbc9c7
--- /dev/null
+++ b/Source/WebCore/fileapi/DOMFileSystemSync.cpp
@@ -0,0 +1,172 @@
+/*
+ * 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 "DOMFilePath.h"
+#include "DirectoryEntrySync.h"
+#include "ErrorCallback.h"
+#include "File.h"
+#include "FileEntrySync.h"
+#include "FileError.h"
+#include "FileException.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_name, fileSystem->m_asyncFileSystem.release()));
+}
+
+DOMFileSystemSync::DOMFileSystemSync(const String& name, PassOwnPtr<AsyncFileSystem> asyncFileSystem)
+ : DOMFileSystemBase(name, asyncFileSystem)
+{
+}
+
+DOMFileSystemSync::~DOMFileSystemSync()
+{
+}
+
+PassRefPtr<DirectoryEntrySync> DOMFileSystemSync::root()
+{
+ return DirectoryEntrySync::create(this, DOMFilePath::root);
+}
+
+PassRefPtr<File> DOMFileSystemSync::createFile(const FileEntrySync* fileEntry, ExceptionCode& ec)
+{
+ ec = 0;
+ String platformPath = m_asyncFileSystem->virtualToPlatformPath(fileEntry->fullPath());
+ return File::create(platformPath);
+}
+
+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;
+
+ String platformPath = m_asyncFileSystem->virtualToPlatformPath(fileEntry->fullPath());
+
+ 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(), platformPath, 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 0000000..ce07c85
--- /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(const String& name, PassOwnPtr<AsyncFileSystem> asyncFileSystem)
+ {
+ return adoptRef(new DOMFileSystemSync(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(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 0000000..b51d8cc
--- /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 0000000..7bc0af8
--- /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<Flags> 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<Flags> 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 0000000..da903da
--- /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 "Flags.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<Flags> = 0, PassRefPtr<EntryCallback> = 0, PassRefPtr<ErrorCallback> = 0);
+ void getDirectory(const String& path, PassRefPtr<Flags> = 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 0000000..0e38153
--- /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] Flags flags, in [Optional, Callback] EntryCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback);
+ [Custom] void getDirectory(in [ConvertUndefinedOrNullToNullString] DOMString path, in [Optional] Flags flags, in [Optional, Callback] EntryCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback);
+ void removeRecursively(in [Optional, 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 0000000..e68f7be
--- /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<Flags> 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<Flags> 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 0000000..eb412bb
--- /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 "Flags.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<Flags>, ExceptionCode&);
+ PassRefPtr<DirectoryEntrySync> getDirectory(const String& path, PassRefPtr<Flags>, 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 0000000..268b2a9
--- /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 Flags flags) raises (FileException);
+ [Custom] DirectoryEntrySync getDirectory(in [ConvertUndefinedOrNullToNullString] DOMString path, in Flags 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 0000000..fe2d99f
--- /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 0000000..bc89858
--- /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 0000000..831fb05
--- /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 0000000..4096fe8
--- /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 0000000..15cdaa8
--- /dev/null
+++ b/Source/WebCore/fileapi/DirectoryReaderSync.cpp
@@ -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.
+ */
+
+#include "config.h"
+#include "DirectoryReaderSync.h"
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "DirectoryEntry.h"
+#include "DirectoryEntrySync.h"
+#include "EntryArraySync.h"
+#include "EntrySync.h"
+#include "ExceptionCode.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 0000000..5e3d61b
--- /dev/null
+++ b/Source/WebCore/fileapi/DirectoryReaderSync.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 DirectoryReaderSync_h
+#define DirectoryReaderSync_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "DirectoryReaderBase.h"
+#include "EntryArraySync.h"
+#include "PlatformString.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+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 0000000..aa39928
--- /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 0000000..9f812e9
--- /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 0000000..73b374d
--- /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 0000000..9c3fa4e
--- /dev/null
+++ b/Source/WebCore/fileapi/Entry.cpp
@@ -0,0 +1,94 @@
+/*
+ * 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 "DirectoryEntry.h"
+#include "EntryCallback.h"
+#include "ErrorCallback.h"
+#include "FileError.h"
+#include "FileSystemCallbacks.h"
+#include "MetadataCallback.h"
+#include "VoidCallback.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));
+}
+
+String Entry::toURI(const String&)
+{
+ // FIXME: to be implemented.
+ ASSERT_NOT_REACHED();
+ return String();
+}
+
+} // 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 0000000..9367f4f
--- /dev/null
+++ b/Source/WebCore/fileapi/Entry.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 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;
+
+ String toURI(const String& mimeType = String());
+
+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 0000000..f6fcdb3
--- /dev/null
+++ b/Source/WebCore/fileapi/Entry.idl
@@ -0,0 +1,49 @@
+/*
+ * 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 [Optional, 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);
+ void remove(in [Optional, 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 0000000..6c4f74f
--- /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 0000000..e5957ab
--- /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 0000000..dca7827
--- /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 0000000..1e2fa91
--- /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 0000000..46cf409
--- /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 0000000..bd54f33
--- /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.h b/Source/WebCore/fileapi/EntryBase.h
new file mode 100644
index 0000000..16f93ba
--- /dev/null
+++ b/Source/WebCore/fileapi/EntryBase.h
@@ -0,0 +1,81 @@
+/*
+ * 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 "DOMFilePath.h"
+#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; }
+
+protected:
+ EntryBase(PassRefPtr<DOMFileSystemBase> fileSystem, const String& fullPath)
+ : m_fileSystem(fileSystem)
+ , m_fullPath(fullPath)
+ , m_name(DOMFilePath::getName(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 0000000..9580eda
--- /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 0000000..bea3fd1
--- /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 0000000..299aeda
--- /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 0000000..175d591
--- /dev/null
+++ b/Source/WebCore/fileapi/EntrySync.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 EntrySync_h
+#define EntrySync_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "DOMFileSystemSync.h"
+#include "EntryBase.h"
+#include "ExceptionCode.h"
+#include "PlatformString.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class DirectoryEntrySync;
+class Metadata;
+
+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 0000000..fb7ee3c
--- /dev/null
+++ b/Source/WebCore/fileapi/EntrySync.idl
@@ -0,0 +1,49 @@
+/*
+ * 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);
+ 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 0000000..cceb354
--- /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 0000000..fc7fa85
--- /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 0000000..dd81f5a
--- /dev/null
+++ b/Source/WebCore/fileapi/File.cpp
@@ -0,0 +1,106 @@
+/*
+ * 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> createBlobDataForFile(const String& path)
+{
+ String type;
+ int index = path.reverseFind('.');
+ if (index != -1)
+ type = MIMETypeRegistry::getMIMETypeForExtension(path.substring(index + 1));
+
+ OwnPtr<BlobData> blobData = BlobData::create();
+ blobData->setContentType(type);
+ blobData->appendFile(path);
+ return blobData.release();
+}
+
+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);
+}
+
+#if ENABLE(DIRECTORY_UPLOAD)
+File::File(const String& relativePath, const String& path)
+ : Blob(createBlobDataForFile(path), -1)
+ , m_path(path)
+ , m_relativePath(relativePath)
+{
+ m_name = pathGetFileName(path);
+}
+#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 0000000..d22b035
--- /dev/null
+++ b/Source/WebCore/fileapi/File.h
@@ -0,0 +1,95 @@
+/*
+ * 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> create(const String& relativePath, const String& path)
+ {
+ return adoptRef(new File(relativePath, path));
+ }
+#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(DIRECTORY_UPLOAD)
+ File(const String& relativePath, const String& path);
+#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 0000000..74a6f76
--- /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 0000000..6f5ca3d
--- /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 0000000..0ab814f
--- /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 0000000..a5ecff5
--- /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 0000000..2fa4394
--- /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"
+#include "FileCallback.h"
+#include "FileWriterCallback.h"
+
+namespace WebCore {
+
+class DOMFileSystemBase;
+
+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 0000000..73ef895
--- /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 0000000..d899de7
--- /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 0000000..615a604
--- /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 0000000..c569839
--- /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 0000000..0597633
--- /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 0000000..bab815a
--- /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.h b/Source/WebCore/fileapi/FileException.h
new file mode 100644
index 0000000..c3cc638
--- /dev/null
+++ b/Source/WebCore/fileapi/FileException.h
@@ -0,0 +1,83 @@
+/*
+ * 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;
+ }
+
+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 0000000..10bd151
--- /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 0000000..ba81087
--- /dev/null
+++ b/Source/WebCore/fileapi/FileList.cpp
@@ -0,0 +1,44 @@
+/*
+ * 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();
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/fileapi/FileList.h b/Source/WebCore/fileapi/FileList.h
new file mode 100644
index 0000000..e078191
--- /dev/null
+++ b/Source/WebCore/fileapi/FileList.h
@@ -0,0 +1,59 @@
+/*
+ * 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); }
+
+ 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 0000000..0d0b046
--- /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 0000000..fd2e263
--- /dev/null
+++ b/Source/WebCore/fileapi/FileReader.cpp
@@ -0,0 +1,259 @@
+/*
+ * 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 "ArrayBuffer.h"
+#include "CrossThreadTask.h"
+#include "File.h"
+#include "Logging.h"
+#include "ProgressEvent.h"
+#include "ScriptExecutionContext.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(None)
+ , m_readType(FileReaderLoader::ReadAsBinaryString)
+ , m_lastProgressNotificationTimeMS(0)
+{
+}
+
+FileReader::~FileReader()
+{
+ terminate();
+}
+
+bool FileReader::hasPendingActivity() const
+{
+ return (m_state != None && m_state != Completed) || 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)
+{
+ 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);
+}
+
+void FileReader::readAsBinaryString(Blob* blob)
+{
+ 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);
+}
+
+void FileReader::readAsText(Blob* blob, const String& encoding)
+{
+ 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);
+}
+
+void FileReader::readAsDataURL(Blob* blob)
+{
+ 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);
+}
+
+static void delayedStart(ScriptExecutionContext*, FileReader* reader)
+{
+ reader->start();
+}
+
+void FileReader::readInternal(Blob* blob, FileReaderLoader::ReadType type)
+{
+ // readAs*** methods() can be called multiple times. Only the last call before the actual reading happens is processed.
+ if (m_state != None && m_state != Starting)
+ return;
+
+ if (m_state == None)
+ scriptExecutionContext()->postTask(createCallbackTask(&delayedStart, this));
+
+ m_blob = blob;
+ m_readType = type;
+ m_state = Starting;
+}
+
+static void delayedAbort(ScriptExecutionContext*, FileReader* reader)
+{
+ reader->doAbort();
+}
+
+void FileReader::abort()
+{
+ LOG(FileAPI, "FileReader: aborting\n");
+
+ if (m_state == Aborting)
+ return;
+ m_state = Aborting;
+
+ // 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, this));
+}
+
+void FileReader::doAbort()
+{
+ terminate();
+
+ 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 = 0;
+ }
+ m_state = Completed;
+}
+
+void FileReader::start()
+{
+ m_state = Opening;
+
+ 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());
+}
+
+void FileReader::didStartLoading()
+{
+ m_state = Reading;
+ 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 = Completed;
+
+ 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_state == Aborting)
+ return;
+
+ m_state = Completed;
+
+ 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));
+}
+
+FileReader::ReadyState FileReader::readyState() const
+{
+ switch (m_state) {
+ case None:
+ case Starting:
+ return EMPTY;
+ case Opening:
+ case Reading:
+ case Aborting:
+ return LOADING;
+ case Completed:
+ return DONE;
+ }
+ ASSERT_NOT_REACHED();
+ return EMPTY;
+}
+
+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 0000000..04513f3
--- /dev/null
+++ b/Source/WebCore/fileapi/FileReader.h
@@ -0,0 +1,145 @@
+/*
+ * 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 ArrayBuffer;
+class Blob;
+class ScriptExecutionContext;
+
+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*);
+ void readAsBinaryString(Blob*);
+ void readAsText(Blob*, const String& encoding = "");
+ void readAsDataURL(Blob*);
+ void abort();
+
+ void start();
+ void doAbort();
+
+ ReadyState readyState() const;
+ 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 FileReader* toFileReader() { return this; }
+ 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:
+ enum InternalState {
+ None,
+ Starting,
+ Opening,
+ Reading,
+ Aborting,
+ Completed
+ };
+
+ 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);
+ void fireErrorEvent(int httpStatusCode);
+ void fireEvent(const AtomicString& type);
+
+ InternalState m_state;
+ 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 0000000..ebc6ffd
--- /dev/null
+++ b/Source/WebCore/fileapi/FileReader.idl
@@ -0,0 +1,66 @@
+/*
+ * 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,
+ CanBeConstructed,
+ CallWith=ScriptExecutionContext,
+ EventTarget,
+ NoStaticTables,
+ V8CustomConstructor
+ ] 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);
+ void readAsBinaryString(in Blob blob);
+ void readAsText(in Blob blob, in [Optional] DOMString encoding);
+ void readAsDataURL(in Blob blob);
+
+ void abort();
+
+ // file data
+ readonly attribute [Custom] DOMObject result;
+
+ readonly attribute FileError error;
+
+ 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 0000000..24904e2
--- /dev/null
+++ b/Source/WebCore/fileapi/FileReaderLoader.cpp
@@ -0,0 +1,323 @@
+/*
+ * 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 "ArrayBuffer.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/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());
+ ThreadableBlobRegistry::registerBlobURL(m_urlForReading, blob->url());
+
+ // Construct and load the request.
+ ResourceRequest request(m_urlForReading);
+ request.setHTTPMethod("GET");
+
+ ThreadableLoaderOptions options;
+ options.sendLoadCallbacks = true;
+ options.sniffContent = false;
+ options.forcePreflight = false;
+ options.allowCredentials = true;
+ 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(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 lengthReceived)
+{
+ ASSERT(data);
+ ASSERT(lengthReceived > 0);
+
+ // Bail out if we already encountered an error.
+ if (m_errorCode)
+ return;
+
+ int length = lengthReceived;
+ 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)
+{
+ 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 0000000..a15ee01
--- /dev/null
+++ b/Source/WebCore/fileapi/FileReaderLoader.h
@@ -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.
+ */
+
+#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 ArrayBuffer;
+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(const ResourceResponse&);
+ virtual void didReceiveData(const char*, int);
+ virtual void didFinishLoading(unsigned long identifier);
+ 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 0000000..4acb8ad
--- /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 0000000..85e7f52
--- /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 "ArrayBuffer.h"
+#include "Blob.h"
+#include "BlobURL.h"
+#include "FileException.h"
+#include "FileReaderLoader.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 0000000..79b637f
--- /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 "ExceptionCode.h"
+#include <wtf/Forward.h>
+#include <wtf/RefCounted.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class ArrayBuffer;
+class Blob;
+class FileReaderLoader;
+class ScriptExecutionContext;
+
+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 0000000..381d483
--- /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,
+ CanBeConstructed,
+ 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 0000000..5daf983
--- /dev/null
+++ b/Source/WebCore/fileapi/FileStreamProxy.cpp
@@ -0,0 +1,219 @@
+/*
+ * 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()
+{
+ m_stream->start();
+ m_context->postTask(createCallbackTask(&didStart, 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, 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, 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, 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, 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, buffer, length));
+}
+
+void FileStreamProxy::readOnFileThread(char* buffer, int length)
+{
+ int bytesRead = m_stream->read(buffer, length);
+ m_context->postTask(createCallbackTask(&didRead, 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, 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, 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 0000000..ce9a105
--- /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 0000000..63f8416
--- /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 0000000..cf686ff
--- /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 0000000..966337b
--- /dev/null
+++ b/Source/WebCore/fileapi/FileSystemCallbacks.cpp
@@ -0,0 +1,259 @@
+/*
+ * 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);
+ m_successCallback->handleEvent(DOMFileSystem::create(m_scriptExecutionContext.get(), name, asyncFileSystem.leakPtr()).get());
+ m_scriptExecutionContext.clear();
+ }
+ m_successCallback.clear();
+}
+
+// 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 0000000..83000c2
--- /dev/null
+++ b/Source/WebCore/fileapi/FileSystemCallbacks.h
@@ -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.
+ */
+
+#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 ErrorCallback;
+class EntriesCallback;
+class EntryArray;
+class EntryCallback;
+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 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 0000000..4d55630
--- /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 0000000..d7aabf7
--- /dev/null
+++ b/Source/WebCore/fileapi/FileThread.h
@@ -0,0 +1,88 @@
+/*
+ * 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 ThreadSafeShared<FileThread> {
+public:
+ static PassRefPtr<FileThread> create()
+ {
+ return adoptRef(new FileThread());
+ }
+
+ ~FileThread();
+
+ bool start();
+ void stop();
+
+ class Task : public Noncopyable {
+ 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 0000000..8a8ffcb
--- /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 0000000..45ba42b
--- /dev/null
+++ b/Source/WebCore/fileapi/FileWriter.cpp
@@ -0,0 +1,200 @@
+/*
+ * 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 {
+
+FileWriter::FileWriter(ScriptExecutionContext* context)
+ : ActiveDOMObject(context, this)
+ , m_readyState(INIT)
+ , m_startedWriting(false)
+ , m_bytesWritten(0)
+ , m_bytesToWrite(0)
+ , m_truncateLength(-1)
+{
+}
+
+FileWriter::~FileWriter()
+{
+ if (m_readyState == WRITING)
+ stop();
+}
+
+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()
+{
+ if (writer() && m_readyState == WRITING)
+ writer()->abort();
+ m_blobBeingWritten.clear();
+ m_readyState = DONE;
+}
+
+void FileWriter::write(Blob* data, ExceptionCode& ec)
+{
+ ASSERT(writer());
+ if (m_readyState == WRITING) {
+ setError(FileError::INVALID_STATE_ERR, ec);
+ return;
+ }
+ if (!data) {
+ setError(FileError::TYPE_MISMATCH_ERR, ec);
+ return;
+ }
+
+ m_blobBeingWritten = data;
+ m_readyState = WRITING;
+ m_startedWriting = false;
+ m_bytesWritten = 0;
+ m_bytesToWrite = data->size();
+ writer()->write(position(), data);
+}
+
+void FileWriter::seek(long long position, ExceptionCode& ec)
+{
+ ASSERT(writer());
+ if (m_readyState == WRITING) {
+ setError(FileError::INVALID_STATE_ERR, ec);
+ return;
+ }
+
+ m_bytesWritten = 0;
+ m_bytesToWrite = 0;
+ seekInternal(position);
+}
+
+void FileWriter::truncate(long long position, ExceptionCode& ec)
+{
+ ASSERT(writer());
+ if (m_readyState == WRITING || position < 0) {
+ setError(FileError::INVALID_STATE_ERR, ec);
+ return;
+ }
+ m_readyState = WRITING;
+ m_bytesWritten = 0;
+ m_bytesToWrite = 0;
+ m_truncateLength = position;
+ writer()->truncate(position);
+}
+
+void FileWriter::abort(ExceptionCode& ec)
+{
+ ASSERT(writer());
+ if (m_readyState != WRITING) {
+ setError(FileError::INVALID_STATE_ERR, ec);
+ return;
+ }
+
+ m_error = FileError::create(FileError::ABORT_ERR);
+ writer()->abort();
+}
+
+void FileWriter::didWrite(long long bytes, bool complete)
+{
+ ASSERT(bytes + m_bytesWritten > 0);
+ ASSERT(bytes + m_bytesWritten <= m_bytesToWrite);
+ if (!m_startedWriting) {
+ fireEvent(eventNames().writestartEvent);
+ m_startedWriting = true;
+ }
+ m_bytesWritten += bytes;
+ ASSERT((m_bytesWritten == m_bytesToWrite) || !complete);
+ setPosition(position() + bytes);
+ if (position() > length())
+ setLength(position());
+ fireEvent(eventNames().progressEvent);
+ if (complete) {
+ m_blobBeingWritten.clear();
+ fireEvent(eventNames().writeEvent);
+ m_readyState = DONE;
+ fireEvent(eventNames().writeendEvent);
+ }
+}
+
+void FileWriter::didTruncate()
+{
+ ASSERT(m_truncateLength >= 0);
+ fireEvent(eventNames().writestartEvent);
+ setLength(m_truncateLength);
+ if (position() > length())
+ setPosition(length());
+ m_truncateLength = -1;
+ fireEvent(eventNames().writeEvent);
+ m_readyState = DONE;
+ fireEvent(eventNames().writeendEvent);
+}
+
+void FileWriter::didFail(FileError::ErrorCode code)
+{
+ m_error = FileError::create(code);
+ fireEvent(eventNames().errorEvent);
+ if (FileError::ABORT_ERR == code)
+ fireEvent(eventNames().abortEvent);
+ fireEvent(eventNames().errorEvent);
+ m_blobBeingWritten.clear();
+ m_readyState = DONE;
+ fireEvent(eventNames().writeendEvent);
+}
+
+void FileWriter::fireEvent(const AtomicString& type)
+{
+ dispatchEvent(ProgressEvent::create(type, true, m_bytesWritten, m_bytesToWrite));
+}
+
+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 0000000..89289a9
--- /dev/null
+++ b/Source/WebCore/fileapi/FileWriter.h
@@ -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.
+ */
+
+#ifndef FileWriter_h
+#define FileWriter_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include "ActiveDOMObject.h"
+#include "EventTarget.h"
+#include "FileWriterBase.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+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 FileWriter* toFileWriter() { return this; }
+ 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:
+ 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 fireEvent(const AtomicString& type);
+
+ void setError(FileError::ErrorCode, ExceptionCode&);
+
+ RefPtr<FileError> m_error;
+ EventTargetData m_eventTargetData;
+ ReadyState m_readyState;
+ bool m_startedWriting;
+ long long m_bytesWritten;
+ long long m_bytesToWrite;
+ long long m_truncateLength;
+ 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 0000000..4d46e9e
--- /dev/null
+++ b/Source/WebCore/fileapi/FileWriter.idl
@@ -0,0 +1,62 @@
+/*
+ * 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,
+ 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 0000000..dc55bb8
--- /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 0000000..2eecfff
--- /dev/null
+++ b/Source/WebCore/fileapi/FileWriterBase.h
@@ -0,0 +1,94 @@
+/*
+ * 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 "AsyncFileWriterClient.h"
+#include <wtf/OwnPtr.h>
+#include <wtf/PassOwnPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class AsyncFileWriter;
+class Blob;
+
+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 0000000..51e8ab7
--- /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 0000000..3f9e746
--- /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 0000000..df82fed
--- /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 0000000..28a68f8
--- /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 0000000..3917f2e
--- /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 "ActiveDOMObject.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 0000000..c561bb4
--- /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/Flags.h b/Source/WebCore/fileapi/Flags.h
new file mode 100644
index 0000000..30884fc
--- /dev/null
+++ b/Source/WebCore/fileapi/Flags.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 Flags_h
+#define Flags_h
+
+#if ENABLE(FILE_SYSTEM)
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class Flags : public RefCounted<Flags> {
+public:
+ static PassRefPtr<Flags> create(bool create = false, bool exclusive = false)
+ {
+ return adoptRef(new Flags(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:
+ Flags(bool create, bool exclusive)
+ : m_create(create)
+ , m_exclusive(exclusive)
+ {
+ }
+ bool m_create;
+ bool m_exclusive;
+};
+
+} // namespace
+
+#endif // ENABLE(FILE_SYSTEM)
+
+#endif // Flags_h
diff --git a/Source/WebCore/fileapi/Flags.idl b/Source/WebCore/fileapi/Flags.idl
new file mode 100644
index 0000000..88cede3
--- /dev/null
+++ b/Source/WebCore/fileapi/Flags.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,
+ CanBeConstructed,
+ NoStaticTables
+ ] Flags {
+ attribute boolean create;
+ attribute boolean exclusive;
+ };
+}
diff --git a/Source/WebCore/fileapi/LocalFileSystem.cpp b/Source/WebCore/fileapi/LocalFileSystem.cpp
new file mode 100644
index 0000000..721fdf5
--- /dev/null
+++ b/Source/WebCore/fileapi/LocalFileSystem.cpp
@@ -0,0 +1,98 @@
+/*
+ * 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/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, long long, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
+{
+ // 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 0000000..b779a5f
--- /dev/null
+++ b/Source/WebCore/fileapi/LocalFileSystem.h
@@ -0,0 +1,94 @@
+/*
+ * 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 : public Noncopyable {
+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, long long size, PassOwnPtr<AsyncFileSystemCallbacks>);
+
+ 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.threadsafeCopy();
+ }
+ 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 0000000..b70806b
--- /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 0000000..df50b66
--- /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 0000000..725a0c1
--- /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 0000000..44ca180
--- /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/SyncCallbackHelper.h b/Source/WebCore/fileapi/SyncCallbackHelper.h
new file mode 100644
index 0000000..25e6739
--- /dev/null
+++ b/Source/WebCore/fileapi/SyncCallbackHelper.h
@@ -0,0 +1,186 @@
+/*
+ * 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 "ExceptionCode.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;
+
+// A helper template for FileSystemSync implementation.
+template <typename SuccessCallback, typename ObserverType, typename CallbackArg, typename ResultType>
+class SyncCallbackHelper : public Noncopyable {
+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 0000000..2ec421b
--- /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 0000000..fe7df7f
--- /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