1// Copyright 2014 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 PPAPI_NACL_IRT_PPAPI_DISPATCHER_H_ 6#define PPAPI_NACL_IRT_PPAPI_DISPATCHER_H_ 7 8#include <map> 9#include <set> 10#include <string> 11 12#include "base/files/file.h" 13#include "base/memory/ref_counted.h" 14#include "base/process/process_handle.h" 15#include "ipc/ipc_listener.h" 16#include "ipc/ipc_platform_file.h" 17#include "ipc/ipc_sender.h" 18#include "ppapi/c/pp_instance.h" 19#include "ppapi/c/trusted/ppb_browser_font_trusted.h" 20#include "ppapi/proxy/connection.h" 21#include "ppapi/proxy/plugin_dispatcher.h" 22#include "ppapi/proxy/plugin_proxy_delegate.h" 23 24struct PP_BrowserFont_Trusted_Description; 25 26namespace base { 27class MessageLoopProxy; 28class WaitableEvent; 29} // namespace base 30 31namespace IPC { 32class Message; 33class SyncChannel; 34} // namespace IPC 35 36namespace ppapi { 37 38struct PpapiNaClPluginArgs; 39struct Preferences; 40 41// This class manages communication between the plugin and the browser, and 42// manages the PluginDispatcher instances for communication between the plugin 43// and the renderer. 44class PpapiDispatcher : public proxy::PluginDispatcher::PluginDelegate, 45 public proxy::PluginProxyDelegate, 46 public IPC::Listener, 47 public IPC::Sender { 48 public: 49 PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop, 50 base::WaitableEvent* shutdown_event, 51 int browser_ipc_fd, 52 int renderer_ipc_fd); 53 54 // PluginDispatcher::PluginDelegate implementation. 55 virtual base::MessageLoopProxy* GetIPCMessageLoop() OVERRIDE; 56 virtual base::WaitableEvent* GetShutdownEvent() OVERRIDE; 57 virtual IPC::PlatformFileForTransit ShareHandleWithRemote( 58 base::PlatformFile handle, 59 base::ProcessId peer_pid, 60 bool should_close_source) OVERRIDE; 61 virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() OVERRIDE; 62 virtual uint32 Register( 63 proxy::PluginDispatcher* plugin_dispatcher) OVERRIDE; 64 virtual void Unregister(uint32 plugin_dispatcher_id) OVERRIDE; 65 66 // PluginProxyDelegate implementation. 67 virtual IPC::Sender* GetBrowserSender() OVERRIDE; 68 virtual std::string GetUILanguage() OVERRIDE; 69 virtual void PreCacheFont(const void* logfontw) OVERRIDE; 70 virtual void SetActiveURL(const std::string& url) OVERRIDE; 71 virtual PP_Resource CreateBrowserFont( 72 proxy::Connection connection, 73 PP_Instance instance, 74 const PP_BrowserFont_Trusted_Description& desc, 75 const Preferences& prefs) OVERRIDE; 76 77 // IPC::Listener implementation. 78 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 79 virtual void OnChannelError() OVERRIDE; 80 81 // IPC::Sender implementation 82 virtual bool Send(IPC::Message* message) OVERRIDE; 83 84 private: 85 void OnMsgInitializeNaClDispatcher(const PpapiNaClPluginArgs& args); 86 void OnPluginDispatcherMessageReceived(const IPC::Message& msg); 87 88 std::set<PP_Instance> instances_; 89 std::map<uint32, proxy::PluginDispatcher*> plugin_dispatchers_; 90 uint32 next_plugin_dispatcher_id_; 91 92 scoped_refptr<base::MessageLoopProxy> message_loop_; 93 base::WaitableEvent* shutdown_event_; 94 int renderer_ipc_fd_; 95 scoped_ptr<IPC::SyncChannel> channel_; 96}; 97 98} // namespace ppapi 99 100#endif // PPAPI_NACL_IRT_PPAPI_DISPATCHER_H_ 101