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