| 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)) { |
| 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)) { |
| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 return; | 352 return; |
| 338 CallWhileUnlocked(ppp_decryptor_impl_->DecryptAndDecode, | 353 CallWhileUnlocked(ppp_decryptor_impl_->DecryptAndDecode, |
| 339 instance, | 354 instance, |
| 340 plugin_resource, | 355 plugin_resource, |
| 341 const_cast<const PP_EncryptedBlockInfo*>(&block_info)); | 356 const_cast<const PP_EncryptedBlockInfo*>(&block_info)); |
| 342 } | 357 } |
| 343 } | 358 } |
| 344 | 359 |
| 345 } // namespace proxy | 360 } // namespace proxy |
| 346 } // namespace ppapi | 361 } // namespace ppapi |
| OLD | NEW |