Home | History | Annotate | Download | only in npapi
      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 
      5 #ifndef CONTENT_RENDERER_NPAPI_PLUGIN_CHANNEL_HOST_H_
      6 #define CONTENT_RENDERER_NPAPI_PLUGIN_CHANNEL_HOST_H_
      7 
      8 #include "base/containers/hash_tables.h"
      9 #include "content/child/npapi/np_channel_base.h"
     10 #include "ipc/ipc_channel_handle.h"
     11 
     12 namespace content {
     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 
     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 
     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 
     75 #endif  // CONTENT_RENDERER_NPAPI_PLUGIN_CHANNEL_HOST_H_
     76