| 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/cpp/private/content_decryptor_private.h" | 5 #include "ppapi/cpp/private/content_decryptor_private.h" |
| 6 | 6 |
| 7 #include <cstring> // memcpy | 7 #include <cstring> // memcpy |
| 8 | 8 |
| 9 #include "ppapi/c/ppb_var.h" | 9 #include "ppapi/c/ppb_var.h" |
| 10 #include "ppapi/c/private/ppb_content_decryptor_private.h" | 10 #include "ppapi/c/private/ppb_content_decryptor_private.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 pp::Var server_certificate_var(server_certificate_arg); | 50 pp::Var server_certificate_var(server_certificate_arg); |
| 51 if (!server_certificate_var.is_array_buffer()) | 51 if (!server_certificate_var.is_array_buffer()) |
| 52 return; | 52 return; |
| 53 pp::VarArrayBuffer server_certificate(server_certificate_var); | 53 pp::VarArrayBuffer server_certificate(server_certificate_var); |
| 54 | 54 |
| 55 static_cast<ContentDecryptor_Private*>(object) | 55 static_cast<ContentDecryptor_Private*>(object) |
| 56 ->SetServerCertificate(promise_id, server_certificate); | 56 ->SetServerCertificate(promise_id, server_certificate); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void CreateSession(PP_Instance instance, | 59 void CreateSessionAndGenerateRequest(PP_Instance instance, |
| 60 uint32_t promise_id, | 60 uint32_t promise_id, |
| 61 PP_Var init_data_type_arg, | 61 PP_SessionType session_type, |
| 62 PP_Var init_data_arg, | 62 PP_Var init_data_type_arg, |
| 63 PP_SessionType session_type) { | 63 PP_Var init_data_arg) { |
| 64 void* object = | 64 void* object = |
| 65 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | 65 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
| 66 if (!object) | 66 if (!object) |
| 67 return; | 67 return; |
| 68 | 68 |
| 69 pp::Var init_data_type_var(pp::PASS_REF, init_data_type_arg); | 69 pp::Var init_data_type_var(pp::PASS_REF, init_data_type_arg); |
| 70 if (!init_data_type_var.is_string()) | 70 if (!init_data_type_var.is_string()) |
| 71 return; | 71 return; |
| 72 | 72 |
| 73 pp::Var init_data_var(pp::PASS_REF, init_data_arg); | 73 pp::Var init_data_var(pp::PASS_REF, init_data_arg); |
| 74 if (!init_data_var.is_array_buffer()) | 74 if (!init_data_var.is_array_buffer()) |
| 75 return; | 75 return; |
| 76 pp::VarArrayBuffer init_data_array_buffer(init_data_var); | 76 pp::VarArrayBuffer init_data_array_buffer(init_data_var); |
| 77 | 77 |
| 78 static_cast<ContentDecryptor_Private*>(object) | 78 static_cast<ContentDecryptor_Private*>(object) |
| 79 ->CreateSession(promise_id, | 79 ->CreateSessionAndGenerateRequest(promise_id, session_type, |
| 80 init_data_type_var.AsString(), | 80 init_data_type_var.AsString(), |
| 81 init_data_array_buffer, | 81 init_data_array_buffer); |
| 82 session_type); | |
| 83 } | 82 } |
| 84 | 83 |
| 85 void LoadSession(PP_Instance instance, | 84 void LoadSession(PP_Instance instance, |
| 86 uint32_t promise_id, | 85 uint32_t promise_id, |
| 86 PP_SessionType session_type, |
| 87 PP_Var web_session_id_arg) { | 87 PP_Var web_session_id_arg) { |
| 88 void* object = | 88 void* object = |
| 89 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | 89 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
| 90 if (!object) | 90 if (!object) |
| 91 return; | 91 return; |
| 92 | 92 |
| 93 pp::Var web_session_id_var(web_session_id_arg); | 93 pp::Var web_session_id_var(web_session_id_arg); |
| 94 if (!web_session_id_var.is_string()) | 94 if (!web_session_id_var.is_string()) |
| 95 return; | 95 return; |
| 96 | 96 |
| 97 static_cast<ContentDecryptor_Private*>(object) | 97 static_cast<ContentDecryptor_Private*>(object) |
| 98 ->LoadSession(promise_id, web_session_id_var.AsString()); | 98 ->LoadSession(promise_id, session_type, web_session_id_var.AsString()); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void UpdateSession(PP_Instance instance, | 101 void UpdateSession(PP_Instance instance, |
| 102 uint32_t promise_id, | 102 uint32_t promise_id, |
| 103 PP_Var web_session_id_arg, | 103 PP_Var web_session_id_arg, |
| 104 PP_Var response_arg) { | 104 PP_Var response_arg) { |
| 105 void* object = | 105 void* object = |
| 106 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | 106 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
| 107 if (!object) | 107 if (!object) |
| 108 return; | 108 return; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 return; | 145 return; |
| 146 | 146 |
| 147 pp::Var web_session_id_var(web_session_id_arg); | 147 pp::Var web_session_id_var(web_session_id_arg); |
| 148 if (!web_session_id_var.is_string()) | 148 if (!web_session_id_var.is_string()) |
| 149 return; | 149 return; |
| 150 | 150 |
| 151 static_cast<ContentDecryptor_Private*>(object) | 151 static_cast<ContentDecryptor_Private*>(object) |
| 152 ->RemoveSession(promise_id, web_session_id_var.AsString()); | 152 ->RemoveSession(promise_id, web_session_id_var.AsString()); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void GetUsableKeyIds(PP_Instance instance, | |
| 156 uint32_t promise_id, | |
| 157 PP_Var web_session_id_arg) { | |
| 158 void* object = | |
| 159 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | |
| 160 if (!object) | |
| 161 return; | |
| 162 | |
| 163 pp::Var web_session_id_var(web_session_id_arg); | |
| 164 if (!web_session_id_var.is_string()) | |
| 165 return; | |
| 166 | |
| 167 static_cast<ContentDecryptor_Private*>(object) | |
| 168 ->GetUsableKeyIds(promise_id, web_session_id_var.AsString()); | |
| 169 } | |
| 170 | |
| 171 void Decrypt(PP_Instance instance, | 155 void Decrypt(PP_Instance instance, |
| 172 PP_Resource encrypted_resource, | 156 PP_Resource encrypted_resource, |
| 173 const PP_EncryptedBlockInfo* encrypted_block_info) { | 157 const PP_EncryptedBlockInfo* encrypted_block_info) { |
| 174 pp::Buffer_Dev encrypted_block(encrypted_resource); | 158 pp::Buffer_Dev encrypted_block(encrypted_resource); |
| 175 | 159 |
| 176 void* object = | 160 void* object = |
| 177 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | 161 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
| 178 if (!object) | 162 if (!object) |
| 179 return; | 163 return; |
| 180 | 164 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 | 235 |
| 252 static_cast<ContentDecryptor_Private*>(object)->DecryptAndDecode( | 236 static_cast<ContentDecryptor_Private*>(object)->DecryptAndDecode( |
| 253 decoder_type, | 237 decoder_type, |
| 254 encrypted_buffer, | 238 encrypted_buffer, |
| 255 *encrypted_block_info); | 239 *encrypted_block_info); |
| 256 } | 240 } |
| 257 | 241 |
| 258 const PPP_ContentDecryptor_Private ppp_content_decryptor = { | 242 const PPP_ContentDecryptor_Private ppp_content_decryptor = { |
| 259 &Initialize, | 243 &Initialize, |
| 260 &SetServerCertificate, | 244 &SetServerCertificate, |
| 261 &CreateSession, | 245 &CreateSessionAndGenerateRequest, |
| 262 &LoadSession, | 246 &LoadSession, |
| 263 &UpdateSession, | 247 &UpdateSession, |
| 264 &CloseSession, | 248 &CloseSession, |
| 265 &RemoveSession, | 249 &RemoveSession, |
| 266 &GetUsableKeyIds, | |
| 267 &Decrypt, | 250 &Decrypt, |
| 268 &InitializeAudioDecoder, | 251 &InitializeAudioDecoder, |
| 269 &InitializeVideoDecoder, | 252 &InitializeVideoDecoder, |
| 270 &DeinitializeDecoder, | 253 &DeinitializeDecoder, |
| 271 &ResetDecoder, | 254 &ResetDecoder, |
| 272 &DecryptAndDecode}; | 255 &DecryptAndDecode}; |
| 273 | 256 |
| 274 template <> const char* interface_name<PPB_ContentDecryptor_Private>() { | 257 template <> const char* interface_name<PPB_ContentDecryptor_Private>() { |
| 275 return PPB_CONTENTDECRYPTOR_PRIVATE_INTERFACE; | 258 return PPB_CONTENTDECRYPTOR_PRIVATE_INTERFACE; |
| 276 } | 259 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 302 const std::string& web_session_id) { | 285 const std::string& web_session_id) { |
| 303 if (has_interface<PPB_ContentDecryptor_Private>()) { | 286 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 304 pp::Var web_session_id_var(web_session_id); | 287 pp::Var web_session_id_var(web_session_id); |
| 305 get_interface<PPB_ContentDecryptor_Private>()->PromiseResolvedWithSession( | 288 get_interface<PPB_ContentDecryptor_Private>()->PromiseResolvedWithSession( |
| 306 associated_instance_.pp_instance(), | 289 associated_instance_.pp_instance(), |
| 307 promise_id, | 290 promise_id, |
| 308 web_session_id_var.pp_var()); | 291 web_session_id_var.pp_var()); |
| 309 } | 292 } |
| 310 } | 293 } |
| 311 | 294 |
| 312 void ContentDecryptor_Private::PromiseResolvedWithKeyIds( | |
| 313 uint32_t promise_id, | |
| 314 const std::vector<std::vector<uint8_t> >& key_ids) { | |
| 315 if (has_interface<PPB_ContentDecryptor_Private>()) { | |
| 316 pp::VarArray key_ids_array = pp::VarArray(); | |
| 317 key_ids_array.SetLength(key_ids.size()); | |
| 318 for (size_t i = 0; i < key_ids.size(); ++i) { | |
| 319 const std::vector<uint8_t>& entry = key_ids[i]; | |
| 320 pp::VarArrayBuffer array_buffer(entry.size()); | |
| 321 memcpy(array_buffer.Map(), &entry[0], entry.size()); | |
| 322 key_ids_array.Set(i, array_buffer); | |
| 323 } | |
| 324 get_interface<PPB_ContentDecryptor_Private>()->PromiseResolvedWithKeyIds( | |
| 325 associated_instance_.pp_instance(), promise_id, key_ids_array.pp_var()); | |
| 326 } | |
| 327 } | |
| 328 | |
| 329 void ContentDecryptor_Private::PromiseRejected( | 295 void ContentDecryptor_Private::PromiseRejected( |
| 330 uint32_t promise_id, | 296 uint32_t promise_id, |
| 331 PP_CdmExceptionCode exception_code, | 297 PP_CdmExceptionCode exception_code, |
| 332 uint32_t system_code, | 298 uint32_t system_code, |
| 333 const std::string& error_description) { | 299 const std::string& error_description) { |
| 334 if (has_interface<PPB_ContentDecryptor_Private>()) { | 300 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 335 pp::Var error_description_var(error_description); | 301 pp::Var error_description_var(error_description); |
| 336 get_interface<PPB_ContentDecryptor_Private>()->PromiseRejected( | 302 get_interface<PPB_ContentDecryptor_Private>()->PromiseRejected( |
| 337 associated_instance_.pp_instance(), | 303 associated_instance_.pp_instance(), |
| 338 promise_id, | 304 promise_id, |
| 339 exception_code, | 305 exception_code, |
| 340 system_code, | 306 system_code, |
| 341 error_description_var.pp_var()); | 307 error_description_var.pp_var()); |
| 342 } | 308 } |
| 343 } | 309 } |
| 344 | 310 |
| 345 void ContentDecryptor_Private::SessionMessage( | 311 void ContentDecryptor_Private::SessionMessage(const std::string& web_session_id, |
| 346 const std::string& web_session_id, | 312 PP_MessageType message_type, |
| 347 pp::VarArrayBuffer message, | 313 pp::VarArrayBuffer message) { |
| 348 const std::string& destination_url) { | |
| 349 if (has_interface<PPB_ContentDecryptor_Private>()) { | 314 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 350 pp::Var web_session_id_var(web_session_id); | 315 pp::Var web_session_id_var(web_session_id); |
| 351 pp::Var destination_url_var(destination_url); | |
| 352 get_interface<PPB_ContentDecryptor_Private>()->SessionMessage( | 316 get_interface<PPB_ContentDecryptor_Private>()->SessionMessage( |
| 353 associated_instance_.pp_instance(), | 317 associated_instance_.pp_instance(), web_session_id_var.pp_var(), |
| 354 web_session_id_var.pp_var(), | 318 message_type, message.pp_var()); |
| 355 message.pp_var(), | |
| 356 destination_url_var.pp_var()); | |
| 357 } | 319 } |
| 358 } | 320 } |
| 359 | 321 |
| 360 void ContentDecryptor_Private::SessionKeysChange( | 322 void ContentDecryptor_Private::SessionKeysChange( |
| 361 const std::string& web_session_id, | 323 const std::string& web_session_id, |
| 362 bool has_additional_usable_key) { | 324 bool has_additional_usable_key, |
| 325 const std::vector<PP_KeyInformation>& key_information) { |
| 363 if (has_interface<PPB_ContentDecryptor_Private>()) { | 326 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 364 pp::Var web_session_id_var(web_session_id); | 327 pp::Var web_session_id_var(web_session_id); |
| 328 pp::VarArray key_information_array = pp::VarArray(); |
| 329 key_information_array.SetLength(key_information.size()); |
| 330 for (size_t i = 0; i < key_information.size(); ++i) { |
| 331 auto entry = key_information[i]; |
| 332 pp::VarArrayBuffer array_buffer(sizeof(PP_KeyInformation)); |
| 333 memcpy(array_buffer.Map(), &entry, sizeof(PP_KeyInformation)); |
| 334 key_information_array.Set(i, array_buffer); |
| 335 } |
| 365 get_interface<PPB_ContentDecryptor_Private>()->SessionKeysChange( | 336 get_interface<PPB_ContentDecryptor_Private>()->SessionKeysChange( |
| 366 associated_instance_.pp_instance(), | 337 associated_instance_.pp_instance(), web_session_id_var.pp_var(), |
| 367 web_session_id_var.pp_var(), | 338 PP_FromBool(has_additional_usable_key), key_information_array.pp_var()); |
| 368 PP_FromBool(has_additional_usable_key)); | |
| 369 } | 339 } |
| 370 } | 340 } |
| 371 | 341 |
| 372 void ContentDecryptor_Private::SessionExpirationChange( | 342 void ContentDecryptor_Private::SessionExpirationChange( |
| 373 const std::string& web_session_id, | 343 const std::string& web_session_id, |
| 374 PP_Time new_expiry_time) { | 344 PP_Time new_expiry_time) { |
| 375 if (has_interface<PPB_ContentDecryptor_Private>()) { | 345 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 376 pp::Var web_session_id_var(web_session_id); | 346 pp::Var web_session_id_var(web_session_id); |
| 377 get_interface<PPB_ContentDecryptor_Private>()->SessionExpirationChange( | 347 get_interface<PPB_ContentDecryptor_Private>()->SessionExpirationChange( |
| 378 associated_instance_.pp_instance(), | 348 associated_instance_.pp_instance(), |
| 379 web_session_id_var.pp_var(), | 349 web_session_id_var.pp_var(), |
| 380 new_expiry_time); | 350 new_expiry_time); |
| 381 } | 351 } |
| 382 } | 352 } |
| 383 | 353 |
| 384 void ContentDecryptor_Private::SessionReady(const std::string& web_session_id) { | |
| 385 if (has_interface<PPB_ContentDecryptor_Private>()) { | |
| 386 pp::Var web_session_id_var(web_session_id); | |
| 387 get_interface<PPB_ContentDecryptor_Private>()->SessionReady( | |
| 388 associated_instance_.pp_instance(), web_session_id_var.pp_var()); | |
| 389 } | |
| 390 } | |
| 391 | |
| 392 void ContentDecryptor_Private::SessionClosed( | 354 void ContentDecryptor_Private::SessionClosed( |
| 393 const std::string& web_session_id) { | 355 const std::string& web_session_id) { |
| 394 if (has_interface<PPB_ContentDecryptor_Private>()) { | 356 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 395 pp::Var web_session_id_var(web_session_id); | 357 pp::Var web_session_id_var(web_session_id); |
| 396 get_interface<PPB_ContentDecryptor_Private>()->SessionClosed( | 358 get_interface<PPB_ContentDecryptor_Private>()->SessionClosed( |
| 397 associated_instance_.pp_instance(), web_session_id_var.pp_var()); | 359 associated_instance_.pp_instance(), web_session_id_var.pp_var()); |
| 398 } | 360 } |
| 399 } | 361 } |
| 400 | 362 |
| 401 void ContentDecryptor_Private::SessionError( | 363 void ContentDecryptor_Private::SessionError( |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 const PP_DecryptedSampleInfo& decrypted_sample_info) { | 439 const PP_DecryptedSampleInfo& decrypted_sample_info) { |
| 478 if (has_interface<PPB_ContentDecryptor_Private>()) { | 440 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 479 get_interface<PPB_ContentDecryptor_Private>()->DeliverSamples( | 441 get_interface<PPB_ContentDecryptor_Private>()->DeliverSamples( |
| 480 associated_instance_.pp_instance(), | 442 associated_instance_.pp_instance(), |
| 481 audio_frames.pp_resource(), | 443 audio_frames.pp_resource(), |
| 482 &decrypted_sample_info); | 444 &decrypted_sample_info); |
| 483 } | 445 } |
| 484 } | 446 } |
| 485 | 447 |
| 486 } // namespace pp | 448 } // namespace pp |
| OLD | NEW |