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

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 yet another link error, and rebase once again. 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
« no previous file with comments | « ppapi/cpp/private/content_decryptor_private.h ('k') | ppapi/ppapi_proxy.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 pp::VarArrayBuffer 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
154 // TODO(tomfinegan): Host to plugin stuff needed for init_data?
155
156 get_interface<PPB_ContentDecryptor_Private>()->NeedKey(
157 associated_instance_.pp_instance(),
158 key_system_var.pp_var(),
159 session_id_var.pp_var(),
160 init_data.pp_var());
161 }
162 }
163
164 void ContentDecryptor_Private::KeyAdded(const std::string& key_system,
165 const std::string& session_id) {
166 if (has_interface<PPB_ContentDecryptor_Private>()) {
167 pp::Var key_system_var(key_system);
168 pp::Var session_id_var(session_id);
169 get_interface<PPB_ContentDecryptor_Private>()->KeyAdded(
170 associated_instance_.pp_instance(),
171 key_system_var.pp_var(),
172 session_id_var.pp_var());
173 }
174 }
175
176 void ContentDecryptor_Private::KeyMessage(const std::string& key_system,
177 const std::string& session_id,
178 pp::Buffer_Dev message,
179 const std::string& default_url) {
180 if (has_interface<PPB_ContentDecryptor_Private>()) {
181 pp::Var key_system_var(key_system);
182 pp::Var session_id_var(session_id);
183 pp::Var default_url_var(default_url);
184 get_interface<PPB_ContentDecryptor_Private>()->KeyMessage(
185 associated_instance_.pp_instance(),
186 key_system_var.pp_var(),
187 session_id_var.pp_var(),
188 message.pp_resource(),
189 default_url_var.pp_var());
190 }
191 }
192
193 void ContentDecryptor_Private::KeyError(const std::string& key_system,
194 const std::string& session_id,
195 int32_t media_error,
196 int32_t system_code) {
197 if (has_interface<PPB_ContentDecryptor_Private>()) {
198 pp::Var key_system_var(key_system);
199 pp::Var session_id_var(session_id);
200 get_interface<PPB_ContentDecryptor_Private>()->KeyError(
201 associated_instance_.pp_instance(),
202 key_system_var.pp_var(),
203 session_id_var.pp_var(),
204 media_error,
205 system_code);
206 }
207 }
208
209 void ContentDecryptor_Private::DeliverBlock(pp::Buffer_Dev decrypted_block,
210 int32_t request_id) {
211 if (has_interface<PPB_ContentDecryptor_Private>()) {
212 get_interface<PPB_ContentDecryptor_Private>()->DeliverBlock(
213 associated_instance_.pp_instance(),
214 decrypted_block.pp_resource(),
215 request_id);
216 }
217 }
218
219 void ContentDecryptor_Private::DeliverFrame(pp::Buffer_Dev decrypted_frame,
220 int32_t request_id) {
221 if (has_interface<PPB_ContentDecryptor_Private>()) {
222 get_interface<PPB_ContentDecryptor_Private>()->DeliverFrame(
223 associated_instance_.pp_instance(),
224 decrypted_frame.pp_resource(),
225 request_id);
226 }
227 }
228
229 void ContentDecryptor_Private::DeliverSamples(pp::Buffer_Dev decrypted_samples,
230 int32_t request_id) {
231 if (has_interface<PPB_ContentDecryptor_Private>()) {
232 get_interface<PPB_ContentDecryptor_Private>()->DeliverSamples(
233 associated_instance_.pp_instance(),
234 decrypted_samples.pp_resource(),
235 request_id);
236 }
237 }
238
239 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/cpp/private/content_decryptor_private.h ('k') | ppapi/ppapi_proxy.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698