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(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 |
87 pp::Var response_var(pp::PASS_REF, response_arg); | 92 pp::Var web_session_id_var(web_session_id_arg); |
| 93 if (!web_session_id_var.is_string()) |
| 94 return; |
| 95 |
| 96 pp::Var response_var(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(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 |
| 260 void ContentDecryptor_Private::PromiseRejected( |
| 261 uint32_t promise_id, |
| 262 PP_CdmExceptionCode exception_code, |
| 263 uint32_t system_code, |
| 264 const std::string& error_description) { |
| 265 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 266 pp::Var error_description_var(error_description); |
| 267 get_interface<PPB_ContentDecryptor_Private>()->PromiseRejected( |
| 268 associated_instance_.pp_instance(), |
| 269 promise_id, |
| 270 exception_code, |
| 271 system_code, |
| 272 error_description_var.pp_var()); |
| 273 } |
| 274 } |
| 275 |
238 void ContentDecryptor_Private::SessionMessage( | 276 void ContentDecryptor_Private::SessionMessage( |
239 uint32_t session_id, | 277 const std::string& web_session_id, |
240 pp::VarArrayBuffer message, | 278 pp::VarArrayBuffer message, |
241 const std::string& destination_url) { | 279 const std::string& destination_url) { |
242 if (has_interface<PPB_ContentDecryptor_Private>()) { | 280 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 281 pp::Var web_session_id_var(web_session_id); |
243 pp::Var destination_url_var(destination_url); | 282 pp::Var destination_url_var(destination_url); |
244 get_interface<PPB_ContentDecryptor_Private>()->SessionMessage( | 283 get_interface<PPB_ContentDecryptor_Private>()->SessionMessage( |
245 associated_instance_.pp_instance(), | 284 associated_instance_.pp_instance(), |
246 session_id, | 285 web_session_id_var.pp_var(), |
247 message.pp_var(), | 286 message.pp_var(), |
248 destination_url_var.pp_var()); | 287 destination_url_var.pp_var()); |
249 } | 288 } |
250 } | 289 } |
251 | 290 |
252 void ContentDecryptor_Private::SessionReady(uint32_t session_id) { | 291 void ContentDecryptor_Private::SessionReady(const std::string& web_session_id) { |
253 if (has_interface<PPB_ContentDecryptor_Private>()) { | 292 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 293 pp::Var web_session_id_var(web_session_id); |
254 get_interface<PPB_ContentDecryptor_Private>()->SessionReady( | 294 get_interface<PPB_ContentDecryptor_Private>()->SessionReady( |
255 associated_instance_.pp_instance(), session_id); | 295 associated_instance_.pp_instance(), web_session_id_var.pp_var()); |
256 } | 296 } |
257 } | 297 } |
258 | 298 |
259 void ContentDecryptor_Private::SessionClosed(uint32_t session_id) { | 299 void ContentDecryptor_Private::SessionClosed( |
| 300 const std::string& web_session_id) { |
260 if (has_interface<PPB_ContentDecryptor_Private>()) { | 301 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 302 pp::Var web_session_id_var(web_session_id); |
261 get_interface<PPB_ContentDecryptor_Private>()->SessionClosed( | 303 get_interface<PPB_ContentDecryptor_Private>()->SessionClosed( |
262 associated_instance_.pp_instance(), session_id); | 304 associated_instance_.pp_instance(), web_session_id_var.pp_var()); |
263 } | 305 } |
264 } | 306 } |
265 | 307 |
266 void ContentDecryptor_Private::SessionError(uint32_t session_id, | 308 void ContentDecryptor_Private::SessionError( |
267 int32_t media_error, | 309 const std::string& web_session_id, |
268 uint32_t system_code) { | 310 PP_CdmExceptionCode exception_code, |
| 311 uint32_t system_code, |
| 312 const std::string& error_description) { |
269 if (has_interface<PPB_ContentDecryptor_Private>()) { | 313 if (has_interface<PPB_ContentDecryptor_Private>()) { |
| 314 pp::Var web_session_id_var(web_session_id); |
| 315 pp::Var error_description_var(error_description); |
270 get_interface<PPB_ContentDecryptor_Private>()->SessionError( | 316 get_interface<PPB_ContentDecryptor_Private>()->SessionError( |
271 associated_instance_.pp_instance(), | 317 associated_instance_.pp_instance(), |
272 session_id, | 318 web_session_id_var.pp_var(), |
273 media_error, | 319 exception_code, |
274 system_code); | 320 system_code, |
| 321 error_description_var.pp_var()); |
275 } | 322 } |
276 } | 323 } |
277 | 324 |
278 void ContentDecryptor_Private::DeliverBlock( | 325 void ContentDecryptor_Private::DeliverBlock( |
279 pp::Buffer_Dev decrypted_block, | 326 pp::Buffer_Dev decrypted_block, |
280 const PP_DecryptedBlockInfo& decrypted_block_info) { | 327 const PP_DecryptedBlockInfo& decrypted_block_info) { |
281 if (has_interface<PPB_ContentDecryptor_Private>()) { | 328 if (has_interface<PPB_ContentDecryptor_Private>()) { |
282 get_interface<PPB_ContentDecryptor_Private>()->DeliverBlock( | 329 get_interface<PPB_ContentDecryptor_Private>()->DeliverBlock( |
283 associated_instance_.pp_instance(), | 330 associated_instance_.pp_instance(), |
284 decrypted_block.pp_resource(), | 331 decrypted_block.pp_resource(), |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 const PP_DecryptedSampleInfo& decrypted_sample_info) { | 384 const PP_DecryptedSampleInfo& decrypted_sample_info) { |
338 if (has_interface<PPB_ContentDecryptor_Private>()) { | 385 if (has_interface<PPB_ContentDecryptor_Private>()) { |
339 get_interface<PPB_ContentDecryptor_Private>()->DeliverSamples( | 386 get_interface<PPB_ContentDecryptor_Private>()->DeliverSamples( |
340 associated_instance_.pp_instance(), | 387 associated_instance_.pp_instance(), |
341 audio_frames.pp_resource(), | 388 audio_frames.pp_resource(), |
342 &decrypted_sample_info); | 389 &decrypted_sample_info); |
343 } | 390 } |
344 } | 391 } |
345 | 392 |
346 } // namespace pp | 393 } // namespace pp |
OLD | NEW |