render_frame_observer.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
1// Copyright 2013 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_FRAME_OBSERVER_H_ 6#define CONTENT_PUBLIC_RENDERER_RENDER_FRAME_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 "v8/include/v8.h" 14 15namespace blink { 16class WebFrame; 17struct WebURLError; 18} 19 20namespace content { 21 22class RendererPpapiHost; 23class RenderFrame; 24class RenderFrameImpl; 25 26// Base class for objects that want to filter incoming IPCs, and also get 27// notified of changes to the frame. 28class CONTENT_EXPORT RenderFrameObserver : public IPC::Listener, 29 public IPC::Sender { 30 public: 31 // By default, observers will be deleted when the RenderFrame goes away. If 32 // they want to outlive it, they can override this function. 33 virtual void OnDestruct(); 34 35 // Called when a Pepper plugin is created. 36 virtual void DidCreatePepperPlugin(RendererPpapiHost* host) {} 37 38 // Called when a load is explicitly stopped by the user or browser. 39 virtual void OnStop() {} 40 41 // These match the Blink API notifications 42 virtual void DidCommitProvisionalLoad(bool is_new_navigation) {} 43 virtual void DidStartProvisionalLoad() {} 44 virtual void DidFailProvisionalLoad(const blink::WebURLError& error) {} 45 virtual void DidFinishLoad() {} 46 virtual void WillReleaseScriptContext(v8::Handle<v8::Context> context, 47 int world_id) {} 48 virtual void DidClearWindowObject(int world_id) {} 49 50 // IPC::Listener implementation. 51 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 52 53 // IPC::Sender implementation. 54 virtual bool Send(IPC::Message* message) OVERRIDE; 55 56 RenderFrame* render_frame() const; 57 int routing_id() const { return routing_id_; } 58 59 protected: 60 explicit RenderFrameObserver(RenderFrame* render_frame); 61 virtual ~RenderFrameObserver(); 62 63 private: 64 friend class RenderFrameImpl; 65 66 // This is called by the RenderFrame when it's going away so that this object 67 // can null out its pointer. 68 void RenderFrameGone(); 69 70 RenderFrame* render_frame_; 71 // The routing ID of the associated RenderFrame. 72 int routing_id_; 73 74 DISALLOW_COPY_AND_ASSIGN(RenderFrameObserver); 75}; 76 77} // namespace content 78 79#endif // CONTENT_PUBLIC_RENDERER_RENDER_FRAME_OBSERVER_H_ 80