| OLD | NEW |
| (Empty) | |
| 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/ppb_talk_private_proxy.h" |
| 6 |
| 7 #include "ipc/ipc_message_macros.h" |
| 8 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/proxy/plugin_dispatcher.h" |
| 10 #include "ppapi/proxy/plugin_globals.h" |
| 11 #include "ppapi/proxy/plugin_proxy_delegate.h" |
| 12 #include "ppapi/proxy/ppapi_messages.h" |
| 13 #include "ppapi/shared_impl/resource.h" |
| 14 #include "ppapi/shared_impl/tracked_callback.h" |
| 15 #include "ppapi/thunk/enter.h" |
| 16 #include "ppapi/thunk/ppb_talk_private_api.h" |
| 17 |
| 18 namespace ppapi { |
| 19 namespace proxy { |
| 20 |
| 21 namespace { |
| 22 |
| 23 class Talk : public Resource, public thunk::PPB_Talk_Private_API { |
| 24 public: |
| 25 Talk(PP_Instance instance) : Resource(OBJECT_IS_PROXY, instance) { |
| 26 } |
| 27 |
| 28 // Resource overrides. |
| 29 thunk::PPB_Talk_Private_API* AsPPB_Talk_Private_API() { return this; } |
| 30 |
| 31 // PPB_Talk_API implementation. |
| 32 int32_t GetPermission(const PP_CompletionCallback& callback) { |
| 33 if (TrackedCallback::IsPending(callback_)) |
| 34 return PP_ERROR_INPROGRESS; |
| 35 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( |
| 36 pp_instance()); |
| 37 if (!dispatcher) |
| 38 return PP_ERROR_FAILED; |
| 39 |
| 40 callback_ = new TrackedCallback(this, callback); |
| 41 |
| 42 if (PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser( |
| 43 new PpapiHostMsg_PPBTalk_GetPermission( |
| 44 API_ID_PPB_TALK, |
| 45 dispatcher->plugin_dispatcher_id(), |
| 46 pp_resource()))) |
| 47 return PP_OK_COMPLETIONPENDING; |
| 48 return PP_ERROR_FAILED; |
| 49 } |
| 50 |
| 51 void GotCompletion(int32_t result) { |
| 52 TrackedCallback::ClearAndRun(&callback_, result); |
| 53 } |
| 54 |
| 55 private: |
| 56 scoped_refptr<TrackedCallback> callback_; |
| 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(Talk); |
| 59 }; |
| 60 |
| 61 } // namespace |
| 62 |
| 63 PPB_Talk_Private_Proxy::PPB_Talk_Private_Proxy(Dispatcher* dispatcher) |
| 64 : InterfaceProxy(dispatcher) { |
| 65 } |
| 66 |
| 67 // static |
| 68 PP_Resource PPB_Talk_Private_Proxy::CreateProxyResource(PP_Instance instance) { |
| 69 return (new Talk(instance))->GetReference(); |
| 70 } |
| 71 |
| 72 bool PPB_Talk_Private_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 73 bool handled = true; |
| 74 IPC_BEGIN_MESSAGE_MAP(PPB_Talk_Private_Proxy, msg) |
| 75 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTalk_GetPermissionACK, |
| 76 OnMsgGetPermissionACK) |
| 77 IPC_MESSAGE_UNHANDLED(handled = false); |
| 78 IPC_END_MESSAGE_MAP(); |
| 79 return handled; |
| 80 } |
| 81 |
| 82 void PPB_Talk_Private_Proxy::OnMsgGetPermissionACK(uint32 /* dispatcher_id */, |
| 83 PP_Resource resource, |
| 84 int32_t result) { |
| 85 thunk::EnterResourceNoLock<thunk::PPB_Talk_Private_API> enter( |
| 86 resource, false); |
| 87 if (enter.succeeded()) |
| 88 static_cast<Talk*>(enter.object())->GotCompletion(result); |
| 89 } |
| 90 |
| 91 } // namespace proxy |
| 92 } // namespace ppapi |
| OLD | NEW |