render_view_observer.h revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
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/public/platform/WebVector.h"
14#include "third_party/WebKit/public/web/WebIconURL.h"
15// TODO(dcheng): Temporary. Convert back to a forward declare.
16#include "third_party/WebKit/public/web/WebLocalFrame.h"
17
18class GURL;
19
20namespace ppapi {
21namespace host {
22class PpapiHost;
23}
24}
25
26namespace blink {
27class WebDataSource;
28class WebFrame;
29class WebFormElement;
30class WebGestureEvent;
31class WebMediaPlayerClient;
32class WebMouseEvent;
33class WebNode;
34class WebTouchEvent;
35class WebURL;
36struct WebURLError;
37}
38
39namespace content {
40
41class RendererPpapiHost;
42class RenderView;
43class RenderViewImpl;
44
45// Base class for objects that want to filter incoming IPCs, and also get
46// notified of changes to the frame.
47class CONTENT_EXPORT RenderViewObserver : public IPC::Listener,
48                                          public IPC::Sender {
49 public:
50  // By default, observers will be deleted when the RenderView goes away.  If
51  // they want to outlive it, they can override this function.
52  virtual void OnDestruct();
53
54  // These match the WebKit API notifications
55  virtual void DidStartLoading() {}
56  virtual void DidStopLoading() {}
57  virtual void DidFinishDocumentLoad(blink::WebLocalFrame* frame) {}
58  virtual void DidFailLoad(blink::WebLocalFrame* frame,
59                           const blink::WebURLError& error) {}
60  virtual void DidFinishLoad(blink::WebLocalFrame* frame) {}
61  virtual void DidStartProvisionalLoad(blink::WebLocalFrame* frame) {}
62  virtual void DidFailProvisionalLoad(blink::WebLocalFrame* frame,
63                                      const blink::WebURLError& error) {}
64  virtual void DidCommitProvisionalLoad(blink::WebLocalFrame* frame,
65                                        bool is_new_navigation) {}
66  virtual void DidClearWindowObject(blink::WebLocalFrame* frame, int world_id) {
67  }
68  virtual void DidCreateDocumentElement(blink::WebLocalFrame* frame) {}
69  virtual void FrameCreated(blink::WebLocalFrame* parent,
70                            blink::WebFrame* frame) {}
71  virtual void FrameDetached(blink::WebFrame* frame) {}
72  virtual void FrameWillClose(blink::WebFrame* frame) {}
73  virtual void DidMatchCSS(
74      blink::WebLocalFrame* frame,
75      const blink::WebVector<blink::WebString>& newly_matching_selectors,
76      const blink::WebVector<blink::WebString>& stopped_matching_selectors) {}
77  virtual void WillSendSubmitEvent(blink::WebLocalFrame* frame,
78                                   const blink::WebFormElement& form) {}
79  virtual void WillSubmitForm(blink::WebLocalFrame* frame,
80                              const blink::WebFormElement& form) {}
81  virtual void DidCreateDataSource(blink::WebLocalFrame* frame,
82                                   blink::WebDataSource* ds) {}
83  virtual void PrintPage(blink::WebLocalFrame* frame, bool user_initiated) {}
84  virtual void FocusedNodeChanged(const blink::WebNode& node) {}
85  virtual void WillCreateMediaPlayer(blink::WebLocalFrame* frame,
86                                     blink::WebMediaPlayerClient* client) {}
87  virtual void ZoomLevelChanged() {};
88  virtual void DidChangeScrollOffset(blink::WebLocalFrame* frame) {}
89  virtual void DraggableRegionsChanged(blink::WebFrame* frame) {}
90  virtual void DidCommitCompositorFrame() {}
91  virtual void DidUpdateLayout() {}
92
93  // These match the RenderView methods.
94  virtual void DidHandleMouseEvent(const blink::WebMouseEvent& event) {}
95  virtual void DidHandleTouchEvent(const blink::WebTouchEvent& event) {}
96
97  // This matches the RenderWidget method.
98  virtual void WillProcessUserGesture() {}
99
100  // Called when we receive a console message from WebKit for which we requested
101  // extra details (like the stack trace). |message| is the error message,
102  // |source| is the WebKit-reported source of the error (either external or
103  // internal), and |stack_trace| is the stack trace of the error in a
104  // human-readable format (each frame is formatted as
105  // "\n    at function_name (source:line_number:column_number)").
106  virtual void DetailedConsoleMessageAdded(const base::string16& message,
107                                           const base::string16& source,
108                                           const base::string16& stack_trace,
109                                           int32 line_number,
110                                           int32 severity_level) {}
111
112  // These match incoming IPCs.
113  virtual void Navigate(const GURL& url) {}
114  virtual void ClosePage() {}
115  virtual void OrientationChangeEvent(int orientation) {}
116
117  virtual void OnStop() {}
118
119  // IPC::Listener implementation.
120  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
121
122  // IPC::Sender implementation.
123  virtual bool Send(IPC::Message* message) OVERRIDE;
124
125  RenderView* render_view() const;
126  int routing_id() const { return routing_id_; }
127
128 protected:
129  explicit RenderViewObserver(RenderView* render_view);
130  virtual ~RenderViewObserver();
131
132 private:
133  friend class RenderViewImpl;
134
135  // This is called by the RenderView when it's going away so that this object
136  // can null out its pointer.
137  void RenderViewGone();
138
139  RenderView* render_view_;
140  // The routing ID of the associated RenderView.
141  int routing_id_;
142
143  DISALLOW_COPY_AND_ASSIGN(RenderViewObserver);
144};
145
146}  // namespace content
147
148#endif  // CONTENT_PUBLIC_RENDERER_RENDER_VIEW_OBSERVER_H_
149