diff options
author | Ben Murdoch <benm@google.com> | 2010-10-22 13:02:20 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-10-26 15:21:41 +0100 |
commit | a94275402997c11dd2e778633dacf4b7e630a35d (patch) | |
tree | e66f56c67e3b01f22c9c23cd932271ee9ac558ed /WebCore/fileapi | |
parent | 09e26c78506587b3f5d930d7bc72a23287ffbec0 (diff) | |
download | external_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.zip external_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.tar.gz external_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.tar.bz2 |
Merge WebKit at r70209: Initial merge by Git
Change-Id: Id23a68efa36e9d1126bcce0b137872db00892c8e
Diffstat (limited to 'WebCore/fileapi')
50 files changed, 1983 insertions, 385 deletions
diff --git a/WebCore/fileapi/Blob.cpp b/WebCore/fileapi/Blob.cpp index d5a5602..90df3c4 100644 --- a/WebCore/fileapi/Blob.cpp +++ b/WebCore/fileapi/Blob.cpp @@ -86,7 +86,7 @@ PassRefPtr<Blob> Blob::slice(long long start, long long length, const String& co if (start >= size) { start = 0; length = 0; - } else if (start + length > size) + } else if (start + length > size || length > std::numeric_limits<long long>::max() - start) length = size - start; OwnPtr<BlobData> blobData = BlobData::create(); diff --git a/WebCore/fileapi/BlobBuilder.cpp b/WebCore/fileapi/BlobBuilder.cpp index 34864a5..69443a5 100644 --- a/WebCore/fileapi/BlobBuilder.cpp +++ b/WebCore/fileapi/BlobBuilder.cpp @@ -41,36 +41,6 @@ namespace WebCore { -static CString convertToCString(const String& text, const String& endingType, ExceptionCode& ec) -{ - DEFINE_STATIC_LOCAL(AtomicString, transparent, ("transparent")); - DEFINE_STATIC_LOCAL(AtomicString, native, ("native")); - - ec = 0; - - if (endingType.isEmpty() || endingType == transparent) - return UTF8Encoding().encode(text.characters(), text.length(), EntitiesForUnencodables); - if (endingType == native) - return normalizeLineEndingsToNative(UTF8Encoding().encode(text.characters(), text.length(), EntitiesForUnencodables)); - - ec = SYNTAX_ERR; - return CString(); -} - -static CString concatenateTwoCStrings(const CString& a, const CString& b) -{ - if (a.isNull() && b.isNull()) - return CString(); - - char* q; - CString result = CString::newUninitialized(a.length() + b.length(), q); - if (a.length()) - memcpy(q, a.data(), a.length()); - if (b.length()) - memcpy(q + a.length(), b.data(), b.length()); - return result; -} - BlobBuilder::BlobBuilder() : m_size(0) { @@ -78,17 +48,30 @@ BlobBuilder::BlobBuilder() bool BlobBuilder::append(const String& text, const String& endingType, ExceptionCode& ec) { - CString cstr = convertToCString(text, endingType, ec); - if (ec) - return false; + bool isEndingTypeTransparent = endingType == "transparent"; + bool isEndingTypeNative = endingType == "native"; + if (!endingType.isEmpty() && !isEndingTypeTransparent && !isEndingTypeNative) { + ec = SYNTAX_ERR; + return 0; + } + + CString utf8Text = UTF8Encoding().encode(text.characters(), text.length(), EntitiesForUnencodables); - m_size += cstr.length(); + // 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())); + + if (!utf8Text.isNull()) { + Vector<char>& buffer = *m_items[m_items.size() - 1].data->mutableData(); + size_t oldSize = buffer.size(); + + if (isEndingTypeNative) + normalizeLineEndingsToNative(utf8Text, buffer); + else + buffer.append(utf8Text.data(), utf8Text.length()); + m_size += buffer.size() - oldSize; + } - // If the last item is a string, concatenate it with current string. - if (!m_items.isEmpty() && m_items[m_items.size() - 1].type == BlobDataItem::Data) - m_items[m_items.size() - 1].data = concatenateTwoCStrings(m_items[m_items.size() - 1].data, cstr); - else - m_items.append(BlobDataItem(cstr)); return true; } diff --git a/WebCore/fileapi/DOMFileSystem.cpp b/WebCore/fileapi/DOMFileSystem.cpp index 2bd09c2..f38acaa 100644 --- a/WebCore/fileapi/DOMFileSystem.cpp +++ b/WebCore/fileapi/DOMFileSystem.cpp @@ -36,31 +36,21 @@ #include "AsyncFileSystem.h" #include "DOMFilePath.h" #include "DirectoryEntry.h" -#include "EntriesCallback.h" -#include "Entry.h" -#include "EntryArray.h" -#include "EntryCallback.h" #include "ErrorCallback.h" +#include "File.h" #include "FileEntry.h" -#include "FileError.h" #include "FileSystemCallbacks.h" #include "FileWriter.h" #include "FileWriterCallback.h" #include "MetadataCallback.h" #include "ScriptExecutionContext.h" -#include "VoidCallback.h" #include <wtf/OwnPtr.h> namespace WebCore { DOMFileSystem::DOMFileSystem(ScriptExecutionContext* context, const String& name, PassOwnPtr<AsyncFileSystem> asyncFileSystem) - : ActiveDOMObject(context, this) - , m_name(name) - , m_asyncFileSystem(asyncFileSystem) -{ -} - -DOMFileSystem::~DOMFileSystem() + : DOMFileSystemBase(name, asyncFileSystem) + , ActiveDOMObject(context, this) { } @@ -85,140 +75,21 @@ void DOMFileSystem::contextDestroyed() ActiveDOMObject::contextDestroyed(); } -void DOMFileSystem::getMetadata(const Entry* entry, PassRefPtr<MetadataCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) -{ - String platformPath = m_asyncFileSystem->virtualToPlatformPath(entry->fullPath()); - m_asyncFileSystem->readMetadata(platformPath, MetadataCallbacks::create(successCallback, errorCallback)); -} - -static bool checkValidityForForCopyOrMove(const Entry* src, Entry* parent, const String& newName) -{ - ASSERT(src); - - 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 (src->isDirectory() && DOMFilePath::isParentOf(src->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() || src->name() == newName) && DOMFilePath::getDirectory(src->fullPath()) == parent->fullPath()) - return false; - - return true; -} - -void DOMFileSystem::move(const Entry* src, PassRefPtr<Entry> parent, const String& newName, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) -{ - if (!checkValidityForForCopyOrMove(src, parent.get(), newName)) { - scheduleCallback(scriptExecutionContext(), errorCallback, FileError::create(INVALID_MODIFICATION_ERR)); - return; - } - - String destPath = parent->fullPath(); - if (!newName.isEmpty()) - destPath = DOMFilePath::append(destPath, newName); - else - destPath = DOMFilePath::append(destPath, src->name()); - - String srcPlatformPath = m_asyncFileSystem->virtualToPlatformPath(src->fullPath()); - String destPlatformPath = parent->filesystem()->asyncFileSystem()->virtualToPlatformPath(destPath); - m_asyncFileSystem->move(srcPlatformPath, destPlatformPath, EntryCallbacks::create(successCallback, errorCallback, this, destPath, src->isDirectory())); -} - -void DOMFileSystem::copy(const Entry* src, PassRefPtr<Entry> parent, const String& newName, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) -{ - if (!checkValidityForForCopyOrMove(src, parent.get(), newName)) { - scheduleCallback(scriptExecutionContext(), errorCallback, FileError::create(INVALID_MODIFICATION_ERR)); - return; - } - - String destPath = parent->fullPath(); - if (!newName.isEmpty()) - destPath = DOMFilePath::append(destPath, newName); - else - destPath = DOMFilePath::append(destPath, src->name()); - - String srcPlatformPath = m_asyncFileSystem->virtualToPlatformPath(src->fullPath()); - String destPlatformPath = parent->filesystem()->asyncFileSystem()->virtualToPlatformPath(destPath); - m_asyncFileSystem->copy(srcPlatformPath, destPlatformPath, EntryCallbacks::create(successCallback, errorCallback, this, destPath, src->isDirectory())); -} - -void DOMFileSystem::remove(const Entry* entry, PassRefPtr<VoidCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) -{ - ASSERT(entry); - String platformPath = m_asyncFileSystem->virtualToPlatformPath(entry->fullPath()); - m_asyncFileSystem->remove(platformPath, VoidCallbacks::create(successCallback, errorCallback)); -} - -void DOMFileSystem::getParent(const Entry* 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)); -} - -void DOMFileSystem::getFile(const Entry* base, const String& path, PassRefPtr<Flags> flags, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) -{ - ASSERT(base); - if (!DOMFilePath::isValidPath(path)) { - scheduleCallback(scriptExecutionContext(), errorCallback, FileError::create(INVALID_MODIFICATION_ERR)); - return; - } - - String absolutePath = path; - if (!DOMFilePath::isAbsolute(path)) - absolutePath = DOMFilePath::removeExtraParentReferences(DOMFilePath::append(base->fullPath(), path)); - 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()); -} - -void DOMFileSystem::getDirectory(const Entry* base, const String& path, PassRefPtr<Flags> flags, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) -{ - ASSERT(base); - if (!DOMFilePath::isValidPath(path)) { - scheduleCallback(scriptExecutionContext(), errorCallback, FileError::create(INVALID_MODIFICATION_ERR)); - return; - } - - String absolutePath = path; - if (!DOMFilePath::isAbsolute(path)) - absolutePath = DOMFilePath::removeExtraParentReferences(DOMFilePath::append(base->fullPath(), path)); - 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()); -} - -void DOMFileSystem::createWriter(const FileEntry* file, PassRefPtr<FileWriterCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) +void DOMFileSystem::createWriter(const FileEntry* fileEntry, PassRefPtr<FileWriterCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) { - ASSERT(file); + ASSERT(fileEntry); - String platformPath = m_asyncFileSystem->virtualToPlatformPath(file->fullPath()); + String platformPath = m_asyncFileSystem->virtualToPlatformPath(fileEntry->fullPath()); RefPtr<FileWriter> fileWriter = FileWriter::create(scriptExecutionContext()); OwnPtr<FileWriterCallbacks> callbacks = FileWriterCallbacks::create(fileWriter, successCallback, errorCallback); m_asyncFileSystem->createWriter(fileWriter.get(), platformPath, callbacks.release()); } -void DOMFileSystem::readDirectory(const String& path, PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) +void DOMFileSystem::createFile(const FileEntry* fileEntry, PassRefPtr<FileCallback> successCallback, PassRefPtr<ErrorCallback>) { - ASSERT(DOMFilePath::isAbsolute(path)); - String platformPath = m_asyncFileSystem->virtualToPlatformPath(path); - m_asyncFileSystem->readDirectory(platformPath, EntriesCallbacks::create(successCallback, errorCallback, this, path)); + String platformPath = m_asyncFileSystem->virtualToPlatformPath(fileEntry->fullPath()); + scheduleCallback(successCallback, File::create(platformPath)); } } // namespace diff --git a/WebCore/fileapi/DOMFileSystem.h b/WebCore/fileapi/DOMFileSystem.h index 881ffc5..1d820f1 100644 --- a/WebCore/fileapi/DOMFileSystem.h +++ b/WebCore/fileapi/DOMFileSystem.h @@ -34,35 +34,24 @@ #if ENABLE(FILE_SYSTEM) #include "ActiveDOMObject.h" -#include "AsyncFileSystem.h" -#include "Flags.h" -#include "PlatformString.h" +#include "DOMFileSystemBase.h" #include "ScriptExecutionContext.h" -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> namespace WebCore { class DirectoryEntry; -class Entry; -class EntryCallback; -class EntriesCallback; -class ErrorCallback; +class File; +class FileCallback; class FileEntry; class FileWriterCallback; -class MetadataCallback; -class VoidCallback; -class DOMFileSystem : public RefCounted<DOMFileSystem>, public ActiveDOMObject { +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)); } - virtual ~DOMFileSystem(); - - const String& name() const { return m_name; } PassRefPtr<DirectoryEntry> root(); // ActiveDOMObject methods. @@ -70,28 +59,24 @@ public: virtual bool hasPendingActivity() const; virtual void contextDestroyed(); - // Actual FileSystem API implementations. All the validity checks on virtual paths are done at DOMFileSystem level. - void getMetadata(const Entry* entry, PassRefPtr<MetadataCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback); - void move(const Entry* src, PassRefPtr<Entry> parent, const String& name, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>); - void copy(const Entry* src, PassRefPtr<Entry> parent, const String& name, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>); - void remove(const Entry* entry, PassRefPtr<VoidCallback>, PassRefPtr<ErrorCallback>); - void getParent(const Entry* entry, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>); - void getFile(const Entry* base, const String& path, PassRefPtr<Flags>, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>); - void getDirectory(const Entry* base, const String& path, PassRefPtr<Flags>, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>); - void readDirectory(const String& path, PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>); - void createWriter(const FileEntry* file, PassRefPtr<FileWriterCallback>, PassRefPtr<ErrorCallback>); + 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>); - AsyncFileSystem* asyncFileSystem() const { return m_asyncFileSystem.get(); } - // A helper template to schedule a callback task. - // FIXME: move this to a more generic place. template <typename CB, typename CBArg> class DispatchCallbackTask : public ScriptExecutionContext::Task { public: @@ -110,15 +95,13 @@ private: RefPtr<CB> m_callback; RefPtr<CBArg> m_callbackArg; }; - - String m_name; - mutable OwnPtr<AsyncFileSystem> m_asyncFileSystem; }; 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)); } diff --git a/WebCore/fileapi/DOMFileSystemBase.cpp b/WebCore/fileapi/DOMFileSystemBase.cpp new file mode 100644 index 0000000..fefe99f --- /dev/null +++ b/WebCore/fileapi/DOMFileSystemBase.cpp @@ -0,0 +1,203 @@ +/* + * 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 "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(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/WebCore/fileapi/DOMFileSystemBase.h b/WebCore/fileapi/DOMFileSystemBase.h new file mode 100644 index 0000000..36e35b4 --- /dev/null +++ b/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(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/WebCore/fileapi/DOMFileSystemSync.cpp b/WebCore/fileapi/DOMFileSystemSync.cpp new file mode 100644 index 0000000..3de64a7 --- /dev/null +++ b/WebCore/fileapi/DOMFileSystemSync.cpp @@ -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. + */ + +#include "config.h" +#include "DOMFileSystemSync.h" + +#if ENABLE(FILE_SYSTEM) + +#include "DOMFilePath.h" +#include "DirectoryEntrySync.h" +#include "File.h" +#include "FileEntrySync.h" + +namespace WebCore { + +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); +} + +} + +#endif // ENABLE(FILE_SYSTEM) diff --git a/WebCore/fileapi/DOMFileSystemSync.h b/WebCore/fileapi/DOMFileSystemSync.h new file mode 100644 index 0000000..1856747 --- /dev/null +++ b/WebCore/fileapi/DOMFileSystemSync.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 DOMFileSystemSync_h +#define DOMFileSystemSync_h + +#if ENABLE(FILE_SYSTEM) + +#include "DOMFileSystemBase.h" + +namespace WebCore { + +class DirectoryEntrySync; +class File; +class FileEntrySync; + +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&); + +private: + DOMFileSystemSync(const String& name, PassOwnPtr<AsyncFileSystem>); +}; + +} + +#endif // ENABLE(FILE_SYSTEM) + +#endif // DOMFileSystemSync_h diff --git a/WebCore/fileapi/DOMFileSystemSync.idl b/WebCore/fileapi/DOMFileSystemSync.idl new file mode 100644 index 0000000..b51d8cc --- /dev/null +++ b/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/WebCore/fileapi/DirectoryEntry.cpp b/WebCore/fileapi/DirectoryEntry.cpp index 95c12e4..765fcd5 100644 --- a/WebCore/fileapi/DirectoryEntry.cpp +++ b/WebCore/fileapi/DirectoryEntry.cpp @@ -36,10 +36,12 @@ #include "DirectoryReader.h" #include "EntryCallback.h" #include "ErrorCallback.h" +#include "FileError.h" +#include "VoidCallback.h" namespace WebCore { -DirectoryEntry::DirectoryEntry(DOMFileSystem* fileSystem, const String& fullPath) +DirectoryEntry::DirectoryEntry(DOMFileSystemBase* fileSystem, const String& fullPath) : Entry(fileSystem, fullPath) { } @@ -49,16 +51,27 @@ 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> errorCallback) +void DirectoryEntry::getFile(const String& path, PassRefPtr<Flags> flags, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef) { - m_fileSystem->getFile(this, path, flags, successCallback, errorCallback); + RefPtr<ErrorCallback> errorCallback(errorCallbackRef); + if (!m_fileSystem->getFile(this, path, flags, successCallback, errorCallback)) + filesystem()->scheduleCallback(errorCallback.release(), FileError::create(INVALID_MODIFICATION_ERR)); } -void DirectoryEntry::getDirectory(const String& path, PassRefPtr<Flags> flags, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) +void DirectoryEntry::getDirectory(const String& path, PassRefPtr<Flags> flags, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef) { - m_fileSystem->getDirectory(this, path, flags, successCallback, errorCallback); + RefPtr<ErrorCallback> errorCallback(errorCallbackRef); + if (!m_fileSystem->getDirectory(this, path, flags, successCallback, errorCallback)) + filesystem()->scheduleCallback(errorCallback.release(), FileError::create(INVALID_MODIFICATION_ERR)); } -} // namespace +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(INVALID_MODIFICATION_ERR)); +} + +} #endif // ENABLE(FILE_SYSTEM) diff --git a/WebCore/fileapi/DirectoryEntry.h b/WebCore/fileapi/DirectoryEntry.h index c76b204..dd0159e 100644 --- a/WebCore/fileapi/DirectoryEntry.h +++ b/WebCore/fileapi/DirectoryEntry.h @@ -41,13 +41,15 @@ namespace WebCore { +class DOMFileSystemBase; class DirectoryReader; class EntryCallback; class ErrorCallback; +class VoidCallback; class DirectoryEntry : public Entry { public: - static PassRefPtr<DirectoryEntry> create(DOMFileSystem* fileSystem, const String& fullPath) + static PassRefPtr<DirectoryEntry> create(DOMFileSystemBase* fileSystem, const String& fullPath) { return adoptRef(new DirectoryEntry(fileSystem, fullPath)); } @@ -56,9 +58,10 @@ public: 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(DOMFileSystem* fileSystem, const String& fullPath); + DirectoryEntry(DOMFileSystemBase*, const String& fullPath); }; } // namespace diff --git a/WebCore/fileapi/DirectoryEntry.idl b/WebCore/fileapi/DirectoryEntry.idl index 2880ed0..0e38153 100644 --- a/WebCore/fileapi/DirectoryEntry.idl +++ b/WebCore/fileapi/DirectoryEntry.idl @@ -38,5 +38,6 @@ module storage { 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/WebCore/fileapi/DirectoryEntrySync.cpp b/WebCore/fileapi/DirectoryEntrySync.cpp new file mode 100644 index 0000000..d8d22c2 --- /dev/null +++ b/WebCore/fileapi/DirectoryEntrySync.cpp @@ -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. + */ + +#include "config.h" +#include "DirectoryEntrySync.h" + +#if ENABLE(FILE_SYSTEM) + +#include "DirectoryReaderSync.h" +#include "EntrySync.h" +#include "FileEntrySync.h" +#include "SyncCallbackHelper.h" + +namespace WebCore { + +DirectoryEntrySync::DirectoryEntrySync(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 = 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 = 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 = INVALID_MODIFICATION_ERR; + return; + } + helper.getResult(ec); +} + +} + +#endif // ENABLE(FILE_SYSTEM) diff --git a/WebCore/fileapi/DirectoryEntrySync.h b/WebCore/fileapi/DirectoryEntrySync.h new file mode 100644 index 0000000..9a3e0df --- /dev/null +++ b/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(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(DOMFileSystemBase*, const String& fullPath); +}; + +} + +#endif // ENABLE(FILE_SYSTEM) + +#endif // DirectoryEntrySync_h diff --git a/WebCore/fileapi/DirectoryEntrySync.idl b/WebCore/fileapi/DirectoryEntrySync.idl new file mode 100644 index 0000000..268b2a9 --- /dev/null +++ b/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/WebCore/fileapi/DirectoryReader.cpp b/WebCore/fileapi/DirectoryReader.cpp index b0eef1c..3437675 100644 --- a/WebCore/fileapi/DirectoryReader.cpp +++ b/WebCore/fileapi/DirectoryReader.cpp @@ -33,23 +33,27 @@ #if ENABLE(FILE_SYSTEM) -#include "DOMFileSystem.h" #include "EntriesCallback.h" +#include "EntryArray.h" #include "ErrorCallback.h" +#include "FileError.h" namespace WebCore { -DirectoryReader::DirectoryReader(PassRefPtr<DOMFileSystem> fileSystem, const String& fullPath) - : m_fileSystem(fileSystem) - , m_fullPath(fullPath) +DirectoryReader::DirectoryReader(DOMFileSystemBase* fileSystem, const String& fullPath) + : DirectoryReaderBase(fileSystem, fullPath) { } void DirectoryReader::readEntries(PassRefPtr<EntriesCallback> entriesCallback, PassRefPtr<ErrorCallback> errorCallback) { - m_fileSystem->readDirectory(m_fullPath, entriesCallback, errorCallback); + if (!m_hasMoreEntries) { + filesystem()->scheduleCallback(entriesCallback, EntryArray::create()); + return; + } + filesystem()->readDirectory(this, m_fullPath, entriesCallback, errorCallback); } -} // namespace +} #endif // ENABLE(FILE_SYSTEM) diff --git a/WebCore/fileapi/DirectoryReader.h b/WebCore/fileapi/DirectoryReader.h index 0e2ef0f..806fdf1 100644 --- a/WebCore/fileapi/DirectoryReader.h +++ b/WebCore/fileapi/DirectoryReader.h @@ -34,6 +34,7 @@ #if ENABLE(FILE_SYSTEM) #include "DOMFileSystem.h" +#include "DirectoryReaderBase.h" #include "PlatformString.h" #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> @@ -41,25 +42,25 @@ namespace WebCore { class EntriesCallback; +class EntriesCallbacks; class ErrorCallback; -class DirectoryReader : public RefCounted<DirectoryReader> { +class DirectoryReader : public DirectoryReaderBase { public: - static PassRefPtr<DirectoryReader> create(PassRefPtr<DOMFileSystem> fileSystem, const String& path) + static PassRefPtr<DirectoryReader> create(DOMFileSystemBase* fileSystem, const String& fullPath) { - return adoptRef(new DirectoryReader(fileSystem, path)); + return adoptRef(new DirectoryReader(fileSystem, fullPath)); } - void readEntries(PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback = 0); + void readEntries(PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback> = 0); -private: - DirectoryReader(PassRefPtr<DOMFileSystem> fileSystem, const String& path); + DOMFileSystem* filesystem() const { return static_cast<DOMFileSystem*>(m_fileSystem); } - RefPtr<DOMFileSystem> m_fileSystem; - String m_fullPath; +private: + DirectoryReader(DOMFileSystemBase*, const String& fullPath); }; -} // namespace +} #endif // ENABLE(FILE_SYSTEM) diff --git a/WebCore/fileapi/DirectoryReaderBase.h b/WebCore/fileapi/DirectoryReaderBase.h new file mode 100644 index 0000000..5a2c048 --- /dev/null +++ b/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; } + void setHasMoreEntries(bool hasMoreEntries) { m_hasMoreEntries = hasMoreEntries; } + +protected: + DirectoryReaderBase(DOMFileSystemBase* fileSystem, const String& fullPath) + : m_fileSystem(fileSystem) + , m_fullPath(fullPath) + , m_hasMoreEntries(true) + { + } + + 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/WebCore/fileapi/DirectoryReaderSync.cpp b/WebCore/fileapi/DirectoryReaderSync.cpp new file mode 100644 index 0000000..6c66a15 --- /dev/null +++ b/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 "FileError.h" +#include "SyncCallbackHelper.h" + +namespace WebCore { + +DirectoryReaderSync::DirectoryReaderSync(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 = INVALID_MODIFICATION_ERR; + setHasMoreEntries(false); + return 0; + } + return helper.getResult(ec); +} + +} // namespace + +#endif // ENABLE(FILE_SYSTEM) diff --git a/WebCore/fileapi/DirectoryReaderSync.h b/WebCore/fileapi/DirectoryReaderSync.h new file mode 100644 index 0000000..39119b7 --- /dev/null +++ b/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(DOMFileSystemBase* fileSystem, const String& fullPath) + { + return adoptRef(new DirectoryReaderSync(fileSystem, fullPath)); + } + + PassRefPtr<EntryArraySync> readEntries(ExceptionCode&); + +private: + DirectoryReaderSync(DOMFileSystemBase*, const String& fullPath); +}; + +} // namespace + +#endif // ENABLE(FILE_SYSTEM) + +#endif // DirectoryReaderSync_h diff --git a/WebCore/fileapi/DirectoryReaderSync.idl b/WebCore/fileapi/DirectoryReaderSync.idl new file mode 100644 index 0000000..aa39928 --- /dev/null +++ b/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/WebCore/fileapi/Entry.cpp b/WebCore/fileapi/Entry.cpp index 969ae2b..2183b33 100644 --- a/WebCore/fileapi/Entry.cpp +++ b/WebCore/fileapi/Entry.cpp @@ -32,46 +32,54 @@ #if ENABLE(FILE_SYSTEM) -#include "DOMFilePath.h" -#include "DOMFileSystem.h" +#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(DOMFileSystem* fileSystem, const String& fullPath) - : m_fileSystem(fileSystem) - , m_fullPath(fullPath) - , m_name(DOMFilePath::getName(fullPath)) +Entry::Entry(DOMFileSystemBase* fileSystem, const String& fullPath) + : EntryBase(fileSystem, fullPath) { } -void Entry::getMetadata(PassRefPtr<MetadataCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) +void Entry::getMetadata(PassRefPtr<MetadataCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef) { - m_fileSystem->getMetadata(this, successCallback, errorCallback); + RefPtr<ErrorCallback> errorCallback(errorCallbackRef); + if (!m_fileSystem->getMetadata(this, successCallback, errorCallback)) + filesystem()->scheduleCallback(errorCallback.release(), FileError::create(INVALID_MODIFICATION_ERR)); } -void Entry::moveTo(PassRefPtr<Entry> parent, const String& name, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) const +void Entry::moveTo(PassRefPtr<DirectoryEntry> parent, const String& name, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef) const { - m_fileSystem->move(this, parent, name, successCallback, errorCallback); + RefPtr<ErrorCallback> errorCallback(errorCallbackRef); + if (!m_fileSystem->move(this, parent.get(), name, successCallback, errorCallback)) + filesystem()->scheduleCallback(errorCallback.release(), FileError::create(INVALID_MODIFICATION_ERR)); } -void Entry::copyTo(PassRefPtr<Entry> parent, const String& name, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) const +void Entry::copyTo(PassRefPtr<DirectoryEntry> parent, const String& name, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef) const { - m_fileSystem->copy(this, parent, name, successCallback, errorCallback); + RefPtr<ErrorCallback> errorCallback(errorCallbackRef); + if (!m_fileSystem->copy(this, parent.get(), name, successCallback, errorCallback)) + filesystem()->scheduleCallback(errorCallback.release(), FileError::create(INVALID_MODIFICATION_ERR)); } -void Entry::remove(PassRefPtr<VoidCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) const +void Entry::remove(PassRefPtr<VoidCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef) const { - m_fileSystem->remove(this, successCallback, errorCallback); + RefPtr<ErrorCallback> errorCallback(errorCallbackRef); + if (!m_fileSystem->remove(this, successCallback, errorCallback)) + filesystem()->scheduleCallback(errorCallback.release(), FileError::create(INVALID_MODIFICATION_ERR)); } -void Entry::getParent(PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) const +void Entry::getParent(PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallbackRef) const { - m_fileSystem->getParent(this, successCallback, errorCallback); + RefPtr<ErrorCallback> errorCallback(errorCallbackRef); + if (!m_fileSystem->getParent(this, successCallback, errorCallback)) + filesystem()->scheduleCallback(errorCallback.release(), FileError::create(INVALID_MODIFICATION_ERR)); } String Entry::toURI(const String&) diff --git a/WebCore/fileapi/Entry.h b/WebCore/fileapi/Entry.h index 9af532f..36f85eb 100644 --- a/WebCore/fileapi/Entry.h +++ b/WebCore/fileapi/Entry.h @@ -34,42 +34,33 @@ #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 RefCounted<Entry> { +class Entry : public EntryBase { public: - virtual ~Entry() { } + DOMFileSystem* filesystem() const { return static_cast<DOMFileSystem*>(m_fileSystem); } - virtual bool isFile() const { return false; } - virtual bool isDirectory() const { return false; } + 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; - const String& fullPath() const { return m_fullPath; } - const String& name() const { return m_name; } - - DOMFileSystem* filesystem() const { return m_fileSystem; } - - virtual void getMetadata(PassRefPtr<MetadataCallback> successCallback = 0, PassRefPtr<ErrorCallback> errorCallback = 0); - virtual void moveTo(PassRefPtr<Entry> parent, const String& name = String(), PassRefPtr<EntryCallback> successCallback = 0, PassRefPtr<ErrorCallback> errorCallback = 0) const; - virtual void copyTo(PassRefPtr<Entry> parent, const String& name = String(), PassRefPtr<EntryCallback> successCallback = 0, PassRefPtr<ErrorCallback> errorCallback = 0) const; - virtual void remove(PassRefPtr<VoidCallback> successCallback = 0, PassRefPtr<ErrorCallback> errorCallback = 0) const; - virtual void getParent(PassRefPtr<EntryCallback> successCallback = 0, PassRefPtr<ErrorCallback> errorCallback = 0) const; - - virtual String toURI(const String& mimeType = String()); + String toURI(const String& mimeType = String()); protected: - Entry(DOMFileSystem* fileSystem, const String& fullPath); - - DOMFileSystem* m_fileSystem; - String m_fullPath; - String m_name; + Entry(DOMFileSystemBase*, const String& fullPath); }; } // namespace WebCore diff --git a/WebCore/fileapi/Entry.idl b/WebCore/fileapi/Entry.idl index d363bcd..f6fcdb3 100644 --- a/WebCore/fileapi/Entry.idl +++ b/WebCore/fileapi/Entry.idl @@ -41,8 +41,8 @@ module storage { readonly attribute DOMFileSystem filesystem; void getMetadata(in [Optional, Callback] MetadataCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback); - void moveTo(in Entry parent, in [Optional, ConvertUndefinedOrNullToNullString] DOMString name, in [Optional, Callback] EntryCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback); - void copyTo(in Entry parent, in [Optional, ConvertUndefinedOrNullToNullString] DOMString name, in [Optional, Callback] EntryCallback 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/WebCore/fileapi/EntryArraySync.cpp b/WebCore/fileapi/EntryArraySync.cpp new file mode 100644 index 0000000..1e2fa91 --- /dev/null +++ b/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/WebCore/fileapi/EntryArraySync.h b/WebCore/fileapi/EntryArraySync.h new file mode 100644 index 0000000..46cf409 --- /dev/null +++ b/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/WebCore/fileapi/EntryArraySync.idl b/WebCore/fileapi/EntryArraySync.idl new file mode 100644 index 0000000..bd54f33 --- /dev/null +++ b/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/WebCore/fileapi/EntryBase.h b/WebCore/fileapi/EntryBase.h new file mode 100644 index 0000000..2aaeba8 --- /dev/null +++ b/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; } + + 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(DOMFileSystemBase* fileSystem, const String& fullPath) + : m_fileSystem(fileSystem) + , m_fullPath(fullPath) + , m_name(DOMFilePath::getName(fullPath)) + { + } + + friend class EntrySync; + + DOMFileSystemBase* m_fileSystem; + + // This is a virtual path. + String m_fullPath; + + String m_name; +}; + +} + +#endif // ENABLE(FILE_SYSTEM) + +#endif // EntryBase_h diff --git a/WebCore/fileapi/EntrySync.cpp b/WebCore/fileapi/EntrySync.cpp new file mode 100644 index 0000000..ad007db --- /dev/null +++ b/WebCore/fileapi/EntrySync.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "EntrySync.h" + +#if ENABLE(FILE_SYSTEM) + +#include "DOMFilePath.h" +#include "DOMFileSystemSync.h" +#include "DirectoryEntry.h" +#include "DirectoryEntrySync.h" +#include "FileEntrySync.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 = 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 = 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 = 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 = 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(DOMFileSystemBase* fileSystem, const String& fullPath) + : EntryBase(fileSystem, fullPath) +{ +} + +} + +#endif // ENABLE(FILE_SYSTEM) diff --git a/WebCore/fileapi/EntrySync.h b/WebCore/fileapi/EntrySync.h new file mode 100644 index 0000000..24a0101 --- /dev/null +++ b/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); } + + 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(DOMFileSystemBase*, const String& fullPath); +}; + +} + +#endif // ENABLE(FILE_SYSTEM) + +#endif // EntrySync_h diff --git a/WebCore/fileapi/EntrySync.idl b/WebCore/fileapi/EntrySync.idl new file mode 100644 index 0000000..fb7ee3c --- /dev/null +++ b/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/WebCore/fileapi/FileEntry.cpp b/WebCore/fileapi/FileEntry.cpp index 2d1e623..29cbd33 100644 --- a/WebCore/fileapi/FileEntry.cpp +++ b/WebCore/fileapi/FileEntry.cpp @@ -33,25 +33,27 @@ #if ENABLE(FILE_SYSTEM) +#include "DOMFileSystem.h" #include "ErrorCallback.h" +#include "File.h" #include "FileCallback.h" #include "FileWriterCallback.h" namespace WebCore { -FileEntry::FileEntry(DOMFileSystem* fileSystem, const String& fullPath) +FileEntry::FileEntry(DOMFileSystemBase* fileSystem, const String& fullPath) : Entry(fileSystem, fullPath) { } -void FileEntry::createWriter(PassRefPtr<FileWriterCallback>, PassRefPtr<ErrorCallback>) +void FileEntry::createWriter(PassRefPtr<FileWriterCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) { - // FIXME: to be implemented. + filesystem()->createWriter(this, successCallback, errorCallback); } -void FileEntry::file(PassRefPtr<FileCallback>, PassRefPtr<ErrorCallback>) +void FileEntry::file(PassRefPtr<FileCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) { - // FIXME: to be implemented. + filesystem()->createFile(this, successCallback, errorCallback); } } // namespace diff --git a/WebCore/fileapi/FileEntry.h b/WebCore/fileapi/FileEntry.h index 2c85d73..216cca2 100644 --- a/WebCore/fileapi/FileEntry.h +++ b/WebCore/fileapi/FileEntry.h @@ -39,11 +39,11 @@ namespace WebCore { -class DOMFileSystem; +class DOMFileSystemBase; class FileEntry : public Entry { public: - static PassRefPtr<FileEntry> create(DOMFileSystem* fileSystem, const String& fullPath) + static PassRefPtr<FileEntry> create(DOMFileSystemBase* fileSystem, const String& fullPath) { return adoptRef(new FileEntry(fileSystem, fullPath)); } @@ -54,7 +54,7 @@ public: virtual bool isFile() const { return true; } private: - FileEntry(DOMFileSystem* fileSystem, const String& fullPath); + FileEntry(DOMFileSystemBase* fileSystem, const String& fullPath); }; } // namespace diff --git a/WebCore/fileapi/FileEntrySync.cpp b/WebCore/fileapi/FileEntrySync.cpp new file mode 100644 index 0000000..8fc5a77 --- /dev/null +++ b/WebCore/fileapi/FileEntrySync.cpp @@ -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. + */ + +#include "config.h" +#include "FileEntrySync.h" + +#if ENABLE(FILE_SYSTEM) + +#include "File.h" + +namespace WebCore { + +FileEntrySync::FileEntrySync(DOMFileSystemBase* fileSystem, const String& fullPath) + : EntrySync(fileSystem, fullPath) +{ +} + +PassRefPtr<File> FileEntrySync::file(ExceptionCode& ec) +{ + return filesystem()->createFile(this, ec); +} + +} + +#endif // ENABLE(FILE_SYSTEM) diff --git a/WebCore/fileapi/FileEntrySync.h b/WebCore/fileapi/FileEntrySync.h new file mode 100644 index 0000000..d027f63 --- /dev/null +++ b/WebCore/fileapi/FileEntrySync.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 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 FileEntrySync : public EntrySync { +public: + static PassRefPtr<FileEntrySync> create(DOMFileSystemBase* fileSystem, const String& fullPath) + { + return adoptRef(new FileEntrySync(fileSystem, fullPath)); + } + + virtual bool isFile() const { return true; } + + PassRefPtr<File> file(ExceptionCode&); + +private: + friend class EntrySync; + FileEntrySync(DOMFileSystemBase*, const String& fullPath); +}; + +} + +#endif // ENABLE(FILE_SYSTEM) + +#endif // FileEntrySync_h diff --git a/WebCore/fileapi/FileEntrySync.idl b/WebCore/fileapi/FileEntrySync.idl new file mode 100644 index 0000000..e2d2871 --- /dev/null +++ b/WebCore/fileapi/FileEntrySync.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, + GenerateNativeConverter, + GenerateToJS, + NoStaticTables + ] FileEntrySync : EntrySync { + File file() raises (FileException); + }; +} diff --git a/WebCore/fileapi/FileReader.cpp b/WebCore/fileapi/FileReader.cpp index 8036468..0b7b46d 100644 --- a/WebCore/fileapi/FileReader.cpp +++ b/WebCore/fileapi/FileReader.cpp @@ -43,6 +43,7 @@ #include "ProgressEvent.h" #include "ResourceError.h" #include "ResourceRequest.h" +#include "ResourceResponse.h" #include "ScriptExecutionContext.h" #include "TextResourceDecoder.h" #include "ThreadableBlobRegistry.h" @@ -57,7 +58,6 @@ FileReader::FileReader(ScriptExecutionContext* context) : ActiveDOMObject(context, this) , m_state(None) , m_readType(ReadFileAsBinaryString) - , m_result("") , m_isRawDataConverted(false) , m_bytesLoaded(0) , m_totalBytes(0) @@ -144,7 +144,7 @@ void FileReader::abort() terminate(); - m_result = ""; + m_builder.clear(); m_error = FileError::create(ABORT_ERR); fireEvent(eventNames().errorEvent); @@ -212,7 +212,7 @@ void FileReader::didReceiveData(const char* data, int lengthReceived) switch (m_readType) { case ReadFileAsBinaryString: - m_result += String(data, static_cast<unsigned>(lengthReceived)); + m_builder.append(data, static_cast<unsigned>(lengthReceived)); break; case ReadFileAsText: case ReadFileAsDataURL: @@ -296,30 +296,30 @@ FileReader::ReadyState FileReader::readyState() const return EMPTY; } -const ScriptString& FileReader::result() +String FileReader::result() { // If reading as binary string, we can return the result immediately. if (m_readType == ReadFileAsBinaryString) - return m_result; + return m_builder.toString(); // If we already convert the raw data received so far, we can return the result now. if (m_isRawDataConverted) - return m_result; + return m_builder.toString(); m_isRawDataConverted = true; if (m_readType == ReadFileAsText) convertToText(); // For data URL, we only do the coversion until we receive all the raw data. else if (m_readType == ReadFileAsDataURL && m_state == Completed) - convertToDataURL(m_rawData, m_fileType, m_result); + convertToDataURL(m_rawData, m_fileType, m_builder); - return m_result; + return m_builder.toString(); } void FileReader::convertToText() { if (!m_rawData.size()) { - m_result = ""; + m_builder.clear(); return; } @@ -330,28 +330,31 @@ void FileReader::convertToText() // FIXME: consider supporting incremental decoding to improve the perf. if (!m_decoder) m_decoder = TextResourceDecoder::create("text/plain", m_encoding.isValid() ? m_encoding : UTF8Encoding()); - m_result = m_decoder->decode(&m_rawData.at(0), m_rawData.size()); + m_builder.clear(); + m_builder.append(m_decoder->decode(&m_rawData.at(0), m_rawData.size())); if (m_state == Completed && !m_error) - m_result += m_decoder->flush(); + m_builder.append(m_decoder->flush()); } -void FileReader::convertToDataURL(const Vector<char>& rawData, const String& fileType, ScriptString& result) +void FileReader::convertToDataURL(const Vector<char>& rawData, const String& fileType, StringBuilder& builder) { - result = "data:"; + builder.clear(); + builder.append("data:"); if (!rawData.size()) return; - result += fileType; - if (!fileType.isEmpty()) - result += ";"; - result += "base64,"; + if (!fileType.isEmpty()) { + builder.append(fileType); + builder.append(";base64,"); + } else + builder.append("base64,"); Vector<char> out; base64Encode(rawData, out); out.append('\0'); - result += out.data(); + builder.append(out.data()); } } // namespace WebCore diff --git a/WebCore/fileapi/FileReader.h b/WebCore/fileapi/FileReader.h index 68c0f83..f914dad 100644 --- a/WebCore/fileapi/FileReader.h +++ b/WebCore/fileapi/FileReader.h @@ -37,14 +37,14 @@ #include "EventTarget.h" #include "FileError.h" #include "KURL.h" -#include "PlatformString.h" -#include "ScriptString.h" #include "TextEncoding.h" #include "ThreadableLoaderClient.h" #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> #include <wtf/RefPtr.h> #include <wtf/Vector.h> +#include <wtf/text/StringBuilder.h> +#include <wtf/text/WTFString.h> namespace WebCore { @@ -77,11 +77,11 @@ public: ReadyState readyState() const; PassRefPtr<FileError> error() { return m_error; } - const ScriptString& result(); + String result(); // Helper methods, also used by FileReaderSync. static ExceptionCode httpStatusCodeToExceptionCode(int httpStatusCode); - static void convertToDataURL(const Vector<char>& rawData, const String& fileType, ScriptString& result); + static void convertToDataURL(const Vector<char>& rawData, const String& fileType, StringBuilder&); // ActiveDOMObject virtual bool canSuspend() const; @@ -147,13 +147,7 @@ private: ReadType m_readType; TextEncoding m_encoding; - // Like XMLHttpRequest.m_responseText, we keep this as a ScriptString, not a WTF::String. - // That's because these strings can easily get huge (they are filled from the file) and - // because JS can easily observe many intermediate states, so it's very useful to be - // able to share the buffer with JavaScript versions of the whole or partial string. - // In contrast, this string doesn't interact much with the rest of the engine so it's not that - // big a cost that it isn't a String. - ScriptString m_result; + StringBuilder m_builder; // The raw data. We have to keep track of all the raw data for it to be converted to text or data URL data. Vector<char> m_rawData; diff --git a/WebCore/fileapi/FileReader.idl b/WebCore/fileapi/FileReader.idl index b36e9d3..febb231 100644 --- a/WebCore/fileapi/FileReader.idl +++ b/WebCore/fileapi/FileReader.idl @@ -34,7 +34,8 @@ module html { CanBeConstructed, CallWith=ScriptExecutionContext, EventTarget, - NoStaticTables + NoStaticTables, + V8CustomConstructor ] FileReader { // ready states const unsigned short EMPTY = 0; @@ -43,9 +44,9 @@ module html { readonly attribute unsigned short readyState; // async read methods - void readAsBinaryString(in Blob fileBlob); - void readAsText(in Blob fileBlob, in [Optional] DOMString encoding); - void readAsDataURL(in File file); + void readAsBinaryString(in Blob blob); + void readAsText(in Blob blob, in [Optional] DOMString encoding); + void readAsDataURL(in Blob blob); void abort(); diff --git a/WebCore/fileapi/FileReaderSync.cpp b/WebCore/fileapi/FileReaderSync.cpp index 6c76714..6425bcf 100644 --- a/WebCore/fileapi/FileReaderSync.cpp +++ b/WebCore/fileapi/FileReaderSync.cpp @@ -39,6 +39,7 @@ #include "BlobURL.h" #include "FileReader.h" #include "ResourceRequest.h" +#include "ResourceResponse.h" #include "ScriptExecutionContext.h" #include "TextEncoding.h" #include "TextResourceDecoder.h" @@ -50,7 +51,7 @@ namespace WebCore { class FileReaderSyncLoader : public ThreadableLoaderClient { public: // If the output result is provided, use it. Otherwise, save it as the raw data. - FileReaderSyncLoader(ScriptString* result); + FileReaderSyncLoader(StringBuilder*); // Returns the http status code. void start(ScriptExecutionContext*, const ResourceRequest&, ExceptionCode&); @@ -65,7 +66,7 @@ public: private: // The output result. The caller provides this in order to load the binary data directly. - ScriptString* m_result; + StringBuilder* m_builder; // The raw data. The caller does not provide the above output result and we need to save it here. Vector<char> m_rawData; @@ -73,8 +74,8 @@ private: int m_httpStatusCode; }; -FileReaderSyncLoader::FileReaderSyncLoader(ScriptString* result) - : m_result(result) +FileReaderSyncLoader::FileReaderSyncLoader(StringBuilder* builder) + : m_builder(builder) , m_httpStatusCode(0) { } @@ -100,8 +101,8 @@ void FileReaderSyncLoader::didReceiveResponse(const ResourceResponse& response) void FileReaderSyncLoader::didReceiveData(const char* data, int lengthReceived) { - if (m_result) - *m_result += String(data, static_cast<unsigned>(lengthReceived)); + if (m_builder) + m_builder->append(data, static_cast<unsigned>(lengthReceived)); else m_rawData.append(data, static_cast<unsigned>(lengthReceived)); } @@ -116,37 +117,32 @@ void FileReaderSyncLoader::didFail(const ResourceError&) m_httpStatusCode = 500; } -FileReaderSync::FileReaderSync() - : m_result("") -{ -} - -const ScriptString& FileReaderSync::readAsBinaryString(ScriptExecutionContext* scriptExecutionContext, Blob* blob, ExceptionCode& ec) +String FileReaderSync::readAsBinaryString(ScriptExecutionContext* scriptExecutionContext, Blob* blob, ExceptionCode& ec) { if (!blob) - return m_result; + return m_builder.toString(); read(scriptExecutionContext, blob, ReadAsBinaryString, ec); - return m_result; + return m_builder.toString(); } -const ScriptString& FileReaderSync::readAsText(ScriptExecutionContext* scriptExecutionContext, Blob* blob, const String& encoding, ExceptionCode& ec) +String FileReaderSync::readAsText(ScriptExecutionContext* scriptExecutionContext, Blob* blob, const String& encoding, ExceptionCode& ec) { if (!blob) - return m_result; + return m_builder.toString(); m_encoding = encoding; read(scriptExecutionContext, blob, ReadAsText, ec); - return m_result; + return m_builder.toString(); } -const ScriptString& FileReaderSync::readAsDataURL(ScriptExecutionContext* scriptExecutionContext, Blob* blob, ExceptionCode& ec) +String FileReaderSync::readAsDataURL(ScriptExecutionContext* scriptExecutionContext, Blob* blob, ExceptionCode& ec) { if (!blob) - return m_result; + return m_builder.toString(); read(scriptExecutionContext, blob, ReadAsDataURL, ec); - return m_result; + return m_builder.toString(); } void FileReaderSync::read(ScriptExecutionContext* scriptExecutionContext, Blob* blob, ReadType readType, ExceptionCode& ec) @@ -158,7 +154,7 @@ void FileReaderSync::read(ScriptExecutionContext* scriptExecutionContext, Blob* ResourceRequest request(urlForReading); request.setHTTPMethod("GET"); - FileReaderSyncLoader loader((readType == ReadAsBinaryString) ? &m_result : 0); + FileReaderSyncLoader loader((readType == ReadAsBinaryString) ? &m_builder : 0); loader.start(scriptExecutionContext, request, ec); ThreadableBlobRegistry::unregisterBlobURL(urlForReading); if (ec) @@ -169,17 +165,17 @@ void FileReaderSync::read(ScriptExecutionContext* scriptExecutionContext, Blob* // Nothing to do since we need no conversion. return; case ReadAsText: - convertToText(loader.rawData().data(), loader.rawData().size(), m_result); + convertToText(loader.rawData().data(), loader.rawData().size(), m_builder); return; case ReadAsDataURL: - FileReader::convertToDataURL(loader.rawData(), blob->type(), m_result); + FileReader::convertToDataURL(loader.rawData(), blob->type(), m_builder); return; } ASSERT_NOT_REACHED(); } -void FileReaderSync::convertToText(const char* data, int size, ScriptString& result) +void FileReaderSync::convertToText(const char* data, int size, StringBuilder& builder) { if (!size) return; @@ -190,8 +186,9 @@ void FileReaderSync::convertToText(const char* data, int size, ScriptString& res // provided encoding. // FIXME: consider supporting incremental decoding to improve the perf. RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("text/plain", m_encoding.isEmpty() ? UTF8Encoding() : TextEncoding(m_encoding)); - result = decoder->decode(data, size); - result += decoder->flush(); + builder.clear(); + builder.append(decoder->decode(data, size)); + builder.append(decoder->flush()); } } // namespace WebCore diff --git a/WebCore/fileapi/FileReaderSync.h b/WebCore/fileapi/FileReaderSync.h index a517cab..cb0e00d 100644 --- a/WebCore/fileapi/FileReaderSync.h +++ b/WebCore/fileapi/FileReaderSync.h @@ -34,9 +34,9 @@ #if ENABLE(BLOB) #include "ExceptionCode.h" -#include "ScriptString.h" #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> +#include <wtf/text/StringBuilder.h> namespace WebCore { @@ -52,13 +52,13 @@ public: virtual ~FileReaderSync() { } - const ScriptString& readAsBinaryString(ScriptExecutionContext*, Blob*, ExceptionCode&); - const ScriptString& readAsText(ScriptExecutionContext* scriptExecutionContext, Blob* blob, ExceptionCode& ec) + String readAsBinaryString(ScriptExecutionContext*, Blob*, ExceptionCode&); + String readAsText(ScriptExecutionContext* scriptExecutionContext, Blob* blob, ExceptionCode& ec) { return readAsText(scriptExecutionContext, blob, "", ec); } - const ScriptString& readAsText(ScriptExecutionContext*, Blob*, const String& encoding, ExceptionCode&); - const ScriptString& readAsDataURL(ScriptExecutionContext*, Blob*, ExceptionCode&); + String readAsText(ScriptExecutionContext*, Blob*, const String& encoding, ExceptionCode&); + String readAsDataURL(ScriptExecutionContext*, Blob*, ExceptionCode&); private: enum ReadType { @@ -67,18 +67,12 @@ private: ReadAsDataURL }; - FileReaderSync(); - + FileReaderSync() { } + void read(ScriptExecutionContext*, Blob*, ReadType, ExceptionCode&); - void convertToText(const char* data, int size, ScriptString& result); - - // Like XMLHttpRequest.m_responseText, we keep this as a ScriptString, not a WTF::String. - // That's because these strings can easily get huge (they are filled from the file) and - // because JS can easily observe many intermediate states, so it's very useful to be - // able to share the buffer with JavaScript versions of the whole or partial string. - // In contrast, this string doesn't interact much with the rest of the engine so it's not that - // big a cost that it isn't a String. - ScriptString m_result; + void convertToText(const char* data, int size, StringBuilder&); + + StringBuilder m_builder; String m_encoding; }; diff --git a/WebCore/fileapi/FileSystemCallbacks.cpp b/WebCore/fileapi/FileSystemCallbacks.cpp index 550b509..e5f404e 100644 --- a/WebCore/fileapi/FileSystemCallbacks.cpp +++ b/WebCore/fileapi/FileSystemCallbacks.cpp @@ -36,8 +36,9 @@ #include "AsyncFileSystem.h" #include "AsyncFileWriter.h" #include "DOMFilePath.h" -#include "DOMFileSystem.h" +#include "DOMFileSystemBase.h" #include "DirectoryEntry.h" +#include "DirectoryReader.h" #include "EntriesCallback.h" #include "EntryArray.h" #include "EntryCallback.h" @@ -110,12 +111,12 @@ void FileSystemCallbacksBase::didFail(int code) // EntryCallbacks ------------------------------------------------------------- -PassOwnPtr<EntryCallbacks> EntryCallbacks::create(PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, DOMFileSystem* fileSystem, const String& expectedPath, bool isDirectory) +PassOwnPtr<EntryCallbacks> EntryCallbacks::create(PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, DOMFileSystemBase* fileSystem, const String& expectedPath, bool isDirectory) { return adoptPtr(new EntryCallbacks(successCallback, errorCallback, fileSystem, expectedPath, isDirectory)); } -EntryCallbacks::EntryCallbacks(PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, DOMFileSystem* fileSystem, const String& expectedPath, bool isDirectory) +EntryCallbacks::EntryCallbacks(PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, DOMFileSystemBase* fileSystem, const String& expectedPath, bool isDirectory) : FileSystemCallbacksBase(errorCallback) , m_successCallback(successCallback) , m_fileSystem(fileSystem) @@ -137,39 +138,34 @@ void EntryCallbacks::didSucceed() // EntriesCallbacks ----------------------------------------------------------- -PassOwnPtr<EntriesCallbacks> EntriesCallbacks::create(PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, DOMFileSystem* fileSystem, const String& basePath) +PassOwnPtr<EntriesCallbacks> EntriesCallbacks::create(PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, DirectoryReaderBase* directoryReader, const String& basePath) { - return adoptPtr(new EntriesCallbacks(successCallback, errorCallback, fileSystem, basePath)); + return adoptPtr(new EntriesCallbacks(successCallback, errorCallback, directoryReader, basePath)); } -EntriesCallbacks::EntriesCallbacks(PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, DOMFileSystem* fileSystem, const String& basePath) +EntriesCallbacks::EntriesCallbacks(PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, DirectoryReaderBase* directoryReader, const String& basePath) : FileSystemCallbacksBase(errorCallback) , m_successCallback(successCallback) - , m_fileSystem(fileSystem) + , 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_fileSystem, DOMFilePath::append(m_basePath, name))); + m_entries->append(DirectoryEntry::create(m_directoryReader->filesystem(), DOMFilePath::append(m_basePath, name))); else - m_entries->append(FileEntry::create(m_fileSystem, DOMFilePath::append(m_basePath, name))); + m_entries->append(FileEntry::create(m_directoryReader->filesystem(), DOMFilePath::append(m_basePath, name))); } void EntriesCallbacks::didReadDirectoryEntries(bool hasMore) { - if (m_successCallback) { + m_directoryReader->setHasMoreEntries(hasMore); + if (m_successCallback) m_successCallback->handleEvent(m_entries.get()); - if (!m_entries->isEmpty() && !hasMore) { - // If we have returned some entries and there're no more coming entries (hasMore==false), call back once more with an empty array. - m_successCallback->handleEvent(EntryArray::create().get()); - m_successCallback.clear(); - } - m_entries->clear(); - } } // FileSystemCallbacks -------------------------------------------------------- diff --git a/WebCore/fileapi/FileSystemCallbacks.h b/WebCore/fileapi/FileSystemCallbacks.h index 3647ad3..c600a76 100644 --- a/WebCore/fileapi/FileSystemCallbacks.h +++ b/WebCore/fileapi/FileSystemCallbacks.h @@ -41,7 +41,8 @@ namespace WebCore { class AsyncFileWriter; -class DOMFileSystem; +class DOMFileSystemBase; +class DirectoryReaderBase; class ErrorCallback; class EntriesCallback; class EntryArray; @@ -85,27 +86,27 @@ protected: class EntryCallbacks : public FileSystemCallbacksBase { public: - static PassOwnPtr<EntryCallbacks> create(PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, DOMFileSystem*, const String& expectedPath, bool isDirectory); + static PassOwnPtr<EntryCallbacks> create(PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, DOMFileSystemBase*, const String& expectedPath, bool isDirectory); virtual void didSucceed(); private: - EntryCallbacks(PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, DOMFileSystem*, const String& expectedPath, bool isDirectory); + EntryCallbacks(PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, DOMFileSystemBase*, const String& expectedPath, bool isDirectory); RefPtr<EntryCallback> m_successCallback; - DOMFileSystem* m_fileSystem; + DOMFileSystemBase* m_fileSystem; String m_expectedPath; bool m_isDirectory; }; class EntriesCallbacks : public FileSystemCallbacksBase { public: - static PassOwnPtr<EntriesCallbacks> create(PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>, DOMFileSystem*, const String& basePath); + static PassOwnPtr<EntriesCallbacks> create(PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>, DirectoryReaderBase*, const String& basePath); virtual void didReadDirectoryEntry(const String& name, bool isDirectory); virtual void didReadDirectoryEntries(bool hasMore); private: - EntriesCallbacks(PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>, DOMFileSystem*, const String& basePath); + EntriesCallbacks(PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>, DirectoryReaderBase*, const String& basePath); RefPtr<EntriesCallback> m_successCallback; - DOMFileSystem* m_fileSystem; + DirectoryReaderBase* m_directoryReader; String m_basePath; RefPtr<EntryArray> m_entries; }; diff --git a/WebCore/fileapi/FileWriter.cpp b/WebCore/fileapi/FileWriter.cpp index 8367bf9..bc76984 100644 --- a/WebCore/fileapi/FileWriter.cpp +++ b/WebCore/fileapi/FileWriter.cpp @@ -46,6 +46,7 @@ FileWriter::FileWriter(ScriptExecutionContext* context) : ActiveDOMObject(context, this) , m_readyState(INIT) , m_position(0) + , m_startedWriting(false) , m_bytesWritten(0) , m_bytesToWrite(0) , m_truncateLength(-1) @@ -81,6 +82,7 @@ void FileWriter::stop() { if (m_writer && m_readyState == WRITING) m_writer->abort(); + m_blobBeingWritten.clear(); m_readyState = DONE; } @@ -92,8 +94,15 @@ void FileWriter::write(Blob* data, ExceptionCode& ec) m_error = FileError::create(ec); return; } + if (!data) { + ec = TYPE_MISMATCH_ERR; + m_error = FileError::create(ec); + return; + } + m_blobBeingWritten = data; m_readyState = WRITING; + m_startedWriting = false; m_bytesWritten = 0; m_bytesToWrite = data->size(); m_writer->write(m_position, data); @@ -149,18 +158,21 @@ void FileWriter::abort(ExceptionCode& ec) void FileWriter::didWrite(long long bytes, bool complete) { - ASSERT(bytes > 0); ASSERT(bytes + m_bytesWritten > 0); ASSERT(bytes + m_bytesWritten <= m_bytesToWrite); - if (!m_bytesWritten) + if (!m_startedWriting) { fireEvent(eventNames().writestartEvent); + m_startedWriting = true; + } m_bytesWritten += bytes; - ASSERT((m_bytesWritten == m_bytesToWrite) == complete); + ASSERT((m_bytesWritten == m_bytesToWrite) || !complete); m_position += bytes; if (m_position > m_length) m_length = m_position; - fireEvent(eventNames().writeEvent); + fireEvent(eventNames().progressEvent); if (complete) { + m_blobBeingWritten.clear(); + fireEvent(eventNames().writeEvent); m_readyState = DONE; fireEvent(eventNames().writeendEvent); } @@ -186,6 +198,7 @@ void FileWriter::didFail(ExceptionCode ec) if (ABORT_ERR == ec) fireEvent(eventNames().abortEvent); fireEvent(eventNames().errorEvent); + m_blobBeingWritten.clear(); m_readyState = DONE; fireEvent(eventNames().writeendEvent); } diff --git a/WebCore/fileapi/FileWriter.h b/WebCore/fileapi/FileWriter.h index 4bb91ef..454081c 100644 --- a/WebCore/fileapi/FileWriter.h +++ b/WebCore/fileapi/FileWriter.h @@ -119,9 +119,11 @@ private: ReadyState m_readyState; long long m_position; long long m_length; + bool m_startedWriting; long long m_bytesWritten; long long m_bytesToWrite; long long m_truncateLength; + RefPtr<Blob> m_blobBeingWritten; }; } // namespace WebCore diff --git a/WebCore/fileapi/LocalFileSystem.cpp b/WebCore/fileapi/LocalFileSystem.cpp index 567aafe..c7347b8 100644 --- a/WebCore/fileapi/LocalFileSystem.cpp +++ b/WebCore/fileapi/LocalFileSystem.cpp @@ -81,7 +81,7 @@ static void openFileSystem(ScriptExecutionContext*, const String& basePath, cons AsyncFileSystem::openFileSystem(basePath, identifier, type, callbacks); } -void LocalFileSystem::requestFileSystem(ScriptExecutionContext* context, AsyncFileSystem::Type type, long long, PassOwnPtr<AsyncFileSystemCallbacks> 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, callbacks)); diff --git a/WebCore/fileapi/LocalFileSystem.h b/WebCore/fileapi/LocalFileSystem.h index bb1d045..9d8ae65 100644 --- a/WebCore/fileapi/LocalFileSystem.h +++ b/WebCore/fileapi/LocalFileSystem.h @@ -52,7 +52,7 @@ public: // calling this one. static LocalFileSystem& localFileSystem(); - void requestFileSystem(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. diff --git a/WebCore/fileapi/Metadata.h b/WebCore/fileapi/Metadata.h index 1fec943..b70806b 100644 --- a/WebCore/fileapi/Metadata.h +++ b/WebCore/fileapi/Metadata.h @@ -44,6 +44,11 @@ public: 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; } diff --git a/WebCore/fileapi/SyncCallbackHelper.h b/WebCore/fileapi/SyncCallbackHelper.h new file mode 100644 index 0000000..1612e93 --- /dev/null +++ b/WebCore/fileapi/SyncCallbackHelper.h @@ -0,0 +1,185 @@ +/* + * 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 "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_error(0) + , m_completed(false) + { + } + + PassRefPtr<ResultType> getResult(ExceptionCode& ec) + { + if (m_observer) { + while (!m_completed) { + if (!m_observer->waitForOperationToComplete()) { + m_error = ABORT_ERR; + break; + } + } + } + ec = m_error; + 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(ExceptionCode ec) + { + m_error = ec; + 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_error; + 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/WebCore/fileapi/ThreadableBlobRegistry.cpp b/WebCore/fileapi/ThreadableBlobRegistry.cpp index f74c680..2ec421b 100644 --- a/WebCore/fileapi/ThreadableBlobRegistry.cpp +++ b/WebCore/fileapi/ThreadableBlobRegistry.cpp @@ -41,8 +41,9 @@ namespace WebCore { struct BlobRegistryContext { BlobRegistryContext(const KURL& url, PassOwnPtr<BlobData> blobData) : url(url.copy()) - , blobData(blobData->copy()) + , blobData(blobData) { + this->blobData->detachFromCurrentThread(); } BlobRegistryContext(const KURL& url, const KURL& srcURL) |