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 CloseSession(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 ->CloseSession(promise_id, web_session_id_var.AsString()); |
| 137 } |
| 138 |
| 139 void RemoveSession(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 ->RemoveSession(promise_id, web_session_id_var.AsString()); |
| 153 } |
| 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) |
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 ->GetUsableKeyIds(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 &CloseSession, |
215 &InitializeAudioDecoder, | 265 &RemoveSession, |
216 &InitializeVideoDecoder, | 266 &GetUsableKeyIds, |
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 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 |
260 void ContentDecryptor_Private::PromiseRejected( | 329 void ContentDecryptor_Private::PromiseRejected( |
261 uint32_t promise_id, | 330 uint32_t promise_id, |
262 PP_CdmExceptionCode exception_code, | 331 PP_CdmExceptionCode exception_code, |
263 uint32_t system_code, | 332 uint32_t system_code, |
264 const std::string& error_description) { | 333 const std::string& error_description) { |
265 if (has_interface<PPB_ContentDecryptor_Private>()) { | 334 if (has_interface<PPB_ContentDecryptor_Private>()) { |
266 pp::Var error_description_var(error_description); | 335 pp::Var error_description_var(error_description); |
267 get_interface<PPB_ContentDecryptor_Private>()->PromiseRejected( | 336 get_interface<PPB_ContentDecryptor_Private>()->PromiseRejected( |
268 associated_instance_.pp_instance(), | 337 associated_instance_.pp_instance(), |
269 promise_id, | 338 promise_id, |
(...skipping 11 matching lines...) Expand all Loading... |
281 pp::Var web_session_id_var(web_session_id); | 350 pp::Var web_session_id_var(web_session_id); |
282 pp::Var destination_url_var(destination_url); | 351 pp::Var destination_url_var(destination_url); |
283 get_interface<PPB_ContentDecryptor_Private>()->SessionMessage( | 352 get_interface<PPB_ContentDecryptor_Private>()->SessionMessage( |
284 associated_instance_.pp_instance(), | 353 associated_instance_.pp_instance(), |
285 web_session_id_var.pp_var(), | 354 web_session_id_var.pp_var(), |
286 message.pp_var(), | 355 message.pp_var(), |
287 destination_url_var.pp_var()); | 356 destination_url_var.pp_var()); |
288 } | 357 } |
289 } | 358 } |
290 | 359 |
| 360 void ContentDecryptor_Private::SessionKeysChange( |
| 361 const std::string& web_session_id, |
| 362 bool has_additional_usable_key) { |
| 363 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 364 pp::Var web_session_id_var(web_session_id); |
| 365 get_interface<PPB_ContentDecryptor_Private>()->SessionKeysChange( |
| 366 associated_instance_.pp_instance(), |
| 367 web_session_id_var.pp_var(), |
| 368 PP_FromBool(has_additional_usable_key)); |
| 369 } |
| 370 } |
| 371 |
| 372 void ContentDecryptor_Private::SessionExpirationChange( |
| 373 const std::string& web_session_id, |
| 374 PP_Time new_expiry_time) { |
| 375 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 376 pp::Var web_session_id_var(web_session_id); |
| 377 get_interface<PPB_ContentDecryptor_Private>()->SessionExpirationChange( |
| 378 associated_instance_.pp_instance(), |
| 379 web_session_id_var.pp_var(), |
| 380 new_expiry_time); |
| 381 } |
| 382 } |
| 383 |
291 void ContentDecryptor_Private::SessionReady(const std::string& web_session_id) { | 384 void ContentDecryptor_Private::SessionReady(const std::string& web_session_id) { |
292 if (has_interface<PPB_ContentDecryptor_Private>()) { | 385 if (has_interface<PPB_ContentDecryptor_Private>()) { |
293 pp::Var web_session_id_var(web_session_id); | 386 pp::Var web_session_id_var(web_session_id); |
294 get_interface<PPB_ContentDecryptor_Private>()->SessionReady( | 387 get_interface<PPB_ContentDecryptor_Private>()->SessionReady( |
295 associated_instance_.pp_instance(), web_session_id_var.pp_var()); | 388 associated_instance_.pp_instance(), web_session_id_var.pp_var()); |
296 } | 389 } |
297 } | 390 } |
298 | 391 |
299 void ContentDecryptor_Private::SessionClosed( | 392 void ContentDecryptor_Private::SessionClosed( |
300 const std::string& web_session_id) { | 393 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) { | 477 const PP_DecryptedSampleInfo& decrypted_sample_info) { |
385 if (has_interface<PPB_ContentDecryptor_Private>()) { | 478 if (has_interface<PPB_ContentDecryptor_Private>()) { |
386 get_interface<PPB_ContentDecryptor_Private>()->DeliverSamples( | 479 get_interface<PPB_ContentDecryptor_Private>()->DeliverSamples( |
387 associated_instance_.pp_instance(), | 480 associated_instance_.pp_instance(), |
388 audio_frames.pp_resource(), | 481 audio_frames.pp_resource(), |
389 &decrypted_sample_info); | 482 &decrypted_sample_info); |
390 } | 483 } |
391 } | 484 } |
392 | 485 |
393 } // namespace pp | 486 } // namespace pp |
OLD | NEW |