Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: ppapi/proxy/ppb_flash_file_proxy.cc

Issue 6594099: Pepper/Flapper: Get rid of unimplemented private file ref stuff and implement proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/ppb_flash_file_proxy.h ('k') | webkit/plugins/ppapi/ppb_flash_file_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 24 matching lines...) Expand all
35 } 35 }
36 36
37 void FreeDirContents(PP_Instance /* instance */, 37 void FreeDirContents(PP_Instance /* instance */,
38 PP_DirContents_Dev* contents) { 38 PP_DirContents_Dev* contents) {
39 for (int32_t i = 0; i < contents->count; ++i) 39 for (int32_t i = 0; i < contents->count; ++i)
40 delete[] contents->entries[i].name; 40 delete[] contents->entries[i].name;
41 delete[] contents->entries; 41 delete[] contents->entries;
42 delete contents; 42 delete contents;
43 } 43 }
44 44
45 } // namespace
46
47 // PPB_Flash_File_ModuleLocal --------------------------------------------------
48
49 namespace {
50
45 int32_t OpenModuleLocalFile(PP_Instance instance, 51 int32_t OpenModuleLocalFile(PP_Instance instance,
46 const char* path, 52 const char* path,
47 int32_t mode, 53 int32_t mode,
48 PP_FileHandle* file) { 54 PP_FileHandle* file) {
49 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); 55 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
50 if (!dispatcher) 56 if (!dispatcher)
51 return PP_ERROR_BADARGUMENT; 57 return PP_ERROR_BADARGUMENT;
52 58
53 int32_t result = PP_ERROR_FAILED; 59 int32_t result = PP_ERROR_FAILED;
54 IPC::PlatformFileForTransit transit; 60 IPC::PlatformFileForTransit transit;
55 dispatcher->Send(new PpapiHostMsg_PPBFlashFile_ModuleLocal_OpenFile( 61 dispatcher->Send(new PpapiHostMsg_PPBFlashFile_ModuleLocal_OpenFile(
56 INTERFACE_ID_PPB_FLASH_FILE_MODULELOCAL, 62 INTERFACE_ID_PPB_FLASH_FILE_MODULELOCAL,
57 instance, path, mode, &transit, &result)); 63 instance, path, mode, &transit, &result));
58 *file = IPC::PlatformFileForTransitToPlatformFile(transit); 64 *file = IPC::PlatformFileForTransitToPlatformFile(transit);
59 return result; 65 return result;
60 } 66 }
61 67
62 int32_t RenameModuleLocalFile(PP_Instance instance, 68 int32_t RenameModuleLocalFile(PP_Instance instance,
63 const char* path_from, 69 const char* from_path,
64 const char* path_to) { 70 const char* to_path) {
65 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); 71 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
66 if (!dispatcher) 72 if (!dispatcher)
67 return PP_ERROR_BADARGUMENT; 73 return PP_ERROR_BADARGUMENT;
68 74
69 int32_t result = PP_ERROR_FAILED; 75 int32_t result = PP_ERROR_FAILED;
70 dispatcher->Send(new PpapiHostMsg_PPBFlashFile_ModuleLocal_RenameFile( 76 dispatcher->Send(new PpapiHostMsg_PPBFlashFile_ModuleLocal_RenameFile(
71 INTERFACE_ID_PPB_FLASH_FILE_MODULELOCAL, 77 INTERFACE_ID_PPB_FLASH_FILE_MODULELOCAL,
72 instance, path_from, path_to, &result)); 78 instance, from_path, to_path, &result));
73 return result; 79 return result;
74 } 80 }
75 81
76 int32_t DeleteModuleLocalFileOrDir(PP_Instance instance, 82 int32_t DeleteModuleLocalFileOrDir(PP_Instance instance,
77 const char* path, 83 const char* path,
78 PP_Bool recursive) { 84 PP_Bool recursive) {
79 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); 85 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
80 if (!dispatcher) 86 if (!dispatcher)
81 return PP_ERROR_BADARGUMENT; 87 return PP_ERROR_BADARGUMENT;
82 88
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 143
138 char* name_copy = new char[source.name.size() + 1]; 144 char* name_copy = new char[source.name.size() + 1];
139 memcpy(name_copy, source.name.c_str(), source.name.size() + 1); 145 memcpy(name_copy, source.name.c_str(), source.name.size() + 1);
140 dest->name = name_copy; 146 dest->name = name_copy;
141 dest->is_dir = BoolToPPBool(source.is_dir); 147 dest->is_dir = BoolToPPBool(source.is_dir);
142 } 148 }
143 149
144 return result; 150 return result;
145 } 151 }
146 152
147 const PPB_Flash_File_ModuleLocal flash_file_module_local_interface = { 153 const PPB_Flash_File_ModuleLocal flash_file_modulelocal_interface = {
148 &OpenModuleLocalFile, 154 &OpenModuleLocalFile,
149 &RenameModuleLocalFile, 155 &RenameModuleLocalFile,
150 &DeleteModuleLocalFileOrDir, 156 &DeleteModuleLocalFileOrDir,
151 &CreateModuleLocalDir, 157 &CreateModuleLocalDir,
152 &QueryModuleLocalFile, 158 &QueryModuleLocalFile,
153 &GetModuleLocalDirContents, 159 &GetModuleLocalDirContents,
154 &FreeDirContents, 160 &FreeDirContents,
155 }; 161 };
156 162
157 InterfaceProxy* CreateFlashFileModuleLocalProxy(Dispatcher* dispatcher, 163 InterfaceProxy* CreateFlashFileModuleLocalProxy(Dispatcher* dispatcher,
158 const void* target_interface) { 164 const void* target_interface) {
159 return new PPB_Flash_File_ModuleLocal_Proxy(dispatcher, target_interface); 165 return new PPB_Flash_File_ModuleLocal_Proxy(dispatcher, target_interface);
160 } 166 }
161 167
162 } // namespace 168 } // namespace
163 169
164 PPB_Flash_File_ModuleLocal_Proxy::PPB_Flash_File_ModuleLocal_Proxy( 170 PPB_Flash_File_ModuleLocal_Proxy::PPB_Flash_File_ModuleLocal_Proxy(
165 Dispatcher* dispatcher, 171 Dispatcher* dispatcher,
166 const void* target_interface) 172 const void* target_interface)
167 : InterfaceProxy(dispatcher, target_interface) { 173 : InterfaceProxy(dispatcher, target_interface) {
168 } 174 }
169 175
170 PPB_Flash_File_ModuleLocal_Proxy::~PPB_Flash_File_ModuleLocal_Proxy() { 176 PPB_Flash_File_ModuleLocal_Proxy::~PPB_Flash_File_ModuleLocal_Proxy() {
171 } 177 }
172 178
173 // static 179 // static
174 const InterfaceProxy::Info* PPB_Flash_File_ModuleLocal_Proxy::GetInfo() { 180 const InterfaceProxy::Info* PPB_Flash_File_ModuleLocal_Proxy::GetInfo() {
175 static const Info info = { 181 static const Info info = {
176 &flash_file_module_local_interface, 182 &flash_file_modulelocal_interface,
177 PPB_FLASH_FILE_MODULELOCAL_INTERFACE, 183 PPB_FLASH_FILE_MODULELOCAL_INTERFACE,
178 INTERFACE_ID_PPB_FLASH_FILE_MODULELOCAL, 184 INTERFACE_ID_PPB_FLASH_FILE_MODULELOCAL,
179 true, 185 true,
180 &CreateFlashFileModuleLocalProxy, 186 &CreateFlashFileModuleLocalProxy,
181 }; 187 };
182 return &info; 188 return &info;
183 } 189 }
184 190
185 bool PPB_Flash_File_ModuleLocal_Proxy::OnMessageReceived( 191 bool PPB_Flash_File_ModuleLocal_Proxy::OnMessageReceived(
186 const IPC::Message& msg) { 192 const IPC::Message& msg) {
(...skipping 25 matching lines...) Expand all
212 int32_t* result) { 218 int32_t* result) {
213 base::PlatformFile file; 219 base::PlatformFile file;
214 *result = ppb_flash_file_module_local_target()-> 220 *result = ppb_flash_file_module_local_target()->
215 OpenFile(instance, path.c_str(), mode, &file); 221 OpenFile(instance, path.c_str(), mode, &file);
216 *file_handle = PlatformFileToPlatformFileForTransit( 222 *file_handle = PlatformFileToPlatformFileForTransit(
217 dispatcher(), result, file); 223 dispatcher(), result, file);
218 } 224 }
219 225
220 void PPB_Flash_File_ModuleLocal_Proxy::OnMsgRenameFile( 226 void PPB_Flash_File_ModuleLocal_Proxy::OnMsgRenameFile(
221 PP_Instance instance, 227 PP_Instance instance,
222 const std::string& path_from, 228 const std::string& from_path,
223 const std::string& path_to, 229 const std::string& to_path,
224 int32_t* result) { 230 int32_t* result) {
225 *result = ppb_flash_file_module_local_target()-> 231 *result = ppb_flash_file_module_local_target()->
226 RenameFile(instance, path_from.c_str(), path_to.c_str()); 232 RenameFile(instance, from_path.c_str(), to_path.c_str());
227 } 233 }
228 234
229 void PPB_Flash_File_ModuleLocal_Proxy::OnMsgDeleteFileOrDir( 235 void PPB_Flash_File_ModuleLocal_Proxy::OnMsgDeleteFileOrDir(
230 PP_Instance instance, 236 PP_Instance instance,
231 const std::string& path, 237 const std::string& path,
232 PP_Bool recursive, 238 PP_Bool recursive,
233 int32_t* result) { 239 int32_t* result) {
234 *result = ppb_flash_file_module_local_target()-> 240 *result = ppb_flash_file_module_local_target()->
235 DeleteFileOrDir(instance, path.c_str(), recursive); 241 DeleteFileOrDir(instance, path.c_str(), recursive);
236 } 242 }
(...skipping 26 matching lines...) Expand all
263 269
264 // Convert the list of entries to the serialized version. 270 // Convert the list of entries to the serialized version.
265 entries->resize(contents->count); 271 entries->resize(contents->count);
266 for (int32_t i = 0; i < contents->count; i++) { 272 for (int32_t i = 0; i < contents->count; i++) {
267 (*entries)[i].name.assign(contents->entries[i].name); 273 (*entries)[i].name.assign(contents->entries[i].name);
268 (*entries)[i].is_dir = PPBoolToBool(contents->entries[i].is_dir); 274 (*entries)[i].is_dir = PPBoolToBool(contents->entries[i].is_dir);
269 } 275 }
270 ppb_flash_file_module_local_target()->FreeDirContents(instance, contents); 276 ppb_flash_file_module_local_target()->FreeDirContents(instance, contents);
271 } 277 }
272 278
279 // PPB_Flash_File_FileRef ------------------------------------------------------
280
281 namespace {
282
283 int32_t OpenFileRefFile(PP_Resource file_ref_id,
284 int32_t mode,
285 PP_FileHandle* file) {
286 PluginResource* file_ref =
287 PluginResourceTracker::GetInstance()->GetResourceObject(file_ref_id);
288 if (!file_ref)
289 return PP_ERROR_BADRESOURCE;
290
291 PluginDispatcher* dispatcher =
292 PluginDispatcher::GetForInstance(file_ref->instance());
293 if (!dispatcher)
294 return PP_ERROR_BADARGUMENT;
295
296 int32_t result = PP_ERROR_FAILED;
297 IPC::PlatformFileForTransit transit;
298 dispatcher->Send(new PpapiHostMsg_PPBFlashFile_FileRef_OpenFile(
299 INTERFACE_ID_PPB_FLASH_FILE_FILEREF,
300 file_ref->host_resource(), mode, &transit, &result));
301 *file = IPC::PlatformFileForTransitToPlatformFile(transit);
302 return result;
303 }
304
305 int32_t QueryFileRefFile(PP_Resource file_ref_id,
306 PP_FileInfo_Dev* info) {
307 PluginResource* file_ref =
308 PluginResourceTracker::GetInstance()->GetResourceObject(file_ref_id);
309 if (!file_ref)
310 return PP_ERROR_BADRESOURCE;
311
312 PluginDispatcher* dispatcher =
313 PluginDispatcher::GetForInstance(file_ref->instance());
314 if (!dispatcher)
315 return PP_ERROR_BADARGUMENT;
316
317 int32_t result = PP_ERROR_FAILED;
318 dispatcher->Send(new PpapiHostMsg_PPBFlashFile_FileRef_QueryFile(
319 INTERFACE_ID_PPB_FLASH_FILE_FILEREF,
320 file_ref->host_resource(), info, &result));
321 return result;
322 }
323
324 const PPB_Flash_File_FileRef flash_file_fileref_interface = {
325 &OpenFileRefFile,
326 &QueryFileRefFile,
327 };
328
329 InterfaceProxy* CreateFlashFileFileRefProxy(Dispatcher* dispatcher,
330 const void* target_interface) {
331 return new PPB_Flash_File_FileRef_Proxy(dispatcher, target_interface);
332 }
333
334 } // namespace
335
336 PPB_Flash_File_FileRef_Proxy::PPB_Flash_File_FileRef_Proxy(
337 Dispatcher* dispatcher,
338 const void* target_interface)
339 : InterfaceProxy(dispatcher, target_interface) {
340 }
341
342 PPB_Flash_File_FileRef_Proxy::~PPB_Flash_File_FileRef_Proxy() {
343 }
344
345 // static
346 const InterfaceProxy::Info* PPB_Flash_File_FileRef_Proxy::GetInfo() {
347 static const Info info = {
348 &flash_file_fileref_interface,
349 PPB_FLASH_FILE_FILEREF_INTERFACE,
350 INTERFACE_ID_PPB_FLASH_FILE_FILEREF,
351 true,
352 &CreateFlashFileFileRefProxy,
353 };
354 return &info;
355 }
356
357 bool PPB_Flash_File_FileRef_Proxy::OnMessageReceived(
358 const IPC::Message& msg) {
359 bool handled = true;
360 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_File_FileRef_Proxy, msg)
361 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashFile_FileRef_OpenFile,
362 OnMsgOpenFile)
363 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashFile_FileRef_QueryFile,
364 OnMsgQueryFile)
365 IPC_MESSAGE_UNHANDLED(handled = false)
366 IPC_END_MESSAGE_MAP()
367 // TODO(brettw) handle bad messages!
368 return handled;
369 }
370
371 void PPB_Flash_File_FileRef_Proxy::OnMsgOpenFile(
372 const HostResource& host_resource,
373 int32_t mode,
374 IPC::PlatformFileForTransit* file_handle,
375 int32_t* result) {
376 base::PlatformFile file;
377 *result = ppb_flash_file_module_local_target()->
378 OpenFile(host_resource.host_resource(), mode, &file);
379 *file_handle = PlatformFileToPlatformFileForTransit(
380 dispatcher(), result, file);
381 }
382
383 void PPB_Flash_File_FileRef_Proxy::OnMsgQueryFile(
384 const HostResource& host_resource,
385 PP_FileInfo_Dev* info,
386 int32_t* result) {
387 *result = ppb_flash_file_module_local_target()->
388 QueryFile(host_resource.host_resource(), info);
389 }
390
273 } // namespace proxy 391 } // namespace proxy
274 } // namespace pp 392 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_flash_file_proxy.h ('k') | webkit/plugins/ppapi/ppb_flash_file_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698