Home | History | Annotate | Download | only in browser
      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_PUBLIC_BROWSER_RENDER_VIEW_HOST_OBSERVER_H_
      6 #define CONTENT_PUBLIC_BROWSER_RENDER_VIEW_HOST_OBSERVER_H_
      7 
      8 #include "base/compiler_specific.h"
      9 #include "ipc/ipc_listener.h"
     10 #include "ipc/ipc_sender.h"
     11 #include "content/common/content_export.h"
     12 
     13 class GURL;
     14 
     15 namespace content {
     16 
     17 class RenderViewHost;
     18 class RenderViewHostImpl;
     19 
     20 // An observer API implemented by classes which want to filter IPC messages from
     21 // RenderViewHost.
     22 class CONTENT_EXPORT RenderViewHostObserver : public IPC::Listener,
     23                                               public IPC::Sender {
     24  public:
     25 
     26  protected:
     27   explicit RenderViewHostObserver(RenderViewHost* render_view_host);
     28 
     29   virtual ~RenderViewHostObserver();
     30 
     31   // Invoked after the RenderViewHost is created in the renderer process.  After
     32   // this point, messages can be sent to it (or to observers in the renderer).
     33   virtual void RenderViewHostInitialized();
     34 
     35   // Invoked when the RenderViewHost is being destroyed. Gives subclasses a
     36   // chance to cleanup.  The base implementation will delete the object.
     37   // |render_view_host| is passed as an argument since render_view_host() will
     38   // return NULL once this method enters.
     39   virtual void RenderViewHostDestroyed(RenderViewHost* render_view_host);
     40 
     41   // Notifies that a navigation is starting.
     42   virtual void Navigate(const GURL& url);
     43 
     44   // IPC::Listener implementation.
     45   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
     46 
     47   // IPC::Sender implementation.
     48   virtual bool Send(IPC::Message* message) OVERRIDE;
     49 
     50   RenderViewHost* render_view_host() const;
     51   int routing_id() { return routing_id_; }
     52 
     53  private:
     54   friend class RenderViewHostImpl;
     55 
     56   // Invoked from RenderViewHost. Invokes RenderViewHostDestroyed and NULL out
     57   // |render_view_host_|.
     58   void RenderViewHostDestruction();
     59 
     60   RenderViewHostImpl* render_view_host_;
     61 
     62   // The routing ID of the associated RenderViewHost.
     63   int routing_id_;
     64 
     65   DISALLOW_COPY_AND_ASSIGN(RenderViewHostObserver);
     66 };
     67 
     68 }  // namespace content
     69 
     70 #endif  // CONTENT_PUBLIC_BROWSER_RENDER_VIEW_HOST_OBSERVER_H_
     71