1 // Copyright 2013 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/output_protection_resource.h"
7 #include "base/logging.h"
8 #include "ppapi/proxy/plugin_globals.h"
9 #include "ppapi/proxy/plugin_resource_tracker.h"
10 #include "ppapi/proxy/ppapi_messages.h"
11 #include "ppapi/shared_impl/proxy_lock.h"
12 #include "ppapi/shared_impl/resource_tracker.h"
13 #include "ppapi/shared_impl/tracked_callback.h"
14 #include "ppapi/thunk/enter.h"
15 #include "ppapi/thunk/ppb_output_protection_api.h"
20 OutputProtectionResource::OutputProtectionResource(
21 Connection connection
,
23 : PluginResource(connection
, instance
) {
24 SendCreate(BROWSER
, PpapiHostMsg_OutputProtection_Create());
27 OutputProtectionResource::~OutputProtectionResource() {
28 if (TrackedCallback::IsPending(query_status_callback_
))
29 query_status_callback_
->PostAbort();
30 if (TrackedCallback::IsPending(enable_protection_callback_
))
31 enable_protection_callback_
->PostAbort();
34 thunk::PPB_OutputProtection_API
*
35 OutputProtectionResource::AsPPB_OutputProtection_API() {
39 int32_t OutputProtectionResource::QueryStatus(
41 uint32_t* protection_mask
,
42 const scoped_refptr
<TrackedCallback
>& callback
) {
43 if (!link_mask
|| !protection_mask
)
44 return PP_ERROR_BADARGUMENT
;
45 if (TrackedCallback::IsPending(query_status_callback_
))
46 return PP_ERROR_INPROGRESS
;
48 query_status_callback_
= callback
;
50 Call
<PpapiPluginMsg_OutputProtection_QueryStatusReply
>(
52 PpapiHostMsg_OutputProtection_QueryStatus(),
53 base::Bind(&OutputProtectionResource::OnPluginMsgQueryStatusReply
,
54 base::Unretained(this),
57 return PP_OK_COMPLETIONPENDING
;
60 void OutputProtectionResource::OnPluginMsgQueryStatusReply(
61 uint32_t* out_link_mask
,
62 uint32_t* out_protection_mask
,
63 const ResourceMessageReplyParams
& params
,
65 uint32_t protection_mask
) {
66 // The callback may have been aborted.
67 if (!TrackedCallback::IsPending(query_status_callback_
))
70 int32_t result
= params
.result();
72 if (result
== PP_OK
) {
73 DCHECK(out_link_mask
);
74 DCHECK(out_protection_mask
);
75 *out_link_mask
= link_mask
;
76 *out_protection_mask
= protection_mask
;
78 query_status_callback_
->Run(result
);
81 int32_t OutputProtectionResource::EnableProtection(
82 uint32_t desired_method_mask
,
83 const scoped_refptr
<TrackedCallback
>& callback
) {
84 if (TrackedCallback::IsPending(enable_protection_callback_
))
85 return PP_ERROR_INPROGRESS
;
87 enable_protection_callback_
= callback
;
89 Call
<PpapiPluginMsg_OutputProtection_EnableProtectionReply
>(
91 PpapiHostMsg_OutputProtection_EnableProtection(desired_method_mask
),
92 base::Bind(&OutputProtectionResource::OnPluginMsgEnableProtectionReply
,
93 base::Unretained(this)));
94 return PP_OK_COMPLETIONPENDING
;
97 void OutputProtectionResource::OnPluginMsgEnableProtectionReply(
98 const ResourceMessageReplyParams
& params
) {
99 // The callback may have been aborted.
100 if (TrackedCallback::IsPending(enable_protection_callback_
))
101 enable_protection_callback_
->Run(params
.result());