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 #ifndef CONTENT_RENDERER_PEPPER_PPB_BROKER_IMPL_H_ 6 #define CONTENT_RENDERER_PEPPER_PPB_BROKER_IMPL_H_ 7 8 #include "base/basictypes.h" 9 #include "base/compiler_specific.h" 10 #include "base/memory/weak_ptr.h" 11 #include "base/process/process.h" 12 #include "ipc/ipc_listener.h" 13 #include "ppapi/c/pp_completion_callback.h" 14 #include "ppapi/c/trusted/ppb_broker_trusted.h" 15 #include "ppapi/shared_impl/resource.h" 16 #include "ppapi/shared_impl/tracked_callback.h" 17 #include "ppapi/thunk/ppb_broker_api.h" 18 19 class GURL; 20 21 namespace IPC { 22 struct ChannelHandle; 23 } 24 25 namespace content { 26 class PepperBroker; 27 28 class PPB_Broker_Impl : public ppapi::Resource, 29 public ppapi::thunk::PPB_Broker_API, 30 public IPC::Listener, 31 public base::SupportsWeakPtr<PPB_Broker_Impl> { 32 public: 33 explicit PPB_Broker_Impl(PP_Instance instance); 34 35 // Resource override. 36 virtual ppapi::thunk::PPB_Broker_API* AsPPB_Broker_API() OVERRIDE; 37 38 // PPB_BrokerTrusted implementation. 39 virtual int32_t Connect( 40 scoped_refptr<ppapi::TrackedCallback> connect_callback) OVERRIDE; 41 virtual int32_t GetHandle(int32_t* handle) OVERRIDE; 42 43 // Returns the URL of the document this plug-in runs in. This is necessary to 44 // decide whether to grant access to the PPAPI broker. 45 GURL GetDocumentUrl(); 46 47 void BrokerConnected(int32_t handle, int32_t result); 48 49 private: 50 virtual ~PPB_Broker_Impl(); 51 52 // IPC::Listener implementation. 53 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 54 55 void OnPpapiBrokerChannelCreated(base::ProcessId broker_pid, 56 const IPC::ChannelHandle& handle); 57 void OnPpapiBrokerPermissionResult(bool result); 58 59 // PluginDelegate ppapi broker object. 60 // We don't own this pointer but are responsible for calling Disconnect on it. 61 PepperBroker* broker_; 62 63 // Callback invoked from BrokerConnected. 64 scoped_refptr<ppapi::TrackedCallback> connect_callback_; 65 66 // Pipe handle for the plugin instance to use to communicate with the broker. 67 // Never owned by this object. 68 int32_t pipe_handle_; 69 70 int routing_id_; 71 72 DISALLOW_COPY_AND_ASSIGN(PPB_Broker_Impl); 73 }; 74 75 } // namespace content 76 77 #endif // CONTENT_RENDERER_PEPPER_PPB_BROKER_IMPL_H_ 78