Chromium Code Reviews| 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" |
| 11 #include "ppapi/c/private/ppp_content_decryptor_private.h" | 11 #include "ppapi/c/private/ppp_content_decryptor_private.h" |
| 12 #include "ppapi/cpp/instance.h" | 12 #include "ppapi/cpp/instance.h" |
| 13 #include "ppapi/cpp/instance_handle.h" | 13 #include "ppapi/cpp/instance_handle.h" |
| 14 #include "ppapi/cpp/logging.h" | 14 #include "ppapi/cpp/logging.h" |
| 15 #include "ppapi/cpp/module.h" | 15 #include "ppapi/cpp/module.h" |
| 16 #include "ppapi/cpp/module_impl.h" | 16 #include "ppapi/cpp/module_impl.h" |
| 17 #include "ppapi/cpp/var.h" | 17 #include "ppapi/cpp/var.h" |
| 18 #include "ppapi/cpp/var_array.h" | |
| 18 | 19 |
| 19 namespace pp { | 20 namespace pp { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 static const char kPPPContentDecryptorInterface[] = | 24 static const char kPPPContentDecryptorInterface[] = |
| 24 PPP_CONTENTDECRYPTOR_PRIVATE_INTERFACE; | 25 PPP_CONTENTDECRYPTOR_PRIVATE_INTERFACE; |
| 25 | 26 |
| 26 void Initialize(PP_Instance instance, | 27 void Initialize(PP_Instance instance, |
| 27 PP_Var key_system_arg) { | 28 PP_Var key_system_arg) { |
| 28 void* object = | 29 void* object = |
| 29 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | 30 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
| 30 if (!object) | 31 if (!object) |
| 31 return; | 32 return; |
| 32 | 33 |
| 33 pp::Var key_system_var(pp::PASS_REF, key_system_arg); | 34 pp::Var key_system_var(pp::PASS_REF, key_system_arg); |
| 34 if (!key_system_var.is_string()) | 35 if (!key_system_var.is_string()) |
| 35 return; | 36 return; |
| 36 | 37 |
| 37 static_cast<ContentDecryptor_Private*>(object)->Initialize( | 38 static_cast<ContentDecryptor_Private*>(object)->Initialize( |
| 38 key_system_var.AsString()); | 39 key_system_var.AsString()); |
| 39 } | 40 } |
| 40 | 41 |
| 42 void SetServerCertificate(PP_Instance instance, | |
| 43 uint32_t promise_id, | |
| 44 PP_Var server_certificate_arg) { | |
| 45 void* object = | |
| 46 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | |
| 47 if (!object) | |
| 48 return; | |
| 49 | |
| 50 pp::Var server_certificate_var(server_certificate_arg); | |
| 51 if (!server_certificate_var.is_array_buffer()) | |
| 52 return; | |
| 53 pp::VarArrayBuffer server_certificate(server_certificate_var); | |
| 54 | |
| 55 static_cast<ContentDecryptor_Private*>(object) | |
| 56 ->SetServerCertificate(promise_id, server_certificate); | |
| 57 } | |
| 58 | |
| 41 void CreateSession(PP_Instance instance, | 59 void CreateSession(PP_Instance instance, |
| 42 uint32_t promise_id, | 60 uint32_t promise_id, |
| 43 PP_Var init_data_type_arg, | 61 PP_Var init_data_type_arg, |
| 44 PP_Var init_data_arg, | 62 PP_Var init_data_arg, |
| 45 PP_SessionType session_type) { | 63 PP_SessionType session_type) { |
| 46 void* object = | 64 void* object = |
| 47 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | 65 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
| 48 if (!object) | 66 if (!object) |
| 49 return; | 67 return; |
| 50 | 68 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 | 113 |
| 96 pp::Var response_var(response_arg); | 114 pp::Var response_var(response_arg); |
| 97 if (!response_var.is_array_buffer()) | 115 if (!response_var.is_array_buffer()) |
| 98 return; | 116 return; |
| 99 pp::VarArrayBuffer response(response_var); | 117 pp::VarArrayBuffer response(response_var); |
| 100 | 118 |
| 101 static_cast<ContentDecryptor_Private*>(object) | 119 static_cast<ContentDecryptor_Private*>(object) |
| 102 ->UpdateSession(promise_id, web_session_id_var.AsString(), response); | 120 ->UpdateSession(promise_id, web_session_id_var.AsString(), response); |
| 103 } | 121 } |
| 104 | 122 |
| 105 void ReleaseSession(PP_Instance instance, | 123 void GetUsableKeyIds(PP_Instance instance, |
| 106 uint32_t promise_id, | 124 uint32_t promise_id, |
| 107 PP_Var web_session_id_arg) { | 125 PP_Var web_session_id_arg) { |
| 108 void* object = | 126 void* object = |
| 109 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | 127 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
| 110 if (!object) | 128 if (!object) |
| 129 return; | |
| 130 | |
| 131 pp::Var web_session_id_var(web_session_id_arg); | |
| 132 if (!web_session_id_var.is_string()) | |
| 133 return; | |
| 134 | |
| 135 static_cast<ContentDecryptor_Private*>(object) | |
| 136 ->GetUsableKeyIds(promise_id, web_session_id_var.AsString()); | |
| 137 } | |
| 138 | |
| 139 void CloseSession(PP_Instance instance, | |
| 140 uint32_t promise_id, | |
| 141 PP_Var web_session_id_arg) { | |
| 142 void* object = | |
| 143 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | |
| 144 if (!object) | |
| 145 return; | |
| 146 | |
| 147 pp::Var web_session_id_var(web_session_id_arg); | |
| 148 if (!web_session_id_var.is_string()) | |
| 149 return; | |
| 150 | |
| 151 static_cast<ContentDecryptor_Private*>(object) | |
| 152 ->CloseSession(promise_id, web_session_id_var.AsString()); | |
| 153 } | |
| 154 | |
| 155 void RemoveSession(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) | |
| 111 return; | 161 return; |
| 112 | 162 |
| 113 pp::Var web_session_id_var(web_session_id_arg); | 163 pp::Var web_session_id_var(web_session_id_arg); |
| 114 if (!web_session_id_var.is_string()) | 164 if (!web_session_id_var.is_string()) |
| 115 return; | 165 return; |
| 116 | 166 |
| 117 static_cast<ContentDecryptor_Private*>(object) | 167 static_cast<ContentDecryptor_Private*>(object) |
| 118 ->ReleaseSession(promise_id, web_session_id_var.AsString()); | 168 ->RemoveSession(promise_id, web_session_id_var.AsString()); |
| 119 } | 169 } |
| 120 | 170 |
| 121 void Decrypt(PP_Instance instance, | 171 void Decrypt(PP_Instance instance, |
| 122 PP_Resource encrypted_resource, | 172 PP_Resource encrypted_resource, |
| 123 const PP_EncryptedBlockInfo* encrypted_block_info) { | 173 const PP_EncryptedBlockInfo* encrypted_block_info) { |
| 124 pp::Buffer_Dev encrypted_block(encrypted_resource); | 174 pp::Buffer_Dev encrypted_block(encrypted_resource); |
| 125 | 175 |
| 126 void* object = | 176 void* object = |
| 127 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | 177 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
| 128 if (!object) | 178 if (!object) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 if (!object) | 249 if (!object) |
| 200 return; | 250 return; |
| 201 | 251 |
| 202 static_cast<ContentDecryptor_Private*>(object)->DecryptAndDecode( | 252 static_cast<ContentDecryptor_Private*>(object)->DecryptAndDecode( |
| 203 decoder_type, | 253 decoder_type, |
| 204 encrypted_buffer, | 254 encrypted_buffer, |
| 205 *encrypted_block_info); | 255 *encrypted_block_info); |
| 206 } | 256 } |
| 207 | 257 |
| 208 const PPP_ContentDecryptor_Private ppp_content_decryptor = { | 258 const PPP_ContentDecryptor_Private ppp_content_decryptor = { |
| 209 &Initialize, | 259 &Initialize, |
| 210 &CreateSession, | 260 &SetServerCertificate, |
| 211 &LoadSession, | 261 &CreateSession, |
| 212 &UpdateSession, | 262 &LoadSession, |
| 213 &ReleaseSession, | 263 &UpdateSession, |
| 214 &Decrypt, | 264 &GetUsableKeyIds, |
|
ddorwin
2014/08/22 20:49:21
ditto
jrummell
2014/08/25 21:54:37
Done.
| |
| 215 &InitializeAudioDecoder, | 265 &CloseSession, |
| 216 &InitializeVideoDecoder, | 266 &RemoveSession, |
| 217 &DeinitializeDecoder, | 267 &Decrypt, |
| 218 &ResetDecoder, | 268 &InitializeAudioDecoder, |
| 219 &DecryptAndDecode | 269 &InitializeVideoDecoder, |
| 220 }; | 270 &DeinitializeDecoder, |
| 271 &ResetDecoder, | |
| 272 &DecryptAndDecode}; | |
| 221 | 273 |
| 222 template <> const char* interface_name<PPB_ContentDecryptor_Private>() { | 274 template <> const char* interface_name<PPB_ContentDecryptor_Private>() { |
| 223 return PPB_CONTENTDECRYPTOR_PRIVATE_INTERFACE; | 275 return PPB_CONTENTDECRYPTOR_PRIVATE_INTERFACE; |
| 224 } | 276 } |
| 225 | 277 |
| 226 } // namespace | 278 } // namespace |
| 227 | 279 |
| 228 ContentDecryptor_Private::ContentDecryptor_Private(Instance* instance) | 280 ContentDecryptor_Private::ContentDecryptor_Private(Instance* instance) |
| 229 : associated_instance_(instance) { | 281 : associated_instance_(instance) { |
| 230 Module::Get()->AddPluginInterface(kPPPContentDecryptorInterface, | 282 Module::Get()->AddPluginInterface(kPPPContentDecryptorInterface, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 250 const std::string& web_session_id) { | 302 const std::string& web_session_id) { |
| 251 if (has_interface<PPB_ContentDecryptor_Private>()) { | 303 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 252 pp::Var web_session_id_var(web_session_id); | 304 pp::Var web_session_id_var(web_session_id); |
| 253 get_interface<PPB_ContentDecryptor_Private>()->PromiseResolvedWithSession( | 305 get_interface<PPB_ContentDecryptor_Private>()->PromiseResolvedWithSession( |
| 254 associated_instance_.pp_instance(), | 306 associated_instance_.pp_instance(), |
| 255 promise_id, | 307 promise_id, |
| 256 web_session_id_var.pp_var()); | 308 web_session_id_var.pp_var()); |
| 257 } | 309 } |
| 258 } | 310 } |
| 259 | 311 |
| 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 for (size_t i = 0; i < key_ids.size(); ++i) { | |
| 318 std::vector<uint8_t> entry = key_ids[i]; | |
|
ddorwin
2014/08/22 20:49:21
const ref?
jrummell
2014/08/25 21:54:37
Done.
| |
| 319 pp::VarArrayBuffer array_buffer(entry.size()); | |
| 320 memcpy(array_buffer.Map(), &entry[0], entry.size()); | |
| 321 key_ids_array.Set(i, pp::Var(array_buffer)); | |
|
ddorwin
2014/08/22 20:49:21
Is there an Add() or Push()? It seems odd that you
jrummell
2014/08/25 21:54:37
Nope. Added a call to SetLength() above to make it
| |
| 322 } | |
| 323 get_interface<PPB_ContentDecryptor_Private>()->PromiseResolvedWithKeyIds( | |
| 324 associated_instance_.pp_instance(), promise_id, key_ids_array.pp_var()); | |
| 325 } | |
| 326 } | |
| 327 | |
| 260 void ContentDecryptor_Private::PromiseRejected( | 328 void ContentDecryptor_Private::PromiseRejected( |
| 261 uint32_t promise_id, | 329 uint32_t promise_id, |
| 262 PP_CdmExceptionCode exception_code, | 330 PP_CdmExceptionCode exception_code, |
| 263 uint32_t system_code, | 331 uint32_t system_code, |
| 264 const std::string& error_description) { | 332 const std::string& error_description) { |
| 265 if (has_interface<PPB_ContentDecryptor_Private>()) { | 333 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 266 pp::Var error_description_var(error_description); | 334 pp::Var error_description_var(error_description); |
| 267 get_interface<PPB_ContentDecryptor_Private>()->PromiseRejected( | 335 get_interface<PPB_ContentDecryptor_Private>()->PromiseRejected( |
| 268 associated_instance_.pp_instance(), | 336 associated_instance_.pp_instance(), |
| 269 promise_id, | 337 promise_id, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 281 pp::Var web_session_id_var(web_session_id); | 349 pp::Var web_session_id_var(web_session_id); |
| 282 pp::Var destination_url_var(destination_url); | 350 pp::Var destination_url_var(destination_url); |
| 283 get_interface<PPB_ContentDecryptor_Private>()->SessionMessage( | 351 get_interface<PPB_ContentDecryptor_Private>()->SessionMessage( |
| 284 associated_instance_.pp_instance(), | 352 associated_instance_.pp_instance(), |
| 285 web_session_id_var.pp_var(), | 353 web_session_id_var.pp_var(), |
| 286 message.pp_var(), | 354 message.pp_var(), |
| 287 destination_url_var.pp_var()); | 355 destination_url_var.pp_var()); |
| 288 } | 356 } |
| 289 } | 357 } |
| 290 | 358 |
| 359 void ContentDecryptor_Private::SessionKeysChange( | |
| 360 const std::string& web_session_id, | |
| 361 bool has_additional_usable_key) { | |
| 362 if (has_interface<PPB_ContentDecryptor_Private>()) { | |
| 363 pp::Var web_session_id_var(web_session_id); | |
| 364 get_interface<PPB_ContentDecryptor_Private>()->SessionKeysChange( | |
| 365 associated_instance_.pp_instance(), | |
| 366 web_session_id_var.pp_var(), | |
| 367 PP_FromBool(has_additional_usable_key)); | |
| 368 } | |
| 369 } | |
| 370 | |
| 371 void ContentDecryptor_Private::SessionExpirationChange( | |
| 372 const std::string& web_session_id, | |
| 373 PP_Time new_expiry_time) { | |
| 374 if (has_interface<PPB_ContentDecryptor_Private>()) { | |
| 375 pp::Var web_session_id_var(web_session_id); | |
| 376 get_interface<PPB_ContentDecryptor_Private>()->SessionExpirationChange( | |
| 377 associated_instance_.pp_instance(), | |
| 378 web_session_id_var.pp_var(), | |
| 379 new_expiry_time); | |
| 380 } | |
| 381 } | |
| 382 | |
| 291 void ContentDecryptor_Private::SessionReady(const std::string& web_session_id) { | 383 void ContentDecryptor_Private::SessionReady(const std::string& web_session_id) { |
| 292 if (has_interface<PPB_ContentDecryptor_Private>()) { | 384 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 293 pp::Var web_session_id_var(web_session_id); | 385 pp::Var web_session_id_var(web_session_id); |
| 294 get_interface<PPB_ContentDecryptor_Private>()->SessionReady( | 386 get_interface<PPB_ContentDecryptor_Private>()->SessionReady( |
| 295 associated_instance_.pp_instance(), web_session_id_var.pp_var()); | 387 associated_instance_.pp_instance(), web_session_id_var.pp_var()); |
| 296 } | 388 } |
| 297 } | 389 } |
| 298 | 390 |
| 299 void ContentDecryptor_Private::SessionClosed( | 391 void ContentDecryptor_Private::SessionClosed( |
| 300 const std::string& web_session_id) { | 392 const std::string& web_session_id) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 const PP_DecryptedSampleInfo& decrypted_sample_info) { | 476 const PP_DecryptedSampleInfo& decrypted_sample_info) { |
| 385 if (has_interface<PPB_ContentDecryptor_Private>()) { | 477 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 386 get_interface<PPB_ContentDecryptor_Private>()->DeliverSamples( | 478 get_interface<PPB_ContentDecryptor_Private>()->DeliverSamples( |
| 387 associated_instance_.pp_instance(), | 479 associated_instance_.pp_instance(), |
| 388 audio_frames.pp_resource(), | 480 audio_frames.pp_resource(), |
| 389 &decrypted_sample_info); | 481 &decrypted_sample_info); |
| 390 } | 482 } |
| 391 } | 483 } |
| 392 | 484 |
| 393 } // namespace pp | 485 } // namespace pp |
| OLD | NEW |