| 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 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 pp::Var key_system_var(pp::PASS_REF, key_system_arg); | 33 pp::Var key_system_var(pp::PASS_REF, key_system_arg); |
| 34 if (!key_system_var.is_string()) | 34 if (!key_system_var.is_string()) |
| 35 return; | 35 return; |
| 36 | 36 |
| 37 static_cast<ContentDecryptor_Private*>(object)->Initialize( | 37 static_cast<ContentDecryptor_Private*>(object)->Initialize( |
| 38 key_system_var.AsString()); | 38 key_system_var.AsString()); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void CreateSession(PP_Instance instance, | 41 void CreateSession(PP_Instance instance, |
| 42 uint32_t session_id, | 42 uint32_t promise_id, |
| 43 PP_Var type_arg, | 43 PP_Var init_data_type_arg, |
| 44 PP_Var init_data_arg) { | 44 PP_Var init_data_arg, |
| 45 PP_SessionType session_type) { |
| 45 void* object = | 46 void* object = |
| 46 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | 47 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
| 47 if (!object) | 48 if (!object) |
| 48 return; | 49 return; |
| 49 | 50 |
| 50 pp::Var type_var(pp::PASS_REF, type_arg); | 51 pp::Var init_data_type_var(pp::PASS_REF, init_data_type_arg); |
| 51 if (!type_var.is_string()) | 52 if (!init_data_type_var.is_string()) |
| 52 return; | 53 return; |
| 53 | 54 |
| 54 pp::Var init_data_var(pp::PASS_REF, init_data_arg); | 55 pp::Var init_data_var(pp::PASS_REF, init_data_arg); |
| 55 if (!init_data_var.is_array_buffer()) | 56 if (!init_data_var.is_array_buffer()) |
| 56 return; | 57 return; |
| 57 pp::VarArrayBuffer init_data_array_buffer(init_data_var); | 58 pp::VarArrayBuffer init_data_array_buffer(init_data_var); |
| 58 | 59 |
| 59 static_cast<ContentDecryptor_Private*>(object) | 60 static_cast<ContentDecryptor_Private*>(object) |
| 60 ->CreateSession(session_id, type_var.AsString(), init_data_array_buffer); | 61 ->CreateSession(promise_id, |
| 62 init_data_type_var.AsString(), |
| 63 init_data_array_buffer, |
| 64 session_type); |
| 61 } | 65 } |
| 62 | 66 |
| 63 void LoadSession(PP_Instance instance, | 67 void LoadSession(PP_Instance instance, |
| 64 uint32_t session_id, | 68 uint32_t promise_id, |
| 65 PP_Var web_session_id_arg) { | 69 PP_Var web_session_id_arg) { |
| 66 void* object = | 70 void* object = |
| 67 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | 71 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
| 68 if (!object) | 72 if (!object) |
| 69 return; | 73 return; |
| 70 | 74 |
| 71 pp::Var web_session_id_var(pp::PASS_REF, web_session_id_arg); | 75 pp::Var web_session_id_var(pp::PASS_REF, web_session_id_arg); |
| 72 if (!web_session_id_var.is_string()) | 76 if (!web_session_id_var.is_string()) |
| 73 return; | 77 return; |
| 74 | 78 |
| 75 static_cast<ContentDecryptor_Private*>(object) | 79 static_cast<ContentDecryptor_Private*>(object) |
| 76 ->LoadSession(session_id, web_session_id_var.AsString()); | 80 ->LoadSession(promise_id, web_session_id_var.AsString()); |
| 77 } | 81 } |
| 78 | 82 |
| 79 void UpdateSession(PP_Instance instance, | 83 void UpdateSession(PP_Instance instance, |
| 80 uint32_t session_id, | 84 uint32_t promise_id, |
| 85 PP_Var web_session_id_arg, |
| 81 PP_Var response_arg) { | 86 PP_Var response_arg) { |
| 82 void* object = | 87 void* object = |
| 83 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | 88 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
| 84 if (!object) | 89 if (!object) |
| 85 return; | 90 return; |
| 86 | 91 |
| 92 pp::Var web_session_id_var(pp::PASS_REF, web_session_id_arg); |
| 93 if (!web_session_id_var.is_string()) |
| 94 return; |
| 95 |
| 87 pp::Var response_var(pp::PASS_REF, response_arg); | 96 pp::Var response_var(pp::PASS_REF, response_arg); |
| 88 if (!response_var.is_array_buffer()) | 97 if (!response_var.is_array_buffer()) |
| 89 return; | 98 return; |
| 90 pp::VarArrayBuffer response(response_var); | 99 pp::VarArrayBuffer response(response_var); |
| 91 | 100 |
| 92 static_cast<ContentDecryptor_Private*>(object) | 101 static_cast<ContentDecryptor_Private*>(object) |
| 93 ->UpdateSession(session_id, response); | 102 ->UpdateSession(promise_id, web_session_id_var.AsString(), response); |
| 94 } | 103 } |
| 95 | 104 |
| 96 void ReleaseSession(PP_Instance instance, uint32_t session_id) { | 105 void ReleaseSession(PP_Instance instance, |
| 106 uint32_t promise_id, |
| 107 PP_Var web_session_id_arg) { |
| 97 void* object = | 108 void* object = |
| 98 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | 109 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
| 99 if (!object) | 110 if (!object) |
| 100 return; | 111 return; |
| 101 | 112 |
| 102 static_cast<ContentDecryptor_Private*>(object)->ReleaseSession(session_id); | 113 pp::Var web_session_id_var(pp::PASS_REF, web_session_id_arg); |
| 114 if (!web_session_id_var.is_string()) |
| 115 return; |
| 116 |
| 117 static_cast<ContentDecryptor_Private*>(object) |
| 118 ->ReleaseSession(promise_id, web_session_id_var.AsString()); |
| 103 } | 119 } |
| 104 | 120 |
| 105 | |
| 106 void Decrypt(PP_Instance instance, | 121 void Decrypt(PP_Instance instance, |
| 107 PP_Resource encrypted_resource, | 122 PP_Resource encrypted_resource, |
| 108 const PP_EncryptedBlockInfo* encrypted_block_info) { | 123 const PP_EncryptedBlockInfo* encrypted_block_info) { |
| 109 pp::Buffer_Dev encrypted_block(encrypted_resource); | 124 pp::Buffer_Dev encrypted_block(encrypted_resource); |
| 110 | 125 |
| 111 void* object = | 126 void* object = |
| 112 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | 127 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
| 113 if (!object) | 128 if (!object) |
| 114 return; | 129 return; |
| 115 | 130 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 &ppp_content_decryptor); | 231 &ppp_content_decryptor); |
| 217 instance->AddPerInstanceObject(kPPPContentDecryptorInterface, this); | 232 instance->AddPerInstanceObject(kPPPContentDecryptorInterface, this); |
| 218 } | 233 } |
| 219 | 234 |
| 220 ContentDecryptor_Private::~ContentDecryptor_Private() { | 235 ContentDecryptor_Private::~ContentDecryptor_Private() { |
| 221 Instance::RemovePerInstanceObject(associated_instance_, | 236 Instance::RemovePerInstanceObject(associated_instance_, |
| 222 kPPPContentDecryptorInterface, | 237 kPPPContentDecryptorInterface, |
| 223 this); | 238 this); |
| 224 } | 239 } |
| 225 | 240 |
| 226 void ContentDecryptor_Private::SessionCreated( | 241 void ContentDecryptor_Private::PromiseResolved(uint32_t promise_id) { |
| 227 uint32_t session_id, | 242 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 243 get_interface<PPB_ContentDecryptor_Private>()->PromiseResolved( |
| 244 associated_instance_.pp_instance(), promise_id); |
| 245 } |
| 246 } |
| 247 |
| 248 void ContentDecryptor_Private::PromiseResolvedWithSession( |
| 249 uint32_t promise_id, |
| 228 const std::string& web_session_id) { | 250 const std::string& web_session_id) { |
| 229 if (has_interface<PPB_ContentDecryptor_Private>()) { | 251 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 230 pp::Var web_session_id_var(web_session_id); | 252 pp::Var web_session_id_var(web_session_id); |
| 231 get_interface<PPB_ContentDecryptor_Private>()->SessionCreated( | 253 get_interface<PPB_ContentDecryptor_Private>()->PromiseResolvedWithSession( |
| 232 associated_instance_.pp_instance(), | 254 associated_instance_.pp_instance(), |
| 233 session_id, | 255 promise_id, |
| 234 web_session_id_var.pp_var()); | 256 web_session_id_var.pp_var()); |
| 235 } | 257 } |
| 236 } | 258 } |
| 237 | 259 |
| 238 void ContentDecryptor_Private::SessionMessage(uint32_t session_id, | 260 void ContentDecryptor_Private::PromiseRejected( |
| 239 pp::VarArrayBuffer message, | 261 uint32_t promise_id, |
| 240 const std::string& default_url) { | 262 const std::string& error_name, |
| 263 uint32_t system_code, |
| 264 const std::string& error_description) { |
| 241 if (has_interface<PPB_ContentDecryptor_Private>()) { | 265 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 242 pp::Var default_url_var(default_url); | 266 pp::Var error_name_var(error_name); |
| 243 get_interface<PPB_ContentDecryptor_Private>()->SessionMessage( | 267 pp::Var error_description_var(error_description); |
| 268 get_interface<PPB_ContentDecryptor_Private>()->PromiseRejected( |
| 244 associated_instance_.pp_instance(), | 269 associated_instance_.pp_instance(), |
| 245 session_id, | 270 promise_id, |
| 246 message.pp_var(), | 271 error_name_var.pp_var(), |
| 247 default_url_var.pp_var()); | 272 system_code, |
| 273 error_description_var.pp_var()); |
| 248 } | 274 } |
| 249 } | 275 } |
| 250 | 276 |
| 251 void ContentDecryptor_Private::SessionReady(uint32_t session_id) { | 277 void ContentDecryptor_Private::SessionMessage( |
| 278 const std::string& web_session_id, |
| 279 pp::VarArrayBuffer message, |
| 280 const std::string& destination_url) { |
| 252 if (has_interface<PPB_ContentDecryptor_Private>()) { | 281 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 253 get_interface<PPB_ContentDecryptor_Private>()->SessionReady( | 282 pp::Var web_session_id_var(web_session_id); |
| 254 associated_instance_.pp_instance(), session_id); | 283 pp::Var destination_url_var(destination_url); |
| 284 get_interface<PPB_ContentDecryptor_Private>()->SessionMessage( |
| 285 associated_instance_.pp_instance(), |
| 286 web_session_id_var.pp_var(), |
| 287 message.pp_var(), |
| 288 destination_url_var.pp_var()); |
| 255 } | 289 } |
| 256 } | 290 } |
| 257 | 291 |
| 258 void ContentDecryptor_Private::SessionClosed(uint32_t session_id) { | 292 void ContentDecryptor_Private::SessionReady(const std::string& web_session_id) { |
| 259 if (has_interface<PPB_ContentDecryptor_Private>()) { | 293 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 260 get_interface<PPB_ContentDecryptor_Private>()->SessionClosed( | 294 pp::Var web_session_id_var(web_session_id); |
| 261 associated_instance_.pp_instance(), session_id); | 295 get_interface<PPB_ContentDecryptor_Private>()->SessionReady( |
| 296 associated_instance_.pp_instance(), web_session_id_var.pp_var()); |
| 262 } | 297 } |
| 263 } | 298 } |
| 264 | 299 |
| 265 void ContentDecryptor_Private::SessionError(uint32_t session_id, | 300 void ContentDecryptor_Private::SessionClosed( |
| 266 int32_t media_error, | 301 const std::string& web_session_id) { |
| 267 uint32_t system_code) { | |
| 268 if (has_interface<PPB_ContentDecryptor_Private>()) { | 302 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 269 get_interface<PPB_ContentDecryptor_Private>()->SessionError( | 303 pp::Var web_session_id_var(web_session_id); |
| 270 associated_instance_.pp_instance(), | 304 get_interface<PPB_ContentDecryptor_Private>()->SessionClosed( |
| 271 session_id, | 305 associated_instance_.pp_instance(), web_session_id_var.pp_var()); |
| 272 media_error, | |
| 273 system_code); | |
| 274 } | 306 } |
| 275 } | 307 } |
| 276 | 308 |
| 309 void ContentDecryptor_Private::SessionError( |
| 310 const std::string& web_session_id, |
| 311 const std::string& error_name, |
| 312 uint32_t system_code, |
| 313 const std::string& error_description) { |
| 314 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 315 pp::Var web_session_id_var(web_session_id); |
| 316 pp::Var error_name_var(error_name); |
| 317 pp::Var error_description_var(error_description); |
| 318 get_interface<PPB_ContentDecryptor_Private>()->SessionError( |
| 319 associated_instance_.pp_instance(), |
| 320 web_session_id_var.pp_var(), |
| 321 error_name_var.pp_var(), |
| 322 system_code, |
| 323 error_description_var.pp_var()); |
| 324 } |
| 325 } |
| 326 |
| 277 void ContentDecryptor_Private::DeliverBlock( | 327 void ContentDecryptor_Private::DeliverBlock( |
| 278 pp::Buffer_Dev decrypted_block, | 328 pp::Buffer_Dev decrypted_block, |
| 279 const PP_DecryptedBlockInfo& decrypted_block_info) { | 329 const PP_DecryptedBlockInfo& decrypted_block_info) { |
| 280 if (has_interface<PPB_ContentDecryptor_Private>()) { | 330 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 281 get_interface<PPB_ContentDecryptor_Private>()->DeliverBlock( | 331 get_interface<PPB_ContentDecryptor_Private>()->DeliverBlock( |
| 282 associated_instance_.pp_instance(), | 332 associated_instance_.pp_instance(), |
| 283 decrypted_block.pp_resource(), | 333 decrypted_block.pp_resource(), |
| 284 &decrypted_block_info); | 334 &decrypted_block_info); |
| 285 } | 335 } |
| 286 } | 336 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 const PP_DecryptedSampleInfo& decrypted_sample_info) { | 386 const PP_DecryptedSampleInfo& decrypted_sample_info) { |
| 337 if (has_interface<PPB_ContentDecryptor_Private>()) { | 387 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 338 get_interface<PPB_ContentDecryptor_Private>()->DeliverSamples( | 388 get_interface<PPB_ContentDecryptor_Private>()->DeliverSamples( |
| 339 associated_instance_.pp_instance(), | 389 associated_instance_.pp_instance(), |
| 340 audio_frames.pp_resource(), | 390 audio_frames.pp_resource(), |
| 341 &decrypted_sample_info); | 391 &decrypted_sample_info); |
| 342 } | 392 } |
| 343 } | 393 } |
| 344 | 394 |
| 345 } // namespace pp | 395 } // namespace pp |
| OLD | NEW |