render_view_host.h revision effb81e5f8246d0db0270817048dc992db66e9fb
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 <list> 9 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 "third_party/WebKit/public/web/WebDragOperation.h" 16 17#if defined(USE_MOJO) 18#include "mojo/public/cpp/system/core.h" 19#endif 20 21class GURL; 22struct WebPreferences; 23 24namespace gfx { 25class Point; 26} 27 28namespace base { 29class FilePath; 30class Value; 31} 32 33namespace media { 34class AudioOutputController; 35} 36 37namespace ui { 38struct SelectedFileInfo; 39} 40 41namespace blink { 42struct WebMediaPlayerAction; 43struct WebPluginAction; 44} 45 46namespace content { 47 48class ChildProcessSecurityPolicy; 49class RenderFrameHost; 50class RenderViewHostDelegate; 51class SessionStorageNamespace; 52class SiteInstance; 53struct DropData; 54 55// A RenderViewHost is responsible for creating and talking to a RenderView 56// object in a child process. It exposes a high level API to users, for things 57// like loading pages, adjusting the display and other browser functionality, 58// which it translates into IPC messages sent over the IPC channel with the 59// RenderView. It responds to all IPC messages sent by that RenderView and 60// cracks them, calling a delegate object back with higher level types where 61// possible. 62// 63// The intent of this interface is to provide a view-agnostic communication 64// conduit with a renderer. This is so we can build HTML views not only as 65// WebContents (see WebContents for an example) but also as views, etc. 66class CONTENT_EXPORT RenderViewHost : virtual public RenderWidgetHost { 67 public: 68 // Returns the RenderViewHost given its ID and the ID of its render process. 69 // Returns NULL if the IDs do not correspond to a live RenderViewHost. 70 static RenderViewHost* FromID(int render_process_id, int render_view_id); 71 72 // Downcasts from a RenderWidgetHost to a RenderViewHost. Required 73 // because RenderWidgetHost is a virtual base class. 74 static RenderViewHost* From(RenderWidgetHost* rwh); 75 76 virtual ~RenderViewHost() {} 77 78 // Returns the main frame for this render view. 79 virtual RenderFrameHost* GetMainFrame() = 0; 80 81 // Tell the render view to enable a set of javascript bindings. The argument 82 // should be a combination of values from BindingsPolicy. 83 virtual void AllowBindings(int binding_flags) = 0; 84 85 // Tells the renderer to clear the focused element (if any). 86 virtual void ClearFocusedElement() = 0; 87 88 // Causes the renderer to close the current page, including running its 89 // onunload event handler. A ClosePage_ACK message will be sent to the 90 // ResourceDispatcherHost when it is finished. 91 virtual void ClosePage() = 0; 92 93 // Copies the image at location x, y to the clipboard (if there indeed is an 94 // image at that location). 95 virtual void CopyImageAt(int x, int y) = 0; 96 97 // Notifies the renderer about the result of a desktop notification. 98 virtual void DesktopNotificationPermissionRequestDone( 99 int callback_context) = 0; 100 virtual void DesktopNotificationPostDisplay(int callback_context) = 0; 101 virtual void DesktopNotificationPostError(int notification_id, 102 const base::string16& message) = 0; 103 virtual void DesktopNotificationPostClose(int notification_id, 104 bool by_user) = 0; 105 virtual void DesktopNotificationPostClick(int notification_id) = 0; 106 107 // Notifies the listener that a directory enumeration is complete. 108 virtual void DirectoryEnumerationFinished( 109 int request_id, 110 const std::vector<base::FilePath>& files) = 0; 111 112 // Tells the renderer not to add scrollbars with height and width below a 113 // threshold. 114 virtual void DisableScrollbarsForThreshold(const gfx::Size& size) = 0; 115 116 // Notifies the renderer that a a drag operation that it started has ended, 117 // either in a drop or by being cancelled. 118 virtual void DragSourceEndedAt( 119 int client_x, int client_y, int screen_x, int screen_y, 120 blink::WebDragOperation operation) = 0; 121 122 // Notifies the renderer that a drag and drop operation is in progress, with 123 // droppable items positioned over the renderer's view. 124 virtual void DragSourceMovedTo( 125 int client_x, int client_y, int screen_x, int screen_y) = 0; 126 127 // Notifies the renderer that we're done with the drag and drop operation. 128 // This allows the renderer to reset some state. 129 virtual void DragSourceSystemDragEnded() = 0; 130 131 // D&d drop target messages that get sent to WebKit. 132 virtual void DragTargetDragEnter( 133 const DropData& drop_data, 134 const gfx::Point& client_pt, 135 const gfx::Point& screen_pt, 136 blink::WebDragOperationsMask operations_allowed, 137 int key_modifiers) = 0; 138 virtual void DragTargetDragOver( 139 const gfx::Point& client_pt, 140 const gfx::Point& screen_pt, 141 blink::WebDragOperationsMask operations_allowed, 142 int key_modifiers) = 0; 143 virtual void DragTargetDragLeave() = 0; 144 virtual void DragTargetDrop(const gfx::Point& client_pt, 145 const gfx::Point& screen_pt, 146 int key_modifiers) = 0; 147 148 // Instructs the RenderView to automatically resize and send back updates 149 // for the new size. 150 virtual void EnableAutoResize(const gfx::Size& min_size, 151 const gfx::Size& max_size) = 0; 152 153 // Turns off auto-resize and gives a new size that the view should be. 154 virtual void DisableAutoResize(const gfx::Size& new_size) = 0; 155 156 // Instructs the RenderView to send back updates to the preferred size. 157 virtual void EnablePreferredSizeMode() = 0; 158 159 // Tells the renderer to perform the given action on the media player 160 // located at the given point. 161 virtual void ExecuteMediaPlayerActionAtLocation( 162 const gfx::Point& location, 163 const blink::WebMediaPlayerAction& action) = 0; 164 165 // Runs some javascript within the context of a frame in the page. 166 // OBSOLETE; DO NOT USE! Use RenderFrameHost::ExecuteJavaScript instead. 167 virtual void ExecuteJavascriptInWebFrame(const base::string16& frame_xpath, 168 const base::string16& jscript) = 0; 169 170 // Runs some javascript within the context of a frame in the page. The result 171 // is sent back via the provided callback. 172 // OBSOLETE; DO NOT USE! Use RenderFrameHost::ExecuteJavaScript instead. 173 typedef base::Callback<void(const base::Value*)> JavascriptResultCallback; 174 virtual void ExecuteJavascriptInWebFrameCallbackResult( 175 const base::string16& frame_xpath, 176 const base::string16& jscript, 177 const JavascriptResultCallback& callback) = 0; 178 179 // Tells the renderer to perform the given action on the plugin located at 180 // the given point. 181 virtual void ExecutePluginActionAtLocation( 182 const gfx::Point& location, const blink::WebPluginAction& action) = 0; 183 184 // Asks the renderer to exit fullscreen 185 virtual void ExitFullscreen() = 0; 186 187 // Notifies the Listener that one or more files have been chosen by the user 188 // from a file chooser dialog for the form. |permissions| is the file 189 // selection mode in which the chooser dialog was created. 190 virtual void FilesSelectedInChooser( 191 const std::vector<ui::SelectedFileInfo>& files, 192 FileChooserParams::Mode permissions) = 0; 193 194 virtual RenderViewHostDelegate* GetDelegate() const = 0; 195 196 // Returns a bitwise OR of bindings types that have been enabled for this 197 // RenderView. See BindingsPolicy for details. 198 virtual int GetEnabledBindings() const = 0; 199 200 virtual SiteInstance* GetSiteInstance() const = 0; 201 202 // Returns true if the RenderView is active and has not crashed. Virtual 203 // because it is overridden by TestRenderViewHost. 204 virtual bool IsRenderViewLive() const = 0; 205 206 // Notification that a move or resize renderer's containing window has 207 // started. 208 virtual void NotifyMoveOrResizeStarted() = 0; 209 210 // Reloads the current focused frame. 211 virtual void ReloadFrame() = 0; 212 213 // Sets a property with the given name and value on the Web UI binding object. 214 // Must call AllowWebUIBindings() on this renderer first. 215 virtual void SetWebUIProperty(const std::string& name, 216 const std::string& value) = 0; 217 218 // Changes the zoom level for the current main frame. 219 virtual void Zoom(PageZoom zoom) = 0; 220 221 // Send the renderer process the current preferences supplied by the 222 // RenderViewHostDelegate. 223 virtual void SyncRendererPrefs() = 0; 224 225 virtual void ToggleSpeechInput() = 0; 226 227 // Returns the current WebKit preferences. 228 virtual WebPreferences GetWebkitPreferences() = 0; 229 230 // Passes a list of Webkit preferences to the renderer. 231 virtual void UpdateWebkitPreferences(const WebPreferences& prefs) = 0; 232 233 // Retrieves the list of AudioOutputController objects associated 234 // with this object and passes it to the callback you specify, on 235 // the same thread on which you called the method. 236 typedef std::list<scoped_refptr<media::AudioOutputController> > 237 AudioOutputControllerList; 238 typedef base::Callback<void(const AudioOutputControllerList&)> 239 GetAudioOutputControllersCallback; 240 virtual void GetAudioOutputControllers( 241 const GetAudioOutputControllersCallback& callback) const = 0; 242 243#if defined(OS_ANDROID) 244 // Selects and zooms to the find result nearest to the point (x,y) 245 // defined in find-in-page coordinates. 246 virtual void ActivateNearestFindResult(int request_id, float x, float y) = 0; 247 248 // Asks the renderer to send the rects of the current find matches. 249 virtual void RequestFindMatchRects(int current_version) = 0; 250 251 // Disables fullscreen media playback for encrypted video. 252 virtual void DisableFullscreenEncryptedMediaPlayback() = 0; 253#endif 254 255#if defined(USE_MOJO) 256 // Sets the mojo handle for WebUI pages. 257 virtual void SetWebUIHandle(mojo::ScopedMessagePipeHandle handle) = 0; 258#endif 259 260 private: 261 // This interface should only be implemented inside content. 262 friend class RenderViewHostImpl; 263 RenderViewHost() {} 264}; 265 266} // namespace content 267 268#endif // CONTENT_PUBLIC_BROWSER_RENDER_VIEW_HOST_H_ 269