render_frame_observer.h revision effb81e5f8246d0db0270817048dc992db66e9fb
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 DidFinishDocumentLoad() {} 47 virtual void WillReleaseScriptContext(v8::Handle<v8::Context> context, 48 int world_id) {} 49 virtual void DidClearWindowObject(int world_id) {} 50 51 // IPC::Listener implementation. 52 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 53 54 // IPC::Sender implementation. 55 virtual bool Send(IPC::Message* message) OVERRIDE; 56 57 RenderFrame* render_frame() const; 58 int routing_id() const { return routing_id_; } 59 60 protected: 61 explicit RenderFrameObserver(RenderFrame* render_frame); 62 virtual ~RenderFrameObserver(); 63 64 private: 65 friend class RenderFrameImpl; 66 67 // This is called by the RenderFrame when it's going away so that this object 68 // can null out its pointer. 69 void RenderFrameGone(); 70 71 RenderFrame* render_frame_; 72 // The routing ID of the associated RenderFrame. 73 int routing_id_; 74 75 DISALLOW_COPY_AND_ASSIGN(RenderFrameObserver); 76}; 77 78} // namespace content 79 80#endif // CONTENT_PUBLIC_RENDERER_RENDER_FRAME_OBSERVER_H_ 81