Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ppapi / proxy / ppp_content_decryptor_private_proxy.cc
blobe64463805ef2d94c9338a0b445ffcfb66f0cd240
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.
5 #include "ppapi/proxy/ppp_content_decryptor_private_proxy.h"
7 #include "base/files/file.h"
8 #include "media/base/limits.h"
9 #include "ppapi/c/pp_bool.h"
10 #include "ppapi/c/ppb_core.h"
11 #include "ppapi/proxy/content_decryptor_private_serializer.h"
12 #include "ppapi/proxy/host_dispatcher.h"
13 #include "ppapi/proxy/plugin_globals.h"
14 #include "ppapi/proxy/plugin_resource_tracker.h"
15 #include "ppapi/proxy/ppapi_messages.h"
16 #include "ppapi/proxy/ppb_buffer_proxy.h"
17 #include "ppapi/proxy/serialized_var.h"
18 #include "ppapi/shared_impl/scoped_pp_resource.h"
19 #include "ppapi/shared_impl/scoped_pp_var.h"
20 #include "ppapi/shared_impl/var_tracker.h"
21 #include "ppapi/thunk/enter.h"
22 #include "ppapi/thunk/ppb_buffer_api.h"
23 #include "ppapi/thunk/ppb_instance_api.h"
24 #include "ppapi/thunk/thunk.h"
26 using ppapi::thunk::EnterResourceNoLock;
27 using ppapi::thunk::PPB_Buffer_API;
28 using ppapi::thunk::PPB_Instance_API;
30 namespace ppapi {
31 namespace proxy {
33 namespace {
35 PP_Bool DescribeHostBufferResource(PP_Resource resource, uint32_t* size) {
36 EnterResourceNoLock<PPB_Buffer_API> enter(resource, true);
37 if (enter.failed())
38 return PP_FALSE;
39 return enter.object()->Describe(size);
42 // TODO(dmichael): Refactor so this handle sharing code is in one place.
43 PP_Bool ShareHostBufferResourceToPlugin(
44 HostDispatcher* dispatcher,
45 PP_Resource resource,
46 base::SharedMemoryHandle* shared_mem_handle) {
47 if (!dispatcher || resource == 0 || !shared_mem_handle)
48 return PP_FALSE;
49 EnterResourceNoLock<PPB_Buffer_API> enter(resource, true);
50 if (enter.failed())
51 return PP_FALSE;
52 int handle;
53 int32_t result = enter.object()->GetSharedMemory(&handle);
54 if (result != PP_OK)
55 return PP_FALSE;
56 base::PlatformFile platform_file =
57 #if defined(OS_WIN)
58 reinterpret_cast<HANDLE>(static_cast<intptr_t>(handle));
59 #elif defined(OS_POSIX)
60 handle;
61 #else
62 #error Not implemented.
63 #endif
65 *shared_mem_handle = dispatcher->ShareHandleWithRemote(platform_file, false);
66 return PP_TRUE;
69 // SerializedVarReceiveInput will decrement the reference count, but we want
70 // to give the recipient a reference. This utility function takes care of that
71 // work for the message handlers defined below.
72 PP_Var ExtractReceivedVarAndAddRef(Dispatcher* dispatcher,
73 SerializedVarReceiveInput* serialized_var) {
74 PP_Var var = serialized_var->Get(dispatcher);
75 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var);
76 return var;
79 bool InitializePppDecryptorBuffer(PP_Instance instance,
80 HostDispatcher* dispatcher,
81 PP_Resource resource,
82 PPPDecryptor_Buffer* buffer) {
83 if (!buffer) {
84 NOTREACHED();
85 return false;
88 if (resource == 0) {
89 buffer->resource = HostResource();
90 buffer->handle = base::SharedMemoryHandle();
91 buffer->size = 0;
92 return true;
95 HostResource host_resource;
96 host_resource.SetHostResource(instance, resource);
98 uint32_t size = 0;
99 if (DescribeHostBufferResource(resource, &size) == PP_FALSE)
100 return false;
102 base::SharedMemoryHandle handle;
103 if (ShareHostBufferResourceToPlugin(dispatcher,
104 resource,
105 &handle) == PP_FALSE)
106 return false;
108 buffer->resource = host_resource;
109 buffer->handle = handle;
110 buffer->size = size;
111 return true;
114 void Initialize(PP_Instance instance,
115 PP_Var key_system,
116 PP_Bool allow_distinctive_identifier,
117 PP_Bool allow_persistent_state) {
118 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
119 if (!dispatcher) {
120 NOTREACHED();
121 return;
124 dispatcher->Send(
125 new PpapiMsg_PPPContentDecryptor_Initialize(
126 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
127 instance,
128 SerializedVarSendInput(dispatcher, key_system),
129 allow_distinctive_identifier,
130 allow_persistent_state));
133 void SetServerCertificate(PP_Instance instance,
134 uint32_t promise_id,
135 PP_Var server_certificate) {
136 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
137 if (!dispatcher) {
138 NOTREACHED();
139 return;
142 ArrayBufferVar* server_certificate_buffer =
143 ArrayBufferVar::FromPPVar(server_certificate);
144 if (!server_certificate_buffer ||
145 server_certificate_buffer->ByteLength() <
146 media::limits::kMinCertificateLength ||
147 server_certificate_buffer->ByteLength() >
148 media::limits::kMaxCertificateLength) {
149 NOTREACHED();
150 return;
153 const uint8_t* server_certificate_ptr =
154 static_cast<const uint8_t*>(server_certificate_buffer->Map());
155 const uint32_t server_certificate_size =
156 server_certificate_buffer->ByteLength();
157 std::vector<uint8_t> server_certificate_vector(
158 server_certificate_ptr, server_certificate_ptr + server_certificate_size);
160 dispatcher->Send(new PpapiMsg_PPPContentDecryptor_SetServerCertificate(
161 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
162 instance,
163 promise_id,
164 server_certificate_vector));
167 void CreateSessionAndGenerateRequest(PP_Instance instance,
168 uint32_t promise_id,
169 PP_SessionType session_type,
170 PP_InitDataType init_data_type,
171 PP_Var init_data) {
172 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
173 if (!dispatcher) {
174 NOTREACHED();
175 return;
178 dispatcher->Send(
179 new PpapiMsg_PPPContentDecryptor_CreateSessionAndGenerateRequest(
180 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, instance, promise_id,
181 session_type, init_data_type,
182 SerializedVarSendInput(dispatcher, init_data)));
185 void LoadSession(PP_Instance instance,
186 uint32_t promise_id,
187 PP_SessionType session_type,
188 PP_Var session_id) {
189 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
190 if (!dispatcher) {
191 NOTREACHED();
192 return;
195 dispatcher->Send(new PpapiMsg_PPPContentDecryptor_LoadSession(
196 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, instance, promise_id, session_type,
197 SerializedVarSendInput(dispatcher, session_id)));
200 void UpdateSession(PP_Instance instance,
201 uint32_t promise_id,
202 PP_Var session_id,
203 PP_Var response) {
204 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
205 if (!dispatcher) {
206 NOTREACHED();
207 return;
210 dispatcher->Send(new PpapiMsg_PPPContentDecryptor_UpdateSession(
211 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, instance, promise_id,
212 SerializedVarSendInput(dispatcher, session_id),
213 SerializedVarSendInput(dispatcher, response)));
216 void CloseSession(PP_Instance instance,
217 uint32_t promise_id,
218 PP_Var session_id) {
219 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
220 if (!dispatcher) {
221 NOTREACHED();
222 return;
225 StringVar* session_id_string = StringVar::FromPPVar(session_id);
226 if (!session_id_string ||
227 session_id_string->value().length() >
228 media::limits::kMaxSessionIdLength) {
229 NOTREACHED();
230 return;
233 dispatcher->Send(new PpapiMsg_PPPContentDecryptor_CloseSession(
234 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, instance, promise_id,
235 session_id_string->value()));
238 void RemoveSession(PP_Instance instance,
239 uint32_t promise_id,
240 PP_Var session_id) {
241 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
242 if (!dispatcher) {
243 NOTREACHED();
244 return;
247 StringVar* session_id_string = StringVar::FromPPVar(session_id);
248 if (!session_id_string ||
249 session_id_string->value().length() >
250 media::limits::kMaxSessionIdLength) {
251 NOTREACHED();
252 return;
255 dispatcher->Send(new PpapiMsg_PPPContentDecryptor_RemoveSession(
256 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, instance, promise_id,
257 session_id_string->value()));
260 void Decrypt(PP_Instance instance,
261 PP_Resource encrypted_block,
262 const PP_EncryptedBlockInfo* encrypted_block_info) {
263 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
264 if (!dispatcher) {
265 NOTREACHED();
266 return;
269 PPPDecryptor_Buffer buffer;
270 if (!InitializePppDecryptorBuffer(instance,
271 dispatcher,
272 encrypted_block,
273 &buffer)) {
274 NOTREACHED();
275 return;
278 std::string serialized_block_info;
279 if (!SerializeBlockInfo(*encrypted_block_info, &serialized_block_info)) {
280 NOTREACHED();
281 return;
284 // PluginResourceTracker in the plugin process assumes that resources that it
285 // tracks have been addrefed on behalf of the plugin at the renderer side. So
286 // we explicitly do it for |encryped_block| here.
287 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(encrypted_block);
289 dispatcher->Send(
290 new PpapiMsg_PPPContentDecryptor_Decrypt(
291 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
292 instance,
293 buffer,
294 serialized_block_info));
297 void InitializeAudioDecoder(
298 PP_Instance instance,
299 const PP_AudioDecoderConfig* decoder_config,
300 PP_Resource extra_data_buffer) {
301 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
302 if (!dispatcher) {
303 NOTREACHED();
304 return;
307 std::string serialized_decoder_config;
308 if (!SerializeBlockInfo(*decoder_config, &serialized_decoder_config)) {
309 NOTREACHED();
310 return;
313 PPPDecryptor_Buffer buffer;
314 if (!InitializePppDecryptorBuffer(instance,
315 dispatcher,
316 extra_data_buffer,
317 &buffer)) {
318 NOTREACHED();
319 return;
322 // PluginResourceTracker in the plugin process assumes that resources that it
323 // tracks have been addrefed on behalf of the plugin at the renderer side. So
324 // we explicitly do it for |extra_data_buffer| here.
325 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(extra_data_buffer);
327 dispatcher->Send(
328 new PpapiMsg_PPPContentDecryptor_InitializeAudioDecoder(
329 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
330 instance,
331 serialized_decoder_config,
332 buffer));
335 void InitializeVideoDecoder(
336 PP_Instance instance,
337 const PP_VideoDecoderConfig* decoder_config,
338 PP_Resource extra_data_buffer) {
339 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
340 if (!dispatcher) {
341 NOTREACHED();
342 return;
345 std::string serialized_decoder_config;
346 if (!SerializeBlockInfo(*decoder_config, &serialized_decoder_config)) {
347 NOTREACHED();
348 return;
351 PPPDecryptor_Buffer buffer;
352 if (!InitializePppDecryptorBuffer(instance,
353 dispatcher,
354 extra_data_buffer,
355 &buffer)) {
356 NOTREACHED();
357 return;
360 // PluginResourceTracker in the plugin process assumes that resources that it
361 // tracks have been addrefed on behalf of the plugin at the renderer side. So
362 // we explicitly do it for |extra_data_buffer| here.
363 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(extra_data_buffer);
365 dispatcher->Send(
366 new PpapiMsg_PPPContentDecryptor_InitializeVideoDecoder(
367 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
368 instance,
369 serialized_decoder_config,
370 buffer));
374 void DeinitializeDecoder(PP_Instance instance,
375 PP_DecryptorStreamType decoder_type,
376 uint32_t request_id) {
377 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
378 if (!dispatcher) {
379 NOTREACHED();
380 return;
383 dispatcher->Send(
384 new PpapiMsg_PPPContentDecryptor_DeinitializeDecoder(
385 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
386 instance,
387 decoder_type,
388 request_id));
391 void ResetDecoder(PP_Instance instance,
392 PP_DecryptorStreamType decoder_type,
393 uint32_t request_id) {
394 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
395 if (!dispatcher) {
396 NOTREACHED();
397 return;
400 dispatcher->Send(
401 new PpapiMsg_PPPContentDecryptor_ResetDecoder(
402 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
403 instance,
404 decoder_type,
405 request_id));
408 void DecryptAndDecode(PP_Instance instance,
409 PP_DecryptorStreamType decoder_type,
410 PP_Resource encrypted_buffer,
411 const PP_EncryptedBlockInfo* encrypted_block_info) {
412 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
413 if (!dispatcher) {
414 NOTREACHED();
415 return;
418 PPPDecryptor_Buffer buffer;
419 if (!InitializePppDecryptorBuffer(instance,
420 dispatcher,
421 encrypted_buffer,
422 &buffer)) {
423 NOTREACHED();
424 return;
427 std::string serialized_block_info;
428 if (!SerializeBlockInfo(*encrypted_block_info, &serialized_block_info)) {
429 NOTREACHED();
430 return;
433 // PluginResourceTracker in the plugin process assumes that resources that it
434 // tracks have been addrefed on behalf of the plugin at the renderer side. So
435 // we explicitly do it for |encrypted_buffer| here.
436 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(encrypted_buffer);
438 dispatcher->Send(
439 new PpapiMsg_PPPContentDecryptor_DecryptAndDecode(
440 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
441 instance,
442 decoder_type,
443 buffer,
444 serialized_block_info));
447 static const PPP_ContentDecryptor_Private content_decryptor_interface = {
448 &Initialize,
449 &SetServerCertificate,
450 &CreateSessionAndGenerateRequest,
451 &LoadSession,
452 &UpdateSession,
453 &CloseSession,
454 &RemoveSession,
455 &Decrypt,
456 &InitializeAudioDecoder,
457 &InitializeVideoDecoder,
458 &DeinitializeDecoder,
459 &ResetDecoder,
460 &DecryptAndDecode};
462 } // namespace
464 PPP_ContentDecryptor_Private_Proxy::PPP_ContentDecryptor_Private_Proxy(
465 Dispatcher* dispatcher)
466 : InterfaceProxy(dispatcher),
467 ppp_decryptor_impl_(NULL) {
468 if (dispatcher->IsPlugin()) {
469 ppp_decryptor_impl_ = static_cast<const PPP_ContentDecryptor_Private*>(
470 dispatcher->local_get_interface()(
471 PPP_CONTENTDECRYPTOR_PRIVATE_INTERFACE));
475 PPP_ContentDecryptor_Private_Proxy::~PPP_ContentDecryptor_Private_Proxy() {
478 // static
479 const PPP_ContentDecryptor_Private*
480 PPP_ContentDecryptor_Private_Proxy::GetProxyInterface() {
481 return &content_decryptor_interface;
484 bool PPP_ContentDecryptor_Private_Proxy::OnMessageReceived(
485 const IPC::Message& msg) {
486 if (!dispatcher()->IsPlugin())
487 return false; // These are only valid from host->plugin.
488 // Don't allow the plugin to send these to the host.
490 bool handled = true;
491 IPC_BEGIN_MESSAGE_MAP(PPP_ContentDecryptor_Private_Proxy, msg)
492 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_Initialize,
493 OnMsgInitialize)
494 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_SetServerCertificate,
495 OnMsgSetServerCertificate)
496 IPC_MESSAGE_HANDLER(
497 PpapiMsg_PPPContentDecryptor_CreateSessionAndGenerateRequest,
498 OnMsgCreateSessionAndGenerateRequest)
499 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_LoadSession,
500 OnMsgLoadSession)
501 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_UpdateSession,
502 OnMsgUpdateSession)
503 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_CloseSession,
504 OnMsgCloseSession)
505 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_RemoveSession,
506 OnMsgRemoveSession)
507 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_Decrypt,
508 OnMsgDecrypt)
509 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_InitializeAudioDecoder,
510 OnMsgInitializeAudioDecoder)
511 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_InitializeVideoDecoder,
512 OnMsgInitializeVideoDecoder)
513 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_DeinitializeDecoder,
514 OnMsgDeinitializeDecoder)
515 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_ResetDecoder,
516 OnMsgResetDecoder)
517 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_DecryptAndDecode,
518 OnMsgDecryptAndDecode)
519 IPC_MESSAGE_UNHANDLED(handled = false)
520 IPC_END_MESSAGE_MAP()
521 DCHECK(handled);
522 return handled;
525 void PPP_ContentDecryptor_Private_Proxy::OnMsgInitialize(
526 PP_Instance instance,
527 SerializedVarReceiveInput key_system,
528 PP_Bool allow_distinctive_identifier,
529 PP_Bool allow_persistent_state) {
530 if (ppp_decryptor_impl_) {
531 CallWhileUnlocked(
532 ppp_decryptor_impl_->Initialize,
533 instance,
534 ExtractReceivedVarAndAddRef(dispatcher(), &key_system),
535 allow_distinctive_identifier,
536 allow_persistent_state);
540 void PPP_ContentDecryptor_Private_Proxy::OnMsgSetServerCertificate(
541 PP_Instance instance,
542 uint32_t promise_id,
543 std::vector<uint8_t> server_certificate) {
544 if (server_certificate.size() < media::limits::kMinCertificateLength ||
545 server_certificate.size() > media::limits::kMaxCertificateLength) {
546 NOTREACHED();
547 return;
550 if (ppp_decryptor_impl_) {
551 ScopedPPVar server_certificate_var(
552 ScopedPPVar::PassRef(),
553 PpapiGlobals::Get()
554 ->GetVarTracker()
555 ->MakeArrayBufferPPVar(
556 static_cast<uint32_t>(server_certificate.size()),
557 &server_certificate[0]));
558 CallWhileUnlocked(ppp_decryptor_impl_->SetServerCertificate,
559 instance,
560 promise_id,
561 server_certificate_var.get());
565 void PPP_ContentDecryptor_Private_Proxy::OnMsgCreateSessionAndGenerateRequest(
566 PP_Instance instance,
567 uint32_t promise_id,
568 PP_SessionType session_type,
569 PP_InitDataType init_data_type,
570 SerializedVarReceiveInput init_data) {
571 if (ppp_decryptor_impl_) {
572 CallWhileUnlocked(ppp_decryptor_impl_->CreateSessionAndGenerateRequest,
573 instance, promise_id, session_type, init_data_type,
574 ExtractReceivedVarAndAddRef(dispatcher(), &init_data));
578 void PPP_ContentDecryptor_Private_Proxy::OnMsgLoadSession(
579 PP_Instance instance,
580 uint32_t promise_id,
581 PP_SessionType session_type,
582 SerializedVarReceiveInput session_id) {
583 if (ppp_decryptor_impl_) {
584 CallWhileUnlocked(ppp_decryptor_impl_->LoadSession, instance, promise_id,
585 session_type,
586 ExtractReceivedVarAndAddRef(dispatcher(), &session_id));
590 void PPP_ContentDecryptor_Private_Proxy::OnMsgUpdateSession(
591 PP_Instance instance,
592 uint32_t promise_id,
593 SerializedVarReceiveInput session_id,
594 SerializedVarReceiveInput response) {
595 if (ppp_decryptor_impl_) {
596 CallWhileUnlocked(ppp_decryptor_impl_->UpdateSession, instance, promise_id,
597 ExtractReceivedVarAndAddRef(dispatcher(), &session_id),
598 ExtractReceivedVarAndAddRef(dispatcher(), &response));
602 void PPP_ContentDecryptor_Private_Proxy::OnMsgCloseSession(
603 PP_Instance instance,
604 uint32_t promise_id,
605 const std::string& session_id) {
606 if (ppp_decryptor_impl_) {
607 ScopedPPVar session_id_var(ScopedPPVar::PassRef(),
608 StringVar::StringToPPVar(session_id));
609 CallWhileUnlocked(ppp_decryptor_impl_->CloseSession, instance, promise_id,
610 session_id_var.get());
614 void PPP_ContentDecryptor_Private_Proxy::OnMsgRemoveSession(
615 PP_Instance instance,
616 uint32_t promise_id,
617 const std::string& session_id) {
618 if (ppp_decryptor_impl_) {
619 ScopedPPVar session_id_var(ScopedPPVar::PassRef(),
620 StringVar::StringToPPVar(session_id));
621 CallWhileUnlocked(ppp_decryptor_impl_->RemoveSession, instance, promise_id,
622 session_id_var.get());
626 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecrypt(
627 PP_Instance instance,
628 const PPPDecryptor_Buffer& encrypted_buffer,
629 const std::string& serialized_block_info) {
630 ScopedPPResource plugin_resource(
631 ScopedPPResource::PassRef(),
632 PPB_Buffer_Proxy::AddProxyResource(encrypted_buffer.resource,
633 encrypted_buffer.handle,
634 encrypted_buffer.size));
635 if (ppp_decryptor_impl_) {
636 PP_EncryptedBlockInfo block_info;
637 if (!DeserializeBlockInfo(serialized_block_info, &block_info))
638 return;
639 CallWhileUnlocked(ppp_decryptor_impl_->Decrypt,
640 instance,
641 plugin_resource.get(),
642 &block_info);
646 void PPP_ContentDecryptor_Private_Proxy::OnMsgInitializeAudioDecoder(
647 PP_Instance instance,
648 const std::string& serialized_decoder_config,
649 const PPPDecryptor_Buffer& extra_data_buffer) {
650 ScopedPPResource plugin_resource;
651 if (extra_data_buffer.size > 0) {
652 plugin_resource = ScopedPPResource(
653 ScopedPPResource::PassRef(),
654 PPB_Buffer_Proxy::AddProxyResource(extra_data_buffer.resource,
655 extra_data_buffer.handle,
656 extra_data_buffer.size));
659 PP_AudioDecoderConfig decoder_config;
660 if (!DeserializeBlockInfo(serialized_decoder_config, &decoder_config))
661 return;
663 if (ppp_decryptor_impl_) {
664 CallWhileUnlocked(
665 ppp_decryptor_impl_->InitializeAudioDecoder,
666 instance,
667 &decoder_config,
668 plugin_resource.get());
672 void PPP_ContentDecryptor_Private_Proxy::OnMsgInitializeVideoDecoder(
673 PP_Instance instance,
674 const std::string& serialized_decoder_config,
675 const PPPDecryptor_Buffer& extra_data_buffer) {
676 ScopedPPResource plugin_resource;
677 if (extra_data_buffer.resource.host_resource() != 0) {
678 plugin_resource = ScopedPPResource(
679 ScopedPPResource::PassRef(),
680 PPB_Buffer_Proxy::AddProxyResource(extra_data_buffer.resource,
681 extra_data_buffer.handle,
682 extra_data_buffer.size));
685 PP_VideoDecoderConfig decoder_config;
686 if (!DeserializeBlockInfo(serialized_decoder_config, &decoder_config))
687 return;
689 if (ppp_decryptor_impl_) {
690 CallWhileUnlocked(
691 ppp_decryptor_impl_->InitializeVideoDecoder,
692 instance,
693 &decoder_config,
694 plugin_resource.get());
698 void PPP_ContentDecryptor_Private_Proxy::OnMsgDeinitializeDecoder(
699 PP_Instance instance,
700 PP_DecryptorStreamType decoder_type,
701 uint32_t request_id) {
702 if (ppp_decryptor_impl_) {
703 CallWhileUnlocked(
704 ppp_decryptor_impl_->DeinitializeDecoder,
705 instance,
706 decoder_type,
707 request_id);
711 void PPP_ContentDecryptor_Private_Proxy::OnMsgResetDecoder(
712 PP_Instance instance,
713 PP_DecryptorStreamType decoder_type,
714 uint32_t request_id) {
715 if (ppp_decryptor_impl_) {
716 CallWhileUnlocked(
717 ppp_decryptor_impl_->ResetDecoder,
718 instance,
719 decoder_type,
720 request_id);
724 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecryptAndDecode(
725 PP_Instance instance,
726 PP_DecryptorStreamType decoder_type,
727 const PPPDecryptor_Buffer& encrypted_buffer,
728 const std::string& serialized_block_info) {
729 ScopedPPResource plugin_resource;
730 if (encrypted_buffer.resource.host_resource() != 0) {
731 plugin_resource = ScopedPPResource(
732 ScopedPPResource::PassRef(),
733 PPB_Buffer_Proxy::AddProxyResource(encrypted_buffer.resource,
734 encrypted_buffer.handle,
735 encrypted_buffer.size));
738 if (ppp_decryptor_impl_) {
739 PP_EncryptedBlockInfo block_info;
740 if (!DeserializeBlockInfo(serialized_block_info, &block_info))
741 return;
742 CallWhileUnlocked(
743 ppp_decryptor_impl_->DecryptAndDecode,
744 instance,
745 decoder_type,
746 plugin_resource.get(),
747 &block_info);
751 } // namespace proxy
752 } // namespace ppapi