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/ppb_file_io_proxy.h" | 5 #include "ppapi/proxy/ppb_file_io_proxy.h" |
6 | 6 |
7 #include "ppapi/c/pp_errors.h" | 7 #include "ppapi/c/pp_errors.h" |
8 #include "ppapi/proxy/enter_proxy.h" | 8 #include "ppapi/proxy/enter_proxy.h" |
9 #include "ppapi/proxy/ppapi_messages.h" | 9 #include "ppapi/proxy/ppapi_messages.h" |
10 #include "ppapi/proxy/ppb_file_ref_proxy.h" | 10 #include "ppapi/proxy/ppb_file_ref_proxy.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // The maximum size we'll support reading in one chunk. The renderer process | 24 // The maximum size we'll support reading in one chunk. The renderer process |
25 // must allocate a buffer sized according to the request of the plugin. To | 25 // must allocate a buffer sized according to the request of the plugin. To |
26 // keep things from getting out of control, we cap the read size to this value. | 26 // keep things from getting out of control, we cap the read size to this value. |
27 // This should generally be OK since the API specifies that it may perform a | 27 // This should generally be OK since the API specifies that it may perform a |
28 // partial read. | 28 // partial read. |
29 static const int32_t kMaxReadSize = 33554432; // 32MB | 29 static const int32_t kMaxReadSize = 33554432; // 32MB |
30 | 30 |
| 31 #if !defined(OS_NACL) |
31 typedef EnterHostFromHostResourceForceCallback<PPB_FileIO_API> EnterHostFileIO; | 32 typedef EnterHostFromHostResourceForceCallback<PPB_FileIO_API> EnterHostFileIO; |
| 33 #endif |
32 typedef EnterPluginFromHostResource<PPB_FileIO_API> EnterPluginFileIO; | 34 typedef EnterPluginFromHostResource<PPB_FileIO_API> EnterPluginFileIO; |
33 | 35 |
34 class FileIO : public PPB_FileIO_Shared { | 36 class FileIO : public PPB_FileIO_Shared { |
35 public: | 37 public: |
36 explicit FileIO(const HostResource& host_resource); | 38 explicit FileIO(const HostResource& host_resource); |
37 virtual ~FileIO(); | 39 virtual ~FileIO(); |
38 | 40 |
39 // PPB_FileIO_API implementation (not provided by FileIOImpl). | 41 // PPB_FileIO_API implementation (not provided by FileIOImpl). |
40 virtual void Close() OVERRIDE; | 42 virtual void Close() OVERRIDE; |
41 virtual int32_t GetOSFileDescriptor() OVERRIDE; | 43 virtual int32_t GetOSFileDescriptor() OVERRIDE; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 dispatcher->Send(new PpapiHostMsg_PPBFileIO_Create(kApiID, instance, | 213 dispatcher->Send(new PpapiHostMsg_PPBFileIO_Create(kApiID, instance, |
212 &result)); | 214 &result)); |
213 if (result.is_null()) | 215 if (result.is_null()) |
214 return 0; | 216 return 0; |
215 return (new FileIO(result))->GetReference(); | 217 return (new FileIO(result))->GetReference(); |
216 } | 218 } |
217 | 219 |
218 bool PPB_FileIO_Proxy::OnMessageReceived(const IPC::Message& msg) { | 220 bool PPB_FileIO_Proxy::OnMessageReceived(const IPC::Message& msg) { |
219 bool handled = true; | 221 bool handled = true; |
220 IPC_BEGIN_MESSAGE_MAP(PPB_FileIO_Proxy, msg) | 222 IPC_BEGIN_MESSAGE_MAP(PPB_FileIO_Proxy, msg) |
| 223 #if !defined(OS_NACL) |
221 // Plugin -> host message. | 224 // Plugin -> host message. |
222 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Create, OnHostMsgCreate) | 225 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Create, OnHostMsgCreate) |
223 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Open, OnHostMsgOpen) | 226 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Open, OnHostMsgOpen) |
224 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Close, OnHostMsgClose) | 227 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Close, OnHostMsgClose) |
225 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Query, OnHostMsgQuery) | 228 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Query, OnHostMsgQuery) |
226 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Touch, OnHostMsgTouch) | 229 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Touch, OnHostMsgTouch) |
227 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Read, OnHostMsgRead) | 230 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Read, OnHostMsgRead) |
228 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Write, OnHostMsgWrite) | 231 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Write, OnHostMsgWrite) |
229 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_SetLength, OnHostMsgSetLength) | 232 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_SetLength, OnHostMsgSetLength) |
230 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Flush, OnHostMsgFlush) | 233 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Flush, OnHostMsgFlush) |
231 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_WillWrite, OnHostMsgWillWrite) | 234 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_WillWrite, OnHostMsgWillWrite) |
232 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_WillSetLength, | 235 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_WillSetLength, |
233 OnHostMsgWillSetLength) | 236 OnHostMsgWillSetLength) |
234 | 237 #endif // !defined(OS_NACL) |
235 // Host -> plugin messages. | 238 // Host -> plugin messages. |
236 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileIO_GeneralComplete, | 239 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileIO_GeneralComplete, |
237 OnPluginMsgGeneralComplete) | 240 OnPluginMsgGeneralComplete) |
238 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileIO_OpenFileComplete, | 241 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileIO_OpenFileComplete, |
239 OnPluginMsgOpenFileComplete) | 242 OnPluginMsgOpenFileComplete) |
240 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileIO_QueryComplete, | 243 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileIO_QueryComplete, |
241 OnPluginMsgQueryComplete) | 244 OnPluginMsgQueryComplete) |
242 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileIO_ReadComplete, | 245 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileIO_ReadComplete, |
243 OnPluginMsgReadComplete) | 246 OnPluginMsgReadComplete) |
244 IPC_MESSAGE_UNHANDLED(handled = false) | 247 IPC_MESSAGE_UNHANDLED(handled = false) |
245 IPC_END_MESSAGE_MAP() | 248 IPC_END_MESSAGE_MAP() |
246 return handled; | 249 return handled; |
247 } | 250 } |
248 | 251 |
| 252 #if !defined(OS_NACL) |
249 void PPB_FileIO_Proxy::OnHostMsgCreate(PP_Instance instance, | 253 void PPB_FileIO_Proxy::OnHostMsgCreate(PP_Instance instance, |
250 HostResource* result) { | 254 HostResource* result) { |
251 thunk::EnterResourceCreation enter(instance); | 255 thunk::EnterResourceCreation enter(instance); |
252 if (enter.succeeded()) { | 256 if (enter.succeeded()) { |
253 result->SetHostResource(instance, | 257 result->SetHostResource(instance, |
254 enter.functions()->CreateFileIO(instance)); | 258 enter.functions()->CreateFileIO(instance)); |
255 } | 259 } |
256 } | 260 } |
257 | 261 |
258 void PPB_FileIO_Proxy::OnHostMsgOpen(const HostResource& host_resource, | 262 void PPB_FileIO_Proxy::OnHostMsgOpen(const HostResource& host_resource, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 } | 367 } |
364 | 368 |
365 void PPB_FileIO_Proxy::OnHostMsgWillSetLength(const HostResource& host_resource, | 369 void PPB_FileIO_Proxy::OnHostMsgWillSetLength(const HostResource& host_resource, |
366 int64_t length) { | 370 int64_t length) { |
367 EnterHostFileIO enter(host_resource, callback_factory_, | 371 EnterHostFileIO enter(host_resource, callback_factory_, |
368 &PPB_FileIO_Proxy::GeneralCallbackCompleteInHost, | 372 &PPB_FileIO_Proxy::GeneralCallbackCompleteInHost, |
369 host_resource); | 373 host_resource); |
370 if (enter.succeeded()) | 374 if (enter.succeeded()) |
371 enter.SetResult(enter.object()->WillSetLength(length, enter.callback())); | 375 enter.SetResult(enter.object()->WillSetLength(length, enter.callback())); |
372 } | 376 } |
| 377 #endif // !defined(OS_NACL) |
373 | 378 |
374 void PPB_FileIO_Proxy::OnPluginMsgGeneralComplete( | 379 void PPB_FileIO_Proxy::OnPluginMsgGeneralComplete( |
375 const HostResource& host_resource, | 380 const HostResource& host_resource, |
376 int32_t result) { | 381 int32_t result) { |
377 EnterPluginFileIO enter(host_resource); | 382 EnterPluginFileIO enter(host_resource); |
378 if (enter.succeeded()) | 383 if (enter.succeeded()) |
379 static_cast<FileIO*>(enter.object())->ExecuteGeneralCallback(result); | 384 static_cast<FileIO*>(enter.object())->ExecuteGeneralCallback(result); |
380 } | 385 } |
381 | 386 |
382 void PPB_FileIO_Proxy::OnPluginMsgOpenFileComplete( | 387 void PPB_FileIO_Proxy::OnPluginMsgOpenFileComplete( |
(...skipping 20 matching lines...) Expand all Loading... |
403 EnterPluginFileIO enter(host_resource); | 408 EnterPluginFileIO enter(host_resource); |
404 if (enter.succeeded()) { | 409 if (enter.succeeded()) { |
405 // The result code should contain the data size if it's positive. | 410 // The result code should contain the data size if it's positive. |
406 DCHECK((result < 0 && data.size() == 0) || | 411 DCHECK((result < 0 && data.size() == 0) || |
407 result == static_cast<int32_t>(data.size())); | 412 result == static_cast<int32_t>(data.size())); |
408 static_cast<FileIO*>(enter.object())->ExecuteReadCallback(result, | 413 static_cast<FileIO*>(enter.object())->ExecuteReadCallback(result, |
409 data.data()); | 414 data.data()); |
410 } | 415 } |
411 } | 416 } |
412 | 417 |
| 418 #if !defined(OS_NACL) |
413 void PPB_FileIO_Proxy::GeneralCallbackCompleteInHost( | 419 void PPB_FileIO_Proxy::GeneralCallbackCompleteInHost( |
414 int32_t pp_error, | 420 int32_t pp_error, |
415 const HostResource& host_resource) { | 421 const HostResource& host_resource) { |
416 Send(new PpapiMsg_PPBFileIO_GeneralComplete(kApiID, host_resource, pp_error)); | 422 Send(new PpapiMsg_PPBFileIO_GeneralComplete(kApiID, host_resource, pp_error)); |
417 } | 423 } |
418 | 424 |
419 void PPB_FileIO_Proxy::OpenFileCallbackCompleteInHost( | 425 void PPB_FileIO_Proxy::OpenFileCallbackCompleteInHost( |
420 int32_t pp_error, | 426 int32_t pp_error, |
421 const HostResource& host_resource) { | 427 const HostResource& host_resource) { |
422 Send(new PpapiMsg_PPBFileIO_OpenFileComplete(kApiID, host_resource, | 428 Send(new PpapiMsg_PPBFileIO_OpenFileComplete(kApiID, host_resource, |
(...skipping 15 matching lines...) Expand all Loading... |
438 std::string* data) { | 444 std::string* data) { |
439 // Only send the amount of data in the string that was actually read. | 445 // Only send the amount of data in the string that was actually read. |
440 if (pp_error >= 0) { | 446 if (pp_error >= 0) { |
441 DCHECK(pp_error <= static_cast<int32_t>(data->size())); | 447 DCHECK(pp_error <= static_cast<int32_t>(data->size())); |
442 data->resize(pp_error); | 448 data->resize(pp_error); |
443 } | 449 } |
444 Send(new PpapiMsg_PPBFileIO_ReadComplete(kApiID, host_resource, pp_error, | 450 Send(new PpapiMsg_PPBFileIO_ReadComplete(kApiID, host_resource, pp_error, |
445 *data)); | 451 *data)); |
446 delete data; | 452 delete data; |
447 } | 453 } |
| 454 #endif // !defined(OS_NACL) |
448 | 455 |
449 } // namespace proxy | 456 } // namespace proxy |
450 } // namespace ppapi | 457 } // namespace ppapi |
OLD | NEW |