summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorkkanetkar@chromium.org <kkanetkar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-16 04:46:14 +0000
committerkkanetkar@chromium.org <kkanetkar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-16 04:46:14 +0000
commitf05ca65c8857804c078f06b260f3175493dd4720 (patch)
treef3d22e6412bf18bf9597729d91c468c4846ab598 /webkit
parent88dd4bc31fbce0e6cfe7612ba3fccd08407c1cb2 (diff)
downloadchromium_src-f05ca65c8857804c078f06b260f3175493dd4720.zip
chromium_src-f05ca65c8857804c078f06b260f3175493dd4720.tar.gz
chromium_src-f05ca65c8857804c078f06b260f3175493dd4720.tar.bz2
Test shell impl for WebKit's File System API:BUG=52799TEST=none
Also refactored a bunch of code from chrome/browser to webkit/fileapi for reuse. Added class hierarchy. Test shell and browser operations now inherit from common webkit/fileapi/file_system_operation. Review URL: http://codereview.chromium.org/3186009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59616 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/fileapi/file_system_operation.cc192
-rw-r--r--webkit/fileapi/file_system_operation.h99
-rw-r--r--webkit/fileapi/file_system_operation_client.h39
-rw-r--r--webkit/fileapi/webkit_fileapi.gypi31
-rw-r--r--webkit/support/test_webkit_client.cc6
-rw-r--r--webkit/support/test_webkit_client.h3
-rw-r--r--webkit/support/webkit_support.gyp1
-rw-r--r--webkit/support/webkit_support.gypi3
-rw-r--r--webkit/tools/test_shell/simple_file_system.cc160
-rw-r--r--webkit/tools/test_shell/simple_file_system.h95
-rw-r--r--webkit/tools/test_shell/test_shell_webkit_init.h6
11 files changed, 635 insertions, 0 deletions
diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc
new file mode 100644
index 0000000..90eabad
--- /dev/null
+++ b/webkit/fileapi/file_system_operation.cc
@@ -0,0 +1,192 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/fileapi/file_system_operation.h"
+
+#include "webkit/fileapi/file_system_operation_client.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebFileError.h"
+
+namespace {
+// Utility method for error conversions.
+WebKit::WebFileError PlatformFileErrorToWebFileError(
+ base::PlatformFileError rv) {
+ switch (rv) {
+ case base::PLATFORM_FILE_ERROR_NOT_FOUND:
+ return WebKit::WebFileErrorNotFound;
+ case base::PLATFORM_FILE_ERROR_INVALID_OPERATION:
+ case base::PLATFORM_FILE_ERROR_EXISTS:
+ case base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY:
+ return WebKit::WebFileErrorInvalidModification;
+ case base::PLATFORM_FILE_ERROR_ACCESS_DENIED:
+ return WebKit::WebFileErrorNoModificationAllowed;
+ default:
+ return WebKit::WebFileErrorInvalidModification;
+ }
+}
+} // namespace
+
+namespace fileapi {
+
+FileSystemOperation::FileSystemOperation(
+ FileSystemOperationClient* client,
+ scoped_refptr<base::MessageLoopProxy> proxy)
+ : proxy_(proxy),
+ client_(client),
+ callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
+ operation_pending_(false) {
+ DCHECK(client_);
+}
+
+void FileSystemOperation::CreateFile(const FilePath& path,
+ bool exclusive) {
+ DCHECK(!operation_pending_);
+ operation_pending_ = true;
+ base::FileUtilProxy::CreateOrOpen(
+ proxy_, path, base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_READ,
+ callback_factory_.NewCallback(
+ exclusive ? &FileSystemOperation::DidCreateFileExclusive
+ : &FileSystemOperation::DidCreateFileNonExclusive));
+}
+
+void FileSystemOperation::CreateDirectory(const FilePath& path,
+ bool exclusive) {
+ DCHECK(!operation_pending_);
+ operation_pending_ = true;
+ base::FileUtilProxy::CreateDirectory(proxy_, path, exclusive,
+ false /* recursive */, callback_factory_.NewCallback(
+ &FileSystemOperation::DidFinishFileOperation));
+}
+
+void FileSystemOperation::Copy(const FilePath& src_path,
+ const FilePath& dest_path) {
+ DCHECK(!operation_pending_);
+ operation_pending_ = true;
+ base::FileUtilProxy::Copy(proxy_, src_path, dest_path,
+ callback_factory_.NewCallback(
+ &FileSystemOperation::DidFinishFileOperation));
+}
+
+void FileSystemOperation::Move(const FilePath& src_path,
+ const FilePath& dest_path) {
+ DCHECK(!operation_pending_);
+ operation_pending_ = true;
+ base::FileUtilProxy::Move(proxy_, src_path, dest_path,
+ callback_factory_.NewCallback(
+ &FileSystemOperation::DidFinishFileOperation));
+}
+
+void FileSystemOperation::DirectoryExists(const FilePath& path) {
+ DCHECK(!operation_pending_);
+ operation_pending_ = true;
+ base::FileUtilProxy::GetFileInfo(proxy_, path, callback_factory_.NewCallback(
+ &FileSystemOperation::DidDirectoryExists));
+}
+
+void FileSystemOperation::FileExists(const FilePath& path) {
+ DCHECK(!operation_pending_);
+ operation_pending_ = true;
+ base::FileUtilProxy::GetFileInfo(proxy_, path, callback_factory_.NewCallback(
+ &FileSystemOperation::DidFileExists));
+}
+
+void FileSystemOperation::GetMetadata(const FilePath& path) {
+ DCHECK(!operation_pending_);
+ operation_pending_ = true;
+ base::FileUtilProxy::GetFileInfo(proxy_, path, callback_factory_.NewCallback(
+ &FileSystemOperation::DidGetMetadata));
+}
+
+void FileSystemOperation::ReadDirectory(const FilePath& path) {
+ DCHECK(!operation_pending_);
+ operation_pending_ = true;
+ base::FileUtilProxy::ReadDirectory(proxy_, path,
+ callback_factory_.NewCallback(
+ &FileSystemOperation::DidReadDirectory));
+}
+
+void FileSystemOperation::Remove(const FilePath& path) {
+ DCHECK(!operation_pending_);
+ operation_pending_ = true;
+ base::FileUtilProxy::Delete(proxy_, path, callback_factory_.NewCallback(
+ &FileSystemOperation::DidFinishFileOperation));
+}
+
+void FileSystemOperation::DidCreateFileExclusive(
+ base::PlatformFileError rv,
+ base::PassPlatformFile file,
+ bool created) {
+ DidFinishFileOperation(rv);
+}
+
+void FileSystemOperation::DidCreateFileNonExclusive(
+ base::PlatformFileError rv,
+ base::PassPlatformFile file,
+ bool created) {
+ // Suppress the already exists error and report success.
+ if (rv == base::PLATFORM_FILE_OK ||
+ rv == base::PLATFORM_FILE_ERROR_EXISTS)
+ client_->DidSucceed(this);
+ else
+ client_->DidFail(PlatformFileErrorToWebFileError(rv), this);
+}
+
+void FileSystemOperation::DidFinishFileOperation(
+ base::PlatformFileError rv) {
+ if (rv == base::PLATFORM_FILE_OK)
+ client_->DidSucceed(this);
+ else
+ client_->DidFail(PlatformFileErrorToWebFileError(rv), this);
+}
+
+void FileSystemOperation::DidDirectoryExists(
+ base::PlatformFileError rv,
+ const base::PlatformFileInfo& file_info) {
+ if (rv == base::PLATFORM_FILE_OK) {
+ if (file_info.is_directory)
+ client_->DidSucceed(this);
+ else
+ client_->DidFail(WebKit::WebFileErrorInvalidState,
+ this);
+ } else {
+ // Something else went wrong.
+ client_->DidFail(PlatformFileErrorToWebFileError(rv), this);
+ }
+}
+
+void FileSystemOperation::DidFileExists(
+ base::PlatformFileError rv,
+ const base::PlatformFileInfo& file_info) {
+ if (rv == base::PLATFORM_FILE_OK) {
+ if (file_info.is_directory)
+ client_->DidFail(WebKit::WebFileErrorInvalidState,
+ this);
+ else
+ client_->DidSucceed(this);
+ } else {
+ // Something else went wrong.
+ client_->DidFail(PlatformFileErrorToWebFileError(rv), this);
+ }
+}
+
+void FileSystemOperation::DidGetMetadata(
+ base::PlatformFileError rv,
+ const base::PlatformFileInfo& file_info) {
+ if (rv == base::PLATFORM_FILE_OK)
+ client_->DidReadMetadata(file_info, this);
+ else
+ client_->DidFail(PlatformFileErrorToWebFileError(rv), this);
+}
+
+void FileSystemOperation::DidReadDirectory(
+ base::PlatformFileError rv,
+ const std::vector<base::file_util_proxy::Entry>& entries) {
+ if (rv == base::PLATFORM_FILE_OK)
+ client_->DidReadDirectory(
+ entries, false /* has_more */ , this);
+ else
+ client_->DidFail(PlatformFileErrorToWebFileError(rv), this);
+}
+
+} // namespace fileapi
+
diff --git a/webkit/fileapi/file_system_operation.h b/webkit/fileapi/file_system_operation.h
new file mode 100644
index 0000000..f9431c9
--- /dev/null
+++ b/webkit/fileapi/file_system_operation.h
@@ -0,0 +1,99 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_
+#define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_
+
+#include <vector>
+
+#include "base/file_path.h"
+#include "base/file_util_proxy.h"
+#include "base/message_loop_proxy.h"
+#include "base/platform_file.h"
+#include "base/ref_counted.h"
+#include "base/scoped_callback_factory.h"
+
+namespace fileapi {
+
+class FileSystemOperationClient;
+
+// This class is designed to serve one-time file system operation per instance.
+// Each operation method (CreateFile, CreateDirectory, Copy, Move,
+// DirectoryExists, GetMetadata, ReadDirectory and Remove) must be called
+// only once in its lifetime.
+class FileSystemOperation {
+ public:
+ FileSystemOperation(
+ FileSystemOperationClient* client,
+ scoped_refptr<base::MessageLoopProxy> proxy);
+
+ void CreateFile(const FilePath& path,
+ bool exclusive);
+
+ void CreateDirectory(const FilePath& path,
+ bool exclusive);
+
+ void Copy(const FilePath& src_path,
+ const FilePath& dest_path);
+
+ // If |dest_path| exists and is a directory, behavior is unspecified or
+ // varies for different platforms. TODO(kkanetkar): Fix this as per spec
+ // when it is addressed in spec.
+ void Move(const FilePath& src_path,
+ const FilePath& dest_path);
+
+ void DirectoryExists(const FilePath& path);
+
+ void FileExists(const FilePath& path);
+
+ void GetMetadata(const FilePath& path);
+
+ void ReadDirectory(const FilePath& path);
+
+ void Remove(const FilePath& path);
+
+ protected:
+ // Proxy for calling file_util_proxy methods.
+ scoped_refptr<base::MessageLoopProxy> proxy_;
+
+ private:
+ // Callbacks for above methods.
+ void DidCreateFileExclusive(
+ base::PlatformFileError rv, base::PassPlatformFile file, bool created);
+
+ // Returns success even if the file already existed.
+ void DidCreateFileNonExclusive(
+ base::PlatformFileError rv, base::PassPlatformFile file, bool created);
+
+ // Generic callback that translates platform errors to WebKit error codes.
+ void DidFinishFileOperation(base::PlatformFileError rv);
+
+ void DidDirectoryExists(base::PlatformFileError rv,
+ const base::PlatformFileInfo& file_info);
+
+ void DidFileExists(base::PlatformFileError rv,
+ const base::PlatformFileInfo& file_info);
+
+ void DidGetMetadata(base::PlatformFileError rv,
+ const base::PlatformFileInfo& file_info);
+
+ void DidReadDirectory(
+ base::PlatformFileError rv,
+ const std::vector<base::file_util_proxy::Entry>& entries);
+
+ // Not owned.
+ FileSystemOperationClient* client_;
+
+ base::ScopedCallbackFactory<FileSystemOperation> callback_factory_;
+
+ // A flag to make sure we call operation only once per instance.
+ bool operation_pending_;
+
+ DISALLOW_COPY_AND_ASSIGN(FileSystemOperation);
+};
+
+} // namespace fileapi
+
+#endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_
+
diff --git a/webkit/fileapi/file_system_operation_client.h b/webkit/fileapi/file_system_operation_client.h
new file mode 100644
index 0000000..b126d4e
--- /dev/null
+++ b/webkit/fileapi/file_system_operation_client.h
@@ -0,0 +1,39 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CLIENT_H_
+#define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CLIENT_H_
+
+#include <vector>
+
+#include "base/file_util_proxy.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebFileError.h"
+
+namespace fileapi {
+
+class FileSystemOperation;
+
+// Interface for client of FileSystemOperation.
+class FileSystemOperationClient {
+ public:
+ virtual ~FileSystemOperationClient() {}
+
+ virtual void DidFail(
+ WebKit::WebFileError status,
+ FileSystemOperation* operation) = 0;
+
+ virtual void DidSucceed(FileSystemOperation* operation) = 0;
+
+ // Info about the file entry such as modification date and size.
+ virtual void DidReadMetadata(const base::PlatformFileInfo& info,
+ FileSystemOperation* operation) = 0;
+
+ virtual void DidReadDirectory(
+ const std::vector<base::file_util_proxy::Entry>& entries,
+ bool has_more, FileSystemOperation* operation) = 0;
+};
+
+} // namespace fileapi
+
+#endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CLIENT_H_
diff --git a/webkit/fileapi/webkit_fileapi.gypi b/webkit/fileapi/webkit_fileapi.gypi
new file mode 100644
index 0000000..cce29cc
--- /dev/null
+++ b/webkit/fileapi/webkit_fileapi.gypi
@@ -0,0 +1,31 @@
+# Copyright (c) 2010 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+{
+ 'targets': [
+ {
+ 'target_name': 'fileapi',
+ 'type': '<(library)',
+ 'msvs_guid': '40B53211-03ED-4932-8D53-52B172599DFE',
+ 'dependencies': [
+ '<(DEPTH)/app/app.gyp:app_base',
+ '<(DEPTH)/base/base.gyp:base',
+ '<(DEPTH)/net/net.gyp:net',
+ ],
+ 'sources': [
+ 'file_system_operation.cc',
+ 'file_system_operation.h',
+ 'file_system_operation_client.h',
+ ],
+ 'conditions': [
+ ['inside_chromium_build==0', {
+ 'dependencies': [
+ '<(DEPTH)/webkit/support/setup_third_party.gyp:third_party_headers',
+ ],
+ }],
+ ],
+ },
+ ],
+}
+
diff --git a/webkit/support/test_webkit_client.cc b/webkit/support/test_webkit_client.cc
index cb176b1..9bc8692 100644
--- a/webkit/support/test_webkit_client.cc
+++ b/webkit/support/test_webkit_client.cc
@@ -14,6 +14,7 @@
#include "media/base/media.h"
#include "third_party/WebKit/WebKit/chromium/public/WebData.h"
#include "third_party/WebKit/WebKit/chromium/public/WebDatabase.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h"
#include "third_party/WebKit/WebKit/chromium/public/WebGraphicsContext3D.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBFactory.h"
#include "third_party/WebKit/WebKit/chromium/public/WebRuntimeFeatures.h"
@@ -39,6 +40,7 @@
#include "webkit/tools/test_shell/mock_webclipboard_impl.h"
#include "webkit/tools/test_shell/simple_appcache_system.h"
#include "webkit/tools/test_shell/simple_database_system.h"
+#include "webkit/tools/test_shell/simple_file_system.h"
#include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
#include "webkit/tools/test_shell/simple_webcookiejar_impl.h"
#include "webkit/tools/test_shell/test_shell_request_context.h"
@@ -158,6 +160,10 @@ WebKit::WebBlobRegistry* TestWebKitClient::blobRegistry() {
return blob_registry_.get();
}
+WebKit::WebFileSystem* TestWebKitClient::fileSystem() {
+ return &file_system_;
+}
+
bool TestWebKitClient::sandboxEnabled() {
return true;
}
diff --git a/webkit/support/test_webkit_client.h b/webkit/support/test_webkit_client.h
index 8a0b3a4..e7b2805 100644
--- a/webkit/support/test_webkit_client.h
+++ b/webkit/support/test_webkit_client.h
@@ -11,6 +11,7 @@
#include "webkit/tools/test_shell/mock_webclipboard_impl.h"
#include "webkit/tools/test_shell/simple_appcache_system.h"
#include "webkit/tools/test_shell/simple_database_system.h"
+#include "webkit/tools/test_shell/simple_file_system.h"
#include "webkit/tools/test_shell/simple_webcookiejar_impl.h"
#include "webkit/tools/test_shell/test_shell_webmimeregistry_impl.h"
@@ -28,6 +29,7 @@ class TestWebKitClient : public webkit_glue::WebKitClientImpl {
virtual WebKit::WebSandboxSupport* sandboxSupport();
virtual WebKit::WebCookieJar* cookieJar();
virtual WebKit::WebBlobRegistry* blobRegistry();
+ virtual WebKit::WebFileSystem* fileSystem();
virtual bool sandboxEnabled();
virtual WebKit::WebKitClient::FileHandle databaseOpenFile(
@@ -76,6 +78,7 @@ class TestWebKitClient : public webkit_glue::WebKitClientImpl {
SimpleDatabaseSystem database_system_;
SimpleWebCookieJarImpl cookie_jar_;
scoped_refptr<TestShellWebBlobRegistryImpl> blob_registry_;
+ SimpleFileSystem file_system_;
WebURLLoaderMockFactory url_loader_factory_;
bool unit_test_mode_;
diff --git a/webkit/support/webkit_support.gyp b/webkit/support/webkit_support.gyp
index 0de6dcb..7fab468 100644
--- a/webkit/support/webkit_support.gyp
+++ b/webkit/support/webkit_support.gyp
@@ -6,6 +6,7 @@
'includes': [
'../appcache/webkit_appcache.gypi',
'../blob/webkit_blob.gypi',
+ '../fileapi/webkit_fileapi.gypi',
'../database/webkit_database.gypi',
'../glue/webkit_glue.gypi',
# TODO(tkent): Merge npapi_layout_test_plugin into TestNetscapePlugIn
diff --git a/webkit/support/webkit_support.gypi b/webkit/support/webkit_support.gypi
index 2aa5d6a..99c8ae0 100644
--- a/webkit/support/webkit_support.gypi
+++ b/webkit/support/webkit_support.gypi
@@ -18,6 +18,7 @@
'appcache',
'blob',
'database',
+ 'fileapi',
'glue',
],
'include_dirs': [
@@ -51,6 +52,8 @@
'<(DEPTH)/webkit/tools/test_shell/mock_webclipboard_impl.h',
'<(DEPTH)/webkit/tools/test_shell/simple_appcache_system.cc',
'<(DEPTH)/webkit/tools/test_shell/simple_appcache_system.h',
+ '<(DEPTH)/webkit/tools/test_shell/simple_file_system.cc',
+ '<(DEPTH)/webkit/tools/test_shell/simple_file_system.h',
'<(DEPTH)/webkit/tools/test_shell/simple_clipboard_impl.cc',
'<(DEPTH)/webkit/tools/test_shell/simple_database_system.cc',
'<(DEPTH)/webkit/tools/test_shell/simple_database_system.h',
diff --git a/webkit/tools/test_shell/simple_file_system.cc b/webkit/tools/test_shell/simple_file_system.cc
new file mode 100644
index 0000000..11da52c
--- /dev/null
+++ b/webkit/tools/test_shell/simple_file_system.cc
@@ -0,0 +1,160 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/tools/test_shell/simple_file_system.h"
+
+#include "base/file_path.h"
+#include "base/message_loop_proxy.h"
+#include "base/time.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebFileInfo.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebFileSystemEntry.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
+#include "webkit/glue/webkit_glue.h"
+
+using WebKit::WebFileSystemCallbacks;
+using WebKit::WebString;
+
+TestShellFileSystemOperation::TestShellFileSystemOperation(
+ fileapi::FileSystemOperationClient* client,
+ scoped_refptr<base::MessageLoopProxy> proxy,
+ WebFileSystemCallbacks* callbacks)
+ : fileapi::FileSystemOperation(client, proxy), callbacks_(callbacks) { }
+
+SimpleFileSystem::~SimpleFileSystem() {
+ // Drop all the operations.
+ for (OperationsMap::const_iterator iter(&operations_);
+ !iter.IsAtEnd(); iter.Advance()) {
+ operations_.Remove(iter.GetCurrentKey());
+ }
+}
+
+void SimpleFileSystem::move(
+ const WebString& src_path,
+ const WebString& dest_path, WebFileSystemCallbacks* callbacks) {
+ FilePath dest_filepath(webkit_glue::WebStringToFilePath(dest_path));
+ FilePath src_filepath(webkit_glue::WebStringToFilePath(src_path));
+
+ GetNewOperation(callbacks)->Move(src_filepath, dest_filepath);
+}
+
+void SimpleFileSystem::copy(
+ const WebString& src_path, const WebString& dest_path,
+ WebFileSystemCallbacks* callbacks) {
+ FilePath dest_filepath(webkit_glue::WebStringToFilePath(dest_path));
+ FilePath src_filepath(webkit_glue::WebStringToFilePath(src_path));
+
+ GetNewOperation(callbacks)->Copy(src_filepath, dest_filepath);
+}
+
+void SimpleFileSystem::remove(
+ const WebString& path, WebFileSystemCallbacks* callbacks) {
+ FilePath filepath(webkit_glue::WebStringToFilePath(path));
+
+ GetNewOperation(callbacks)->Remove(filepath);
+}
+
+void SimpleFileSystem::getMetadata(
+ const WebString& path, WebFileSystemCallbacks* callbacks) {
+ FilePath filepath(webkit_glue::WebStringToFilePath(path));
+
+ GetNewOperation(callbacks)->GetMetadata(filepath);
+}
+
+void SimpleFileSystem::createFile(
+ const WebString& path, bool exclusive, WebFileSystemCallbacks* callbacks) {
+ FilePath filepath(webkit_glue::WebStringToFilePath(path));
+
+ GetNewOperation(callbacks)->CreateFile(filepath, exclusive);
+}
+
+void SimpleFileSystem::createDirectory(
+ const WebString& path, bool exclusive, WebFileSystemCallbacks* callbacks) {
+ FilePath filepath(webkit_glue::WebStringToFilePath(path));
+
+ GetNewOperation(callbacks)->CreateDirectory(filepath, exclusive);
+}
+
+void SimpleFileSystem::fileExists(
+ const WebString& path, WebFileSystemCallbacks* callbacks) {
+ FilePath filepath(webkit_glue::WebStringToFilePath(path));
+
+ GetNewOperation(callbacks)->FileExists(filepath);
+}
+
+void SimpleFileSystem::directoryExists(
+ const WebString& path, WebFileSystemCallbacks* callbacks) {
+ FilePath filepath(webkit_glue::WebStringToFilePath(path));
+
+ GetNewOperation(callbacks)->DirectoryExists(filepath);
+}
+
+void SimpleFileSystem::readDirectory(
+ const WebString& path, WebFileSystemCallbacks* callbacks) {
+ FilePath filepath(webkit_glue::WebStringToFilePath(path));
+
+ GetNewOperation(callbacks)->ReadDirectory(filepath);
+}
+
+void SimpleFileSystem::DidFail(WebKit::WebFileError status,
+ fileapi::FileSystemOperation* operation) {
+ WebFileSystemCallbacks* callbacks =
+ static_cast<TestShellFileSystemOperation*>(operation)->callbacks();
+ callbacks->didFail(status);
+ RemoveOperation(operation);
+}
+
+void SimpleFileSystem::DidSucceed(fileapi::FileSystemOperation* operation) {
+ WebFileSystemCallbacks* callbacks =
+ static_cast<TestShellFileSystemOperation*>(operation)->callbacks();
+ callbacks->didSucceed();
+ RemoveOperation(operation);
+}
+
+void SimpleFileSystem::DidReadMetadata(
+ const base::PlatformFileInfo& info,
+ fileapi::FileSystemOperation* operation) {
+ WebFileSystemCallbacks* callbacks =
+ static_cast<TestShellFileSystemOperation*>(operation)->callbacks();
+ WebKit::WebFileInfo web_file_info;
+ web_file_info.modificationTime = info.last_modified.ToDoubleT();
+ callbacks->didReadMetadata(web_file_info);
+ RemoveOperation(operation);
+}
+
+void SimpleFileSystem::DidReadDirectory(
+ const std::vector<base::file_util_proxy::Entry>& entries,
+ bool has_more, fileapi::FileSystemOperation* operation) {
+ WebFileSystemCallbacks* callbacks =
+ static_cast<TestShellFileSystemOperation*>(operation)->callbacks();
+ std::vector<WebKit::WebFileSystemEntry> web_entries_vector;
+ for (std::vector<base::file_util_proxy::Entry>::const_iterator it =
+ entries.begin(); it != entries.end(); ++it) {
+ WebKit::WebFileSystemEntry entry;
+ entry.name = webkit_glue::FilePathStringToWebString(it->name);
+ entry.isDirectory = it->is_directory;
+ web_entries_vector.push_back(entry);
+ }
+ WebKit::WebVector<WebKit::WebFileSystemEntry> web_entries =
+ web_entries_vector;
+ callbacks->didReadDirectory(web_entries, false);
+ RemoveOperation(operation);
+}
+
+TestShellFileSystemOperation* SimpleFileSystem::GetNewOperation(
+ WebFileSystemCallbacks* callbacks) {
+ scoped_ptr<TestShellFileSystemOperation> operation(
+ new TestShellFileSystemOperation(
+ this,
+ base::MessageLoopProxy::CreateForCurrentThread(), callbacks));
+ int32 request_id = operations_.Add(operation.get());
+ operation->set_request_id(request_id);
+ return operation.release();
+}
+
+void SimpleFileSystem::RemoveOperation(
+ fileapi::FileSystemOperation* operation) {
+ int request_id = static_cast<TestShellFileSystemOperation*>(
+ operation)->request_id();
+ operations_.Remove(request_id);
+}
diff --git a/webkit/tools/test_shell/simple_file_system.h b/webkit/tools/test_shell/simple_file_system.h
new file mode 100644
index 0000000..b3487c6
--- /dev/null
+++ b/webkit/tools/test_shell/simple_file_system.h
@@ -0,0 +1,95 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this
+// source code is governed by a BSD-style license that can be found in the
+// LICENSE file.
+
+#ifndef WEBKIT_TOOLS_TEST_SHELL_SIMPLE_FILE_SYSTEM_H_
+#define WEBKIT_TOOLS_TEST_SHELL_SIMPLE_FILE_SYSTEM_H_
+
+#include <vector>
+#include "base/file_util_proxy.h"
+#include "base/id_map.h"
+#include "base/message_loop_proxy.h"
+#include "base/platform_file.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h"
+#include "webkit/fileapi/file_system_operation.h"
+#include "webkit/fileapi/file_system_operation_client.h"
+
+class TestShellFileSystemOperation : public fileapi::FileSystemOperation {
+ public:
+ TestShellFileSystemOperation(
+ fileapi::FileSystemOperationClient* client,
+ scoped_refptr<base::MessageLoopProxy> proxy,
+ WebKit::WebFileSystemCallbacks* callbacks);
+
+ WebKit::WebFileSystemCallbacks* callbacks() { return callbacks_; }
+
+ void set_request_id(int request_id) { request_id_ = request_id; }
+ int request_id() { return request_id_; }
+
+ private:
+ // Not owned.
+ WebKit::WebFileSystemCallbacks* callbacks_;
+
+ // Just for IDMap of operations.
+ int request_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestShellFileSystemOperation);
+};
+
+class SimpleFileSystem
+ : public WebKit::WebFileSystem,
+ public fileapi::FileSystemOperationClient {
+ public:
+ SimpleFileSystem() {}
+ virtual ~SimpleFileSystem();
+
+ // WebKit::WebFileSystem methods.
+ virtual void move(const WebKit::WebString& src_path,
+ const WebKit::WebString& dest_path,
+ WebKit::WebFileSystemCallbacks* callbacks);
+ virtual void copy(const WebKit::WebString& src_path,
+ const WebKit::WebString& dest_path,
+ WebKit::WebFileSystemCallbacks* callbacks);
+ virtual void remove(const WebKit::WebString& path,
+ WebKit::WebFileSystemCallbacks* callbacks);
+ virtual void getMetadata(const WebKit::WebString& path,
+ WebKit::WebFileSystemCallbacks* callbacks);
+ virtual void createFile(const WebKit::WebString& path, bool exclusive,
+ WebKit::WebFileSystemCallbacks* callbacks);
+ virtual void createDirectory(const WebKit::WebString& path, bool exclusive,
+ WebKit::WebFileSystemCallbacks* callbacks);
+ virtual void fileExists(const WebKit::WebString& path,
+ WebKit::WebFileSystemCallbacks* callbacks);
+ virtual void directoryExists(const WebKit::WebString& path,
+ WebKit::WebFileSystemCallbacks* callbacks);
+ virtual void readDirectory(const WebKit::WebString& path,
+ WebKit::WebFileSystemCallbacks* callbacks);
+
+ // FileSystemOperationClient methods.
+ virtual void DidFail(WebKit::WebFileError status,
+ fileapi::FileSystemOperation* operation);
+ virtual void DidSucceed(fileapi::FileSystemOperation* operation);
+ virtual void DidReadMetadata(
+ const base::PlatformFileInfo& info,
+ fileapi::FileSystemOperation* operation);
+ virtual void DidReadDirectory(
+ const std::vector<base::file_util_proxy::Entry>& entries,
+ bool has_more, fileapi::FileSystemOperation* operation);
+
+ private:
+ // Helpers.
+ TestShellFileSystemOperation* GetNewOperation(
+ WebKit::WebFileSystemCallbacks* callbacks);
+
+ void RemoveOperation(fileapi::FileSystemOperation* operation);
+
+ // Keeps ongoing file system operations.
+ typedef IDMap<TestShellFileSystemOperation, IDMapOwnPointer> OperationsMap;
+ OperationsMap operations_;
+
+ DISALLOW_COPY_AND_ASSIGN(SimpleFileSystem);
+};
+
+#endif // WEBKIT_TOOLS_TEST_SHELL_SIMPLE_FILE_SYSTEM_H_
+
diff --git a/webkit/tools/test_shell/test_shell_webkit_init.h b/webkit/tools/test_shell/test_shell_webkit_init.h
index 459c253..08468c9 100644
--- a/webkit/tools/test_shell/test_shell_webkit_init.h
+++ b/webkit/tools/test_shell/test_shell_webkit_init.h
@@ -19,6 +19,7 @@
#include "webkit/tools/test_shell/mock_webclipboard_impl.h"
#include "webkit/tools/test_shell/simple_appcache_system.h"
#include "webkit/tools/test_shell/simple_database_system.h"
+#include "webkit/tools/test_shell/simple_file_system.h"
#include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
#include "webkit/tools/test_shell/simple_webcookiejar_impl.h"
#include "webkit/tools/test_shell/test_shell_webblobregistry_impl.h"
@@ -55,6 +56,10 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl {
return blob_registry_.get();
}
+ virtual WebKit::WebFileSystem* fileSystem() {
+ return &file_system_;
+ }
+
virtual bool sandboxEnabled() {
return true;
}
@@ -162,6 +167,7 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl {
SimpleDatabaseSystem database_system_;
SimpleWebCookieJarImpl cookie_jar_;
scoped_refptr<TestShellWebBlobRegistryImpl> blob_registry_;
+ SimpleFileSystem file_system_;
#if defined(OS_WIN)
WebKit::WebThemeEngine* active_theme_engine_;