Popular sites on the NTP: Try to keep the ordering constant
[chromium-blink-merge.git] / content / public / browser / render_frame_host.h
blob0424979a088fdcbfe92491db901ede378799e9f0
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_BROWSER_RENDER_FRAME_HOST_H_
6 #define CONTENT_PUBLIC_BROWSER_RENDER_FRAME_HOST_H_
8 #include <string>
10 #include "base/callback_forward.h"
11 #include "content/common/content_export.h"
12 #include "content/public/common/console_message_level.h"
13 #include "ipc/ipc_listener.h"
14 #include "ipc/ipc_sender.h"
15 #include "third_party/WebKit/public/platform/WebPageVisibilityState.h"
16 #include "ui/gfx/geometry/rect.h"
17 #include "ui/gfx/native_widget_types.h"
18 #include "url/gurl.h"
20 namespace base {
21 class Value;
24 namespace content {
25 class RenderProcessHost;
26 class RenderViewHost;
27 class ServiceRegistry;
28 class SiteInstance;
30 // The interface provides a communication conduit with a frame in the renderer.
31 class CONTENT_EXPORT RenderFrameHost : public IPC::Listener,
32 public IPC::Sender {
33 public:
34 // Returns the RenderFrameHost given its ID and the ID of its render process.
35 // Returns nullptr if the IDs do not correspond to a live RenderFrameHost.
36 static RenderFrameHost* FromID(int render_process_id, int render_frame_id);
38 // Globally allows for injecting JavaScript into the main world. This feature
39 // is present only to support Android WebView and must not be used in other
40 // configurations.
41 static void AllowInjectingJavaScriptForAndroidWebView();
43 // Returns a RenderFrameHost given its accessibility tree ID.
44 static RenderFrameHost* FromAXTreeID(int ax_tree_id);
46 ~RenderFrameHost() override {}
48 // Returns the route id for this frame.
49 virtual int GetRoutingID() = 0;
51 // Returns the accessibility tree ID for this RenderFrameHost.
52 virtual int GetAXTreeID() = 0;
54 // Returns the SiteInstance grouping all RenderFrameHosts that have script
55 // access to this RenderFrameHost, and must therefore live in the same
56 // process.
57 virtual SiteInstance* GetSiteInstance() = 0;
59 // Returns the process for this frame.
60 virtual RenderProcessHost* GetProcess() = 0;
62 // Returns the current RenderFrameHost of the parent frame, or nullptr if
63 // there is no parent. The result may be in a different process than the
64 // current RenderFrameHost.
65 virtual RenderFrameHost* GetParent() = 0;
67 // Returns the assigned name of the frame, the name of the iframe tag
68 // declaring it. For example, <iframe name="framename">[...]</iframe>. It is
69 // quite possible for a frame to have no name, in which case GetFrameName will
70 // return an empty string.
71 virtual const std::string& GetFrameName() = 0;
73 // Returns true if the frame is out of process.
74 virtual bool IsCrossProcessSubframe() = 0;
76 // Returns the last committed URL of the frame.
77 virtual GURL GetLastCommittedURL() = 0;
79 // Returns the associated widget's native view.
80 virtual gfx::NativeView GetNativeView() = 0;
82 // Adds |message| to the DevTools console.
83 virtual void AddMessageToConsole(ConsoleMessageLevel level,
84 const std::string& message) = 0;
86 // Runs some JavaScript in this frame's context. If a callback is provided, it
87 // will be used to return the result, when the result is available.
88 // This API can only be called on chrome:// or chrome-devtools:// URLs.
89 typedef base::Callback<void(const base::Value*)> JavaScriptResultCallback;
90 virtual void ExecuteJavaScript(const base::string16& javascript) = 0;
91 virtual void ExecuteJavaScript(const base::string16& javascript,
92 const JavaScriptResultCallback& callback) = 0;
94 // Runs some JavaScript in an isolated world of top of this frame's context.
95 virtual void ExecuteJavaScriptInIsolatedWorld(
96 const base::string16& javascript,
97 const JavaScriptResultCallback& callback,
98 int world_id) = 0;
100 // ONLY FOR TESTS: Same as above but without restrictions. Optionally, adds a
101 // fake UserGestureIndicator around execution. (crbug.com/408426)
102 virtual void ExecuteJavaScriptForTests(const base::string16& javascript) = 0;
103 virtual void ExecuteJavaScriptForTests(
104 const base::string16& javascript,
105 const JavaScriptResultCallback& callback) = 0;
106 virtual void ExecuteJavaScriptWithUserGestureForTests(
107 const base::string16& javascript) = 0;
109 // Accessibility actions - these send a message to the RenderFrame
110 // to trigger an action on an accessibility object.
111 virtual void AccessibilitySetFocus(int acc_obj_id) = 0;
112 virtual void AccessibilityDoDefaultAction(int acc_obj_id) = 0;
113 virtual void AccessibilityScrollToMakeVisible(
114 int acc_obj_id, const gfx::Rect& subfocus) = 0;
115 virtual void AccessibilityShowContextMenu(int acc_obj_id) = 0;
116 virtual void AccessibilitySetTextSelection(
117 int acc_obj_id, int start_offset, int end_offset) = 0;
119 // This is called when the user has committed to the given find in page
120 // request (e.g. by pressing enter or by clicking on the next / previous
121 // result buttons). It triggers sending a native accessibility event on
122 // the result object on the page, navigating assistive technology to that
123 // result.
124 virtual void ActivateFindInPageResultForAccessibility(int request_id) = 0;
126 // Roundtrips through the renderer and compositor pipeline to ensure that any
127 // changes to the contents resulting from operations executed prior to this
128 // call are visible on screen. The call completes asynchronously by running
129 // the supplied |callback| with a value of true upon successful completion and
130 // false otherwise (when the frame is destroyed, detached, etc..).
131 typedef base::Callback<void(bool)> VisualStateCallback;
132 virtual void InsertVisualStateCallback(
133 const VisualStateCallback& callback) = 0;
135 // Temporary until we get rid of RenderViewHost.
136 virtual RenderViewHost* GetRenderViewHost() = 0;
138 // Returns the ServiceRegistry for this frame.
139 virtual ServiceRegistry* GetServiceRegistry() = 0;
141 // Returns the visibility state of the frame. The different visibility states
142 // of a frame are defined in Blink.
143 virtual blink::WebPageVisibilityState GetVisibilityState() = 0;
145 // Returns whether the RenderFrame in the renderer process has been created
146 // and still has a connection. This is valid for all frames.
147 virtual bool IsRenderFrameLive() = 0;
149 private:
150 // This interface should only be implemented inside content.
151 friend class RenderFrameHostImpl;
152 RenderFrameHost() {}
155 } // namespace content
157 #endif // CONTENT_PUBLIC_BROWSER_RENDER_FRAME_HOST_H_