render_view_host.h revision 0529e5d033099cbfc42635f6f6183833b09dff6e
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 18class GURL; 19struct WebPreferences; 20 21namespace gfx { 22class Point; 23} 24 25namespace base { 26class FilePath; 27class Value; 28} 29 30namespace media { 31class AudioOutputController; 32} 33 34namespace ui { 35struct SelectedFileInfo; 36} 37 38namespace blink { 39struct WebMediaPlayerAction; 40struct WebPluginAction; 41} 42 43namespace content { 44 45class ChildProcessSecurityPolicy; 46class RenderFrameHost; 47class RenderViewHostDelegate; 48class SessionStorageNamespace; 49class SiteInstance; 50struct 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. 63class 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 // Causes the renderer to close the current page, including running its 86 // onunload event handler. A ClosePage_ACK message will be sent to the 87 // ResourceDispatcherHost when it is finished. 88 virtual void ClosePage() = 0; 89 90 // Copies the image at location x, y to the clipboard (if there indeed is an 91 // image at that location). 92 virtual void CopyImageAt(int x, int y) = 0; 93 94 // Notifies the listener that a directory enumeration is complete. 95 virtual void DirectoryEnumerationFinished( 96 int request_id, 97 const std::vector<base::FilePath>& files) = 0; 98 99 // Tells the renderer not to add scrollbars with height and width below a 100 // threshold. 101 virtual void DisableScrollbarsForThreshold(const gfx::Size& size) = 0; 102 103 // Notifies the renderer that a a drag operation that it started has ended, 104 // either in a drop or by being cancelled. 105 virtual void DragSourceEndedAt( 106 int client_x, int client_y, int screen_x, int screen_y, 107 blink::WebDragOperation operation) = 0; 108 109 // Notifies the renderer that we're done with the drag and drop operation. 110 // This allows the renderer to reset some state. 111 virtual void DragSourceSystemDragEnded() = 0; 112 113 // D&d drop target messages that get sent to WebKit. 114 virtual void DragTargetDragEnter( 115 const DropData& drop_data, 116 const gfx::Point& client_pt, 117 const gfx::Point& screen_pt, 118 blink::WebDragOperationsMask operations_allowed, 119 int key_modifiers) = 0; 120 virtual void DragTargetDragOver( 121 const gfx::Point& client_pt, 122 const gfx::Point& screen_pt, 123 blink::WebDragOperationsMask operations_allowed, 124 int key_modifiers) = 0; 125 virtual void DragTargetDragLeave() = 0; 126 virtual void DragTargetDrop(const gfx::Point& client_pt, 127 const gfx::Point& screen_pt, 128 int key_modifiers) = 0; 129 130 // Instructs the RenderView to automatically resize and send back updates 131 // for the new size. 132 virtual void EnableAutoResize(const gfx::Size& min_size, 133 const gfx::Size& max_size) = 0; 134 135 // Turns off auto-resize and gives a new size that the view should be. 136 virtual void DisableAutoResize(const gfx::Size& new_size) = 0; 137 138 // Instructs the RenderView to send back updates to the preferred size. 139 virtual void EnablePreferredSizeMode() = 0; 140 141 // Tells the renderer to perform the given action on the media player 142 // located at the given point. 143 virtual void ExecuteMediaPlayerActionAtLocation( 144 const gfx::Point& location, 145 const blink::WebMediaPlayerAction& action) = 0; 146 147 // Tells the renderer to perform the given action on the plugin located at 148 // the given point. 149 virtual void ExecutePluginActionAtLocation( 150 const gfx::Point& location, const blink::WebPluginAction& action) = 0; 151 152 // Asks the renderer to exit fullscreen 153 virtual void ExitFullscreen() = 0; 154 155 // Notifies the Listener that one or more files have been chosen by the user 156 // from a file chooser dialog for the form. |permissions| is the file 157 // selection mode in which the chooser dialog was created. 158 virtual void FilesSelectedInChooser( 159 const std::vector<ui::SelectedFileInfo>& files, 160 FileChooserParams::Mode permissions) = 0; 161 162 virtual RenderViewHostDelegate* GetDelegate() const = 0; 163 164 // Returns a bitwise OR of bindings types that have been enabled for this 165 // RenderView. See BindingsPolicy for details. 166 virtual int GetEnabledBindings() const = 0; 167 168 virtual SiteInstance* GetSiteInstance() const = 0; 169 170 // Returns true if the RenderView is active and has not crashed. Virtual 171 // because it is overridden by TestRenderViewHost. 172 virtual bool IsRenderViewLive() const = 0; 173 174 // Notification that a move or resize renderer's containing window has 175 // started. 176 virtual void NotifyMoveOrResizeStarted() = 0; 177 178 // Sets a property with the given name and value on the Web UI binding object. 179 // Must call AllowWebUIBindings() on this renderer first. 180 virtual void SetWebUIProperty(const std::string& name, 181 const std::string& value) = 0; 182 183 // Changes the zoom level for the current main frame. 184 virtual void Zoom(PageZoom zoom) = 0; 185 186 // Send the renderer process the current preferences supplied by the 187 // RenderViewHostDelegate. 188 virtual void SyncRendererPrefs() = 0; 189 190 virtual void ToggleSpeechInput() = 0; 191 192 // Returns the current WebKit preferences. 193 virtual WebPreferences GetWebkitPreferences() = 0; 194 195 // Passes a list of Webkit preferences to the renderer. 196 virtual void UpdateWebkitPreferences(const WebPreferences& prefs) = 0; 197 198 // Retrieves the list of AudioOutputController objects associated 199 // with this object and passes it to the callback you specify, on 200 // the same thread on which you called the method. 201 typedef std::list<scoped_refptr<media::AudioOutputController> > 202 AudioOutputControllerList; 203 typedef base::Callback<void(const AudioOutputControllerList&)> 204 GetAudioOutputControllersCallback; 205 virtual void GetAudioOutputControllers( 206 const GetAudioOutputControllersCallback& callback) const = 0; 207 208 // Sets the mojo handle for WebUI pages. 209 virtual void SetWebUIHandle(mojo::ScopedMessagePipeHandle handle) = 0; 210 211#if defined(OS_ANDROID) 212 // Selects and zooms to the find result nearest to the point (x,y) 213 // defined in find-in-page coordinates. 214 virtual void ActivateNearestFindResult(int request_id, float x, float y) = 0; 215 216 // Asks the renderer to send the rects of the current find matches. 217 virtual void RequestFindMatchRects(int current_version) = 0; 218#endif 219 220 private: 221 // This interface should only be implemented inside content. 222 friend class RenderViewHostImpl; 223 RenderViewHost() {} 224}; 225 226} // namespace content 227 228#endif // CONTENT_PUBLIC_BROWSER_RENDER_VIEW_HOST_H_ 229