diff options
author | tsepez@chromium.org <tsepez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-01 20:37:35 +0000 |
---|---|---|
committer | tsepez@chromium.org <tsepez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-01 20:37:35 +0000 |
commit | 7e1dc3d25fb9211ae4baf7577ef72afcad78f2e1 (patch) | |
tree | 4ecc5db6beecb9b4c6812ed06a206ac887c4d2f6 /ppapi | |
parent | 893dfd9a63c58061e961e0dbd777b8ffb46c50ed (diff) | |
download | chromium_src-7e1dc3d25fb9211ae4baf7577ef72afcad78f2e1.zip chromium_src-7e1dc3d25fb9211ae4baf7577ef72afcad78f2e1.tar.gz chromium_src-7e1dc3d25fb9211ae4baf7577ef72afcad78f2e1.tar.bz2 |
Open pepper files directly in browser.
This CL merges in the changes for the per-profile plugin process from the
previously retired CL.
Review URL: https://chromiumcodereview.appspot.com/10387195
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140093 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/ppapi_proxy.gypi | 2 | ||||
-rw-r--r-- | ppapi/ppapi_proxy_untrusted.gypi | 1 | ||||
-rw-r--r-- | ppapi/ppapi_shared.gypi | 4 | ||||
-rw-r--r-- | ppapi/proxy/pepper_file_messages.cc | 68 | ||||
-rw-r--r-- | ppapi/proxy/pepper_file_messages.h | 74 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 32 | ||||
-rw-r--r-- | ppapi/proxy/ppb_flash_proxy.cc | 273 | ||||
-rw-r--r-- | ppapi/proxy/ppb_flash_proxy.h | 24 | ||||
-rw-r--r-- | ppapi/shared_impl/dir_contents.h | 24 | ||||
-rw-r--r-- | ppapi/shared_impl/file_path.cc | 51 | ||||
-rw-r--r-- | ppapi/shared_impl/file_path.h | 47 |
11 files changed, 367 insertions, 233 deletions
diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi index 538c333..fde6415 100644 --- a/ppapi/ppapi_proxy.gypi +++ b/ppapi/ppapi_proxy.gypi @@ -48,6 +48,8 @@ 'proxy/interface_list.h', 'proxy/interface_proxy.cc', 'proxy/interface_proxy.h', + 'proxy/pepper_file_messages.cc', + 'proxy/pepper_file_messages.h', 'proxy/plugin_array_buffer_var.cc', 'proxy/plugin_array_buffer_var.h', 'proxy/plugin_dispatcher.cc', diff --git a/ppapi/ppapi_proxy_untrusted.gypi b/ppapi/ppapi_proxy_untrusted.gypi index 82e9936..4985f76 100644 --- a/ppapi/ppapi_proxy_untrusted.gypi +++ b/ppapi/ppapi_proxy_untrusted.gypi @@ -344,6 +344,7 @@ 'proxy/host_var_serialization_rules.cc', 'proxy/interface_list.cc', 'proxy/interface_proxy.cc', + 'proxy/pepper_file_messages.cc', 'proxy/plugin_array_buffer_var.cc', 'proxy/plugin_dispatcher.cc', 'proxy/plugin_globals.cc', diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index d9d0140..5afcefe 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -41,7 +41,7 @@ ], 'export_dependent_settings': [ '../base/base.gyp:base', - '<(webkit_src_dir)/Source/WebKit/chromium/WebKit.gyp:webkit', + '<(webkit_src_dir)/Source/WebKit/chromium/WebKit.gyp:webkit', ], 'conditions': [ ['OS=="mac"', { @@ -57,6 +57,8 @@ 'shared_impl/array_writer.h', 'shared_impl/callback_tracker.cc', 'shared_impl/callback_tracker.h', + 'shared_impl/file_path.cc', + 'shared_impl/file_path.h', 'shared_impl/file_type_conversion.cc', 'shared_impl/file_type_conversion.h', 'shared_impl/host_resource.h', diff --git a/ppapi/proxy/pepper_file_messages.cc b/ppapi/proxy/pepper_file_messages.cc new file mode 100644 index 0000000..53b4fcb --- /dev/null +++ b/ppapi/proxy/pepper_file_messages.cc @@ -0,0 +1,68 @@ +// Copyright (c) 2012 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. + + +// Get basic type definitions. +#define IPC_MESSAGE_IMPL +#include "ppapi/proxy/pepper_file_messages.h" + +// Generate constructors. +#include "ipc/struct_constructor_macros.h" +#include "ppapi/proxy/pepper_file_messages.h" + +// Generate destructors. +#include "ipc/struct_destructor_macros.h" +#include "ppapi/proxy/pepper_file_messages.h" + +// Generate param traits write methods. +#include "ipc/param_traits_write_macros.h" +namespace IPC { +#include "ppapi/proxy/pepper_file_messages.h" +} // namespace IPC + +// Generate param traits read methods. +#include "ipc/param_traits_read_macros.h" +namespace IPC { +#include "ppapi/proxy/pepper_file_messages.h" +} // namespace IPC + +// Generate param traits log methods. +#include "ipc/param_traits_log_macros.h" +namespace IPC { +#include "ppapi/proxy/pepper_file_messages.h" +} // namespace IPC + +namespace IPC { + +void ParamTraits<ppapi::PepperFilePath>::Write(Message* m, + const param_type& p) { + WriteParam(m, static_cast<unsigned>(p.domain())); + WriteParam(m, p.path()); +} + +bool ParamTraits<ppapi::PepperFilePath>::Read(const Message* m, + PickleIterator* iter, + param_type* p) { + unsigned domain; + FilePath path; + if (!ReadParam(m, iter, &domain) || !ReadParam(m, iter, &path)) + return false; + if (domain > ppapi::PepperFilePath::DOMAIN_MAX_VALID) + return false; + + *p = ppapi::PepperFilePath( + static_cast<ppapi::PepperFilePath::Domain>(domain), path); + return true; +} + +void ParamTraits<ppapi::PepperFilePath>::Log(const param_type& p, + std::string* l) { + l->append("("); + LogParam(static_cast<unsigned>(p.domain()), l); + l->append(", "); + LogParam(p.path(), l); + l->append(")"); +} + +} // namespace IPC diff --git a/ppapi/proxy/pepper_file_messages.h b/ppapi/proxy/pepper_file_messages.h new file mode 100644 index 0000000..b8ec98c --- /dev/null +++ b/ppapi/proxy/pepper_file_messages.h @@ -0,0 +1,74 @@ +// Copyright (c) 2012 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. + +// Multiply-included message file, no traditional include guard. +#include "ipc/ipc_message_macros.h" +#include "ipc/ipc_param_traits.h" +#include "ipc/ipc_platform_file.h" +#include "ppapi/shared_impl/dir_contents.h" +#include "ppapi/shared_impl/file_path.h" + +// Singly-included section since need custom serialization. +#ifndef PPAPI_SHARED_IMPL_PEPPER_FILE_MESSAGES_H_ +#define PPAPI_SHARED_IMPL_PEPPER_FILE_MESSAGES_H_ + +namespace IPC { + +template <> +struct ParamTraits<ppapi::PepperFilePath> { + typedef ppapi::PepperFilePath param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, PickleIterator* iter, param_type* p); + static void Log(const param_type& p, std::string* l); +}; + +} // namespace IPC + +#endif // PPAPI_SHARED_IMPL_PEPPER_FILE_MESSAGES_H_ + +#define IPC_MESSAGE_START PepperFileMsgStart + +IPC_STRUCT_TRAITS_BEGIN(ppapi::DirEntry) + IPC_STRUCT_TRAITS_MEMBER(name) + IPC_STRUCT_TRAITS_MEMBER(is_dir) +IPC_STRUCT_TRAITS_END() + +// Trusted Pepper Filesystem messages from the renderer to the browser. + +// Open the file. +IPC_SYNC_MESSAGE_CONTROL2_2(PepperFileMsg_OpenFile, + ppapi::PepperFilePath /* path */, + int /* flags */, + base::PlatformFileError /* error_code */, + IPC::PlatformFileForTransit /* result */) + +// Rename the file. +IPC_SYNC_MESSAGE_CONTROL2_1(PepperFileMsg_RenameFile, + ppapi::PepperFilePath /* from_path */, + ppapi::PepperFilePath /* to_path */, + base::PlatformFileError /* error_code */) + +// Delete the file. +IPC_SYNC_MESSAGE_CONTROL2_1(PepperFileMsg_DeleteFileOrDir, + ppapi::PepperFilePath /* path */, + bool /* recursive */, + base::PlatformFileError /* error_code */) + +// Create the directory. +IPC_SYNC_MESSAGE_CONTROL1_1(PepperFileMsg_CreateDir, + ppapi::PepperFilePath /* path */, + base::PlatformFileError /* error_code */) + +// Query the file's info. +IPC_SYNC_MESSAGE_CONTROL1_2(PepperFileMsg_QueryFile, + ppapi::PepperFilePath /* path */, + base::PlatformFileInfo, /* info */ + base::PlatformFileError /* error_code */) + +// Get the directory's contents. +IPC_SYNC_MESSAGE_CONTROL1_2(PepperFileMsg_GetDirContents, + ppapi::PepperFilePath /* path */, + ppapi::DirContents, /* contents */ + base::PlatformFileError /* error_code */) + diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index 3eba62e..72de40b 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -1206,38 +1206,6 @@ IPC_MESSAGE_ROUTED4(PpapiHostMsg_PPBFlash_WriteClipboardData, int /* clipboard_type */, std::vector<int> /* formats */, std::vector<ppapi::proxy::SerializedVar> /* data */) -IPC_SYNC_MESSAGE_ROUTED3_2(PpapiHostMsg_PPBFlash_OpenFile, - PP_Instance /* instance */, - std::string /* path */, - int32_t /* mode */, - IPC::PlatformFileForTransit /* file_handle */, - int32_t /* result */) -IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlash_RenameFile, - PP_Instance /* instance */, - std::string /* path_from */, - std::string /* path_to */, - int32_t /* result */) -IPC_SYNC_MESSAGE_ROUTED3_1( - PpapiHostMsg_PPBFlash_DeleteFileOrDir, - PP_Instance /* instance */, - std::string /* path */, - PP_Bool /* recursive */, - int32_t /* result */) -IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBFlash_CreateDir, - PP_Instance /* instance */, - std::string /* path */, - int32_t /* result */) -IPC_SYNC_MESSAGE_ROUTED2_2(PpapiHostMsg_PPBFlash_QueryFile, - PP_Instance /* instance */, - std::string /* path */, - PP_FileInfo /* info */, - int32_t /* result */) -IPC_SYNC_MESSAGE_ROUTED2_2( - PpapiHostMsg_PPBFlash_GetDirContents, - PP_Instance /* instance */, - std::string /* path */, - std::vector<ppapi::proxy::SerializedDirEntry> /* entries */, - int32_t /* result */) IPC_SYNC_MESSAGE_ROUTED3_2(PpapiHostMsg_PPBFlash_OpenFileRef, PP_Instance /* instance */, ppapi::HostResource /* file_ref */, diff --git a/ppapi/proxy/ppb_flash_proxy.cc b/ppapi/proxy/ppb_flash_proxy.cc index 901a61f..4692d6e 100644 --- a/ppapi/proxy/ppb_flash_proxy.cc +++ b/ppapi/proxy/ppb_flash_proxy.cc @@ -20,17 +20,21 @@ #include "ppapi/c/private/ppb_flash.h" #include "ppapi/c/private/ppb_flash_print.h" #include "ppapi/proxy/host_dispatcher.h" +#include "ppapi/proxy/pepper_file_messages.h" #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_globals.h" #include "ppapi/proxy/plugin_proxy_delegate.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/proxy_module.h" #include "ppapi/proxy/serialized_var.h" +#include "ppapi/shared_impl/dir_contents.h" +#include "ppapi/shared_impl/file_type_conversion.h" #include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/proxy_lock.h" #include "ppapi/shared_impl/resource.h" #include "ppapi/shared_impl/resource_tracker.h" #include "ppapi/shared_impl/scoped_pp_resource.h" +#include "ppapi/shared_impl/time_conversion.h" #include "ppapi/shared_impl/var.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_instance_api.h" @@ -426,18 +430,6 @@ bool PPB_Flash_Proxy::OnMessageReceived(const IPC::Message& msg) { OnHostMsgReadClipboardData) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_WriteClipboardData, OnHostMsgWriteClipboardData) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_OpenFile, - OnHostMsgOpenFile) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_RenameFile, - OnHostMsgRenameFile) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_DeleteFileOrDir, - OnHostMsgDeleteFileOrDir) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_CreateDir, - OnHostMsgCreateDir) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_QueryFile, - OnHostMsgQueryFile) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetDirContents, - OnHostMsgGetDirContents) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_OpenFileRef, OnHostMsgOpenFileRef) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_QueryFileRef, @@ -668,102 +660,126 @@ void PPB_Flash_Proxy::ClearThreadAdapterForInstance(PP_Instance instance) { g_module_local_thread_adapter->ClearInstanceRouting(instance); } -int32_t PPB_Flash_Proxy::OpenFile(PP_Instance instance, +int32_t PPB_Flash_Proxy::OpenFile(PP_Instance, const char* path, int32_t mode, PP_FileHandle* file) { - if (!g_module_local_thread_adapter) - return PP_ERROR_FAILED; + int flags = 0; + if (!path || + !ppapi::PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || + !file) + return PP_ERROR_BADARGUMENT; - int32_t result = PP_ERROR_FAILED; - IPC::PlatformFileForTransit transit; - g_module_local_thread_adapter->Send(instance, - new PpapiHostMsg_PPBFlash_OpenFile( - API_ID_PPB_FLASH, instance, path, mode, &transit, &result)); - *file = IPC::PlatformFileForTransitToPlatformFile(transit); - return result; + base::PlatformFileError error; + IPC::PlatformFileForTransit transit_file; + ppapi::PepperFilePath pepper_path( + ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, FilePath(path)); + + if (PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser( + new PepperFileMsg_OpenFile(pepper_path, flags, + &error, &transit_file))) { + *file = IPC::PlatformFileForTransitToPlatformFile(transit_file); + } else { + *file = base::kInvalidPlatformFileValue; + error = base::PLATFORM_FILE_ERROR_FAILED; + } + + return ppapi::PlatformFileErrorToPepperError(error); } -int32_t PPB_Flash_Proxy::RenameFile(PP_Instance instance, - const char* path_from, - const char* path_to) { - if (!g_module_local_thread_adapter) - return PP_ERROR_FAILED; +int32_t PPB_Flash_Proxy::RenameFile(PP_Instance, + const char* from_path, + const char* to_path) { + base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; + ppapi::PepperFilePath pepper_from( + ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, FilePath(from_path)); + ppapi::PepperFilePath pepper_to( + ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, FilePath(to_path)); - int32_t result = PP_ERROR_FAILED; - g_module_local_thread_adapter->Send(instance, - new PpapiHostMsg_PPBFlash_RenameFile( - API_ID_PPB_FLASH, instance, path_from, path_to, &result)); - return result; + PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser( + new PepperFileMsg_RenameFile(pepper_from, pepper_to, &error)); + + return ppapi::PlatformFileErrorToPepperError(error); } -int32_t PPB_Flash_Proxy::DeleteFileOrDir(PP_Instance instance, +int32_t PPB_Flash_Proxy::DeleteFileOrDir(PP_Instance, const char* path, PP_Bool recursive) { - if (!g_module_local_thread_adapter) - return PP_ERROR_FAILED; + base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; + ppapi::PepperFilePath pepper_path( + ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, FilePath(path)); - int32_t result = PP_ERROR_FAILED; - g_module_local_thread_adapter->Send(instance, - new PpapiHostMsg_PPBFlash_DeleteFileOrDir( - API_ID_PPB_FLASH, instance, path, recursive, &result)); - return result; + PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser( + new PepperFileMsg_DeleteFileOrDir(pepper_path, recursive, &error)); + + return ppapi::PlatformFileErrorToPepperError(error); } -int32_t PPB_Flash_Proxy::CreateDir(PP_Instance instance, const char* path) { - if (!g_module_local_thread_adapter) - return PP_ERROR_FAILED; +int32_t PPB_Flash_Proxy::CreateDir(PP_Instance, const char* path) { + base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; + ppapi::PepperFilePath pepper_path( + ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, FilePath(path)); - int32_t result = PP_ERROR_FAILED; - g_module_local_thread_adapter->Send(instance, - new PpapiHostMsg_PPBFlash_CreateDir( - API_ID_PPB_FLASH, instance, path, &result)); - return result; + PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser( + new PepperFileMsg_CreateDir(pepper_path, &error)); + + return ppapi::PlatformFileErrorToPepperError(error); } -int32_t PPB_Flash_Proxy::QueryFile(PP_Instance instance, +int32_t PPB_Flash_Proxy::QueryFile(PP_Instance, const char* path, PP_FileInfo* info) { - if (!g_module_local_thread_adapter) - return PP_ERROR_FAILED; + base::PlatformFileInfo file_info; + base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; + ppapi::PepperFilePath pepper_path( + ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, FilePath(path)); - int32_t result = PP_ERROR_FAILED; - g_module_local_thread_adapter->Send(instance, - new PpapiHostMsg_PPBFlash_QueryFile( - API_ID_PPB_FLASH, instance, path, info, &result)); - return result; + PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser( + new PepperFileMsg_QueryFile(pepper_path, &file_info, &error)); + + if (error == base::PLATFORM_FILE_OK) { + info->size = file_info.size; + info->creation_time = TimeToPPTime(file_info.creation_time); + info->last_access_time = TimeToPPTime(file_info.last_accessed); + info->last_modified_time = TimeToPPTime(file_info.last_modified); + info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; + if (file_info.is_directory) + info->type = PP_FILETYPE_DIRECTORY; + else + info->type = PP_FILETYPE_REGULAR; + } + + return ppapi::PlatformFileErrorToPepperError(error); } -int32_t PPB_Flash_Proxy::GetDirContents(PP_Instance instance, +int32_t PPB_Flash_Proxy::GetDirContents(PP_Instance, const char* path, PP_DirContents_Dev** contents) { - if (!g_module_local_thread_adapter) - return PP_ERROR_FAILED; + ppapi::DirContents entries; + base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; + ppapi::PepperFilePath pepper_path( + ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, FilePath(path)); - int32_t result = PP_ERROR_FAILED; - std::vector<SerializedDirEntry> entries; - g_module_local_thread_adapter->Send(instance, - new PpapiHostMsg_PPBFlash_GetDirContents( - API_ID_PPB_FLASH, instance, path, &entries, &result)); - - if (result != PP_OK) - return result; - - // Copy the serialized dir entries to the output struct. - *contents = new PP_DirContents_Dev; - (*contents)->count = static_cast<int32_t>(entries.size()); - (*contents)->entries = new PP_DirEntry_Dev[entries.size()]; - for (size_t i = 0; i < entries.size(); i++) { - const SerializedDirEntry& source = entries[i]; - PP_DirEntry_Dev* dest = &(*contents)->entries[i]; - - char* name_copy = new char[source.name.size() + 1]; - memcpy(name_copy, source.name.c_str(), source.name.size() + 1); - dest->name = name_copy; - dest->is_dir = PP_FromBool(source.is_dir); + PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser( + new PepperFileMsg_GetDirContents(pepper_path, &entries, &error)); + + if (error == base::PLATFORM_FILE_OK) { + // Copy the serialized dir entries to the output struct. + *contents = new PP_DirContents_Dev; + (*contents)->count = static_cast<int32_t>(entries.size()); + (*contents)->entries = new PP_DirEntry_Dev[entries.size()]; + for (size_t i = 0; i < entries.size(); i++) { + const ppapi::DirEntry& source = entries[i]; + PP_DirEntry_Dev* dest = &(*contents)->entries[i]; + std::string name = source.name.AsUTF8Unsafe(); + char* name_copy = new char[name.size() + 1]; + memcpy(name_copy, name.c_str(), name.size() + 1); + dest->name = name_copy; + dest->is_dir = PP_FromBool(source.is_dir); + } } - return result; + return ppapi::PlatformFileErrorToPepperError(error); } int32_t PPB_Flash_Proxy::OpenFileRef(PP_Instance instance, @@ -1029,101 +1045,6 @@ void PPB_Flash_Proxy::OnHostMsgWriteClipboardData( } } -void PPB_Flash_Proxy::OnHostMsgOpenFile( - PP_Instance instance, - const std::string& path, - int32_t mode, - IPC::PlatformFileForTransit* file_handle, - int32_t* result) { - EnterInstanceNoLock enter(instance); - if (enter.succeeded()) { - base::PlatformFile file; - *result = enter.functions()->GetFlashAPI()->OpenFile( - instance, path.c_str(), mode, &file); - *file_handle = PlatformFileToPlatformFileForTransit( - dispatcher(), result, file); - } else { - *result = PP_ERROR_BADARGUMENT; - } -} - -void PPB_Flash_Proxy::OnHostMsgRenameFile(PP_Instance instance, - const std::string& from_path, - const std::string& to_path, - int32_t* result) { - EnterInstanceNoLock enter(instance); - if (enter.succeeded()) { - *result = enter.functions()->GetFlashAPI()->RenameFile( - instance, from_path.c_str(), to_path.c_str()); - } else { - *result = PP_ERROR_BADARGUMENT; - } -} - -void PPB_Flash_Proxy::OnHostMsgDeleteFileOrDir(PP_Instance instance, - const std::string& path, - PP_Bool recursive, - int32_t* result) { - EnterInstanceNoLock enter(instance); - if (enter.succeeded()) { - *result = enter.functions()->GetFlashAPI()->DeleteFileOrDir( - instance, path.c_str(), recursive); - } else { - *result = PP_ERROR_BADARGUMENT; - } -} - -void PPB_Flash_Proxy::OnHostMsgCreateDir(PP_Instance instance, - const std::string& path, - int32_t* result) { - EnterInstanceNoLock enter(instance); - if (enter.succeeded()) { - *result = enter.functions()->GetFlashAPI()->CreateDir( - instance, path.c_str()); - } else { - *result = PP_ERROR_BADARGUMENT; - } -} - -void PPB_Flash_Proxy::OnHostMsgQueryFile(PP_Instance instance, - const std::string& path, - PP_FileInfo* info, - int32_t* result) { - EnterInstanceNoLock enter(instance); - if (enter.succeeded()) { - *result = enter.functions()->GetFlashAPI()->QueryFile( - instance, path.c_str(), info); - } else { - *result = PP_ERROR_BADARGUMENT; - } -} - -void PPB_Flash_Proxy::OnHostMsgGetDirContents( - PP_Instance instance, - const std::string& path, - std::vector<SerializedDirEntry>* entries, - int32_t* result) { - EnterInstanceNoLock enter(instance); - if (enter.failed()) { - *result = PP_ERROR_BADARGUMENT; - return; - } - - PP_DirContents_Dev* contents = NULL; - *result = enter.functions()->GetFlashAPI()->GetDirContents( - instance, path.c_str(), &contents); - if (*result != PP_OK) - return; - - // Convert the list of entries to the serialized version. - entries->resize(contents->count); - for (int32_t i = 0; i < contents->count; i++) { - (*entries)[i].name.assign(contents->entries[i].name); - (*entries)[i].is_dir = PP_ToBool(contents->entries[i].is_dir); - } - enter.functions()->GetFlashAPI()->FreeDirContents(instance, contents); -} - void PPB_Flash_Proxy::OnHostMsgOpenFileRef( PP_Instance instance, const HostResource& host_resource, diff --git a/ppapi/proxy/ppb_flash_proxy.h b/ppapi/proxy/ppb_flash_proxy.h index b9ae9d0..8cbf144 100644 --- a/ppapi/proxy/ppb_flash_proxy.h +++ b/ppapi/proxy/ppb_flash_proxy.h @@ -160,30 +160,6 @@ class PPB_Flash_Proxy : public InterfaceProxy, public PPB_Flash_Shared { int clipboard_type, const std::vector<int>& formats, SerializedVarVectorReceiveInput data_items); - void OnHostMsgOpenFile(PP_Instance instance, - const std::string& path, - int32_t mode, - IPC::PlatformFileForTransit* file_handle, - int32_t* result); - void OnHostMsgRenameFile(PP_Instance instance, - const std::string& path_from, - const std::string& path_to, - int32_t* result); - void OnHostMsgDeleteFileOrDir(PP_Instance instance, - const std::string& path, - PP_Bool recursive, - int32_t* result); - void OnHostMsgCreateDir(PP_Instance instance, - const std::string& path, - int32_t* result); - void OnHostMsgQueryFile(PP_Instance instance, - const std::string& path, - PP_FileInfo* info, - int32_t* result); - void OnHostMsgGetDirContents(PP_Instance instance, - const std::string& path, - std::vector<SerializedDirEntry>* entries, - int32_t* result); void OnHostMsgOpenFileRef(PP_Instance instance, const ppapi::HostResource& host_resource, int32_t mode, diff --git a/ppapi/shared_impl/dir_contents.h b/ppapi/shared_impl/dir_contents.h new file mode 100644 index 0000000..23b1ec3 --- /dev/null +++ b/ppapi/shared_impl/dir_contents.h @@ -0,0 +1,24 @@ +// Copyright (c) 2012 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 PPAPI_SHARED_IMPL_DIR_CONTENTS_H_ +#define PPAPI_SHARED_IMPL_DIR_CONTENTS_H_ + + +#include <vector> + +#include "base/file_path.h" + +namespace ppapi { + +struct DirEntry { + FilePath name; + bool is_dir; +}; + +typedef std::vector<DirEntry> DirContents; + +} // namespace ppapi + +#endif // PPAPI_SHARED_IMPL_DIR_CONTENTS_H_ diff --git a/ppapi/shared_impl/file_path.cc b/ppapi/shared_impl/file_path.cc new file mode 100644 index 0000000..abea27d --- /dev/null +++ b/ppapi/shared_impl/file_path.cc @@ -0,0 +1,51 @@ +// Copyright (c) 2012 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 "ppapi/shared_impl/file_path.h" + +#include <string> + +#if defined(OS_WIN) +#include "base/utf_string_conversions.h" +#endif + +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, const FilePath& path) + : domain_(domain), + path_(path) { + // TODO(viettrungluu): Should we DCHECK() some things here? +} + +// static +PepperFilePath PepperFilePath::MakeAbsolute(const FilePath& path) { + return PepperFilePath(DOMAIN_ABSOLUTE, path); +} + +// static +PepperFilePath PepperFilePath::MakeModuleLocal(const std::string& name, + const char* utf8_path) { + FilePath full_path = GetFilePathFromUTF8(name).Append( + GetFilePathFromUTF8(utf8_path)); + return PepperFilePath(DOMAIN_MODULE_LOCAL, full_path); +} + +} // namespace ppapi diff --git a/ppapi/shared_impl/file_path.h b/ppapi/shared_impl/file_path.h new file mode 100644 index 0000000..9d44f7c --- /dev/null +++ b/ppapi/shared_impl/file_path.h @@ -0,0 +1,47 @@ +// Copyright (c) 2012 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 PPAPI_SHARED_IMPL_FILE_PATH_H_ +#define PPAPI_SHARED_IMPL_FILE_PATH_H_ + +#include <string> + +#include "base/file_path.h" +#include "ppapi/shared_impl/ppapi_shared_export.h" + +namespace ppapi { + +// 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 + }; + + PPAPI_SHARED_EXPORT PepperFilePath(); + PPAPI_SHARED_EXPORT PepperFilePath(Domain d, const FilePath& p); + + static PepperFilePath MakeAbsolute(const FilePath& path); + static PepperFilePath MakeModuleLocal(const std::string& name, + const char* utf8_path); + + Domain domain() const { return domain_; } + const FilePath& path() const { return path_; } + + private: + Domain domain_; + FilePath path_; +}; + +} // namespace ppapi + +#endif // PPAPI_SHARED_IMPL_FILE_PATH_H_ |