diff options
author | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-04 00:36:22 +0000 |
---|---|---|
committer | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-04 00:36:22 +0000 |
commit | de9bdd1e4d2f87f53b1c2d3eacfbe43ef6ca1019 (patch) | |
tree | 7e714193e2f5abad3d3ca54d353b62a7f9ebf7e3 /webkit/glue/plugins | |
parent | f8ce465c025d457778f8376eca12d94e723965bb (diff) | |
download | chromium_src-de9bdd1e4d2f87f53b1c2d3eacfbe43ef6ca1019.zip chromium_src-de9bdd1e4d2f87f53b1c2d3eacfbe43ef6ca1019.tar.gz chromium_src-de9bdd1e4d2f87f53b1c2d3eacfbe43ef6ca1019.tar.bz2 |
Pepper's directory reader implementation + test.
BUG=none
TEST=test_directory_reader.cc
Review URL: http://codereview.chromium.org/4107004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65002 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/plugins')
-rw-r--r-- | webkit/glue/plugins/pepper_directory_reader.cc | 94 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_directory_reader.h | 11 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_file_callbacks.cc | 17 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_file_callbacks.h | 9 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_file_ref.cc | 11 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_file_system.cc | 3 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_plugin_delegate.h | 3 |
7 files changed, 131 insertions, 17 deletions
diff --git a/webkit/glue/plugins/pepper_directory_reader.cc b/webkit/glue/plugins/pepper_directory_reader.cc index a40ef1d..558560e 100644 --- a/webkit/glue/plugins/pepper_directory_reader.cc +++ b/webkit/glue/plugins/pepper_directory_reader.cc @@ -5,16 +5,42 @@ #include "webkit/glue/plugins/pepper_directory_reader.h" #include "base/logging.h" +#include "base/utf_string_conversions.h" #include "ppapi/c/pp_completion_callback.h" -#include "ppapi/c/dev/ppb_directory_reader_dev.h" #include "ppapi/c/pp_errors.h" +#include "ppapi/c/dev/ppb_directory_reader_dev.h" +#include "webkit/glue/plugins/pepper_file_callbacks.h" #include "webkit/glue/plugins/pepper_file_ref.h" +#include "webkit/glue/plugins/pepper_file_system.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_tracker.h" namespace pepper { namespace { +std::string FilePathStringToUTF8String(const FilePath::StringType& str) { +#if defined(OS_WIN) + return WideToUTF8(str); +#elif defined(OS_POSIX) + return str; +#else +#error "Unsupported platform." +#endif +} + +FilePath::StringType UTF8StringToFilePathString(const std::string& str) { +#if defined(OS_WIN) + return UTF8ToWide(str); +#elif defined(OS_POSIX) + return str; +#else +#error "Unsupported platform." +#endif +} + PP_Resource Create(PP_Resource directory_ref_id) { scoped_refptr<FileRef> directory_ref( Resource::GetAs<FileRef>(directory_ref_id)); @@ -50,7 +76,9 @@ const PPB_DirectoryReader_Dev ppb_directoryreader = { DirectoryReader::DirectoryReader(FileRef* directory_ref) : Resource(directory_ref->module()), - directory_ref_(directory_ref) { + directory_ref_(directory_ref), + has_more_(true), + entry_(NULL) { } DirectoryReader::~DirectoryReader() { @@ -62,8 +90,66 @@ const PPB_DirectoryReader_Dev* DirectoryReader::GetInterface() { int32_t DirectoryReader::GetNextEntry(PP_DirectoryEntry_Dev* entry, PP_CompletionCallback callback) { - NOTIMPLEMENTED(); // TODO(darin): Implement me! - return PP_ERROR_FAILED; + if (directory_ref_->GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) + return PP_ERROR_FAILED; + + entry_ = entry; + if (FillUpEntry()) { + entry_ = NULL; + return PP_OK; + } + + PluginInstance* instance = directory_ref_->GetFileSystem()->instance(); + if (!instance->delegate()->ReadDirectory( + directory_ref_->GetSystemPath(), + new FileCallbacks(instance->module()->AsWeakPtr(), + callback, NULL, NULL, this))) + return PP_ERROR_FAILED; + + return PP_ERROR_WOULDBLOCK; +} + +void DirectoryReader::AddNewEntries( + const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { + DCHECK(!entries.empty()); + has_more_ = has_more; + std::string dir_path = directory_ref_->GetPath(); + if (dir_path[dir_path.size() - 1] != '/') + dir_path += '/'; + FilePath::StringType dir_file_path = UTF8StringToFilePathString(dir_path); + for (std::vector<base::FileUtilProxy::Entry>::const_iterator it = + entries.begin(); it != entries.end(); it++) { + base::FileUtilProxy::Entry entry; + entry.name = dir_file_path + it->name; + entry.is_directory = it->is_directory; + entries_.push(entry); + } + + FillUpEntry(); + entry_ = NULL; +} + +bool DirectoryReader::FillUpEntry() { + DCHECK(entry_); + if (!entries_.empty()) { + base::FileUtilProxy::Entry dir_entry = entries_.front(); + entries_.pop(); + if (entry_->file_ref) + ResourceTracker::Get()->UnrefResource(entry_->file_ref); + FileRef* file_ref = new FileRef(module(), directory_ref_->GetFileSystem(), + FilePathStringToUTF8String(dir_entry.name)); + entry_->file_ref = file_ref->GetReference(); + entry_->file_type = + (dir_entry.is_directory ? PP_FILETYPE_DIRECTORY : PP_FILETYPE_REGULAR); + return true; + } + + if (!has_more_) { + entry_->file_ref = 0; + return true; + } + + return false; } } // namespace pepper diff --git a/webkit/glue/plugins/pepper_directory_reader.h b/webkit/glue/plugins/pepper_directory_reader.h index a56d546..38496bb8 100644 --- a/webkit/glue/plugins/pepper_directory_reader.h +++ b/webkit/glue/plugins/pepper_directory_reader.h @@ -5,6 +5,9 @@ #ifndef WEBKIT_GLUE_PLUGINS_PEPPER_DIRECTORY_READER_H_ #define WEBKIT_GLUE_PLUGINS_PEPPER_DIRECTORY_READER_H_ +#include <queue> + +#include "base/file_util_proxy.h" #include "webkit/glue/plugins/pepper_resource.h" struct PP_CompletionCallback; @@ -31,8 +34,16 @@ class DirectoryReader : public Resource { int32_t GetNextEntry(PP_DirectoryEntry_Dev* entry, PP_CompletionCallback callback); + void AddNewEntries(const std::vector<base::FileUtilProxy::Entry>& entries, + bool has_more); + private: + bool FillUpEntry(); + scoped_refptr<FileRef> directory_ref_; + std::queue<base::FileUtilProxy::Entry> entries_; + bool has_more_; + PP_DirectoryEntry_Dev* entry_; }; } // namespace pepper diff --git a/webkit/glue/plugins/pepper_file_callbacks.cc b/webkit/glue/plugins/pepper_file_callbacks.cc index fe6ad95..e24927a 100644 --- a/webkit/glue/plugins/pepper_file_callbacks.cc +++ b/webkit/glue/plugins/pepper_file_callbacks.cc @@ -9,6 +9,7 @@ #include "ppapi/c/dev/ppb_file_system_dev.h" #include "ppapi/c/dev/pp_file_info_dev.h" #include "ppapi/c/pp_errors.h" +#include "webkit/glue/plugins/pepper_directory_reader.h" #include "webkit/glue/plugins/pepper_error_util.h" #include "webkit/glue/plugins/pepper_file_system.h" #include "webkit/fileapi/file_system_types.h" @@ -18,11 +19,13 @@ namespace pepper { FileCallbacks::FileCallbacks(const base::WeakPtr<PluginModule>& module, PP_CompletionCallback callback, PP_FileInfo_Dev* info, - scoped_refptr<FileSystem> file_system) + scoped_refptr<FileSystem> file_system, + scoped_refptr<DirectoryReader> directory_reader) : module_(module), callback_(callback), info_(info), - file_system_(file_system) { + file_system_(file_system), + directory_reader_(directory_reader) { } FileCallbacks::~FileCallbacks() {} @@ -55,8 +58,14 @@ void FileCallbacks::DidReadMetadata( } void FileCallbacks::DidReadDirectory( - const std::vector<base::FileUtilProxy::Entry>&, bool) { - NOTREACHED(); + const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { + if (!module_.get() || !callback_.func) + return; + + DCHECK(directory_reader_); + directory_reader_->AddNewEntries(entries, has_more); + + PP_RunCompletionCallback(&callback_, PP_OK); } void FileCallbacks::DidOpenFileSystem(const std::string&, diff --git a/webkit/glue/plugins/pepper_file_callbacks.h b/webkit/glue/plugins/pepper_file_callbacks.h index 20cb8d3..d4a92f2c 100644 --- a/webkit/glue/plugins/pepper_file_callbacks.h +++ b/webkit/glue/plugins/pepper_file_callbacks.h @@ -18,6 +18,7 @@ class FilePath; namespace pepper { +class DirectoryReader; class FileSystem; class PluginModule; @@ -27,14 +28,15 @@ class FileCallbacks : public fileapi::FileSystemCallbackDispatcher { FileCallbacks(const base::WeakPtr<PluginModule>& module, PP_CompletionCallback callback, PP_FileInfo_Dev* info, - scoped_refptr<FileSystem> file_system); + scoped_refptr<FileSystem> file_system, + scoped_refptr<DirectoryReader> directory_reader); virtual ~FileCallbacks(); // FileSystemCallbackDispatcher implementation. virtual void DidSucceed(); virtual void DidReadMetadata(const base::PlatformFileInfo& file_info); virtual void DidReadDirectory( - const std::vector<base::FileUtilProxy::Entry>&, bool); + const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more); virtual void DidOpenFileSystem(const std::string&, const FilePath& root_path); virtual void DidFail(base::PlatformFileError error_code); @@ -43,10 +45,11 @@ class FileCallbacks : public fileapi::FileSystemCallbackDispatcher { private: void RunCallback(base::PlatformFileError error_code); - base::WeakPtr<pepper::PluginModule> module_; + base::WeakPtr<PluginModule> module_; PP_CompletionCallback callback_; PP_FileInfo_Dev* info_; scoped_refptr<FileSystem> file_system_; + scoped_refptr<DirectoryReader> directory_reader_; }; } // namespace pepper diff --git a/webkit/glue/plugins/pepper_file_ref.cc b/webkit/glue/plugins/pepper_file_ref.cc index 8fb685b..a135cf6 100644 --- a/webkit/glue/plugins/pepper_file_ref.cc +++ b/webkit/glue/plugins/pepper_file_ref.cc @@ -7,6 +7,7 @@ #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "ppapi/c/pp_errors.h" +#include "webkit/glue/plugins/pepper_directory_reader.h" #include "webkit/glue/plugins/pepper_file_callbacks.h" #include "webkit/glue/plugins/pepper_file_system.h" #include "webkit/glue/plugins/pepper_plugin_delegate.h" @@ -118,7 +119,7 @@ int32_t MakeDirectory(PP_Resource directory_ref_id, if (!instance->delegate()->MakeDirectory( directory_ref->GetSystemPath(), make_ancestors, new FileCallbacks(instance->module()->AsWeakPtr(), - callback, NULL, NULL))) + callback, NULL, NULL, NULL))) return PP_ERROR_FAILED; return PP_ERROR_WOULDBLOCK; @@ -140,7 +141,7 @@ int32_t Query(PP_Resource file_ref_id, if (!instance->delegate()->Query( file_ref->GetSystemPath(), new FileCallbacks(instance->module()->AsWeakPtr(), - callback, info, file_system))) + callback, info, file_system, NULL))) return PP_ERROR_FAILED; return PP_ERROR_WOULDBLOCK; @@ -164,7 +165,7 @@ int32_t Touch(PP_Resource file_ref_id, file_ref->GetSystemPath(), base::Time::FromDoubleT(last_access_time), base::Time::FromDoubleT(last_modified_time), new FileCallbacks(instance->module()->AsWeakPtr(), - callback, NULL, NULL))) + callback, NULL, NULL, NULL))) return PP_ERROR_FAILED; return PP_ERROR_WOULDBLOCK; @@ -185,7 +186,7 @@ int32_t Delete(PP_Resource file_ref_id, if (!instance->delegate()->Delete( file_ref->GetSystemPath(), new FileCallbacks(instance->module()->AsWeakPtr(), - callback, NULL, NULL))) + callback, NULL, NULL, NULL))) return PP_ERROR_FAILED; return PP_ERROR_WOULDBLOCK; @@ -213,7 +214,7 @@ int32_t Rename(PP_Resource file_ref_id, if (!instance->delegate()->Rename( file_ref->GetSystemPath(), new_file_ref->GetSystemPath(), new FileCallbacks(instance->module()->AsWeakPtr(), - callback, NULL, NULL))) + callback, NULL, NULL, NULL))) return PP_ERROR_FAILED; return PP_ERROR_WOULDBLOCK; diff --git a/webkit/glue/plugins/pepper_file_system.cc b/webkit/glue/plugins/pepper_file_system.cc index b2e17d5..9262798 100644 --- a/webkit/glue/plugins/pepper_file_system.cc +++ b/webkit/glue/plugins/pepper_file_system.cc @@ -12,6 +12,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" #include "webkit/fileapi/file_system_types.h" +#include "webkit/glue/plugins/pepper_directory_reader.h" #include "webkit/glue/plugins/pepper_file_callbacks.h" #include "webkit/glue/plugins/pepper_plugin_delegate.h" #include "webkit/glue/plugins/pepper_plugin_instance.h" @@ -57,7 +58,7 @@ int32_t Open(PP_Resource file_system_id, instance->container()->element().document().frame()->url(), file_system_type, expected_size, new FileCallbacks(instance->module()->AsWeakPtr(), - callback, NULL, file_system))) + callback, NULL, file_system, NULL))) return PP_ERROR_FAILED; return PP_ERROR_WOULDBLOCK; diff --git a/webkit/glue/plugins/pepper_plugin_delegate.h b/webkit/glue/plugins/pepper_plugin_delegate.h index 897b16f..0998355 100644 --- a/webkit/glue/plugins/pepper_plugin_delegate.h +++ b/webkit/glue/plugins/pepper_plugin_delegate.h @@ -198,6 +198,9 @@ class PluginDelegate { virtual bool Rename(const FilePath& file_path, const FilePath& new_file_path, fileapi::FileSystemCallbackDispatcher* dispatcher) = 0; + virtual bool ReadDirectory( + const FilePath& directory_path, + fileapi::FileSystemCallbackDispatcher* dispatcher) = 0; virtual base::PlatformFileError OpenModuleLocalFile( const std::string& module_name, |