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_buffer_proxy.h" | 5 #include "ppapi/proxy/ppb_buffer_proxy.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 68 } |
69 | 69 |
70 // static | 70 // static |
71 PP_Resource PPB_Buffer_Proxy::CreateProxyResource(PP_Instance instance, | 71 PP_Resource PPB_Buffer_Proxy::CreateProxyResource(PP_Instance instance, |
72 uint32_t size) { | 72 uint32_t size) { |
73 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 73 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
74 if (!dispatcher) | 74 if (!dispatcher) |
75 return 0; | 75 return 0; |
76 | 76 |
77 HostResource result; | 77 HostResource result; |
78 base::SharedMemoryHandle shm_handle = base::SharedMemory::NULLHandle(); | 78 ppapi::proxy::SerializedHandle shm_handle; |
79 dispatcher->Send(new PpapiHostMsg_PPBBuffer_Create( | 79 dispatcher->Send(new PpapiHostMsg_PPBBuffer_Create( |
80 API_ID_PPB_BUFFER, instance, size, | 80 API_ID_PPB_BUFFER, instance, size, &result, &shm_handle)); |
81 &result, &shm_handle)); | 81 if (result.is_null() || !shm_handle.IsHandleValid() || |
82 if (result.is_null() || !base::SharedMemory::IsHandleValid(shm_handle)) | 82 !shm_handle.is_shmem()) |
83 return 0; | 83 return 0; |
84 | 84 |
85 return AddProxyResource(result, shm_handle, size); | 85 return AddProxyResource(result, shm_handle.shmem(), size); |
86 } | 86 } |
87 | 87 |
88 // static | 88 // static |
89 PP_Resource PPB_Buffer_Proxy::AddProxyResource( | 89 PP_Resource PPB_Buffer_Proxy::AddProxyResource( |
90 const HostResource& resource, | 90 const HostResource& resource, |
91 base::SharedMemoryHandle shm_handle, | 91 base::SharedMemoryHandle shm_handle, |
92 uint32_t size) { | 92 uint32_t size) { |
93 return (new Buffer(resource, shm_handle, size))->GetReference(); | 93 return (new Buffer(resource, shm_handle, size))->GetReference(); |
94 } | 94 } |
95 | 95 |
96 bool PPB_Buffer_Proxy::OnMessageReceived(const IPC::Message& msg) { | 96 bool PPB_Buffer_Proxy::OnMessageReceived(const IPC::Message& msg) { |
97 bool handled = true; | 97 bool handled = true; |
98 IPC_BEGIN_MESSAGE_MAP(PPB_Buffer_Proxy, msg) | 98 IPC_BEGIN_MESSAGE_MAP(PPB_Buffer_Proxy, msg) |
99 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBBuffer_Create, OnMsgCreate) | 99 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBBuffer_Create, OnMsgCreate) |
100 IPC_MESSAGE_UNHANDLED(handled = false) | 100 IPC_MESSAGE_UNHANDLED(handled = false) |
101 IPC_END_MESSAGE_MAP() | 101 IPC_END_MESSAGE_MAP() |
102 // TODO(brettw) handle bad messages! | 102 // TODO(brettw) handle bad messages! |
103 return handled; | 103 return handled; |
104 } | 104 } |
105 | 105 |
106 void PPB_Buffer_Proxy::OnMsgCreate( | 106 void PPB_Buffer_Proxy::OnMsgCreate( |
107 PP_Instance instance, | 107 PP_Instance instance, |
108 uint32_t size, | 108 uint32_t size, |
109 HostResource* result_resource, | 109 HostResource* result_resource, |
110 base::SharedMemoryHandle* result_shm_handle) { | 110 ppapi::proxy::SerializedHandle* result_shm_handle) { |
111 // Overwritten below on success. | 111 // Overwritten below on success. |
112 *result_shm_handle = base::SharedMemory::NULLHandle(); | 112 result_shm_handle->set_null_shmem(); |
113 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 113 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
114 if (!dispatcher) | 114 if (!dispatcher) |
115 return; | 115 return; |
116 | 116 |
117 thunk::EnterResourceCreation enter(instance); | 117 thunk::EnterResourceCreation enter(instance); |
118 if (enter.failed()) | 118 if (enter.failed()) |
119 return; | 119 return; |
120 PP_Resource local_buffer_resource = enter.functions()->CreateBuffer(instance, | 120 PP_Resource local_buffer_resource = enter.functions()->CreateBuffer(instance, |
121 size); | 121 size); |
122 if (local_buffer_resource == 0) | 122 if (local_buffer_resource == 0) |
(...skipping 12 matching lines...) Expand all Loading... |
135 // TODO(piman/brettw): Change trusted interface to return a PP_FileHandle, | 135 // TODO(piman/brettw): Change trusted interface to return a PP_FileHandle, |
136 // those casts are ugly. | 136 // those casts are ugly. |
137 base::PlatformFile platform_file = | 137 base::PlatformFile platform_file = |
138 #if defined(OS_WIN) | 138 #if defined(OS_WIN) |
139 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)); | 139 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)); |
140 #elif defined(OS_POSIX) | 140 #elif defined(OS_POSIX) |
141 local_fd; | 141 local_fd; |
142 #else | 142 #else |
143 #error Not implemented. | 143 #error Not implemented. |
144 #endif | 144 #endif |
145 *result_shm_handle = dispatcher->ShareHandleWithRemote(platform_file, false); | 145 result_shm_handle->set_shmem( |
| 146 dispatcher->ShareHandleWithRemote(platform_file, false), size); |
146 } | 147 } |
147 | 148 |
148 } // namespace proxy | 149 } // namespace proxy |
149 } // namespace ppapi | 150 } // namespace ppapi |
OLD | NEW |