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