Chromium Code Reviews| 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.h" | 10 #include "ppapi/proxy/content_decryptor_private_serializer.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 const PPB_Core* core = static_cast<const PPB_Core*>( | 84 const PPB_Core* core = static_cast<const PPB_Core*>( |
| 85 dispatcher->local_get_interface()(PPB_CORE_INTERFACE)); | 85 dispatcher->local_get_interface()(PPB_CORE_INTERFACE)); |
| 86 if (!core) { | 86 if (!core) { |
| 87 NOTREACHED(); | 87 NOTREACHED(); |
| 88 return PP_FALSE; | 88 return PP_FALSE; |
| 89 } | 89 } |
| 90 core->AddRefResource(resource); | 90 core->AddRefResource(resource); |
| 91 return PP_TRUE; | 91 return PP_TRUE; |
| 92 } | 92 } |
| 93 | 93 |
| 94 bool InitializePppDecryptorBuffer(PP_Instance instance, | |
| 95 HostDispatcher* dispatcher, | |
| 96 PP_Resource resource, | |
| 97 PPPDecryptor_Buffer* buffer) { | |
| 98 if (!buffer) { | |
| 99 NOTREACHED(); | |
| 100 return false; | |
| 101 } | |
| 102 | |
| 103 if (!AddRefResourceForPlugin(dispatcher, resource)) | |
| 104 return false; | |
| 105 | |
| 106 HostResource host_resource; | |
| 107 host_resource.SetHostResource(instance, resource); | |
| 108 | |
| 109 uint32_t size = 0; | |
| 110 if (DescribeHostBufferResource(resource, &size) == PP_FALSE) | |
| 111 return false; | |
| 112 | |
| 113 base::SharedMemoryHandle handle; | |
| 114 if (ShareHostBufferResourceToPlugin(dispatcher, | |
| 115 resource, | |
| 116 &handle) == PP_FALSE) | |
| 117 return false; | |
| 118 | |
| 119 buffer->resource = host_resource; | |
| 120 buffer->handle = handle; | |
| 121 buffer->size = size; | |
| 122 return true; | |
| 123 } | |
| 124 | |
| 94 void GenerateKeyRequest(PP_Instance instance, | 125 void GenerateKeyRequest(PP_Instance instance, |
| 95 PP_Var key_system, | 126 PP_Var key_system, |
| 96 PP_Var init_data) { | 127 PP_Var init_data) { |
| 97 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 128 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 98 if (!dispatcher) { | 129 if (!dispatcher) { |
| 99 NOTREACHED(); | 130 NOTREACHED(); |
| 100 return; | 131 return; |
| 101 } | 132 } |
| 102 | 133 |
| 103 dispatcher->Send( | 134 dispatcher->Send( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 } | 166 } |
| 136 | 167 |
| 137 dispatcher->Send( | 168 dispatcher->Send( |
| 138 new PpapiMsg_PPPContentDecryptor_CancelKeyRequest( | 169 new PpapiMsg_PPPContentDecryptor_CancelKeyRequest( |
| 139 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, | 170 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, |
| 140 instance, | 171 instance, |
| 141 SerializedVarSendInput(dispatcher, session_id))); | 172 SerializedVarSendInput(dispatcher, session_id))); |
| 142 } | 173 } |
| 143 | 174 |
| 144 void Decrypt(PP_Instance instance, | 175 void Decrypt(PP_Instance instance, |
| 145 PP_Resource encrypted_block, | 176 PP_Resource encrypted_block, |
| 146 const PP_EncryptedBlockInfo* encrypted_block_info) { | 177 const PP_EncryptedBlockInfo* encrypted_block_info) { |
| 147 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 178 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 148 if (!dispatcher) { | 179 if (!dispatcher) { |
| 149 NOTREACHED(); | 180 NOTREACHED(); |
| 150 return; | 181 return; |
| 151 } | 182 } |
| 152 | 183 |
| 153 if (!AddRefResourceForPlugin(dispatcher, encrypted_block)) { | 184 PPPDecryptor_Buffer buffer; |
| 185 if (!InitializePppDecryptorBuffer(instance, | |
| 186 dispatcher, | |
| 187 encrypted_block, | |
| 188 &buffer)) { | |
| 154 NOTREACHED(); | 189 NOTREACHED(); |
| 155 return; | 190 return; |
| 156 } | 191 } |
| 157 | 192 |
| 158 HostResource host_resource; | 193 std::string serialized_block_info; |
| 159 host_resource.SetHostResource(instance, encrypted_block); | 194 if (!SerializeBlockInfo(*encrypted_block_info, &serialized_block_info)) { |
| 160 | 195 NOTREACHED(); |
| 161 uint32_t size = 0; | |
| 162 if (DescribeHostBufferResource(encrypted_block, &size) == PP_FALSE) | |
| 163 return; | 196 return; |
| 164 | 197 } |
| 165 base::SharedMemoryHandle handle; | |
| 166 if (ShareHostBufferResourceToPlugin(dispatcher, | |
| 167 encrypted_block, | |
| 168 &handle) == PP_FALSE) | |
| 169 return; | |
| 170 | |
| 171 PPPDecryptor_Buffer buffer; | |
| 172 buffer.resource = host_resource; | |
| 173 buffer.handle = handle; | |
| 174 buffer.size = size; | |
| 175 | |
| 176 std::string serialized_block_info; | |
| 177 if (!SerializeBlockInfo(*encrypted_block_info, &serialized_block_info)) | |
| 178 return; | |
| 179 | 198 |
| 180 dispatcher->Send( | 199 dispatcher->Send( |
| 181 new PpapiMsg_PPPContentDecryptor_Decrypt( | 200 new PpapiMsg_PPPContentDecryptor_Decrypt( |
| 182 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, | 201 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, |
| 183 instance, | 202 instance, |
| 184 buffer, | 203 buffer, |
| 185 serialized_block_info)); | 204 serialized_block_info)); |
| 186 } | 205 } |
| 187 | 206 |
| 207 void InitializeVideoDecoder( | |
| 208 PP_Instance instance, | |
| 209 const PP_VideoDecoderConfig* decoder_config, | |
| 210 PP_Resource extra_data_buffer) { | |
| 211 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | |
| 212 if (!dispatcher) { | |
| 213 NOTREACHED(); | |
| 214 return; | |
| 215 } | |
| 216 | |
| 217 std::string serialized_decoder_config; | |
| 218 if (!SerializeBlockInfo(*decoder_config, &serialized_decoder_config)) { | |
| 219 NOTREACHED(); | |
| 220 return; | |
| 221 } | |
| 222 | |
| 223 PPPDecryptor_Buffer buffer; | |
| 224 if (!InitializePppDecryptorBuffer(instance, | |
| 225 dispatcher, | |
| 226 extra_data_buffer, | |
| 227 &buffer)) { | |
| 228 NOTREACHED(); | |
| 229 return; | |
| 230 } | |
| 231 | |
| 232 dispatcher->Send( | |
| 233 new PpapiMsg_PPPContentDecryptor_InitializeVideoDecoder( | |
| 234 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, | |
| 235 instance, | |
| 236 serialized_decoder_config, | |
| 237 buffer)); | |
| 238 } | |
| 239 | |
| 240 | |
| 188 void DecryptAndDecodeFrame( | 241 void DecryptAndDecodeFrame( |
| 189 PP_Instance instance, | 242 PP_Instance instance, |
| 190 PP_Resource encrypted_frame, | 243 PP_Resource encrypted_frame, |
| 191 const PP_EncryptedVideoFrameInfo* encrypted_video_frame_info) { | 244 const PP_EncryptedVideoFrameInfo* encrypted_video_frame_info) { |
| 192 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 245 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 193 if (!dispatcher) { | 246 if (!dispatcher) { |
| 194 NOTREACHED(); | 247 NOTREACHED(); |
| 195 return; | 248 return; |
| 196 } | 249 } |
| 197 | 250 |
| 198 if (!AddRefResourceForPlugin(dispatcher, encrypted_frame)) { | 251 PPPDecryptor_Buffer buffer; |
| 252 if (!InitializePppDecryptorBuffer(instance, | |
| 253 dispatcher, | |
| 254 encrypted_frame, | |
| 255 &buffer)) { | |
| 199 NOTREACHED(); | 256 NOTREACHED(); |
| 200 return; | 257 return; |
| 201 } | 258 } |
| 202 | 259 |
| 203 HostResource host_resource; | 260 std::string serialized_frame_info; |
| 204 host_resource.SetHostResource(instance, encrypted_frame); | 261 if (!SerializeBlockInfo(*encrypted_video_frame_info, |
| 205 | 262 &serialized_frame_info)) { |
| 206 uint32_t size = 0; | 263 NOTREACHED(); |
| 207 if (DescribeHostBufferResource(encrypted_frame, &size) == PP_FALSE) | |
| 208 return; | 264 return; |
| 209 | 265 } |
| 210 base::SharedMemoryHandle handle; | |
| 211 if (ShareHostBufferResourceToPlugin(dispatcher, | |
| 212 encrypted_frame, | |
| 213 &handle) == PP_FALSE) | |
| 214 return; | |
| 215 | |
| 216 PPPDecryptor_Buffer buffer; | |
| 217 buffer.resource = host_resource; | |
| 218 buffer.handle = handle; | |
| 219 buffer.size = size; | |
| 220 | |
| 221 std::string serialized_frame_info; | |
| 222 if (!SerializeBlockInfo(*encrypted_video_frame_info, &serialized_frame_info)) | |
| 223 return; | |
| 224 | 266 |
| 225 dispatcher->Send( | 267 dispatcher->Send( |
| 226 new PpapiMsg_PPPContentDecryptor_DecryptAndDecodeFrame( | 268 new PpapiMsg_PPPContentDecryptor_DecryptAndDecodeFrame( |
| 227 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, | 269 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, |
| 228 instance, | 270 instance, |
| 229 buffer, | 271 buffer, |
| 230 serialized_frame_info)); | 272 serialized_frame_info)); |
| 231 } | 273 } |
| 232 | 274 |
| 233 static const PPP_ContentDecryptor_Private content_decryptor_interface = { | 275 static const PPP_ContentDecryptor_Private content_decryptor_interface = { |
| 234 &GenerateKeyRequest, | 276 &GenerateKeyRequest, |
| 235 &AddKey, | 277 &AddKey, |
| 236 &CancelKeyRequest, | 278 &CancelKeyRequest, |
| 237 &Decrypt, | 279 &Decrypt, |
| 280 &InitializeVideoDecoder, | |
| 238 &DecryptAndDecodeFrame | 281 &DecryptAndDecodeFrame |
| 239 }; | 282 }; |
| 240 | 283 |
| 241 } // namespace | 284 } // namespace |
| 242 | 285 |
| 243 PPP_ContentDecryptor_Private_Proxy::PPP_ContentDecryptor_Private_Proxy( | 286 PPP_ContentDecryptor_Private_Proxy::PPP_ContentDecryptor_Private_Proxy( |
| 244 Dispatcher* dispatcher) | 287 Dispatcher* dispatcher) |
| 245 : InterfaceProxy(dispatcher), | 288 : InterfaceProxy(dispatcher), |
| 246 ppp_decryptor_impl_(NULL) { | 289 ppp_decryptor_impl_(NULL) { |
| 247 if (dispatcher->IsPlugin()) { | 290 if (dispatcher->IsPlugin()) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 265 bool handled = true; | 308 bool handled = true; |
| 266 IPC_BEGIN_MESSAGE_MAP(PPP_ContentDecryptor_Private_Proxy, msg) | 309 IPC_BEGIN_MESSAGE_MAP(PPP_ContentDecryptor_Private_Proxy, msg) |
| 267 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_GenerateKeyRequest, | 310 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_GenerateKeyRequest, |
| 268 OnMsgGenerateKeyRequest) | 311 OnMsgGenerateKeyRequest) |
| 269 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_AddKey, | 312 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_AddKey, |
| 270 OnMsgAddKey) | 313 OnMsgAddKey) |
| 271 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_CancelKeyRequest, | 314 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_CancelKeyRequest, |
| 272 OnMsgCancelKeyRequest) | 315 OnMsgCancelKeyRequest) |
| 273 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_Decrypt, | 316 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_Decrypt, |
| 274 OnMsgDecrypt) | 317 OnMsgDecrypt) |
| 318 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_InitializeVideoDecoder, | |
| 319 OnMsgInitializeVideoDecoder) | |
| 275 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_DecryptAndDecodeFrame, | 320 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_DecryptAndDecodeFrame, |
| 276 OnMsgDecryptAndDecodeFrame) | 321 OnMsgDecryptAndDecodeFrame) |
| 277 IPC_MESSAGE_UNHANDLED(handled = false) | 322 IPC_MESSAGE_UNHANDLED(handled = false) |
| 278 IPC_END_MESSAGE_MAP() | 323 IPC_END_MESSAGE_MAP() |
| 279 DCHECK(handled); | 324 DCHECK(handled); |
| 280 return handled; | 325 return handled; |
| 281 } | 326 } |
| 282 | 327 |
| 283 void PPP_ContentDecryptor_Private_Proxy::OnMsgGenerateKeyRequest( | 328 void PPP_ContentDecryptor_Private_Proxy::OnMsgGenerateKeyRequest( |
| 284 PP_Instance instance, | 329 PP_Instance instance, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 PP_EncryptedBlockInfo block_info; | 373 PP_EncryptedBlockInfo block_info; |
| 329 if (!DeserializeBlockInfo(serialized_block_info, &block_info)) | 374 if (!DeserializeBlockInfo(serialized_block_info, &block_info)) |
| 330 return; | 375 return; |
| 331 CallWhileUnlocked(ppp_decryptor_impl_->Decrypt, | 376 CallWhileUnlocked(ppp_decryptor_impl_->Decrypt, |
| 332 instance, | 377 instance, |
| 333 plugin_resource, | 378 plugin_resource, |
| 334 const_cast<const PP_EncryptedBlockInfo*>(&block_info)); | 379 const_cast<const PP_EncryptedBlockInfo*>(&block_info)); |
| 335 } | 380 } |
| 336 } | 381 } |
| 337 | 382 |
| 383 void PPP_ContentDecryptor_Private_Proxy::OnMsgInitializeVideoDecoder( | |
| 384 PP_Instance instance, | |
| 385 const std::string& serialized_decoder_config, | |
| 386 const PPPDecryptor_Buffer& extra_data_buffer) { | |
| 387 | |
| 388 PP_VideoDecoderConfig decoder_config; | |
| 389 if (!DeserializeBlockInfo(serialized_decoder_config, &decoder_config)) | |
| 390 return; | |
| 391 | |
| 392 if (ppp_decryptor_impl_) { | |
| 393 PP_Resource plugin_resource = 0; | |
| 394 if (extra_data_buffer.size > 0) { | |
| 395 plugin_resource = | |
| 396 PPB_Buffer_Proxy::AddProxyResource(extra_data_buffer.resource, | |
| 397 extra_data_buffer.handle, | |
| 398 extra_data_buffer.size); | |
| 399 } | |
| 400 | |
| 401 CallWhileUnlocked( | |
| 402 ppp_decryptor_impl_->InitializeVideoDecoder, | |
| 403 instance, | |
| 404 const_cast<const PP_VideoDecoderConfig*>(&decoder_config), | |
|
brettw
2012/10/11 20:45:58
Are you sure you need this const cast? I thought t
Tom Finegan
2012/10/11 21:04:04
Can't construct the base::Closure because of non-c
| |
| 405 plugin_resource); | |
| 406 } | |
| 407 } | |
| 408 | |
| 338 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecryptAndDecodeFrame( | 409 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecryptAndDecodeFrame( |
| 339 PP_Instance instance, | 410 PP_Instance instance, |
| 340 const PPPDecryptor_Buffer& encrypted_frame, | 411 const PPPDecryptor_Buffer& encrypted_frame, |
| 341 const std::string& serialized_frame_info) { | 412 const std::string& serialized_frame_info) { |
| 342 if (ppp_decryptor_impl_) { | 413 if (ppp_decryptor_impl_) { |
| 343 PP_Resource plugin_resource = | 414 PP_Resource plugin_resource = |
| 344 PPB_Buffer_Proxy::AddProxyResource(encrypted_frame.resource, | 415 PPB_Buffer_Proxy::AddProxyResource(encrypted_frame.resource, |
| 345 encrypted_frame.handle, | 416 encrypted_frame.handle, |
| 346 encrypted_frame.size); | 417 encrypted_frame.size); |
| 347 PP_EncryptedVideoFrameInfo frame_info; | 418 PP_EncryptedVideoFrameInfo frame_info; |
| 348 if (!DeserializeBlockInfo(serialized_frame_info, &frame_info)) | 419 if (!DeserializeBlockInfo(serialized_frame_info, &frame_info)) |
| 349 return; | 420 return; |
| 350 CallWhileUnlocked( | 421 CallWhileUnlocked( |
| 351 ppp_decryptor_impl_->DecryptAndDecodeFrame, | 422 ppp_decryptor_impl_->DecryptAndDecodeFrame, |
| 352 instance, | 423 instance, |
| 353 plugin_resource, | 424 plugin_resource, |
| 354 const_cast<const PP_EncryptedVideoFrameInfo*>(&frame_info)); | 425 const_cast<const PP_EncryptedVideoFrameInfo*>(&frame_info)); |
| 355 } | 426 } |
| 356 } | 427 } |
| 357 | 428 |
| 358 } // namespace proxy | 429 } // namespace proxy |
| 359 } // namespace ppapi | 430 } // namespace ppapi |
| OLD | NEW |