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/module.h" | 15 #include "ppapi/cpp/module.h" |
15 #include "ppapi/cpp/module_impl.h" | 16 #include "ppapi/cpp/module_impl.h" |
16 #include "ppapi/cpp/var.h" | 17 #include "ppapi/cpp/var.h" |
17 | 18 |
18 namespace pp { | 19 namespace pp { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 static const char kPPPContentDecryptorInterface[] = | 23 static const char kPPPContentDecryptorInterface[] = |
23 PPP_CONTENTDECRYPTOR_PRIVATE_INTERFACE; | 24 PPP_CONTENTDECRYPTOR_PRIVATE_INTERFACE; |
(...skipping 16 matching lines...) Expand all Loading... |
40 pp::VarArrayBuffer init_data_array_buffer(init_data_var); | 41 pp::VarArrayBuffer init_data_array_buffer(init_data_var); |
41 | 42 |
42 return PP_FromBool( | 43 return PP_FromBool( |
43 static_cast<ContentDecryptor_Private*>(object)->GenerateKeyRequest( | 44 static_cast<ContentDecryptor_Private*>(object)->GenerateKeyRequest( |
44 key_system_var.AsString(), | 45 key_system_var.AsString(), |
45 init_data_array_buffer)); | 46 init_data_array_buffer)); |
46 } | 47 } |
47 | 48 |
48 PP_Bool AddKey(PP_Instance instance, | 49 PP_Bool AddKey(PP_Instance instance, |
49 PP_Var session_id_arg, | 50 PP_Var session_id_arg, |
50 PP_Var key_arg) { | 51 PP_Var key_arg, |
| 52 PP_Var init_data_arg) { |
51 void* object = | 53 void* object = |
52 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | 54 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
53 if (!object) | 55 if (!object) |
54 return PP_FALSE; | 56 return PP_FALSE; |
55 | 57 |
56 pp::Var session_id_var(pp::PASS_REF, session_id_arg); | 58 pp::Var session_id_var(pp::PASS_REF, session_id_arg); |
57 if (session_id_var.is_string() == false) | 59 if (session_id_var.is_string() == false) |
58 return PP_FALSE; | 60 return PP_FALSE; |
59 | 61 |
60 pp::Var key_var(pp::PASS_REF, key_arg); | 62 pp::Var key_var(pp::PASS_REF, key_arg); |
61 if (key_var.is_array_buffer() == false) | 63 if (key_var.is_array_buffer() == false) |
62 return PP_FALSE; | 64 return PP_FALSE; |
63 pp::VarArrayBuffer key(key_var); | 65 pp::VarArrayBuffer key(key_var); |
64 | 66 |
| 67 pp::Var init_data_var(pp::PASS_REF, init_data_arg); |
| 68 if (init_data_var.is_array_buffer() == false) |
| 69 return PP_FALSE; |
| 70 pp::VarArrayBuffer init_data(init_data_var); |
| 71 |
65 return PP_FromBool( | 72 return PP_FromBool( |
66 static_cast<ContentDecryptor_Private*>(object)->AddKey( | 73 static_cast<ContentDecryptor_Private*>(object)->AddKey( |
67 session_id_var.AsString(), | 74 session_id_var.AsString(), |
68 key)); | 75 key, |
| 76 init_data)); |
69 } | 77 } |
70 | 78 |
71 PP_Bool CancelKeyRequest(PP_Instance instance, | 79 PP_Bool CancelKeyRequest(PP_Instance instance, |
72 PP_Var session_id_arg) { | 80 PP_Var session_id_arg) { |
73 void* object = | 81 void* object = |
74 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | 82 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
75 if (!object) | 83 if (!object) |
76 return PP_FALSE; | 84 return PP_FALSE; |
77 | 85 |
78 pp::Var session_id_var(pp::PASS_REF, session_id_arg); | 86 pp::Var session_id_var(pp::PASS_REF, session_id_arg); |
79 if (session_id_var.is_string() == false) | 87 if (session_id_var.is_string() == false) |
80 return PP_FALSE; | 88 return PP_FALSE; |
81 | 89 |
82 return PP_FromBool( | 90 return PP_FromBool( |
83 static_cast<ContentDecryptor_Private*>(object)-> | 91 static_cast<ContentDecryptor_Private*>(object)-> |
84 CancelKeyRequest(session_id_var.AsString())); | 92 CancelKeyRequest(session_id_var.AsString())); |
85 } | 93 } |
86 | 94 |
87 | 95 |
88 PP_Bool Decrypt(PP_Instance instance, | 96 PP_Bool Decrypt(PP_Instance instance, |
89 PP_Resource encrypted_resource, | 97 PP_Resource encrypted_resource, |
90 int32_t request_id) { | 98 const PP_EncryptedBlockInfo* encrypted_block_info) { |
91 void* object = | 99 void* object = |
92 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | 100 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
93 if (!object) | 101 if (!object) |
94 return PP_FALSE; | 102 return PP_FALSE; |
95 | 103 |
96 pp::Buffer_Dev encrypted_block(encrypted_resource); | 104 pp::Buffer_Dev encrypted_block(encrypted_resource); |
97 | 105 |
98 return PP_FromBool( | 106 return PP_FromBool( |
99 static_cast<ContentDecryptor_Private*>(object)->Decrypt(encrypted_block, | 107 static_cast<ContentDecryptor_Private*>(object)->Decrypt( |
100 request_id)); | 108 encrypted_block, |
| 109 *encrypted_block_info)); |
101 } | 110 } |
102 | 111 |
103 PP_Bool DecryptAndDecode(PP_Instance instance, | 112 PP_Bool DecryptAndDecode(PP_Instance instance, |
104 PP_Resource encrypted_resource, | 113 PP_Resource encrypted_resource, |
105 int32_t request_id) { | 114 const PP_EncryptedBlockInfo* encrypted_block_info) { |
106 void* object = | 115 void* object = |
107 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); | 116 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); |
108 if (!object) | 117 if (!object) |
109 return PP_FALSE; | 118 return PP_FALSE; |
110 | 119 |
111 pp::Buffer_Dev encrypted_block(encrypted_resource); | 120 pp::Buffer_Dev encrypted_block(encrypted_resource); |
112 | 121 |
113 return PP_FromBool( | 122 return PP_FromBool( |
114 static_cast<ContentDecryptor_Private*>(object)->DecryptAndDecode( | 123 static_cast<ContentDecryptor_Private*>(object)->DecryptAndDecode( |
115 encrypted_block, | 124 encrypted_block, |
116 request_id)); | 125 *encrypted_block_info)); |
117 } | 126 } |
118 | 127 |
119 const PPP_ContentDecryptor_Private ppp_content_decryptor = { | 128 const PPP_ContentDecryptor_Private ppp_content_decryptor = { |
120 &GenerateKeyRequest, | 129 &GenerateKeyRequest, |
121 &AddKey, | 130 &AddKey, |
122 &CancelKeyRequest, | 131 &CancelKeyRequest, |
123 &Decrypt, | 132 &Decrypt, |
124 &DecryptAndDecode | 133 &DecryptAndDecode |
125 }; | 134 }; |
126 | 135 |
(...skipping 17 matching lines...) Expand all Loading... |
144 } | 153 } |
145 | 154 |
146 void ContentDecryptor_Private::NeedKey(const std::string& key_system, | 155 void ContentDecryptor_Private::NeedKey(const std::string& key_system, |
147 const std::string& session_id, | 156 const std::string& session_id, |
148 pp::VarArrayBuffer init_data) { | 157 pp::VarArrayBuffer init_data) { |
149 // session_id can be empty here. | 158 // session_id can be empty here. |
150 if (has_interface<PPB_ContentDecryptor_Private>()) { | 159 if (has_interface<PPB_ContentDecryptor_Private>()) { |
151 pp::Var key_system_var(key_system); | 160 pp::Var key_system_var(key_system); |
152 pp::Var session_id_var(session_id); | 161 pp::Var session_id_var(session_id); |
153 | 162 |
154 // TODO(tomfinegan): Host to plugin stuff needed for init_data? | |
155 | |
156 get_interface<PPB_ContentDecryptor_Private>()->NeedKey( | 163 get_interface<PPB_ContentDecryptor_Private>()->NeedKey( |
157 associated_instance_.pp_instance(), | 164 associated_instance_.pp_instance(), |
158 key_system_var.pp_var(), | 165 key_system_var.pp_var(), |
159 session_id_var.pp_var(), | 166 session_id_var.pp_var(), |
160 init_data.pp_var()); | 167 init_data.pp_var()); |
161 } | 168 } |
162 } | 169 } |
163 | 170 |
164 void ContentDecryptor_Private::KeyAdded(const std::string& key_system, | 171 void ContentDecryptor_Private::KeyAdded(const std::string& key_system, |
165 const std::string& session_id) { | 172 const std::string& session_id) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 pp::Var session_id_var(session_id); | 206 pp::Var session_id_var(session_id); |
200 get_interface<PPB_ContentDecryptor_Private>()->KeyError( | 207 get_interface<PPB_ContentDecryptor_Private>()->KeyError( |
201 associated_instance_.pp_instance(), | 208 associated_instance_.pp_instance(), |
202 key_system_var.pp_var(), | 209 key_system_var.pp_var(), |
203 session_id_var.pp_var(), | 210 session_id_var.pp_var(), |
204 media_error, | 211 media_error, |
205 system_code); | 212 system_code); |
206 } | 213 } |
207 } | 214 } |
208 | 215 |
209 void ContentDecryptor_Private::DeliverBlock(pp::Buffer_Dev decrypted_block, | 216 void ContentDecryptor_Private::DeliverBlock( |
210 int32_t request_id) { | 217 pp::Buffer_Dev decrypted_block, |
| 218 const PP_DecryptedBlockInfo& decrypted_block_info) { |
211 if (has_interface<PPB_ContentDecryptor_Private>()) { | 219 if (has_interface<PPB_ContentDecryptor_Private>()) { |
212 get_interface<PPB_ContentDecryptor_Private>()->DeliverBlock( | 220 get_interface<PPB_ContentDecryptor_Private>()->DeliverBlock( |
213 associated_instance_.pp_instance(), | 221 associated_instance_.pp_instance(), |
214 decrypted_block.pp_resource(), | 222 decrypted_block.pp_resource(), |
215 request_id); | 223 &decrypted_block_info); |
216 } | 224 } |
217 } | 225 } |
218 | 226 |
219 void ContentDecryptor_Private::DeliverFrame(pp::Buffer_Dev decrypted_frame, | 227 void ContentDecryptor_Private::DeliverFrame( |
220 int32_t request_id) { | 228 pp::Buffer_Dev decrypted_frame, |
| 229 const PP_DecryptedBlockInfo& decrypted_block_info) { |
221 if (has_interface<PPB_ContentDecryptor_Private>()) { | 230 if (has_interface<PPB_ContentDecryptor_Private>()) { |
222 get_interface<PPB_ContentDecryptor_Private>()->DeliverFrame( | 231 get_interface<PPB_ContentDecryptor_Private>()->DeliverFrame( |
223 associated_instance_.pp_instance(), | 232 associated_instance_.pp_instance(), |
224 decrypted_frame.pp_resource(), | 233 decrypted_frame.pp_resource(), |
225 request_id); | 234 &decrypted_block_info); |
226 } | 235 } |
227 } | 236 } |
228 | 237 |
229 void ContentDecryptor_Private::DeliverSamples(pp::Buffer_Dev decrypted_samples, | 238 void ContentDecryptor_Private::DeliverSamples( |
230 int32_t request_id) { | 239 pp::Buffer_Dev decrypted_samples, |
| 240 const PP_DecryptedBlockInfo& decrypted_block_info) { |
231 if (has_interface<PPB_ContentDecryptor_Private>()) { | 241 if (has_interface<PPB_ContentDecryptor_Private>()) { |
232 get_interface<PPB_ContentDecryptor_Private>()->DeliverSamples( | 242 get_interface<PPB_ContentDecryptor_Private>()->DeliverSamples( |
233 associated_instance_.pp_instance(), | 243 associated_instance_.pp_instance(), |
234 decrypted_samples.pp_resource(), | 244 decrypted_samples.pp_resource(), |
235 request_id); | 245 &decrypted_block_info); |
236 } | 246 } |
237 } | 247 } |
238 | 248 |
239 } // namespace pp | 249 } // namespace pp |
OLD | NEW |