render_frame_observer.h revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
1b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato// Copyright 2013 The Chromium Authors. All rights reserved.
2b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato// Use of this source code is governed by a BSD-style license that can be
3b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato// found in the LICENSE file.
4b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
5b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang#ifndef CONTENT_PUBLIC_RENDERER_RENDER_FRAME_OBSERVER_H_
6b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang#define CONTENT_PUBLIC_RENDERER_RENDER_FRAME_OBSERVER_H_
7b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang
8b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang#include "base/basictypes.h"
9b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato#include "base/compiler_specific.h"
10b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang#include "base/strings/string16.h"
11b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato#include "content/common/content_export.h"
12b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang#include "ipc/ipc_listener.h"
13b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang#include "ipc/ipc_sender.h"
14b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang#include "v8/include/v8.h"
15b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang
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  // These match the Blink API notifications
43  virtual void DidCommitProvisionalLoad(bool is_new_navigation) {}
44  virtual void DidStartProvisionalLoad() {}
45  virtual void DidFailProvisionalLoad(const blink::WebURLError& error) {}
46  virtual void DidFinishLoad() {}
47  virtual void DidFinishDocumentLoad() {}
48  virtual void WillReleaseScriptContext(v8::Handle<v8::Context> context,
49                                        int world_id) {}
50  virtual void DidClearWindowObject(int world_id) {}
51
52  // Called when we receive a console message from Blink for which we requested
53  // extra details (like the stack trace). |message| is the error message,
54  // |source| is the Blink-reported source of the error (either external or
55  // internal), and |stack_trace| is the stack trace of the error in a
56  // human-readable format (each frame is formatted as
57  // "\n    at function_name (source:line_number:column_number)").
58  virtual void DetailedConsoleMessageAdded(const base::string16& message,
59                                           const base::string16& source,
60                                           const base::string16& stack_trace,
61                                           int32 line_number,
62                                           int32 severity_level) {}
63
64  // IPC::Listener implementation.
65  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
66
67  // IPC::Sender implementation.
68  virtual bool Send(IPC::Message* message) OVERRIDE;
69
70  RenderFrame* render_frame() const;
71  int routing_id() const { return routing_id_; }
72
73 protected:
74  explicit RenderFrameObserver(RenderFrame* render_frame);
75  virtual ~RenderFrameObserver();
76
77 private:
78  friend class RenderFrameImpl;
79
80  // This is called by the RenderFrame when it's going away so that this object
81  // can null out its pointer.
82  void RenderFrameGone();
83
84  RenderFrame* render_frame_;
85  // The routing ID of the associated RenderFrame.
86  int routing_id_;
87
88  DISALLOW_COPY_AND_ASSIGN(RenderFrameObserver);
89};
90
91}  // namespace content
92
93#endif  // CONTENT_PUBLIC_RENDERER_RENDER_FRAME_OBSERVER_H_
94