Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 5 | #ifndef CONTENT_RENDERER_NPAPI_PLUGIN_CHANNEL_HOST_H_ |
| 6 | #define CONTENT_RENDERER_NPAPI_PLUGIN_CHANNEL_HOST_H_ |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 7 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 8 | #include "base/containers/hash_tables.h" |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 9 | #include "content/child/npapi/np_channel_base.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 10 | #include "ipc/ipc_channel_handle.h" |
| 11 | |
| 12 | namespace content { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 13 | class NPObjectBase; |
| 14 | |
| 15 | // Encapsulates an IPC channel between the renderer and one plugin process. |
| 16 | // On the plugin side there's a corresponding PluginChannel. |
| 17 | class PluginChannelHost : public NPChannelBase { |
| 18 | public: |
| 19 | #if defined(OS_MACOSX) |
| 20 | // TODO(shess): Debugging for http://crbug.com/97285 . See comment |
| 21 | // in plugin_channel_host.cc. |
| 22 | static bool* GetRemoveTrackingFlag(); |
| 23 | #endif |
| 24 | static PluginChannelHost* GetPluginChannelHost( |
| 25 | const IPC::ChannelHandle& channel_handle, |
| 26 | base::MessageLoopProxy* ipc_message_loop); |
| 27 | |
| 28 | virtual bool Init(base::MessageLoopProxy* ipc_message_loop, |
| 29 | bool create_pipe_now, |
| 30 | base::WaitableEvent* shutdown_event) OVERRIDE; |
| 31 | |
| 32 | virtual int GenerateRouteID() OVERRIDE; |
| 33 | |
| 34 | void AddRoute(int route_id, IPC::Listener* listener, |
| 35 | NPObjectBase* npobject); |
| 36 | void RemoveRoute(int route_id); |
| 37 | |
| 38 | // NPChannelBase override: |
| 39 | virtual bool Send(IPC::Message* msg) OVERRIDE; |
| 40 | |
| 41 | // IPC::Listener override |
| 42 | virtual void OnChannelError() OVERRIDE; |
| 43 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 44 | static void Broadcast(IPC::Message* message) { |
| 45 | NPChannelBase::Broadcast(message); |
| 46 | } |
| 47 | |
| 48 | bool expecting_shutdown() { return expecting_shutdown_; } |
| 49 | |
| 50 | private: |
| 51 | // Called on the render thread |
| 52 | PluginChannelHost(); |
| 53 | virtual ~PluginChannelHost(); |
| 54 | |
| 55 | static NPChannelBase* ClassFactory() { return new PluginChannelHost(); } |
| 56 | |
| 57 | virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; |
| 58 | void OnSetException(const std::string& message); |
| 59 | void OnPluginShuttingDown(); |
| 60 | |
| 61 | // Keep track of all the registered WebPluginDelegeProxies to |
| 62 | // inform about OnChannelError |
| 63 | typedef base::hash_map<int, IPC::Listener*> ProxyMap; |
| 64 | ProxyMap proxies_; |
| 65 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 66 | // True if we are expecting the plugin process to go away - in which case, |
| 67 | // don't treat it as a crash. |
| 68 | bool expecting_shutdown_; |
| 69 | |
| 70 | DISALLOW_COPY_AND_ASSIGN(PluginChannelHost); |
| 71 | }; |
| 72 | |
| 73 | } // namespace content |
| 74 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 75 | #endif // CONTENT_RENDERER_NPAPI_PLUGIN_CHANNEL_HOST_H_ |