Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: ppapi/cpp/private/content_decryptor_private.cc

Issue 10827280: Add PPAPI decryptor implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix proxied interface definition. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ppapi/cpp/private/content_decryptor_private.h"
6
7 #include <cstring> // memcpy
8
9 #include "ppapi/c/ppb_var.h"
10 #include "ppapi/c/private/ppb_content_decryptor_private.h"
11 #include "ppapi/c/private/ppp_content_decryptor_private.h"
12 #include "ppapi/cpp/instance.h"
13 #include "ppapi/cpp/instance_handle.h"
14 #include "ppapi/cpp/module.h"
15 #include "ppapi/cpp/module_impl.h"
16 #include "ppapi/cpp/var.h"
17
18 namespace pp {
19
20 namespace {
21
22 static const char kPPPContentDecryptorInterface[] =
23 PPP_CONTENTDECRYPTOR_PRIVATE_INTERFACE;
24
25 PP_Bool GenerateKeyRequest(PP_Instance instance,
26 PP_Var key_system_arg,
27 PP_Var init_data_arg) {
28 void* object =
29 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface);
30 if (!object)
31 return PP_FALSE;
32
33 pp::Var key_system_var(pp::PASS_REF, key_system_arg);
34 if (key_system_var.is_string() == false)
35 return PP_FALSE;
36
37 pp::Var init_data_var(pp::PASS_REF, init_data_arg);
38 if (init_data_var.is_array_buffer() == false)
39 return PP_FALSE;
40 pp::VarArrayBuffer init_data_array_buffer(init_data_var);
41
42 return PP_FromBool(
43 static_cast<ContentDecryptor_Private*>(object)->GenerateKeyRequest(
44 key_system_var.AsString(),
45 init_data_array_buffer));
46 }
47
48 PP_Bool AddKey(PP_Instance instance,
49 PP_Var session_id_arg,
50 PP_Var key_arg) {
51 void* object =
52 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface);
53 if (!object)
54 return PP_FALSE;
55
56 pp::Var session_id_var(pp::PASS_REF, session_id_arg);
57 if (session_id_var.is_string() == false)
58 return PP_FALSE;
59
60 pp::Var key_var(pp::PASS_REF, key_arg);
61 if (key_var.is_array_buffer() == false)
62 return PP_FALSE;
63 pp::VarArrayBuffer key(key_var);
64
65 return PP_FromBool(
66 static_cast<ContentDecryptor_Private*>(object)->AddKey(
67 session_id_var.AsString(),
68 key));
69 }
70
71 PP_Bool CancelKeyRequest(PP_Instance instance,
72 PP_Var session_id_arg) {
73 void* object =
74 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface);
75 if (!object)
76 return PP_FALSE;
77
78 pp::Var session_id_var(pp::PASS_REF, session_id_arg);
79 if (session_id_var.is_string() == false)
80 return PP_FALSE;
81
82 return PP_FromBool(
83 static_cast<ContentDecryptor_Private*>(object)->
84 CancelKeyRequest(session_id_var.AsString()));
85 }
86
87
88 PP_Bool Decrypt(PP_Instance instance,
89 PP_Resource encrypted_resource,
90 int32_t request_id) {
91 void* object =
92 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface);
93 if (!object)
94 return PP_FALSE;
95
96 pp::Buffer_Dev encrypted_block(encrypted_resource);
97
98 return PP_FromBool(
99 static_cast<ContentDecryptor_Private*>(object)->Decrypt(encrypted_block,
100 request_id));
101 }
102
103 PP_Bool DecryptAndDecode(PP_Instance instance,
104 PP_Resource encrypted_resource,
105 int32_t request_id) {
106 void* object =
107 Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface);
108 if (!object)
109 return PP_FALSE;
110
111 pp::Buffer_Dev encrypted_block(encrypted_resource);
112
113 return PP_FromBool(
114 static_cast<ContentDecryptor_Private*>(object)->DecryptAndDecode(
115 encrypted_block,
116 request_id));
117 }
118
119 const PPP_ContentDecryptor_Private ppp_content_decryptor = {
120 &GenerateKeyRequest,
121 &AddKey,
122 &CancelKeyRequest,
123 &Decrypt,
124 &DecryptAndDecode
125 };
126
127 template <> const char* interface_name<PPB_ContentDecryptor_Private>() {
128 return PPB_CONTENTDECRYPTOR_PRIVATE_INTERFACE;
129 }
130
131 } // namespace
132
133 ContentDecryptor_Private::ContentDecryptor_Private(Instance* instance)
134 : associated_instance_(instance) {
135 Module::Get()->AddPluginInterface(kPPPContentDecryptorInterface,
136 &ppp_content_decryptor);
137 instance->AddPerInstanceObject(kPPPContentDecryptorInterface, this);
138 }
139
140 ContentDecryptor_Private::~ContentDecryptor_Private() {
141 Instance::RemovePerInstanceObject(associated_instance_,
142 kPPPContentDecryptorInterface,
143 this);
144 }
145
146 void ContentDecryptor_Private::NeedKey(const std::string& key_system,
147 const std::string& session_id,
148 const std::string& init_data) {
149 // session_id can be empty here.
150 if (has_interface<PPB_ContentDecryptor_Private>()) {
151 pp::Var key_system_var(key_system);
152 pp::Var session_id_var(session_id);
153 pp::VarArrayBuffer init_data_array_buffer(init_data.size());
154 memcpy(init_data_array_buffer.Map(), init_data.data(), init_data.size());
155
156 // TODO(tomfinegan): Unmap init_data_array_buffer, or leave it Map'd and
157 // assume it is already mapped inside the plugin?
158
159 get_interface<PPB_ContentDecryptor_Private>()->NeedKey(
160 associated_instance_.pp_instance(),
161 key_system_var.pp_var(),
162 session_id_var.pp_var(),
163 init_data_array_buffer.pp_var());
164 }
165 }
166
167 void ContentDecryptor_Private::KeyAdded(const std::string& key_system,
168 const std::string& session_id) {
169 if (has_interface<PPB_ContentDecryptor_Private>()) {
170 pp::Var key_system_var(key_system);
171 pp::Var session_id_var(session_id);
172 get_interface<PPB_ContentDecryptor_Private>()->KeyAdded(
173 associated_instance_.pp_instance(),
174 key_system_var.pp_var(),
175 session_id_var.pp_var());
176 }
177 }
178
179 void ContentDecryptor_Private::KeyMessage(const std::string& key_system,
180 const std::string& session_id,
181 pp::Buffer_Dev message,
182 const std::string& default_url) {
183 if (has_interface<PPB_ContentDecryptor_Private>()) {
184 pp::Var key_system_var(key_system);
185 pp::Var session_id_var(session_id);
186 pp::Var default_url_var(default_url);
187 get_interface<PPB_ContentDecryptor_Private>()->KeyMessage(
188 associated_instance_.pp_instance(),
189 key_system_var.pp_var(),
190 session_id_var.pp_var(),
191 message.pp_resource(),
192 default_url_var.pp_var());
193 }
194 }
195
196 void ContentDecryptor_Private::KeyError(const std::string& key_system,
197 const std::string& session_id,
198 int32_t media_error,
199 int32_t system_code) {
200 if (has_interface<PPB_ContentDecryptor_Private>()) {
201 pp::Var key_system_var(key_system);
202 pp::Var session_id_var(session_id);
203 get_interface<PPB_ContentDecryptor_Private>()->KeyError(
204 associated_instance_.pp_instance(),
205 key_system_var.pp_var(),
206 session_id_var.pp_var(),
207 media_error,
208 system_code);
209 }
210 }
211
212 void ContentDecryptor_Private::DeliverBlock(pp::Buffer_Dev decrypted_block,
213 int32_t request_id) {
214 if (has_interface<PPB_ContentDecryptor_Private>()) {
215 get_interface<PPB_ContentDecryptor_Private>()->DeliverBlock(
216 associated_instance_.pp_instance(),
217 decrypted_block.pp_resource(),
218 request_id);
219 }
220 }
221
222 void ContentDecryptor_Private::DeliverFrame(pp::Buffer_Dev decrypted_frame,
223 int32_t request_id) {
224 if (has_interface<PPB_ContentDecryptor_Private>()) {
225 get_interface<PPB_ContentDecryptor_Private>()->DeliverFrame(
226 associated_instance_.pp_instance(),
227 decrypted_frame.pp_resource(),
228 request_id);
229 }
230 }
231
232 void ContentDecryptor_Private::DeliverSamples(pp::Buffer_Dev decrypted_samples,
233 int32_t request_id) {
234 if (has_interface<PPB_ContentDecryptor_Private>()) {
235 get_interface<PPB_ContentDecryptor_Private>()->DeliverSamples(
236 associated_instance_.pp_instance(),
237 decrypted_samples.pp_resource(),
238 request_id);
239 }
240 }
241
242 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698