OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/flash_file_resource.h" | 5 #include "ppapi/proxy/flash_file_resource.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "ipc/ipc_message.h" | 8 #include "ipc/ipc_message.h" |
9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
10 #include "ppapi/proxy/ppapi_messages.h" | 10 #include "ppapi/proxy/ppapi_messages.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 const char* path, | 53 const char* path, |
54 int32_t mode, | 54 int32_t mode, |
55 PP_FileHandle* file) { | 55 PP_FileHandle* file) { |
56 return OpenFileHelper(path, PepperFilePath::DOMAIN_MODULE_LOCAL, mode, file); | 56 return OpenFileHelper(path, PepperFilePath::DOMAIN_MODULE_LOCAL, mode, file); |
57 } | 57 } |
58 | 58 |
59 int32_t FlashFileResource::RenameFile(PP_Instance /*instance*/, | 59 int32_t FlashFileResource::RenameFile(PP_Instance /*instance*/, |
60 const char* path_from, | 60 const char* path_from, |
61 const char* path_to) { | 61 const char* path_to) { |
62 PepperFilePath pepper_from(PepperFilePath::DOMAIN_MODULE_LOCAL, | 62 PepperFilePath pepper_from(PepperFilePath::DOMAIN_MODULE_LOCAL, |
63 FilePath::FromUTF8Unsafe(path_from)); | 63 base::FilePath::FromUTF8Unsafe(path_from)); |
64 PepperFilePath pepper_to(PepperFilePath::DOMAIN_MODULE_LOCAL, | 64 PepperFilePath pepper_to(PepperFilePath::DOMAIN_MODULE_LOCAL, |
65 FilePath::FromUTF8Unsafe(path_to)); | 65 base::FilePath::FromUTF8Unsafe(path_to)); |
66 | 66 |
67 int32_t error = SyncCall<IPC::Message>( | 67 int32_t error = SyncCall<IPC::Message>( |
68 BROWSER, PpapiHostMsg_FlashFile_RenameFile(pepper_from, pepper_to)); | 68 BROWSER, PpapiHostMsg_FlashFile_RenameFile(pepper_from, pepper_to)); |
69 | 69 |
70 return error; | 70 return error; |
71 } | 71 } |
72 | 72 |
73 int32_t FlashFileResource::DeleteFileOrDir(PP_Instance /*instance*/, | 73 int32_t FlashFileResource::DeleteFileOrDir(PP_Instance /*instance*/, |
74 const char* path, | 74 const char* path, |
75 PP_Bool recursive) { | 75 PP_Bool recursive) { |
76 PepperFilePath pepper_path(PepperFilePath::DOMAIN_MODULE_LOCAL, | 76 PepperFilePath pepper_path(PepperFilePath::DOMAIN_MODULE_LOCAL, |
77 FilePath::FromUTF8Unsafe(path)); | 77 base::FilePath::FromUTF8Unsafe(path)); |
78 | 78 |
79 int32_t error = SyncCall<IPC::Message>( | 79 int32_t error = SyncCall<IPC::Message>( |
80 BROWSER, PpapiHostMsg_FlashFile_DeleteFileOrDir(pepper_path, | 80 BROWSER, PpapiHostMsg_FlashFile_DeleteFileOrDir(pepper_path, |
81 PP_ToBool(recursive))); | 81 PP_ToBool(recursive))); |
82 | 82 |
83 return error; | 83 return error; |
84 } | 84 } |
85 | 85 |
86 int32_t FlashFileResource::CreateDir(PP_Instance /*instance*/, | 86 int32_t FlashFileResource::CreateDir(PP_Instance /*instance*/, |
87 const char* path) { | 87 const char* path) { |
88 PepperFilePath pepper_path(PepperFilePath::DOMAIN_MODULE_LOCAL, | 88 PepperFilePath pepper_path(PepperFilePath::DOMAIN_MODULE_LOCAL, |
89 FilePath::FromUTF8Unsafe(path)); | 89 base::FilePath::FromUTF8Unsafe(path)); |
90 | 90 |
91 int32_t error = SyncCall<IPC::Message>(BROWSER, | 91 int32_t error = SyncCall<IPC::Message>(BROWSER, |
92 PpapiHostMsg_FlashFile_CreateDir(pepper_path)); | 92 PpapiHostMsg_FlashFile_CreateDir(pepper_path)); |
93 | 93 |
94 return error; | 94 return error; |
95 } | 95 } |
96 | 96 |
97 int32_t FlashFileResource::QueryFile(PP_Instance /*instance*/, | 97 int32_t FlashFileResource::QueryFile(PP_Instance /*instance*/, |
98 const char* path, | 98 const char* path, |
99 PP_FileInfo* info) { | 99 PP_FileInfo* info) { |
100 return QueryFileHelper(path, PepperFilePath::DOMAIN_MODULE_LOCAL, info); | 100 return QueryFileHelper(path, PepperFilePath::DOMAIN_MODULE_LOCAL, info); |
101 } | 101 } |
102 | 102 |
103 int32_t FlashFileResource::GetDirContents(PP_Instance /*instance*/, | 103 int32_t FlashFileResource::GetDirContents(PP_Instance /*instance*/, |
104 const char* path, | 104 const char* path, |
105 PP_DirContents_Dev** contents) { | 105 PP_DirContents_Dev** contents) { |
106 ppapi::DirContents entries; | 106 ppapi::DirContents entries; |
107 PepperFilePath pepper_path(PepperFilePath::DOMAIN_MODULE_LOCAL, | 107 PepperFilePath pepper_path(PepperFilePath::DOMAIN_MODULE_LOCAL, |
108 FilePath::FromUTF8Unsafe(path)); | 108 base::FilePath::FromUTF8Unsafe(path)); |
109 | 109 |
110 int32_t error = SyncCall<PpapiPluginMsg_FlashFile_GetDirContentsReply>( | 110 int32_t error = SyncCall<PpapiPluginMsg_FlashFile_GetDirContentsReply>( |
111 BROWSER, PpapiHostMsg_FlashFile_GetDirContents(pepper_path), &entries); | 111 BROWSER, PpapiHostMsg_FlashFile_GetDirContents(pepper_path), &entries); |
112 | 112 |
113 if (error == PP_OK) { | 113 if (error == PP_OK) { |
114 // Copy the serialized dir entries to the output struct. | 114 // Copy the serialized dir entries to the output struct. |
115 *contents = new PP_DirContents_Dev; | 115 *contents = new PP_DirContents_Dev; |
116 (*contents)->count = static_cast<int32_t>(entries.size()); | 116 (*contents)->count = static_cast<int32_t>(entries.size()); |
117 (*contents)->entries = new PP_DirEntry_Dev[entries.size()]; | 117 (*contents)->entries = new PP_DirEntry_Dev[entries.size()]; |
118 for (size_t i = 0; i < entries.size(); i++) { | 118 for (size_t i = 0; i < entries.size(); i++) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 int32_t FlashFileResource::OpenFileHelper(const std::string& path, | 175 int32_t FlashFileResource::OpenFileHelper(const std::string& path, |
176 PepperFilePath::Domain domain_type, | 176 PepperFilePath::Domain domain_type, |
177 int32_t mode, | 177 int32_t mode, |
178 PP_FileHandle* file) { | 178 PP_FileHandle* file) { |
179 int flags = 0; | 179 int flags = 0; |
180 if (path.empty() || | 180 if (path.empty() || |
181 !ppapi::PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || | 181 !ppapi::PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || |
182 !file) | 182 !file) |
183 return PP_ERROR_BADARGUMENT; | 183 return PP_ERROR_BADARGUMENT; |
184 | 184 |
185 PepperFilePath pepper_path(domain_type, FilePath::FromUTF8Unsafe(path)); | 185 PepperFilePath pepper_path(domain_type, base::FilePath::FromUTF8Unsafe(path)); |
186 | 186 |
187 IPC::Message unused; | 187 IPC::Message unused; |
188 ResourceMessageReplyParams reply_params; | 188 ResourceMessageReplyParams reply_params; |
189 int32_t error = GenericSyncCall(BROWSER, | 189 int32_t error = GenericSyncCall(BROWSER, |
190 PpapiHostMsg_FlashFile_OpenFile(pepper_path, flags), &unused, | 190 PpapiHostMsg_FlashFile_OpenFile(pepper_path, flags), &unused, |
191 &reply_params); | 191 &reply_params); |
192 if (error != PP_OK) | 192 if (error != PP_OK) |
193 return error; | 193 return error; |
194 | 194 |
195 IPC::PlatformFileForTransit transit_file; | 195 IPC::PlatformFileForTransit transit_file; |
196 if (!reply_params.TakeFileHandleAtIndex(0, &transit_file)) | 196 if (!reply_params.TakeFileHandleAtIndex(0, &transit_file)) |
197 return PP_ERROR_FAILED; | 197 return PP_ERROR_FAILED; |
198 | 198 |
199 *file = IPC::PlatformFileForTransitToPlatformFile(transit_file); | 199 *file = IPC::PlatformFileForTransitToPlatformFile(transit_file); |
200 return PP_OK; | 200 return PP_OK; |
201 } | 201 } |
202 | 202 |
203 int32_t FlashFileResource::QueryFileHelper(const std::string& path, | 203 int32_t FlashFileResource::QueryFileHelper(const std::string& path, |
204 PepperFilePath::Domain domain_type, | 204 PepperFilePath::Domain domain_type, |
205 PP_FileInfo* info) { | 205 PP_FileInfo* info) { |
206 if (path.empty() || !info) | 206 if (path.empty() || !info) |
207 return PP_ERROR_BADARGUMENT; | 207 return PP_ERROR_BADARGUMENT; |
208 | 208 |
209 base::PlatformFileInfo file_info; | 209 base::PlatformFileInfo file_info; |
210 PepperFilePath pepper_path(domain_type, FilePath::FromUTF8Unsafe(path)); | 210 PepperFilePath pepper_path(domain_type, base::FilePath::FromUTF8Unsafe(path)); |
211 | 211 |
212 int32_t error = SyncCall<PpapiPluginMsg_FlashFile_QueryFileReply>(BROWSER, | 212 int32_t error = SyncCall<PpapiPluginMsg_FlashFile_QueryFileReply>(BROWSER, |
213 PpapiHostMsg_FlashFile_QueryFile(pepper_path), &file_info); | 213 PpapiHostMsg_FlashFile_QueryFile(pepper_path), &file_info); |
214 | 214 |
215 if (error == PP_OK) { | 215 if (error == PP_OK) { |
216 info->size = file_info.size; | 216 info->size = file_info.size; |
217 info->creation_time = TimeToPPTime(file_info.creation_time); | 217 info->creation_time = TimeToPPTime(file_info.creation_time); |
218 info->last_access_time = TimeToPPTime(file_info.last_accessed); | 218 info->last_access_time = TimeToPPTime(file_info.last_accessed); |
219 info->last_modified_time = TimeToPPTime(file_info.last_modified); | 219 info->last_modified_time = TimeToPPTime(file_info.last_modified); |
220 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; | 220 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; |
221 if (file_info.is_directory) | 221 if (file_info.is_directory) |
222 info->type = PP_FILETYPE_DIRECTORY; | 222 info->type = PP_FILETYPE_DIRECTORY; |
223 else | 223 else |
224 info->type = PP_FILETYPE_REGULAR; | 224 info->type = PP_FILETYPE_REGULAR; |
225 } | 225 } |
226 | 226 |
227 return error; | 227 return error; |
228 } | 228 } |
229 | 229 |
230 } // namespace proxy | 230 } // namespace proxy |
231 } // namespace ppapi | 231 } // namespace ppapi |
OLD | NEW |