OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "ppapi/proxy/output_protection_resource.h" |
| 6 |
| 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" |
| 16 |
| 17 namespace ppapi { |
| 18 namespace proxy { |
| 19 |
| 20 OutputProtectionResource::OutputProtectionResource( |
| 21 Connection connection, |
| 22 PP_Instance instance) |
| 23 : PluginResource(connection, instance) { |
| 24 SendCreate(BROWSER, PpapiHostMsg_OutputProtection_Create()); |
| 25 } |
| 26 |
| 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(); |
| 32 } |
| 33 |
| 34 thunk::PPB_OutputProtection_API* |
| 35 OutputProtectionResource::AsPPB_OutputProtection_API() { |
| 36 return this; |
| 37 } |
| 38 |
| 39 int32_t OutputProtectionResource::QueryStatus( |
| 40 uint32_t* link_mask, |
| 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; |
| 47 |
| 48 query_status_callback_ = callback; |
| 49 |
| 50 Call<PpapiPluginMsg_OutputProtection_QueryStatusReply>( |
| 51 BROWSER, |
| 52 PpapiHostMsg_OutputProtection_QueryStatus(), |
| 53 base::Bind(&OutputProtectionResource::OnPluginMsgQueryStatusReply, |
| 54 base::Unretained(this), |
| 55 link_mask, |
| 56 protection_mask)); |
| 57 return PP_OK_COMPLETIONPENDING; |
| 58 } |
| 59 |
| 60 void OutputProtectionResource::OnPluginMsgQueryStatusReply( |
| 61 uint32_t* out_link_mask, |
| 62 uint32_t* out_protection_mask, |
| 63 const ResourceMessageReplyParams& params, |
| 64 uint32_t link_mask, |
| 65 uint32_t protection_mask) { |
| 66 // The callback may have been aborted. |
| 67 if (!TrackedCallback::IsPending(query_status_callback_)) |
| 68 return; |
| 69 |
| 70 int32_t result = params.result(); |
| 71 |
| 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; |
| 77 } |
| 78 query_status_callback_->Run(result); |
| 79 } |
| 80 |
| 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; |
| 86 |
| 87 enable_protection_callback_ = callback; |
| 88 |
| 89 Call<PpapiPluginMsg_OutputProtection_EnableProtectionReply>( |
| 90 BROWSER, |
| 91 PpapiHostMsg_OutputProtection_EnableProtection(desired_method_mask), |
| 92 base::Bind(&OutputProtectionResource::OnPluginMsgEnableProtectionReply, |
| 93 base::Unretained(this))); |
| 94 return PP_OK_COMPLETIONPENDING; |
| 95 } |
| 96 |
| 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()); |
| 102 } |
| 103 |
| 104 } // namespace proxy |
| 105 } // namespace ppapi |
OLD | NEW |