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