diff options
author | ericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-16 00:02:53 +0000 |
---|---|---|
committer | ericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-16 00:02:53 +0000 |
commit | 07c3d212963a1638659c4130f05bd5196957b2f6 (patch) | |
tree | f9fcfd54a7e26b443b1b941f80475725cb4d79cd /webkit | |
parent | 5800f19aa9967928eca31752678ac7d8e4e0cd1d (diff) | |
download | chromium_src-07c3d212963a1638659c4130f05bd5196957b2f6.zip chromium_src-07c3d212963a1638659c4130f05bd5196957b2f6.tar.gz chromium_src-07c3d212963a1638659c4130f05bd5196957b2f6.tar.bz2 |
Let Pepper open FileSystem files again.
TEST=none [existing tests, but they're not currently run automatically]
BUG=none
Review URL: http://codereview.chromium.org/6850027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81837 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/fileapi/file_system_callback_dispatcher.h | 11 | ||||
-rw-r--r-- | webkit/fileapi/file_system_operation.cc | 57 | ||||
-rw-r--r-- | webkit/fileapi/file_system_operation.h | 14 | ||||
-rw-r--r-- | webkit/plugins/ppapi/mock_plugin_delegate.cc | 5 | ||||
-rw-r--r-- | webkit/plugins/ppapi/mock_plugin_delegate.h | 3 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_delegate.h | 3 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_file_io_impl.cc | 25 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_file_ref_impl.cc | 4 |
8 files changed, 115 insertions, 7 deletions
diff --git a/webkit/fileapi/file_system_callback_dispatcher.h b/webkit/fileapi/file_system_callback_dispatcher.h index 8504af9..c32e333 100644 --- a/webkit/fileapi/file_system_callback_dispatcher.h +++ b/webkit/fileapi/file_system_callback_dispatcher.h @@ -8,6 +8,9 @@ #include <vector> #include "base/file_util_proxy.h" +#include "base/logging.h" +#include "base/platform_file.h" +#include "base/process.h" class GURL; @@ -50,6 +53,14 @@ class FileSystemCallbackDispatcher { // Callback for FileWriter's write() call. virtual void DidWrite(int64 bytes, bool complete) = 0; + + // Callback for OpenFile. This isn't in WebFileSystemCallbacks, as it's just + // for Pepper. + virtual void DidOpenFile( + base::PlatformFile file, + base::ProcessHandle peer_handle) { + NOTREACHED(); + } }; } // namespace fileapi diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc index 0e258c1..e242e86 100644 --- a/webkit/fileapi/file_system_operation.cc +++ b/webkit/fileapi/file_system_operation.cc @@ -375,6 +375,52 @@ void FileSystemOperation::TouchFile(const GURL& path, callback_factory_.NewCallback(&FileSystemOperation::DidTouchFile)); } +void FileSystemOperation::OpenFile(const GURL& path, + int file_flags, + base::ProcessHandle peer_handle) { +#ifndef NDEBUG + DCHECK(kOperationNone == pending_operation_); + pending_operation_ = kOperationOpenFile; +#endif + + peer_handle_ = peer_handle; + FilePath virtual_path; + GURL origin_url; + FileSystemType type; + if (file_flags & ( + (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | + base::PLATFORM_FILE_HIDDEN))) { + delete this; + return; + } + if (file_flags & + (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | + base::PLATFORM_FILE_CREATE_ALWAYS | + base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | + base::PLATFORM_FILE_DELETE_ON_CLOSE | base::PLATFORM_FILE_TRUNCATE | + base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { + if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, + &type, &virtual_path)) { + delete this; + return; + } + } else { + if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path)) { + delete this; + return; + } + } + file_system_operation_context_.set_src_origin_url(origin_url); + file_system_operation_context_.set_src_type(type); + FileSystemFileUtilProxy::CreateOrOpen( + file_system_operation_context_, + proxy_, + virtual_path, + file_flags, + callback_factory_.NewCallback( + &FileSystemOperation::DidOpenFile)); +} + // We can only get here on a write or truncate that's not yet completed. // We don't support cancelling any other operation at this time. void FileSystemOperation::Cancel(FileSystemOperation* cancel_operation_ptr) { @@ -527,6 +573,17 @@ void FileSystemOperation::DidTouchFile(base::PlatformFileError rv) { delete this; } +void FileSystemOperation::DidOpenFile( + base::PlatformFileError rv, + base::PassPlatformFile file, + bool unused) { + if (rv == base::PLATFORM_FILE_OK) + dispatcher_->DidOpenFile(file.ReleaseValue(), peer_handle_); + else + dispatcher_->DidFail(rv); + delete this; +} + void FileSystemOperation::OnFileOpenedForWrite( base::PlatformFileError rv, base::PassPlatformFile file, diff --git a/webkit/fileapi/file_system_operation.h b/webkit/fileapi/file_system_operation.h index 8ca3be5..c726403 100644 --- a/webkit/fileapi/file_system_operation.h +++ b/webkit/fileapi/file_system_operation.h @@ -15,6 +15,7 @@ #include "base/memory/scoped_ptr.h" #include "base/message_loop_proxy.h" #include "base/platform_file.h" +#include "base/process.h" #include "googleurl/src/gurl.h" #include "webkit/fileapi/file_system_types.h" #include "webkit/fileapi/file_system_operation_context.h" @@ -79,6 +80,10 @@ class FileSystemOperation { void TouchFile(const GURL& path, const base::Time& last_access_time, const base::Time& last_modified_time); + void OpenFile( + const GURL& path, + int file_flags, + base::ProcessHandle peer_handle); // Try to cancel the current operation [we support cancelling write or // truncate only]. Report failure for the current operation, then tell the @@ -129,6 +134,10 @@ class FileSystemOperation { int64 bytes, bool complete); void DidTouchFile(base::PlatformFileError rv); + void DidOpenFile( + base::PlatformFileError rv, + base::PassPlatformFile file, + bool created); // Helper for Write(). void OnFileOpenedForWrite( @@ -184,6 +193,7 @@ class FileSystemOperation { kOperationWrite, kOperationTruncate, kOperationTouchFile, + kOperationOpenFile, kOperationCancel, }; @@ -206,6 +216,10 @@ class FileSystemOperation { scoped_ptr<net::URLRequest> blob_request_; scoped_ptr<FileSystemOperation> cancel_operation_; + // Used only by OpenFile, in order to clone the file handle back to the + // requesting process. + base::ProcessHandle peer_handle_; + DISALLOW_COPY_AND_ASSIGN(FileSystemOperation); }; diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc index a893956..b0185ab 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.cc +++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc @@ -77,6 +77,11 @@ bool MockPluginDelegate::AsyncOpenFile(const FilePath& path, return false; } +bool MockPluginDelegate::AsyncOpenFileSystemURL( + const GURL& path, int flags, AsyncOpenFileCallback* callback) { + return false; +} + bool MockPluginDelegate::OpenFileSystem( const GURL& url, fileapi::FileSystemType type, diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h index 557d7f3..98f769f 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.h +++ b/webkit/plugins/ppapi/mock_plugin_delegate.h @@ -37,6 +37,9 @@ class MockPluginDelegate : public PluginDelegate { virtual bool AsyncOpenFile(const FilePath& path, int flags, AsyncOpenFileCallback* callback); + virtual bool AsyncOpenFileSystemURL(const GURL& path, + int flags, + AsyncOpenFileCallback* callback); virtual bool OpenFileSystem( const GURL& url, fileapi::FileSystemType type, diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h index 68a6471..212889a 100644 --- a/webkit/plugins/ppapi/plugin_delegate.h +++ b/webkit/plugins/ppapi/plugin_delegate.h @@ -284,6 +284,9 @@ class PluginDelegate { virtual bool AsyncOpenFile(const FilePath& path, int flags, AsyncOpenFileCallback* callback) = 0; + virtual bool AsyncOpenFileSystemURL(const GURL& path, + int flags, + AsyncOpenFileCallback* callback) = 0; virtual bool OpenFileSystem( const GURL& url, diff --git a/webkit/plugins/ppapi/ppb_file_io_impl.cc b/webkit/plugins/ppapi/ppb_file_io_impl.cc index 624ced4..20a95db 100644 --- a/webkit/plugins/ppapi/ppb_file_io_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_io_impl.cc @@ -253,13 +253,26 @@ int32_t PPB_FileIO_Impl::Open(PPB_FileRef_Impl* file_ref, } else { flags |= base::PLATFORM_FILE_OPEN; } - file_system_type_ = file_ref->GetFileSystemType(); - if (!instance()->delegate()->AsyncOpenFile( - file_ref->GetSystemPath(), flags, - callback_factory_.NewCallback( - &PPB_FileIO_Impl::AsyncOpenFileCallback))) - return PP_ERROR_FAILED; + switch (file_system_type_) { + case PP_FILESYSTEMTYPE_EXTERNAL: + if (!instance()->delegate()->AsyncOpenFile( + file_ref->GetSystemPath(), flags, + callback_factory_.NewCallback( + &PPB_FileIO_Impl::AsyncOpenFileCallback))) + return PP_ERROR_FAILED; + break; + case PP_FILESYSTEMTYPE_LOCALPERSISTENT: + case PP_FILESYSTEMTYPE_LOCALTEMPORARY: + if (!instance()->delegate()->AsyncOpenFileSystemURL( + file_ref->GetFileSystemURL(), flags, + callback_factory_.NewCallback( + &PPB_FileIO_Impl::AsyncOpenFileCallback))) + return PP_ERROR_FAILED; + break; + default: + return PP_ERROR_FAILED; + } RegisterCallback(callback); return PP_OK_COMPLETIONPENDING; diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.cc b/webkit/plugins/ppapi/ppb_file_ref_impl.cc index b048caf..8ab57e7 100644 --- a/webkit/plugins/ppapi/ppb_file_ref_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_ref_impl.cc @@ -340,7 +340,9 @@ GURL PPB_FileRef_Impl::GetFileSystemURL() const { // Since |virtual_path_| starts with a '/', it looks like an absolute path. // We need to trim off the '/' before calling Resolve, as FileSystem URLs // start with a storage type identifier that looks like a path segment. - return file_system_->root_url().Resolve(virtual_path_.substr(1)); + // TODO(ericu): Switch this to use Resolve after fixing GURL to understand + // FileSystem URLs. + return GURL(file_system_->root_url().spec() + virtual_path_.substr(1)); } } // namespace ppapi |