diff options
Diffstat (limited to 'Source/WebCore/fileapi')
19 files changed, 393 insertions, 201 deletions
diff --git a/Source/WebCore/fileapi/FileStreamProxy.cpp b/Source/WebCore/fileapi/AsyncFileStream.cpp index d43506566..1b035ccc3 100644 --- a/Source/WebCore/fileapi/FileStreamProxy.cpp +++ b/Source/WebCore/fileapi/AsyncFileStream.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2010 Google Inc. All rights reserved. + * Copyright (C) 2012 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -30,13 +31,14 @@ #include "config.h" -#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM) +#if ENABLE(BLOB) -#include "FileStreamProxy.h" +#include "AsyncFileStream.h" #include "Blob.h" #include "CrossThreadTask.h" #include "FileStream.h" +#include "FileStreamClient.h" #include "FileThread.h" #include "FileThreadTask.h" #include "PlatformString.h" @@ -44,44 +46,44 @@ namespace WebCore { -inline FileStreamProxy::FileStreamProxy(ScriptExecutionContext* context, FileStreamClient* client) - : AsyncFileStream(client) - , m_context(context) +inline AsyncFileStream::AsyncFileStream(ScriptExecutionContext* context, FileStreamClient* client) + : m_context(context) , m_stream(FileStream::create()) + , m_client(client) { } -PassRefPtr<FileStreamProxy> FileStreamProxy::create(ScriptExecutionContext* context, FileStreamClient* client) +PassRefPtr<AsyncFileStream> AsyncFileStream::create(ScriptExecutionContext* context, FileStreamClient* client) { - RefPtr<FileStreamProxy> proxy = adoptRef(new FileStreamProxy(context, client)); + RefPtr<AsyncFileStream> proxy = adoptRef(new AsyncFileStream(context, client)); - // Hold an ref so that the instance will not get deleted while there are tasks on the file thread. + // Hold a reference so that the instance will not get deleted while there are tasks on the file thread. // This is balanced by the deref in derefProxyOnContext below. proxy->ref(); - proxy->fileThread()->postTask(createFileThreadTask(proxy.get(), &FileStreamProxy::startOnFileThread)); + proxy->fileThread()->postTask(createFileThreadTask(proxy.get(), &AsyncFileStream::startOnFileThread)); return proxy.release(); } -FileStreamProxy::~FileStreamProxy() +AsyncFileStream::~AsyncFileStream() { } -FileThread* FileStreamProxy::fileThread() +FileThread* AsyncFileStream::fileThread() { ASSERT(m_context->isContextThread()); ASSERT(m_context->fileThread()); return m_context->fileThread(); } -static void didStart(ScriptExecutionContext*, FileStreamProxy* proxy) +static void didStart(ScriptExecutionContext*, AsyncFileStream* proxy) { if (proxy->client()) proxy->client()->didStart(); } -void FileStreamProxy::startOnFileThread() +void AsyncFileStream::startOnFileThread() { if (!client()) return; @@ -89,132 +91,132 @@ void FileStreamProxy::startOnFileThread() m_context->postTask(createCallbackTask(&didStart, AllowCrossThreadAccess(this))); } -void FileStreamProxy::stop() +void AsyncFileStream::stop() { // Clear the client so that we won't be calling callbacks on the client. setClient(0); fileThread()->unscheduleTasks(m_stream.get()); - fileThread()->postTask(createFileThreadTask(this, &FileStreamProxy::stopOnFileThread)); + fileThread()->postTask(createFileThreadTask(this, &AsyncFileStream::stopOnFileThread)); } -static void derefProxyOnContext(ScriptExecutionContext*, FileStreamProxy* proxy) +static void derefProxyOnContext(ScriptExecutionContext*, AsyncFileStream* proxy) { ASSERT(proxy->hasOneRef()); proxy->deref(); } -void FileStreamProxy::stopOnFileThread() +void AsyncFileStream::stopOnFileThread() { m_stream->stop(); m_context->postTask(createCallbackTask(&derefProxyOnContext, AllowCrossThreadAccess(this))); } -static void didGetSize(ScriptExecutionContext*, FileStreamProxy* proxy, long long size) +static void didGetSize(ScriptExecutionContext*, AsyncFileStream* proxy, long long size) { if (proxy->client()) proxy->client()->didGetSize(size); } -void FileStreamProxy::getSize(const String& path, double expectedModificationTime) +void AsyncFileStream::getSize(const String& path, double expectedModificationTime) { - fileThread()->postTask(createFileThreadTask(this, &FileStreamProxy::getSizeOnFileThread, path, expectedModificationTime)); + fileThread()->postTask(createFileThreadTask(this, &AsyncFileStream::getSizeOnFileThread, path, expectedModificationTime)); } -void FileStreamProxy::getSizeOnFileThread(const String& path, double expectedModificationTime) +void AsyncFileStream::getSizeOnFileThread(const String& path, double expectedModificationTime) { long long size = m_stream->getSize(path, expectedModificationTime); m_context->postTask(createCallbackTask(&didGetSize, AllowCrossThreadAccess(this), size)); } -static void didOpen(ScriptExecutionContext*, FileStreamProxy* proxy, bool success) +static void didOpen(ScriptExecutionContext*, AsyncFileStream* proxy, bool success) { if (proxy->client()) proxy->client()->didOpen(success); } -void FileStreamProxy::openForRead(const String& path, long long offset, long long length) +void AsyncFileStream::openForRead(const String& path, long long offset, long long length) { - fileThread()->postTask(createFileThreadTask(this, &FileStreamProxy::openForReadOnFileThread, path, offset, length)); + fileThread()->postTask(createFileThreadTask(this, &AsyncFileStream::openForReadOnFileThread, path, offset, length)); } -void FileStreamProxy::openForReadOnFileThread(const String& path, long long offset, long long length) +void AsyncFileStream::openForReadOnFileThread(const String& path, long long offset, long long length) { bool success = m_stream->openForRead(path, offset, length); m_context->postTask(createCallbackTask(&didOpen, AllowCrossThreadAccess(this), success)); } -void FileStreamProxy::openForWrite(const String& path) +void AsyncFileStream::openForWrite(const String& path) { fileThread()->postTask( createFileThreadTask(this, - &FileStreamProxy::openForWriteOnFileThread, path)); + &AsyncFileStream::openForWriteOnFileThread, path)); } -void FileStreamProxy::openForWriteOnFileThread(const String& path) +void AsyncFileStream::openForWriteOnFileThread(const String& path) { bool success = m_stream->openForWrite(path); m_context->postTask(createCallbackTask(&didOpen, AllowCrossThreadAccess(this), success)); } -void FileStreamProxy::close() +void AsyncFileStream::close() { - fileThread()->postTask(createFileThreadTask(this, &FileStreamProxy::closeOnFileThread)); + fileThread()->postTask(createFileThreadTask(this, &AsyncFileStream::closeOnFileThread)); } -void FileStreamProxy::closeOnFileThread() +void AsyncFileStream::closeOnFileThread() { m_stream->close(); } -static void didRead(ScriptExecutionContext*, FileStreamProxy* proxy, int bytesRead) +static void didRead(ScriptExecutionContext*, AsyncFileStream* proxy, int bytesRead) { if (proxy->client()) proxy->client()->didRead(bytesRead); } -void FileStreamProxy::read(char* buffer, int length) +void AsyncFileStream::read(char* buffer, int length) { fileThread()->postTask( - createFileThreadTask(this, &FileStreamProxy::readOnFileThread, + createFileThreadTask(this, &AsyncFileStream::readOnFileThread, AllowCrossThreadAccess(buffer), length)); } -void FileStreamProxy::readOnFileThread(char* buffer, int length) +void AsyncFileStream::readOnFileThread(char* buffer, int length) { int bytesRead = m_stream->read(buffer, length); m_context->postTask(createCallbackTask(&didRead, AllowCrossThreadAccess(this), bytesRead)); } -static void didWrite(ScriptExecutionContext*, FileStreamProxy* proxy, int bytesWritten) +static void didWrite(ScriptExecutionContext*, AsyncFileStream* proxy, int bytesWritten) { if (proxy->client()) proxy->client()->didWrite(bytesWritten); } -void FileStreamProxy::write(const KURL& blobURL, long long position, int length) +void AsyncFileStream::write(const KURL& blobURL, long long position, int length) { - fileThread()->postTask(createFileThreadTask(this, &FileStreamProxy::writeOnFileThread, blobURL, position, length)); + fileThread()->postTask(createFileThreadTask(this, &AsyncFileStream::writeOnFileThread, blobURL, position, length)); } -void FileStreamProxy::writeOnFileThread(const KURL& blobURL, long long position, int length) +void AsyncFileStream::writeOnFileThread(const KURL& blobURL, long long position, int length) { int bytesWritten = m_stream->write(blobURL, position, length); m_context->postTask(createCallbackTask(&didWrite, AllowCrossThreadAccess(this), bytesWritten)); } -static void didTruncate(ScriptExecutionContext*, FileStreamProxy* proxy, bool success) +static void didTruncate(ScriptExecutionContext*, AsyncFileStream* proxy, bool success) { if (proxy->client()) proxy->client()->didTruncate(success); } -void FileStreamProxy::truncate(long long position) +void AsyncFileStream::truncate(long long position) { - fileThread()->postTask(createFileThreadTask(this, &FileStreamProxy::truncateOnFileThread, position)); + fileThread()->postTask(createFileThreadTask(this, &AsyncFileStream::truncateOnFileThread, position)); } -void FileStreamProxy::truncateOnFileThread(long long position) +void AsyncFileStream::truncateOnFileThread(long long position) { bool success = m_stream->truncate(position); m_context->postTask(createCallbackTask(&didTruncate, AllowCrossThreadAccess(this), success)); @@ -222,4 +224,4 @@ void FileStreamProxy::truncateOnFileThread(long long position) } // namespace WebCore -#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM) +#endif // ENABLE(BLOB) diff --git a/Source/WebCore/fileapi/FileStreamProxy.h b/Source/WebCore/fileapi/AsyncFileStream.h index ce9a1054c..04be2db0c 100644 --- a/Source/WebCore/fileapi/FileStreamProxy.h +++ b/Source/WebCore/fileapi/AsyncFileStream.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2010 Google Inc. All rights reserved. - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010, 2012 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -29,44 +29,45 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef FileStreamProxy_h -#define FileStreamProxy_h +#ifndef AsyncFileStream_h +#define AsyncFileStream_h -#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM) +#if ENABLE(BLOB) -#include "AsyncFileStream.h" #include <wtf/Forward.h> -#include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> #include <wtf/RefPtr.h> namespace WebCore { +class FileStreamClient; class FileStream; class FileThread; class KURL; class ScriptExecutionContext; -// A proxy module that asynchronously calls corresponding FileStream methods on the file thread. Note: you must call stop() first and then release the reference to destruct the FileStreamProxy instance. -class FileStreamProxy : public AsyncFileStream { +class AsyncFileStream : public RefCounted<AsyncFileStream> { public: - static PassRefPtr<FileStreamProxy> create(ScriptExecutionContext*, FileStreamClient*); - virtual ~FileStreamProxy(); - - virtual void getSize(const String& path, double expectedModificationTime); - virtual void openForRead(const String& path, long long offset, long long length); - virtual void openForWrite(const String& path); - virtual void close(); - virtual void read(char* buffer, int length); - virtual void write(const KURL& blobURL, long long position, int length); - virtual void truncate(long long position); - - // Stops the proxy and scedules it to be destructed. All the pending tasks will be aborted and the file stream will be closed. + static PassRefPtr<AsyncFileStream> create(ScriptExecutionContext*, FileStreamClient*); + ~AsyncFileStream(); + + void getSize(const String& path, double expectedModificationTime); + void openForRead(const String& path, long long offset, long long length); + void openForWrite(const String& path); + void close(); + void read(char* buffer, int length); + void write(const KURL& blobURL, long long position, int length); + void truncate(long long position); + + // Stops the proxy and schedules it to be destructed. All the pending tasks will be aborted and the file stream will be closed. // Note: the caller should deref the instance immediately after calling stop(). - virtual void stop(); + void stop(); + + FileStreamClient* client() const { return m_client; } + void setClient(FileStreamClient* client) { m_client = client; } private: - FileStreamProxy(ScriptExecutionContext*, FileStreamClient*); + AsyncFileStream(ScriptExecutionContext*, FileStreamClient*); FileThread* fileThread(); @@ -83,10 +84,12 @@ private: RefPtr<ScriptExecutionContext> m_context; RefPtr<FileStream> m_stream; + + FileStreamClient* m_client; }; } // namespace WebCore -#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM) +#endif // ENABLE(BLOB) -#endif // FileStreamProxy_h +#endif // AsyncFileStream_h diff --git a/Source/WebCore/fileapi/DOMFileSystem.cpp b/Source/WebCore/fileapi/DOMFileSystem.cpp index 9799e1207..b178f0c64 100644 --- a/Source/WebCore/fileapi/DOMFileSystem.cpp +++ b/Source/WebCore/fileapi/DOMFileSystem.cpp @@ -154,7 +154,7 @@ private: void DOMFileSystem::createFile(const FileEntry* fileEntry, PassRefPtr<FileCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) { - m_asyncFileSystem->readMetadata(fileEntry->fullPath(), GetPathCallback::create(this, fileEntry->name(), successCallback, errorCallback)); + m_asyncFileSystem->createSnapshotFileAndReadMetadata(fileEntry->fullPath(), GetPathCallback::create(this, fileEntry->name(), successCallback, errorCallback)); } } // namespace WebCore diff --git a/Source/WebCore/fileapi/DOMFileSystemSync.cpp b/Source/WebCore/fileapi/DOMFileSystemSync.cpp index e7a8ca70b..8b772bb33 100644 --- a/Source/WebCore/fileapi/DOMFileSystemSync.cpp +++ b/Source/WebCore/fileapi/DOMFileSystemSync.cpp @@ -72,60 +72,35 @@ PassRefPtr<DirectoryEntrySync> DOMFileSystemSync::root() namespace { -class GetPathHelper : public AsyncFileSystemCallbacks { +class CreateFileHelper : public AsyncFileSystemCallbacks { public: - class GetPathResult : public RefCounted<GetPathResult> { + class CreateFileResult : public RefCounted<CreateFileResult> { public: - static PassRefPtr<GetPathResult> create() + static PassRefPtr<CreateFileResult> create() { - return adoptRef(new GetPathResult()); + return adoptRef(new CreateFileResult()); } bool m_failed; int m_code; - String m_path; + RefPtr<File> m_file; private: - GetPathResult() + CreateFileResult() : m_failed(false) , m_code(0) { } - ~GetPathResult() + ~CreateFileResult() { } - friend class WTF::RefCounted<GetPathResult>; + friend class WTF::RefCounted<CreateFileResult>; }; - static PassOwnPtr<GetPathHelper> create(PassRefPtr<GetPathResult> result) + static PassOwnPtr<CreateFileHelper> create(PassRefPtr<CreateFileResult> result, const String& name) { - return adoptPtr(new GetPathHelper(result)); - } - - virtual void didSucceed() - { - ASSERT_NOT_REACHED(); - } - - virtual void didOpenFileSystem(const String&, PassOwnPtr<AsyncFileSystem>) - { - ASSERT_NOT_REACHED(); - } - - virtual void didReadDirectoryEntry(const String&, bool) - { - ASSERT_NOT_REACHED(); - } - - virtual void didReadDirectoryEntries(bool) - { - ASSERT_NOT_REACHED(); - } - - virtual void didCreateFileWriter(PassOwnPtr<AsyncFileWriter>, long long) - { - ASSERT_NOT_REACHED(); + return adoptPtr(new CreateFileHelper(result, name)); } virtual void didFail(int code) @@ -134,21 +109,23 @@ public: m_result->m_code = code; } - virtual ~GetPathHelper() + virtual ~CreateFileHelper() { } void didReadMetadata(const FileMetadata& metadata) { - m_result->m_path = metadata.platformPath; + m_result->m_file = File::createWithName(metadata.platformPath, m_name); } private: - GetPathHelper(PassRefPtr<GetPathResult> result) + CreateFileHelper(PassRefPtr<CreateFileResult> result, const String& name) : m_result(result) + , m_name(name) { } - RefPtr<GetPathResult> m_result; + RefPtr<CreateFileResult> m_result; + String m_name; }; } // namespace @@ -156,8 +133,8 @@ private: PassRefPtr<File> DOMFileSystemSync::createFile(const FileEntrySync* fileEntry, ExceptionCode& ec) { ec = 0; - RefPtr<GetPathHelper::GetPathResult> result(GetPathHelper::GetPathResult::create()); - m_asyncFileSystem->readMetadata(fileEntry->fullPath(), GetPathHelper::create(result)); + RefPtr<CreateFileHelper::CreateFileResult> result(CreateFileHelper::CreateFileResult::create()); + m_asyncFileSystem->createSnapshotFileAndReadMetadata(fileEntry->fullPath(), CreateFileHelper::create(result, fileEntry->name())); if (!m_asyncFileSystem->waitForOperationToComplete()) { ec = FileException::ABORT_ERR; return 0; @@ -166,8 +143,7 @@ PassRefPtr<File> DOMFileSystemSync::createFile(const FileEntrySync* fileEntry, E ec = result->m_code; return 0; } - ASSERT(!result->m_path.isEmpty()); - return File::createWithName(result->m_path, fileEntry->name()); + return result->m_file; } namespace { diff --git a/Source/WebCore/fileapi/DOMWindowFileSystem.idl b/Source/WebCore/fileapi/DOMWindowFileSystem.idl index 79947cbd7..b6ef51319 100644 --- a/Source/WebCore/fileapi/DOMWindowFileSystem.idl +++ b/Source/WebCore/fileapi/DOMWindowFileSystem.idl @@ -1,20 +1,27 @@ /* - * Copyright (C) 2012 Google Inc. All rights reserved. + * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2011 Google Inc. All rights reserved. * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ module window { diff --git a/Source/WebCore/fileapi/FileError.h b/Source/WebCore/fileapi/FileError.h index 0597633e7..7678a5154 100644 --- a/Source/WebCore/fileapi/FileError.h +++ b/Source/WebCore/fileapi/FileError.h @@ -31,7 +31,7 @@ #ifndef FileError_h #define FileError_h -#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM) +#if ENABLE(BLOB) #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> @@ -70,6 +70,6 @@ private: } // namespace WebCore -#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM) +#endif // ENABLE(BLOB) #endif // FileError_h diff --git a/Source/WebCore/fileapi/FileException.cpp b/Source/WebCore/fileapi/FileException.cpp index 7e62ff355..5007f1cd5 100644 --- a/Source/WebCore/fileapi/FileException.cpp +++ b/Source/WebCore/fileapi/FileException.cpp @@ -28,7 +28,7 @@ #include "config.h" -#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM) +#if ENABLE(BLOB) #include "FileException.h" @@ -87,4 +87,4 @@ bool FileException::initializeDescription(ExceptionCode ec, ExceptionCodeDescrip } // namespace WebCore -#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM) +#endif // ENABLE(BLOB) diff --git a/Source/WebCore/fileapi/FileException.h b/Source/WebCore/fileapi/FileException.h index 38f1ed4ae..ccf7982df 100644 --- a/Source/WebCore/fileapi/FileException.h +++ b/Source/WebCore/fileapi/FileException.h @@ -31,7 +31,7 @@ #ifndef FileException_h #define FileException_h -#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM) +#if ENABLE(BLOB) #include "ExceptionBase.h" @@ -80,6 +80,6 @@ private: } // namespace WebCore -#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM) +#endif // ENABLE(BLOB) #endif // FileException_h diff --git a/Source/WebCore/fileapi/FileSystemCallbacks.cpp b/Source/WebCore/fileapi/FileSystemCallbacks.cpp index 06f3b9383..1e9a99d24 100644 --- a/Source/WebCore/fileapi/FileSystemCallbacks.cpp +++ b/Source/WebCore/fileapi/FileSystemCallbacks.cpp @@ -65,42 +65,6 @@ FileSystemCallbacksBase::~FileSystemCallbacksBase() { } -void FileSystemCallbacksBase::didSucceed() -{ - // Each subclass must implement an appropriate one. - ASSERT_NOT_REACHED(); -} - -void FileSystemCallbacksBase::didOpenFileSystem(const String&, PassOwnPtr<AsyncFileSystem>) -{ - // Each subclass must implement an appropriate one. - ASSERT_NOT_REACHED(); -} - -void FileSystemCallbacksBase::didReadMetadata(const FileMetadata&) -{ - // Each subclass must implement an appropriate one. - ASSERT_NOT_REACHED(); -} - -void FileSystemCallbacksBase::didReadDirectoryEntries(bool) -{ - // Each subclass must implement an appropriate one. - ASSERT_NOT_REACHED(); -} - -void FileSystemCallbacksBase::didReadDirectoryEntry(const String&, bool) -{ - // Each subclass must implement an appropriate one. - ASSERT_NOT_REACHED(); -} - -void FileSystemCallbacksBase::didCreateFileWriter(PassOwnPtr<AsyncFileWriter>, long long) -{ - // Each subclass must implement an appropriate one. - ASSERT_NOT_REACHED(); -} - void FileSystemCallbacksBase::didFail(int code) { if (m_errorCallback) { @@ -268,7 +232,7 @@ MetadataCallbacks::MetadataCallbacks(PassRefPtr<MetadataCallback> successCallbac void MetadataCallbacks::didReadMetadata(const FileMetadata& metadata) { if (m_successCallback) - m_successCallback->handleEvent(Metadata::create(metadata.modificationTime).get()); + m_successCallback->handleEvent(Metadata::create(metadata).get()); m_successCallback.clear(); } diff --git a/Source/WebCore/fileapi/FileSystemCallbacks.h b/Source/WebCore/fileapi/FileSystemCallbacks.h index 7f68625ac..e02deb9f0 100644 --- a/Source/WebCore/fileapi/FileSystemCallbacks.h +++ b/Source/WebCore/fileapi/FileSystemCallbacks.h @@ -59,25 +59,11 @@ class FileSystemCallbacksBase : public AsyncFileSystemCallbacks { public: virtual ~FileSystemCallbacksBase(); - // For EntryCallbacks and VoidCallbacks. - virtual void didSucceed(); - - // For FileSystemCallbacks. - virtual void didOpenFileSystem(const String& name, PassOwnPtr<AsyncFileSystem>); - - // For MetadataCallbacks. - virtual void didReadMetadata(const FileMetadata&); - - // For EntriesCallbacks. didReadDirectoryEntry is called each time the API reads an entry, and didReadDirectoryDone is called when a chunk of entries have been read (i.e. good time to call back to the application). If hasMore is true there can be more chunks. - virtual void didReadDirectoryEntry(const String& name, bool isDirectory); - virtual void didReadDirectoryEntries(bool hasMore); - - // For createFileWriter. - virtual void didCreateFileWriter(PassOwnPtr<AsyncFileWriter>, long long length); - // For ErrorCallback. virtual void didFail(int code); + // Other callback methods are implemented by each subclass. + protected: FileSystemCallbacksBase(PassRefPtr<ErrorCallback> errorCallback); RefPtr<ErrorCallback> m_errorCallback; diff --git a/Source/WebCore/fileapi/FileThread.cpp b/Source/WebCore/fileapi/FileThread.cpp index 82bc686f6..4f4f473fd 100644 --- a/Source/WebCore/fileapi/FileThread.cpp +++ b/Source/WebCore/fileapi/FileThread.cpp @@ -30,7 +30,7 @@ #include "config.h" -#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM) +#if ENABLE(BLOB) #include "FileThread.h" @@ -114,4 +114,4 @@ void FileThread::runLoop() } // namespace WebCore -#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM) +#endif // ENABLE(BLOB) diff --git a/Source/WebCore/fileapi/FileThread.h b/Source/WebCore/fileapi/FileThread.h index 6c3255b57..d4e24bca3 100644 --- a/Source/WebCore/fileapi/FileThread.h +++ b/Source/WebCore/fileapi/FileThread.h @@ -31,7 +31,7 @@ #ifndef FileThread_h #define FileThread_h -#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM) +#if ENABLE(BLOB) #include <wtf/MessageQueue.h> #include <wtf/PassOwnPtr.h> @@ -84,6 +84,6 @@ private: } // namespace WebCore -#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM) +#endif // ENABLE(BLOB) #endif // FileThread_h diff --git a/Source/WebCore/fileapi/Metadata.h b/Source/WebCore/fileapi/Metadata.h index b70806b09..7d1253a12 100644 --- a/Source/WebCore/fileapi/Metadata.h +++ b/Source/WebCore/fileapi/Metadata.h @@ -33,32 +33,34 @@ #if ENABLE(FILE_SYSTEM) +#include "FileMetadata.h" #include <wtf/RefCounted.h> namespace WebCore { class Metadata : public RefCounted<Metadata> { public: - static PassRefPtr<Metadata> create(double modificationTime) + static PassRefPtr<Metadata> create(const FileMetadata& platformMetadata) { - return adoptRef(new Metadata(modificationTime)); + return adoptRef(new Metadata(platformMetadata)); } static PassRefPtr<Metadata> create(Metadata* metadata) { - return adoptRef(new Metadata(metadata->m_modificationTime)); + return adoptRef(new Metadata(metadata->m_platformMetadata)); } - // Needs to return epoch time in milliseconds for Date. - double modificationTime() const { return m_modificationTime * 1000.0; } + // Needs to return epoch time in milliseconds for Date while FileMetadata's modificationTime is in seconds. + double modificationTime() const { return m_platformMetadata.modificationTime * 1000.0; } + unsigned long long size() const { return static_cast<unsigned long long>(m_platformMetadata.length); } private: - Metadata(double modificationTime) - : m_modificationTime(modificationTime) + Metadata(const FileMetadata& platformMetadata) + : m_platformMetadata(platformMetadata) { } - double m_modificationTime; + FileMetadata m_platformMetadata; }; } // namespace diff --git a/Source/WebCore/fileapi/Metadata.idl b/Source/WebCore/fileapi/Metadata.idl index ad477f771..ceaf21b5a 100644 --- a/Source/WebCore/fileapi/Metadata.idl +++ b/Source/WebCore/fileapi/Metadata.idl @@ -34,5 +34,6 @@ module storage { JSNoStaticTables ] Metadata { readonly attribute Date modificationTime; + readonly attribute unsigned long long size; }; } diff --git a/Source/WebCore/fileapi/OperationNotAllowedException.cpp b/Source/WebCore/fileapi/OperationNotAllowedException.cpp index e97cfa035..2c9bc8e11 100644 --- a/Source/WebCore/fileapi/OperationNotAllowedException.cpp +++ b/Source/WebCore/fileapi/OperationNotAllowedException.cpp @@ -28,7 +28,7 @@ #include "config.h" -#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM) +#if ENABLE(BLOB) #include "OperationNotAllowedException.h" @@ -65,4 +65,4 @@ bool OperationNotAllowedException::initializeDescription(ExceptionCode ec, Excep } // namespace WebCore -#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM) +#endif // ENABLE(BLOB) diff --git a/Source/WebCore/fileapi/OperationNotAllowedException.h b/Source/WebCore/fileapi/OperationNotAllowedException.h index c3e95595e..5a0e9a1c5 100644 --- a/Source/WebCore/fileapi/OperationNotAllowedException.h +++ b/Source/WebCore/fileapi/OperationNotAllowedException.h @@ -31,7 +31,7 @@ #ifndef OperationNotAllowedException_h #define OperationNotAllowedException_h -#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM) +#if ENABLE(BLOB) #include "ExceptionBase.h" @@ -62,6 +62,6 @@ private: } // namespace WebCore -#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM) +#endif // ENABLE(BLOB) #endif // OperationNotAllowedException_h diff --git a/Source/WebCore/fileapi/WorkerContextFileSystem.cpp b/Source/WebCore/fileapi/WorkerContextFileSystem.cpp new file mode 100644 index 000000000..9651ef427 --- /dev/null +++ b/Source/WebCore/fileapi/WorkerContextFileSystem.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "config.h" +#include "WorkerContextFileSystem.h" + +#if ENABLE(FILE_SYSTEM) + +#include "AsyncFileSystem.h" +#include "DOMFileSystem.h" +#include "DOMFileSystemBase.h" +#include "DOMFileSystemSync.h" +#include "DirectoryEntrySync.h" +#include "ErrorCallback.h" +#include "FileEntrySync.h" +#include "FileError.h" +#include "FileException.h" +#include "FileSystemCallback.h" +#include "FileSystemCallbacks.h" +#include "LocalFileSystem.h" +#include "SecurityOrigin.h" +#include "SyncCallbackHelper.h" +#include "WorkerContext.h" + +namespace WebCore { + +void WorkerContextFileSystem::webkitRequestFileSystem(WorkerContext* worker, int type, long long size, PassRefPtr<FileSystemCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) +{ + ScriptExecutionContext* secureContext = worker->scriptExecutionContext(); + if (!AsyncFileSystem::isAvailable() || !secureContext->securityOrigin()->canAccessFileSystem()) { + DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create(FileError::SECURITY_ERR)); + return; + } + + AsyncFileSystem::Type fileSystemType = static_cast<AsyncFileSystem::Type>(type); + if (!AsyncFileSystem::isValidType(fileSystemType)) { + DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create(FileError::INVALID_MODIFICATION_ERR)); + return; + } + + LocalFileSystem::localFileSystem().requestFileSystem(worker, fileSystemType, size, FileSystemCallbacks::create(successCallback, errorCallback, worker), false); +} + +PassRefPtr<DOMFileSystemSync> WorkerContextFileSystem::webkitRequestFileSystemSync(WorkerContext* worker, int type, long long size, ExceptionCode& ec) +{ + ec = 0; + ScriptExecutionContext* secureContext = worker->scriptExecutionContext(); + if (!AsyncFileSystem::isAvailable() || !secureContext->securityOrigin()->canAccessFileSystem()) { + ec = FileException::SECURITY_ERR; + return 0; + } + + AsyncFileSystem::Type fileSystemType = static_cast<AsyncFileSystem::Type>(type); + if (!AsyncFileSystem::isValidType(fileSystemType)) { + ec = FileException::INVALID_MODIFICATION_ERR; + return 0; + } + + FileSystemSyncCallbackHelper helper; + LocalFileSystem::localFileSystem().requestFileSystem(worker, fileSystemType, size, FileSystemCallbacks::create(helper.successCallback(), helper.errorCallback(), worker), true); + return helper.getResult(ec); +} + +void WorkerContextFileSystem::webkitResolveLocalFileSystemURL(WorkerContext* worker, const String& url, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) +{ + KURL completedURL = worker->completeURL(url); + ScriptExecutionContext* secureContext = worker->scriptExecutionContext(); + if (!AsyncFileSystem::isAvailable() || !secureContext->securityOrigin()->canAccessFileSystem() || !secureContext->securityOrigin()->canRequest(completedURL)) { + DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create(FileError::SECURITY_ERR)); + return; + } + + AsyncFileSystem::Type type; + String filePath; + if (!completedURL.isValid() || !AsyncFileSystem::crackFileSystemURL(completedURL, type, filePath)) { + DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create(FileError::ENCODING_ERR)); + return; + } + + LocalFileSystem::localFileSystem().readFileSystem(worker, type, ResolveURICallbacks::create(successCallback, errorCallback, worker, filePath)); +} + +PassRefPtr<EntrySync> WorkerContextFileSystem::webkitResolveLocalFileSystemSyncURL(WorkerContext* worker, const String& url, ExceptionCode& ec) +{ + ec = 0; + KURL completedURL = worker->completeURL(url); + ScriptExecutionContext* secureContext = worker->scriptExecutionContext(); + if (!AsyncFileSystem::isAvailable() || !secureContext->securityOrigin()->canAccessFileSystem() || !secureContext->securityOrigin()->canRequest(completedURL)) { + ec = FileException::SECURITY_ERR; + return 0; + } + + AsyncFileSystem::Type type; + String filePath; + if (!completedURL.isValid() || !AsyncFileSystem::crackFileSystemURL(completedURL, type, filePath)) { + ec = FileException::ENCODING_ERR; + return 0; + } + + FileSystemSyncCallbackHelper readFileSystemHelper; + LocalFileSystem::localFileSystem().readFileSystem(worker, type, FileSystemCallbacks::create(readFileSystemHelper.successCallback(), readFileSystemHelper.errorCallback(), worker), true); + RefPtr<DOMFileSystemSync> fileSystem = readFileSystemHelper.getResult(ec); + if (!fileSystem) + return 0; + + RefPtr<EntrySync> entry = fileSystem->root()->getDirectory(filePath, 0, ec); + if (ec == FileException::TYPE_MISMATCH_ERR) + return fileSystem->root()->getFile(filePath, 0, ec); + + return entry.release(); +} + +COMPILE_ASSERT(static_cast<int>(WorkerContextFileSystem::TEMPORARY) == static_cast<int>(AsyncFileSystem::Temporary), enum_mismatch); +COMPILE_ASSERT(static_cast<int>(WorkerContextFileSystem::PERSISTENT) == static_cast<int>(AsyncFileSystem::Persistent), enum_mismatch); + +} // namespace WebCore + +#endif // ENABLE(FILE_SYSTEM) diff --git a/Source/WebCore/fileapi/WorkerContextFileSystem.h b/Source/WebCore/fileapi/WorkerContextFileSystem.h new file mode 100644 index 000000000..c500f5e2e --- /dev/null +++ b/Source/WebCore/fileapi/WorkerContextFileSystem.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef WorkerContextFileSystem_h +#define WorkerContextFileSystem_h + +#if ENABLE(FILE_SYSTEM) + +#include "DOMFileSystemSync.h" +#include <wtf/PassRefPtr.h> + +namespace WebCore { + +class EntryCallback; +class EntrySync; +class ErrorCallback; +class FileSystemCallback; +class WorkerContext; + +class WorkerContextFileSystem { +public: + enum FileSystemType { + TEMPORARY, + PERSISTENT, + }; + + static void webkitRequestFileSystem(WorkerContext*, int type, long long size, PassRefPtr<FileSystemCallback> successCallback, PassRefPtr<ErrorCallback>); + static PassRefPtr<DOMFileSystemSync> webkitRequestFileSystemSync(WorkerContext*, int type, long long size, ExceptionCode&); + static void webkitResolveLocalFileSystemURL(WorkerContext*, const String& url, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback>); + static PassRefPtr<EntrySync> webkitResolveLocalFileSystemSyncURL(WorkerContext*, const String& url, ExceptionCode&); + +private: + WorkerContextFileSystem(); + ~WorkerContextFileSystem(); +}; + +} // namespace WebCore + +#endif // ENABLE(FILE_SYSTEM) + +#endif // WorkerContextFileSystem_h diff --git a/Source/WebCore/fileapi/WorkerContextFileSystem.idl b/Source/WebCore/fileapi/WorkerContextFileSystem.idl new file mode 100644 index 000000000..cb9c32849 --- /dev/null +++ b/Source/WebCore/fileapi/WorkerContextFileSystem.idl @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +module threads { + + interface [ + Conditional=FILE_SYSTEM, + Supplemental=WorkerContext + ] WorkerContextFileSystem { + const unsigned short TEMPORARY = 0; + const unsigned short PERSISTENT = 1; + + [V8EnabledAtRuntime=FileSystem] void webkitRequestFileSystem(in unsigned short type, in long long size, in [Callback, Optional] FileSystemCallback successCallback, in [Callback, Optional] ErrorCallback errorCallback); + [V8EnabledAtRuntime=FileSystem] DOMFileSystemSync webkitRequestFileSystemSync(in unsigned short type, in long long size) raises (FileException); + [V8EnabledAtRuntime=FileSystem] void webkitResolveLocalFileSystemURL(in DOMString url, in [Callback, Optional] EntryCallback successCallback, in [Callback, Optional] ErrorCallback errorCallback); + [V8EnabledAtRuntime=FileSystem] EntrySync webkitResolveLocalFileSystemSyncURL(in DOMString url) raises (FileException); + + attribute [V8EnabledAtRuntime=FileSystem] FileErrorConstructor FileError; + attribute [V8EnabledAtRuntime=FileSystem] FileExceptionConstructor FileException; + }; + +} |