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

Side by Side Diff: ppapi/proxy/ppp_content_decryptor_private_proxy.cc

Issue 496143002: Update Pepper interface for EME (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cdm_promise rebase Created 6 years, 3 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
OLDNEW
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/proxy/ppp_content_decryptor_private_proxy.h" 5 #include "ppapi/proxy/ppp_content_decryptor_private_proxy.h"
6 6
7 #include "base/files/file.h" 7 #include "base/files/file.h"
8 #include "media/base/limits.h"
8 #include "ppapi/c/pp_bool.h" 9 #include "ppapi/c/pp_bool.h"
9 #include "ppapi/c/ppb_core.h" 10 #include "ppapi/c/ppb_core.h"
10 #include "ppapi/proxy/content_decryptor_private_serializer.h" 11 #include "ppapi/proxy/content_decryptor_private_serializer.h"
11 #include "ppapi/proxy/host_dispatcher.h" 12 #include "ppapi/proxy/host_dispatcher.h"
12 #include "ppapi/proxy/plugin_globals.h" 13 #include "ppapi/proxy/plugin_globals.h"
13 #include "ppapi/proxy/plugin_resource_tracker.h" 14 #include "ppapi/proxy/plugin_resource_tracker.h"
14 #include "ppapi/proxy/ppapi_messages.h" 15 #include "ppapi/proxy/ppapi_messages.h"
15 #include "ppapi/proxy/ppb_buffer_proxy.h" 16 #include "ppapi/proxy/ppb_buffer_proxy.h"
16 #include "ppapi/proxy/serialized_var.h" 17 #include "ppapi/proxy/serialized_var.h"
17 #include "ppapi/shared_impl/scoped_pp_resource.h" 18 #include "ppapi/shared_impl/scoped_pp_resource.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 return; 118 return;
118 } 119 }
119 120
120 dispatcher->Send( 121 dispatcher->Send(
121 new PpapiMsg_PPPContentDecryptor_Initialize( 122 new PpapiMsg_PPPContentDecryptor_Initialize(
122 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, 123 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
123 instance, 124 instance,
124 SerializedVarSendInput(dispatcher, key_system))); 125 SerializedVarSendInput(dispatcher, key_system)));
125 } 126 }
126 127
128 void SetServerCertificate(PP_Instance instance,
129 uint32_t promise_id,
130 PP_Var server_certificate) {
131 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
132 if (!dispatcher) {
133 NOTREACHED();
134 return;
135 }
136
137 ArrayBufferVar* server_certificate_buffer =
138 ArrayBufferVar::FromPPVar(server_certificate);
139 if (!server_certificate_buffer ||
140 server_certificate_buffer->ByteLength() <
141 media::limits::kMinCertificateLength ||
142 server_certificate_buffer->ByteLength() >
143 media::limits::kMaxCertificateLength) {
144 NOTREACHED();
145 return;
146 }
147
148 const uint8_t* server_certificate_ptr =
149 static_cast<const uint8_t*>(server_certificate_buffer->Map());
150 const uint32_t server_certificate_size =
151 server_certificate_buffer->ByteLength();
152 std::vector<uint8_t> server_certificate_vector(
153 server_certificate_ptr, server_certificate_ptr + server_certificate_size);
154
155 dispatcher->Send(new PpapiMsg_PPPContentDecryptor_SetServerCertificate(
156 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
157 instance,
158 promise_id,
159 server_certificate_vector));
160 }
161
127 void CreateSession(PP_Instance instance, 162 void CreateSession(PP_Instance instance,
128 uint32_t promise_id, 163 uint32_t promise_id,
129 PP_Var init_data_type, 164 PP_Var init_data_type,
130 PP_Var init_data, 165 PP_Var init_data,
131 PP_SessionType session_type) { 166 PP_SessionType session_type) {
132 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); 167 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
133 if (!dispatcher) { 168 if (!dispatcher) {
134 NOTREACHED(); 169 NOTREACHED();
135 return; 170 return;
136 } 171 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 } 206 }
172 207
173 dispatcher->Send(new PpapiMsg_PPPContentDecryptor_UpdateSession( 208 dispatcher->Send(new PpapiMsg_PPPContentDecryptor_UpdateSession(
174 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, 209 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
175 instance, 210 instance,
176 promise_id, 211 promise_id,
177 SerializedVarSendInput(dispatcher, web_session_id), 212 SerializedVarSendInput(dispatcher, web_session_id),
178 SerializedVarSendInput(dispatcher, response))); 213 SerializedVarSendInput(dispatcher, response)));
179 } 214 }
180 215
181 void ReleaseSession(PP_Instance instance, 216 void CloseSession(PP_Instance instance,
182 uint32_t promise_id, 217 uint32_t promise_id,
183 PP_Var web_session_id) { 218 PP_Var web_session_id) {
184 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); 219 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
185 if (!dispatcher) { 220 if (!dispatcher) {
186 NOTREACHED(); 221 NOTREACHED();
187 return; 222 return;
188 } 223 }
189 224
190 dispatcher->Send(new PpapiMsg_PPPContentDecryptor_ReleaseSession( 225 StringVar* session_id = StringVar::FromPPVar(web_session_id);
226 if (!session_id ||
227 session_id->value().length() > media::limits::kMaxWebSessionIdLength) {
228 NOTREACHED();
229 return;
230 }
231
232 dispatcher->Send(new PpapiMsg_PPPContentDecryptor_CloseSession(
191 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, 233 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
192 instance, 234 instance,
193 promise_id, 235 promise_id,
194 SerializedVarSendInput(dispatcher, web_session_id))); 236 session_id->value()));
237 }
238
239 void RemoveSession(PP_Instance instance,
240 uint32_t promise_id,
241 PP_Var web_session_id) {
242 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
243 if (!dispatcher) {
244 NOTREACHED();
245 return;
246 }
247
248 StringVar* session_id = StringVar::FromPPVar(web_session_id);
249 if (!session_id ||
250 session_id->value().length() > media::limits::kMaxWebSessionIdLength) {
251 NOTREACHED();
252 return;
253 }
254
255 dispatcher->Send(new PpapiMsg_PPPContentDecryptor_RemoveSession(
256 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
257 instance,
258 promise_id,
259 session_id->value()));
260 }
261
262 void GetUsableKeyIds(PP_Instance instance,
263 uint32_t promise_id,
264 PP_Var web_session_id) {
265 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
266 if (!dispatcher) {
267 NOTREACHED();
268 return;
269 }
270
271 StringVar* session_id = StringVar::FromPPVar(web_session_id);
272 if (!session_id ||
273 session_id->value().length() > media::limits::kMaxWebSessionIdLength) {
274 NOTREACHED();
275 return;
276 }
277
278 dispatcher->Send(new PpapiMsg_PPPContentDecryptor_GetUsableKeyIds(
279 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
280 instance,
281 promise_id,
282 session_id->value()));
195 } 283 }
196 284
197 void Decrypt(PP_Instance instance, 285 void Decrypt(PP_Instance instance,
198 PP_Resource encrypted_block, 286 PP_Resource encrypted_block,
199 const PP_EncryptedBlockInfo* encrypted_block_info) { 287 const PP_EncryptedBlockInfo* encrypted_block_info) {
200 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); 288 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
201 if (!dispatcher) { 289 if (!dispatcher) {
202 NOTREACHED(); 290 NOTREACHED();
203 return; 291 return;
204 } 292 }
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 dispatcher->Send( 463 dispatcher->Send(
376 new PpapiMsg_PPPContentDecryptor_DecryptAndDecode( 464 new PpapiMsg_PPPContentDecryptor_DecryptAndDecode(
377 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, 465 API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE,
378 instance, 466 instance,
379 decoder_type, 467 decoder_type,
380 buffer, 468 buffer,
381 serialized_block_info)); 469 serialized_block_info));
382 } 470 }
383 471
384 static const PPP_ContentDecryptor_Private content_decryptor_interface = { 472 static const PPP_ContentDecryptor_Private content_decryptor_interface = {
385 &Initialize, 473 &Initialize,
386 &CreateSession, 474 &SetServerCertificate,
387 &LoadSession, 475 &CreateSession,
388 &UpdateSession, 476 &LoadSession,
389 &ReleaseSession, 477 &UpdateSession,
390 &Decrypt, 478 &CloseSession,
391 &InitializeAudioDecoder, 479 &RemoveSession,
392 &InitializeVideoDecoder, 480 &GetUsableKeyIds,
393 &DeinitializeDecoder, 481 &Decrypt,
394 &ResetDecoder, 482 &InitializeAudioDecoder,
395 &DecryptAndDecode 483 &InitializeVideoDecoder,
396 }; 484 &DeinitializeDecoder,
485 &ResetDecoder,
486 &DecryptAndDecode};
397 487
398 } // namespace 488 } // namespace
399 489
400 PPP_ContentDecryptor_Private_Proxy::PPP_ContentDecryptor_Private_Proxy( 490 PPP_ContentDecryptor_Private_Proxy::PPP_ContentDecryptor_Private_Proxy(
401 Dispatcher* dispatcher) 491 Dispatcher* dispatcher)
402 : InterfaceProxy(dispatcher), 492 : InterfaceProxy(dispatcher),
403 ppp_decryptor_impl_(NULL) { 493 ppp_decryptor_impl_(NULL) {
404 if (dispatcher->IsPlugin()) { 494 if (dispatcher->IsPlugin()) {
405 ppp_decryptor_impl_ = static_cast<const PPP_ContentDecryptor_Private*>( 495 ppp_decryptor_impl_ = static_cast<const PPP_ContentDecryptor_Private*>(
406 dispatcher->local_get_interface()( 496 dispatcher->local_get_interface()(
(...skipping 13 matching lines...) Expand all
420 bool PPP_ContentDecryptor_Private_Proxy::OnMessageReceived( 510 bool PPP_ContentDecryptor_Private_Proxy::OnMessageReceived(
421 const IPC::Message& msg) { 511 const IPC::Message& msg) {
422 if (!dispatcher()->IsPlugin()) 512 if (!dispatcher()->IsPlugin())
423 return false; // These are only valid from host->plugin. 513 return false; // These are only valid from host->plugin.
424 // Don't allow the plugin to send these to the host. 514 // Don't allow the plugin to send these to the host.
425 515
426 bool handled = true; 516 bool handled = true;
427 IPC_BEGIN_MESSAGE_MAP(PPP_ContentDecryptor_Private_Proxy, msg) 517 IPC_BEGIN_MESSAGE_MAP(PPP_ContentDecryptor_Private_Proxy, msg)
428 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_Initialize, 518 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_Initialize,
429 OnMsgInitialize) 519 OnMsgInitialize)
520 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_SetServerCertificate,
521 OnMsgSetServerCertificate)
430 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_CreateSession, 522 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_CreateSession,
431 OnMsgCreateSession) 523 OnMsgCreateSession)
432 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_LoadSession, 524 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_LoadSession,
433 OnMsgLoadSession) 525 OnMsgLoadSession)
434 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_UpdateSession, 526 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_UpdateSession,
435 OnMsgUpdateSession) 527 OnMsgUpdateSession)
436 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_ReleaseSession, 528 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_CloseSession,
437 OnMsgReleaseSession) 529 OnMsgCloseSession)
530 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_RemoveSession,
531 OnMsgRemoveSession)
532 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_GetUsableKeyIds,
533 OnMsgGetUsableKeyIds)
438 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_Decrypt, 534 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_Decrypt,
439 OnMsgDecrypt) 535 OnMsgDecrypt)
440 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_InitializeAudioDecoder, 536 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_InitializeAudioDecoder,
441 OnMsgInitializeAudioDecoder) 537 OnMsgInitializeAudioDecoder)
442 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_InitializeVideoDecoder, 538 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_InitializeVideoDecoder,
443 OnMsgInitializeVideoDecoder) 539 OnMsgInitializeVideoDecoder)
444 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_DeinitializeDecoder, 540 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_DeinitializeDecoder,
445 OnMsgDeinitializeDecoder) 541 OnMsgDeinitializeDecoder)
446 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_ResetDecoder, 542 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_ResetDecoder,
447 OnMsgResetDecoder) 543 OnMsgResetDecoder)
448 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_DecryptAndDecode, 544 IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_DecryptAndDecode,
449 OnMsgDecryptAndDecode) 545 OnMsgDecryptAndDecode)
450 IPC_MESSAGE_UNHANDLED(handled = false) 546 IPC_MESSAGE_UNHANDLED(handled = false)
451 IPC_END_MESSAGE_MAP() 547 IPC_END_MESSAGE_MAP()
452 DCHECK(handled); 548 DCHECK(handled);
453 return handled; 549 return handled;
454 } 550 }
455 551
456 void PPP_ContentDecryptor_Private_Proxy::OnMsgInitialize( 552 void PPP_ContentDecryptor_Private_Proxy::OnMsgInitialize(
457 PP_Instance instance, 553 PP_Instance instance,
458 SerializedVarReceiveInput key_system) { 554 SerializedVarReceiveInput key_system) {
459 if (ppp_decryptor_impl_) { 555 if (ppp_decryptor_impl_) {
460 CallWhileUnlocked( 556 CallWhileUnlocked(
461 ppp_decryptor_impl_->Initialize, 557 ppp_decryptor_impl_->Initialize,
462 instance, 558 instance,
463 ExtractReceivedVarAndAddRef(dispatcher(), &key_system)); 559 ExtractReceivedVarAndAddRef(dispatcher(), &key_system));
464 } 560 }
465 } 561 }
466 562
563 void PPP_ContentDecryptor_Private_Proxy::OnMsgSetServerCertificate(
564 PP_Instance instance,
565 uint32_t promise_id,
566 std::vector<uint8_t> server_certificate) {
567 if (server_certificate.size() < media::limits::kMinCertificateLength ||
568 server_certificate.size() > media::limits::kMaxCertificateLength) {
569 NOTREACHED();
570 return;
571 }
572
573 if (ppp_decryptor_impl_) {
574 PP_Var server_certificate_buffer =
575 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(
576 server_certificate.size(), server_certificate.data());
dmichael (off chromium) 2014/09/04 21:17:11 Same problem as the PPB_Instance proxy; you never
jrummell 2014/09/04 23:05:03 Done.
577 CallWhileUnlocked(ppp_decryptor_impl_->SetServerCertificate,
578 instance,
579 promise_id,
580 server_certificate_buffer);
581 }
582 }
583
467 void PPP_ContentDecryptor_Private_Proxy::OnMsgCreateSession( 584 void PPP_ContentDecryptor_Private_Proxy::OnMsgCreateSession(
468 PP_Instance instance, 585 PP_Instance instance,
469 uint32_t promise_id, 586 uint32_t promise_id,
470 SerializedVarReceiveInput init_data_type, 587 SerializedVarReceiveInput init_data_type,
471 SerializedVarReceiveInput init_data, 588 SerializedVarReceiveInput init_data,
472 PP_SessionType session_type) { 589 PP_SessionType session_type) {
473 if (ppp_decryptor_impl_) { 590 if (ppp_decryptor_impl_) {
474 CallWhileUnlocked( 591 CallWhileUnlocked(
475 ppp_decryptor_impl_->CreateSession, 592 ppp_decryptor_impl_->CreateSession,
476 instance, 593 instance,
(...skipping 25 matching lines...) Expand all
502 if (ppp_decryptor_impl_) { 619 if (ppp_decryptor_impl_) {
503 CallWhileUnlocked( 620 CallWhileUnlocked(
504 ppp_decryptor_impl_->UpdateSession, 621 ppp_decryptor_impl_->UpdateSession,
505 instance, 622 instance,
506 promise_id, 623 promise_id,
507 ExtractReceivedVarAndAddRef(dispatcher(), &web_session_id), 624 ExtractReceivedVarAndAddRef(dispatcher(), &web_session_id),
508 ExtractReceivedVarAndAddRef(dispatcher(), &response)); 625 ExtractReceivedVarAndAddRef(dispatcher(), &response));
509 } 626 }
510 } 627 }
511 628
512 void PPP_ContentDecryptor_Private_Proxy::OnMsgReleaseSession( 629 void PPP_ContentDecryptor_Private_Proxy::OnMsgCloseSession(
513 PP_Instance instance, 630 PP_Instance instance,
514 uint32_t promise_id, 631 uint32_t promise_id,
515 SerializedVarReceiveInput web_session_id) { 632 const std::string& web_session_id) {
516 if (ppp_decryptor_impl_) { 633 if (ppp_decryptor_impl_) {
517 CallWhileUnlocked( 634 CallWhileUnlocked(ppp_decryptor_impl_->CloseSession,
518 ppp_decryptor_impl_->ReleaseSession, 635 instance,
519 instance, 636 promise_id,
520 promise_id, 637 StringVar::StringToPPVar(web_session_id));
dmichael (off chromium) 2014/09/04 21:17:11 ditto
jrummell 2014/09/04 23:05:03 Done.
521 ExtractReceivedVarAndAddRef(dispatcher(), &web_session_id));
522 } 638 }
523 } 639 }
524 640
641 void PPP_ContentDecryptor_Private_Proxy::OnMsgRemoveSession(
642 PP_Instance instance,
643 uint32_t promise_id,
644 const std::string& web_session_id) {
645 if (ppp_decryptor_impl_) {
646 CallWhileUnlocked(ppp_decryptor_impl_->RemoveSession,
647 instance,
648 promise_id,
649 StringVar::StringToPPVar(web_session_id));
dmichael (off chromium) 2014/09/04 21:17:11 ditto
jrummell 2014/09/04 23:05:03 Done.
650 }
651 }
652
653 void PPP_ContentDecryptor_Private_Proxy::OnMsgGetUsableKeyIds(
654 PP_Instance instance,
655 uint32_t promise_id,
656 const std::string& web_session_id) {
657 if (ppp_decryptor_impl_) {
658 CallWhileUnlocked(ppp_decryptor_impl_->GetUsableKeyIds,
659 instance,
660 promise_id,
661 StringVar::StringToPPVar(web_session_id));
dmichael (off chromium) 2014/09/04 21:17:11 ditto
jrummell 2014/09/04 23:05:03 Done.
662 }
663 }
664
525 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecrypt( 665 void PPP_ContentDecryptor_Private_Proxy::OnMsgDecrypt(
526 PP_Instance instance, 666 PP_Instance instance,
527 const PPPDecryptor_Buffer& encrypted_buffer, 667 const PPPDecryptor_Buffer& encrypted_buffer,
528 const std::string& serialized_block_info) { 668 const std::string& serialized_block_info) {
529 ScopedPPResource plugin_resource( 669 ScopedPPResource plugin_resource(
530 ScopedPPResource::PassRef(), 670 ScopedPPResource::PassRef(),
531 PPB_Buffer_Proxy::AddProxyResource(encrypted_buffer.resource, 671 PPB_Buffer_Proxy::AddProxyResource(encrypted_buffer.resource,
532 encrypted_buffer.handle, 672 encrypted_buffer.handle,
533 encrypted_buffer.size)); 673 encrypted_buffer.size));
534 if (ppp_decryptor_impl_) { 674 if (ppp_decryptor_impl_) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 ppp_decryptor_impl_->DecryptAndDecode, 782 ppp_decryptor_impl_->DecryptAndDecode,
643 instance, 783 instance,
644 decoder_type, 784 decoder_type,
645 plugin_resource.get(), 785 plugin_resource.get(),
646 const_cast<const PP_EncryptedBlockInfo*>(&block_info)); 786 const_cast<const PP_EncryptedBlockInfo*>(&block_info));
647 } 787 }
648 } 788 }
649 789
650 } // namespace proxy 790 } // namespace proxy
651 } // namespace ppapi 791 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698