diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-26 00:16:05 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-26 00:16:05 +0000 |
commit | 494184c1d68dfbdaa51af78f680e59dd0bfc6143 (patch) | |
tree | f897b02dc34dbc4e860c9dad561311d1a9e16e34 /webkit/plugins/ppapi | |
parent | 287b86bfa8405f38377eb4b6c33c28b8a926fb2a (diff) | |
download | chromium_src-494184c1d68dfbdaa51af78f680e59dd0bfc6143.zip chromium_src-494184c1d68dfbdaa51af78f680e59dd0bfc6143.tar.gz chromium_src-494184c1d68dfbdaa51af78f680e59dd0bfc6143.tar.bz2 |
Pepper/Flapper: Refactor module-local file stuff to make it easier/nicer to add file ref versions.
BUG=none
TEST=everything still works
Review URL: http://codereview.chromium.org/6599015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76124 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/plugins/ppapi')
-rw-r--r-- | webkit/plugins/ppapi/file_path.cc | 55 | ||||
-rw-r--r-- | webkit/plugins/ppapi/file_path.h | 50 | ||||
-rw-r--r-- | webkit/plugins/ppapi/mock_plugin_delegate.cc | 32 | ||||
-rw-r--r-- | webkit/plugins/ppapi/mock_plugin_delegate.h | 36 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_delegate.h | 38 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_flash_file_impl.cc | 143 |
6 files changed, 226 insertions, 128 deletions
diff --git a/webkit/plugins/ppapi/file_path.cc b/webkit/plugins/ppapi/file_path.cc new file mode 100644 index 0000000..a7ed447 --- /dev/null +++ b/webkit/plugins/ppapi/file_path.cc @@ -0,0 +1,55 @@ +// Copyright (c) 2011 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/plugins/ppapi/file_path.h" + +#include <string> + +#include "webkit/plugins/ppapi/plugin_module.h" + +#if defined(OS_WIN) +#include "base/utf_string_conversions.h" +#endif + +namespace webkit { +namespace ppapi { + +namespace { + +FilePath GetFilePathFromUTF8(const std::string& utf8_path) { +#if defined(OS_WIN) + return FilePath(UTF8ToUTF16(utf8_path)); +#else + return FilePath(utf8_path); +#endif +} + +} // namespace + +PepperFilePath::PepperFilePath() + : domain_(DOMAIN_INVALID), + path_() { +} + +PepperFilePath::PepperFilePath(Domain domain, FilePath path) + : domain_(domain), + path_(path) { + // TODO(viettrungluu): Should we DCHECK() some things here? +} + +// static +PepperFilePath PepperFilePath::MakeAbsolute(const char* utf8_path) { + return PepperFilePath(DOMAIN_ABSOLUTE, GetFilePathFromUTF8(utf8_path)); +} + +// static +PepperFilePath PepperFilePath::MakeModuleLocal(PluginModule* module, + const char* utf8_path) { + FilePath full_path = GetFilePathFromUTF8(module->name()).Append( + GetFilePathFromUTF8(utf8_path)); + return PepperFilePath(DOMAIN_MODULE_LOCAL, full_path); +} + +} // namespace ppapi +} // namespace webkit diff --git a/webkit/plugins/ppapi/file_path.h b/webkit/plugins/ppapi/file_path.h new file mode 100644 index 0000000..6d6f4dc --- /dev/null +++ b/webkit/plugins/ppapi/file_path.h @@ -0,0 +1,50 @@ +// Copyright (c) 2011 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_PLUGINS_PPAPI_FILE_PATH_H_ +#define WEBKIT_PLUGINS_PPAPI_FILE_PATH_H_ + +#include <string> + +#include "base/file_path.h" + +namespace webkit { +namespace ppapi { + +class PluginModule; + +// TODO(vtl): Once we put |::FilePath| into the |base| namespace, get rid of the +// |Pepper| (or |PEPPER_|) prefixes. Right now, it's just too +// confusing/dangerous! + +class PepperFilePath { + public: + enum Domain { + DOMAIN_INVALID = 0, + DOMAIN_ABSOLUTE, + DOMAIN_MODULE_LOCAL, + + // Used for validity-checking. + DOMAIN_MAX_VALID = DOMAIN_MODULE_LOCAL + }; + + PepperFilePath(); + PepperFilePath(Domain d, FilePath p); + + static PepperFilePath MakeAbsolute(const char* utf8_path); + static PepperFilePath MakeModuleLocal(PluginModule* module, + const char* utf8_path); + + Domain domain() const { return domain_; } + const FilePath& path() const { return path_; } + + private: + Domain domain_; + FilePath path_; +}; + +} // namespace ppapi +} // namespace webkit + +#endif // WEBKIT_PLUGINS_PPAPI_FILE_PATH_H_ diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc index 54e55ee..6f55e9b 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.cc +++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc @@ -113,44 +113,38 @@ bool MockPluginDelegate::ReadDirectory( return false; } -base::PlatformFileError MockPluginDelegate::OpenModuleLocalFile( - const std::string& module_name, - const FilePath& path, +base::PlatformFileError MockPluginDelegate::OpenFile( + const PepperFilePath& path, int flags, base::PlatformFile* file) { return base::PLATFORM_FILE_ERROR_FAILED; } -base::PlatformFileError MockPluginDelegate::RenameModuleLocalFile( - const std::string& module_name, - const FilePath& path_from, - const FilePath& path_to) { +base::PlatformFileError MockPluginDelegate::RenameFile( + const PepperFilePath& from_path, + const PepperFilePath& to_path) { return base::PLATFORM_FILE_ERROR_FAILED; } -base::PlatformFileError MockPluginDelegate::DeleteModuleLocalFileOrDir( - const std::string& module_name, - const FilePath& path, +base::PlatformFileError MockPluginDelegate::DeleteFileOrDir( + const PepperFilePath& path, bool recursive) { return base::PLATFORM_FILE_ERROR_FAILED; } -base::PlatformFileError MockPluginDelegate::CreateModuleLocalDir( - const std::string& module_name, - const FilePath& path) { +base::PlatformFileError MockPluginDelegate::CreateDir( + const PepperFilePath& path) { return base::PLATFORM_FILE_ERROR_FAILED; } -base::PlatformFileError MockPluginDelegate::QueryModuleLocalFile( - const std::string& module_name, - const FilePath& path, +base::PlatformFileError MockPluginDelegate::QueryFile( + const PepperFilePath& path, base::PlatformFileInfo* info) { return base::PLATFORM_FILE_ERROR_FAILED; } -base::PlatformFileError MockPluginDelegate::GetModuleLocalDirContents( - const std::string& module_name, - const FilePath& path, +base::PlatformFileError MockPluginDelegate::GetDirContents( + const PepperFilePath& path, DirContents* contents) { return base::PLATFORM_FILE_ERROR_FAILED; } diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h index 75d4637..6efa63f 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.h +++ b/webkit/plugins/ppapi/mock_plugin_delegate.h @@ -57,30 +57,18 @@ class MockPluginDelegate : public PluginDelegate { virtual bool ReadDirectory( const FilePath& directory_path, fileapi::FileSystemCallbackDispatcher* dispatcher); - virtual base::PlatformFileError OpenModuleLocalFile( - const std::string& module_name, - const FilePath& path, - int flags, - base::PlatformFile* file); - virtual base::PlatformFileError RenameModuleLocalFile( - const std::string& module_name, - const FilePath& path_from, - const FilePath& path_to); - virtual base::PlatformFileError DeleteModuleLocalFileOrDir( - const std::string& module_name, - const FilePath& path, - bool recursive); - virtual base::PlatformFileError CreateModuleLocalDir( - const std::string& module_name, - const FilePath& path); - virtual base::PlatformFileError QueryModuleLocalFile( - const std::string& module_name, - const FilePath& path, - base::PlatformFileInfo* info); - virtual base::PlatformFileError GetModuleLocalDirContents( - const std::string& module_name, - const FilePath& path, - DirContents* contents); + virtual base::PlatformFileError OpenFile(const PepperFilePath& path, + int flags, + base::PlatformFile* file); + virtual base::PlatformFileError RenameFile(const PepperFilePath& from_path, + const PepperFilePath& to_path); + virtual base::PlatformFileError DeleteFileOrDir(const PepperFilePath& path, + bool recursive); + virtual base::PlatformFileError CreateDir(const PepperFilePath& path); + virtual base::PlatformFileError QueryFile(const PepperFilePath& path, + base::PlatformFileInfo* info); + virtual base::PlatformFileError GetDirContents(const PepperFilePath& path, + DirContents* contents); virtual scoped_refptr<base::MessageLoopProxy> GetFileThreadMessageLoopProxy(); virtual int32_t ConnectTcp( diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h index 32bc025..72d5c9b 100644 --- a/webkit/plugins/ppapi/plugin_delegate.h +++ b/webkit/plugins/ppapi/plugin_delegate.h @@ -63,6 +63,7 @@ namespace ppapi { class FileIO; class FullscreenContainer; +class PepperFilePath; class PluginInstance; class PluginModule; class PPB_Flash_Menu_Impl; @@ -242,6 +243,7 @@ class PluginDelegate { virtual bool AsyncOpenFile(const FilePath& path, int flags, AsyncOpenFileCallback* callback) = 0; + virtual bool OpenFileSystem( const GURL& url, fileapi::FileSystemType type, @@ -266,30 +268,18 @@ class PluginDelegate { const FilePath& directory_path, fileapi::FileSystemCallbackDispatcher* dispatcher) = 0; - virtual base::PlatformFileError OpenModuleLocalFile( - const std::string& module_name, - const FilePath& path, - int flags, - base::PlatformFile* file) = 0; - virtual base::PlatformFileError RenameModuleLocalFile( - const std::string& module_name, - const FilePath& path_from, - const FilePath& path_to) = 0; - virtual base::PlatformFileError DeleteModuleLocalFileOrDir( - const std::string& module_name, - const FilePath& path, - bool recursive) = 0; - virtual base::PlatformFileError CreateModuleLocalDir( - const std::string& module_name, - const FilePath& path) = 0; - virtual base::PlatformFileError QueryModuleLocalFile( - const std::string& module_name, - const FilePath& path, - base::PlatformFileInfo* info) = 0; - virtual base::PlatformFileError GetModuleLocalDirContents( - const std::string& module_name, - const FilePath& path, - DirContents* contents) = 0; + virtual base::PlatformFileError OpenFile(const PepperFilePath& path, + int flags, + base::PlatformFile* file) = 0; + virtual base::PlatformFileError RenameFile(const PepperFilePath& from_path, + const PepperFilePath& to_path) = 0; + virtual base::PlatformFileError DeleteFileOrDir(const PepperFilePath& path, + bool recursive) = 0; + virtual base::PlatformFileError CreateDir(const PepperFilePath& path) = 0; + virtual base::PlatformFileError QueryFile(const PepperFilePath& path, + base::PlatformFileInfo* info) = 0; + virtual base::PlatformFileError GetDirContents(const PepperFilePath& path, + DirContents* contents) = 0; // Returns a MessageLoopProxy instance associated with the message loop // of the file thread in this renderer. diff --git a/webkit/plugins/ppapi/ppb_flash_file_impl.cc b/webkit/plugins/ppapi/ppb_flash_file_impl.cc index c71a8d1..bbd7f97 100644 --- a/webkit/plugins/ppapi/ppb_flash_file_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_file_impl.cc @@ -8,119 +8,150 @@ #include <string> -#include "base/file_path.h" -#include "base/utf_string_conversions.h" #include "ppapi/c/dev/pp_file_info_dev.h" #include "ppapi/c/dev/ppb_file_io_dev.h" #include "ppapi/c/private/ppb_flash_file.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/error_util.h" +#include "webkit/plugins/ppapi/file_path.h" #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/ppb_file_ref_impl.h" #include "webkit/plugins/ppapi/resource_tracker.h" +#if defined(OS_WIN) +#include "base/utf_string_conversions.h" +#endif + namespace webkit { namespace ppapi { namespace { -FilePath GetFilePathFromUTF8(const char* path) { -#if defined(OS_WIN) - return FilePath(UTF8ToUTF16(path)); -#else - return FilePath(path); -#endif -} - -int32_t OpenModuleLocalFile(PP_Instance pp_instance, - const char* path, - int32_t mode, - PP_FileHandle* file) { - PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); - if (!instance) - return PP_ERROR_FAILED; - +// TODO(viettrungluu): The code below is duplicated in ppb_file_io_impl.cc +// (where it's incorrect to boot). +// Returns |true| if okay. +bool ConvertFromPPFileOpenFlags(int32_t pp_open_flags, int* flags_out) { int flags = 0; - if (mode & PP_FILEOPENFLAG_READ) + if (pp_open_flags & PP_FILEOPENFLAG_READ) flags |= base::PLATFORM_FILE_READ; - if (mode & PP_FILEOPENFLAG_WRITE) { + if (pp_open_flags & PP_FILEOPENFLAG_WRITE) { flags |= base::PLATFORM_FILE_WRITE; flags |= base::PLATFORM_FILE_WRITE_ATTRIBUTES; } - if (mode & PP_FILEOPENFLAG_TRUNCATE) { - DCHECK(mode & PP_FILEOPENFLAG_WRITE); + if (pp_open_flags & PP_FILEOPENFLAG_TRUNCATE) { + if (!(pp_open_flags & PP_FILEOPENFLAG_WRITE)) + return false; flags |= base::PLATFORM_FILE_TRUNCATE; } - - if (mode & PP_FILEOPENFLAG_CREATE) { - if (mode & PP_FILEOPENFLAG_EXCLUSIVE) + if (pp_open_flags & PP_FILEOPENFLAG_CREATE) { + if (pp_open_flags & PP_FILEOPENFLAG_EXCLUSIVE) flags |= base::PLATFORM_FILE_CREATE; else flags |= base::PLATFORM_FILE_OPEN_ALWAYS; } else { flags |= base::PLATFORM_FILE_OPEN; } + *flags_out = flags; + return true; +} + +void FreeDirContents(PP_Instance instance, PP_DirContents_Dev* contents) { + DCHECK(contents); + for (int32_t i = 0; i < contents->count; ++i) { + delete [] contents->entries[i].name; + } + delete [] contents->entries; + delete contents; +} + +} // namespace + +// PPB_Flash_File_ModuleLocal_Impl --------------------------------------------- + +namespace { + +int32_t OpenModuleLocalFile(PP_Instance pp_instance, + const char* path, + int32_t mode, + PP_FileHandle* file) { + int flags = 0; + if (!path || !ConvertFromPPFileOpenFlags(mode, &flags) || !file) + return PP_ERROR_BADARGUMENT; + + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); + if (!instance) + return PP_ERROR_FAILED; base::PlatformFile base_file; - base::PlatformFileError result = instance->delegate()->OpenModuleLocalFile( - instance->module()->name(), - GetFilePathFromUTF8(path), + base::PlatformFileError result = instance->delegate()->OpenFile( + PepperFilePath::MakeModuleLocal(instance->module(), path), flags, &base_file); *file = base_file; return PlatformFileErrorToPepperError(result); } - int32_t RenameModuleLocalFile(PP_Instance pp_instance, - const char* path_from, - const char* path_to) { + const char* from_path, + const char* to_path) { + if (!from_path || !to_path) + return PP_ERROR_BADARGUMENT; + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return PP_ERROR_FAILED; - base::PlatformFileError result = instance->delegate()->RenameModuleLocalFile( - instance->module()->name(), - GetFilePathFromUTF8(path_from), - GetFilePathFromUTF8(path_to)); + base::PlatformFileError result = instance->delegate()->RenameFile( + PepperFilePath::MakeModuleLocal(instance->module(), from_path), + PepperFilePath::MakeModuleLocal(instance->module(), to_path)); return PlatformFileErrorToPepperError(result); } int32_t DeleteModuleLocalFileOrDir(PP_Instance pp_instance, const char* path, PP_Bool recursive) { + if (!path) + return PP_ERROR_BADARGUMENT; + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return PP_ERROR_FAILED; - base::PlatformFileError result = - instance->delegate()->DeleteModuleLocalFileOrDir( - instance->module()->name(), GetFilePathFromUTF8(path), - PPBoolToBool(recursive)); + base::PlatformFileError result = instance->delegate()->DeleteFileOrDir( + PepperFilePath::MakeModuleLocal(instance->module(), path), + PPBoolToBool(recursive)); return PlatformFileErrorToPepperError(result); } int32_t CreateModuleLocalDir(PP_Instance pp_instance, const char* path) { + if (!path) + return PP_ERROR_BADARGUMENT; + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return PP_ERROR_FAILED; - base::PlatformFileError result = instance->delegate()->CreateModuleLocalDir( - instance->module()->name(), GetFilePathFromUTF8(path)); + base::PlatformFileError result = instance->delegate()->CreateDir( + PepperFilePath::MakeModuleLocal(instance->module(), path)); return PlatformFileErrorToPepperError(result); } int32_t QueryModuleLocalFile(PP_Instance pp_instance, const char* path, PP_FileInfo_Dev* info) { + if (!path || !info) + return PP_ERROR_BADARGUMENT; + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return PP_ERROR_FAILED; base::PlatformFileInfo file_info; - base::PlatformFileError result = instance->delegate()->QueryModuleLocalFile( - instance->module()->name(), GetFilePathFromUTF8(path), &file_info); + base::PlatformFileError result = instance->delegate()->QueryFile( + PepperFilePath::MakeModuleLocal(instance->module(), path), + &file_info); if (result == base::PLATFORM_FILE_OK) { info->size = file_info.size; info->creation_time = file_info.creation_time.ToDoubleT(); @@ -138,17 +169,17 @@ int32_t QueryModuleLocalFile(PP_Instance pp_instance, int32_t GetModuleLocalDirContents(PP_Instance pp_instance, const char* path, PP_DirContents_Dev** contents) { + if (!path || !contents) + return PP_ERROR_BADARGUMENT; PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return PP_ERROR_FAILED; *contents = NULL; DirContents pepper_contents; - base::PlatformFileError result = - instance->delegate()->GetModuleLocalDirContents( - instance->module()->name(), - GetFilePathFromUTF8(path), - &pepper_contents); + base::PlatformFileError result = instance->delegate()->GetDirContents( + PepperFilePath::MakeModuleLocal(instance->module(), path), + &pepper_contents); if (result != base::PLATFORM_FILE_OK) return PlatformFileErrorToPepperError(result); @@ -173,24 +204,14 @@ int32_t GetModuleLocalDirContents(PP_Instance pp_instance, return PP_OK; } -void FreeModuleLocalDirContents(PP_Instance instance, - PP_DirContents_Dev* contents) { - DCHECK(contents); - for (int32_t i = 0; i < contents->count; ++i) { - delete [] contents->entries[i].name; - } - delete [] contents->entries; - delete contents; -} - -const PPB_Flash_File_ModuleLocal ppb_flash_file_module_local = { +const PPB_Flash_File_ModuleLocal ppb_flash_file_modulelocal = { &OpenModuleLocalFile, &RenameModuleLocalFile, &DeleteModuleLocalFileOrDir, &CreateModuleLocalDir, &QueryModuleLocalFile, &GetModuleLocalDirContents, - &FreeModuleLocalDirContents, + &FreeDirContents, }; } // namespace @@ -198,7 +219,7 @@ const PPB_Flash_File_ModuleLocal ppb_flash_file_module_local = { // static const PPB_Flash_File_ModuleLocal* PPB_Flash_File_ModuleLocal_Impl::GetInterface() { - return &ppb_flash_file_module_local; + return &ppb_flash_file_modulelocal; } } // namespace ppapi |