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/ppp_content_decryptor_private_proxy.h" | 5 #include "ppapi/proxy/ppp_content_decryptor_private_proxy.h" |
6 | 6 |
7 #include "base/platform_file.h" | 7 #include "base/platform_file.h" |
8 #include "ppapi/c/pp_bool.h" | 8 #include "ppapi/c/pp_bool.h" |
9 #include "ppapi/c/ppb_core.h" | 9 #include "ppapi/c/ppb_core.h" |
10 #include "ppapi/proxy/content_decryptor_private_serializer-inl.h" | |
10 #include "ppapi/proxy/host_dispatcher.h" | 11 #include "ppapi/proxy/host_dispatcher.h" |
11 #include "ppapi/proxy/plugin_globals.h" | 12 #include "ppapi/proxy/plugin_globals.h" |
12 #include "ppapi/proxy/plugin_resource_tracker.h" | 13 #include "ppapi/proxy/plugin_resource_tracker.h" |
13 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
14 #include "ppapi/proxy/ppb_buffer_proxy.h" | 15 #include "ppapi/proxy/ppb_buffer_proxy.h" |
15 #include "ppapi/proxy/serialized_var.h" | 16 #include "ppapi/proxy/serialized_var.h" |
16 #include "ppapi/shared_impl/var_tracker.h" | 17 #include "ppapi/shared_impl/var_tracker.h" |
17 #include "ppapi/thunk/enter.h" | 18 #include "ppapi/thunk/enter.h" |
18 #include "ppapi/thunk/ppb_buffer_api.h" | 19 #include "ppapi/thunk/ppb_buffer_api.h" |
19 #include "ppapi/thunk/ppb_buffer_trusted_api.h" | 20 #include "ppapi/thunk/ppb_buffer_trusted_api.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 return PP_FromBool(dispatcher->Send( | 87 return PP_FromBool(dispatcher->Send( |
87 new PpapiMsg_PPPContentDecryptor_GenerateKeyRequest( | 88 new PpapiMsg_PPPContentDecryptor_GenerateKeyRequest( |
88 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, | 89 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, |
89 instance, | 90 instance, |
90 SerializedVarSendInput(dispatcher, key_system), | 91 SerializedVarSendInput(dispatcher, key_system), |
91 SerializedVarSendInput(dispatcher, init_data)))); | 92 SerializedVarSendInput(dispatcher, init_data)))); |
92 } | 93 } |
93 | 94 |
94 PP_Bool AddKey(PP_Instance instance, | 95 PP_Bool AddKey(PP_Instance instance, |
95 PP_Var session_id, | 96 PP_Var session_id, |
96 PP_Var key) { | 97 PP_Var key, |
98 PP_Var init_data) { | |
97 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 99 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
98 if (!dispatcher) { | 100 if (!dispatcher) { |
99 NOTREACHED(); | 101 NOTREACHED(); |
100 return PP_FALSE; | 102 return PP_FALSE; |
101 } | 103 } |
102 | 104 |
103 return PP_FromBool(dispatcher->Send( | 105 return PP_FromBool(dispatcher->Send( |
104 new PpapiMsg_PPPContentDecryptor_AddKey( | 106 new PpapiMsg_PPPContentDecryptor_AddKey( |
105 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, | 107 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, |
106 instance, | 108 instance, |
107 SerializedVarSendInput(dispatcher, session_id), | 109 SerializedVarSendInput(dispatcher, session_id), |
108 SerializedVarSendInput(dispatcher, key)))); | 110 SerializedVarSendInput(dispatcher, key), |
111 SerializedVarSendInput(dispatcher, init_data)))); | |
109 } | 112 } |
110 | 113 |
111 PP_Bool CancelKeyRequest(PP_Instance instance, PP_Var session_id) { | 114 PP_Bool CancelKeyRequest(PP_Instance instance, PP_Var session_id) { |
112 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 115 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
113 if (!dispatcher) { | 116 if (!dispatcher) { |
114 NOTREACHED(); | 117 NOTREACHED(); |
115 return PP_FALSE; | 118 return PP_FALSE; |
116 } | 119 } |
117 | 120 |
118 return PP_FromBool(dispatcher->Send( | 121 return PP_FromBool(dispatcher->Send( |
119 new PpapiMsg_PPPContentDecryptor_CancelKeyRequest( | 122 new PpapiMsg_PPPContentDecryptor_CancelKeyRequest( |
120 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, | 123 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, |
121 instance, | 124 instance, |
122 SerializedVarSendInput(dispatcher, session_id)))); | 125 SerializedVarSendInput(dispatcher, session_id)))); |
123 } | 126 } |
124 | 127 |
125 PP_Bool Decrypt(PP_Instance instance, | 128 PP_Bool Decrypt(PP_Instance instance, |
126 PP_Resource encrypted_block, | 129 PP_Resource encrypted_block, |
127 int32_t request_id) { | 130 const PP_EncryptedBlockInfo* encrypted_block_info) { |
128 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 131 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
129 if (!dispatcher) { | 132 if (!dispatcher) { |
130 NOTREACHED(); | 133 NOTREACHED(); |
131 return PP_FALSE; | 134 return PP_FALSE; |
132 } | 135 } |
133 const PPB_Core* core = static_cast<const PPB_Core*>( | 136 const PPB_Core* core = static_cast<const PPB_Core*>( |
134 dispatcher->local_get_interface()(PPB_CORE_INTERFACE)); | 137 dispatcher->local_get_interface()(PPB_CORE_INTERFACE)); |
135 if (!core) { | 138 if (!core) { |
136 NOTREACHED(); | 139 NOTREACHED(); |
137 return PP_FALSE; | 140 return PP_FALSE; |
(...skipping 15 matching lines...) Expand all Loading... | |
153 if (ShareHostBufferResourceToPlugin(dispatcher, | 156 if (ShareHostBufferResourceToPlugin(dispatcher, |
154 encrypted_block, | 157 encrypted_block, |
155 &handle) == PP_FALSE) | 158 &handle) == PP_FALSE) |
156 return PP_FALSE; | 159 return PP_FALSE; |
157 | 160 |
158 PPPDecryptor_Buffer buffer; | 161 PPPDecryptor_Buffer buffer; |
159 buffer.resource = host_resource; | 162 buffer.resource = host_resource; |
160 buffer.handle = handle; | 163 buffer.handle = handle; |
161 buffer.size = size; | 164 buffer.size = size; |
162 | 165 |
166 using ppapi::proxy::SerializeBlockInfo; | |
Tom Finegan
2012/08/20 21:31:45
Should I just do this at file scope?
dmichael (off chromium)
2012/08/21 17:37:08
Why do you even need it? Aren't you in ppapi::prox
Tom Finegan
2012/08/21 22:57:38
Oops; question mooted.
| |
167 std::string serialized_block_info; | |
168 if (!SerializeBlockInfo(encrypted_block_info, &serialized_block_info)) | |
169 return PP_FALSE; | |
170 | |
163 return PP_FromBool(dispatcher->Send( | 171 return PP_FromBool(dispatcher->Send( |
164 new PpapiMsg_PPPContentDecryptor_Decrypt( | 172 new PpapiMsg_PPPContentDecryptor_Decrypt( |
165 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, | 173 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, |
166 instance, | 174 instance, |
167 buffer, | 175 buffer, |
168 request_id))); | 176 serialized_block_info))); |
169 } | 177 } |
170 | 178 |
171 PP_Bool DecryptAndDecode(PP_Instance instance, | 179 PP_Bool DecryptAndDecode(PP_Instance instance, |
172 PP_Resource encrypted_block, | 180 PP_Resource encrypted_block, |
173 int32_t request_id) { | 181 const PP_EncryptedBlockInfo* encrypted_block_info) { |
174 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 182 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
175 if (!dispatcher) { | 183 if (!dispatcher) { |
176 NOTREACHED(); | 184 NOTREACHED(); |
177 return PP_FALSE; | 185 return PP_FALSE; |
178 } | 186 } |
179 | 187 |
180 HostResource host_resource; | 188 HostResource host_resource; |
181 host_resource.SetHostResource(instance, encrypted_block); | 189 host_resource.SetHostResource(instance, encrypted_block); |
182 | 190 |
191 uint32_t size = 0; | |
192 if (DescribeHostBufferResource(encrypted_block, &size) == PP_FALSE) | |
193 return PP_FALSE; | |
194 | |
195 base::SharedMemoryHandle handle; | |
196 if (ShareHostBufferResourceToPlugin(dispatcher, | |
197 encrypted_block, | |
198 &handle) == PP_FALSE) | |
199 return PP_FALSE; | |
200 | |
201 PPPDecryptor_Buffer buffer; | |
202 buffer.resource = host_resource; | |
203 buffer.handle = handle; | |
204 buffer.size = size; | |
205 | |
206 using ppapi::proxy::SerializeBlockInfo; | |
207 std::string serialized_block_info; | |
208 if (!SerializeBlockInfo(encrypted_block_info, &serialized_block_info)) | |
209 return PP_FALSE; | |
210 | |
183 return PP_FromBool(dispatcher->Send( | 211 return PP_FromBool(dispatcher->Send( |
184 new PpapiMsg_PPPContentDecryptor_DecryptAndDecode( | 212 new PpapiMsg_PPPContentDecryptor_DecryptAndDecode( |
185 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, | 213 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, |
186 instance, | 214 instance, |
187 host_resource, | 215 buffer, |
188 request_id))); | 216 serialized_block_info))); |
189 } | 217 } |
190 | 218 |
191 static const PPP_ContentDecryptor_Private content_decryptor_interface = { | 219 static const PPP_ContentDecryptor_Private content_decryptor_interface = { |
192 &GenerateKeyRequest, | 220 &GenerateKeyRequest, |
193 &AddKey, | 221 &AddKey, |
194 &CancelKeyRequest, | 222 &CancelKeyRequest, |
195 &Decrypt, | 223 &Decrypt, |
196 &DecryptAndDecode | 224 &DecryptAndDecode |
197 }; | 225 }; |
198 | 226 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 CallWhileUnlocked(ppp_decryptor_impl_->GenerateKeyRequest, | 278 CallWhileUnlocked(ppp_decryptor_impl_->GenerateKeyRequest, |
251 instance, | 279 instance, |
252 ExtractReceivedVarAndAddRef(dispatcher(), &key_system), | 280 ExtractReceivedVarAndAddRef(dispatcher(), &key_system), |
253 ExtractReceivedVarAndAddRef(dispatcher(), &init_data)); | 281 ExtractReceivedVarAndAddRef(dispatcher(), &init_data)); |
254 } | 282 } |
255 } | 283 } |
256 | 284 |
257 void PPP_ContentDecryptor_Private_Proxy::OnMsgAddKey( | 285 void PPP_ContentDecryptor_Private_Proxy::OnMsgAddKey( |
258 PP_Instance instance, | 286 PP_Instance instance, |
259 SerializedVarReceiveInput session_id, | 287 SerializedVarReceiveInput session_id, |
260 SerializedVarReceiveInput key) { | 288 SerializedVarReceiveInput key, |
289 SerializedVarReceiveInput init_data) { | |
261 if (ppp_decryptor_impl_) { | 290 if (ppp_decryptor_impl_) { |
262 CallWhileUnlocked(ppp_decryptor_impl_->AddKey, | 291 CallWhileUnlocked(ppp_decryptor_impl_->AddKey, |
263 instance, | 292 instance, |
264 ExtractReceivedVarAndAddRef(dispatcher(), &session_id), | 293 ExtractReceivedVarAndAddRef(dispatcher(), &session_id), |
265 ExtractReceivedVarAndAddRef(dispatcher(), &key)); | 294 ExtractReceivedVarAndAddRef(dispatcher(), &key), |
295 ExtractReceivedVarAndAddRef(dispatcher(), &init_data)); | |
266 } | 296 } |
267 } | 297 } |
268 | 298 |
269 void PPP_ContentDecryptor_Private_Proxy::OnMsgCancelKeyRequest( | 299 void PPP_ContentDecryptor_Private_Proxy::OnMsgCancelKeyRequest( |
270 PP_Instance instance, | 300 PP_Instance instance, |
271 SerializedVarReceiveInput session_id) { | 301 SerializedVarReceiveInput session_id) { |
272 if (ppp_decryptor_impl_) { | 302 if (ppp_decryptor_impl_) { |
273 CallWhileUnlocked(ppp_decryptor_impl_->CancelKeyRequest, | 303 CallWhileUnlocked(ppp_decryptor_impl_->CancelKeyRequest, |
274 instance, | 304 instance, |
275 ExtractReceivedVarAndAddRef(dispatcher(), &session_id)); | 305 ExtractReceivedVarAndAddRef(dispatcher(), &session_id)); |
276 } | 306 } |
277 } | 307 } |
278 | 308 |
279 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecrypt( | 309 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecrypt( |
280 PP_Instance instance, | 310 PP_Instance instance, |
281 const PPPDecryptor_Buffer& encrypted_buffer, | 311 const PPPDecryptor_Buffer& encrypted_buffer, |
282 int32_t request_id) { | 312 const std::string& serialized_block_info) { |
283 if (ppp_decryptor_impl_) { | 313 if (ppp_decryptor_impl_) { |
284 PP_Resource plugin_resource = | 314 PP_Resource plugin_resource = |
285 PPB_Buffer_Proxy::AddProxyResource(encrypted_buffer.resource, | 315 PPB_Buffer_Proxy::AddProxyResource(encrypted_buffer.resource, |
286 encrypted_buffer.handle, | 316 encrypted_buffer.handle, |
287 encrypted_buffer.size); | 317 encrypted_buffer.size); |
318 PP_EncryptedBlockInfo block_info; | |
319 if (!DeserializeBlockInfo(serialized_block_info, &block_info)) | |
320 return; | |
288 CallWhileUnlocked(ppp_decryptor_impl_->Decrypt, | 321 CallWhileUnlocked(ppp_decryptor_impl_->Decrypt, |
289 instance, | 322 instance, |
290 plugin_resource, | 323 plugin_resource, |
291 request_id); | 324 const_cast<const PP_EncryptedBlockInfo*>(&block_info)); |
xhwang
2012/08/20 22:19:31
Do you need this const cast?
Tom Finegan
2012/08/20 22:50:03
Yeah, clang refuses to compile without it:
../../
dmichael (off chromium)
2012/08/21 17:37:08
Oops, yeah, we could also improve the CallWhileUnl
| |
292 } | 325 } |
293 } | 326 } |
294 | 327 |
295 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecryptAndDecode( | 328 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecryptAndDecode( |
296 PP_Instance instance, | 329 PP_Instance instance, |
297 const HostResource& encrypted_block, | 330 const PPPDecryptor_Buffer& encrypted_buffer, |
298 int32_t request_id) { | 331 const std::string& serialized_block_info) { |
299 if (ppp_decryptor_impl_) { | 332 if (ppp_decryptor_impl_) { |
300 PP_Resource plugin_resource = | 333 PP_Resource plugin_resource = |
301 PluginGlobals::Get()->plugin_resource_tracker()-> | 334 PPB_Buffer_Proxy::AddProxyResource(encrypted_buffer.resource, |
302 PluginResourceForHostResource(encrypted_block); | 335 encrypted_buffer.handle, |
336 encrypted_buffer.size); | |
337 PP_EncryptedBlockInfo block_info; | |
338 if (!DeserializeBlockInfo(serialized_block_info, &block_info)) | |
339 return; | |
303 CallWhileUnlocked(ppp_decryptor_impl_->DecryptAndDecode, | 340 CallWhileUnlocked(ppp_decryptor_impl_->DecryptAndDecode, |
304 instance, | 341 instance, |
305 plugin_resource, | 342 plugin_resource, |
306 request_id); | 343 const_cast<const PP_EncryptedBlockInfo*>(&block_info)); |
307 } | 344 } |
308 } | 345 } |
309 | 346 |
310 } // namespace proxy | 347 } // namespace proxy |
311 } // namespace ppapi | 348 } // namespace ppapi |
OLD | NEW |