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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 // SerializedVarReceiveInput will decrement the reference count, but we want | 68 // SerializedVarReceiveInput will decrement the reference count, but we want |
| 69 // to give the recipient a reference. This utility function takes care of that | 69 // to give the recipient a reference. This utility function takes care of that |
| 70 // work for the message handlers defined below. | 70 // work for the message handlers defined below. |
| 71 PP_Var ExtractReceivedVarAndAddRef(Dispatcher* dispatcher, | 71 PP_Var ExtractReceivedVarAndAddRef(Dispatcher* dispatcher, |
| 72 SerializedVarReceiveInput* serialized_var) { | 72 SerializedVarReceiveInput* serialized_var) { |
| 73 PP_Var var = serialized_var->Get(dispatcher); | 73 PP_Var var = serialized_var->Get(dispatcher); |
| 74 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var); | 74 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var); |
| 75 return var; | 75 return var; |
| 76 } | 76 } |
| 77 | 77 |
| 78 // Increments the reference count on |resource| to ensure that it remains valid | |
| 79 // until the plugin receives the resource within the asynchronous message sent | |
| 80 // from the proxy. The plugin side takes ownership of that reference. Returns | |
| 81 // PP_TRUE when the reference is successfully added, PP_FALSE otherwise. | |
| 82 PP_Bool AddRefResourceForPlugin(HostDispatcher* dispatcher, | |
| 83 PP_Resource resource) { | |
| 84 const PPB_Core* core = static_cast<const PPB_Core*>( | |
| 85 dispatcher->local_get_interface()(PPB_CORE_INTERFACE)); | |
| 86 if (!core) { | |
| 87 NOTREACHED(); | |
| 88 return PP_FALSE; | |
| 89 } | |
| 90 core->AddRefResource(resource); | |
| 91 return PP_TRUE; | |
| 92 } | |
| 93 | |
| 78 PP_Bool GenerateKeyRequest(PP_Instance instance, | 94 PP_Bool GenerateKeyRequest(PP_Instance instance, |
| 79 PP_Var key_system, | 95 PP_Var key_system, |
| 80 PP_Var init_data) { | 96 PP_Var init_data) { |
| 81 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 97 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 82 if (!dispatcher) { | 98 if (!dispatcher) { |
| 83 NOTREACHED(); | 99 NOTREACHED(); |
| 84 return PP_FALSE; | 100 return PP_FALSE; |
| 85 } | 101 } |
| 86 | 102 |
| 87 return PP_FromBool(dispatcher->Send( | 103 return PP_FromBool(dispatcher->Send( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 } | 142 } |
| 127 | 143 |
| 128 PP_Bool Decrypt(PP_Instance instance, | 144 PP_Bool Decrypt(PP_Instance instance, |
| 129 PP_Resource encrypted_block, | 145 PP_Resource encrypted_block, |
| 130 const PP_EncryptedBlockInfo* encrypted_block_info) { | 146 const PP_EncryptedBlockInfo* encrypted_block_info) { |
| 131 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 147 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 132 if (!dispatcher) { | 148 if (!dispatcher) { |
| 133 NOTREACHED(); | 149 NOTREACHED(); |
| 134 return PP_FALSE; | 150 return PP_FALSE; |
| 135 } | 151 } |
| 136 const PPB_Core* core = static_cast<const PPB_Core*>( | |
| 137 dispatcher->local_get_interface()(PPB_CORE_INTERFACE)); | |
| 138 if (!core) { | |
| 139 NOTREACHED(); | |
| 140 return PP_FALSE; | |
| 141 } | |
| 142 | 152 |
| 143 // We need to take a ref on the resource now. The browser may drop | 153 if (AddRefResourceForPlugin(dispatcher, encrypted_block) != PP_TRUE) { |
|
dmichael (off chromium)
2012/09/05 19:46:19
You could just do if (!AddRefResource...) {
right?
Tom Finegan
2012/09/05 20:15:26
Done.
| |
| 144 // references once we return from here, but we're sending an asynchronous | 154 NOTREACHED(); |
| 145 // message. The plugin side takes ownership of that reference. | 155 return PP_FALSE; |
| 146 core->AddRefResource(encrypted_block); | 156 } |
| 147 | 157 |
| 148 HostResource host_resource; | 158 HostResource host_resource; |
| 149 host_resource.SetHostResource(instance, encrypted_block); | 159 host_resource.SetHostResource(instance, encrypted_block); |
| 150 | 160 |
| 151 uint32_t size = 0; | 161 uint32_t size = 0; |
| 152 if (DescribeHostBufferResource(encrypted_block, &size) == PP_FALSE) | 162 if (DescribeHostBufferResource(encrypted_block, &size) == PP_FALSE) |
| 153 return PP_FALSE; | 163 return PP_FALSE; |
| 154 | 164 |
| 155 base::SharedMemoryHandle handle; | 165 base::SharedMemoryHandle handle; |
| 156 if (ShareHostBufferResourceToPlugin(dispatcher, | 166 if (ShareHostBufferResourceToPlugin(dispatcher, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 177 | 187 |
| 178 PP_Bool DecryptAndDecode(PP_Instance instance, | 188 PP_Bool DecryptAndDecode(PP_Instance instance, |
| 179 PP_Resource encrypted_block, | 189 PP_Resource encrypted_block, |
| 180 const PP_EncryptedBlockInfo* encrypted_block_info) { | 190 const PP_EncryptedBlockInfo* encrypted_block_info) { |
| 181 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 191 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 182 if (!dispatcher) { | 192 if (!dispatcher) { |
| 183 NOTREACHED(); | 193 NOTREACHED(); |
| 184 return PP_FALSE; | 194 return PP_FALSE; |
| 185 } | 195 } |
| 186 | 196 |
| 197 if (AddRefResourceForPlugin(dispatcher, encrypted_block) != PP_TRUE) { | |
| 198 NOTREACHED(); | |
| 199 return PP_FALSE; | |
| 200 } | |
| 201 | |
| 187 HostResource host_resource; | 202 HostResource host_resource; |
| 188 host_resource.SetHostResource(instance, encrypted_block); | 203 host_resource.SetHostResource(instance, encrypted_block); |
| 189 | 204 |
| 190 uint32_t size = 0; | 205 uint32_t size = 0; |
| 191 if (DescribeHostBufferResource(encrypted_block, &size) == PP_FALSE) | 206 if (DescribeHostBufferResource(encrypted_block, &size) == PP_FALSE) |
| 192 return PP_FALSE; | 207 return PP_FALSE; |
| 193 | 208 |
| 194 base::SharedMemoryHandle handle; | 209 base::SharedMemoryHandle handle; |
| 195 if (ShareHostBufferResourceToPlugin(dispatcher, | 210 if (ShareHostBufferResourceToPlugin(dispatcher, |
| 196 encrypted_block, | 211 encrypted_block, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 encrypted_buffer.handle, | 329 encrypted_buffer.handle, |
| 315 encrypted_buffer.size); | 330 encrypted_buffer.size); |
| 316 PP_EncryptedBlockInfo block_info; | 331 PP_EncryptedBlockInfo block_info; |
| 317 if (!DeserializeBlockInfo(serialized_block_info, &block_info)) | 332 if (!DeserializeBlockInfo(serialized_block_info, &block_info)) |
| 318 return; | 333 return; |
| 319 CallWhileUnlocked(ppp_decryptor_impl_->Decrypt, | 334 CallWhileUnlocked(ppp_decryptor_impl_->Decrypt, |
| 320 instance, | 335 instance, |
| 321 plugin_resource, | 336 plugin_resource, |
| 322 const_cast<const PP_EncryptedBlockInfo*>(&block_info)); | 337 const_cast<const PP_EncryptedBlockInfo*>(&block_info)); |
| 323 } | 338 } |
| 339 | |
| 340 // Tell the host to release its reference on the resource. The plugin has | |
| 341 // taken ownership. | |
| 342 dispatcher()->Send(new PpapiHostMsg_PPBCore_ReleaseResource( | |
| 343 API_ID_PPB_CORE, encrypted_buffer.resource)); | |
| 324 } | 344 } |
| 325 | 345 |
| 326 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecryptAndDecode( | 346 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecryptAndDecode( |
| 327 PP_Instance instance, | 347 PP_Instance instance, |
| 328 const PPPDecryptor_Buffer& encrypted_buffer, | 348 const PPPDecryptor_Buffer& encrypted_buffer, |
| 329 const std::string& serialized_block_info) { | 349 const std::string& serialized_block_info) { |
| 330 if (ppp_decryptor_impl_) { | 350 if (ppp_decryptor_impl_) { |
| 331 PP_Resource plugin_resource = | 351 PP_Resource plugin_resource = |
| 332 PPB_Buffer_Proxy::AddProxyResource(encrypted_buffer.resource, | 352 PPB_Buffer_Proxy::AddProxyResource(encrypted_buffer.resource, |
| 333 encrypted_buffer.handle, | 353 encrypted_buffer.handle, |
| 334 encrypted_buffer.size); | 354 encrypted_buffer.size); |
| 335 PP_EncryptedBlockInfo block_info; | 355 PP_EncryptedBlockInfo block_info; |
| 336 if (!DeserializeBlockInfo(serialized_block_info, &block_info)) | 356 if (!DeserializeBlockInfo(serialized_block_info, &block_info)) |
| 337 return; | 357 return; |
| 338 CallWhileUnlocked(ppp_decryptor_impl_->DecryptAndDecode, | 358 CallWhileUnlocked(ppp_decryptor_impl_->DecryptAndDecode, |
| 339 instance, | 359 instance, |
| 340 plugin_resource, | 360 plugin_resource, |
| 341 const_cast<const PP_EncryptedBlockInfo*>(&block_info)); | 361 const_cast<const PP_EncryptedBlockInfo*>(&block_info)); |
| 342 } | 362 } |
| 363 | |
| 364 // Tell the host to release its reference on the resource. The plugin has | |
| 365 // taken ownership. | |
| 366 dispatcher()->Send(new PpapiHostMsg_PPBCore_ReleaseResource( | |
| 367 API_ID_PPB_CORE, encrypted_buffer.resource)); | |
|
dmichael (off chromium)
2012/09/05 19:46:19
Sorry, as I mentioned in a more recent comment, I
Tom Finegan
2012/09/05 20:15:26
Removed.
| |
| 343 } | 368 } |
| 344 | 369 |
| 345 } // namespace proxy | 370 } // namespace proxy |
| 346 } // namespace ppapi | 371 } // namespace ppapi |
| OLD | NEW |