Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / public / renderer / render_view_observer.h
blob966a72c389cd2b386dbbf2a3e687fec6dfa28ac2
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_PUBLIC_RENDERER_RENDER_VIEW_OBSERVER_H_
6 #define CONTENT_PUBLIC_RENDERER_RENDER_VIEW_OBSERVER_H_
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 "v8/include/v8.h"
16 class GURL;
18 namespace ppapi {
19 namespace host {
20 class PpapiHost;
24 namespace blink {
25 class WebDataSource;
26 class WebFrame;
27 class WebFormElement;
28 class WebGestureEvent;
29 class WebLocalFrame;
30 class WebMouseEvent;
31 class WebNode;
32 class WebString;
33 class WebTouchEvent;
34 class WebURL;
35 struct WebURLError;
38 namespace content {
40 class RendererPpapiHost;
41 class RenderView;
42 class RenderViewImpl;
44 // Base class for objects that want to filter incoming IPCs, and also get
45 // notified of changes to the frame.
46 class CONTENT_EXPORT RenderViewObserver : public IPC::Listener,
47 public IPC::Sender {
48 public:
49 // By default, observers will be deleted when the RenderView goes away. If
50 // they want to outlive it, they can override this function.
51 virtual void OnDestruct();
53 // These match the WebKit API notifications
54 virtual void DidStartLoading() {}
55 virtual void DidStopLoading() {}
56 virtual void DidFinishDocumentLoad(blink::WebLocalFrame* frame) {}
57 virtual void DidFailLoad(blink::WebLocalFrame* frame,
58 const blink::WebURLError& error) {}
59 virtual void DidFinishLoad(blink::WebLocalFrame* frame) {}
60 virtual void DidStartProvisionalLoad(blink::WebLocalFrame* frame) {}
61 virtual void DidFailProvisionalLoad(blink::WebLocalFrame* frame,
62 const blink::WebURLError& error) {}
63 virtual void DidCommitProvisionalLoad(blink::WebLocalFrame* frame,
64 bool is_new_navigation) {}
65 virtual void DidCreateNewDocument(blink::WebLocalFrame* frame) {}
66 virtual void DidClearWindowObject(blink::WebLocalFrame* frame) {}
67 virtual void DidCreateDocumentElement(blink::WebLocalFrame* frame) {}
68 virtual void FrameCreated(blink::WebLocalFrame* parent,
69 blink::WebFrame* frame) {}
70 virtual void FrameDetached(blink::WebFrame* frame) {}
71 virtual void FrameWillClose(blink::WebFrame* frame) {}
72 virtual void DidMatchCSS(
73 blink::WebLocalFrame* frame,
74 const blink::WebVector<blink::WebString>& newly_matching_selectors,
75 const blink::WebVector<blink::WebString>& stopped_matching_selectors) {}
76 virtual void PrintPage(blink::WebLocalFrame* frame, bool user_initiated) {}
77 virtual void FocusedNodeChanged(const blink::WebNode& node) {}
78 virtual void DraggableRegionsChanged(blink::WebFrame* frame) {}
79 virtual void DidCommitCompositorFrame() {}
80 virtual void DidUpdateLayout() {}
82 // These match the RenderView methods.
83 virtual void DidHandleMouseEvent(const blink::WebMouseEvent& event) {}
84 virtual void DidHandleTouchEvent(const blink::WebTouchEvent& event) {}
85 virtual void DidHandleGestureEvent(const blink::WebGestureEvent& event) {}
87 // These match incoming IPCs.
88 virtual void Navigate(const GURL& url) {}
89 virtual void ClosePage() {}
91 // This indicates that animations to scroll the focused element into view (if
92 // any) have completed. May be called more than once for a single focus. Can
93 // be called from browser, renderer, or compositor.
94 virtual void FocusChangeComplete() {}
96 virtual void OnStop() {}
98 // IPC::Listener implementation.
99 bool OnMessageReceived(const IPC::Message& message) override;
101 // IPC::Sender implementation.
102 bool Send(IPC::Message* message) override;
104 RenderView* render_view() const;
105 int routing_id() const { return routing_id_; }
107 protected:
108 explicit RenderViewObserver(RenderView* render_view);
109 ~RenderViewObserver() override;
111 // Sets |render_view_| to track.
112 // Removes itself of previous (if any) |render_view_| observer list and adds
113 // to the new |render_view|. Since it assumes that observer outlives
114 // render_view, OnDestruct should be overridden.
115 void Observe(RenderView* render_view);
117 private:
118 friend class RenderViewImpl;
120 // This is called by the RenderView when it's going away so that this object
121 // can null out its pointer.
122 void RenderViewGone();
124 RenderView* render_view_;
125 // The routing ID of the associated RenderView.
126 int routing_id_;
128 DISALLOW_COPY_AND_ASSIGN(RenderViewObserver);
131 } // namespace content
133 #endif // CONTENT_PUBLIC_RENDERER_RENDER_VIEW_OBSERVER_H_