render_view_host.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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/public/web/WebDragOperation.h" 14 15class GURL; 16struct WebPreferences; 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 content { 38 39class ChildProcessSecurityPolicy; 40class RenderProcessHost; 41class RenderViewHostDelegate; 42class SessionStorageNamespace; 43class SiteInstance; 44struct CustomContextMenuContext; 45struct DropData; 46 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 53// possible. 54// 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. 58class CONTENT_EXPORT RenderViewHost : virtual public RenderWidgetHost { 59 public: 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); 63 64 // Downcasts from a RenderWidgetHost to a RenderViewHost. Required 65 // because RenderWidgetHost is a virtual base class. 66 static RenderViewHost* From(RenderWidgetHost* rwh); 67 68 // Checks that the given renderer can request |url|, if not it sets it to 69 // about:blank. 70 // |empty_allowed| must be set to false for navigations for security reasons. 71 static void FilterURL(const RenderProcessHost* process, 72 bool empty_allowed, 73 GURL* url); 74 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); 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 DropData& 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 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; 186 187 // Tells the renderer to perform the given action on the plugin located at 188 // the given point. 189 virtual void ExecutePluginActionAtLocation( 190 const gfx::Point& location, const WebKit::WebPluginAction& action) = 0; 191 192 // Asks the renderer to exit fullscreen 193 virtual void ExitFullscreen() = 0; 194 195 // Finds text on a page. 196 virtual void Find(int request_id, const string16& search_text, 197 const WebKit::WebFindOptions& options) = 0; 198 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; 202 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. 206 // 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; 211 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; 219 220 virtual RenderViewHostDelegate* GetDelegate() const = 0; 221 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; 225 226 virtual SiteInstance* GetSiteInstance() const = 0; 227 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; 232 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; 236 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; 240 241 // Let the renderer know that the menu has been closed. 242 virtual void NotifyContextMenuClosed( 243 const CustomContextMenuContext& context) = 0; 244 245 // Notification that a move or resize renderer's containing window has 246 // started. 247 virtual void NotifyMoveOrResizeStarted() = 0; 248 249 // Reloads the current focused frame. 250 virtual void ReloadFrame() = 0; 251 252 // Sets the alternate error page URL (link doctor) for the renderer process. 253 virtual void SetAltErrorPageURL(const GURL& url) = 0; 254 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; 259 260 // Set the zoom level for the current main frame 261 virtual void SetZoomLevel(double level) = 0; 262 263 // Changes the zoom level for the current main frame. 264 virtual void Zoom(PageZoom zoom) = 0; 265 266 // Send the renderer process the current preferences supplied by the 267 // RenderViewHostDelegate. 268 virtual void SyncRendererPrefs() = 0; 269 270 virtual void ToggleSpeechInput() = 0; 271 272 // Returns the current WebKit preferences. 273 virtual WebPreferences GetWebkitPreferences() = 0; 274 275 // Passes a list of Webkit preferences to the renderer. 276 virtual void UpdateWebkitPreferences(const 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