flash_drm_resource.cc revision f2477e01787aa58f445919b809d89e252beef54f
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/file_ref_resource.h"
11#include "ppapi/proxy/ppapi_messages.h"
12#include "ppapi/shared_impl/var.h"
13
14namespace ppapi {
15namespace proxy {
16
17FlashDRMResource::FlashDRMResource(Connection connection,
18                                   PP_Instance instance)
19    : PluginResource(connection, instance) {
20  SendCreate(BROWSER, PpapiHostMsg_FlashDRM_Create());
21  SendCreate(RENDERER, PpapiHostMsg_FlashDRM_Create());
22}
23
24FlashDRMResource::~FlashDRMResource() {
25}
26
27thunk::PPB_Flash_DRM_API* FlashDRMResource::AsPPB_Flash_DRM_API() {
28  return this;
29}
30
31int32_t FlashDRMResource::GetDeviceID(PP_Var* id,
32                                      scoped_refptr<TrackedCallback> callback) {
33  if (!id)
34    return PP_ERROR_BADARGUMENT;
35
36  *id = PP_MakeUndefined();
37
38  Call<PpapiPluginMsg_FlashDRM_GetDeviceIDReply>(
39      BROWSER,
40      PpapiHostMsg_FlashDRM_GetDeviceID(),
41      base::Bind(&FlashDRMResource::OnPluginMsgGetDeviceIDReply, this,
42      id, callback));
43  return PP_OK_COMPLETIONPENDING;
44}
45
46PP_Bool FlashDRMResource::GetHmonitor(int64_t* hmonitor) {
47  int64_t hmonitor_out;
48  int32_t result = SyncCall<PpapiPluginMsg_FlashDRM_GetHmonitorReply>(
49      BROWSER,
50      PpapiHostMsg_FlashDRM_GetHmonitor(),
51      &hmonitor_out);
52  if (result != PP_OK)
53    return PP_FALSE;
54  *hmonitor = hmonitor_out;
55  return PP_TRUE;
56}
57
58int32_t FlashDRMResource::GetVoucherFile(
59    PP_Resource* file_ref,
60    scoped_refptr<TrackedCallback> callback) {
61  if (!file_ref)
62    return PP_ERROR_BADARGUMENT;
63
64  *file_ref = 0;
65
66  Call<PpapiPluginMsg_FlashDRM_GetVoucherFileReply>(
67      RENDERER,
68      PpapiHostMsg_FlashDRM_GetVoucherFile(),
69      base::Bind(&FlashDRMResource::OnPluginMsgGetVoucherFileReply, this,
70      file_ref, callback));
71  return PP_OK_COMPLETIONPENDING;
72}
73
74int32_t FlashDRMResource::MonitorIsExternal(
75    PP_Bool* is_external,
76    scoped_refptr<TrackedCallback> callback) {
77  if (!is_external)
78    return PP_ERROR_BADARGUMENT;
79
80  *is_external = PP_FALSE;
81
82  Call<PpapiPluginMsg_FlashDRM_MonitorIsExternalReply>(
83      BROWSER,
84      PpapiHostMsg_FlashDRM_MonitorIsExternal(),
85      base::Bind(&FlashDRMResource::OnPluginMsgMonitorIsExternalReply, this,
86                 is_external, callback));
87  return PP_OK_COMPLETIONPENDING;
88}
89
90void FlashDRMResource::OnPluginMsgGetDeviceIDReply(
91    PP_Var* dest,
92    scoped_refptr<TrackedCallback> callback,
93    const ResourceMessageReplyParams& params,
94    const std::string& id) {
95  if (TrackedCallback::IsPending(callback)) {
96    if (params.result() == PP_OK)
97      *dest = StringVar::StringToPPVar(id);
98    callback->Run(params.result());
99  }
100}
101
102void FlashDRMResource::OnPluginMsgGetVoucherFileReply(
103    PP_Resource* dest,
104    scoped_refptr<TrackedCallback> callback,
105    const ResourceMessageReplyParams& params,
106    const FileRefCreateInfo& file_info) {
107  if (TrackedCallback::IsPending(callback)) {
108    if (params.result() == PP_OK) {
109      *dest = FileRefResource::CreateFileRef(
110          connection(),
111          pp_instance(),
112          file_info);
113    }
114    callback->Run(params.result());
115  }
116}
117
118void FlashDRMResource::OnPluginMsgMonitorIsExternalReply(
119    PP_Bool* dest,
120    scoped_refptr<TrackedCallback> callback,
121    const ResourceMessageReplyParams& params,
122    PP_Bool is_external) {
123  if (TrackedCallback::IsPending(callback)) {
124    if (params.result() == PP_OK)
125      *dest = is_external;
126    callback->Run(params.result());
127  }
128}
129
130}  // namespace proxy
131}  // namespace ppapi
132