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