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