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/proxy/flash_drm_resource.h" 6 7#include "base/bind.h" 8#include "ppapi/c/pp_errors.h" 9#include "ppapi/proxy/dispatch_reply_message.h" 10#include "ppapi/proxy/ppapi_messages.h" 11#include "ppapi/proxy/ppb_file_ref_proxy.h" 12#include "ppapi/shared_impl/ppb_file_ref_shared.h" 13#include "ppapi/shared_impl/var.h" 14 15namespace ppapi { 16namespace proxy { 17 18FlashDRMResource::FlashDRMResource(Connection connection, 19 PP_Instance instance) 20 : PluginResource(connection, instance) { 21 SendCreate(BROWSER, PpapiHostMsg_FlashDRM_Create()); 22 SendCreate(RENDERER, PpapiHostMsg_FlashDRM_Create()); 23} 24 25FlashDRMResource::~FlashDRMResource() { 26} 27 28thunk::PPB_Flash_DRM_API* FlashDRMResource::AsPPB_Flash_DRM_API() { 29 return this; 30} 31 32int32_t FlashDRMResource::GetDeviceID(PP_Var* id, 33 scoped_refptr<TrackedCallback> callback) { 34 if (!id) 35 return PP_ERROR_BADARGUMENT; 36 37 *id = PP_MakeUndefined(); 38 39 Call<PpapiPluginMsg_FlashDRM_GetDeviceIDReply>( 40 BROWSER, 41 PpapiHostMsg_FlashDRM_GetDeviceID(), 42 base::Bind(&FlashDRMResource::OnPluginMsgGetDeviceIDReply, this, 43 id, callback)); 44 return PP_OK_COMPLETIONPENDING; 45} 46 47PP_Bool FlashDRMResource::GetHmonitor(int64_t* hmonitor) { 48 int64_t hmonitor_out; 49 int32_t result = SyncCall<PpapiPluginMsg_FlashDRM_GetHmonitorReply>( 50 BROWSER, 51 PpapiHostMsg_FlashDRM_GetHmonitor(), 52 &hmonitor_out); 53 if (result != PP_OK) 54 return PP_FALSE; 55 *hmonitor = hmonitor_out; 56 return PP_TRUE; 57} 58 59int32_t FlashDRMResource::GetVoucherFile( 60 PP_Resource* file_ref, 61 scoped_refptr<TrackedCallback> callback) { 62 if (!file_ref) 63 return PP_ERROR_BADARGUMENT; 64 65 *file_ref = 0; 66 67 Call<PpapiPluginMsg_FlashDRM_GetVoucherFileReply>( 68 RENDERER, 69 PpapiHostMsg_FlashDRM_GetVoucherFile(), 70 base::Bind(&FlashDRMResource::OnPluginMsgGetVoucherFileReply, this, 71 file_ref, callback)); 72 return PP_OK_COMPLETIONPENDING; 73} 74 75void FlashDRMResource::OnPluginMsgGetDeviceIDReply( 76 PP_Var* dest, 77 scoped_refptr<TrackedCallback> callback, 78 const ResourceMessageReplyParams& params, 79 const std::string& id) { 80 if (TrackedCallback::IsPending(callback)) { 81 if (params.result() == PP_OK) 82 *dest = StringVar::StringToPPVar(id); 83 callback->Run(params.result()); 84 } 85} 86 87void FlashDRMResource::OnPluginMsgGetVoucherFileReply( 88 PP_Resource* dest, 89 scoped_refptr<TrackedCallback> callback, 90 const ResourceMessageReplyParams& params, 91 const PPB_FileRef_CreateInfo& file_info) { 92 if (TrackedCallback::IsPending(callback)) { 93 if (params.result() == PP_OK) 94 *dest = PPB_FileRef_Proxy::DeserializeFileRef(file_info); 95 callback->Run(params.result()); 96 } 97} 98 99} // namespace proxy 100} // namespace ppapi 101