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 16 class GURL; 17 struct WebPreferences; 18 19 namespace gfx { 20 class Point; 21 } 22 23 namespace base { 24 class FilePath; 25 class Value; 26 } 27 28 namespace ui { 29 struct SelectedFileInfo; 30 } 31 32 namespace WebKit { 33 struct WebFindOptions; 34 struct WebMediaPlayerAction; 35 struct WebPluginAction; 36 } 37 38 namespace content { 39 40 class ChildProcessSecurityPolicy; 41 class RenderProcessHost; 42 class RenderViewHostDelegate; 43 class SessionStorageNamespace; 44 class SiteInstance; 45 struct CustomContextMenuContext; 46 struct 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. 59 class 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 // Sent to the renderer when a popup window should no longer count against 100 // the current popup count (either because it's not a popup or because it was 101 // a generated by a user action). 102 virtual void DisassociateFromPopupCount() = 0; 103 104 // Notifies the renderer about the result of a desktop notification. 105 virtual void DesktopNotificationPermissionRequestDone( 106 int callback_context) = 0; 107 virtual void DesktopNotificationPostDisplay(int callback_context) = 0; 108 virtual void DesktopNotificationPostError(int notification_id, 109 const string16& message) = 0; 110 virtual void DesktopNotificationPostClose(int notification_id, 111 bool by_user) = 0; 112 virtual void DesktopNotificationPostClick(int notification_id) = 0; 113 114 // Notifies the listener that a directory enumeration is complete. 115 virtual void DirectoryEnumerationFinished( 116 int request_id, 117 const std::vector<base::FilePath>& files) = 0; 118 119 // Tells the renderer not to add scrollbars with height and width below a 120 // threshold. 121 virtual void DisableScrollbarsForThreshold(const gfx::Size& size) = 0; 122 123 // Notifies the renderer that a a drag operation that it started has ended, 124 // either in a drop or by being cancelled. 125 virtual void DragSourceEndedAt( 126 int client_x, int client_y, int screen_x, int screen_y, 127 WebKit::WebDragOperation operation) = 0; 128 129 // Notifies the renderer that a drag and drop operation is in progress, with 130 // droppable items positioned over the renderer's view. 131 virtual void DragSourceMovedTo( 132 int client_x, int client_y, int screen_x, int screen_y) = 0; 133 134 // Notifies the renderer that we're done with the drag and drop operation. 135 // This allows the renderer to reset some state. 136 virtual void DragSourceSystemDragEnded() = 0; 137 138 // D&d drop target messages that get sent to WebKit. 139 virtual void DragTargetDragEnter( 140 const DropData& drop_data, 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 DragTargetDragOver( 146 const gfx::Point& client_pt, 147 const gfx::Point& screen_pt, 148 WebKit::WebDragOperationsMask operations_allowed, 149 int key_modifiers) = 0; 150 virtual void DragTargetDragLeave() = 0; 151 virtual void DragTargetDrop(const gfx::Point& client_pt, 152 const gfx::Point& screen_pt, 153 int key_modifiers) = 0; 154 155 // Instructs the RenderView to automatically resize and send back updates 156 // for the new size. 157 virtual void EnableAutoResize(const gfx::Size& min_size, 158 const gfx::Size& max_size) = 0; 159 160 // Turns off auto-resize and gives a new size that the view should be. 161 virtual void DisableAutoResize(const gfx::Size& new_size) = 0; 162 163 // Instructs the RenderView to send back updates to the preferred size. 164 virtual void EnablePreferredSizeMode() = 0; 165 166 // Executes custom context menu action that was provided from WebKit. 167 virtual void ExecuteCustomContextMenuCommand( 168 int action, const CustomContextMenuContext& context) = 0; 169 170 // Tells the renderer to perform the given action on the media player 171 // located at the given point. 172 virtual void ExecuteMediaPlayerActionAtLocation( 173 const gfx::Point& location, 174 const WebKit::WebMediaPlayerAction& action) = 0; 175 176 // Runs some javascript within the context of a frame in the page. 177 virtual void ExecuteJavascriptInWebFrame(const string16& frame_xpath, 178 const string16& jscript) = 0; 179 180 // Runs some javascript within the context of a frame in the page. The result 181 // is sent back via the provided callback. 182 typedef base::Callback<void(const base::Value*)> JavascriptResultCallback; 183 virtual void ExecuteJavascriptInWebFrameCallbackResult( 184 const string16& frame_xpath, 185 const string16& jscript, 186 const JavascriptResultCallback& callback) = 0; 187 188 // Tells the renderer to perform the given action on the plugin located at 189 // the given point. 190 virtual void ExecutePluginActionAtLocation( 191 const gfx::Point& location, const WebKit::WebPluginAction& action) = 0; 192 193 // Asks the renderer to exit fullscreen 194 virtual void ExitFullscreen() = 0; 195 196 // Finds text on a page. 197 virtual void Find(int request_id, const string16& search_text, 198 const WebKit::WebFindOptions& options) = 0; 199 200 // Notifies the renderer that the user has closed the FindInPage window 201 // (and what action to take regarding the selection). 202 virtual void StopFinding(StopFindAction action) = 0; 203 204 // Causes the renderer to invoke the onbeforeunload event handler. The 205 // result will be returned via ViewMsg_ShouldClose. See also ClosePage and 206 // SwapOut, which fire the PageUnload event. 207 // 208 // Set bool for_cross_site_transition when this close is just for the current 209 // RenderView in the case of a cross-site transition. False means we're 210 // closing the entire tab. 211 virtual void FirePageBeforeUnload(bool for_cross_site_transition) = 0; 212 213 // Notifies the Listener that one or more files have been chosen by the user 214 // from a file chooser dialog for the form. |permissions| is the file 215 // selection mode in which the chooser dialog was created. 216 virtual void FilesSelectedInChooser( 217 const std::vector<ui::SelectedFileInfo>& files, 218 FileChooserParams::Mode 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