render_view_host.h revision 010d83a9304c5a91596085d917d248abff47903a
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CONTENT_PUBLIC_BROWSER_RENDER_VIEW_HOST_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CONTENT_PUBLIC_BROWSER_RENDER_VIEW_HOST_H_
76e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <list>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/callback_forward.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/common/content_export.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/render_widget_host.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/file_chooser_params.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/page_zoom.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "mojo/public/cpp/system/core.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/WebKit/public/web/WebDragOperation.h"
17c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GURL;
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct WebPreferences;
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gfx {
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Point;
23a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace base {
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class FilePath;
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Value;
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace media {
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AudioOutputController;
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui {
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct SelectedFileInfo;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace blink {
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct WebMediaPlayerAction;
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct WebPluginAction;
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ChildProcessSecurityPolicy;
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class RenderFrameHost;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class RenderViewHostDelegate;
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SessionStorageNamespace;
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SiteInstance;
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct DropData;
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A RenderViewHost is responsible for creating and talking to a RenderView
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// object in a child process. It exposes a high level API to users, for things
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// like loading pages, adjusting the display and other browser functionality,
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// which it translates into IPC messages sent over the IPC channel with the
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// RenderView. It responds to all IPC messages sent by that RenderView and
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// cracks them, calling a delegate object back with higher level types where
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// possible.
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The intent of this interface is to provide a view-agnostic communication
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// conduit with a renderer. This is so we can build HTML views not only as
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// WebContents (see WebContents for an example) but also as views, etc.
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CONTENT_EXPORT RenderViewHost : virtual public RenderWidgetHost {
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the RenderViewHost given its ID and the ID of its render process.
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns NULL if the IDs do not correspond to a live RenderViewHost.
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static RenderViewHost* FromID(int render_process_id, int render_view_id);
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Downcasts from a RenderWidgetHost to a RenderViewHost.  Required
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // because RenderWidgetHost is a virtual base class.
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static RenderViewHost* From(RenderWidgetHost* rwh);
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~RenderViewHost() {}
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the main frame for this render view.
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual RenderFrameHost* GetMainFrame() = 0;
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Tell the render view to enable a set of javascript bindings. The argument
797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // should be a combination of values from BindingsPolicy.
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void AllowBindings(int binding_flags) = 0;
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Tells the renderer to clear the focused element (if any).
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void ClearFocusedElement() = 0;
847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the current focused element is editable.
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool IsFocusedElementEditable() = 0;
875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Causes the renderer to close the current page, including running its
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // onunload event handler.  A ClosePage_ACK message will be sent to the
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // ResourceDispatcherHost when it is finished.
915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void ClosePage() = 0;
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Copies the image at location x, y to the clipboard (if there indeed is an
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // image at that location).
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void CopyImageAt(int x, int y) = 0;
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Saves the image at location x, y to the disk (if there indeed is an
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // image at that location).
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SaveImageAt(int x, int y) = 0;
100c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notifies the listener that a directory enumeration is complete.
102a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void DirectoryEnumerationFinished(
103a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      int request_id,
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const std::vector<base::FilePath>& files) = 0;
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Tells the renderer not to add scrollbars with height and width below a
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // threshold.
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void DisableScrollbarsForThreshold(const gfx::Size& size) = 0;
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
110a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // Notifies the renderer that a a drag operation that it started has ended,
111a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // either in a drop or by being cancelled.
1127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual void DragSourceEndedAt(
113a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      int client_x, int client_y, int screen_x, int screen_y,
114a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      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#if defined(OS_ANDROID)
217  // Selects and zooms to the find result nearest to the point (x,y)
218  // defined in find-in-page coordinates.
219  virtual void ActivateNearestFindResult(int request_id, float x, float y) = 0;
220
221  // Asks the renderer to send the rects of the current find matches.
222  virtual void RequestFindMatchRects(int current_version) = 0;
223#endif
224
225 private:
226  // This interface should only be implemented inside content.
227  friend class RenderViewHostImpl;
228  RenderViewHost() {}
229};
230
231}  // namespace content
232
233#endif  // CONTENT_PUBLIC_BROWSER_RENDER_VIEW_HOST_H_
234