diff options
Diffstat (limited to 'ppapi/proxy')
-rw-r--r-- | ppapi/proxy/interface_list.cc | 3 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 53 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_param_traits.cc | 3 | ||||
-rw-r--r-- | ppapi/proxy/ppb_file_io_proxy.cc | 442 | ||||
-rw-r--r-- | ppapi/proxy/ppb_file_io_proxy.h | 93 | ||||
-rw-r--r-- | ppapi/proxy/ppb_file_ref_proxy.cc | 9 | ||||
-rw-r--r-- | ppapi/proxy/ppb_file_ref_proxy.h | 4 | ||||
-rw-r--r-- | ppapi/proxy/resource_creation_proxy.cc | 4 |
8 files changed, 607 insertions, 4 deletions
diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc index da978e1..2d5b90b 100644 --- a/ppapi/proxy/interface_list.cc +++ b/ppapi/proxy/interface_list.cc @@ -24,6 +24,7 @@ #include "ppapi/c/ppb_audio_config.h" #include "ppapi/c/ppb_audio.h" #include "ppapi/c/ppb_core.h" +#include "ppapi/c/ppb_file_io.h" #include "ppapi/c/ppb_file_ref.h" #include "ppapi/c/ppb_file_system.h" #include "ppapi/c/ppb_fullscreen.h" @@ -53,6 +54,7 @@ #include "ppapi/c/private/ppb_tcp_socket_private.h" #include "ppapi/c/private/ppb_udp_socket_private.h" #include "ppapi/c/trusted/ppb_broker_trusted.h" +#include "ppapi/c/trusted/ppb_file_io_trusted.h" #include "ppapi/c/trusted/ppb_url_loader_trusted.h" #include "ppapi/proxy/interface_proxy.h" #include "ppapi/proxy/ppb_audio_input_proxy.h" @@ -62,6 +64,7 @@ #include "ppapi/proxy/ppb_core_proxy.h" #include "ppapi/proxy/ppb_cursor_control_proxy.h" #include "ppapi/proxy/ppb_file_chooser_proxy.h" +#include "ppapi/proxy/ppb_file_io_proxy.h" #include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/proxy/ppb_file_system_proxy.h" #include "ppapi/proxy/ppb_flash_clipboard_proxy.h" diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index b894db9..32ac229 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -238,6 +238,22 @@ IPC_MESSAGE_ROUTED3( int32_t /* result_code (will be != PP_OK on failure */, std::vector<ppapi::PPB_FileRef_CreateInfo> /* chosen_files */) +// PPB_FileIO. +IPC_MESSAGE_ROUTED2(PpapiMsg_PPBFileIO_GeneralComplete, + ppapi::HostResource /* file_io */, + int32_t /* result */) +IPC_MESSAGE_ROUTED2(PpapiMsg_PPBFileIO_OpenFileComplete, + ppapi::HostResource /* file_io */, + int32_t /* result */) +IPC_MESSAGE_ROUTED3(PpapiMsg_PPBFileIO_QueryComplete, + ppapi::HostResource /* file_io */, + int32_t /* result */, + PP_FileInfo /* info */) +IPC_MESSAGE_ROUTED3(PpapiMsg_PPBFileIO_ReadComplete, + ppapi::HostResource /* file_io */, + int32_t /* result */, + std::string /* data */) + // PPB_FileRef. IPC_MESSAGE_ROUTED3( PpapiMsg_PPBFileRef_CallbackComplete, @@ -555,6 +571,43 @@ IPC_MESSAGE_ROUTED4(PpapiHostMsg_PPBFileChooser_Show, std::string /* suggested_file_name */, bool /* require_user_gesture */) +// PPB_FileIO. +IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBFileIO_Create, + PP_Instance /* instance */, + ppapi::HostResource /* result */) +IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBFileIO_Open, + ppapi::HostResource /* host_resource */, + ppapi::HostResource /* file_ref_resource */, + int32_t /* open_flags */) +IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBFileIO_Close, + ppapi::HostResource /* host_resource */) +IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBFileIO_Query, + ppapi::HostResource /* host_resource */) +IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBFileIO_Touch, + ppapi::HostResource /* host_resource */, + PP_Time /* last_access_time */, + PP_Time /* last_modified_time */) +IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBFileIO_Read, + ppapi::HostResource /* host_resource */, + int64_t /* offset */, + int32_t /* bytes_to_read */) +IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBFileIO_Write, + ppapi::HostResource /* host_resource */, + int64_t /* offset */, + std::string /* data */) +IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBFileIO_SetLength, + ppapi::HostResource /* host_resource */, + int64_t /* length */) +IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBFileIO_Flush, + ppapi::HostResource /* host_resource */) +IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBFileIO_WillWrite, + ppapi::HostResource /* host_resource */, + int64_t /* offset */, + int32_t /* bytes_to_write */) +IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBFileIO_WillSetLength, + ppapi::HostResource /* host_resource */, + int64_t /* length */) + // PPB_FileRef. IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBFileRef_Create, ppapi::HostResource /* file_system */, diff --git a/ppapi/proxy/ppapi_param_traits.cc b/ppapi/proxy/ppapi_param_traits.cc index ac66648..ca03910 100644 --- a/ppapi/proxy/ppapi_param_traits.cc +++ b/ppapi/proxy/ppapi_param_traits.cc @@ -124,7 +124,8 @@ bool ParamTraits<PP_FileInfo>::Read(const Message* m, void** iter, type != PP_FILETYPE_OTHER) return false; r->type = static_cast<PP_FileType>(type); - if (system_type != PP_FILESYSTEMTYPE_EXTERNAL && + if (system_type != PP_FILESYSTEMTYPE_INVALID && + system_type != PP_FILESYSTEMTYPE_EXTERNAL && system_type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && system_type != PP_FILESYSTEMTYPE_LOCALTEMPORARY) return false; diff --git a/ppapi/proxy/ppb_file_io_proxy.cc b/ppapi/proxy/ppb_file_io_proxy.cc new file mode 100644 index 0000000..0acd3ac --- /dev/null +++ b/ppapi/proxy/ppb_file_io_proxy.cc @@ -0,0 +1,442 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/proxy/ppb_file_io_proxy.h" + +#include "ppapi/c/pp_errors.h" +#include "ppapi/proxy/enter_proxy.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/proxy/ppb_file_ref_proxy.h" +#include "ppapi/shared_impl/ppapi_globals.h" +#include "ppapi/shared_impl/ppb_file_io_shared.h" +#include "ppapi/shared_impl/resource.h" +#include "ppapi/shared_impl/resource_tracker.h" + +using ppapi::thunk::PPB_FileIO_API; +using ppapi::thunk::PPB_FileRef_API; + +namespace ppapi { +namespace proxy { + +namespace { + +// The maximum size we'll support reading in one chunk. The renderer process +// must allocate a buffer sized according to the request of the plugin. To +// keep things from getting out of control, we cap the read size to this value. +// This should generally be OK since the API specifies that it may perform a +// partial read. +static const int32_t kMaxReadSize = 33554432; // 32MB + +typedef EnterHostFromHostResourceForceCallback<PPB_FileIO_API> EnterHostFileIO; +typedef EnterPluginFromHostResource<PPB_FileIO_API> EnterPluginFileIO; + +class FileIO : public PPB_FileIO_Shared { + public: + explicit FileIO(const HostResource& host_resource); + virtual ~FileIO(); + + // PPB_FileIO_API implementation (not provided by FileIOImpl). + virtual void Close() OVERRIDE; + virtual int32_t GetOSFileDescriptor() OVERRIDE; + virtual int32_t WillWrite(int64_t offset, + int32_t bytes_to_write, + PP_CompletionCallback callback) OVERRIDE; + virtual int32_t WillSetLength(int64_t length, + PP_CompletionCallback callback) OVERRIDE; + + private: + // FileIOImpl overrides. + virtual int32_t OpenValidated(PP_Resource file_ref_resource, + PPB_FileRef_API* file_ref_api, + int32_t open_flags, + PP_CompletionCallback callback) OVERRIDE; + virtual int32_t QueryValidated(PP_FileInfo* info, + PP_CompletionCallback callback) OVERRIDE; + virtual int32_t TouchValidated(PP_Time last_access_time, + PP_Time last_modified_time, + PP_CompletionCallback callback) OVERRIDE; + virtual int32_t ReadValidated(int64_t offset, + char* buffer, + int32_t bytes_to_read, + PP_CompletionCallback callback) OVERRIDE; + virtual int32_t WriteValidated(int64_t offset, + const char* buffer, + int32_t bytes_to_write, + PP_CompletionCallback callback) OVERRIDE; + virtual int32_t SetLengthValidated(int64_t length, + PP_CompletionCallback callback) OVERRIDE; + virtual int32_t FlushValidated(PP_CompletionCallback callback) OVERRIDE; + + PluginDispatcher* GetDispatcher() const { + return PluginDispatcher::GetForResource(this); + } + + static const ApiID kApiID = API_ID_PPB_FILE_IO; + + DISALLOW_IMPLICIT_CONSTRUCTORS(FileIO); +}; + +FileIO::FileIO(const HostResource& host_resource) + : PPB_FileIO_Shared(host_resource) { +} + +FileIO::~FileIO() { + Close(); +} + +void FileIO::Close() { + if (file_open_) { + GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Close(kApiID, + host_resource())); + } +} + +int32_t FileIO::GetOSFileDescriptor() { + return -1; +} + +int32_t FileIO::WillWrite(int64_t offset, + int32_t bytes_to_write, + PP_CompletionCallback callback) { + GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_WillWrite( + kApiID, host_resource(), offset, bytes_to_write)); + RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); + return PP_OK_COMPLETIONPENDING; +} + +int32_t FileIO::WillSetLength(int64_t length, + PP_CompletionCallback callback) { + GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_WillSetLength( + kApiID, host_resource(), length)); + RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); + return PP_OK_COMPLETIONPENDING; +} + +int32_t FileIO::OpenValidated(PP_Resource file_ref_resource, + PPB_FileRef_API* file_ref_api, + int32_t open_flags, + PP_CompletionCallback callback) { + Resource* file_ref_object = + PpapiGlobals::Get()->GetResourceTracker()->GetResource(file_ref_resource); + + GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Open( + kApiID, host_resource(), file_ref_object->host_resource(), open_flags)); + RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); + return PP_OK_COMPLETIONPENDING; +} + +int32_t FileIO::QueryValidated(PP_FileInfo* info, + PP_CompletionCallback callback) { + GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Query( + kApiID, host_resource())); + RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, info); + return PP_OK_COMPLETIONPENDING; +} + +int32_t FileIO::TouchValidated(PP_Time last_access_time, + PP_Time last_modified_time, + PP_CompletionCallback callback) { + GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Touch( + kApiID, host_resource(), last_access_time, last_modified_time)); + RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); + return PP_OK_COMPLETIONPENDING; +} + +int32_t FileIO::ReadValidated(int64_t offset, + char* buffer, + int32_t bytes_to_read, + PP_CompletionCallback callback) { + GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Read( + kApiID, host_resource(), offset, bytes_to_read)); + RegisterCallback(OPERATION_READ, callback, buffer, NULL); + return PP_OK_COMPLETIONPENDING; +} + +int32_t FileIO::WriteValidated(int64_t offset, + const char* buffer, + int32_t bytes_to_write, + PP_CompletionCallback callback) { + // TODO(brettw) it would be nice to use a shared memory buffer for large + // writes rather than having to copy to a string (which will involve a number + // of extra copies to serialize over IPC). + GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Write( + kApiID, host_resource(), offset, std::string(buffer, bytes_to_write))); + RegisterCallback(OPERATION_WRITE, callback, NULL, NULL); + return PP_OK_COMPLETIONPENDING; +} + +int32_t FileIO::SetLengthValidated(int64_t length, + PP_CompletionCallback callback) { + GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_SetLength( + kApiID, host_resource(), length)); + RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); + return PP_OK_COMPLETIONPENDING; +} + +int32_t FileIO::FlushValidated(PP_CompletionCallback callback) { + GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Flush( + kApiID, host_resource())); + RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); + return PP_OK_COMPLETIONPENDING; +} + +} // namespace + +// ----------------------------------------------------------------------------- + +PPB_FileIO_Proxy::PPB_FileIO_Proxy(Dispatcher* dispatcher) + : InterfaceProxy(dispatcher), + callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { +} + +PPB_FileIO_Proxy::~PPB_FileIO_Proxy() { +} + +// static +PP_Resource PPB_FileIO_Proxy::CreateProxyResource(PP_Instance instance) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); + if (!dispatcher) + return 0; + + HostResource result; + dispatcher->Send(new PpapiHostMsg_PPBFileIO_Create(kApiID, instance, + &result)); + if (result.is_null()) + return 0; + return (new FileIO(result))->GetReference(); +} + +bool PPB_FileIO_Proxy::OnMessageReceived(const IPC::Message& msg) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(PPB_FileIO_Proxy, msg) + // Plugin -> host message. + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Create, OnHostMsgCreate) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Open, OnHostMsgOpen) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Close, OnHostMsgClose) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Query, OnHostMsgQuery) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Touch, OnHostMsgTouch) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Read, OnHostMsgRead) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Write, OnHostMsgWrite) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_SetLength, OnHostMsgSetLength) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_Flush, OnHostMsgFlush) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_WillWrite, OnHostMsgWillWrite) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileIO_WillSetLength, + OnHostMsgWillSetLength) + + // Host -> plugin messages. + IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileIO_GeneralComplete, + OnPluginMsgGeneralComplete) + IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileIO_OpenFileComplete, + OnPluginMsgOpenFileComplete) + IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileIO_QueryComplete, + OnPluginMsgQueryComplete) + IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileIO_ReadComplete, + OnPluginMsgReadComplete) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void PPB_FileIO_Proxy::OnHostMsgCreate(PP_Instance instance, + HostResource* result) { + thunk::EnterResourceCreation enter(instance); + if (enter.succeeded()) { + result->SetHostResource(instance, + enter.functions()->CreateFileIO(instance)); + } +} + +void PPB_FileIO_Proxy::OnHostMsgOpen(const HostResource& host_resource, + const HostResource& file_ref_resource, + int32_t open_flags) { + EnterHostFileIO enter(host_resource, callback_factory_, + &PPB_FileIO_Proxy::OpenFileCallbackCompleteInHost, host_resource); + if (enter.succeeded()) { + enter.SetResult(enter.object()->Open( + file_ref_resource.host_resource(), open_flags, enter.callback())); + } +} + +void PPB_FileIO_Proxy::OnHostMsgClose(const HostResource& host_resource) { + EnterHostFromHostResource<PPB_FileIO_API> enter(host_resource); + if (enter.succeeded()) + enter.object()->Close(); +} + +void PPB_FileIO_Proxy::OnHostMsgQuery(const HostResource& host_resource) { + // The callback will take charge of deleting the FileInfo. The contents must + // be defined so we don't send garbage to the plugin in the failure case. + PP_FileInfo* info = new PP_FileInfo; + memset(info, 0, sizeof(PP_FileInfo)); + EnterHostFileIO enter(host_resource, callback_factory_, + &PPB_FileIO_Proxy::QueryCallbackCompleteInHost, + host_resource, info); + if (enter.succeeded()) + enter.SetResult(enter.object()->Query(info, enter.callback())); +} + +void PPB_FileIO_Proxy::OnHostMsgTouch(const HostResource& host_resource, + PP_Time last_access_time, + PP_Time last_modified_time) { + EnterHostFileIO enter(host_resource, callback_factory_, + &PPB_FileIO_Proxy::GeneralCallbackCompleteInHost, + host_resource); + if (enter.succeeded()) { + enter.SetResult(enter.object()->Touch(last_access_time, last_modified_time, + enter.callback())); + } +} + +void PPB_FileIO_Proxy::OnHostMsgRead(const HostResource& host_resource, + int64_t offset, + int32_t bytes_to_read) { + // Validate bytes_to_read before allocating below. This value is coming from + // the untrusted plugin. + bytes_to_read = std::min(bytes_to_read, kMaxReadSize); + if (bytes_to_read < 0) { + ReadCallbackCompleteInHost(PP_ERROR_FAILED, host_resource, + new std::string()); + return; + } + + // The callback will take charge of deleting the string. + std::string* dest = new std::string; + dest->resize(bytes_to_read); + EnterHostFileIO enter(host_resource, callback_factory_, + &PPB_FileIO_Proxy::ReadCallbackCompleteInHost, + host_resource, dest); + if (enter.succeeded()) { + enter.SetResult(enter.object()->Read(offset, + bytes_to_read > 0 ? &(*dest)[0] : NULL, + bytes_to_read, enter.callback())); + } +} + +void PPB_FileIO_Proxy::OnHostMsgWrite(const HostResource& host_resource, + int64_t offset, + const std::string& data) { + EnterHostFileIO enter(host_resource, callback_factory_, + &PPB_FileIO_Proxy::GeneralCallbackCompleteInHost, + host_resource); + if (enter.succeeded()) { + enter.SetResult(enter.object()->Write(offset, data.data(), data.size(), + enter.callback())); + } +} + +void PPB_FileIO_Proxy::OnHostMsgSetLength(const HostResource& host_resource, + int64_t length) { + EnterHostFileIO enter(host_resource, callback_factory_, + &PPB_FileIO_Proxy::GeneralCallbackCompleteInHost, + host_resource); + if (enter.succeeded()) + enter.SetResult(enter.object()->SetLength(length, enter.callback())); +} + +void PPB_FileIO_Proxy::OnHostMsgFlush(const HostResource& host_resource) { + EnterHostFileIO enter(host_resource, callback_factory_, + &PPB_FileIO_Proxy::GeneralCallbackCompleteInHost, + host_resource); + if (enter.succeeded()) + enter.SetResult(enter.object()->Flush(enter.callback())); +} + +void PPB_FileIO_Proxy::OnHostMsgWillWrite(const HostResource& host_resource, + int64_t offset, + int32_t bytes_to_write) { + EnterHostFileIO enter(host_resource, callback_factory_, + &PPB_FileIO_Proxy::GeneralCallbackCompleteInHost, + host_resource); + if (enter.succeeded()) { + enter.SetResult(enter.object()->WillWrite(offset, bytes_to_write, + enter.callback())); + } +} + +void PPB_FileIO_Proxy::OnHostMsgWillSetLength(const HostResource& host_resource, + int64_t length) { + EnterHostFileIO enter(host_resource, callback_factory_, + &PPB_FileIO_Proxy::GeneralCallbackCompleteInHost, + host_resource); + if (enter.succeeded()) + enter.SetResult(enter.object()->WillSetLength(length, enter.callback())); +} + +void PPB_FileIO_Proxy::OnPluginMsgGeneralComplete( + const HostResource& host_resource, + int32_t result) { + EnterPluginFileIO enter(host_resource); + if (enter.succeeded()) + static_cast<FileIO*>(enter.object())->ExecuteGeneralCallback(result); +} + +void PPB_FileIO_Proxy::OnPluginMsgOpenFileComplete( + const HostResource& host_resource, + int32_t result) { + EnterPluginFileIO enter(host_resource); + if (enter.succeeded()) + static_cast<FileIO*>(enter.object())->ExecuteOpenFileCallback(result); +} + +void PPB_FileIO_Proxy::OnPluginMsgQueryComplete( + const HostResource& host_resource, + int32_t result, + const PP_FileInfo& info) { + EnterPluginFileIO enter(host_resource); + if (enter.succeeded()) + static_cast<FileIO*>(enter.object())->ExecuteQueryCallback(result, info); +} + +void PPB_FileIO_Proxy::OnPluginMsgReadComplete( + const HostResource& host_resource, + int32_t result, + const std::string& data) { + EnterPluginFileIO enter(host_resource); + if (enter.succeeded()) { + // The result code should contain the data size if it's positive. + DCHECK((result < 0 && data.size() == 0) || + result == static_cast<int32_t>(data.size())); + static_cast<FileIO*>(enter.object())->ExecuteReadCallback(result, + data.data()); + } +} + +void PPB_FileIO_Proxy::GeneralCallbackCompleteInHost( + int32_t pp_error, + const HostResource& host_resource) { + Send(new PpapiMsg_PPBFileIO_GeneralComplete(kApiID, host_resource, pp_error)); +} + +void PPB_FileIO_Proxy::OpenFileCallbackCompleteInHost( + int32_t pp_error, + const HostResource& host_resource) { + Send(new PpapiMsg_PPBFileIO_OpenFileComplete(kApiID, host_resource, + pp_error)); +} + +void PPB_FileIO_Proxy::QueryCallbackCompleteInHost( + int32_t pp_error, + const HostResource& host_resource, + PP_FileInfo* info) { + Send(new PpapiMsg_PPBFileIO_QueryComplete(kApiID, host_resource, pp_error, + *info)); + delete info; +} + +void PPB_FileIO_Proxy::ReadCallbackCompleteInHost( + int32_t pp_error, + const HostResource& host_resource, + std::string* data) { + // Only send the amount of data in the string that was actually read. + if (pp_error >= 0) { + DCHECK(pp_error <= static_cast<int32_t>(data->size())); + data->resize(pp_error); + } + Send(new PpapiMsg_PPBFileIO_ReadComplete(kApiID, host_resource, pp_error, + *data)); + delete data; +} + +} // namespace proxy +} // namespace ppapi diff --git a/ppapi/proxy/ppb_file_io_proxy.h b/ppapi/proxy/ppb_file_io_proxy.h new file mode 100644 index 0000000..fbc8a16 --- /dev/null +++ b/ppapi/proxy/ppb_file_io_proxy.h @@ -0,0 +1,93 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_PROXY_PPB_FILE_IO_PROXY_H_ +#define PPAPI_PROXY_PPB_FILE_IO_PROXY_H_ + +#include <string> + +#include "base/basictypes.h" +#include "ppapi/c/pp_file_info.h" +#include "ppapi/proxy/interface_proxy.h" +#include "ppapi/proxy/proxy_non_thread_safe_ref_count.h" + +namespace ppapi { + +class HostResource; +namespace proxy { + +class PPB_FileIO_Proxy : public InterfaceProxy { + public: + explicit PPB_FileIO_Proxy(Dispatcher* dispatcher); + virtual ~PPB_FileIO_Proxy(); + + static PP_Resource CreateProxyResource(PP_Instance instance); + + // InterfaceProxy implementation. + virtual bool OnMessageReceived(const IPC::Message& msg); + + static const ApiID kApiID = API_ID_PPB_FILE_IO; + + private: + // Plugin -> Host message handlers. + void OnHostMsgCreate(PP_Instance instance, HostResource* result); + void OnHostMsgOpen(const HostResource& host_resource, + const HostResource& file_ref_resource, + int32_t open_flags); + void OnHostMsgClose(const HostResource& host_resource); + void OnHostMsgQuery(const HostResource& host_resource); + void OnHostMsgTouch(const HostResource& host_resource, + PP_Time last_access_time, + PP_Time last_modified_time); + void OnHostMsgRead(const HostResource& host_resource, + int64_t offset, + int32_t bytes_to_read); + void OnHostMsgWrite(const HostResource& host_resource, + int64_t offset, + const std::string& data); + void OnHostMsgSetLength(const HostResource& host_resource, + int64_t length); + void OnHostMsgFlush(const HostResource& host_resource); + void OnHostMsgWillWrite(const HostResource& host_resource, + int64_t offset, + int32_t bytes_to_write); + void OnHostMsgWillSetLength(const HostResource& host_resource, + int64_t length); + + // Host -> Plugin message handlers. + void OnPluginMsgGeneralComplete(const HostResource& host_resource, + int32_t result); + void OnPluginMsgOpenFileComplete(const HostResource& host_resource, + int32_t result); + void OnPluginMsgQueryComplete(const HostResource& host_resource, + int32_t result, + const PP_FileInfo& info); + void OnPluginMsgReadComplete(const HostResource& host_resource, + int32_t result, + const std::string& data); + void OnPluginMsgWriteComplete(const HostResource& host_resource, + int32_t result); + + // Host-side callback handlers. These convert the callbacks to an IPC message + // to the plugin. + void GeneralCallbackCompleteInHost(int32_t pp_error, + const HostResource& host_resource); + void OpenFileCallbackCompleteInHost(int32_t pp_error, + const HostResource& host_resource); + void QueryCallbackCompleteInHost(int32_t pp_error, + const HostResource& host_resource, + PP_FileInfo* info); + void ReadCallbackCompleteInHost(int32_t pp_error, + const HostResource& host_resource, + std::string* data); + pp::CompletionCallbackFactory<PPB_FileIO_Proxy, + ProxyNonThreadSafeRefCount> callback_factory_; + + DISALLOW_COPY_AND_ASSIGN(PPB_FileIO_Proxy); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_PPB_FILE_IO_PROXY_H_ diff --git a/ppapi/proxy/ppb_file_ref_proxy.cc b/ppapi/proxy/ppb_file_ref_proxy.cc index 20b522c..e481f86 100644 --- a/ppapi/proxy/ppb_file_ref_proxy.cc +++ b/ppapi/proxy/ppb_file_ref_proxy.cc @@ -33,6 +33,9 @@ class FileRef : public PPB_FileRef_Shared { explicit FileRef(const PPB_FileRef_CreateInfo& info); virtual ~FileRef(); + // Resource overrides. + virtual void LastPluginRefWasDeleted() OVERRIDE; + // PPB_FileRef_API implementation (not provided by PPB_FileRef_Shared). virtual PP_Resource GetParent() OVERRIDE; virtual int32_t MakeDirectory(PP_Bool make_ancestors, @@ -77,6 +80,11 @@ FileRef::FileRef(const PPB_FileRef_CreateInfo& info) } FileRef::~FileRef() { + // The callbacks map should have been cleared by LastPluginRefWasDeleted. + DCHECK(pending_callbacks_.empty()); +} + +void FileRef::LastPluginRefWasDeleted() { // Abort all pending callbacks. Do this by posting a task to avoid reentering // the plugin's Release() call that probably deleted this object. for (PendingCallbackMap::iterator i = pending_callbacks_.begin(); @@ -85,6 +93,7 @@ FileRef::~FileRef() { i->second.func, i->second.user_data, static_cast<int32_t>(PP_ERROR_ABORTED))); } + pending_callbacks_.clear(); } PP_Resource FileRef::GetParent() { diff --git a/ppapi/proxy/ppb_file_ref_proxy.h b/ppapi/proxy/ppb_file_ref_proxy.h index 5f0f947..c0fa23c 100644 --- a/ppapi/proxy/ppb_file_ref_proxy.h +++ b/ppapi/proxy/ppb_file_ref_proxy.h @@ -31,6 +31,8 @@ class PPB_FileRef_Proxy : public InterfaceProxy { static PP_Resource CreateProxyResource(PP_Resource file_system, const char* path); + static PP_Resource CreateProxyResource( + const PPB_FileRef_CreateInfo& serialized); // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); @@ -60,7 +62,7 @@ class PPB_FileRef_Proxy : public InterfaceProxy { static const ApiID kApiID = API_ID_PPB_FILE_REF; private: - // Message handlers. + // Plugin -> host message handlers. void OnMsgCreate(const HostResource& file_system, const std::string& path, PPB_FileRef_CreateInfo* result); diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index 52cce18..e758035 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -15,6 +15,7 @@ #include "ppapi/proxy/ppb_buffer_proxy.h" #include "ppapi/proxy/ppb_broker_proxy.h" #include "ppapi/proxy/ppb_file_chooser_proxy.h" +#include "ppapi/proxy/ppb_file_io_proxy.h" #include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/proxy/ppb_file_system_proxy.h" #include "ppapi/proxy/ppb_flash_menu_proxy.h" @@ -122,8 +123,7 @@ PP_Resource ResourceCreationProxy::CreateFileChooser( } PP_Resource ResourceCreationProxy::CreateFileIO(PP_Instance instance) { - NOTIMPLEMENTED(); // Not proxied yet. - return 0; + return PPB_FileIO_Proxy::CreateProxyResource(instance); } PP_Resource ResourceCreationProxy::CreateFileRef(PP_Resource file_system, |