| 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 PP_Bool GenerateKeyRequest(PP_Instance instance, | 94 void GenerateKeyRequest(PP_Instance instance, |
| 95 PP_Var key_system, | 95 PP_Var key_system, |
| 96 PP_Var init_data) { | 96 PP_Var init_data) { |
| 97 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 97 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 98 if (!dispatcher) { | 98 if (!dispatcher) { |
| 99 NOTREACHED(); | 99 NOTREACHED(); |
| 100 return PP_FALSE; | 100 return; |
| 101 } | 101 } |
| 102 | 102 |
| 103 return PP_FromBool(dispatcher->Send( | 103 dispatcher->Send( |
| 104 new PpapiMsg_PPPContentDecryptor_GenerateKeyRequest( | 104 new PpapiMsg_PPPContentDecryptor_GenerateKeyRequest( |
| 105 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, | 105 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, |
| 106 instance, | 106 instance, |
| 107 SerializedVarSendInput(dispatcher, key_system), | 107 SerializedVarSendInput(dispatcher, key_system), |
| 108 SerializedVarSendInput(dispatcher, init_data)))); | 108 SerializedVarSendInput(dispatcher, init_data))); |
| 109 } | 109 } |
| 110 | 110 |
| 111 PP_Bool AddKey(PP_Instance instance, | 111 void AddKey(PP_Instance instance, |
| 112 PP_Var session_id, | 112 PP_Var session_id, |
| 113 PP_Var key, | 113 PP_Var key, |
| 114 PP_Var init_data) { | 114 PP_Var init_data) { |
| 115 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 115 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 116 if (!dispatcher) { | 116 if (!dispatcher) { |
| 117 NOTREACHED(); | 117 NOTREACHED(); |
| 118 return PP_FALSE; | 118 return; |
| 119 } | 119 } |
| 120 | 120 |
| 121 return PP_FromBool(dispatcher->Send( | 121 dispatcher->Send( |
| 122 new PpapiMsg_PPPContentDecryptor_AddKey( | 122 new PpapiMsg_PPPContentDecryptor_AddKey( |
| 123 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, | 123 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, |
| 124 instance, | 124 instance, |
| 125 SerializedVarSendInput(dispatcher, session_id), | 125 SerializedVarSendInput(dispatcher, session_id), |
| 126 SerializedVarSendInput(dispatcher, key), | 126 SerializedVarSendInput(dispatcher, key), |
| 127 SerializedVarSendInput(dispatcher, init_data)))); | 127 SerializedVarSendInput(dispatcher, init_data))); |
| 128 } | 128 } |
| 129 | 129 |
| 130 PP_Bool CancelKeyRequest(PP_Instance instance, PP_Var session_id) { | 130 void CancelKeyRequest(PP_Instance instance, PP_Var session_id) { |
| 131 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 131 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 132 if (!dispatcher) { | 132 if (!dispatcher) { |
| 133 NOTREACHED(); | 133 NOTREACHED(); |
| 134 return PP_FALSE; | 134 return; |
| 135 } | 135 } |
| 136 | 136 |
| 137 return PP_FromBool(dispatcher->Send( | 137 dispatcher->Send( |
| 138 new PpapiMsg_PPPContentDecryptor_CancelKeyRequest( | 138 new PpapiMsg_PPPContentDecryptor_CancelKeyRequest( |
| 139 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, | 139 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, |
| 140 instance, | 140 instance, |
| 141 SerializedVarSendInput(dispatcher, session_id)))); | 141 SerializedVarSendInput(dispatcher, session_id))); |
| 142 } | 142 } |
| 143 | 143 |
| 144 PP_Bool Decrypt(PP_Instance instance, | 144 void Decrypt(PP_Instance instance, |
| 145 PP_Resource encrypted_block, | 145 PP_Resource encrypted_block, |
| 146 const PP_EncryptedBlockInfo* encrypted_block_info) { | 146 const PP_EncryptedBlockInfo* encrypted_block_info) { |
| 147 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 147 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 148 if (!dispatcher) { | 148 if (!dispatcher) { |
| 149 NOTREACHED(); | 149 NOTREACHED(); |
| 150 return PP_FALSE; | 150 return; |
| 151 } | 151 } |
| 152 | 152 |
| 153 if (!AddRefResourceForPlugin(dispatcher, encrypted_block)) { | 153 if (!AddRefResourceForPlugin(dispatcher, encrypted_block)) { |
| 154 NOTREACHED(); | 154 NOTREACHED(); |
| 155 return PP_FALSE; | 155 return; |
| 156 } | 156 } |
| 157 | 157 |
| 158 HostResource host_resource; | 158 HostResource host_resource; |
| 159 host_resource.SetHostResource(instance, encrypted_block); | 159 host_resource.SetHostResource(instance, encrypted_block); |
| 160 | 160 |
| 161 uint32_t size = 0; | 161 uint32_t size = 0; |
| 162 if (DescribeHostBufferResource(encrypted_block, &size) == PP_FALSE) | 162 if (DescribeHostBufferResource(encrypted_block, &size) == PP_FALSE) |
| 163 return PP_FALSE; | 163 return; |
| 164 | 164 |
| 165 base::SharedMemoryHandle handle; | 165 base::SharedMemoryHandle handle; |
| 166 if (ShareHostBufferResourceToPlugin(dispatcher, | 166 if (ShareHostBufferResourceToPlugin(dispatcher, |
| 167 encrypted_block, | 167 encrypted_block, |
| 168 &handle) == PP_FALSE) | 168 &handle) == PP_FALSE) |
| 169 return PP_FALSE; | 169 return; |
| 170 | 170 |
| 171 PPPDecryptor_Buffer buffer; | 171 PPPDecryptor_Buffer buffer; |
| 172 buffer.resource = host_resource; | 172 buffer.resource = host_resource; |
| 173 buffer.handle = handle; | 173 buffer.handle = handle; |
| 174 buffer.size = size; | 174 buffer.size = size; |
| 175 | 175 |
| 176 std::string serialized_block_info; | 176 std::string serialized_block_info; |
| 177 if (!SerializeBlockInfo(*encrypted_block_info, &serialized_block_info)) | 177 if (!SerializeBlockInfo(*encrypted_block_info, &serialized_block_info)) |
| 178 return PP_FALSE; | 178 return; |
| 179 | 179 |
| 180 return PP_FromBool(dispatcher->Send( | 180 dispatcher->Send( |
| 181 new PpapiMsg_PPPContentDecryptor_Decrypt( | 181 new PpapiMsg_PPPContentDecryptor_Decrypt( |
| 182 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, | 182 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, |
| 183 instance, | 183 instance, |
| 184 buffer, | 184 buffer, |
| 185 serialized_block_info))); | 185 serialized_block_info)); |
| 186 } | 186 } |
| 187 | 187 |
| 188 PP_Bool DecryptAndDecode(PP_Instance instance, | 188 void DecryptAndDecode(PP_Instance instance, |
| 189 PP_Resource encrypted_block, | 189 PP_Resource encrypted_block, |
| 190 const PP_EncryptedBlockInfo* encrypted_block_info) { | 190 const PP_EncryptedBlockInfo* encrypted_block_info) { |
| 191 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 191 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 192 if (!dispatcher) { | 192 if (!dispatcher) { |
| 193 NOTREACHED(); | 193 NOTREACHED(); |
| 194 return PP_FALSE; | 194 return; |
| 195 } | 195 } |
| 196 | 196 |
| 197 if (!AddRefResourceForPlugin(dispatcher, encrypted_block)) { | 197 if (!AddRefResourceForPlugin(dispatcher, encrypted_block)) { |
| 198 NOTREACHED(); | 198 NOTREACHED(); |
| 199 return PP_FALSE; | 199 return; |
| 200 } | 200 } |
| 201 | 201 |
| 202 HostResource host_resource; | 202 HostResource host_resource; |
| 203 host_resource.SetHostResource(instance, encrypted_block); | 203 host_resource.SetHostResource(instance, encrypted_block); |
| 204 | 204 |
| 205 uint32_t size = 0; | 205 uint32_t size = 0; |
| 206 if (DescribeHostBufferResource(encrypted_block, &size) == PP_FALSE) | 206 if (DescribeHostBufferResource(encrypted_block, &size) == PP_FALSE) |
| 207 return PP_FALSE; | 207 return; |
| 208 | 208 |
| 209 base::SharedMemoryHandle handle; | 209 base::SharedMemoryHandle handle; |
| 210 if (ShareHostBufferResourceToPlugin(dispatcher, | 210 if (ShareHostBufferResourceToPlugin(dispatcher, |
| 211 encrypted_block, | 211 encrypted_block, |
| 212 &handle) == PP_FALSE) | 212 &handle) == PP_FALSE) |
| 213 return PP_FALSE; | 213 return; |
| 214 | 214 |
| 215 PPPDecryptor_Buffer buffer; | 215 PPPDecryptor_Buffer buffer; |
| 216 buffer.resource = host_resource; | 216 buffer.resource = host_resource; |
| 217 buffer.handle = handle; | 217 buffer.handle = handle; |
| 218 buffer.size = size; | 218 buffer.size = size; |
| 219 | 219 |
| 220 std::string serialized_block_info; | 220 std::string serialized_block_info; |
| 221 if (!SerializeBlockInfo(*encrypted_block_info, &serialized_block_info)) | 221 if (!SerializeBlockInfo(*encrypted_block_info, &serialized_block_info)) |
| 222 return PP_FALSE; | 222 return; |
| 223 | 223 |
| 224 return PP_FromBool(dispatcher->Send( | 224 dispatcher->Send( |
| 225 new PpapiMsg_PPPContentDecryptor_DecryptAndDecode( | 225 new PpapiMsg_PPPContentDecryptor_DecryptAndDecode( |
| 226 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, | 226 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, |
| 227 instance, | 227 instance, |
| 228 buffer, | 228 buffer, |
| 229 serialized_block_info))); | 229 serialized_block_info)); |
| 230 } | 230 } |
| 231 | 231 |
| 232 static const PPP_ContentDecryptor_Private content_decryptor_interface = { | 232 static const PPP_ContentDecryptor_Private content_decryptor_interface = { |
| 233 &GenerateKeyRequest, | 233 &GenerateKeyRequest, |
| 234 &AddKey, | 234 &AddKey, |
| 235 &CancelKeyRequest, | 235 &CancelKeyRequest, |
| 236 &Decrypt, | 236 &Decrypt, |
| 237 &DecryptAndDecode | 237 &DecryptAndDecode |
| 238 }; | 238 }; |
| 239 | 239 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 return; | 352 return; |
| 353 CallWhileUnlocked(ppp_decryptor_impl_->DecryptAndDecode, | 353 CallWhileUnlocked(ppp_decryptor_impl_->DecryptAndDecode, |
| 354 instance, | 354 instance, |
| 355 plugin_resource, | 355 plugin_resource, |
| 356 const_cast<const PP_EncryptedBlockInfo*>(&block_info)); | 356 const_cast<const PP_EncryptedBlockInfo*>(&block_info)); |
| 357 } | 357 } |
| 358 } | 358 } |
| 359 | 359 |
| 360 } // namespace proxy | 360 } // namespace proxy |
| 361 } // namespace ppapi | 361 } // namespace ppapi |
| OLD | NEW |