blob: 6e613463dbac34dd44324864dd7eeb114c617bbc [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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 Murdochbb1529c2013-08-08 10:24:53 +01005#ifndef CONTENT_RENDERER_NPAPI_PLUGIN_CHANNEL_HOST_H_
6#define CONTENT_RENDERER_NPAPI_PLUGIN_CHANNEL_HOST_H_
Torne (Richard Coles)58218062012-11-14 11:43:16 +00007
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +01008#include "base/containers/hash_tables.h"
Ben Murdochca12bfa2013-07-23 11:17:05 +01009#include "content/child/npapi/np_channel_base.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000010#include "ipc/ipc_channel_handle.h"
11
12namespace content {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000013class NPObjectBase;
14
15// Encapsulates an IPC channel between the renderer and one plugin process.
16// On the plugin side there's a corresponding PluginChannel.
17class 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)58218062012-11-14 11:43:16 +000044 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)58218062012-11-14 11:43:16 +000066 // 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 Murdochbb1529c2013-08-08 10:24:53 +010075#endif // CONTENT_RENDERER_NPAPI_PLUGIN_CHANNEL_HOST_H_