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