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