| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/proxy/ppb_flash_file_proxy.h" | 5 #include "ppapi/proxy/ppb_flash_file_proxy.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "ppapi/c/dev/pp_file_info_dev.h" | 9 #include "ppapi/c/dev/pp_file_info_dev.h" |
| 10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
| 11 #include "ppapi/c/private/ppb_flash_file.h" | 11 #include "ppapi/c/private/ppb_flash_file.h" |
| 12 #include "ppapi/proxy/plugin_dispatcher.h" | 12 #include "ppapi/proxy/plugin_dispatcher.h" |
| 13 #include "ppapi/proxy/plugin_resource.h" | 13 #include "ppapi/proxy/plugin_resource.h" |
| 14 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
| 15 | 15 |
| 16 namespace pp { | 16 namespace pp { |
| 17 namespace proxy { | 17 namespace proxy { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // Given an error code and a handle result from a Pepper API call, converts | 21 // Given an error code and a handle result from a Pepper API call, converts to a |
| 22 // to a PlatformFileForTransit, possibly also updating the error value if | 22 // PlatformFileForTransit by sharing with the other side, closing the original |
| 23 // an error occurred. | 23 // handle, possibly also updating the error value if an error occurred. |
| 24 IPC::PlatformFileForTransit PlatformFileToPlatformFileForTransit( | 24 IPC::PlatformFileForTransit PlatformFileToPlatformFileForTransit( |
| 25 Dispatcher* dispatcher, |
| 25 int32_t* error, | 26 int32_t* error, |
| 26 base::PlatformFile file) { | 27 base::PlatformFile file) { |
| 27 if (*error != PP_OK) | 28 if (*error != PP_OK) |
| 28 return IPC::InvalidPlatformFileForTransit(); | 29 return IPC::InvalidPlatformFileForTransit(); |
| 29 #if defined(OS_WIN) | 30 IPC::PlatformFileForTransit out_handle = |
| 30 /* TODO(brettw): figure out how to get the target process handle. | 31 dispatcher->ShareHandleWithRemote(file, true); |
| 31 HANDLE result; | 32 if (out_handle == IPC::InvalidPlatformFileForTransit()) |
| 32 if (!::DuplicateHandle(::GetCurrentProcess(), file, | |
| 33 target_process, &result, 0, false, | |
| 34 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { | |
| 35 *error = PP_ERROR_NOACCESS; | 33 *error = PP_ERROR_NOACCESS; |
| 36 return INVALID_HANDLE_VALUE; | 34 return out_handle; |
| 37 } | |
| 38 return result; | |
| 39 */ | |
| 40 NOTIMPLEMENTED(); | |
| 41 *error = PP_ERROR_NOACCESS; | |
| 42 return INVALID_HANDLE_VALUE; | |
| 43 #elif defined(OS_POSIX) | |
| 44 return base::FileDescriptor(file, true); | |
| 45 #endif | |
| 46 } | 35 } |
| 47 | 36 |
| 48 void FreeDirContents(PP_Instance /* instance */, | 37 void FreeDirContents(PP_Instance /* instance */, |
| 49 PP_DirContents_Dev* contents) { | 38 PP_DirContents_Dev* contents) { |
| 50 for (int32_t i = 0; i < contents->count; ++i) | 39 for (int32_t i = 0; i < contents->count; ++i) |
| 51 delete[] contents->entries[i].name; | 40 delete[] contents->entries[i].name; |
| 52 delete[] contents->entries; | 41 delete[] contents->entries; |
| 53 delete contents; | 42 delete contents; |
| 54 } | 43 } |
| 55 | 44 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 206 |
| 218 void PPB_Flash_File_ModuleLocal_Proxy::OnMsgOpenFile( | 207 void PPB_Flash_File_ModuleLocal_Proxy::OnMsgOpenFile( |
| 219 PP_Instance instance, | 208 PP_Instance instance, |
| 220 const std::string& path, | 209 const std::string& path, |
| 221 int32_t mode, | 210 int32_t mode, |
| 222 IPC::PlatformFileForTransit* file_handle, | 211 IPC::PlatformFileForTransit* file_handle, |
| 223 int32_t* result) { | 212 int32_t* result) { |
| 224 base::PlatformFile file; | 213 base::PlatformFile file; |
| 225 *result = ppb_flash_file_module_local_target()-> | 214 *result = ppb_flash_file_module_local_target()-> |
| 226 OpenFile(instance, path.c_str(), mode, &file); | 215 OpenFile(instance, path.c_str(), mode, &file); |
| 227 *file_handle = PlatformFileToPlatformFileForTransit(result, file); | 216 *file_handle = PlatformFileToPlatformFileForTransit( |
| 217 dispatcher(), result, file); |
| 228 } | 218 } |
| 229 | 219 |
| 230 void PPB_Flash_File_ModuleLocal_Proxy::OnMsgRenameFile( | 220 void PPB_Flash_File_ModuleLocal_Proxy::OnMsgRenameFile( |
| 231 PP_Instance instance, | 221 PP_Instance instance, |
| 232 const std::string& path_from, | 222 const std::string& path_from, |
| 233 const std::string& path_to, | 223 const std::string& path_to, |
| 234 int32_t* result) { | 224 int32_t* result) { |
| 235 *result = ppb_flash_file_module_local_target()-> | 225 *result = ppb_flash_file_module_local_target()-> |
| 236 RenameFile(instance, path_from.c_str(), path_to.c_str()); | 226 RenameFile(instance, path_from.c_str(), path_to.c_str()); |
| 237 } | 227 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 entries->resize(contents->count); | 265 entries->resize(contents->count); |
| 276 for (int32_t i = 0; i < contents->count; i++) { | 266 for (int32_t i = 0; i < contents->count; i++) { |
| 277 (*entries)[i].name.assign(contents->entries[i].name); | 267 (*entries)[i].name.assign(contents->entries[i].name); |
| 278 (*entries)[i].is_dir = PPBoolToBool(contents->entries[i].is_dir); | 268 (*entries)[i].is_dir = PPBoolToBool(contents->entries[i].is_dir); |
| 279 } | 269 } |
| 280 ppb_flash_file_module_local_target()->FreeDirContents(instance, contents); | 270 ppb_flash_file_module_local_target()->FreeDirContents(instance, contents); |
| 281 } | 271 } |
| 282 | 272 |
| 283 } // namespace proxy | 273 } // namespace proxy |
| 284 } // namespace pp | 274 } // namespace pp |
| OLD | NEW |