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.
5 #ifndef CONTENT_RENDERER_PLUGIN_CHANNEL_HOST_H_
6 #define CONTENT_RENDERER_PLUGIN_CHANNEL_HOST_H_
8 #include "base/hash_tables.h"
9 #include "content/common/np_channel_base.h"
10 #include "ipc/ipc_channel_handle.h"
13 class IsListeningFilter
;
16 // Encapsulates an IPC channel between the renderer and one plugin process.
17 // On the plugin side there's a corresponding PluginChannel.
18 class PluginChannelHost
: public NPChannelBase
{
20 #if defined(OS_MACOSX)
21 // TODO(shess): Debugging for http://crbug.com/97285 . See comment
22 // in plugin_channel_host.cc.
23 static bool* GetRemoveTrackingFlag();
25 static PluginChannelHost
* GetPluginChannelHost(
26 const IPC::ChannelHandle
& channel_handle
,
27 base::MessageLoopProxy
* ipc_message_loop
);
29 virtual bool Init(base::MessageLoopProxy
* ipc_message_loop
,
31 base::WaitableEvent
* shutdown_event
) OVERRIDE
;
33 virtual int GenerateRouteID() OVERRIDE
;
35 void AddRoute(int route_id
, IPC::Listener
* listener
,
36 NPObjectBase
* npobject
);
37 void RemoveRoute(int route_id
);
39 // NPChannelBase override:
40 virtual bool Send(IPC::Message
* msg
) OVERRIDE
;
42 // IPC::Listener override
43 virtual void OnChannelError() OVERRIDE
;
45 static void SetListening(bool flag
);
47 static bool IsListening();
49 static void Broadcast(IPC::Message
* message
) {
50 NPChannelBase::Broadcast(message
);
53 bool expecting_shutdown() { return expecting_shutdown_
; }
56 // Called on the render thread
58 virtual ~PluginChannelHost();
60 static NPChannelBase
* ClassFactory() { return new PluginChannelHost(); }
62 virtual bool OnControlMessageReceived(const IPC::Message
& message
) OVERRIDE
;
63 void OnSetException(const std::string
& message
);
64 void OnPluginShuttingDown();
66 // Keep track of all the registered WebPluginDelegeProxies to
67 // inform about OnChannelError
68 typedef base::hash_map
<int, IPC::Listener
*> ProxyMap
;
71 // An IPC MessageFilter that can be told to filter out all messages. This is
72 // used when the JS debugger is attached in order to avoid browser hangs.
73 scoped_refptr
<IsListeningFilter
> is_listening_filter_
;
75 // True if we are expecting the plugin process to go away - in which case,
76 // don't treat it as a crash.
77 bool expecting_shutdown_
;
79 DISALLOW_COPY_AND_ASSIGN(PluginChannelHost
);
82 } // namespace content
84 #endif // CONTENT_RENDERER_PLUGIN_CHANNEL_HOST_H_