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.
5 #ifndef CONTENT_PUBLIC_BROWSER_RENDER_VIEW_HOST_H_
6 #define CONTENT_PUBLIC_BROWSER_RENDER_VIEW_HOST_H_
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"
19 struct WebPreferences
;
31 class AudioOutputController
;
35 struct SelectedFileInfo
;
39 struct WebMediaPlayerAction
;
40 struct WebPluginAction
;
45 class ChildProcessSecurityPolicy
;
46 class RenderFrameHost
;
47 class RenderViewHostDelegate
;
48 class SessionStorageNamespace
;
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
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
{
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
);
69 // Downcasts from a RenderWidgetHost to a RenderViewHost. Required
70 // because RenderWidgetHost is a virtual base class.
71 static RenderViewHost
* From(RenderWidgetHost
* rwh
);
73 virtual ~RenderViewHost() {}
75 // Returns the main frame for this render view.
76 virtual RenderFrameHost
* GetMainFrame() = 0;
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;
82 // Tells the renderer to clear the focused element (if any).
83 virtual void ClearFocusedElement() = 0;
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;
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;
94 // Saves the image at location x, y to the disk (if there indeed is an
95 // image at that location).
96 virtual void SaveImageAt(int x
, int y
) = 0;
98 // Notifies the listener that a directory enumeration is complete.
99 virtual void DirectoryEnumerationFinished(
101 const std::vector
<base::FilePath
>& files
) = 0;
103 // Tells the renderer not to add scrollbars with height and width below a
105 virtual void DisableScrollbarsForThreshold(const gfx::Size
& size
) = 0;
107 // Notifies the renderer that a a drag operation that it started has ended,
108 // either in a drop or by being cancelled.
109 virtual void DragSourceEndedAt(
110 int client_x
, int client_y
, int screen_x
, int screen_y
,
111 blink::WebDragOperation operation
) = 0;
113 // Notifies the renderer that we're done with the drag and drop operation.
114 // This allows the renderer to reset some state.
115 virtual void DragSourceSystemDragEnded() = 0;
117 // D&d drop target messages that get sent to WebKit.
118 virtual void DragTargetDragEnter(
119 const DropData
& drop_data
,
120 const gfx::Point
& client_pt
,
121 const gfx::Point
& screen_pt
,
122 blink::WebDragOperationsMask operations_allowed
,
123 int key_modifiers
) = 0;
124 virtual void DragTargetDragOver(
125 const gfx::Point
& client_pt
,
126 const gfx::Point
& screen_pt
,
127 blink::WebDragOperationsMask operations_allowed
,
128 int key_modifiers
) = 0;
129 virtual void DragTargetDragLeave() = 0;
130 virtual void DragTargetDrop(const gfx::Point
& client_pt
,
131 const gfx::Point
& screen_pt
,
132 int key_modifiers
) = 0;
134 // Instructs the RenderView to automatically resize and send back updates
136 virtual void EnableAutoResize(const gfx::Size
& min_size
,
137 const gfx::Size
& max_size
) = 0;
139 // Turns off auto-resize and gives a new size that the view should be.
140 virtual void DisableAutoResize(const gfx::Size
& new_size
) = 0;
142 // Instructs the RenderView to send back updates to the preferred size.
143 virtual void EnablePreferredSizeMode() = 0;
145 // Tells the renderer to perform the given action on the media player
146 // located at the given point.
147 virtual void ExecuteMediaPlayerActionAtLocation(
148 const gfx::Point
& location
,
149 const blink::WebMediaPlayerAction
& action
) = 0;
151 // Tells the renderer to perform the given action on the plugin located at
153 virtual void ExecutePluginActionAtLocation(
154 const gfx::Point
& location
, const blink::WebPluginAction
& action
) = 0;
156 // Asks the renderer to exit fullscreen
157 virtual void ExitFullscreen() = 0;
159 // Notifies the Listener that one or more files have been chosen by the user
160 // from a file chooser dialog for the form. |permissions| is the file
161 // selection mode in which the chooser dialog was created.
162 virtual void FilesSelectedInChooser(
163 const std::vector
<ui::SelectedFileInfo
>& files
,
164 FileChooserParams::Mode permissions
) = 0;
166 virtual RenderViewHostDelegate
* GetDelegate() const = 0;
168 // Returns a bitwise OR of bindings types that have been enabled for this
169 // RenderView. See BindingsPolicy for details.
170 virtual int GetEnabledBindings() const = 0;
172 virtual SiteInstance
* GetSiteInstance() const = 0;
174 // Returns true if the RenderView is active and has not crashed. Virtual
175 // because it is overridden by TestRenderViewHost.
176 virtual bool IsRenderViewLive() const = 0;
178 // Notification that a move or resize renderer's containing window has
180 virtual void NotifyMoveOrResizeStarted() = 0;
182 // Sets a property with the given name and value on the Web UI binding object.
183 // Must call AllowWebUIBindings() on this renderer first.
184 virtual void SetWebUIProperty(const std::string
& name
,
185 const std::string
& value
) = 0;
187 // Changes the zoom level for the current main frame.
188 virtual void Zoom(PageZoom zoom
) = 0;
190 // Send the renderer process the current preferences supplied by the
191 // RenderViewHostDelegate.
192 virtual void SyncRendererPrefs() = 0;
194 // Returns the current WebKit preferences.
195 virtual WebPreferences
GetWebkitPreferences() = 0;
197 // Passes a list of Webkit preferences to the renderer.
198 virtual void UpdateWebkitPreferences(const WebPreferences
& prefs
) = 0;
200 // Retrieves the list of AudioOutputController objects associated
201 // with this object and passes it to the callback you specify, on
202 // the same thread on which you called the method.
203 typedef std::list
<scoped_refptr
<media::AudioOutputController
> >
204 AudioOutputControllerList
;
205 typedef base::Callback
<void(const AudioOutputControllerList
&)>
206 GetAudioOutputControllersCallback
;
207 virtual void GetAudioOutputControllers(
208 const GetAudioOutputControllersCallback
& callback
) const = 0;
210 // Sets the mojo handle for WebUI pages.
211 virtual void SetWebUIHandle(mojo::ScopedMessagePipeHandle handle
) = 0;
213 #if defined(OS_ANDROID)
214 // Selects and zooms to the find result nearest to the point (x,y)
215 // defined in find-in-page coordinates.
216 virtual void ActivateNearestFindResult(int request_id
, float x
, float y
) = 0;
218 // Asks the renderer to send the rects of the current find matches.
219 virtual void RequestFindMatchRects(int current_version
) = 0;
223 // This interface should only be implemented inside content.
224 friend class RenderViewHostImpl
;
228 } // namespace content
230 #endif // CONTENT_PUBLIC_BROWSER_RENDER_VIEW_HOST_H_