summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy
diff options
context:
space:
mode:
Diffstat (limited to 'ppapi/proxy')
-rw-r--r--ppapi/proxy/DEPS1
-rw-r--r--ppapi/proxy/plugin_array_buffer_var.cc2
-rw-r--r--ppapi/proxy/plugin_dispatcher_unittest.cc5
-rw-r--r--ppapi/proxy/ppapi_command_buffer_proxy.cc14
-rw-r--r--ppapi/proxy/ppapi_messages.h46
-rw-r--r--ppapi/proxy/ppapi_param_traits.cc59
-rw-r--r--ppapi/proxy/ppapi_param_traits.h14
-rw-r--r--ppapi/proxy/ppapi_proxy_export.h4
-rw-r--r--ppapi/proxy/ppb_audio_input_proxy.cc50
-rw-r--r--ppapi/proxy/ppb_audio_input_proxy.h6
-rw-r--r--ppapi/proxy/ppb_audio_proxy.cc38
-rw-r--r--ppapi/proxy/ppb_audio_proxy.h11
-rw-r--r--ppapi/proxy/ppb_buffer_proxy.cc17
-rw-r--r--ppapi/proxy/ppb_buffer_proxy.h3
-rw-r--r--ppapi/proxy/ppb_graphics_3d_proxy.cc11
-rw-r--r--ppapi/proxy/ppb_graphics_3d_proxy.h4
-rw-r--r--ppapi/proxy/ppb_image_data_proxy.cc19
-rw-r--r--ppapi/proxy/ppb_image_data_proxy.h2
-rw-r--r--ppapi/proxy/serialized_structs.cc81
-rw-r--r--ppapi/proxy/serialized_structs.h92
-rw-r--r--ppapi/proxy/serialized_var.cc3
21 files changed, 382 insertions, 100 deletions
diff --git a/ppapi/proxy/DEPS b/ppapi/proxy/DEPS
index 4fd421d..1a3c174 100644
--- a/ppapi/proxy/DEPS
+++ b/ppapi/proxy/DEPS
@@ -2,6 +2,7 @@ include_rules = [
"+base",
"+ipc",
"+gpu",
+ "+media/audio",
"+skia",
"+ui/surface",
diff --git a/ppapi/proxy/plugin_array_buffer_var.cc b/ppapi/proxy/plugin_array_buffer_var.cc
index 6d16cfe..c9d302f 100644
--- a/ppapi/proxy/plugin_array_buffer_var.cc
+++ b/ppapi/proxy/plugin_array_buffer_var.cc
@@ -28,7 +28,7 @@ void PluginArrayBufferVar::Unmap() {
}
uint32 PluginArrayBufferVar::ByteLength() {
- return buffer_.size();
+ return static_cast<uint32>(buffer_.size());
}
} // namespace ppapi
diff --git a/ppapi/proxy/plugin_dispatcher_unittest.cc b/ppapi/proxy/plugin_dispatcher_unittest.cc
index a2999d0..821ecad 100644
--- a/ppapi/proxy/plugin_dispatcher_unittest.cc
+++ b/ppapi/proxy/plugin_dispatcher_unittest.cc
@@ -74,7 +74,10 @@ TEST_F(PluginDispatcherTest, PPBCreation) {
EXPECT_FALSE(HasTargetProxy(API_ID_PPB_AUDIO));
PpapiMsg_PPBAudio_NotifyAudioStreamCreated audio_msg(
API_ID_PPB_AUDIO, HostResource(), 0,
- IPC::PlatformFileForTransit(), base::SharedMemoryHandle(), 0);
+ ppapi::proxy::SerializedHandle(
+ ppapi::proxy::SerializedHandle::SOCKET),
+ ppapi::proxy::SerializedHandle(
+ ppapi::proxy::SerializedHandle::SHARED_MEMORY));
plugin_dispatcher()->OnMessageReceived(audio_msg);
EXPECT_TRUE(HasTargetProxy(API_ID_PPB_AUDIO));
}
diff --git a/ppapi/proxy/ppapi_command_buffer_proxy.cc b/ppapi/proxy/ppapi_command_buffer_proxy.cc
index 91cd268..282a876 100644
--- a/ppapi/proxy/ppapi_command_buffer_proxy.cc
+++ b/ppapi/proxy/ppapi_command_buffer_proxy.cc
@@ -225,27 +225,29 @@ gpu::Buffer PpapiCommandBufferProxy::GetTransferBuffer(int32 id) {
// Assuming we are in the renderer process, the service is responsible for
// duplicating the handle. This might not be true for NaCl.
- base::SharedMemoryHandle handle;
- uint32 size;
+ ppapi::proxy::SerializedHandle handle(
+ ppapi::proxy::SerializedHandle::SHARED_MEMORY);
if (!Send(new PpapiHostMsg_PPBGraphics3D_GetTransferBuffer(
- ppapi::API_ID_PPB_GRAPHICS_3D, resource_, id, &handle, &size))) {
+ ppapi::API_ID_PPB_GRAPHICS_3D, resource_, id, &handle))) {
return gpu::Buffer();
}
+ if (!handle.is_shmem())
+ return gpu::Buffer();
// Cache the transfer buffer shared memory object client side.
scoped_ptr<base::SharedMemory> shared_memory(
- new base::SharedMemory(handle, false));
+ new base::SharedMemory(handle.shmem(), false));
// Map the shared memory on demand.
if (!shared_memory->memory()) {
- if (!shared_memory->Map(size)) {
+ if (!shared_memory->Map(handle.size())) {
return gpu::Buffer();
}
}
gpu::Buffer buffer;
buffer.ptr = shared_memory->memory();
- buffer.size = size;
+ buffer.size = handle.size();
buffer.shared_memory = shared_memory.release();
transfer_buffers_[id] = buffer;
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index a5a9cfb..8ba5760 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -230,7 +230,7 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::PPB_URLRequestInfo_Data::BodyItem)
IPC_STRUCT_TRAITS_MEMBER(expected_last_modified_time)
IPC_STRUCT_TRAITS_END()
-#if !defined(OS_NACL)
+#if !defined(OS_NACL) && !defined(NACL_WIN64)
IPC_STRUCT_TRAITS_BEGIN(ppapi::proxy::PPPVideoCapture_Buffer)
IPC_STRUCT_TRAITS_MEMBER(resource)
IPC_STRUCT_TRAITS_MEMBER(handle)
@@ -294,7 +294,7 @@ IPC_SYNC_MESSAGE_CONTROL1_1(PpapiMsg_SupportsInterface,
std::string /* interface_name */,
bool /* result */)
-#if !defined(OS_NACL)
+#if !defined(OS_NACL) && !defined(NACL_WIN64)
// Network state notification from the browser for implementing
// PPP_NetworkState_Dev.
IPC_MESSAGE_CONTROL1(PpapiMsg_SetNetworkState,
@@ -365,7 +365,7 @@ IPC_SYNC_MESSAGE_CONTROL2_1(PpapiMsg_ConnectToPlugin,
PP_Instance /* instance */,
IPC::PlatformFileForTransit /* handle */,
int32_t /* result */)
-#endif // !defined(OS_NACL)
+#endif // !defined(OS_NACL) && !defined(NACL_WIN64)
// PPB_Audio.
@@ -376,24 +376,22 @@ IPC_SYNC_MESSAGE_CONTROL2_1(PpapiMsg_ConnectToPlugin,
//
// The handler of this message should always close all of the handles passed
// in, since some could be valid even in the error case.
-IPC_MESSAGE_ROUTED5(PpapiMsg_PPBAudio_NotifyAudioStreamCreated,
+IPC_MESSAGE_ROUTED4(PpapiMsg_PPBAudio_NotifyAudioStreamCreated,
ppapi::HostResource /* audio_id */,
int32_t /* result_code (will be != PP_OK on failure) */,
- IPC::PlatformFileForTransit /* socket_handle */,
- base::SharedMemoryHandle /* handle */,
- int32_t /* length */)
+ ppapi::proxy::SerializedHandle /* socket_handle */,
+ ppapi::proxy::SerializedHandle /* handle */)
// PPB_AudioInput_Dev.
IPC_MESSAGE_ROUTED3(PpapiMsg_PPBAudioInput_EnumerateDevicesACK,
ppapi::HostResource /* audio_input */,
int32_t /* result */,
std::vector<ppapi::DeviceRefData> /* devices */)
-IPC_MESSAGE_ROUTED5(PpapiMsg_PPBAudioInput_OpenACK,
+IPC_MESSAGE_ROUTED4(PpapiMsg_PPBAudioInput_OpenACK,
ppapi::HostResource /* audio_input */,
int32_t /* result_code (will be != PP_OK on failure) */,
- IPC::PlatformFileForTransit /* socket_handle */,
- base::SharedMemoryHandle /* handle */,
- int32_t /* length */)
+ ppapi::proxy::SerializedHandle /* socket_handle */,
+ ppapi::proxy::SerializedHandle /* handle */)
// PPB_FileIO.
IPC_MESSAGE_ROUTED2(PpapiMsg_PPBFileIO_GeneralComplete,
@@ -580,7 +578,7 @@ IPC_MESSAGE_ROUTED3(PpapiMsg_PPBURLLoader_ReadResponseBody_Ack,
IPC_MESSAGE_ROUTED2(PpapiMsg_PPBURLLoader_CallbackComplete,
ppapi::HostResource /* loader */,
int32_t /* result */)
-#if !defined(OS_NACL)
+#if !defined(OS_NACL) && !defined(NACL_WIN64)
// PPB_Broker.
IPC_MESSAGE_ROUTED3(
PpapiMsg_PPBBroker_ConnectComplete,
@@ -756,7 +754,7 @@ IPC_MESSAGE_ROUTED2(PpapiMsg_PPPVideoDecoder_PictureReady,
IPC_MESSAGE_ROUTED2(PpapiMsg_PPPVideoDecoder_NotifyError,
ppapi::HostResource /* video_decoder */,
PP_VideoDecodeError_Dev /* error */)
-#endif // !defined(OS_NACL)
+#endif // !defined(OS_NACL) && !defined(NACL_WIN64)
// -----------------------------------------------------------------------------
// These are from the plugin to the renderer.
@@ -939,11 +937,10 @@ IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer,
IPC_SYNC_MESSAGE_ROUTED2_0(PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer,
ppapi::HostResource /* context */,
int32 /* id */)
-IPC_SYNC_MESSAGE_ROUTED2_2(PpapiHostMsg_PPBGraphics3D_GetTransferBuffer,
+IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBGraphics3D_GetTransferBuffer,
ppapi::HostResource /* context */,
int32 /* id */,
- base::SharedMemoryHandle /* transfer_buffer */,
- uint32 /* size */)
+ ppapi::proxy::SerializedHandle /* transfer_buffer */)
IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBGraphics3D_SwapBuffers,
ppapi::HostResource /* graphics_3d */)
@@ -963,7 +960,7 @@ IPC_SYNC_MESSAGE_ROUTED4_3(PpapiHostMsg_PPBImageData_CreateNaCl,
PP_Bool /* init_to_zero */,
ppapi::HostResource /* result_resource */,
std::string /* image_data_desc */,
- base::SharedMemoryHandle /* result */)
+ ppapi::proxy::SerializedHandle /* result */)
// PPB_Instance.
IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBInstance_GetWindowObject,
@@ -1156,7 +1153,7 @@ IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBVar_CreateObjectDeprecated,
int64 /* object_data */,
ppapi::proxy::SerializedVar /* result */)
-#if !defined(OS_NACL)
+#if !defined(OS_NACL) && !defined(NACL_WIN64)
// PPB_Broker.
IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBBroker_Create,
PP_Instance /* instance */,
@@ -1165,11 +1162,12 @@ IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBBroker_Connect,
ppapi::HostResource /* broker */)
// PPB_Buffer.
-IPC_SYNC_MESSAGE_ROUTED2_2(PpapiHostMsg_PPBBuffer_Create,
- PP_Instance /* instance */,
- uint32_t /* size */,
- ppapi::HostResource /* result_resource */,
- base::SharedMemoryHandle /* result_shm_handle */)
+IPC_SYNC_MESSAGE_ROUTED2_2(
+ PpapiHostMsg_PPBBuffer_Create,
+ PP_Instance /* instance */,
+ uint32_t /* size */,
+ ppapi::HostResource /* result_resource */,
+ ppapi::proxy::SerializedHandle /* result_shm_handle */)
// PPB_ContentDecryptor_Dev messages handled in PPB_Instance_Proxy.
IPC_MESSAGE_ROUTED4(PpapiHostMsg_PPBInstance_NeedKey,
@@ -1480,7 +1478,7 @@ IPC_SYNC_MESSAGE_CONTROL1_2(PpapiHostMsg_PPBX509Certificate_ParseDER,
IPC_SYNC_MESSAGE_CONTROL0_1(PpapiHostMsg_PPBFont_GetFontFamilies,
std::string /* result */)
-#endif // !defined(OS_NACL)
+#endif // !defined(OS_NACL) && !defined(NACL_WIN64)
//-----------------------------------------------------------------------------
// Resource call/reply messages.
diff --git a/ppapi/proxy/ppapi_param_traits.cc b/ppapi/proxy/ppapi_param_traits.cc
index 87ce4fc..bcb2df0 100644
--- a/ppapi/proxy/ppapi_param_traits.cc
+++ b/ppapi/proxy/ppapi_param_traits.cc
@@ -312,7 +312,62 @@ void ParamTraits< std::vector<ppapi::PPB_FileRef_CreateInfo> >::Log(
std::string* l) {
}
-#if !defined(OS_NACL)
+// SerializedHandle ------------------------------------------------------------
+
+// static
+void ParamTraits<ppapi::proxy::SerializedHandle>::Write(Message* m,
+ const param_type& p) {
+ ppapi::proxy::SerializedHandle::WriteHeader(p.header(), m);
+ switch (p.type()) {
+ case ppapi::proxy::SerializedHandle::SHARED_MEMORY:
+ ParamTraits<base::SharedMemoryHandle>::Write(m, p.shmem());
+ break;
+ case ppapi::proxy::SerializedHandle::SOCKET:
+ ParamTraits<IPC::PlatformFileForTransit>::Write(m, p.descriptor());
+ break;
+ case ppapi::proxy::SerializedHandle::INVALID:
+ break;
+ // No default so the compiler will warn on new types.
+ }
+}
+
+// static
+bool ParamTraits<ppapi::proxy::SerializedHandle>::Read(const Message* m,
+ PickleIterator* iter,
+ param_type* r) {
+ ppapi::proxy::SerializedHandle::Header header;
+ if (!ppapi::proxy::SerializedHandle::ReadHeader(iter, &header))
+ return false;
+ switch (header.type) {
+ case ppapi::proxy::SerializedHandle::SHARED_MEMORY: {
+ base::SharedMemoryHandle handle;
+ if (ParamTraits<base::SharedMemoryHandle>::Read(m, iter, &handle)) {
+ r->set_shmem(handle, header.size);
+ return true;
+ }
+ break;
+ }
+ case ppapi::proxy::SerializedHandle::SOCKET: {
+ IPC::PlatformFileForTransit socket;
+ if (ParamTraits<IPC::PlatformFileForTransit>::Read(m, iter, &socket)) {
+ r->set_socket(socket);
+ return true;
+ }
+ break;
+ }
+ case ppapi::proxy::SerializedHandle::INVALID:
+ return true;
+ // No default so the compiler will warn us if a new type is added.
+ }
+ return false;
+}
+
+// static
+void ParamTraits<ppapi::proxy::SerializedHandle>::Log(const param_type& p,
+ std::string* l) {
+}
+
+#if !defined(OS_NACL) && !defined(NACL_WIN64)
// PPBFlash_DrawGlyphs_Params --------------------------------------------------
// static
void ParamTraits<ppapi::proxy::PPBFlash_DrawGlyphs_Params>::Write(
@@ -507,6 +562,6 @@ bool ParamTraits<ppapi::PPB_X509Certificate_Fields>::Read(const Message* m,
void ParamTraits<ppapi::PPB_X509Certificate_Fields>::Log(const param_type& p,
std::string* l) {
}
-#endif // !defined(OS_NACL)
+#endif // !defined(OS_NACL) && !defined(NACL_WIN64)
} // namespace IPC
diff --git a/ppapi/proxy/ppapi_param_traits.h b/ppapi/proxy/ppapi_param_traits.h
index 5b12f60..399513c 100644
--- a/ppapi/proxy/ppapi_param_traits.h
+++ b/ppapi/proxy/ppapi_param_traits.h
@@ -32,6 +32,7 @@ struct PPBURLLoader_UpdateProgress_Params;
struct SerializedDirEntry;
struct SerializedFontDescription;
class SerializedFlashMenu;
+class SerializedHandle;
class SerializedVar;
} // namespace proxy
@@ -114,6 +115,14 @@ struct PPAPI_PROXY_EXPORT ParamTraits<ppapi::proxy::SerializedFontDescription> {
};
template<>
+struct PPAPI_PROXY_EXPORT ParamTraits<ppapi::proxy::SerializedHandle> {
+ typedef ppapi::proxy::SerializedHandle param_type;
+ static void Write(Message* m, const param_type& p);
+ static bool Read(const Message* m, PickleIterator* iter, param_type* r);
+ static void Log(const param_type& p, std::string* l);
+};
+
+template<>
struct PPAPI_PROXY_EXPORT ParamTraits<ppapi::HostResource> {
typedef ppapi::HostResource param_type;
static void Write(Message* m, const param_type& p);
@@ -147,7 +156,7 @@ struct PPAPI_PROXY_EXPORT ParamTraits< std::vector<
static void Log(const param_type& p, std::string* l);
};
-#if !defined(OS_NACL)
+#if !defined(OS_NACL) && !defined(NACL_WIN64)
template<>
struct PPAPI_PROXY_EXPORT ParamTraits<ppapi::proxy::SerializedFlashMenu> {
typedef ppapi::proxy::SerializedFlashMenu param_type;
@@ -163,7 +172,8 @@ struct PPAPI_PROXY_EXPORT ParamTraits<ppapi::PPB_X509Certificate_Fields> {
static bool Read(const Message* m, PickleIterator* iter, param_type* r);
static void Log(const param_type& p, std::string* l);
};
-#endif // !defined(OS_NACL)
+#endif // !defined(OS_NACL) && !defined(NACL_WIN64)
+
} // namespace IPC
diff --git a/ppapi/proxy/ppapi_proxy_export.h b/ppapi/proxy/ppapi_proxy_export.h
index 6b1e83b..be86da4 100644
--- a/ppapi/proxy/ppapi_proxy_export.h
+++ b/ppapi/proxy/ppapi_proxy_export.h
@@ -5,7 +5,7 @@
#ifndef PPAPI_PROXY_PPAPI_PROXY_EXPORT_H_
#define PPAPI_PROXY_PPAPI_PROXY_EXPORT_H_
-#if defined(COMPONENT_BUILD)
+#if defined(COMPONENT_BUILD) && !defined(NACL_WIN64)
#if defined(WIN32)
#if defined(PPAPI_PROXY_IMPLEMENTATION)
@@ -22,7 +22,7 @@
#endif
#endif
-#else // defined(COMPONENT_BUILD)
+#else // defined(COMPONENT_BUILD) && !defined(NACL_WIN64)
#define PPAPI_PROXY_EXPORT
#endif
diff --git a/ppapi/proxy/ppb_audio_input_proxy.cc b/ppapi/proxy/ppb_audio_input_proxy.cc
index 011e332..dfc2d0c 100644
--- a/ppapi/proxy/ppb_audio_input_proxy.cc
+++ b/ppapi/proxy/ppb_audio_input_proxy.cc
@@ -5,6 +5,7 @@
#include "ppapi/proxy/ppb_audio_input_proxy.h"
#include "base/compiler_specific.h"
+#include "media/audio/shared_memory_util.h"
#include "ppapi/c/dev/ppb_audio_input_dev.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/ppb_audio_config.h"
@@ -286,21 +287,27 @@ void PPB_AudioInput_Proxy::OnMsgEnumerateDevicesACK(
void PPB_AudioInput_Proxy::OnMsgOpenACK(
const HostResource& audio_input,
int32_t result,
- IPC::PlatformFileForTransit socket_handle,
- base::SharedMemoryHandle handle,
- uint32_t length) {
+ const ppapi::proxy::SerializedHandle& socket_handle,
+ const ppapi::proxy::SerializedHandle& handle) {
+ CHECK(socket_handle.is_socket());
+ CHECK(handle.is_shmem());
EnterPluginFromHostResource<PPB_AudioInput_API> enter(audio_input);
if (enter.failed()) {
// The caller may still have given us these handles in the failure case.
// The easiest way to clean these up is to just put them in the objects
// and then close them. This failure case is not performance critical.
base::SyncSocket temp_socket(
- IPC::PlatformFileForTransitToPlatformFile(socket_handle));
- base::SharedMemory temp_mem(handle, false);
+ IPC::PlatformFileForTransitToPlatformFile(
+ socket_handle.descriptor()));
+ base::SharedMemory temp_mem(handle.shmem(), false);
} else {
+ // See the comment above about how we must call
+ // TotalSharedMemorySizeInBytes to get the actual size of the buffer. Here,
+ // we must call PacketSizeInBytes to get back the size of the audio buffer,
+ // excluding the bytes that audio uses for book-keeping.
static_cast<AudioInput*>(enter.object())->OnOpenComplete(
- result, handle, length,
- IPC::PlatformFileForTransitToPlatformFile(socket_handle));
+ result, handle.shmem(), media::PacketSizeInBytes(handle.size()),
+ IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor()));
}
}
@@ -316,15 +323,28 @@ void PPB_AudioInput_Proxy::EnumerateDevicesACKInHost(
void PPB_AudioInput_Proxy::OpenACKInHost(int32_t result,
const HostResource& audio_input) {
- IPC::PlatformFileForTransit socket_handle =
- IPC::InvalidPlatformFileForTransit();
- base::SharedMemoryHandle shared_memory = IPC::InvalidPlatformFileForTransit();
- uint32_t shared_memory_length = 0;
+ ppapi::proxy::SerializedHandle socket_handle(
+ ppapi::proxy::SerializedHandle::SOCKET);
+ ppapi::proxy::SerializedHandle shared_memory(
+ ppapi::proxy::SerializedHandle::SHARED_MEMORY);
if (result == PP_OK) {
- result = GetAudioInputConnectedHandles(audio_input, &socket_handle,
- &shared_memory,
- &shared_memory_length);
+ IPC::PlatformFileForTransit temp_socket;
+ base::SharedMemoryHandle temp_shmem;
+ uint32_t audio_buffer_size;
+ result = GetAudioInputConnectedHandles(audio_input, &temp_socket,
+ &temp_shmem, &audio_buffer_size);
+ if (result == PP_OK) {
+ socket_handle.set_socket(temp_socket);
+ // Note that we must call TotalSharedMemorySizeInBytes because
+ // Audio allocates extra space in shared memory for book-keeping, so the
+ // actual size of the shared memory buffer is larger than
+ // audio_buffer_length. When sending to NaCl, NaClIPCAdapter expects this
+ // size to match the size of the full shared memory buffer.
+ shared_memory.set_shmem(
+ temp_shmem,
+ media::TotalSharedMemorySizeInBytes(audio_buffer_size));
+ }
}
// Send all the values, even on error. This simplifies some of our cleanup
@@ -334,7 +354,7 @@ void PPB_AudioInput_Proxy::OpenACKInHost(int32_t result,
// (in OnMsgOpenACK), even in the failure case.
dispatcher()->Send(new PpapiMsg_PPBAudioInput_OpenACK(
API_ID_PPB_AUDIO_INPUT_DEV, audio_input, result, socket_handle,
- shared_memory, shared_memory_length));
+ shared_memory));
}
int32_t PPB_AudioInput_Proxy::GetAudioInputConnectedHandles(
diff --git a/ppapi/proxy/ppb_audio_input_proxy.h b/ppapi/proxy/ppb_audio_input_proxy.h
index f1fac75..ea259fd 100644
--- a/ppapi/proxy/ppb_audio_input_proxy.h
+++ b/ppapi/proxy/ppb_audio_input_proxy.h
@@ -17,6 +17,7 @@
#include "ppapi/c/ppb_audio_config.h"
#include "ppapi/proxy/interface_proxy.h"
#include "ppapi/proxy/proxy_completion_callback_factory.h"
+#include "ppapi/proxy/serialized_structs.h"
#include "ppapi/utility/completion_callback_factory.h"
namespace ppapi {
@@ -63,9 +64,8 @@ class PPB_AudioInput_Proxy : public InterfaceProxy {
const std::vector<ppapi::DeviceRefData>& devices);
void OnMsgOpenACK(const ppapi::HostResource& audio_input,
int32_t result,
- IPC::PlatformFileForTransit socket_handle,
- base::SharedMemoryHandle handle,
- uint32_t length);
+ const ppapi::proxy::SerializedHandle& socket_handle,
+ const ppapi::proxy::SerializedHandle& handle);
void EnumerateDevicesACKInHost(int32_t result,
const ppapi::HostResource& audio_input);
diff --git a/ppapi/proxy/ppb_audio_proxy.cc b/ppapi/proxy/ppb_audio_proxy.cc
index f60ac81..bc83be3 100644
--- a/ppapi/proxy/ppb_audio_proxy.cc
+++ b/ppapi/proxy/ppb_audio_proxy.cc
@@ -6,6 +6,7 @@
#include "base/compiler_specific.h"
#include "base/threading/simple_thread.h"
+#include "media/audio/shared_memory_util.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/ppb_audio.h"
#include "ppapi/c/ppb_audio_config.h"
@@ -238,13 +239,13 @@ void PPB_Audio_Proxy::AudioChannelConnected(
IPC::PlatformFileForTransit socket_handle =
IPC::InvalidPlatformFileForTransit();
base::SharedMemoryHandle shared_memory = IPC::InvalidPlatformFileForTransit();
- uint32_t shared_memory_length = 0;
+ uint32_t audio_buffer_length = 0;
int32_t result_code = result;
if (result_code == PP_OK) {
result_code = GetAudioConnectedHandles(resource, &socket_handle,
&shared_memory,
- &shared_memory_length);
+ &audio_buffer_length);
}
// Send all the values, even on error. This simplifies some of our cleanup
@@ -252,9 +253,18 @@ void PPB_Audio_Proxy::AudioChannelConnected(
// inconvenient to clean up. Our IPC code will automatically handle this for
// us, as long as the remote side always closes the handles it receives
// (in OnMsgNotifyAudioStreamCreated), even in the failure case.
+ ppapi::proxy::SerializedHandle fd_wrapper(socket_handle);
+
+ // Note that we must call TotalSharedMemorySizeInBytes because
+ // Audio allocates extra space in shared memory for book-keeping, so the
+ // actual size of the shared memory buffer is larger than audio_buffer_length.
+ // When sending to NaCl, NaClIPCAdapter expects this size to match the size
+ // of the full shared memory buffer.
+ ppapi::proxy::SerializedHandle handle_wrapper(
+ shared_memory,
+ media::TotalSharedMemorySizeInBytes(audio_buffer_length));
dispatcher()->Send(new PpapiMsg_PPBAudio_NotifyAudioStreamCreated(
- API_ID_PPB_AUDIO, resource, result_code, socket_handle,
- shared_memory, shared_memory_length));
+ API_ID_PPB_AUDIO, resource, result_code, fd_wrapper, handle_wrapper));
}
int32_t PPB_Audio_Proxy::GetAudioConnectedHandles(
@@ -299,21 +309,27 @@ int32_t PPB_Audio_Proxy::GetAudioConnectedHandles(
void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated(
const HostResource& audio_id,
int32_t result_code,
- IPC::PlatformFileForTransit socket_handle,
- base::SharedMemoryHandle handle,
- uint32_t length) {
+ ppapi::proxy::SerializedHandle socket_handle,
+ ppapi::proxy::SerializedHandle handle) {
+ CHECK(socket_handle.is_socket());
+ CHECK(handle.is_shmem());
EnterPluginFromHostResource<PPB_Audio_API> enter(audio_id);
if (enter.failed() || result_code != PP_OK) {
// The caller may still have given us these handles in the failure case.
// The easiest way to clean these up is to just put them in the objects
// and then close them. This failure case is not performance critical.
base::SyncSocket temp_socket(
- IPC::PlatformFileForTransitToPlatformFile(socket_handle));
- base::SharedMemory temp_mem(handle, false);
+ IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor()));
+ base::SharedMemory temp_mem(handle.shmem(), false);
} else {
+ // See the comment above about how we must call
+ // TotalSharedMemorySizeInBytes to get the actual size of the buffer. Here,
+ // we must call PacketSizeInBytes to get back the size of the audio buffer,
+ // excluding the bytes that audio uses for book-keeping.
static_cast<Audio*>(enter.object())->SetStreamInfo(
- enter.resource()->pp_instance(), handle, length,
- IPC::PlatformFileForTransitToPlatformFile(socket_handle));
+ enter.resource()->pp_instance(), handle.shmem(),
+ media::PacketSizeInBytes(handle.size()),
+ IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor()));
}
}
diff --git a/ppapi/proxy/ppb_audio_proxy.h b/ppapi/proxy/ppb_audio_proxy.h
index b516925..2f85a83 100644
--- a/ppapi/proxy/ppb_audio_proxy.h
+++ b/ppapi/proxy/ppb_audio_proxy.h
@@ -17,6 +17,7 @@
#include "ppapi/c/ppb_audio_config.h"
#include "ppapi/proxy/interface_proxy.h"
#include "ppapi/proxy/proxy_completion_callback_factory.h"
+#include "ppapi/proxy/serialized_structs.h"
#include "ppapi/utility/completion_callback_factory.h"
namespace ppapi {
@@ -51,11 +52,11 @@ class PPB_Audio_Proxy : public InterfaceProxy {
void OnMsgStartOrStop(const ppapi::HostResource& audio_id, bool play);
// Renderer->plugin message handlers.
- void OnMsgNotifyAudioStreamCreated(const ppapi::HostResource& audio_id,
- int32_t result_code,
- IPC::PlatformFileForTransit socket_handle,
- base::SharedMemoryHandle handle,
- uint32_t length);
+ void OnMsgNotifyAudioStreamCreated(
+ const ppapi::HostResource& audio_id,
+ int32_t result_code,
+ ppapi::proxy::SerializedHandle socket_handle,
+ ppapi::proxy::SerializedHandle handle);
void AudioChannelConnected(int32_t result,
const ppapi::HostResource& resource);
diff --git a/ppapi/proxy/ppb_buffer_proxy.cc b/ppapi/proxy/ppb_buffer_proxy.cc
index 6c4561d..813d340 100644
--- a/ppapi/proxy/ppb_buffer_proxy.cc
+++ b/ppapi/proxy/ppb_buffer_proxy.cc
@@ -75,14 +75,14 @@ PP_Resource PPB_Buffer_Proxy::CreateProxyResource(PP_Instance instance,
return 0;
HostResource result;
- base::SharedMemoryHandle shm_handle = base::SharedMemory::NULLHandle();
+ ppapi::proxy::SerializedHandle shm_handle;
dispatcher->Send(new PpapiHostMsg_PPBBuffer_Create(
- API_ID_PPB_BUFFER, instance, size,
- &result, &shm_handle));
- if (result.is_null() || !base::SharedMemory::IsHandleValid(shm_handle))
+ API_ID_PPB_BUFFER, instance, size, &result, &shm_handle));
+ if (result.is_null() || !shm_handle.IsHandleValid() ||
+ !shm_handle.is_shmem())
return 0;
- return AddProxyResource(result, shm_handle, size);
+ return AddProxyResource(result, shm_handle.shmem(), size);
}
// static
@@ -107,9 +107,9 @@ void PPB_Buffer_Proxy::OnMsgCreate(
PP_Instance instance,
uint32_t size,
HostResource* result_resource,
- base::SharedMemoryHandle* result_shm_handle) {
+ ppapi::proxy::SerializedHandle* result_shm_handle) {
// Overwritten below on success.
- *result_shm_handle = base::SharedMemory::NULLHandle();
+ result_shm_handle->set_null_shmem();
HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
if (!dispatcher)
return;
@@ -142,7 +142,8 @@ void PPB_Buffer_Proxy::OnMsgCreate(
#else
#error Not implemented.
#endif
- *result_shm_handle = dispatcher->ShareHandleWithRemote(platform_file, false);
+ result_shm_handle->set_shmem(
+ dispatcher->ShareHandleWithRemote(platform_file, false), size);
}
} // namespace proxy
diff --git a/ppapi/proxy/ppb_buffer_proxy.h b/ppapi/proxy/ppb_buffer_proxy.h
index cc8f598..41f5e19 100644
--- a/ppapi/proxy/ppb_buffer_proxy.h
+++ b/ppapi/proxy/ppb_buffer_proxy.h
@@ -8,6 +8,7 @@
#include "base/shared_memory.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/proxy/interface_proxy.h"
+#include "ppapi/proxy/serialized_structs.h"
#include "ppapi/shared_impl/resource.h"
#include "ppapi/thunk/ppb_buffer_api.h"
@@ -62,7 +63,7 @@ class PPB_Buffer_Proxy : public InterfaceProxy {
void OnMsgCreate(PP_Instance instance,
uint32_t size,
HostResource* result_resource,
- base::SharedMemoryHandle* result_shm_handle);
+ ppapi::proxy::SerializedHandle* result_shm_handle);
};
} // namespace proxy
diff --git a/ppapi/proxy/ppb_graphics_3d_proxy.cc b/ppapi/proxy/ppb_graphics_3d_proxy.cc
index 25bcd44..a5612c4 100644
--- a/ppapi/proxy/ppb_graphics_3d_proxy.cc
+++ b/ppapi/proxy/ppb_graphics_3d_proxy.cc
@@ -316,18 +316,17 @@ void PPB_Graphics3D_Proxy::OnMsgDestroyTransferBuffer(
void PPB_Graphics3D_Proxy::OnMsgGetTransferBuffer(
const HostResource& context,
int32 id,
- base::SharedMemoryHandle* transfer_buffer,
- uint32* size) {
- *transfer_buffer = base::SharedMemory::NULLHandle();
- *size = 0;
+ ppapi::proxy::SerializedHandle* transfer_buffer) {
+ transfer_buffer->set_null_shmem();
EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
int shm_handle = 0;
uint32_t shm_size = 0;
if (enter.succeeded() &&
enter.object()->GetTransferBuffer(id, &shm_handle, &shm_size)) {
- *transfer_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle);
- *size = shm_size;
+ transfer_buffer->set_shmem(
+ TransportSHMHandleFromInt(dispatcher(), shm_handle),
+ shm_size);
}
}
diff --git a/ppapi/proxy/ppb_graphics_3d_proxy.h b/ppapi/proxy/ppb_graphics_3d_proxy.h
index d16053c..a27da48 100644
--- a/ppapi/proxy/ppb_graphics_3d_proxy.h
+++ b/ppapi/proxy/ppb_graphics_3d_proxy.h
@@ -13,6 +13,7 @@
#include "ppapi/c/pp_instance.h"
#include "ppapi/proxy/interface_proxy.h"
#include "ppapi/proxy/proxy_completion_callback_factory.h"
+#include "ppapi/proxy/serialized_structs.h"
#include "ppapi/shared_impl/ppb_graphics_3d_shared.h"
#include "ppapi/shared_impl/resource.h"
#include "ppapi/utility/completion_callback_factory.h"
@@ -96,8 +97,7 @@ class PPB_Graphics3D_Proxy : public InterfaceProxy {
int32 id);
void OnMsgGetTransferBuffer(const HostResource& context,
int32 id,
- base::SharedMemoryHandle* transfer_buffer,
- uint32* size);
+ ppapi::proxy::SerializedHandle* transfer_buffer);
void OnMsgSwapBuffers(const HostResource& context);
// Renderer->plugin message handlers.
void OnMsgSwapBuffersACK(const HostResource& context,
diff --git a/ppapi/proxy/ppb_image_data_proxy.cc b/ppapi/proxy/ppb_image_data_proxy.cc
index d7c621d..eca9749 100644
--- a/ppapi/proxy/ppb_image_data_proxy.cc
+++ b/ppapi/proxy/ppb_image_data_proxy.cc
@@ -326,7 +326,7 @@ ImageData::ImageData(const HostResource& resource,
map_count_(0),
used_in_replace_contents_(false) {
}
-#endif // !defined(OS_NACL)
+#endif // else, !defined(OS_NACL)
ImageData::~ImageData() {
}
@@ -465,10 +465,13 @@ PP_Resource PPB_ImageData_Proxy::CreateProxyResource(PP_Instance instance,
HostResource result;
std::string image_data_desc;
#if defined(OS_NACL)
- base::SharedMemoryHandle image_handle = base::SharedMemory::NULLHandle();
+ ppapi::proxy::SerializedHandle image_handle_wrapper;
dispatcher->Send(new PpapiHostMsg_PPBImageData_CreateNaCl(
kApiID, instance, format, size, init_to_zero,
- &result, &image_data_desc, &image_handle));
+ &result, &image_data_desc, &image_handle_wrapper));
+ if (!image_handle_wrapper.is_shmem())
+ return 0;
+ base::SharedMemoryHandle image_handle = image_handle_wrapper.shmem();
#else
ImageHandle image_handle = ImageData::NullHandle();
dispatcher->Send(new PpapiHostMsg_PPBImageData_Create(
@@ -554,13 +557,13 @@ void PPB_ImageData_Proxy::OnHostMsgCreateNaCl(
PP_Bool init_to_zero,
HostResource* result,
std::string* image_data_desc,
- base::SharedMemoryHandle* result_image_handle) {
+ ppapi::proxy::SerializedHandle* result_image_handle) {
#if defined(OS_NACL)
// This message should never be received in untrusted code. To minimize the
// size of the IRT, we just don't handle it.
return;
#else
- *result_image_handle = base::SharedMemory::NULLHandle();
+ result_image_handle->set_null_shmem();
HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
if (!dispatcher)
return;
@@ -588,7 +591,6 @@ void PPB_ImageData_Proxy::OnHostMsgCreateNaCl(
uint32_t byte_count;
if (enter_resource.object()->GetSharedMemory(&local_fd, &byte_count) != PP_OK)
return;
-
// TODO(dmichael): Change trusted interface to return a PP_FileHandle, those
// casts are ugly.
base::PlatformFile platform_file =
@@ -599,8 +601,9 @@ void PPB_ImageData_Proxy::OnHostMsgCreateNaCl(
#else
#error Not implemented.
#endif // defined(OS_WIN)
- *result_image_handle =
- dispatcher->ShareHandleWithRemote(platform_file, false);
+ result_image_handle->set_shmem(
+ dispatcher->ShareHandleWithRemote(platform_file, false),
+ byte_count);
#endif // defined(OS_NACL)
}
diff --git a/ppapi/proxy/ppb_image_data_proxy.h b/ppapi/proxy/ppb_image_data_proxy.h
index 046c1ce..3c44dda 100644
--- a/ppapi/proxy/ppb_image_data_proxy.h
+++ b/ppapi/proxy/ppb_image_data_proxy.h
@@ -124,7 +124,7 @@ class PPB_ImageData_Proxy : public InterfaceProxy {
PP_Bool init_to_zero,
HostResource* result,
std::string* image_data_desc,
- base::SharedMemoryHandle* result_image_handle);
+ ppapi::proxy::SerializedHandle* result_image_handle);
// Host->Plugin message handlers.
void OnPluginMsgNotifyUnusedImageData(const HostResource& old_image_data);
diff --git a/ppapi/proxy/serialized_structs.cc b/ppapi/proxy/serialized_structs.cc
index bd17e4d..5e0989f 100644
--- a/ppapi/proxy/serialized_structs.cc
+++ b/ppapi/proxy/serialized_structs.cc
@@ -1,9 +1,10 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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/serialized_structs.h"
+#include "base/pickle.h"
#include "ppapi/c/dev/ppb_font_dev.h"
#include "ppapi/c/pp_file_info.h"
#include "ppapi/c/pp_rect.h"
@@ -78,5 +79,83 @@ PPBFlash_DrawGlyphs_Params::PPBFlash_DrawGlyphs_Params()
PPBFlash_DrawGlyphs_Params::~PPBFlash_DrawGlyphs_Params() {}
+SerializedHandle::SerializedHandle()
+ : type_(INVALID),
+ shm_handle_(base::SharedMemory::NULLHandle()),
+ size_(0),
+ descriptor_(IPC::InvalidPlatformFileForTransit()) {
+}
+
+SerializedHandle::SerializedHandle(Type type_param)
+ : type_(type_param),
+ shm_handle_(base::SharedMemory::NULLHandle()),
+ size_(0),
+ descriptor_(IPC::InvalidPlatformFileForTransit()) {
+}
+
+SerializedHandle::SerializedHandle(const base::SharedMemoryHandle& handle,
+ uint32_t size)
+ : type_(SHARED_MEMORY),
+ shm_handle_(handle),
+ size_(size),
+ descriptor_(IPC::InvalidPlatformFileForTransit()) {
+}
+
+SerializedHandle::SerializedHandle(
+ const IPC::PlatformFileForTransit& socket_descriptor)
+ : type_(SOCKET),
+ shm_handle_(base::SharedMemory::NULLHandle()),
+ size_(0),
+ descriptor_(socket_descriptor) {
+}
+
+bool SerializedHandle::IsHandleValid() const {
+ if (type_ == SHARED_MEMORY)
+ return base::SharedMemory::IsHandleValid(shm_handle_);
+ else if (type_ == SOCKET)
+ return (IPC::InvalidPlatformFileForTransit() == descriptor_);
+ return false;
+}
+
+// static
+bool SerializedHandle::WriteHeader(const Header& hdr, Pickle* pickle) {
+ if (!pickle->WriteInt(hdr.type))
+ return false;
+ if (hdr.type == SHARED_MEMORY) {
+ if (!pickle->WriteUInt32(hdr.size))
+ return false;
+ }
+ return true;
+}
+
+// static
+bool SerializedHandle::ReadHeader(PickleIterator* iter, Header* hdr) {
+ *hdr = Header(INVALID, 0);
+ int type = 0;
+ if (!iter->ReadInt(&type))
+ return false;
+ bool valid_type = false;
+ switch (type) {
+ case SHARED_MEMORY: {
+ uint32_t size = 0;
+ if (!iter->ReadUInt32(&size))
+ return false;
+ hdr->size = size;
+ valid_type = true;
+ break;
+ }
+ case SOCKET:
+ valid_type = true;
+ break;
+ case INVALID:
+ valid_type = true;
+ break;
+ // No default so the compiler will warn us if a new type is added.
+ }
+ if (valid_type)
+ hdr->type = Type(type);
+ return valid_type;
+}
+
} // namespace proxy
} // namespace ppapi
diff --git a/ppapi/proxy/serialized_structs.h b/ppapi/proxy/serialized_structs.h
index 3174449..7ad8456 100644
--- a/ppapi/proxy/serialized_structs.h
+++ b/ppapi/proxy/serialized_structs.h
@@ -8,6 +8,7 @@
#include <string>
#include <vector>
+#include "base/logging.h"
#include "base/shared_memory.h"
#include "build/build_config.h"
#include "ipc/ipc_platform_file.h"
@@ -18,6 +19,7 @@
#include "ppapi/proxy/serialized_var.h"
#include "ppapi/shared_impl/host_resource.h"
+class Pickle;
struct PP_FontDescription_Dev;
namespace ppapi {
@@ -101,6 +103,96 @@ struct PPPVideoCapture_Buffer {
base::SharedMemoryHandle handle;
};
+// We put all our handles in a unified structure to make it easy to translate
+// them in NaClIPCAdapter for use in NaCl.
+class PPAPI_PROXY_EXPORT SerializedHandle {
+ public:
+ enum Type { INVALID, SHARED_MEMORY, SOCKET };
+ struct Header {
+ Header() : type(INVALID), size(0) {}
+ Header(Type type_arg, uint32_t size_arg)
+ : type(type_arg), size(size_arg) {
+ }
+ Type type;
+ uint32_t size;
+ };
+
+ SerializedHandle();
+ // Create an invalid handle of the given type.
+ explicit SerializedHandle(Type type);
+
+ // Create a shared memory handle.
+ SerializedHandle(const base::SharedMemoryHandle& handle, uint32_t size);
+
+ // Create a socket handle.
+ // TODO(dmichael): If we have other ways to use FDs later, this would be
+ // ambiguous.
+ explicit SerializedHandle(
+ const IPC::PlatformFileForTransit& socket_descriptor);
+
+ Type type() const { return type_; }
+ bool is_shmem() const { return type_ == SHARED_MEMORY; }
+ bool is_socket() const { return type_ == SOCKET; }
+ const base::SharedMemoryHandle& shmem() const {
+ DCHECK(is_shmem());
+ return shm_handle_;
+ }
+ uint32_t size() const {
+ DCHECK(is_shmem());
+ return size_;
+ }
+ const IPC::PlatformFileForTransit& descriptor() const {
+ DCHECK(is_socket());
+ return descriptor_;
+ }
+ void set_shmem(const base::SharedMemoryHandle& handle, uint32_t size) {
+ type_ = SHARED_MEMORY;
+ shm_handle_ = handle;
+ size_ = size;
+
+ descriptor_ = IPC::InvalidPlatformFileForTransit();
+ }
+ void set_socket(const IPC::PlatformFileForTransit& socket) {
+ type_ = SOCKET;
+ descriptor_ = socket;
+
+ shm_handle_ = base::SharedMemory::NULLHandle();
+ size_ = 0;
+ }
+ void set_null_shmem() {
+ set_shmem(base::SharedMemory::NULLHandle(), 0);
+ }
+ void set_null_socket() {
+ set_socket(IPC::InvalidPlatformFileForTransit());
+ }
+ bool IsHandleValid() const;
+
+ Header header() const {
+ return Header(type_, size_);
+ }
+
+ // Write/Read a Header, which contains all the data except the handle. This
+ // allows us to write the handle in a platform-specific way, as is necessary
+ // in NaClIPCAdapter to share handles with NaCl from Windows.
+ static bool WriteHeader(const Header& hdr, Pickle* pickle);
+ static bool ReadHeader(PickleIterator* iter, Header* hdr);
+
+ private:
+ // The kind of handle we're holding.
+ Type type_;
+
+ // We hold more members than we really need; we can't easily use a union,
+ // because we hold non-POD types. But these types are pretty light-weight. If
+ // we add more complex things later, we should come up with a more memory-
+ // efficient strategy.
+ // These are valid if type == SHARED_MEMORY.
+ base::SharedMemoryHandle shm_handle_;
+ uint32_t size_;
+
+ // This is valid if type == SOCKET.
+ IPC::PlatformFileForTransit descriptor_;
+};
+
// TODO(tomfinegan): This is identical to PPPVideoCapture_Buffer, maybe replace
// both with a single type?
struct PPPDecryptor_Buffer {
diff --git a/ppapi/proxy/serialized_var.cc b/ppapi/proxy/serialized_var.cc
index e648406..ad416db 100644
--- a/ppapi/proxy/serialized_var.cc
+++ b/ppapi/proxy/serialized_var.cc
@@ -249,7 +249,8 @@ void SerializedVar::Inner::ConvertRawVarData() {
}
case PP_VARTYPE_ARRAY_BUFFER: {
var_ = PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(
- raw_var_data_->data.size(), raw_var_data_->data.data());
+ static_cast<uint32>(raw_var_data_->data.size()),
+ raw_var_data_->data.data());
break;
}
default: