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 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 link_mask_ = link_mask; |
| 49 protection_mask_ = protection_mask; |
| 50 query_status_callback_ = callback; |
| 51 |
| 52 Call<PpapiPluginMsg_OutputProtection_QueryStatusReply>( |
| 53 BROWSER, |
| 54 PpapiHostMsg_OutputProtection_QueryStatus(), |
| 55 base::Bind(&OutputProtectionResource::OnPluginMsgQueryStatusReply, |
| 56 base::Unretained(this))); |
| 57 return PP_OK_COMPLETIONPENDING; |
| 58 } |
| 59 |
| 60 void OutputProtectionResource::OnPluginMsgQueryStatusReply( |
| 61 const ResourceMessageReplyParams& params, |
| 62 uint32_t link_mask, |
| 63 uint32_t protection_mask) { |
| 64 // The callback may have been aborted. |
| 65 if (!TrackedCallback::IsPending(query_status_callback_)) |
| 66 return; |
| 67 if (link_mask_ == NULL || protection_mask_ == NULL) |
| 68 return; |
| 69 |
| 70 int32_t result = params.result(); |
| 71 |
| 72 if (result == PP_OK) { |
| 73 *link_mask_ = link_mask; |
| 74 *protection_mask_ = protection_mask; |
| 75 } |
| 76 link_mask_ = NULL; |
| 77 protection_mask_ = NULL; |
| 78 query_status_callback_->Run(result); |
| 79 } |
| 80 |
| 81 int32_t OutputProtectionResource::EnableProtection(uint32_t desired_method_mask, |
| 82 scoped_refptr<TrackedCallback> callback) { |
| 83 if (TrackedCallback::IsPending(enable_protection_callback_)) |
| 84 return PP_ERROR_INPROGRESS; |
| 85 |
| 86 enable_protection_callback_ = callback; |
| 87 |
| 88 Call<PpapiPluginMsg_OutputProtection_EnableProtectionReply>( |
| 89 BROWSER, |
| 90 PpapiHostMsg_OutputProtection_EnableProtection(desired_method_mask), |
| 91 base::Bind(&OutputProtectionResource::OnPluginMsgEnableProtectionReply, |
| 92 base::Unretained(this))); |
| 93 return PP_OK_COMPLETIONPENDING; |
| 94 } |
| 95 |
| 96 void OutputProtectionResource::OnPluginMsgEnableProtectionReply( |
| 97 const ResourceMessageReplyParams& params) { |
| 98 // The callback may have been aborted. |
| 99 if (TrackedCallback::IsPending(enable_protection_callback_)) |
| 100 enable_protection_callback_->Run(params.result()); |
| 101 } |
| 102 |
| 103 } // namespace proxy |
| 104 } // namespace ppapi |
OLD | NEW |