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 "base/strings/string16.h" 11#include "content/common/content_export.h" 12#include "ipc/ipc_listener.h" 13#include "ipc/ipc_sender.h" 14#include "v8/include/v8.h" 15 16namespace blink { 17class WebFrame; 18struct WebURLError; 19} 20 21namespace content { 22 23class RendererPpapiHost; 24class RenderFrame; 25class RenderFrameImpl; 26 27// Base class for objects that want to filter incoming IPCs, and also get 28// notified of changes to the frame. 29class CONTENT_EXPORT RenderFrameObserver : public IPC::Listener, 30 public IPC::Sender { 31 public: 32 // By default, observers will be deleted when the RenderFrame goes away. If 33 // they want to outlive it, they can override this function. 34 virtual void OnDestruct(); 35 36 // Called when a Pepper plugin is created. 37 virtual void DidCreatePepperPlugin(RendererPpapiHost* host) {} 38 39 // Called when a load is explicitly stopped by the user or browser. 40 virtual void OnStop() {} 41 42 // Called when the RenderFrame visiblity is changed. 43 virtual void WasHidden() {} 44 virtual void WasShown() {} 45 46 // These match the Blink API notifications 47 virtual void DidCommitProvisionalLoad(bool is_new_navigation) {} 48 virtual void DidStartProvisionalLoad() {} 49 virtual void DidFailProvisionalLoad(const blink::WebURLError& error) {} 50 virtual void DidFinishLoad() {} 51 virtual void DidFinishDocumentLoad() {} 52 virtual void WillReleaseScriptContext(v8::Handle<v8::Context> context, 53 int world_id) {} 54 virtual void DidClearWindowObject() {} 55 virtual void DidChangeName(const base::string16& name) {} 56 virtual void DidChangeManifest() {} 57 58 // Called when the frame will soon be closed. This is the last opportunity to 59 // send messages to the host (e.g., for clean-up, shutdown, etc.). 60 virtual void FrameWillClose() {} 61 62 // Called when we receive a console message from Blink for which we requested 63 // extra details (like the stack trace). |message| is the error message, 64 // |source| is the Blink-reported source of the error (either external or 65 // internal), and |stack_trace| is the stack trace of the error in a 66 // human-readable format (each frame is formatted as 67 // "\n at function_name (source:line_number:column_number)"). 68 virtual void DetailedConsoleMessageAdded(const base::string16& message, 69 const base::string16& source, 70 const base::string16& stack_trace, 71 int32 line_number, 72 int32 severity_level) {} 73 74 // Called when a compositor frame has committed. 75 virtual void DidCommitCompositorFrame() {} 76 77 // IPC::Listener implementation. 78 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 79 80 // IPC::Sender implementation. 81 virtual bool Send(IPC::Message* message) OVERRIDE; 82 83 RenderFrame* render_frame() const; 84 int routing_id() const { return routing_id_; } 85 86 protected: 87 explicit RenderFrameObserver(RenderFrame* render_frame); 88 virtual ~RenderFrameObserver(); 89 90 private: 91 friend class RenderFrameImpl; 92 93 // This is called by the RenderFrame when it's going away so that this object 94 // can null out its pointer. 95 void RenderFrameGone(); 96 97 RenderFrame* render_frame_; 98 // The routing ID of the associated RenderFrame. 99 int routing_id_; 100 101 DISALLOW_COPY_AND_ASSIGN(RenderFrameObserver); 102}; 103 104} // namespace content 105 106#endif // CONTENT_PUBLIC_RENDERER_RENDER_FRAME_OBSERVER_H_ 107