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 "third_party/WebKit/public/web/WebIconURL.h"
28 class WebGestureEvent
;
39 class RendererPpapiHost
;
43 // Base class for objects that want to filter incoming IPCs, and also get
44 // notified of changes to the frame.
45 class CONTENT_EXPORT RenderViewObserver
: public IPC::Listener
,
48 // By default, observers will be deleted when the RenderView goes away. If
49 // they want to outlive it, they can override this function.
50 virtual void OnDestruct();
52 // These match the WebKit API notifications
53 virtual void DidStartLoading() {}
54 virtual void DidStopLoading() {}
55 virtual void DidFinishDocumentLoad(blink::WebLocalFrame
* frame
) {}
56 virtual void DidFailLoad(blink::WebLocalFrame
* frame
,
57 const blink::WebURLError
& error
) {}
58 virtual void DidFinishLoad(blink::WebLocalFrame
* frame
) {}
59 virtual void DidStartProvisionalLoad(blink::WebLocalFrame
* frame
) {}
60 virtual void DidFailProvisionalLoad(blink::WebLocalFrame
* frame
,
61 const blink::WebURLError
& error
) {}
62 virtual void DidCommitProvisionalLoad(blink::WebLocalFrame
* frame
,
63 bool is_new_navigation
) {}
64 virtual void DidClearWindowObject(blink::WebLocalFrame
* frame
, int world_id
) {
66 virtual void DidCreateDocumentElement(blink::WebLocalFrame
* frame
) {}
67 virtual void FrameCreated(blink::WebLocalFrame
* parent
,
68 blink::WebFrame
* frame
) {}
69 virtual void FrameDetached(blink::WebFrame
* frame
) {}
70 virtual void FrameWillClose(blink::WebFrame
* frame
) {}
71 virtual void DidMatchCSS(
72 blink::WebLocalFrame
* frame
,
73 const blink::WebVector
<blink::WebString
>& newly_matching_selectors
,
74 const blink::WebVector
<blink::WebString
>& stopped_matching_selectors
) {}
75 virtual void WillSendSubmitEvent(blink::WebLocalFrame
* frame
,
76 const blink::WebFormElement
& form
) {}
77 virtual void WillSubmitForm(blink::WebLocalFrame
* frame
,
78 const blink::WebFormElement
& form
) {}
79 virtual void DidCreateDataSource(blink::WebLocalFrame
* frame
,
80 blink::WebDataSource
* ds
) {}
81 virtual void PrintPage(blink::WebLocalFrame
* frame
, bool user_initiated
) {}
82 virtual void FocusedNodeChanged(const blink::WebNode
& node
) {}
83 virtual void ZoomLevelChanged() {};
84 virtual void DidChangeScrollOffset(blink::WebLocalFrame
* frame
) {}
85 virtual void DraggableRegionsChanged(blink::WebFrame
* frame
) {}
86 virtual void DidCommitCompositorFrame() {}
87 virtual void DidUpdateLayout() {}
89 // These match the RenderView methods.
90 virtual void DidHandleMouseEvent(const blink::WebMouseEvent
& event
) {}
91 virtual void DidHandleTouchEvent(const blink::WebTouchEvent
& event
) {}
93 // Called when we receive a console message from WebKit for which we requested
94 // extra details (like the stack trace). |message| is the error message,
95 // |source| is the WebKit-reported source of the error (either external or
96 // internal), and |stack_trace| is the stack trace of the error in a
97 // human-readable format (each frame is formatted as
98 // "\n at function_name (source:line_number:column_number)").
99 virtual void DetailedConsoleMessageAdded(const base::string16
& message
,
100 const base::string16
& source
,
101 const base::string16
& stack_trace
,
103 int32 severity_level
) {}
105 // These match incoming IPCs.
106 virtual void Navigate(const GURL
& url
) {}
107 virtual void ClosePage() {}
108 virtual void OrientationChangeEvent(int orientation
) {}
110 virtual void OnStop() {}
112 // IPC::Listener implementation.
113 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
115 // IPC::Sender implementation.
116 virtual bool Send(IPC::Message
* message
) OVERRIDE
;
118 RenderView
* render_view() const;
119 int routing_id() const { return routing_id_
; }
122 explicit RenderViewObserver(RenderView
* render_view
);
123 virtual ~RenderViewObserver();
126 friend class RenderViewImpl
;
128 // This is called by the RenderView when it's going away so that this object
129 // can null out its pointer.
130 void RenderViewGone();
132 RenderView
* render_view_
;
133 // The routing ID of the associated RenderView.
136 DISALLOW_COPY_AND_ASSIGN(RenderViewObserver
);
139 } // namespace content
141 #endif // CONTENT_PUBLIC_RENDERER_RENDER_VIEW_OBSERVER_H_