Index: content/ppapi_plugin/ppapi_thread.cc |
=================================================================== |
--- content/ppapi_plugin/ppapi_thread.cc (revision 138610) |
+++ content/ppapi_plugin/ppapi_thread.cc (working copy) |
@@ -13,6 +13,7 @@ |
#include "base/utf_string_conversions.h" |
#include "content/common/child_process.h" |
#include "content/common/child_process_messages.h" |
+#include "content/common/pepper_file_messages.h" |
#include "content/ppapi_plugin/broker_process_dispatcher.h" |
#include "content/ppapi_plugin/plugin_process_dispatcher.h" |
#include "content/ppapi_plugin/ppapi_webkitplatformsupport_impl.h" |
@@ -26,6 +27,8 @@ |
#include "ppapi/proxy/plugin_globals.h" |
#include "ppapi/proxy/ppapi_messages.h" |
#include "ppapi/proxy/interface_list.h" |
+#include "ppapi/shared_impl/file_type_conversion.h" |
+#include "ppapi/shared_impl/time_conversion.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
#include "webkit/plugins/plugin_switches.h" |
@@ -164,6 +167,124 @@ |
#endif |
} |
+int32_t PpapiThread::SendOpenFileRequestToBrowser(const char* path, |
+ int32_t mode, |
+ PP_FileHandle* file) { |
+ int flags = 0; |
+ if (!path || |
+ !ppapi::PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || |
+ !file) |
+ return PP_ERROR_BADARGUMENT; |
+ |
+ base::PlatformFileError error; |
+ IPC::PlatformFileForTransit transit_file; |
+ webkit::ppapi::PepperFilePath pepper_path( |
+ webkit::ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, |
+ FilePath::FromUTF8Unsafe(path)); |
+ |
+ if (Send(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 PpapiThread::SendRenameFileRequestToBrowser(const char* from_path, |
+ const char* to_path) { |
+ base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; |
+ webkit::ppapi::PepperFilePath pepper_from( |
+ webkit::ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, |
+ FilePath::FromUTF8Unsafe(from_path)); |
+ webkit::ppapi::PepperFilePath pepper_to( |
+ webkit::ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, |
+ FilePath::FromUTF8Unsafe(to_path)); |
+ |
+ Send(new PepperFileMsg_RenameFile(pepper_from, pepper_to, &error)); |
+ return ppapi::PlatformFileErrorToPepperError(error); |
+} |
+ |
+int32_t PpapiThread::SendDeleteFileOrDirRequestToBrowser(const char* path, |
+ PP_Bool recursive) { |
+ base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; |
brettw
2012/05/29 18:14:15
Is it possible to put all of this message construc
|
+ webkit::ppapi::PepperFilePath pepper_path( |
+ webkit::ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, |
+ FilePath::FromUTF8Unsafe(path)); |
+ |
+ Send(new PepperFileMsg_DeleteFileOrDir( |
+ pepper_path, PP_ToBool(recursive), &error)); |
+ |
+ return ppapi::PlatformFileErrorToPepperError(error); |
+} |
+ |
+int32_t PpapiThread::SendCreateDirRequestToBrowser(const char* path) { |
+ base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; |
+ webkit::ppapi::PepperFilePath pepper_path( |
+ webkit::ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, |
+ FilePath::FromUTF8Unsafe(path)); |
+ |
+ Send(new PepperFileMsg_CreateDir(pepper_path, &error)); |
+ return ppapi::PlatformFileErrorToPepperError(error); |
+} |
+ |
+int32_t PpapiThread::SendQueryFileRequestToBrowser(const char* path, |
+ PP_FileInfo* info) { |
+ base::PlatformFileInfo file_info; |
+ base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; |
+ webkit::ppapi::PepperFilePath pepper_path( |
+ webkit::ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, |
+ FilePath::FromUTF8Unsafe(path)); |
+ |
+ Send(new PepperFileMsg_QueryFile(pepper_path, &file_info, &error)); |
+ |
+ if (error == base::PLATFORM_FILE_OK) { |
+ info->size = file_info.size; |
+ info->creation_time = ppapi::TimeToPPTime(file_info.creation_time); |
+ info->last_access_time = ppapi::TimeToPPTime(file_info.last_accessed); |
+ info->last_modified_time = ppapi::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 PpapiThread::SendGetDirContentsRequestToBrowser( |
+ const char* path, |
+ PP_DirContents_Dev** contents) { |
+ webkit::ppapi::DirContents entries; |
+ base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; |
+ webkit::ppapi::PepperFilePath pepper_path( |
+ webkit::ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, |
+ FilePath::FromUTF8Unsafe(path)); |
+ |
+ Send(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 webkit::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 ppapi::PlatformFileErrorToPepperError(error); |
+} |
+ |
uint32 PpapiThread::Register(ppapi::proxy::PluginDispatcher* plugin_dispatcher) { |
if (!plugin_dispatcher || |
plugin_dispatchers_.size() >= std::numeric_limits<uint32>::max()) { |