diff options
-rw-r--r-- | chrome/renderer/pepper_plugin_delegate_impl.cc | 50 | ||||
-rw-r--r-- | chrome/renderer/pepper_plugin_delegate_impl.h | 14 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_error_util.cc | 32 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_error_util.h | 16 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_file_system.cc | 214 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_file_system.h | 5 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_plugin_delegate.h | 20 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 2 |
8 files changed, 341 insertions, 12 deletions
diff --git a/chrome/renderer/pepper_plugin_delegate_impl.cc b/chrome/renderer/pepper_plugin_delegate_impl.cc index 31b89ff..0577cfd0 100644 --- a/chrome/renderer/pepper_plugin_delegate_impl.cc +++ b/chrome/renderer/pepper_plugin_delegate_impl.cc @@ -10,6 +10,9 @@ #include "base/logging.h" #include "base/scoped_ptr.h" #include "base/task.h" +#include "base/time.h" +#include "chrome/common/child_thread.h" +#include "chrome/common/file_system/file_system_dispatcher.h" #include "chrome/common/render_messages.h" #include "chrome/common/render_messages_params.h" #include "chrome/renderer/audio_message_filter.h" @@ -22,6 +25,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserCompletion.h" #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h" #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" +#include "webkit/fileapi/file_system_callback_dispatcher.h" #include "webkit/glue/plugins/pepper_file_io.h" #include "webkit/glue/plugins/pepper_plugin_instance.h" #include "webkit/glue/plugins/webplugin.h" @@ -669,6 +673,52 @@ void PepperPluginDelegateImpl::OnSetFocus(bool has_focus) { (*i)->SetContentAreaFocus(has_focus); } +bool PepperPluginDelegateImpl::MakeDirectory( + const FilePath& path, + bool recursive, + fileapi::FileSystemCallbackDispatcher* dispatcher) { + FileSystemDispatcher* file_system_dispatcher = + ChildThread::current()->file_system_dispatcher(); + return file_system_dispatcher->Create( + path, false, true, recursive, dispatcher); +} + +bool PepperPluginDelegateImpl::Query( + const FilePath& path, + fileapi::FileSystemCallbackDispatcher* dispatcher) { + FileSystemDispatcher* file_system_dispatcher = + ChildThread::current()->file_system_dispatcher(); + return file_system_dispatcher->ReadMetadata(path, dispatcher); +} + +bool PepperPluginDelegateImpl::Touch( + const FilePath& path, + const base::Time& last_access_time, + const base::Time& last_modified_time, + fileapi::FileSystemCallbackDispatcher* dispatcher) { + FileSystemDispatcher* file_system_dispatcher = + ChildThread::current()->file_system_dispatcher(); + return file_system_dispatcher->TouchFile(path, last_access_time, + last_modified_time, dispatcher); +} + +bool PepperPluginDelegateImpl::Delete( + const FilePath& path, + fileapi::FileSystemCallbackDispatcher* dispatcher) { + FileSystemDispatcher* file_system_dispatcher = + ChildThread::current()->file_system_dispatcher(); + return file_system_dispatcher->Remove(path, dispatcher); +} + +bool PepperPluginDelegateImpl::Rename( + const FilePath& file_path, + const FilePath& new_file_path, + fileapi::FileSystemCallbackDispatcher* dispatcher) { + FileSystemDispatcher* file_system_dispatcher = + ChildThread::current()->file_system_dispatcher(); + return file_system_dispatcher->Move(file_path, new_file_path, dispatcher); +} + scoped_refptr<base::MessageLoopProxy> PepperPluginDelegateImpl::GetFileThreadMessageLoopProxy() { return RenderThread::current()->GetFileThreadMessageLoopProxy(); diff --git a/chrome/renderer/pepper_plugin_delegate_impl.h b/chrome/renderer/pepper_plugin_delegate_impl.h index 8bacb44..b3b5b76 100644 --- a/chrome/renderer/pepper_plugin_delegate_impl.h +++ b/chrome/renderer/pepper_plugin_delegate_impl.h @@ -85,6 +85,20 @@ class PepperPluginDelegateImpl virtual bool AsyncOpenFile(const FilePath& path, int flags, AsyncOpenFileCallback* callback); + virtual bool MakeDirectory(const FilePath& path, + bool recursive, + fileapi::FileSystemCallbackDispatcher* dispatcher); + virtual bool Query(const FilePath& path, + fileapi::FileSystemCallbackDispatcher* dispatcher); + virtual bool Touch(const FilePath& path, + const base::Time& last_access_time, + const base::Time& last_modified_time, + fileapi::FileSystemCallbackDispatcher* dispatcher); + virtual bool Delete(const FilePath& path, + fileapi::FileSystemCallbackDispatcher* dispatcher); + virtual bool Rename(const FilePath& file_path, + const FilePath& new_file_path, + fileapi::FileSystemCallbackDispatcher* dispatcher); virtual scoped_refptr<base::MessageLoopProxy> GetFileThreadMessageLoopProxy(); virtual pepper::FullscreenContainer* CreateFullscreenContainer( pepper::PluginInstance* instance); diff --git a/webkit/glue/plugins/pepper_error_util.cc b/webkit/glue/plugins/pepper_error_util.cc new file mode 100644 index 0000000..a1b5c06 --- /dev/null +++ b/webkit/glue/plugins/pepper_error_util.cc @@ -0,0 +1,32 @@ +// 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/glue/plugins/pepper_error_util.h" + +#include "third_party/ppapi/c/pp_errors.h" + +namespace pepper { + +int PlatformFileErrorToPepperError(base::PlatformFileError error_code) { + switch (error_code) { + case base::PLATFORM_FILE_OK: + return PP_OK; + case base::PLATFORM_FILE_ERROR_EXISTS: + return PP_ERROR_FILEEXISTS; + case base::PLATFORM_FILE_ERROR_NOT_FOUND: + return PP_ERROR_FILENOTFOUND; + case base::PLATFORM_FILE_ERROR_ACCESS_DENIED: + return PP_ERROR_NOACCESS; + case base::PLATFORM_FILE_ERROR_NO_MEMORY: + return PP_ERROR_NOMEMORY; + case base::PLATFORM_FILE_ERROR_NO_SPACE: + return PP_ERROR_NOSPACE; + case base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY: + return PP_ERROR_FAILED; + default: + return PP_ERROR_FAILED; + } +} + +} // namespace pepper diff --git a/webkit/glue/plugins/pepper_error_util.h b/webkit/glue/plugins/pepper_error_util.h new file mode 100644 index 0000000..12e715c --- /dev/null +++ b/webkit/glue/plugins/pepper_error_util.h @@ -0,0 +1,16 @@ +// 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_GLUE_PLUGINS_PEPPER_ERROR_UTIL_H_ +#define WEBKIT_GLUE_PLUGINS_PEPPER_ERROR_UTIL_H_ + +#include "base/platform_file.h" + +namespace pepper { + +int PlatformFileErrorToPepperError(base::PlatformFileError error_code); + +} // namespace pepper + +#endif // WEBKIT_GLUE_PLUGINS_PEPPER_ERROR_UTIL_H_ diff --git a/webkit/glue/plugins/pepper_file_system.cc b/webkit/glue/plugins/pepper_file_system.cc index 475b3e1..82a2fc8 100644 --- a/webkit/glue/plugins/pepper_file_system.cc +++ b/webkit/glue/plugins/pepper_file_system.cc @@ -4,42 +4,232 @@ #include "webkit/glue/plugins/pepper_file_system.h" +#include "base/logging.h" +#include "base/ref_counted.h" +#include "base/weak_ptr.h" #include "third_party/ppapi/c/dev/ppb_file_system_dev.h" #include "third_party/ppapi/c/pp_completion_callback.h" -#include "third_party/ppapi/c/pp_errors.h" +#include "third_party/ppapi/c/pp_time.h" +#include "webkit/fileapi/file_system_callback_dispatcher.h" +#include "webkit/glue/plugins/pepper_resource.h" +#include "webkit/glue/plugins/pepper_error_util.h" +#include "webkit/glue/plugins/pepper_file_ref.h" +#include "webkit/glue/plugins/pepper_plugin_delegate.h" +#include "webkit/glue/plugins/pepper_plugin_instance.h" +#include "webkit/glue/plugins/pepper_plugin_module.h" +#include "webkit/glue/plugins/pepper_resource.h" namespace pepper { namespace { -int32_t MakeDirectory(PP_Resource directory_ref, +// Instances of this class are deleted when RunCallback() is called. +class StatusCallback : public fileapi::FileSystemCallbackDispatcher { + public: + StatusCallback(base::WeakPtr<pepper::PluginModule> module, + PP_CompletionCallback callback) + : module_(module), + callback_(callback) { + } + + // FileSystemCallbackDispatcher implementation. + virtual void DidSucceed() { + RunCallback(base::PLATFORM_FILE_OK); + } + + virtual void DidReadMetadata(const base::PlatformFileInfo&) { + NOTREACHED(); + } + + virtual void DidReadDirectory( + const std::vector<base::file_util_proxy::Entry>&, bool) { + NOTREACHED(); + } + + virtual void DidOpenFileSystem(const std::string&, const FilePath&) { + NOTREACHED(); + } + + virtual void DidFail(base::PlatformFileError error_code) { + RunCallback(error_code); + } + + private: + void RunCallback(base::PlatformFileError error_code) { + if (!module_.get() || !callback_.func) + return; + + PP_RunCompletionCallback( + &callback_, pepper::PlatformFileErrorToPepperError(error_code)); + + delete this; + } + + base::WeakPtr<pepper::PluginModule> module_; + PP_CompletionCallback callback_; +}; + +// Instances of this class are deleted when RunCallback() is called. +class QueryInfoCallback : public fileapi::FileSystemCallbackDispatcher { + public: + QueryInfoCallback(base::WeakPtr<pepper::PluginModule> module, + PP_CompletionCallback callback, + PP_FileInfo_Dev* info, + PP_FileSystemType_Dev file_system_type) + : module_(module), + callback_(callback), + info_(info), + file_system_type_(file_system_type) { + DCHECK(info_); + } + + // FileSystemCallbackDispatcher implementation. + virtual void DidSucceed() { + NOTREACHED(); + } + + virtual void DidReadMetadata(const base::PlatformFileInfo& file_info) { + RunCallback(base::PLATFORM_FILE_OK, file_info); + } + + virtual void DidReadDirectory( + const std::vector<base::file_util_proxy::Entry>&, bool) { + NOTREACHED(); + } + + virtual void DidOpenFileSystem(const std::string&, const FilePath&) { + NOTREACHED(); + } + + virtual void DidFail(base::PlatformFileError error_code) { + RunCallback(error_code, base::PlatformFileInfo()); + } + + private: + void RunCallback(base::PlatformFileError error_code, + const base::PlatformFileInfo& file_info) { + if (!module_.get() || !callback_.func) + return; + + if (error_code == base::PLATFORM_FILE_OK) { + info_->size = file_info.size; + info_->creation_time = file_info.creation_time.ToDoubleT(); + info_->last_access_time = file_info.last_accessed.ToDoubleT(); + info_->last_modified_time = file_info.last_modified.ToDoubleT(); + info_->system_type = file_system_type_; + if (file_info.is_directory) + info_->type = PP_FILETYPE_DIRECTORY; + else + info_->type = PP_FILETYPE_REGULAR; + } + PP_RunCompletionCallback( + &callback_, pepper::PlatformFileErrorToPepperError(error_code)); + + delete this; + } + + base::WeakPtr<pepper::PluginModule> module_; + PP_CompletionCallback callback_; + PP_FileInfo_Dev* info_; + PP_FileSystemType_Dev file_system_type_; +}; + +int32_t MakeDirectory(PP_Resource directory_ref_id, bool make_ancestors, PP_CompletionCallback callback) { - return PP_ERROR_FAILED; // TODO(darin): Implement me! + scoped_refptr<FileRef> directory_ref( + Resource::GetAs<FileRef>(directory_ref_id)); + if (!directory_ref) + return PP_ERROR_BADRESOURCE; + + if (directory_ref->file_system_type() == PP_FILESYSTEMTYPE_EXTERNAL) + return PP_ERROR_FAILED; + + PluginModule* module = directory_ref->module(); + if (!module->GetSomeInstance()->delegate()->MakeDirectory( + directory_ref->system_path(), make_ancestors, + new StatusCallback(module->AsWeakPtr(), callback))) + return PP_ERROR_FAILED; + + return PP_ERROR_WOULDBLOCK; } -int32_t Query(PP_Resource file_ref, +int32_t Query(PP_Resource file_ref_id, PP_FileInfo_Dev* info, PP_CompletionCallback callback) { - return PP_ERROR_FAILED; // TODO(darin): Implement me! + scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); + if (!file_ref) + return PP_ERROR_BADRESOURCE; + + PluginModule* module = file_ref->module(); + if (!module->GetSomeInstance()->delegate()->Query( + file_ref->system_path(), + new QueryInfoCallback(module->AsWeakPtr(), callback, + info, file_ref->file_system_type()))) + return PP_ERROR_FAILED; + + return PP_ERROR_WOULDBLOCK; } -int32_t Touch(PP_Resource file_ref, +int32_t Touch(PP_Resource file_ref_id, PP_Time last_access_time, PP_Time last_modified_time, PP_CompletionCallback callback) { - return PP_ERROR_FAILED; // TODO(darin): Implement me! + scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); + if (!file_ref) + return PP_ERROR_BADRESOURCE; + + PluginModule* module = file_ref->module(); + if (!module->GetSomeInstance()->delegate()->Touch( + file_ref->system_path(), base::Time::FromDoubleT(last_access_time), + base::Time::FromDoubleT(last_modified_time), + new StatusCallback(module->AsWeakPtr(), callback))) + return PP_ERROR_FAILED; + + return PP_ERROR_WOULDBLOCK; } -int32_t Delete(PP_Resource file_ref, +int32_t Delete(PP_Resource file_ref_id, PP_CompletionCallback callback) { - return PP_ERROR_FAILED; // TODO(darin): Implement me! + scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); + if (!file_ref) + return PP_ERROR_BADRESOURCE; + + if (file_ref->file_system_type() == PP_FILESYSTEMTYPE_EXTERNAL) + return PP_ERROR_FAILED; + + PluginModule* module = file_ref->module(); + if (!module->GetSomeInstance()->delegate()->Delete( + file_ref->system_path(), + new StatusCallback(module->AsWeakPtr(), callback))) + return PP_ERROR_FAILED; + + return PP_ERROR_WOULDBLOCK; } -int32_t Rename(PP_Resource file_ref, - PP_Resource new_file_ref, +int32_t Rename(PP_Resource file_ref_id, + PP_Resource new_file_ref_id, PP_CompletionCallback callback) { - return PP_ERROR_FAILED; // TODO(darin): Implement me! + scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); + if (!file_ref) + return PP_ERROR_BADRESOURCE; + + scoped_refptr<FileRef> new_file_ref( + Resource::GetAs<FileRef>(new_file_ref_id)); + if (!new_file_ref) + return PP_ERROR_BADRESOURCE; + + if ((file_ref->file_system_type() == PP_FILESYSTEMTYPE_EXTERNAL) || + (file_ref->file_system_type() != new_file_ref->file_system_type())) + return PP_ERROR_FAILED; + + PluginModule* module = file_ref->module(); + if (!module->GetSomeInstance()->delegate()->Rename( + file_ref->system_path(), new_file_ref->system_path(), + new StatusCallback(module->AsWeakPtr(), callback))) + return PP_ERROR_FAILED; + + return PP_ERROR_WOULDBLOCK; } const PPB_FileSystem_Dev ppb_filesystem = { diff --git a/webkit/glue/plugins/pepper_file_system.h b/webkit/glue/plugins/pepper_file_system.h index b0a2f47..1abfc52 100644 --- a/webkit/glue/plugins/pepper_file_system.h +++ b/webkit/glue/plugins/pepper_file_system.h @@ -5,6 +5,8 @@ #ifndef WEBKIT_GLUE_PLUGINS_PEPPER_FILE_SYSTEM_H_ #define WEBKIT_GLUE_PLUGINS_PEPPER_FILE_SYSTEM_H_ +#include "base/basictypes.h" + struct PPB_FileSystem_Dev; namespace pepper { @@ -14,6 +16,9 @@ class FileSystem { // Returns a pointer to the interface implementing PPB_FileSystem that is // exposed to the plugin. static const PPB_FileSystem_Dev* GetInterface(); + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystem); }; } // namespace pepper diff --git a/webkit/glue/plugins/pepper_plugin_delegate.h b/webkit/glue/plugins/pepper_plugin_delegate.h index 3bd8897..1bb4bed 100644 --- a/webkit/glue/plugins/pepper_plugin_delegate.h +++ b/webkit/glue/plugins/pepper_plugin_delegate.h @@ -21,6 +21,11 @@ class AudioMessageFilter; namespace base { class MessageLoopProxy; +class Time; +} + +namespace fileapi { +class FileSystemCallbackDispatcher; } namespace gfx { @@ -169,6 +174,21 @@ class PluginDelegate { virtual bool AsyncOpenFile(const FilePath& path, int flags, AsyncOpenFileCallback* callback) = 0; + virtual bool MakeDirectory( + const FilePath& path, + bool recursive, + fileapi::FileSystemCallbackDispatcher* dispatcher) = 0; + virtual bool Query(const FilePath& path, + fileapi::FileSystemCallbackDispatcher* dispatcher) = 0; + virtual bool Touch(const FilePath& path, + const base::Time& last_access_time, + const base::Time& last_modified_time, + fileapi::FileSystemCallbackDispatcher* dispatcher) = 0; + virtual bool Delete(const FilePath& path, + fileapi::FileSystemCallbackDispatcher* dispatcher) = 0; + virtual bool Rename(const FilePath& file_path, + const FilePath& new_file_path, + fileapi::FileSystemCallbackDispatcher* dispatcher) = 0; // Returns a MessageLoopProxy instance associated with the message loop // of the file thread in this renderer. diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index 354b2d0..f5d03c4 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -197,6 +197,8 @@ 'plugins/pepper_cursor_control.h', 'plugins/pepper_directory_reader.cc', 'plugins/pepper_directory_reader.h', + 'plugins/pepper_error_util.cc', + 'plugins/pepper_error_util.h', 'plugins/pepper_event_conversion.cc', 'plugins/pepper_event_conversion.h', 'plugins/pepper_file_chooser.cc', |