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 // Adds/removes a callback called on creation of each new RenderViewHost.
83 typedef base::Callback
<void(RenderViewHost
*)> CreatedCallback
;
84 static void AddCreatedCallback(const CreatedCallback
& callback
);
85 static void RemoveCreatedCallback(const CreatedCallback
& callback
);
87 virtual ~RenderViewHost() {}
89 // Tell the render view to enable a set of javascript bindings. The argument
90 // should be a combination of values from BindingsPolicy.
91 virtual void AllowBindings(int binding_flags
) = 0;
93 // Tells the renderer to clear the focused node (if any).
94 virtual void ClearFocusedNode() = 0;
96 // Causes the renderer to close the current page, including running its
97 // onunload event handler. A ClosePage_ACK message will be sent to the
98 // ResourceDispatcherHost when it is finished.
99 virtual void ClosePage() = 0;
101 // Copies the image at location x, y to the clipboard (if there indeed is an
102 // image at that location).
103 virtual void CopyImageAt(int x
, int y
) = 0;
105 // Notifies the renderer about the result of a desktop notification.
106 virtual void DesktopNotificationPermissionRequestDone(
107 int callback_context
) = 0;
108 virtual void DesktopNotificationPostDisplay(int callback_context
) = 0;
109 virtual void DesktopNotificationPostError(int notification_id
,
110 const string16
& message
) = 0;
111 virtual void DesktopNotificationPostClose(int notification_id
,
113 virtual void DesktopNotificationPostClick(int notification_id
) = 0;
115 // Notifies the listener that a directory enumeration is complete.
116 virtual void DirectoryEnumerationFinished(
118 const std::vector
<base::FilePath
>& files
) = 0;
120 // Tells the renderer not to add scrollbars with height and width below a
122 virtual void DisableScrollbarsForThreshold(const gfx::Size
& size
) = 0;
124 // Notifies the renderer that a a drag operation that it started has ended,
125 // either in a drop or by being cancelled.
126 virtual void DragSourceEndedAt(
127 int client_x
, int client_y
, int screen_x
, int screen_y
,
128 WebKit::WebDragOperation operation
) = 0;
130 // Notifies the renderer that a drag and drop operation is in progress, with
131 // droppable items positioned over the renderer's view.
132 virtual void DragSourceMovedTo(
133 int client_x
, int client_y
, int screen_x
, int screen_y
) = 0;
135 // Notifies the renderer that we're done with the drag and drop operation.
136 // This allows the renderer to reset some state.
137 virtual void DragSourceSystemDragEnded() = 0;
139 // D&d drop target messages that get sent to WebKit.
140 virtual void DragTargetDragEnter(
141 const DropData
& drop_data
,
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 DragTargetDragOver(
147 const gfx::Point
& client_pt
,
148 const gfx::Point
& screen_pt
,
149 WebKit::WebDragOperationsMask operations_allowed
,
150 int key_modifiers
) = 0;
151 virtual void DragTargetDragLeave() = 0;
152 virtual void DragTargetDrop(const gfx::Point
& client_pt
,
153 const gfx::Point
& screen_pt
,
154 int key_modifiers
) = 0;
156 // Instructs the RenderView to automatically resize and send back updates
158 virtual void EnableAutoResize(const gfx::Size
& min_size
,
159 const gfx::Size
& max_size
) = 0;
161 // Turns off auto-resize and gives a new size that the view should be.
162 virtual void DisableAutoResize(const gfx::Size
& new_size
) = 0;
164 // Instructs the RenderView to send back updates to the preferred size.
165 virtual void EnablePreferredSizeMode() = 0;
167 // Executes custom context menu action that was provided from WebKit.
168 virtual void ExecuteCustomContextMenuCommand(
169 int action
, const CustomContextMenuContext
& context
) = 0;
171 // Tells the renderer to perform the given action on the media player
172 // located at the given point.
173 virtual void ExecuteMediaPlayerActionAtLocation(
174 const gfx::Point
& location
,
175 const WebKit::WebMediaPlayerAction
& action
) = 0;
177 // Runs some javascript within the context of a frame in the page.
178 virtual void ExecuteJavascriptInWebFrame(const string16
& frame_xpath
,
179 const string16
& jscript
) = 0;
181 // Runs some javascript within the context of a frame in the page. The result
182 // is sent back via the provided callback.
183 typedef base::Callback
<void(const base::Value
*)> JavascriptResultCallback
;
184 virtual void ExecuteJavascriptInWebFrameCallbackResult(
185 const string16
& frame_xpath
,
186 const string16
& jscript
,
187 const JavascriptResultCallback
& callback
) = 0;
189 // Tells the renderer to perform the given action on the plugin located at
191 virtual void ExecutePluginActionAtLocation(
192 const gfx::Point
& location
, const WebKit::WebPluginAction
& action
) = 0;
194 // Asks the renderer to exit fullscreen
195 virtual void ExitFullscreen() = 0;
197 // Finds text on a page.
198 virtual void Find(int request_id
, const string16
& search_text
,
199 const WebKit::WebFindOptions
& options
) = 0;
201 // Notifies the renderer that the user has closed the FindInPage window
202 // (and what action to take regarding the selection).
203 virtual void StopFinding(StopFindAction action
) = 0;
205 // Causes the renderer to invoke the onbeforeunload event handler. The
206 // result will be returned via ViewMsg_ShouldClose. See also ClosePage and
207 // SwapOut, which fire the PageUnload event.
209 // Set bool for_cross_site_transition when this close is just for the current
210 // RenderView in the case of a cross-site transition. False means we're
211 // closing the entire tab.
212 virtual void FirePageBeforeUnload(bool for_cross_site_transition
) = 0;
214 // Notifies the Listener that one or more files have been chosen by the user
215 // from a file chooser dialog for the form. |permissions| is the file
216 // selection mode in which the chooser dialog was created.
217 virtual void FilesSelectedInChooser(
218 const std::vector
<ui::SelectedFileInfo
>& files
,
219 FileChooserParams::Mode permissions
) = 0;
221 virtual RenderViewHostDelegate
* GetDelegate() const = 0;
223 // Returns a bitwise OR of bindings types that have been enabled for this
224 // RenderView. See BindingsPolicy for details.
225 virtual int GetEnabledBindings() const = 0;
227 virtual SiteInstance
* GetSiteInstance() const = 0;
229 // Requests the renderer to evaluate an xpath to a frame and insert css
230 // into that frame's document.
231 virtual void InsertCSS(const string16
& frame_xpath
,
232 const std::string
& css
) = 0;
234 // Returns true if the RenderView is active and has not crashed. Virtual
235 // because it is overridden by TestRenderViewHost.
236 virtual bool IsRenderViewLive() const = 0;
238 // Returns true if the RenderView is responsible for displaying a subframe
239 // in a different process from its parent page.
240 virtual bool IsSubframe() const = 0;
242 // Let the renderer know that the menu has been closed.
243 virtual void NotifyContextMenuClosed(
244 const CustomContextMenuContext
& context
) = 0;
246 // Notification that a move or resize renderer's containing window has
248 virtual void NotifyMoveOrResizeStarted() = 0;
250 // Reloads the current focused frame.
251 virtual void ReloadFrame() = 0;
253 // Sets the alternate error page URL (link doctor) for the renderer process.
254 virtual void SetAltErrorPageURL(const GURL
& url
) = 0;
256 // Sets a property with the given name and value on the Web UI binding object.
257 // Must call AllowWebUIBindings() on this renderer first.
258 virtual void SetWebUIProperty(const std::string
& name
,
259 const std::string
& value
) = 0;
261 // Set the zoom level for the current main frame
262 virtual void SetZoomLevel(double level
) = 0;
264 // Changes the zoom level for the current main frame.
265 virtual void Zoom(PageZoom zoom
) = 0;
267 // Send the renderer process the current preferences supplied by the
268 // RenderViewHostDelegate.
269 virtual void SyncRendererPrefs() = 0;
271 virtual void ToggleSpeechInput() = 0;
273 // Returns the current WebKit preferences.
274 virtual WebPreferences
GetWebkitPreferences() = 0;
276 // Passes a list of Webkit preferences to the renderer.
277 virtual void UpdateWebkitPreferences(const WebPreferences
& prefs
) = 0;
279 // Informs the renderer process of a change in timezone.
280 virtual void NotifyTimezoneChange() = 0;
282 // Retrieves the list of AudioOutputController objects associated
283 // with this object and passes it to the callback you specify, on
284 // the same thread on which you called the method.
285 typedef std::list
<scoped_refptr
<media::AudioOutputController
> >
286 AudioOutputControllerList
;
287 typedef base::Callback
<void(const AudioOutputControllerList
&)>
288 GetAudioOutputControllersCallback
;
289 virtual void GetAudioOutputControllers(
290 const GetAudioOutputControllersCallback
& callback
) const = 0;
292 #if defined(OS_ANDROID)
293 // Selects and zooms to the find result nearest to the point (x,y)
294 // defined in find-in-page coordinates.
295 virtual void ActivateNearestFindResult(int request_id
, float x
, float y
) = 0;
297 // Asks the renderer to send the rects of the current find matches.
298 virtual void RequestFindMatchRects(int current_version
) = 0;
300 // Disables fullscreen media playback for encrypted video.
301 virtual void DisableFullscreenEncryptedMediaPlayback() = 0;
305 // This interface should only be implemented inside content.
306 friend class RenderViewHostImpl
;
310 } // namespace content
312 #endif // CONTENT_PUBLIC_BROWSER_RENDER_VIEW_HOST_H_