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