| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <unistd.h> |
| 6 |
| 5 #include <map> | 7 #include <map> |
| 6 #include <set> | 8 #include <set> |
| 7 | 9 |
| 8 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 9 // Need to include this before most other files because it defines | 11 // Need to include this before most other files because it defines |
| 10 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define | 12 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define |
| 11 // IPC_MESSAGE_MACROS_LOG_ENABLED so ppapi_messages.h will generate the | 13 // IPC_MESSAGE_MACROS_LOG_ENABLED so ppapi_messages.h will generate the |
| 12 // ViewMsgLog et al. functions. | 14 // ViewMsgLog et al. functions. |
| 13 | 15 |
| 14 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
| 16 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/synchronization/waitable_event.h" | 20 #include "base/synchronization/waitable_event.h" |
| 18 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
| 19 #include "components/tracing/child_trace_message_filter.h" | 22 #include "components/tracing/child_trace_message_filter.h" |
| 20 #include "ipc/ipc_channel_handle.h" | 23 #include "ipc/ipc_channel_handle.h" |
| 21 #include "ipc/ipc_logging.h" | 24 #include "ipc/ipc_logging.h" |
| 22 #include "ipc/ipc_message.h" | 25 #include "ipc/ipc_message.h" |
| 23 #include "native_client/src/public/chrome_main.h" | 26 #include "native_client/src/public/chrome_main.h" |
| 24 #include "native_client/src/shared/srpc/nacl_srpc.h" | 27 #include "native_client/src/shared/srpc/nacl_srpc.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 49 using ppapi::proxy::PluginGlobals; | 52 using ppapi::proxy::PluginGlobals; |
| 50 using ppapi::proxy::PluginProxyDelegate; | 53 using ppapi::proxy::PluginProxyDelegate; |
| 51 using ppapi::proxy::ProxyChannel; | 54 using ppapi::proxy::ProxyChannel; |
| 52 using ppapi::proxy::SerializedHandle; | 55 using ppapi::proxy::SerializedHandle; |
| 53 | 56 |
| 54 namespace { | 57 namespace { |
| 55 | 58 |
| 56 // This class manages communication between the plugin and the browser, and | 59 // This class manages communication between the plugin and the browser, and |
| 57 // manages the PluginDispatcher instances for communication between the plugin | 60 // manages the PluginDispatcher instances for communication between the plugin |
| 58 // and the renderer. | 61 // and the renderer. |
| 59 class PpapiDispatcher : public ProxyChannel, | 62 class PpapiDispatcher : public PluginDispatcher::PluginDelegate, |
| 60 public PluginDispatcher::PluginDelegate, | 63 public PluginProxyDelegate, |
| 61 public PluginProxyDelegate { | 64 public IPC::Listener, |
| 65 public IPC::Sender { |
| 62 public: | 66 public: |
| 63 explicit PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop); | 67 explicit PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop); |
| 64 | 68 |
| 65 // PluginDispatcher::PluginDelegate implementation. | 69 // PluginDispatcher::PluginDelegate implementation. |
| 66 virtual base::MessageLoopProxy* GetIPCMessageLoop() OVERRIDE; | 70 virtual base::MessageLoopProxy* GetIPCMessageLoop() OVERRIDE; |
| 67 virtual base::WaitableEvent* GetShutdownEvent() OVERRIDE; | 71 virtual base::WaitableEvent* GetShutdownEvent() OVERRIDE; |
| 68 virtual IPC::PlatformFileForTransit ShareHandleWithRemote( | 72 virtual IPC::PlatformFileForTransit ShareHandleWithRemote( |
| 69 base::PlatformFile handle, | 73 base::PlatformFile handle, |
| 70 base::ProcessId peer_pid, | 74 base::ProcessId peer_pid, |
| 71 bool should_close_source) OVERRIDE; | 75 bool should_close_source) OVERRIDE; |
| 72 virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() OVERRIDE; | 76 virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() OVERRIDE; |
| 73 virtual uint32 Register(PluginDispatcher* plugin_dispatcher) OVERRIDE; | 77 virtual uint32 Register(PluginDispatcher* plugin_dispatcher) OVERRIDE; |
| 74 virtual void Unregister(uint32 plugin_dispatcher_id) OVERRIDE; | 78 virtual void Unregister(uint32 plugin_dispatcher_id) OVERRIDE; |
| 75 | 79 |
| 76 // PluginProxyDelegate implementation. | 80 // PluginProxyDelegate implementation. |
| 77 virtual IPC::Sender* GetBrowserSender() OVERRIDE; | 81 virtual IPC::Sender* GetBrowserSender() OVERRIDE; |
| 78 virtual std::string GetUILanguage() OVERRIDE; | 82 virtual std::string GetUILanguage() OVERRIDE; |
| 79 virtual void PreCacheFont(const void* logfontw) OVERRIDE; | 83 virtual void PreCacheFont(const void* logfontw) OVERRIDE; |
| 80 virtual void SetActiveURL(const std::string& url) OVERRIDE; | 84 virtual void SetActiveURL(const std::string& url) OVERRIDE; |
| 81 virtual PP_Resource CreateBrowserFont( | 85 virtual PP_Resource CreateBrowserFont( |
| 82 ppapi::proxy::Connection connection, | 86 ppapi::proxy::Connection connection, |
| 83 PP_Instance instance, | 87 PP_Instance instance, |
| 84 const PP_BrowserFont_Trusted_Description& desc, | 88 const PP_BrowserFont_Trusted_Description& desc, |
| 85 const ppapi::Preferences& prefs) OVERRIDE; | 89 const ppapi::Preferences& prefs) OVERRIDE; |
| 86 | 90 |
| 87 // IPC::Listener implementation. | 91 // IPC::Listener implementation. |
| 88 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 92 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 93 virtual void OnChannelError() OVERRIDE; |
| 94 |
| 95 // IPC::Sender implementation |
| 96 virtual bool Send(IPC::Message* message) OVERRIDE; |
| 89 | 97 |
| 90 private: | 98 private: |
| 91 void OnMsgInitializeNaClDispatcher(const ppapi::PpapiNaClPluginArgs& args); | 99 void OnMsgInitializeNaClDispatcher(const ppapi::PpapiNaClPluginArgs& args); |
| 92 void OnPluginDispatcherMessageReceived(const IPC::Message& msg); | 100 void OnPluginDispatcherMessageReceived(const IPC::Message& msg); |
| 93 | 101 |
| 94 void SetPpapiKeepAliveThrottleFromCommandLine(); | 102 void SetPpapiKeepAliveThrottleFromCommandLine(); |
| 95 | 103 |
| 96 std::set<PP_Instance> instances_; | 104 std::set<PP_Instance> instances_; |
| 97 std::map<uint32, PluginDispatcher*> plugin_dispatchers_; | 105 std::map<uint32, PluginDispatcher*> plugin_dispatchers_; |
| 98 uint32 next_plugin_dispatcher_id_; | 106 uint32 next_plugin_dispatcher_id_; |
| 99 scoped_refptr<base::MessageLoopProxy> message_loop_; | 107 scoped_refptr<base::MessageLoopProxy> message_loop_; |
| 100 base::WaitableEvent shutdown_event_; | 108 base::WaitableEvent shutdown_event_; |
| 109 scoped_ptr<IPC::SyncChannel> channel_; |
| 101 }; | 110 }; |
| 102 | 111 |
| 103 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop) | 112 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop) |
| 104 : next_plugin_dispatcher_id_(0), | 113 : next_plugin_dispatcher_id_(0), |
| 105 message_loop_(io_loop), | 114 message_loop_(io_loop), |
| 106 shutdown_event_(true, false) { | 115 shutdown_event_(true, false) { |
| 107 // The first FD (based on NACL_CHROME_DESC_BASE) is the IPC channel to the | 116 // The first FD (based on NACL_CHROME_DESC_BASE) is the IPC channel to the |
| 108 // browser. | 117 // browser. |
| 109 IPC::ChannelHandle channel_handle( | 118 IPC::ChannelHandle channel_handle( |
| 110 "NaCl IPC", base::FileDescriptor(NACL_CHROME_DESC_BASE, false)); | 119 "NaCl IPC", base::FileDescriptor(NACL_CHROME_DESC_BASE, false)); |
| 111 // We don't have/need a PID since handle sharing happens outside of the | 120 // We don't have/need a PID since handle sharing happens outside of the |
| 112 // NaCl sandbox. | 121 // NaCl sandbox. |
| 113 InitWithChannel(this, base::kNullProcessId, channel_handle, | 122 channel_.reset(new IPC::SyncChannel( |
| 114 false); // Channel is server. | 123 channel_handle, IPC::Channel::MODE_SERVER, this, |
| 115 channel()->AddFilter(new ppapi::proxy::PluginMessageFilter( | 124 GetIPCMessageLoop(), true, GetShutdownEvent())); |
| 125 |
| 126 channel_->AddFilter(new ppapi::proxy::PluginMessageFilter( |
| 116 NULL, PluginGlobals::Get()->resource_reply_thread_registrar())); | 127 NULL, PluginGlobals::Get()->resource_reply_thread_registrar())); |
| 117 channel()->AddFilter( | 128 channel_->AddFilter( |
| 118 new tracing::ChildTraceMessageFilter(message_loop_.get())); | 129 new tracing::ChildTraceMessageFilter(message_loop_.get())); |
| 119 } | 130 } |
| 120 | 131 |
| 121 base::MessageLoopProxy* PpapiDispatcher::GetIPCMessageLoop() { | 132 base::MessageLoopProxy* PpapiDispatcher::GetIPCMessageLoop() { |
| 122 return message_loop_.get(); | 133 return message_loop_.get(); |
| 123 } | 134 } |
| 124 | 135 |
| 125 base::WaitableEvent* PpapiDispatcher::GetShutdownEvent() { | 136 base::WaitableEvent* PpapiDispatcher::GetShutdownEvent() { |
| 126 return &shutdown_event_; | 137 return &shutdown_event_; |
| 127 } | 138 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 bool PpapiDispatcher::OnMessageReceived(const IPC::Message& msg) { | 198 bool PpapiDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 188 IPC_BEGIN_MESSAGE_MAP(PpapiDispatcher, msg) | 199 IPC_BEGIN_MESSAGE_MAP(PpapiDispatcher, msg) |
| 189 IPC_MESSAGE_HANDLER(PpapiMsg_InitializeNaClDispatcher, | 200 IPC_MESSAGE_HANDLER(PpapiMsg_InitializeNaClDispatcher, |
| 190 OnMsgInitializeNaClDispatcher) | 201 OnMsgInitializeNaClDispatcher) |
| 191 // All other messages are simply forwarded to a PluginDispatcher. | 202 // All other messages are simply forwarded to a PluginDispatcher. |
| 192 IPC_MESSAGE_UNHANDLED(OnPluginDispatcherMessageReceived(msg)) | 203 IPC_MESSAGE_UNHANDLED(OnPluginDispatcherMessageReceived(msg)) |
| 193 IPC_END_MESSAGE_MAP() | 204 IPC_END_MESSAGE_MAP() |
| 194 return true; | 205 return true; |
| 195 } | 206 } |
| 196 | 207 |
| 208 void PpapiDispatcher::OnChannelError() { |
| 209 exit(1); |
| 210 } |
| 211 |
| 212 bool PpapiDispatcher::Send(IPC::Message* msg) { |
| 213 return channel_->Send(msg); |
| 214 } |
| 215 |
| 197 void PpapiDispatcher::OnMsgInitializeNaClDispatcher( | 216 void PpapiDispatcher::OnMsgInitializeNaClDispatcher( |
| 198 const ppapi::PpapiNaClPluginArgs& args) { | 217 const ppapi::PpapiNaClPluginArgs& args) { |
| 199 static bool command_line_and_logging_initialized = false; | 218 static bool command_line_and_logging_initialized = false; |
| 200 if (command_line_and_logging_initialized) { | 219 if (command_line_and_logging_initialized) { |
| 201 LOG(FATAL) << "InitializeNaClDispatcher must be called once per plugin."; | 220 LOG(FATAL) << "InitializeNaClDispatcher must be called once per plugin."; |
| 202 return; | 221 return; |
| 203 } | 222 } |
| 204 | 223 |
| 205 command_line_and_logging_initialized = true; | 224 command_line_and_logging_initialized = true; |
| 206 CommandLine::Init(0, NULL); | 225 CommandLine::Init(0, NULL); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 return 1; | 317 return 1; |
| 299 } | 318 } |
| 300 | 319 |
| 301 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy()); | 320 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy()); |
| 302 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher); | 321 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher); |
| 303 | 322 |
| 304 loop.Run(); | 323 loop.Run(); |
| 305 | 324 |
| 306 return 0; | 325 return 0; |
| 307 } | 326 } |
| OLD | NEW |