render_frame_host_delegate.h revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
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_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_DELEGATE_H_
6#define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_DELEGATE_H_
7
8#include "base/basictypes.h"
9#include "content/common/content_export.h"
10#include "content/public/common/javascript_message_type.h"
11
12class GURL;
13
14namespace IPC {
15class Message;
16}
17
18namespace content {
19class RenderFrameHost;
20class WebContents;
21struct ContextMenuParams;
22
23// An interface implemented by an object interested in knowing about the state
24// of the RenderFrameHost.
25class CONTENT_EXPORT RenderFrameHostDelegate {
26 public:
27  // This is used to give the delegate a chance to filter IPC messages.
28  virtual bool OnMessageReceived(RenderFrameHost* render_frame_host,
29                                 const IPC::Message& message);
30
31  // Gets the last committed URL. See WebContents::GetLastCommittedURL for a
32  // description of the semantics.
33  virtual const GURL& GetMainFrameLastCommittedURL() const;
34
35  // A message was added to to the console.
36  virtual bool AddMessageToConsole(int32 level,
37                                   const base::string16& message,
38                                   int32 line_no,
39                                   const base::string16& source_id);
40
41  // Informs the delegate whenever a RenderFrameHost is created.
42  virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) {}
43
44  // Informs the delegate whenever a RenderFrameHost is deleted.
45  virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) {}
46
47  // The top-level RenderFrame began loading a new page. This corresponds to
48  // Blink's notion of the throbber starting.
49  // |to_different_document| will be true unless the load is a fragment
50  // navigation, or triggered by history.pushState/replaceState.
51  virtual void DidStartLoading(RenderFrameHost* render_frame_host,
52                               bool to_different_document) {}
53
54  // The top-level RenderFrame stopped loading a page. This corresponds to
55  // Blink's notion of the throbber stopping.
56  virtual void DidStopLoading(RenderFrameHost* render_frame_host) {}
57
58  // The RenderFrameHost has been swapped out.
59  virtual void SwappedOut(RenderFrameHost* render_frame_host) {}
60
61  // Notification that a worker process has crashed.
62  virtual void WorkerCrashed(RenderFrameHost* render_frame_host) {}
63
64  // A context menu should be shown, to be built using the context information
65  // provided in the supplied params.
66  virtual void ShowContextMenu(RenderFrameHost* render_frame_host,
67                               const ContextMenuParams& params) {}
68
69  // A JavaScript message, confirmation or prompt should be shown.
70  virtual void RunJavaScriptMessage(RenderFrameHost* rfh,
71                                    const base::string16& message,
72                                    const base::string16& default_prompt,
73                                    const GURL& frame_url,
74                                    JavaScriptMessageType type,
75                                    IPC::Message* reply_msg) {}
76
77  virtual void RunBeforeUnloadConfirm(RenderFrameHost* rfh,
78                                      const base::string16& message,
79                                      bool is_reload,
80                                      IPC::Message* reply_msg) {}
81
82  // Return this object cast to a WebContents, if it is one. If the object is
83  // not a WebContents, returns NULL.
84  virtual WebContents* GetAsWebContents();
85
86 protected:
87  virtual ~RenderFrameHostDelegate() {}
88};
89
90}  // namespace content
91
92#endif  // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_DELEGATE_H_
93