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