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"
28 class WebGestureEvent
;
40 class RendererPpapiHost
;
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
,
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 DidHandleGestureEvent(const blink::WebGestureEvent
& event
) {}
86 // These match incoming IPCs.
87 virtual void Navigate(const GURL
& url
) {}
88 virtual void ClosePage() {}
90 // This indicates that animations to scroll the focused element into view (if
91 // any) have completed. May be called more than once for a single focus. Can
92 // be called from browser, renderer, or compositor.
93 virtual void FocusChangeComplete() {}
95 virtual void OnStop() {}
97 // IPC::Listener implementation.
98 bool OnMessageReceived(const IPC::Message
& message
) override
;
100 // IPC::Sender implementation.
101 bool Send(IPC::Message
* message
) override
;
103 RenderView
* render_view() const;
104 int routing_id() const { return routing_id_
; }
107 explicit RenderViewObserver(RenderView
* render_view
);
108 ~RenderViewObserver() override
;
110 // Sets |render_view_| to track.
111 // Removes itself of previous (if any) |render_view_| observer list and adds
112 // to the new |render_view|. Since it assumes that observer outlives
113 // render_view, OnDestruct should be overridden.
114 void Observe(RenderView
* render_view
);
117 friend class RenderViewImpl
;
119 // This is called by the RenderView when it's going away so that this object
120 // can null out its pointer.
121 void RenderViewGone();
123 RenderView
* render_view_
;
124 // The routing ID of the associated RenderView.
127 DISALLOW_COPY_AND_ASSIGN(RenderViewObserver
);
130 } // namespace content
132 #endif // CONTENT_PUBLIC_RENDERER_RENDER_VIEW_OBSERVER_H_