| 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/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 std::string serialized_block_info; |
| 167 if (!SerializeBlockInfo(*encrypted_block_info, &serialized_block_info)) |
| 168 return PP_FALSE; |
| 169 |
| 163 return PP_FromBool(dispatcher->Send( | 170 return PP_FromBool(dispatcher->Send( |
| 164 new PpapiMsg_PPPContentDecryptor_Decrypt( | 171 new PpapiMsg_PPPContentDecryptor_Decrypt( |
| 165 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, | 172 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, |
| 166 instance, | 173 instance, |
| 167 buffer, | 174 buffer, |
| 168 request_id))); | 175 serialized_block_info))); |
| 169 } | 176 } |
| 170 | 177 |
| 171 PP_Bool DecryptAndDecode(PP_Instance instance, | 178 PP_Bool DecryptAndDecode(PP_Instance instance, |
| 172 PP_Resource encrypted_block, | 179 PP_Resource encrypted_block, |
| 173 int32_t request_id) { | 180 const PP_EncryptedBlockInfo* encrypted_block_info) { |
| 174 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 181 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 175 if (!dispatcher) { | 182 if (!dispatcher) { |
| 176 NOTREACHED(); | 183 NOTREACHED(); |
| 177 return PP_FALSE; | 184 return PP_FALSE; |
| 178 } | 185 } |
| 179 | 186 |
| 180 HostResource host_resource; | 187 HostResource host_resource; |
| 181 host_resource.SetHostResource(instance, encrypted_block); | 188 host_resource.SetHostResource(instance, encrypted_block); |
| 182 | 189 |
| 190 uint32_t size = 0; |
| 191 if (DescribeHostBufferResource(encrypted_block, &size) == PP_FALSE) |
| 192 return PP_FALSE; |
| 193 |
| 194 base::SharedMemoryHandle handle; |
| 195 if (ShareHostBufferResourceToPlugin(dispatcher, |
| 196 encrypted_block, |
| 197 &handle) == PP_FALSE) |
| 198 return PP_FALSE; |
| 199 |
| 200 PPPDecryptor_Buffer buffer; |
| 201 buffer.resource = host_resource; |
| 202 buffer.handle = handle; |
| 203 buffer.size = size; |
| 204 |
| 205 std::string serialized_block_info; |
| 206 if (!SerializeBlockInfo(*encrypted_block_info, &serialized_block_info)) |
| 207 return PP_FALSE; |
| 208 |
| 183 return PP_FromBool(dispatcher->Send( | 209 return PP_FromBool(dispatcher->Send( |
| 184 new PpapiMsg_PPPContentDecryptor_DecryptAndDecode( | 210 new PpapiMsg_PPPContentDecryptor_DecryptAndDecode( |
| 185 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, | 211 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, |
| 186 instance, | 212 instance, |
| 187 host_resource, | 213 buffer, |
| 188 request_id))); | 214 serialized_block_info))); |
| 189 } | 215 } |
| 190 | 216 |
| 191 static const PPP_ContentDecryptor_Private content_decryptor_interface = { | 217 static const PPP_ContentDecryptor_Private content_decryptor_interface = { |
| 192 &GenerateKeyRequest, | 218 &GenerateKeyRequest, |
| 193 &AddKey, | 219 &AddKey, |
| 194 &CancelKeyRequest, | 220 &CancelKeyRequest, |
| 195 &Decrypt, | 221 &Decrypt, |
| 196 &DecryptAndDecode | 222 &DecryptAndDecode |
| 197 }; | 223 }; |
| 198 | 224 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 CallWhileUnlocked(ppp_decryptor_impl_->GenerateKeyRequest, | 276 CallWhileUnlocked(ppp_decryptor_impl_->GenerateKeyRequest, |
| 251 instance, | 277 instance, |
| 252 ExtractReceivedVarAndAddRef(dispatcher(), &key_system), | 278 ExtractReceivedVarAndAddRef(dispatcher(), &key_system), |
| 253 ExtractReceivedVarAndAddRef(dispatcher(), &init_data)); | 279 ExtractReceivedVarAndAddRef(dispatcher(), &init_data)); |
| 254 } | 280 } |
| 255 } | 281 } |
| 256 | 282 |
| 257 void PPP_ContentDecryptor_Private_Proxy::OnMsgAddKey( | 283 void PPP_ContentDecryptor_Private_Proxy::OnMsgAddKey( |
| 258 PP_Instance instance, | 284 PP_Instance instance, |
| 259 SerializedVarReceiveInput session_id, | 285 SerializedVarReceiveInput session_id, |
| 260 SerializedVarReceiveInput key) { | 286 SerializedVarReceiveInput key, |
| 287 SerializedVarReceiveInput init_data) { |
| 261 if (ppp_decryptor_impl_) { | 288 if (ppp_decryptor_impl_) { |
| 262 CallWhileUnlocked(ppp_decryptor_impl_->AddKey, | 289 CallWhileUnlocked(ppp_decryptor_impl_->AddKey, |
| 263 instance, | 290 instance, |
| 264 ExtractReceivedVarAndAddRef(dispatcher(), &session_id), | 291 ExtractReceivedVarAndAddRef(dispatcher(), &session_id), |
| 265 ExtractReceivedVarAndAddRef(dispatcher(), &key)); | 292 ExtractReceivedVarAndAddRef(dispatcher(), &key), |
| 293 ExtractReceivedVarAndAddRef(dispatcher(), &init_data)); |
| 266 } | 294 } |
| 267 } | 295 } |
| 268 | 296 |
| 269 void PPP_ContentDecryptor_Private_Proxy::OnMsgCancelKeyRequest( | 297 void PPP_ContentDecryptor_Private_Proxy::OnMsgCancelKeyRequest( |
| 270 PP_Instance instance, | 298 PP_Instance instance, |
| 271 SerializedVarReceiveInput session_id) { | 299 SerializedVarReceiveInput session_id) { |
| 272 if (ppp_decryptor_impl_) { | 300 if (ppp_decryptor_impl_) { |
| 273 CallWhileUnlocked(ppp_decryptor_impl_->CancelKeyRequest, | 301 CallWhileUnlocked(ppp_decryptor_impl_->CancelKeyRequest, |
| 274 instance, | 302 instance, |
| 275 ExtractReceivedVarAndAddRef(dispatcher(), &session_id)); | 303 ExtractReceivedVarAndAddRef(dispatcher(), &session_id)); |
| 276 } | 304 } |
| 277 } | 305 } |
| 278 | 306 |
| 279 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecrypt( | 307 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecrypt( |
| 280 PP_Instance instance, | 308 PP_Instance instance, |
| 281 const PPPDecryptor_Buffer& encrypted_buffer, | 309 const PPPDecryptor_Buffer& encrypted_buffer, |
| 282 int32_t request_id) { | 310 const std::string& serialized_block_info) { |
| 283 if (ppp_decryptor_impl_) { | 311 if (ppp_decryptor_impl_) { |
| 284 PP_Resource plugin_resource = | 312 PP_Resource plugin_resource = |
| 285 PPB_Buffer_Proxy::AddProxyResource(encrypted_buffer.resource, | 313 PPB_Buffer_Proxy::AddProxyResource(encrypted_buffer.resource, |
| 286 encrypted_buffer.handle, | 314 encrypted_buffer.handle, |
| 287 encrypted_buffer.size); | 315 encrypted_buffer.size); |
| 316 PP_EncryptedBlockInfo block_info; |
| 317 if (!DeserializeBlockInfo(serialized_block_info, &block_info)) |
| 318 return; |
| 288 CallWhileUnlocked(ppp_decryptor_impl_->Decrypt, | 319 CallWhileUnlocked(ppp_decryptor_impl_->Decrypt, |
| 289 instance, | 320 instance, |
| 290 plugin_resource, | 321 plugin_resource, |
| 291 request_id); | 322 const_cast<const PP_EncryptedBlockInfo*>(&block_info)); |
| 292 } | 323 } |
| 293 } | 324 } |
| 294 | 325 |
| 295 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecryptAndDecode( | 326 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecryptAndDecode( |
| 296 PP_Instance instance, | 327 PP_Instance instance, |
| 297 const HostResource& encrypted_block, | 328 const PPPDecryptor_Buffer& encrypted_buffer, |
| 298 int32_t request_id) { | 329 const std::string& serialized_block_info) { |
| 299 if (ppp_decryptor_impl_) { | 330 if (ppp_decryptor_impl_) { |
| 300 PP_Resource plugin_resource = | 331 PP_Resource plugin_resource = |
| 301 PluginGlobals::Get()->plugin_resource_tracker()-> | 332 PPB_Buffer_Proxy::AddProxyResource(encrypted_buffer.resource, |
| 302 PluginResourceForHostResource(encrypted_block); | 333 encrypted_buffer.handle, |
| 334 encrypted_buffer.size); |
| 335 PP_EncryptedBlockInfo block_info; |
| 336 if (!DeserializeBlockInfo(serialized_block_info, &block_info)) |
| 337 return; |
| 303 CallWhileUnlocked(ppp_decryptor_impl_->DecryptAndDecode, | 338 CallWhileUnlocked(ppp_decryptor_impl_->DecryptAndDecode, |
| 304 instance, | 339 instance, |
| 305 plugin_resource, | 340 plugin_resource, |
| 306 request_id); | 341 const_cast<const PP_EncryptedBlockInfo*>(&block_info)); |
| 307 } | 342 } |
| 308 } | 343 } |
| 309 | 344 |
| 310 } // namespace proxy | 345 } // namespace proxy |
| 311 } // namespace ppapi | 346 } // namespace ppapi |
| OLD | NEW |