flash_drm_resource.cc revision f2477e01787aa58f445919b809d89e252beef54f
190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// found in the LICENSE file. 490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ppapi/proxy/flash_drm_resource.h" 690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "base/bind.h" 890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ppapi/c/pp_errors.h" 990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ppapi/proxy/dispatch_reply_message.h" 10d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ppapi/proxy/file_ref_resource.h" 1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ppapi/proxy/ppapi_messages.h" 1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ppapi/shared_impl/var.h" 1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace ppapi { 1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace proxy { 1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)FlashDRMResource::FlashDRMResource(Connection connection, 1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) PP_Instance instance) 1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) : PluginResource(connection, instance) { 2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SendCreate(BROWSER, PpapiHostMsg_FlashDRM_Create()); 217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) SendCreate(RENDERER, PpapiHostMsg_FlashDRM_Create()); 2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)FlashDRMResource::~FlashDRMResource() { 2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)thunk::PPB_Flash_DRM_API* FlashDRMResource::AsPPB_Flash_DRM_API() { 2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return this; 2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)int32_t FlashDRMResource::GetDeviceID(PP_Var* id, 3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_refptr<TrackedCallback> callback) { 3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (!id) 3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return PP_ERROR_BADARGUMENT; 3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) *id = PP_MakeUndefined(); 3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) Call<PpapiPluginMsg_FlashDRM_GetDeviceIDReply>( 3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) BROWSER, 4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) PpapiHostMsg_FlashDRM_GetDeviceID(), 4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::Bind(&FlashDRMResource::OnPluginMsgGetDeviceIDReply, this, 4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) id, callback)); 4390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return PP_OK_COMPLETIONPENDING; 4490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)PP_Bool FlashDRMResource::GetHmonitor(int64_t* hmonitor) { 477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) int64_t hmonitor_out; 487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) int32_t result = SyncCall<PpapiPluginMsg_FlashDRM_GetHmonitorReply>( 497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) BROWSER, 507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) PpapiHostMsg_FlashDRM_GetHmonitor(), 517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) &hmonitor_out); 527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (result != PP_OK) 537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return PP_FALSE; 547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) *hmonitor = hmonitor_out; 557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return PP_TRUE; 567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)int32_t FlashDRMResource::GetVoucherFile( 597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) PP_Resource* file_ref, 607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) scoped_refptr<TrackedCallback> callback) { 617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (!file_ref) 627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return PP_ERROR_BADARGUMENT; 637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) *file_ref = 0; 657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) Call<PpapiPluginMsg_FlashDRM_GetVoucherFileReply>( 677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) RENDERER, 687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) PpapiHostMsg_FlashDRM_GetVoucherFile(), 697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::Bind(&FlashDRMResource::OnPluginMsgGetVoucherFileReply, this, 707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) file_ref, callback)); 717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return PP_OK_COMPLETIONPENDING; 727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 74f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)int32_t FlashDRMResource::MonitorIsExternal( 75f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) PP_Bool* is_external, 76f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) scoped_refptr<TrackedCallback> callback) { 77f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (!is_external) 78f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return PP_ERROR_BADARGUMENT; 79f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 80f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) *is_external = PP_FALSE; 81f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 82f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) Call<PpapiPluginMsg_FlashDRM_MonitorIsExternalReply>( 83f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) BROWSER, 84f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) PpapiHostMsg_FlashDRM_MonitorIsExternal(), 85f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) base::Bind(&FlashDRMResource::OnPluginMsgMonitorIsExternalReply, this, 86f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) is_external, callback)); 87f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return PP_OK_COMPLETIONPENDING; 88f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 89f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 9090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void FlashDRMResource::OnPluginMsgGetDeviceIDReply( 9190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) PP_Var* dest, 9290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_refptr<TrackedCallback> callback, 9390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const ResourceMessageReplyParams& params, 9490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const std::string& id) { 9590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (TrackedCallback::IsPending(callback)) { 9690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (params.result() == PP_OK) 9790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) *dest = StringVar::StringToPPVar(id); 9890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) callback->Run(params.result()); 9990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 10090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 10190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void FlashDRMResource::OnPluginMsgGetVoucherFileReply( 1037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) PP_Resource* dest, 1047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) scoped_refptr<TrackedCallback> callback, 1057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const ResourceMessageReplyParams& params, 106d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const FileRefCreateInfo& file_info) { 1077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (TrackedCallback::IsPending(callback)) { 108d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) if (params.result() == PP_OK) { 109d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) *dest = FileRefResource::CreateFileRef( 110d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) connection(), 111d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) pp_instance(), 112d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) file_info); 113d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) } 1147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) callback->Run(params.result()); 1157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 1167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 1177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 118f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void FlashDRMResource::OnPluginMsgMonitorIsExternalReply( 119f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) PP_Bool* dest, 120f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) scoped_refptr<TrackedCallback> callback, 121f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const ResourceMessageReplyParams& params, 122f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) PP_Bool is_external) { 123f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (TrackedCallback::IsPending(callback)) { 124f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (params.result() == PP_OK) 125f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) *dest = is_external; 126f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) callback->Run(params.result()); 127f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 128f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 129f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 13090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // namespace proxy 13190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // namespace ppapi 132