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 "third_party/WebKit/public/platform/WebVector.h"
15 #include "v8/include/v8.h"
27 class RendererPpapiHost
;
29 class RenderFrameImpl
;
31 // Base class for objects that want to filter incoming IPCs, and also get
32 // notified of changes to the frame.
33 class CONTENT_EXPORT RenderFrameObserver
: public IPC::Listener
,
36 // By default, observers will be deleted when the RenderFrame goes away. If
37 // they want to outlive it, they can override this function.
38 virtual void OnDestruct();
40 // Called when a Pepper plugin is created.
41 virtual void DidCreatePepperPlugin(RendererPpapiHost
* host
) {}
43 // Called when a load is explicitly stopped by the user or browser.
44 virtual void OnStop() {}
46 // Called when the RenderFrame visiblity is changed.
47 virtual void WasHidden() {}
48 virtual void WasShown() {}
50 // Called when associated widget is about to close.
51 virtual void WidgetWillClose() {}
53 // These match the Blink API notifications
54 virtual void DidCreateNewDocument() {}
55 virtual void DidCreateDocumentElement() {}
56 virtual void DidCommitProvisionalLoad(bool is_new_navigation
,
57 bool is_same_page_navigation
) {}
58 virtual void DidStartProvisionalLoad() {}
59 virtual void DidFailProvisionalLoad(const blink::WebURLError
& error
) {}
60 virtual void DidFinishLoad() {}
61 virtual void DidFinishDocumentLoad() {}
62 virtual void DidCreateScriptContext(v8::Local
<v8::Context
> context
,
65 virtual void WillReleaseScriptContext(v8::Local
<v8::Context
> context
,
67 virtual void DidClearWindowObject() {}
68 virtual void DidChangeManifest() {}
69 virtual void DidChangeScrollOffset() {}
70 virtual void WillSendSubmitEvent(const blink::WebFormElement
& form
) {}
71 virtual void WillSubmitForm(const blink::WebFormElement
& form
) {}
72 virtual void DidMatchCSS(
73 const blink::WebVector
<blink::WebString
>& newly_matching_selectors
,
74 const blink::WebVector
<blink::WebString
>& stopped_matching_selectors
) {}
76 // Called before FrameWillClose, when this frame has been detached from the
77 // view, but has not been closed yet. This *will* be called when parent frames
78 // are closing. Since the frame is already detached from the DOM at this time
79 // it should not be inspected.
80 virtual void FrameDetached() {}
82 // Called when the frame will soon be closed. This is the last opportunity to
83 // send messages to the host (e.g., for clean-up, shutdown, etc.). This is
84 // *not* called on child frames when parent frames are being closed.
85 virtual void FrameWillClose() {}
87 // Called when we receive a console message from Blink for which we requested
88 // extra details (like the stack trace). |message| is the error message,
89 // |source| is the Blink-reported source of the error (either external or
90 // internal), and |stack_trace| is the stack trace of the error in a
91 // human-readable format (each frame is formatted as
92 // "\n at function_name (source:line_number:column_number)").
93 virtual void DetailedConsoleMessageAdded(const base::string16
& message
,
94 const base::string16
& source
,
95 const base::string16
& stack_trace
,
97 int32 severity_level
) {}
99 // Called when a compositor frame has committed.
100 virtual void DidCommitCompositorFrame() {}
102 // Notifications when |PerformanceTiming| data becomes available
103 virtual void DidChangePerformanceTiming() {}
105 // Called when the focused node has changed to |node|.
106 virtual void FocusedNodeChanged(const blink::WebNode
& node
) {}
108 // IPC::Listener implementation.
109 bool OnMessageReceived(const IPC::Message
& message
) override
;
111 // IPC::Sender implementation.
112 bool Send(IPC::Message
* message
) override
;
114 RenderFrame
* render_frame() const;
115 int routing_id() const { return routing_id_
; }
118 explicit RenderFrameObserver(RenderFrame
* render_frame
);
119 ~RenderFrameObserver() override
;
122 friend class RenderFrameImpl
;
124 // This is called by the RenderFrame when it's going away so that this object
125 // can null out its pointer.
126 void RenderFrameGone();
128 RenderFrame
* render_frame_
;
129 // The routing ID of the associated RenderFrame.
132 DISALLOW_COPY_AND_ASSIGN(RenderFrameObserver
);
135 } // namespace content
137 #endif // CONTENT_PUBLIC_RENDERER_RENDER_FRAME_OBSERVER_H_