diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-27 18:37:08 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-27 18:37:08 +0000 |
commit | c5a272dbd00c74dffe922523811a4ecbcd7f882b (patch) | |
tree | 90528ee8bec3657a531a2f5095aff97f5f0a3f18 /chrome | |
parent | 445028be1162ed994286addce0b27d0e6239382d (diff) | |
download | chromium_src-c5a272dbd00c74dffe922523811a4ecbcd7f882b.zip chromium_src-c5a272dbd00c74dffe922523811a4ecbcd7f882b.tar.gz chromium_src-c5a272dbd00c74dffe922523811a4ecbcd7f882b.tar.bz2 |
Add Worker support for FileSystem API.
(corresponds to https://bugs.webkit.org/show_bug.cgi?id=45808)
No support for shared workers yet.
BUG=32277
TEST=none; layout tests will be added later.
Review URL: http://codereview.chromium.org/3394003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60683 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
34 files changed, 321 insertions, 271 deletions
diff --git a/chrome/browser/file_system/browser_file_system_callback_dispatcher.cc b/chrome/browser/file_system/browser_file_system_callback_dispatcher.cc index 129d4a7..1d2ec0a 100644 --- a/chrome/browser/file_system/browser_file_system_callback_dispatcher.cc +++ b/chrome/browser/file_system/browser_file_system_callback_dispatcher.cc @@ -5,6 +5,7 @@ #include "chrome/browser/file_system/browser_file_system_callback_dispatcher.h" #include "chrome/browser/file_system/file_system_dispatcher_host.h" +#include "chrome/common/render_messages.h" BrowserFileSystemCallbackDispatcher::BrowserFileSystemCallbackDispatcher( FileSystemDispatcherHost* dispatcher_host, int request_id) @@ -33,7 +34,7 @@ void BrowserFileSystemCallbackDispatcher::DidReadDirectory( } void BrowserFileSystemCallbackDispatcher::DidOpenFileSystem( - const string16&, const FilePath&) { + const std::string&, const FilePath&) { NOTREACHED(); } diff --git a/chrome/browser/file_system/browser_file_system_callback_dispatcher.h b/chrome/browser/file_system/browser_file_system_callback_dispatcher.h index 075ae30..f24ce71 100644 --- a/chrome/browser/file_system/browser_file_system_callback_dispatcher.h +++ b/chrome/browser/file_system/browser_file_system_callback_dispatcher.h @@ -21,7 +21,7 @@ class BrowserFileSystemCallbackDispatcher virtual void DidReadDirectory( const std::vector<base::file_util_proxy::Entry>& entries, bool has_more); - virtual void DidOpenFileSystem(const string16& name, + virtual void DidOpenFileSystem(const std::string& name, const FilePath& root_path); virtual void DidFail(base::PlatformFileError error_code); virtual void DidWrite(int64 bytes, bool complete); diff --git a/chrome/browser/file_system/file_system_dispatcher_host.cc b/chrome/browser/file_system/file_system_dispatcher_host.cc index 5cfa5be..324612d 100644 --- a/chrome/browser/file_system/file_system_dispatcher_host.cc +++ b/chrome/browser/file_system/file_system_dispatcher_host.cc @@ -7,7 +7,6 @@ #include "base/file_path.h" #include "base/thread.h" #include "base/time.h" -#include "base/utf_string_conversions.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/file_system/browser_file_system_callback_dispatcher.h" @@ -17,19 +16,17 @@ #include "chrome/common/render_messages.h" #include "chrome/common/render_messages_params.h" #include "googleurl/src/gurl.h" -#include "webkit/glue/webkit_glue.h" // A class to hold an ongoing openFileSystem completion task. struct OpenFileSystemCompletionTask { public: static void Run( int request_id, - int routing_id, const std::string& name, const FilePath& root_path, FileSystemDispatcherHost* dispatcher_host) { // The task is self-destructed. - new OpenFileSystemCompletionTask(request_id, routing_id, name, root_path, + new OpenFileSystemCompletionTask(request_id, name, root_path, dispatcher_host); } @@ -37,24 +34,21 @@ struct OpenFileSystemCompletionTask { if (error == base::PLATFORM_FILE_OK) dispatcher_host_->Send( new ViewMsg_OpenFileSystemRequest_Complete( - routing_id_, request_id_, true, UTF8ToUTF16(name_), - webkit_glue::FilePathToWebString(root_path_))); + request_id_, true, name_, root_path_)); else dispatcher_host_->Send( new ViewMsg_OpenFileSystemRequest_Complete( - routing_id_, request_id_, false, string16(), string16())); + request_id_, false, std::string(), FilePath())); delete this; } private: OpenFileSystemCompletionTask( int request_id, - int routing_id, const std::string& name, const FilePath& root_path, FileSystemDispatcherHost* dispatcher_host) : request_id_(request_id), - routing_id_(routing_id), name_(name), root_path_(root_path), dispatcher_host_(dispatcher_host), @@ -66,7 +60,6 @@ struct OpenFileSystemCompletionTask { } int request_id_; - int routing_id_; std::string name_; FilePath root_path_; scoped_refptr<FileSystemDispatcherHost> dispatcher_host_; @@ -124,30 +117,29 @@ bool FileSystemDispatcherHost::OnMessageReceived( } void FileSystemDispatcherHost::OnOpenFileSystem( - const ViewHostMsg_OpenFileSystemRequest_Params& params) { + int request_id, const GURL& origin_url, fileapi::FileSystemType type, + int64 requested_size) { // TODO(kinuko): hook up ContentSettings cookies type checks. FilePath root_path; std::string name; - if (!context_->GetFileSystemRootPath(params.origin_url, - params.type, + if (!context_->GetFileSystemRootPath(origin_url, + type, &root_path, &name)) { Send(new ViewMsg_OpenFileSystemRequest_Complete( - params.routing_id, - params.request_id, + request_id, false, - string16(), - string16())); + std::string(), + FilePath())); return; } // Run the completion task that creates the root directory and sends // back the status code to the dispatcher. - OpenFileSystemCompletionTask::Run( - params.request_id, params.routing_id, name, root_path, this); + OpenFileSystemCompletionTask::Run(request_id, name, root_path, this); } void FileSystemDispatcherHost::OnMove( diff --git a/chrome/browser/file_system/file_system_dispatcher_host.h b/chrome/browser/file_system/file_system_dispatcher_host.h index 561350c..20bb77c 100644 --- a/chrome/browser/file_system/file_system_dispatcher_host.h +++ b/chrome/browser/file_system/file_system_dispatcher_host.h @@ -13,9 +13,11 @@ #include "base/platform_file.h" #include "base/scoped_callback_factory.h" #include "base/ref_counted.h" -#include "chrome/common/render_messages.h" +#include "ipc/ipc_message.h" #include "webkit/fileapi/file_system_operation.h" +#include "webkit/fileapi/file_system_types.h" +class ChromeFileSystemOperation; class FileSystemHostContext; class GURL; class HostContentSettingsMap; @@ -34,7 +36,10 @@ class FileSystemDispatcherHost bool OnMessageReceived(const IPC::Message& message, bool* message_was_ok); - void OnOpenFileSystem(const ViewHostMsg_OpenFileSystemRequest_Params&); + void OnOpenFileSystem(int request_id, + const GURL& origin_url, + fileapi::FileSystemType type, + int64 requested_size); void OnMove(int request_id, const FilePath& src_path, const FilePath& dest_path); diff --git a/chrome/browser/file_system/file_system_host_context.cc b/chrome/browser/file_system/file_system_host_context.cc index c14dfe1..f0cea3b 100644 --- a/chrome/browser/file_system/file_system_host_context.cc +++ b/chrome/browser/file_system/file_system_host_context.cc @@ -7,9 +7,9 @@ #include "base/file_util.h" #include "base/logging.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/profile.h" -#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" +#include "googleurl/src/gurl.h" #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" const FilePath::CharType FileSystemHostContext::kFileSystemDirectory[] = @@ -25,21 +25,21 @@ FileSystemHostContext::FileSystemHostContext( } bool FileSystemHostContext::GetFileSystemRootPath( - const GURL& origin_url, WebKit::WebFileSystem::Type type, + const GURL& origin_url, fileapi::FileSystemType type, FilePath* root_path, std::string* name) const { // TODO(kinuko): should return an isolated temporary file system space. if (is_incognito_) return false; std::string storage_identifier = GetStorageIdentifierFromURL(origin_url); switch (type) { - case WebKit::WebFileSystem::TypeTemporary: + case fileapi::kFileSystemTypeTemporary: if (root_path) *root_path = base_path_.AppendASCII(storage_identifier) .AppendASCII(kTemporaryName); if (name) *name = storage_identifier + ":" + kTemporaryName; return true; - case WebKit::WebFileSystem::TypePersistent: + case fileapi::kFileSystemTypePersistent: if (root_path) *root_path = base_path_.AppendASCII(storage_identifier) .AppendASCII(kPersistentName); @@ -63,3 +63,8 @@ std::string FileSystemHostContext::GetStorageIdentifierFromURL( WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec())); return web_security_origin.databaseIdentifier().utf8(); } + +COMPILE_ASSERT(int(WebKit::WebFileSystem::TypeTemporary) == \ + int(fileapi::kFileSystemTypeTemporary), mismatching_enums); +COMPILE_ASSERT(int(WebKit::WebFileSystem::TypePersistent) == \ + int(fileapi::kFileSystemTypePersistent), mismatching_enums); diff --git a/chrome/browser/file_system/file_system_host_context.h b/chrome/browser/file_system/file_system_host_context.h index 592ccd6..e651a43 100644 --- a/chrome/browser/file_system/file_system_host_context.h +++ b/chrome/browser/file_system/file_system_host_context.h @@ -8,8 +8,9 @@ #include "base/file_path.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" -#include "googleurl/src/gurl.h" -#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" +#include "webkit/fileapi/file_system_types.h" + +class GURL; // This is owned by profile and shared by all the FileSystemDispatcherHost // that shared by the same profile. @@ -23,11 +24,10 @@ class FileSystemHostContext // Returns the root path and name for the file system specified by given // |origin_url| and |type|. Returns true if the file system is available // for the profile and |root_path| and |name| are filled successfully. - bool GetFileSystemRootPath( - const GURL& origin_url, - WebKit::WebFileSystem::Type type, - FilePath* root_path, - std::string* name) const; + bool GetFileSystemRootPath(const GURL& origin_url, + fileapi::FileSystemType type, + FilePath* root_path, + std::string* name) const; // Check if the given |path| is in the FileSystem base directory. bool CheckValidFileSystemPath(const FilePath& path) const; diff --git a/chrome/browser/file_system/file_system_host_context_unittest.cc b/chrome/browser/file_system/file_system_host_context_unittest.cc index 6bcda9d..3837e00 100644 --- a/chrome/browser/file_system/file_system_host_context_unittest.cc +++ b/chrome/browser/file_system/file_system_host_context_unittest.cc @@ -9,7 +9,6 @@ #include "chrome/browser/file_system/file_system_host_context.h" #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" namespace { @@ -24,19 +23,19 @@ const FilePath::CharType kTestDataPath[] = FILE_PATH_LITERAL( "//tmp/TestingProfilePath"); const struct RootPathTest { - WebKit::WebFileSystem::Type type; + fileapi::FileSystemType type; bool off_the_record; const char* origin_url; bool expect_root_path; const char* expected_path; } kRootPathTestCases[] = { - { WebKit::WebFileSystem::TypeTemporary, false, "http://host:1/", + { fileapi::kFileSystemTypeTemporary, false, "http://host:1/", true, "FileSystem" PS "http_host_1" PS "Temporary" }, - { WebKit::WebFileSystem::TypePersistent, false, "http://host:2/", + { fileapi::kFileSystemTypePersistent, false, "http://host:2/", true, "FileSystem" PS "http_host_2" PS "Persistent" }, - { WebKit::WebFileSystem::TypeTemporary, true, "http://host:3/", + { fileapi::kFileSystemTypeTemporary, true, "http://host:3/", false, "" }, - { WebKit::WebFileSystem::TypePersistent, true, "http://host:4/", + { fileapi::kFileSystemTypePersistent, true, "http://host:4/", false, "" }, }; @@ -89,7 +88,7 @@ TEST(FileSystemHostContextTest, CheckValidPath) { FilePath root_path; EXPECT_TRUE(context->GetFileSystemRootPath( - GURL("http://foo.com/"), WebKit::WebFileSystem::TypePersistent, + GURL("http://foo.com/"), fileapi::kFileSystemTypePersistent, &root_path, NULL)); FilePath path(kCheckValidPathTestCases[i].path); if (!path.IsAbsolute()) diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index e7811fc..7cc4a91 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -944,6 +944,7 @@ ChromeURLRequestContext::ChromeURLRequestContext( is_media_ = other->is_media_; is_off_the_record_ = other->is_off_the_record_; blob_storage_context_ = other->blob_storage_context_; + file_system_host_context_ = other->file_system_host_context_; } void ChromeURLRequestContext::OnAcceptLanguageChange( @@ -1029,6 +1030,7 @@ ChromeURLRequestContextFactory::ChromeURLRequestContextFactory(Profile* profile) appcache_service_ = profile->GetAppCacheService(); database_tracker_ = profile->GetDatabaseTracker(); blob_storage_context_ = profile->GetBlobStorageContext(); + file_system_host_context_ = profile->GetFileSystemHostContext(); } ChromeURLRequestContextFactory::~ChromeURLRequestContextFactory() { @@ -1054,6 +1056,7 @@ void ChromeURLRequestContextFactory::ApplyProfileParametersToContext( context->set_appcache_service(appcache_service_); context->set_database_tracker(database_tracker_); context->set_blob_storage_context(blob_storage_context_); + context->set_file_system_host_context(file_system_host_context_); } // ---------------------------------------------------------------------------- diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h index cd4200c..ebae377 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -14,6 +14,7 @@ #include "base/linked_ptr.h" #include "chrome/browser/appcache/chrome_appcache_service.h" #include "chrome/browser/chrome_blob_storage_context.h" +#include "chrome/browser/file_system/file_system_host_context.h" #include "chrome/browser/host_content_settings_map.h" #include "chrome/browser/host_zoom_map.h" #include "chrome/browser/io_thread.h" @@ -134,6 +135,11 @@ class ChromeURLRequestContext : public URLRequestContext { return blob_storage_context_.get(); } + // Gets the file system host context with this context's profile. + FileSystemHostContext* file_system_host_context() const { + return file_system_host_context_.get(); + } + bool is_off_the_record() const { return is_off_the_record_; } @@ -237,6 +243,9 @@ class ChromeURLRequestContext : public URLRequestContext { void set_blob_storage_context(ChromeBlobStorageContext* context) { blob_storage_context_ = context; } + void set_file_system_host_context(FileSystemHostContext* context) { + file_system_host_context_ = context; + } void set_net_log(net::NetLog* net_log) { net_log_ = net_log; } @@ -263,6 +272,7 @@ class ChromeURLRequestContext : public URLRequestContext { scoped_refptr<HostContentSettingsMap> host_content_settings_map_; scoped_refptr<HostZoomMap> host_zoom_map_; scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; + scoped_refptr<FileSystemHostContext> file_system_host_context_; bool is_media_; bool is_off_the_record_; @@ -431,6 +441,7 @@ class ChromeURLRequestContextFactory { scoped_refptr<net::SSLConfigService> ssl_config_service_; scoped_refptr<net::CookieMonster::Delegate> cookie_monster_delegate_; scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; + scoped_refptr<FileSystemHostContext> file_system_host_context_; FilePath profile_dir_path_; diff --git a/chrome/browser/worker_host/worker_process_host.cc b/chrome/browser/worker_host/worker_process_host.cc index 32ce928..868ba6c 100644 --- a/chrome/browser/worker_host/worker_process_host.cc +++ b/chrome/browser/worker_host/worker_process_host.cc @@ -16,6 +16,7 @@ #include "chrome/browser/appcache/appcache_dispatcher_host.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/child_process_security_policy.h" +#include "chrome/browser/file_system/file_system_dispatcher_host.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/blob_dispatcher_host.h" @@ -67,7 +68,11 @@ WorkerProcessHost::WorkerProcessHost( new AppCacheDispatcherHost(request_context)), ALLOW_THIS_IN_INITIALIZER_LIST(blob_dispatcher_host_( new BlobDispatcherHost( - this->id(), request_context->blob_storage_context()))) { + this->id(), request_context->blob_storage_context()))), + ALLOW_THIS_IN_INITIALIZER_LIST(file_system_dispatcher_host_( + new FileSystemDispatcherHost(this, + request_context->file_system_host_context(), + request_context->host_content_settings_map()))) { next_route_id_callback_.reset(NewCallbackWithReturnValue( WorkerService::GetInstance(), &WorkerService::next_worker_route_id)); db_dispatcher_host_ = new DatabaseDispatcherHost( @@ -83,6 +88,9 @@ WorkerProcessHost::~WorkerProcessHost() { // Shut down the blob dispatcher host. blob_dispatcher_host_->Shutdown(); + // Shut down the file system dispatcher host. + file_system_dispatcher_host_->Shutdown(); + // Let interested observers know we are being deleted. NotificationService::current()->Notify( NotificationType::WORKER_PROCESS_HOST_SHUTDOWN, @@ -129,6 +137,7 @@ bool WorkerProcessHost::Init() { #if defined(OS_WIN) switches::kDisableDesktopNotifications, #endif + switches::kEnableFileSystem, }; cmd_line->CopySwitchesFrom(*CommandLine::ForCurrentProcess(), kSwitchNames, arraysize(kSwitchNames)); @@ -241,6 +250,7 @@ void WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { appcache_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || db_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || blob_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || + file_system_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || MessagePortDispatcher::GetInstance()->OnMessageReceived( message, this, next_route_id_callback_.get(), &msg_is_ok); @@ -289,6 +299,7 @@ void WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { void WorkerProcessHost::OnProcessLaunched() { db_dispatcher_host_->Init(handle()); + file_system_dispatcher_host_->Init(handle()); } CallbackWithReturnValue<int>::Type* WorkerProcessHost::GetNextRouteIdCallback( diff --git a/chrome/browser/worker_host/worker_process_host.h b/chrome/browser/worker_host/worker_process_host.h index e009813..0bdc4ef 100644 --- a/chrome/browser/worker_host/worker_process_host.h +++ b/chrome/browser/worker_host/worker_process_host.h @@ -22,6 +22,7 @@ class BlobDispatcherHost; class ChromeURLRequestContext; class ChromeURLRequestContextGetter; class DatabaseDispatcherHost; +class FileSystemDispatcherHost; namespace webkit_database { class DatabaseTracker; } // namespace webkit_database @@ -197,6 +198,7 @@ class WorkerProcessHost : public BrowserChildProcessHost { scoped_ptr<AppCacheDispatcherHost> appcache_dispatcher_host_; scoped_refptr<DatabaseDispatcherHost> db_dispatcher_host_; scoped_ptr<BlobDispatcherHost> blob_dispatcher_host_; + scoped_refptr<FileSystemDispatcherHost> file_system_dispatcher_host_; // A callback to create a routing id for the associated worker process. scoped_ptr<CallbackWithReturnValue<int>::Type> next_route_id_callback_; diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index fa59520..b3b085a3 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -52,6 +52,8 @@ 'common/devtools_messages.cc', 'common/devtools_messages.h', 'common/devtools_messages_internal.h', + 'common/file_system/webfilesystem_callback_dispatcher.cc', + 'common/file_system/webfilesystem_callback_dispatcher.h', 'common/file_system/webfilesystem_impl.cc', 'common/file_system/webfilesystem_impl.h', 'common/font_descriptor_mac.h', diff --git a/chrome/common/file_system/file_system_dispatcher.cc b/chrome/common/file_system/file_system_dispatcher.cc index 8ae0c16..6f5d2a3 100644 --- a/chrome/common/file_system/file_system_dispatcher.cc +++ b/chrome/common/file_system/file_system_dispatcher.cc @@ -8,7 +8,6 @@ #include "chrome/common/child_thread.h" #include "chrome/common/render_messages.h" #include "chrome/common/render_messages_params.h" -#include "webkit/glue/webkit_glue.h" FileSystemDispatcher::FileSystemDispatcher() { } @@ -28,6 +27,8 @@ FileSystemDispatcher::~FileSystemDispatcher() { bool FileSystemDispatcher::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(FileSystemDispatcher, msg) + IPC_MESSAGE_HANDLER(ViewMsg_OpenFileSystemRequest_Complete, + OnOpenFileSystemRequestComplete) IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidSucceed, DidSucceed) IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidReadDirectory, DidReadDirectory) IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidReadMetadata, DidReadMetadata) @@ -37,6 +38,14 @@ bool FileSystemDispatcher::OnMessageReceived(const IPC::Message& msg) { return handled; } +void FileSystemDispatcher::OpenFileSystem( + const GURL& origin_url, fileapi::FileSystemType type, + long long size, fileapi::FileSystemCallbackDispatcher* dispatcher) { + int request_id = dispatchers_.Add(dispatcher); + ChildThread::current()->Send(new ViewHostMsg_OpenFileSystemRequest( + request_id, origin_url, type, size)); +} + bool FileSystemDispatcher::Move( const FilePath& src_path, const FilePath& dest_path, @@ -99,6 +108,19 @@ bool FileSystemDispatcher::ReadDirectory( new ViewHostMsg_FileSystem_ReadDirectory(request_id, path)); } +void FileSystemDispatcher::OnOpenFileSystemRequestComplete( + int request_id, bool accepted, const std::string& name, + const FilePath& root_path) { + fileapi::FileSystemCallbackDispatcher* dispatcher = + dispatchers_.Lookup(request_id); + DCHECK(dispatcher); + if (accepted) + dispatcher->DidOpenFileSystem(name, root_path); + else + dispatcher->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); + dispatchers_.Remove(request_id); +} + void FileSystemDispatcher::DidSucceed(int request_id) { fileapi::FileSystemCallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); diff --git a/chrome/common/file_system/file_system_dispatcher.h b/chrome/common/file_system/file_system_dispatcher.h index 8214b1c..58b3cc72 100644 --- a/chrome/common/file_system/file_system_dispatcher.h +++ b/chrome/common/file_system/file_system_dispatcher.h @@ -10,17 +10,17 @@ #include "base/basictypes.h" #include "base/file_util_proxy.h" #include "base/id_map.h" -#include "base/nullable_string16.h" -#include "googleurl/src/gurl.h" #include "ipc/ipc_channel.h" #include "ipc/ipc_message.h" #include "webkit/fileapi/file_system_callback_dispatcher.h" +#include "webkit/fileapi/file_system_types.h" namespace base { struct PlatformFileInfo; } class FilePath; +class GURL; // Dispatches and sends file system related messages sent to/from a child // process from/to the main browser process. There is one instance @@ -32,6 +32,10 @@ class FileSystemDispatcher { bool OnMessageReceived(const IPC::Message& msg); + void OpenFileSystem(const GURL& origin_url, + fileapi::FileSystemType type, + long long size, + fileapi::FileSystemCallbackDispatcher* dispatcher); bool Move(const FilePath& src_path, const FilePath& dest_path, fileapi::FileSystemCallbackDispatcher* dispatcher); @@ -54,6 +58,14 @@ class FileSystemDispatcher { fileapi::FileSystemCallbackDispatcher* dispatcher); private: + // Message handler for OpenFileSystem. + void OnOpenFileSystemRequestComplete( + int request_id, + bool accepted, + const std::string& name, + const FilePath& root_path); + + // Message handlers for regular file system operations. void DidSucceed(int request_id); void DidReadMetadata(int request_id, const base::PlatformFileInfo& file_info); diff --git a/chrome/common/file_system/webfilesystem_callback_dispatcher.cc b/chrome/common/file_system/webfilesystem_callback_dispatcher.cc new file mode 100644 index 0000000..c68ff18 --- /dev/null +++ b/chrome/common/file_system/webfilesystem_callback_dispatcher.cc @@ -0,0 +1,82 @@ +// 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 "chrome/common/file_system/webfilesystem_callback_dispatcher.h" + +#include "base/file_util_proxy.h" +#include "base/utf_string_conversions.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFileInfo.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h" +#include "third_party/WebKit/WebKit/chromium/public/WebString.h" +#include "webkit/glue/webkit_glue.h" + +using WebKit::WebFileInfo; +using WebKit::WebFileSystemCallbacks; +using WebKit::WebFileSystemEntry; +using WebKit::WebString; +using WebKit::WebVector; + +namespace { + +WebKit::WebFileError PlatformFileErrorToWebFileError( + base::PlatformFileError error_code) { + switch (error_code) { + 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; + case base::PLATFORM_FILE_ERROR_FAILED: + return WebKit::WebFileErrorInvalidState; + case base::PLATFORM_FILE_ERROR_ABORT: + return WebKit::WebFileErrorAbort; + default: + return WebKit::WebFileErrorInvalidModification; + } +} + +} + +WebFileSystemCallbackDispatcher::WebFileSystemCallbackDispatcher( + WebFileSystemCallbacks* callbacks) + : callbacks_(callbacks) { + DCHECK(callbacks_); +} + +void WebFileSystemCallbackDispatcher::DidSucceed() { + callbacks_->didSucceed(); +} + +void WebFileSystemCallbackDispatcher::DidReadMetadata( + const base::PlatformFileInfo& file_info) { + WebFileInfo web_file_info; + web_file_info.modificationTime = file_info.last_modified.ToDoubleT(); + callbacks_->didReadMetadata(web_file_info); +} + +void WebFileSystemCallbackDispatcher::DidReadDirectory( + const std::vector<base::file_util_proxy::Entry>& entries, bool has_more) { + WebVector<WebFileSystemEntry> file_system_entries(entries.size()); + for (size_t i = 0; i < entries.size(); i++) { + file_system_entries[i].name = + webkit_glue::FilePathStringToWebString(entries[i].name); + file_system_entries[i].isDirectory = entries[i].is_directory; + } + callbacks_->didReadDirectory(file_system_entries, has_more); +} + +void WebFileSystemCallbackDispatcher::DidOpenFileSystem( + const std::string& name, const FilePath& root_path) { + callbacks_->didOpenFileSystem(UTF8ToUTF16(name), + webkit_glue::FilePathToWebString(root_path)); +} + +void WebFileSystemCallbackDispatcher::DidFail( + base::PlatformFileError error_code) { + callbacks_->didFail(PlatformFileErrorToWebFileError(error_code)); +} diff --git a/chrome/common/file_system/webfilesystem_callback_dispatcher.h b/chrome/common/file_system/webfilesystem_callback_dispatcher.h new file mode 100644 index 0000000..ade811b --- /dev/null +++ b/chrome/common/file_system/webfilesystem_callback_dispatcher.h @@ -0,0 +1,42 @@ +// 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 CHROME_COMMON_FILE_SYSTEM_WEBFILESYSTEM_CALLBACK_DISPATCHER_H_ +#define CHROME_COMMON_FILE_SYSTEM_WEBFILESYSTEM_CALLBACK_DISPATCHER_H_ + +#include "base/basictypes.h" +#include "base/platform_file.h" +#include "webkit/fileapi/file_system_callback_dispatcher.h" + +namespace base { +namespace file_util_proxy { +struct Entry; +} +} + +namespace WebKit { +class WebFileSystemCallbacks; +} + +class WebFileSystemCallbackDispatcher + : public fileapi::FileSystemCallbackDispatcher { + public: + explicit WebFileSystemCallbackDispatcher( + WebKit::WebFileSystemCallbacks* callbacks); + + // FileSystemCallbackDispatcher implementation + virtual void DidSucceed(); + virtual void DidReadMetadata(const base::PlatformFileInfo& file_info); + virtual void DidReadDirectory( + const std::vector<base::file_util_proxy::Entry>& entries, + bool has_more); + virtual void DidOpenFileSystem(const std::string&, + const FilePath&); + virtual void DidFail(base::PlatformFileError); + + private: + WebKit::WebFileSystemCallbacks* callbacks_; +}; + +#endif // CHROME_COMMON_FILE_SYSTEM_WEBFILESYSTEM_CALLBACK_DISPATCHER_H_ diff --git a/chrome/common/file_system/webfilesystem_impl.cc b/chrome/common/file_system/webfilesystem_impl.cc index 546ed25..b7940c8 100644 --- a/chrome/common/file_system/webfilesystem_impl.cc +++ b/chrome/common/file_system/webfilesystem_impl.cc @@ -5,6 +5,7 @@ #include "chrome/common/file_system/webfilesystem_impl.h" #include "chrome/common/file_system/file_system_dispatcher.h" +#include "chrome/common/file_system/webfilesystem_callback_dispatcher.h" #include "chrome/common/child_thread.h" #include "third_party/WebKit/WebKit/chromium/public/WebFileInfo.h" #include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h" @@ -17,76 +18,6 @@ using WebKit::WebFileSystemEntry; using WebKit::WebString; using WebKit::WebVector; -namespace { - -WebKit::WebFileError PlatformFileErrorToWebFileError( - base::PlatformFileError error_code) { - switch (error_code) { - 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; - case base::PLATFORM_FILE_ERROR_FAILED: - return WebKit::WebFileErrorInvalidState; - case base::PLATFORM_FILE_ERROR_ABORT: - return WebKit::WebFileErrorAbort; - default: - return WebKit::WebFileErrorInvalidModification; - } -} - -class WebFileSystemCallbackDispatcherImpl - : public fileapi::FileSystemCallbackDispatcher { - public: - explicit WebFileSystemCallbackDispatcherImpl( - WebFileSystemCallbacks* callbacks) - : callbacks_(callbacks) { - DCHECK(callbacks_); - } - - virtual ~WebFileSystemCallbackDispatcherImpl() { - } - - // FileSystemCallbackDispatcher implementation - virtual void DidSucceed() { - callbacks_->didSucceed(); - } - - virtual void DidReadMetadata(const base::PlatformFileInfo& file_info) { - WebFileInfo web_file_info; - web_file_info.modificationTime = file_info.last_modified.ToDoubleT(); - callbacks_->didReadMetadata(web_file_info); - } - - virtual void DidReadDirectory( - const std::vector<base::file_util_proxy::Entry>& entries, bool has_more) { - WebVector<WebFileSystemEntry> file_system_entries(entries.size()); - for (size_t i = 0; i < entries.size(); i++) { - file_system_entries[i].name = - webkit_glue::FilePathStringToWebString(entries[i].name); - file_system_entries[i].isDirectory = entries[i].is_directory; - } - callbacks_->didReadDirectory(file_system_entries, has_more); - } - - virtual void DidOpenFileSystem(const string16&, const FilePath&) { - NOTREACHED(); - } - - virtual void DidFail(base::PlatformFileError error_code) { - callbacks_->didFail(PlatformFileErrorToWebFileError(error_code)); - } - - private: - WebFileSystemCallbacks* callbacks_; -}; - -} // namespace - WebFileSystemImpl::WebFileSystemImpl() { } @@ -97,7 +28,7 @@ void WebFileSystemImpl::move(const WebString& src_path, ChildThread::current()->file_system_dispatcher(); dispatcher->Move(webkit_glue::WebStringToFilePath(src_path), webkit_glue::WebStringToFilePath(dest_path), - new WebFileSystemCallbackDispatcherImpl(callbacks)); + new WebFileSystemCallbackDispatcher(callbacks)); } void WebFileSystemImpl::copy(const WebString& src_path, @@ -107,7 +38,7 @@ void WebFileSystemImpl::copy(const WebString& src_path, ChildThread::current()->file_system_dispatcher(); dispatcher->Copy(webkit_glue::WebStringToFilePath(src_path), webkit_glue::WebStringToFilePath(dest_path), - new WebFileSystemCallbackDispatcherImpl(callbacks)); + new WebFileSystemCallbackDispatcher(callbacks)); } void WebFileSystemImpl::remove(const WebString& path, @@ -115,7 +46,7 @@ void WebFileSystemImpl::remove(const WebString& path, FileSystemDispatcher* dispatcher = ChildThread::current()->file_system_dispatcher(); dispatcher->Remove(webkit_glue::WebStringToFilePath(path), - new WebFileSystemCallbackDispatcherImpl(callbacks)); + new WebFileSystemCallbackDispatcher(callbacks)); } void WebFileSystemImpl::readMetadata(const WebString& path, @@ -123,7 +54,7 @@ void WebFileSystemImpl::readMetadata(const WebString& path, FileSystemDispatcher* dispatcher = ChildThread::current()->file_system_dispatcher(); dispatcher->ReadMetadata(webkit_glue::WebStringToFilePath(path), - new WebFileSystemCallbackDispatcherImpl(callbacks)); + new WebFileSystemCallbackDispatcher(callbacks)); } void WebFileSystemImpl::createFile(const WebString& path, @@ -132,7 +63,7 @@ void WebFileSystemImpl::createFile(const WebString& path, FileSystemDispatcher* dispatcher = ChildThread::current()->file_system_dispatcher(); dispatcher->Create(webkit_glue::WebStringToFilePath(path), exclusive, false, - false, new WebFileSystemCallbackDispatcherImpl(callbacks)); + false, new WebFileSystemCallbackDispatcher(callbacks)); } void WebFileSystemImpl::createDirectory(const WebString& path, @@ -141,7 +72,7 @@ void WebFileSystemImpl::createDirectory(const WebString& path, FileSystemDispatcher* dispatcher = ChildThread::current()->file_system_dispatcher(); dispatcher->Create(webkit_glue::WebStringToFilePath(path), exclusive, true, - false, new WebFileSystemCallbackDispatcherImpl(callbacks)); + false, new WebFileSystemCallbackDispatcher(callbacks)); } void WebFileSystemImpl::fileExists(const WebString& path, @@ -149,7 +80,7 @@ void WebFileSystemImpl::fileExists(const WebString& path, FileSystemDispatcher* dispatcher = ChildThread::current()->file_system_dispatcher(); dispatcher->Exists(webkit_glue::WebStringToFilePath(path), false, - new WebFileSystemCallbackDispatcherImpl(callbacks)); + new WebFileSystemCallbackDispatcher(callbacks)); } void WebFileSystemImpl::directoryExists(const WebString& path, @@ -157,7 +88,7 @@ void WebFileSystemImpl::directoryExists(const WebString& path, FileSystemDispatcher* dispatcher = ChildThread::current()->file_system_dispatcher(); dispatcher->Exists(webkit_glue::WebStringToFilePath(path), true, - new WebFileSystemCallbackDispatcherImpl(callbacks)); + new WebFileSystemCallbackDispatcher(callbacks)); } void WebFileSystemImpl::readDirectory(const WebString& path, @@ -165,5 +96,5 @@ void WebFileSystemImpl::readDirectory(const WebString& path, FileSystemDispatcher* dispatcher = ChildThread::current()->file_system_dispatcher(); dispatcher->ReadDirectory(webkit_glue::WebStringToFilePath(path), - new WebFileSystemCallbackDispatcherImpl(callbacks)); + new WebFileSystemCallbackDispatcher(callbacks)); } diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index 2b810af..a32d1c8 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -29,6 +29,7 @@ #include "ipc/ipc_platform_file.h" // ifdefed typedef. #include "third_party/WebKit/WebKit/chromium/public/WebStorageArea.h" #include "webkit/appcache/appcache_interfaces.h" // enum appcache::Status +#include "webkit/fileapi/file_system_types.h" // enum fileapi::FileSystemType #include "webkit/glue/resource_loader_bridge.h" // nested classes #if defined(OS_MACOSX) @@ -106,7 +107,6 @@ struct ViewMsg_ExtensionRendererInfo; struct ViewMsg_ExtensionsUpdated_Params; struct ViewMsg_DeviceOrientationUpdated_Params; struct ViewHostMsg_DomMessage_Params; -struct ViewHostMsg_OpenFileSystemRequest_Params; struct ViewHostMsg_AccessibilityNotification_Params; // Values that may be OR'd together to form the 'flags' parameter of the @@ -742,6 +742,11 @@ struct SimilarTypeTraits<base::PlatformFileError> { typedef int Type; }; +template <> +struct SimilarTypeTraits<fileapi::FileSystemType> { + typedef int Type; +}; + } // namespace IPC #define MESSAGES_INTERNAL_FILE "chrome/common/render_messages_internal.h" diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index b5de540..bc5f1f3 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -1029,11 +1029,11 @@ IPC_BEGIN_MESSAGES(View) ViewMsg_DeviceOrientationUpdated_Params) // WebFrameClient::openFileSystem response messages. - IPC_MESSAGE_ROUTED4(ViewMsg_OpenFileSystemRequest_Complete, - int /* request_id */, - bool /* accepted */, - string16 /* name */, - string16 /* root_path */) + IPC_MESSAGE_CONTROL4(ViewMsg_OpenFileSystemRequest_Complete, + int /* request_id */, + bool /* accepted */, + std::string /* name */, + FilePath /* root_path */) // WebFileSystem response messages. IPC_MESSAGE_CONTROL1(ViewMsg_FileSystem_DidSucceed, @@ -2797,8 +2797,11 @@ IPC_BEGIN_MESSAGES(ViewHost) // These are messages sent from the renderer to the browser process. // WebFrameClient::openFileSystem() message. - IPC_MESSAGE_CONTROL1(ViewHostMsg_OpenFileSystemRequest, - ViewHostMsg_OpenFileSystemRequest_Params) + IPC_MESSAGE_CONTROL4(ViewHostMsg_OpenFileSystemRequest, + int /* request_id */, + GURL /* origin_url */, + fileapi::FileSystemType /* type */, + int64 /* requested_size */) // WebFileSystem::move() message. IPC_MESSAGE_CONTROL3(ViewHostMsg_FileSystem_Move, diff --git a/chrome/common/render_messages_params.cc b/chrome/common/render_messages_params.cc index bcd47f6..4b28b3d 100644 --- a/chrome/common/render_messages_params.cc +++ b/chrome/common/render_messages_params.cc @@ -302,18 +302,6 @@ ViewHostMsg_DomMessage_Params::ViewHostMsg_DomMessage_Params() ViewHostMsg_DomMessage_Params::~ViewHostMsg_DomMessage_Params() { } -ViewHostMsg_OpenFileSystemRequest_Params:: - ViewHostMsg_OpenFileSystemRequest_Params() - : routing_id(0), - request_id(0), - type(WebKit::WebFileSystem::TypeTemporary), - requested_size(0) { -} - -ViewHostMsg_OpenFileSystemRequest_Params:: - ~ViewHostMsg_OpenFileSystemRequest_Params() { -} - namespace IPC { // Self contained templates which are only used inside serializing Params @@ -1800,44 +1788,6 @@ void ParamTraits<ViewHostMsg_DomMessage_Params>::Log(const param_type& p, l->append(")"); } -void ParamTraits<ViewHostMsg_OpenFileSystemRequest_Params>::Write( - Message* m, - const param_type& p) { - WriteParam(m, p.routing_id); - WriteParam(m, p.request_id); - WriteParam(m, p.origin_url); - WriteParam(m, p.type); - WriteParam(m, p.requested_size); -} - -bool ParamTraits<ViewHostMsg_OpenFileSystemRequest_Params>::Read( - const Message* m, - void** iter, - param_type* p) { - return - ReadParam(m, iter, &p->routing_id) && - ReadParam(m, iter, &p->request_id) && - ReadParam(m, iter, &p->origin_url) && - ReadParam(m, iter, &p->type) && - ReadParam(m, iter, &p->requested_size); -} - -void ParamTraits<ViewHostMsg_OpenFileSystemRequest_Params>::Log( - const param_type& p, - std::string* l) { - l->append("("); - LogParam(p.routing_id, l); - l->append(", "); - LogParam(p.request_id, l); - l->append(", "); - LogParam(p.origin_url, l); - l->append(", "); - LogParam(p.type, l); - l->append(", "); - LogParam(p.requested_size, l); - l->append(")"); -} - void ParamTraits<base::file_util_proxy::Entry>::Write( Message* m, const param_type& p) { diff --git a/chrome/common/render_messages_params.h b/chrome/common/render_messages_params.h index 8cb9d93..5c2b0d1 100644 --- a/chrome/common/render_messages_params.h +++ b/chrome/common/render_messages_params.h @@ -30,7 +30,6 @@ #include "googleurl/src/gurl.h" #include "ipc/ipc_param_traits.h" #include "media/audio/audio_parameters.h" -#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" #include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h" #include "webkit/glue/password_form.h" #include "webkit/glue/plugins/webplugin.h" @@ -969,26 +968,6 @@ struct ViewHostMsg_DomMessage_Params { bool user_gesture; }; -struct ViewHostMsg_OpenFileSystemRequest_Params { - ViewHostMsg_OpenFileSystemRequest_Params(); - ~ViewHostMsg_OpenFileSystemRequest_Params(); - - // The routing ID of the view initiating the request. - int routing_id; - - // The response should have this id. - int request_id; - - // The origin doing the initiating. - GURL origin_url; - - // The requested FileSystem type. - WebKit::WebFileSystem::Type type; - - // Indicates how much storage space (in bytes) the caller expects to need. - int64 requested_size; -}; - struct ViewHostMsg_AccessibilityNotification_Params { enum NotificationType { // The node checked state has changed. @@ -1276,14 +1255,6 @@ struct ParamTraits<ViewHostMsg_DomMessage_Params> { }; template <> -struct ParamTraits<ViewHostMsg_OpenFileSystemRequest_Params> { - typedef ViewHostMsg_OpenFileSystemRequest_Params param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, void** iter, param_type* p); - static void Log(const param_type& p, std::string* l); -}; - -template <> struct ParamTraits<base::file_util_proxy::Entry> { typedef base::file_util_proxy::Entry param_type; static void Write(Message* m, const param_type& p); diff --git a/chrome/common/webkit_param_traits.h b/chrome/common/webkit_param_traits.h index dccf1c5..6014f25 100644 --- a/chrome/common/webkit_param_traits.h +++ b/chrome/common/webkit_param_traits.h @@ -30,7 +30,6 @@ #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" #include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h" #include "third_party/WebKit/WebKit/chromium/public/WebFileError.h" -#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" #include "third_party/WebKit/WebKit/chromium/public/WebPopupType.h" #include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h" @@ -270,11 +269,6 @@ struct ParamTraits<WebKit::WebTextInputType> { }; template <> -struct SimilarTypeTraits<WebKit::WebFileSystem::Type> { - typedef int Type; -}; - -template <> struct SimilarTypeTraits<WebKit::WebFileError> { typedef int Type; }; diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 3f65c3e..02e67ea 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -31,6 +31,8 @@ #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" +#include "chrome/common/file_system/file_system_dispatcher.h" +#include "chrome/common/file_system/webfilesystem_callback_dispatcher.h" #include "chrome/common/jstemplate_builder.h" #include "chrome/common/notification_service.h" #include "chrome/common/page_zoom.h" @@ -408,17 +410,6 @@ static std::string DetermineTextLanguage(const string16& text) { return language; } -// Holds pending openFileSystem callbacks. -struct RenderView::PendingOpenFileSystem { - explicit PendingOpenFileSystem(WebFileSystemCallbacks* c) : callbacks(c) { - } - ~PendingOpenFileSystem() { - if (callbacks) - callbacks->didFail(WebKit::WebFileErrorAbort); - } - WebFileSystemCallbacks* callbacks; -}; - /////////////////////////////////////////////////////////////////////////////// int32 RenderView::next_page_id_ = 1; @@ -812,8 +803,6 @@ void RenderView::OnMessageReceived(const IPC::Message& message) { OnAccessibilityDoDefaultAction) IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK, OnAccessibilityNotificationsAck) - IPC_MESSAGE_HANDLER(ViewMsg_OpenFileSystemRequest_Complete, - OnOpenFileSystemRequestComplete) IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened) // Have the super handle all other messages. @@ -3508,21 +3497,18 @@ void RenderView::openFileSystem( WebFileSystem::Type type, long long size, WebFileSystemCallbacks* callbacks) { - scoped_ptr<PendingOpenFileSystem> request( - new PendingOpenFileSystem(callbacks)); + DCHECK(callbacks); WebSecurityOrigin origin = frame->securityOrigin(); - if (origin.isEmpty()) - return; // Uninitialized document? - - ViewHostMsg_OpenFileSystemRequest_Params params; - params.routing_id = routing_id_; - params.request_id = pending_file_system_requests_.Add(request.release()); - params.origin_url = GURL(origin.toString()); - params.type = type; - params.requested_size = size; + if (origin.isEmpty()) { + // Uninitialized document? + callbacks->didFail(WebKit::WebFileErrorAbort); + return; + } - Send(new ViewHostMsg_OpenFileSystemRequest(params)); + ChildThread::current()->file_system_dispatcher()->OpenFileSystem( + GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type), + size, new WebFileSystemCallbackDispatcher(callbacks)); } // webkit_glue::WebPluginPageDelegate ----------------------------------------- @@ -5836,20 +5822,6 @@ bool RenderView::IsNonLocalTopLevelNavigation( return false; } -void RenderView::OnOpenFileSystemRequestComplete( - int request_id, bool accepted, const string16& name, - const string16& root_path) { - PendingOpenFileSystem* request = pending_file_system_requests_.Lookup( - request_id); - DCHECK(request); - if (accepted) - request->callbacks->didOpenFileSystem(name, root_path); - else - request->callbacks->didFail(WebKit::WebFileErrorSecurity); - request->callbacks = NULL; - pending_file_system_requests_.Remove(request_id); -} - void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code, IPC::PlatformFileForTransit file_for_transit, int message_id) { diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 0826b6c5..4fe4c3b 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -16,7 +16,6 @@ #include "app/surface/transport_dib.h" #include "base/basictypes.h" #include "base/gtest_prod_util.h" -#include "base/id_map.h" #include "base/linked_ptr.h" #include "base/timer.h" #include "base/weak_ptr.h" @@ -818,10 +817,6 @@ class RenderView : public RenderWidget, void OnNotifyRendererViewType(ViewType::Type view_type); void OnFillPasswordForm( const webkit_glue::PasswordFormFillData& form_data); - void OnOpenFileSystemRequestComplete(int request_id, - bool accepted, - const string16& name, - const string16& root_path); void OnPaste(); void OnPrintingDone(int document_cookie, bool success); void OnPrintPages(); @@ -1344,11 +1339,6 @@ class RenderView : public RenderWidget, // External host exposed through automation controller. scoped_ptr<ExternalHostBindings> external_host_bindings_; - // Pending openFileSystem completion objects. - struct PendingOpenFileSystem; - IDMap<PendingOpenFileSystem, IDMapOwnPointer> - pending_file_system_requests_; - // --------------------------------------------------------------------------- // ADDING NEW DATA? Please see if it fits appropriately in one of the above // sections rather than throwing it randomly at the end. If you're adding a diff --git a/chrome/worker/websharedworker_stub.cc b/chrome/worker/websharedworker_stub.cc index 3ddef8d..61ffb31 100644 --- a/chrome/worker/websharedworker_stub.cc +++ b/chrome/worker/websharedworker_stub.cc @@ -4,6 +4,8 @@ #include "chrome/worker/websharedworker_stub.h" +#include "chrome/common/child_thread.h" +#include "chrome/common/file_system/file_system_dispatcher.h" #include "chrome/common/webmessageportchannel_impl.h" #include "chrome/common/worker_messages.h" #include "third_party/WebKit/WebKit/chromium/public/WebSharedWorker.h" @@ -46,6 +48,7 @@ void WebSharedWorkerStub::OnStartWorkerContext( impl_->startWorkerContext(url, name_, user_agent, source_code, 0); started_ = true; + url_ = url; // Process any pending connections. for (PendingConnectInfoList::const_iterator iter = pending_connects_.begin(); diff --git a/chrome/worker/websharedworker_stub.h b/chrome/worker/websharedworker_stub.h index e346bda..157dadb 100644 --- a/chrome/worker/websharedworker_stub.h +++ b/chrome/worker/websharedworker_stub.h @@ -25,10 +25,11 @@ class WebSharedWorkerStub : public WebWorkerStubBase { virtual void OnMessageReceived(const IPC::Message& message); virtual void OnChannelError(); + virtual const GURL& url() const { return url_; } + private: virtual ~WebSharedWorkerStub(); - // Invoked when the WebWorkerClientProxy is shutting down. void OnConnect(int sent_message_port_id, int routing_id); void OnStartWorkerContext( const GURL& url, const string16& user_agent, const string16& source_code); @@ -37,6 +38,7 @@ class WebSharedWorkerStub : public WebWorkerStubBase { WebKit::WebSharedWorker* impl_; string16 name_; bool started_; + GURL url_; typedef std::pair<int, int> PendingConnectInfo; typedef std::vector<PendingConnectInfo> PendingConnectInfoList; diff --git a/chrome/worker/webworker_stub.cc b/chrome/worker/webworker_stub.cc index 89cc384..78d980e 100644 --- a/chrome/worker/webworker_stub.cc +++ b/chrome/worker/webworker_stub.cc @@ -5,7 +5,9 @@ #include "chrome/worker/webworker_stub.h" #include "base/command_line.h" +#include "chrome/common/child_thread.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/file_system/file_system_dispatcher.h" #include "chrome/common/webmessageportchannel_impl.h" #include "chrome/common/worker_messages.h" #include "chrome/worker/nativewebworker_impl.h" @@ -35,7 +37,8 @@ static bool UrlIsNativeWorker(const GURL& url) { WebWorkerStub::WebWorkerStub(const GURL& url, int route_id, const WorkerAppCacheInitInfo& appcache_init_info) - : WebWorkerStubBase(route_id, appcache_init_info) { + : WebWorkerStubBase(route_id, appcache_init_info), + url_(url) { if (UrlIsNativeWorker(url)) { // Launch a native worker. impl_ = NativeWebWorkerImpl::create(client()); diff --git a/chrome/worker/webworker_stub.h b/chrome/worker/webworker_stub.h index 4731588..584abce 100644 --- a/chrome/worker/webworker_stub.h +++ b/chrome/worker/webworker_stub.h @@ -25,6 +25,8 @@ class WebWorkerStub : public WebWorkerStubBase { virtual void OnMessageReceived(const IPC::Message& message); virtual void OnChannelError(); + virtual const GURL& url() const { return url_; } + private: virtual ~WebWorkerStub(); @@ -34,6 +36,7 @@ class WebWorkerStub : public WebWorkerStubBase { const std::vector<int>& new_routing_ids); WebKit::WebWorker* impl_; + GURL url_; DISALLOW_COPY_AND_ASSIGN(WebWorkerStub); }; diff --git a/chrome/worker/webworker_stub_base.h b/chrome/worker/webworker_stub_base.h index d3d44be..2ab2ac7 100644 --- a/chrome/worker/webworker_stub_base.h +++ b/chrome/worker/webworker_stub_base.h @@ -6,6 +6,7 @@ #define CHROME_WORKER_WEBWORKER_STUB_BASE_H_ #pragma once +#include "base/scoped_ptr.h" #include "chrome/worker/webworkerclient_proxy.h" #include "chrome/worker/worker_webapplicationcachehost_impl.h" #include "ipc/ipc_channel.h" @@ -30,6 +31,10 @@ class WebWorkerStubBase : public IPC::Channel::Listener { const WorkerAppCacheInitInfo& appcache_init_info() const { return appcache_init_info_; } + + // Returns the script url of this worker. + virtual const GURL& url() const = 0; + private: int route_id_; WorkerAppCacheInitInfo appcache_init_info_; diff --git a/chrome/worker/webworkerclient_proxy.cc b/chrome/worker/webworkerclient_proxy.cc index d591de5..e2ecf5a 100644 --- a/chrome/worker/webworkerclient_proxy.cc +++ b/chrome/worker/webworkerclient_proxy.cc @@ -7,6 +7,8 @@ #include "base/command_line.h" #include "base/message_loop.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/file_system/file_system_dispatcher.h" +#include "chrome/common/file_system/webfilesystem_callback_dispatcher.h" #include "chrome/common/webmessageportchannel_impl.h" #include "chrome/common/worker_messages.h" #include "chrome/renderer/webworker_proxy.h" @@ -14,6 +16,7 @@ #include "chrome/worker/worker_thread.h" #include "chrome/worker/worker_webapplicationcachehost_impl.h" #include "ipc/ipc_logging.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h" #include "third_party/WebKit/WebKit/chromium/public/WebString.h" #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" #include "third_party/WebKit/WebKit/chromium/public/WebWorker.h" @@ -121,6 +124,15 @@ WebApplicationCacheHost* WebWorkerClientProxy::createApplicationCacheHost( return host; } +void WebWorkerClientProxy::openFileSystem( + WebKit::WebFileSystem::Type type, + long long size, + WebKit::WebFileSystemCallbacks* callbacks) { + ChildThread::current()->file_system_dispatcher()->OpenFileSystem( + stub_->url().GetOrigin(), static_cast<fileapi::FileSystemType>(type), + size, new WebFileSystemCallbackDispatcher(callbacks)); +} + bool WebWorkerClientProxy::Send(IPC::Message* message) { return WorkerThread::current()->Send(message); } @@ -144,4 +156,3 @@ void WebWorkerClientProxy::EnsureWorkerContextTerminates() { &WebWorkerClientProxy::workerContextDestroyed), kMaxTimeForRunawayWorkerMs); } - diff --git a/chrome/worker/webworkerclient_proxy.h b/chrome/worker/webworkerclient_proxy.h index 28a662c..8b19688 100644 --- a/chrome/worker/webworkerclient_proxy.h +++ b/chrome/worker/webworkerclient_proxy.h @@ -9,6 +9,7 @@ #include "base/basictypes.h" #include "base/task.h" #include "ipc/ipc_channel.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" #include "third_party/WebKit/WebKit/chromium/public/WebWorkerClient.h" namespace WebKit { @@ -82,6 +83,10 @@ class WebWorkerClientProxy : public WebKit::WebWorkerClient { return true; } + virtual void openFileSystem(WebKit::WebFileSystem::Type type, + long long size, + WebKit::WebFileSystemCallbacks* callbacks); + void EnsureWorkerContextTerminates(); private: diff --git a/chrome/worker/worker_thread.cc b/chrome/worker/worker_thread.cc index c493701..4a8ec52 100644 --- a/chrome/worker/worker_thread.cc +++ b/chrome/worker/worker_thread.cc @@ -55,6 +55,9 @@ WorkerThread::WorkerThread() { WebRuntimeFeatures::enableSockets( !command_line.HasSwitch(switches::kDisableWebSockets)); + + WebRuntimeFeatures::enableFileSystem( + command_line.HasSwitch(switches::kEnableFileSystem)); } WorkerThread::~WorkerThread() { @@ -111,4 +114,3 @@ void WorkerThread::RemoveWorkerStub(WebWorkerStubBase* stub) { void WorkerThread::AddWorkerStub(WebWorkerStubBase* stub) { worker_stubs_.insert(stub); } - diff --git a/chrome/worker/worker_webkitclient_impl.cc b/chrome/worker/worker_webkitclient_impl.cc index b09ca7b..048bda0 100644 --- a/chrome/worker/worker_webkitclient_impl.cc +++ b/chrome/worker/worker_webkitclient_impl.cc @@ -17,6 +17,7 @@ using WebKit::WebBlobRegistry; using WebKit::WebClipboard; +using WebKit::WebFileSystem; using WebKit::WebKitClient; using WebKit::WebMessagePortChannel; using WebKit::WebMimeRegistry; @@ -35,6 +36,12 @@ WebMimeRegistry* WorkerWebKitClientImpl::mimeRegistry() { return this; } +WebKit::WebFileSystem* WorkerWebKitClientImpl::fileSystem() { + if (!web_file_system_.get()) + web_file_system_.reset(new WebFileSystemImpl()); + return web_file_system_.get(); +} + WebKit::WebFileUtilities* WorkerWebKitClientImpl::fileUtilities() { return &file_utilities_; } diff --git a/chrome/worker/worker_webkitclient_impl.h b/chrome/worker/worker_webkitclient_impl.h index 6488c56..16845ab 100644 --- a/chrome/worker/worker_webkitclient_impl.h +++ b/chrome/worker/worker_webkitclient_impl.h @@ -7,6 +7,7 @@ #pragma once #include "base/scoped_ptr.h" +#include "chrome/common/file_system/webfilesystem_impl.h" #include "third_party/WebKit/WebKit/chromium/public/WebMimeRegistry.h" #include "webkit/glue/webfileutilities_impl.h" #include "webkit/glue/webkitclient_impl.h" @@ -17,6 +18,7 @@ class WorkerWebKitClientImpl : public webkit_glue::WebKitClientImpl, // WebKitClient methods: virtual WebKit::WebClipboard* clipboard(); virtual WebKit::WebMimeRegistry* mimeRegistry(); + virtual WebKit::WebFileSystem* fileSystem(); virtual WebKit::WebFileUtilities* fileUtilities(); virtual WebKit::WebSandboxSupport* sandboxSupport(); virtual bool sandboxEnabled(); @@ -72,6 +74,8 @@ class WorkerWebKitClientImpl : public webkit_glue::WebKitClientImpl, webkit_glue::WebFileUtilitiesImpl file_utilities_; scoped_ptr<WebKit::WebBlobRegistry> blob_registry_; + + scoped_ptr<WebFileSystemImpl> web_file_system_; }; #endif // CHROME_WORKER_WORKER_WEBKITCLIENT_IMPL_H_ |