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_
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"
17 struct WebPreferences
;
29 struct SelectedFileInfo
;
33 struct WebFindOptions
;
34 struct WebMediaPlayerAction
;
35 struct WebPluginAction
;
40 class ChildProcessSecurityPolicy
;
41 class RenderProcessHost
;
42 class RenderViewHostDelegate
;
43 class SessionStorageNamespace
;
45 struct CustomContextMenuContext
;
47 // A RenderViewHost is responsible for creating and talking to a RenderView
48 // object in a child process. It exposes a high level API to users, for things
49 // like loading pages, adjusting the display and other browser functionality,
50 // which it translates into IPC messages sent over the IPC channel with the
51 // RenderView. It responds to all IPC messages sent by that RenderView and
52 // cracks them, calling a delegate object back with higher level types where
55 // The intent of this interface is to provide a view-agnostic communication
56 // conduit with a renderer. This is so we can build HTML views not only as
57 // WebContents (see WebContents for an example) but also as views, etc.
58 class CONTENT_EXPORT RenderViewHost
: virtual public RenderWidgetHost
{
60 // Returns the RenderViewHost given its ID and the ID of its render process.
61 // Returns NULL if the IDs do not correspond to a live RenderViewHost.
62 static RenderViewHost
* FromID(int render_process_id
, int render_view_id
);
64 // Downcasts from a RenderWidgetHost to a RenderViewHost. Required
65 // because RenderWidgetHost is a virtual base class.
66 static RenderViewHost
* From(RenderWidgetHost
* rwh
);
68 // Checks that the given renderer can request |url|, if not it sets it to
70 // |empty_allowed| must be set to false for navigations for security reasons.
71 static void FilterURL(const RenderProcessHost
* process
,
75 // Adds/removes a callback called on creation of each new RenderViewHost.
76 typedef base::Callback
<void(RenderViewHost
*)> CreatedCallback
;
77 static void AddCreatedCallback(const CreatedCallback
& callback
);
78 static void RemoveCreatedCallback(const CreatedCallback
& callback
);
80 virtual ~RenderViewHost() {}
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;
86 // Tells the renderer to clear the focused node (if any).
87 virtual void ClearFocusedNode() = 0;
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;
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;
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;
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
,
111 virtual void DesktopNotificationPostClick(int notification_id
) = 0;
113 // Notifies the listener that a directory enumeration is complete.
114 virtual void DirectoryEnumerationFinished(
116 const std::vector
<base::FilePath
>& files
) = 0;
118 // Tells the renderer not to add scrollbars with height and width below a
120 virtual void DisableScrollbarsForThreshold(const gfx::Size
& size
) = 0;
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;
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;
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;
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;
154 // Instructs the RenderView to automatically resize and send back updates
156 virtual void EnableAutoResize(const gfx::Size
& min_size
,
157 const gfx::Size
& max_size
) = 0;
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;
162 // Instructs the RenderView to send back updates to the preferred size.
163 virtual void EnablePreferredSizeMode() = 0;
165 // Executes custom context menu action that was provided from WebKit.
166 virtual void ExecuteCustomContextMenuCommand(
167 int action
, const CustomContextMenuContext
& context
) = 0;
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;
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;
179 // Runs some javascript within the context of a frame in the page. The result
180 // is sent back via the provided callback.
181 typedef base::Callback
<void(const base::Value
*)> JavascriptResultCallback
;
182 virtual void ExecuteJavascriptInWebFrameCallbackResult(
183 const string16
& frame_xpath
,
184 const string16
& jscript
,
185 const JavascriptResultCallback
& callback
) = 0;
187 // Tells the renderer to perform the given action on the plugin located at
189 virtual void ExecutePluginActionAtLocation(
190 const gfx::Point
& location
, const WebKit::WebPluginAction
& action
) = 0;
192 // Asks the renderer to exit fullscreen
193 virtual void ExitFullscreen() = 0;
195 // Finds text on a page.
196 virtual void Find(int request_id
, const string16
& search_text
,
197 const WebKit::WebFindOptions
& options
) = 0;
199 // Notifies the renderer that the user has closed the FindInPage window
200 // (and what action to take regarding the selection).
201 virtual void StopFinding(StopFindAction action
) = 0;
203 // Causes the renderer to invoke the onbeforeunload event handler. The
204 // result will be returned via ViewMsg_ShouldClose. See also ClosePage and
205 // SwapOut, which fire the PageUnload event.
207 // Set bool for_cross_site_transition when this close is just for the current
208 // RenderView in the case of a cross-site transition. False means we're
209 // closing the entire tab.
210 virtual void FirePageBeforeUnload(bool for_cross_site_transition
) = 0;
212 // Notifies the Listener that one or more files have been chosen by the user
213 // from a file chooser dialog for the form. |permissions| are flags from the
214 // base::PlatformFileFlags enum which specify which file permissions should
215 // be granted to the renderer.
216 virtual void FilesSelectedInChooser(
217 const std::vector
<ui::SelectedFileInfo
>& files
,
218 int permissions
) = 0;
220 virtual RenderViewHostDelegate
* GetDelegate() const = 0;
222 // Returns a bitwise OR of bindings types that have been enabled for this
223 // RenderView. See BindingsPolicy for details.
224 virtual int GetEnabledBindings() const = 0;
226 virtual SiteInstance
* GetSiteInstance() const = 0;
228 // Requests the renderer to evaluate an xpath to a frame and insert css
229 // into that frame's document.
230 virtual void InsertCSS(const string16
& frame_xpath
,
231 const std::string
& css
) = 0;
233 // Returns true if the RenderView is active and has not crashed. Virtual
234 // because it is overridden by TestRenderViewHost.
235 virtual bool IsRenderViewLive() const = 0;
237 // Returns true if the RenderView is responsible for displaying a subframe
238 // in a different process from its parent page.
239 virtual bool IsSubframe() const = 0;
241 // Let the renderer know that the menu has been closed.
242 virtual void NotifyContextMenuClosed(
243 const CustomContextMenuContext
& context
) = 0;
245 // Notification that a move or resize renderer's containing window has
247 virtual void NotifyMoveOrResizeStarted() = 0;
249 // Reloads the current focused frame.
250 virtual void ReloadFrame() = 0;
252 // Sets the alternate error page URL (link doctor) for the renderer process.
253 virtual void SetAltErrorPageURL(const GURL
& url
) = 0;
255 // Sets a property with the given name and value on the Web UI binding object.
256 // Must call AllowWebUIBindings() on this renderer first.
257 virtual void SetWebUIProperty(const std::string
& name
,
258 const std::string
& value
) = 0;
260 // Set the zoom level for the current main frame
261 virtual void SetZoomLevel(double level
) = 0;
263 // Changes the zoom level for the current main frame.
264 virtual void Zoom(PageZoom zoom
) = 0;
266 // Send the renderer process the current preferences supplied by the
267 // RenderViewHostDelegate.
268 virtual void SyncRendererPrefs() = 0;
270 virtual void ToggleSpeechInput() = 0;
272 // Returns the current WebKit preferences.
273 virtual WebPreferences
GetWebkitPreferences() = 0;
275 // Passes a list of Webkit preferences to the renderer.
276 virtual void UpdateWebkitPreferences(const WebPreferences
& prefs
) = 0;
278 // Informs the renderer process of a change in timezone.
279 virtual void NotifyTimezoneChange() = 0;
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;
286 // Asks the renderer to send the rects of the current find matches.
287 virtual void RequestFindMatchRects(int current_version
) = 0;
291 // This interface should only be implemented inside content.
292 friend class RenderViewHostImpl
;
296 } // namespace content
298 #endif // CONTENT_PUBLIC_BROWSER_RENDER_VIEW_HOST_H_