render_view_observer.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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_RENDERER_RENDER_VIEW_OBSERVER_H_
6#define CONTENT_PUBLIC_RENDERER_RENDER_VIEW_OBSERVER_H_
7
8#include "base/basictypes.h"
9#include "base/compiler_specific.h"
10#include "content/common/content_export.h"
11#include "ipc/ipc_listener.h"
12#include "ipc/ipc_sender.h"
13#include "third_party/WebKit/Source/WebKit/chromium/public/WebIconURL.h"
14
15namespace ppapi {
16namespace host {
17class PpapiHost;
18}
19}
20
21namespace WebKit {
22class WebDataSource;
23class WebFrame;
24class WebFormElement;
25class WebGestureEvent;
26class WebMediaPlayerClient;
27class WebMouseEvent;
28class WebNode;
29class WebTouchEvent;
30class WebURL;
31struct WebContextMenuData;
32struct WebURLError;
33}
34
35namespace content {
36
37class RendererPpapiHost;
38class RenderView;
39class RenderViewImpl;
40
41// Base class for objects that want to filter incoming IPCs, and also get
42// notified of changes to the frame.
43class CONTENT_EXPORT RenderViewObserver : public IPC::Listener,
44                                          public IPC::Sender {
45 public:
46  // By default, observers will be deleted when the RenderView goes away.  If
47  // they want to outlive it, they can override this function.
48  virtual void OnDestruct();
49
50  // These match the WebKit API notifications
51  virtual void DidStartLoading() {}
52  virtual void DidStopLoading() {}
53  virtual void DidFinishDocumentLoad(WebKit::WebFrame* frame) {}
54  virtual void DidFailLoad(WebKit::WebFrame* frame,
55                           const WebKit::WebURLError& error) {}
56  virtual void DidFinishLoad(WebKit::WebFrame* frame) {}
57  virtual void DidStartProvisionalLoad(WebKit::WebFrame* frame) {}
58  virtual void DidFailProvisionalLoad(WebKit::WebFrame* frame,
59                                      const WebKit::WebURLError& error) {}
60  virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame,
61                                        bool is_new_navigation) {}
62  virtual void DidClearWindowObject(WebKit::WebFrame* frame) {}
63  virtual void WillPerformClientRedirect(
64      WebKit::WebFrame* frame, const WebKit::WebURL& from,
65      const WebKit::WebURL& to, double interval, double fire_time) {}
66  virtual void DidCancelClientRedirect(WebKit::WebFrame* frame) {}
67  virtual void DidCompleteClientRedirect(WebKit::WebFrame* frame,
68                                         const WebKit::WebURL& from) {}
69  virtual void DidCreateDocumentElement(WebKit::WebFrame* frame) {}
70  virtual void FrameCreated(WebKit::WebFrame* parent,
71                            WebKit::WebFrame* frame) {}
72  virtual void FrameDetached(WebKit::WebFrame* frame) {}
73  virtual void FrameWillClose(WebKit::WebFrame* frame) {}
74  virtual void WillSubmitForm(WebKit::WebFrame* frame,
75                              const WebKit::WebFormElement& form) {}
76  virtual void DidCreateDataSource(WebKit::WebFrame* frame,
77                                   WebKit::WebDataSource* ds) {}
78  virtual void PrintPage(WebKit::WebFrame* frame, bool user_initiated) {}
79  virtual void FocusedNodeChanged(const WebKit::WebNode& node) {}
80  virtual void WillCreateMediaPlayer(WebKit::WebFrame* frame,
81                                     WebKit::WebMediaPlayerClient* client) {}
82  virtual void ZoomLevelChanged() {};
83  virtual void DidChangeScrollOffset(WebKit::WebFrame* frame) {}
84  virtual void DraggableRegionsChanged(WebKit::WebFrame* frame) {}
85  virtual void DidRequestShowContextMenu(
86      WebKit::WebFrame* frame,
87      const WebKit::WebContextMenuData& data) {}
88  virtual void DidActivateCompositor(int input_handler_id) {}
89  virtual void DidCommitCompositorFrame() {}
90
91  // These match the RenderView methods.
92  virtual void DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {}
93  virtual void DidHandleTouchEvent(const WebKit::WebTouchEvent& event) {}
94  virtual void DidHandleGestureEvent(const WebKit::WebGestureEvent& event) {}
95  virtual void DidCreatePepperPlugin(RendererPpapiHost* host) {}
96
97  // These match incoming IPCs.
98  virtual void Navigate(const GURL& url) {}
99  virtual void ClosePage() {}
100
101  // IPC::Listener implementation.
102  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
103
104 protected:
105  explicit RenderViewObserver(RenderView* render_view);
106  virtual ~RenderViewObserver();
107
108  // IPC::Sender implementation.
109  virtual bool Send(IPC::Message* message) OVERRIDE;
110
111  RenderView* render_view() const;
112  int routing_id() { return routing_id_; }
113
114 private:
115  friend class RenderViewImpl;
116
117  // This is called by the RenderView when it's going away so that this object
118  // can null out its pointer.
119  void RenderViewGone();
120
121  RenderView* render_view_;
122  // The routing ID of the associated RenderView.
123  int routing_id_;
124
125  DISALLOW_COPY_AND_ASSIGN(RenderViewObserver);
126};
127
128}  // namespace content
129
130#endif  // CONTENT_PUBLIC_RENDERER_RENDER_VIEW_OBSERVER_H_
131