render_view_observer.h revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
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/web/WebIconURL.h" 14 15class GURL; 16 17namespace ppapi { 18namespace host { 19class PpapiHost; 20} 21} 22 23namespace WebKit { 24class WebDataSource; 25class WebFrame; 26class WebFormElement; 27class WebGestureEvent; 28class WebMediaPlayerClient; 29class WebMouseEvent; 30class WebNode; 31class WebTouchEvent; 32class WebURL; 33struct WebContextMenuData; 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(WebKit::WebFrame* frame) {} 56 virtual void DidFailLoad(WebKit::WebFrame* frame, 57 const WebKit::WebURLError& error) {} 58 virtual void DidFinishLoad(WebKit::WebFrame* frame) {} 59 virtual void DidStartProvisionalLoad(WebKit::WebFrame* frame) {} 60 virtual void DidFailProvisionalLoad(WebKit::WebFrame* frame, 61 const WebKit::WebURLError& error) {} 62 virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame, 63 bool is_new_navigation) {} 64 virtual void DidClearWindowObject(WebKit::WebFrame* frame) {} 65 virtual void WillPerformClientRedirect( 66 WebKit::WebFrame* frame, const WebKit::WebURL& from, 67 const WebKit::WebURL& to, double interval, double fire_time) {} 68 virtual void DidCancelClientRedirect(WebKit::WebFrame* frame) {} 69 virtual void DidCompleteClientRedirect(WebKit::WebFrame* frame, 70 const WebKit::WebURL& from) {} 71 virtual void DidCreateDocumentElement(WebKit::WebFrame* frame) {} 72 virtual void FrameCreated(WebKit::WebFrame* parent, 73 WebKit::WebFrame* frame) {} 74 virtual void FrameDetached(WebKit::WebFrame* frame) {} 75 virtual void FrameWillClose(WebKit::WebFrame* frame) {} 76 virtual void WillSubmitForm(WebKit::WebFrame* frame, 77 const WebKit::WebFormElement& form) {} 78 virtual void DidCreateDataSource(WebKit::WebFrame* frame, 79 WebKit::WebDataSource* ds) {} 80 virtual void PrintPage(WebKit::WebFrame* frame, bool user_initiated) {} 81 virtual void FocusedNodeChanged(const WebKit::WebNode& node) {} 82 virtual void WillCreateMediaPlayer(WebKit::WebFrame* frame, 83 WebKit::WebMediaPlayerClient* client) {} 84 virtual void ZoomLevelChanged() {}; 85 virtual void DidChangeScrollOffset(WebKit::WebFrame* frame) {} 86 virtual void DraggableRegionsChanged(WebKit::WebFrame* frame) {} 87 virtual void DidRequestShowContextMenu( 88 WebKit::WebFrame* frame, 89 const WebKit::WebContextMenuData& data) {} 90 virtual void DidCommitCompositorFrame() {} 91 92 // These match the RenderView methods. 93 virtual void DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {} 94 virtual void DidHandleTouchEvent(const WebKit::WebTouchEvent& event) {} 95 virtual void DidHandleGestureEvent(const WebKit::WebGestureEvent& event) {} 96 virtual void DidCreatePepperPlugin(RendererPpapiHost* host) {} 97 98 // These match incoming IPCs. 99 virtual void Navigate(const GURL& url) {} 100 virtual void ClosePage() {} 101 102 // IPC::Listener implementation. 103 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 104 105 protected: 106 explicit RenderViewObserver(RenderView* render_view); 107 virtual ~RenderViewObserver(); 108 109 // IPC::Sender implementation. 110 virtual bool Send(IPC::Message* message) OVERRIDE; 111 112 RenderView* render_view() const; 113 int routing_id() { return routing_id_; } 114 115 private: 116 friend class RenderViewImpl; 117 118 // This is called by the RenderView when it's going away so that this object 119 // can null out its pointer. 120 void RenderViewGone(); 121 122 RenderView* render_view_; 123 // The routing ID of the associated RenderView. 124 int routing_id_; 125 126 DISALLOW_COPY_AND_ASSIGN(RenderViewObserver); 127}; 128 129} // namespace content 130 131#endif // CONTENT_PUBLIC_RENDERER_RENDER_VIEW_OBSERVER_H_ 132