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.
5 #ifndef CONTENT_PUBLIC_RENDERER_RENDER_FRAME_OBSERVER_H_
6 #define CONTENT_PUBLIC_RENDERER_RENDER_FRAME_OBSERVER_H_
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"
23 class RendererPpapiHost
;
25 class RenderFrameImpl
;
27 // Base class for objects that want to filter incoming IPCs, and also get
28 // notified of changes to the frame.
29 class CONTENT_EXPORT RenderFrameObserver
: public IPC::Listener
,
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();
36 // Called when a Pepper plugin is created.
37 virtual void DidCreatePepperPlugin(RendererPpapiHost
* host
) {}
39 // Called when a load is explicitly stopped by the user or browser.
40 virtual void OnStop() {}
42 // Called when the RenderFrame visiblity is changed.
43 virtual void WasHidden() {}
44 virtual void WasShown() {}
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
,
54 virtual void DidClearWindowObject() {}
55 virtual void DidChangeName(const base::string16
& name
) {}
56 virtual void DidChangeManifest() {}
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() {}
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
,
72 int32 severity_level
) {}
74 // Called when a compositor frame has committed.
75 virtual void DidCommitCompositorFrame() {}
77 // IPC::Listener implementation.
78 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
80 // IPC::Sender implementation.
81 virtual bool Send(IPC::Message
* message
) OVERRIDE
;
83 RenderFrame
* render_frame() const;
84 int routing_id() const { return routing_id_
; }
87 explicit RenderFrameObserver(RenderFrame
* render_frame
);
88 virtual ~RenderFrameObserver();
91 friend class RenderFrameImpl
;
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();
97 RenderFrame
* render_frame_
;
98 // The routing ID of the associated RenderFrame.
101 DISALLOW_COPY_AND_ASSIGN(RenderFrameObserver
);
104 } // namespace content
106 #endif // CONTENT_PUBLIC_RENDERER_RENDER_FRAME_OBSERVER_H_