Chromium Code Reviews| Index: ppapi/proxy/ppp_content_decryptor_private_proxy.cc |
| diff --git a/ppapi/proxy/ppp_content_decryptor_private_proxy.cc b/ppapi/proxy/ppp_content_decryptor_private_proxy.cc |
| index fe6a928a64f753b7242e40971a832670f0c2bb56..cad8df064be265b61a6be305feb3a04e2ac35a55 100644 |
| --- a/ppapi/proxy/ppp_content_decryptor_private_proxy.cc |
| +++ b/ppapi/proxy/ppp_content_decryptor_private_proxy.cc |
| @@ -75,6 +75,22 @@ PP_Var ExtractReceivedVarAndAddRef(Dispatcher* dispatcher, |
| return var; |
| } |
| +// Increments the reference count on |resource| to ensure that it remains valid |
| +// until the plugin receives the resource within the asynchronous message sent |
| +// from the proxy. The plugin side takes ownership of that reference. Returns |
| +// PP_TRUE when the reference is successfully added, PP_FALSE otherwise. |
| +PP_Bool AddRefResourceForPlugin(HostDispatcher* dispatcher, |
| + PP_Resource resource) { |
| + const PPB_Core* core = static_cast<const PPB_Core*>( |
| + dispatcher->local_get_interface()(PPB_CORE_INTERFACE)); |
| + if (!core) { |
| + NOTREACHED(); |
| + return PP_FALSE; |
| + } |
| + core->AddRefResource(resource); |
| + return PP_TRUE; |
| +} |
| + |
| PP_Bool GenerateKeyRequest(PP_Instance instance, |
| PP_Var key_system, |
| PP_Var init_data) { |
| @@ -133,18 +149,12 @@ PP_Bool Decrypt(PP_Instance instance, |
| NOTREACHED(); |
| return PP_FALSE; |
| } |
| - const PPB_Core* core = static_cast<const PPB_Core*>( |
| - dispatcher->local_get_interface()(PPB_CORE_INTERFACE)); |
| - if (!core) { |
| + |
| + 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.
|
| NOTREACHED(); |
| return PP_FALSE; |
| } |
| - // We need to take a ref on the resource now. The browser may drop |
| - // references once we return from here, but we're sending an asynchronous |
| - // message. The plugin side takes ownership of that reference. |
| - core->AddRefResource(encrypted_block); |
| - |
| HostResource host_resource; |
| host_resource.SetHostResource(instance, encrypted_block); |
| @@ -184,6 +194,11 @@ PP_Bool DecryptAndDecode(PP_Instance instance, |
| return PP_FALSE; |
| } |
| + if (AddRefResourceForPlugin(dispatcher, encrypted_block) != PP_TRUE) { |
| + NOTREACHED(); |
| + return PP_FALSE; |
| + } |
| + |
| HostResource host_resource; |
| host_resource.SetHostResource(instance, encrypted_block); |
| @@ -321,6 +336,11 @@ void PPP_ContentDecryptor_Private_Proxy::OnMsgDecrypt( |
| plugin_resource, |
| const_cast<const PP_EncryptedBlockInfo*>(&block_info)); |
| } |
| + |
| + // Tell the host to release its reference on the resource. The plugin has |
| + // taken ownership. |
| + dispatcher()->Send(new PpapiHostMsg_PPBCore_ReleaseResource( |
| + API_ID_PPB_CORE, encrypted_buffer.resource)); |
| } |
| void PPP_ContentDecryptor_Private_Proxy::OnMsgDecryptAndDecode( |
| @@ -340,6 +360,11 @@ void PPP_ContentDecryptor_Private_Proxy::OnMsgDecryptAndDecode( |
| plugin_resource, |
| const_cast<const PP_EncryptedBlockInfo*>(&block_info)); |
| } |
| + |
| + // Tell the host to release its reference on the resource. The plugin has |
| + // taken ownership. |
| + dispatcher()->Send(new PpapiHostMsg_PPBCore_ReleaseResource( |
| + 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.
|
| } |
| } // namespace proxy |