render_view_host.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
1// Copyright (c) 2012 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_PUBLIC_BROWSER_RENDER_VIEW_HOST_H_
6#define CONTENT_PUBLIC_BROWSER_RENDER_VIEW_HOST_H_
7
8#include "base/callback_forward.h"
9#include "content/common/content_export.h"
10#include "content/public/browser/render_widget_host.h"
11#include "content/public/common/page_zoom.h"
12#include "content/public/common/stop_find_action.h"
13#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h"
14
15class GURL;
16struct WebDropData;
17
18namespace gfx {
19class Point;
20}
21
22namespace base {
23class FilePath;
24class Value;
25}
26
27namespace ui {
28struct SelectedFileInfo;
29}
30
31namespace WebKit {
32struct WebFindOptions;
33struct WebMediaPlayerAction;
34struct WebPluginAction;
35}
36
37namespace webkit_glue {
38struct WebPreferences;
39}
40
41namespace content {
42
43class ChildProcessSecurityPolicy;
44class RenderProcessHost;
45class RenderViewHostDelegate;
46class SessionStorageNamespace;
47class SiteInstance;
48struct CustomContextMenuContext;
49
50// A RenderViewHost is responsible for creating and talking to a RenderView
51// object in a child process. It exposes a high level API to users, for things
52// like loading pages, adjusting the display and other browser functionality,
53// which it translates into IPC messages sent over the IPC channel with the
54// RenderView. It responds to all IPC messages sent by that RenderView and
55// cracks them, calling a delegate object back with higher level types where
56// possible.
57//
58// The intent of this interface is to provide a view-agnostic communication
59// conduit with a renderer. This is so we can build HTML views not only as
60// WebContents (see WebContents for an example) but also as views, etc.
61class CONTENT_EXPORT RenderViewHost : virtual public RenderWidgetHost {
62 public:
63  typedef base::Callback<void(const base::Value*)> JavascriptResultCallback;
64
65  // Returns the RenderViewHost given its ID and the ID of its render process.
66  // Returns NULL if the IDs do not correspond to a live RenderViewHost.
67  static RenderViewHost* FromID(int render_process_id, int render_view_id);
68
69  // Downcasts from a RenderWidgetHost to a RenderViewHost.  Required
70  // because RenderWidgetHost is a virtual base class.
71  static RenderViewHost* From(RenderWidgetHost* rwh);
72
73  // Checks that the given renderer can request |url|, if not it sets it to
74  // about:blank.
75  // |empty_allowed| must be set to false for navigations for security reasons.
76  static void FilterURL(const RenderProcessHost* process,
77                        bool empty_allowed,
78                        GURL* url);
79
80  virtual ~RenderViewHost() {}
81
82  // Tell the render view to enable a set of javascript bindings. The argument
83  // should be a combination of values from BindingsPolicy.
84  virtual void AllowBindings(int binding_flags) = 0;
85
86  // Tells the renderer to clear the focused node (if any).
87  virtual void ClearFocusedNode() = 0;
88
89  // Causes the renderer to close the current page, including running its
90  // onunload event handler.  A ClosePage_ACK message will be sent to the
91  // ResourceDispatcherHost when it is finished.
92  virtual void ClosePage() = 0;
93
94  // Copies the image at location x, y to the clipboard (if there indeed is an
95  // image at that location).
96  virtual void CopyImageAt(int x, int y) = 0;
97
98  // Sent to the renderer when a popup window should no longer count against
99  // the current popup count (either because it's not a popup or because it was
100  // a generated by a user action).
101  virtual void DisassociateFromPopupCount() = 0;
102
103  // Notifies the renderer about the result of a desktop notification.
104  virtual void DesktopNotificationPermissionRequestDone(
105      int callback_context) = 0;
106  virtual void DesktopNotificationPostDisplay(int callback_context) = 0;
107  virtual void DesktopNotificationPostError(int notification_id,
108                                    const string16& message) = 0;
109  virtual void DesktopNotificationPostClose(int notification_id,
110                                            bool by_user) = 0;
111  virtual void DesktopNotificationPostClick(int notification_id) = 0;
112
113  // Notifies the listener that a directory enumeration is complete.
114  virtual void DirectoryEnumerationFinished(
115      int request_id,
116      const std::vector<base::FilePath>& files) = 0;
117
118  // Tells the renderer not to add scrollbars with height and width below a
119  // threshold.
120  virtual void DisableScrollbarsForThreshold(const gfx::Size& size) = 0;
121
122  // Notifies the renderer that a a drag operation that it started has ended,
123  // either in a drop or by being cancelled.
124  virtual void DragSourceEndedAt(
125      int client_x, int client_y, int screen_x, int screen_y,
126      WebKit::WebDragOperation operation) = 0;
127
128  // Notifies the renderer that a drag and drop operation is in progress, with
129  // droppable items positioned over the renderer's view.
130  virtual void DragSourceMovedTo(
131      int client_x, int client_y, int screen_x, int screen_y) = 0;
132
133  // Notifies the renderer that we're done with the drag and drop operation.
134  // This allows the renderer to reset some state.
135  virtual void DragSourceSystemDragEnded() = 0;
136
137  // D&d drop target messages that get sent to WebKit.
138  virtual void DragTargetDragEnter(
139      const WebDropData& drop_data,
140      const gfx::Point& client_pt,
141      const gfx::Point& screen_pt,
142      WebKit::WebDragOperationsMask operations_allowed,
143      int key_modifiers) = 0;
144  virtual void DragTargetDragOver(
145      const gfx::Point& client_pt,
146      const gfx::Point& screen_pt,
147      WebKit::WebDragOperationsMask operations_allowed,
148      int key_modifiers) = 0;
149  virtual void DragTargetDragLeave() = 0;
150  virtual void DragTargetDrop(const gfx::Point& client_pt,
151                              const gfx::Point& screen_pt,
152                              int key_modifiers) = 0;
153
154  // Instructs the RenderView to automatically resize and send back updates
155  // for the new size.
156  virtual void EnableAutoResize(const gfx::Size& min_size,
157                                const gfx::Size& max_size) = 0;
158
159  // Turns off auto-resize and gives a new size that the view should be.
160  virtual void DisableAutoResize(const gfx::Size& new_size) = 0;
161
162  // Instructs the RenderView to send back updates to the preferred size.
163  virtual void EnablePreferredSizeMode() = 0;
164
165  // Executes custom context menu action that was provided from WebKit.
166  virtual void ExecuteCustomContextMenuCommand(
167      int action, const CustomContextMenuContext& context) = 0;
168
169  // Tells the renderer to perform the given action on the media player
170  // located at the given point.
171  virtual void ExecuteMediaPlayerActionAtLocation(
172      const gfx::Point& location,
173      const WebKit::WebMediaPlayerAction& action) = 0;
174
175  // Runs some javascript within the context of a frame in the page.
176  virtual void ExecuteJavascriptInWebFrame(const string16& frame_xpath,
177                                           const string16& jscript) = 0;
178
179  // Runs some javascript within the context of a frame in the page. The result
180  // is sent back via the provided callback.
181  virtual void ExecuteJavascriptInWebFrameCallbackResult(
182      const string16& frame_xpath,
183      const string16& jscript,
184      const JavascriptResultCallback& callback) = 0;
185
186  // Tells the renderer to perform the given action on the plugin located at
187  // the given point.
188  virtual void ExecutePluginActionAtLocation(
189      const gfx::Point& location, const WebKit::WebPluginAction& action) = 0;
190
191  // Asks the renderer to exit fullscreen
192  virtual void ExitFullscreen() = 0;
193
194  // Finds text on a page.
195  virtual void Find(int request_id, const string16& search_text,
196                    const WebKit::WebFindOptions& options) = 0;
197
198  // Notifies the renderer that the user has closed the FindInPage window
199  // (and what action to take regarding the selection).
200  virtual void StopFinding(StopFindAction action) = 0;
201
202  // Causes the renderer to invoke the onbeforeunload event handler.  The
203  // result will be returned via ViewMsg_ShouldClose. See also ClosePage and
204  // SwapOut, which fire the PageUnload event.
205  //
206  // Set bool for_cross_site_transition when this close is just for the current
207  // RenderView in the case of a cross-site transition. False means we're
208  // closing the entire tab.
209  virtual void FirePageBeforeUnload(bool for_cross_site_transition) = 0;
210
211  // Notifies the Listener that one or more files have been chosen by the user
212  // from a file chooser dialog for the form. |permissions| are flags from the
213  // base::PlatformFileFlags enum which specify which file permissions should
214  // be granted to the renderer.
215  virtual void FilesSelectedInChooser(
216      const std::vector<ui::SelectedFileInfo>& files,
217      int permissions) = 0;
218
219  virtual RenderViewHostDelegate* GetDelegate() const = 0;
220
221  // Returns a bitwise OR of bindings types that have been enabled for this
222  // RenderView. See BindingsPolicy for details.
223  virtual int GetEnabledBindings() const = 0;
224
225  virtual SiteInstance* GetSiteInstance() const = 0;
226
227  // Requests the renderer to evaluate an xpath to a frame and insert css
228  // into that frame's document.
229  virtual void InsertCSS(const string16& frame_xpath,
230                         const std::string& css) = 0;
231
232  // Returns true if the RenderView is active and has not crashed. Virtual
233  // because it is overridden by TestRenderViewHost.
234  virtual bool IsRenderViewLive() const = 0;
235
236  // Returns true if the RenderView is responsible for displaying a subframe
237  // in a different process from its parent page.
238  virtual bool IsSubframe() const = 0;
239
240  // Let the renderer know that the menu has been closed.
241  virtual void NotifyContextMenuClosed(
242      const CustomContextMenuContext& context) = 0;
243
244  // Notification that a move or resize renderer's containing window has
245  // started.
246  virtual void NotifyMoveOrResizeStarted() = 0;
247
248  // Reloads the current focused frame.
249  virtual void ReloadFrame() = 0;
250
251  // Sets the alternate error page URL (link doctor) for the renderer process.
252  virtual void SetAltErrorPageURL(const GURL& url) = 0;
253
254  // Sets a property with the given name and value on the Web UI binding object.
255  // Must call AllowWebUIBindings() on this renderer first.
256  virtual void SetWebUIProperty(const std::string& name,
257                                const std::string& value) = 0;
258
259  // Set the zoom level for the current main frame
260  virtual void SetZoomLevel(double level) = 0;
261
262  // Changes the zoom level for the current main frame.
263  virtual void Zoom(PageZoom zoom) = 0;
264
265  // Send the renderer process the current preferences supplied by the
266  // RenderViewHostDelegate.
267  virtual void SyncRendererPrefs() = 0;
268
269  virtual void ToggleSpeechInput() = 0;
270
271  // Returns the current WebKit preferences.
272  virtual webkit_glue::WebPreferences GetWebkitPreferences() = 0;
273
274  // Passes a list of Webkit preferences to the renderer.
275  virtual void UpdateWebkitPreferences(
276      const webkit_glue::WebPreferences& prefs) = 0;
277
278  // Informs the renderer process of a change in timezone.
279  virtual void NotifyTimezoneChange() = 0;
280
281#if defined(OS_ANDROID)
282  // Selects and zooms to the find result nearest to the point (x,y)
283  // defined in find-in-page coordinates.
284  virtual void ActivateNearestFindResult(int request_id, float x, float y) = 0;
285
286  // Asks the renderer to send the rects of the current find matches.
287  virtual void RequestFindMatchRects(int current_version) = 0;
288#endif
289
290 private:
291  // This interface should only be implemented inside content.
292  friend class RenderViewHostImpl;
293  RenderViewHost() {}
294};
295
296}  // namespace content
297
298#endif  // CONTENT_PUBLIC_BROWSER_RENDER_VIEW_HOST_H_
299