Home | History | Annotate | Download | only in renderer_host
      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_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_DELEGATE_H_
      6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_DELEGATE_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/callback.h"
     12 #include "base/process/kill.h"
     13 #include "base/strings/string16.h"
     14 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
     15 #include "content/common/content_export.h"
     16 #include "content/public/common/media_stream_request.h"
     17 #include "content/public/common/page_transition_types.h"
     18 #include "net/base/load_states.h"
     19 #include "third_party/WebKit/public/web/WebPopupType.h"
     20 #include "ui/base/window_open_disposition.h"
     21 
     22 class GURL;
     23 class SkBitmap;
     24 struct ViewHostMsg_CreateWindow_Params;
     25 struct FrameHostMsg_DidCommitProvisionalLoad_Params;
     26 struct ViewMsg_PostMessage_Params;
     27 struct WebPreferences;
     28 
     29 namespace base {
     30 class ListValue;
     31 class TimeTicks;
     32 }
     33 
     34 namespace IPC {
     35 class Message;
     36 }
     37 
     38 namespace gfx {
     39 class Point;
     40 class Rect;
     41 class Size;
     42 }
     43 
     44 namespace content {
     45 
     46 class BrowserContext;
     47 class CrossSiteTransferringRequest;
     48 class FrameTree;
     49 class PageState;
     50 class RenderViewHost;
     51 class RenderViewHostDelegateView;
     52 class SessionStorageNamespace;
     53 class SiteInstance;
     54 class WebContents;
     55 class WebContentsImpl;
     56 struct AXEventNotificationDetails;
     57 struct FileChooserParams;
     58 struct GlobalRequestID;
     59 struct NativeWebKeyboardEvent;
     60 struct Referrer;
     61 struct RendererPreferences;
     62 
     63 //
     64 // RenderViewHostDelegate
     65 //
     66 //  An interface implemented by an object interested in knowing about the state
     67 //  of the RenderViewHost.
     68 //
     69 //  This interface currently encompasses every type of message that was
     70 //  previously being sent by WebContents itself. Some of these notifications
     71 //  may not be relevant to all users of RenderViewHost and we should consider
     72 //  exposing a more generic Send function on RenderViewHost and a response
     73 //  listener here to serve that need.
     74 class CONTENT_EXPORT RenderViewHostDelegate {
     75  public:
     76   // Returns the current delegate associated with a feature. May return NULL if
     77   // there is no corresponding delegate.
     78   virtual RenderViewHostDelegateView* GetDelegateView();
     79 
     80   // This is used to give the delegate a chance to filter IPC messages.
     81   virtual bool OnMessageReceived(RenderViewHost* render_view_host,
     82                                  const IPC::Message& message);
     83 
     84   // Return this object cast to a WebContents, if it is one. If the object is
     85   // not a WebContents, returns NULL. DEPRECATED: Be sure to include brettw or
     86   // jam as reviewers before you use this method. http://crbug.com/82582
     87   virtual WebContents* GetAsWebContents();
     88 
     89   // Return the rect where to display the resize corner, if any, otherwise
     90   // an empty rect.
     91   virtual gfx::Rect GetRootWindowResizerRect() const = 0;
     92 
     93   // The RenderView is being constructed (message sent to the renderer process
     94   // to construct a RenderView).  Now is a good time to send other setup events
     95   // to the RenderView.  This precedes any other commands to the RenderView.
     96   virtual void RenderViewCreated(RenderViewHost* render_view_host) {}
     97 
     98   // The RenderView has been constructed.
     99   virtual void RenderViewReady(RenderViewHost* render_view_host) {}
    100 
    101   // The RenderView died somehow (crashed or was killed by the user).
    102   virtual void RenderViewTerminated(RenderViewHost* render_view_host,
    103                                     base::TerminationStatus status,
    104                                     int error_code) {}
    105 
    106   // The RenderView is going to be deleted. This is called when each
    107   // RenderView is going to be destroyed
    108   virtual void RenderViewDeleted(RenderViewHost* render_view_host) {}
    109 
    110   // The state for the page changed and should be updated.
    111   virtual void UpdateState(RenderViewHost* render_view_host,
    112                            int32 page_id,
    113                            const PageState& state) {}
    114 
    115   // The destination URL has changed should be updated
    116   virtual void UpdateTargetURL(int32 page_id, const GURL& url) {}
    117 
    118   // The page is trying to close the RenderView's representation in the client.
    119   virtual void Close(RenderViewHost* render_view_host) {}
    120 
    121   // The page is trying to move the RenderView's representation in the client.
    122   virtual void RequestMove(const gfx::Rect& new_bounds) {}
    123 
    124   // The pending page load was canceled.
    125   virtual void DidCancelLoading() {}
    126 
    127   // The RenderView's main frame document element is ready. This happens when
    128   // the document has finished parsing.
    129   virtual void DocumentAvailableInMainFrame(RenderViewHost* render_view_host) {}
    130 
    131   // The page wants to close the active view in this tab.
    132   virtual void RouteCloseEvent(RenderViewHost* rvh) {}
    133 
    134   // The page wants to post a message to the active view in this tab.
    135   virtual void RouteMessageEvent(
    136       RenderViewHost* rvh,
    137       const ViewMsg_PostMessage_Params& params) {}
    138 
    139   // Return a dummy RendererPreferences object that will be used by the renderer
    140   // associated with the owning RenderViewHost.
    141   virtual RendererPreferences GetRendererPrefs(
    142       BrowserContext* browser_context) const = 0;
    143 
    144   // Returns a WebPreferences object that will be used by the renderer
    145   // associated with the owning render view host.
    146   virtual WebPreferences GetWebkitPrefs();
    147 
    148   // Notification the user has made a gesture while focus was on the
    149   // page. This is used to avoid uninitiated user downloads (aka carpet
    150   // bombing), see DownloadRequestLimiter for details.
    151   virtual void OnUserGesture() {}
    152 
    153   // Notification from the renderer host that blocked UI event occurred.
    154   // This happens when there are tab-modal dialogs. In this case, the
    155   // notification is needed to let us draw attention to the dialog (i.e.
    156   // refocus on the modal dialog, flash title etc).
    157   virtual void OnIgnoredUIEvent() {}
    158 
    159   // Notification that the renderer has become unresponsive. The
    160   // delegate can use this notification to show a warning to the user.
    161   virtual void RendererUnresponsive(RenderViewHost* render_view_host,
    162                                     bool is_during_before_unload,
    163                                     bool is_during_unload) {}
    164 
    165   // Notification that a previously unresponsive renderer has become
    166   // responsive again. The delegate can use this notification to end the
    167   // warning shown to the user.
    168   virtual void RendererResponsive(RenderViewHost* render_view_host) {}
    169 
    170   // Notification that the RenderViewHost's load state changed.
    171   virtual void LoadStateChanged(const GURL& url,
    172                                 const net::LoadStateWithParam& load_state,
    173                                 uint64 upload_position,
    174                                 uint64 upload_size) {}
    175 
    176   // The page wants the hosting window to activate/deactivate itself (it
    177   // called the JavaScript window.focus()/blur() method).
    178   virtual void Activate() {}
    179   virtual void Deactivate() {}
    180 
    181   // Notification that the view has lost capture.
    182   virtual void LostCapture() {}
    183 
    184   // Notifications about mouse events in this view.  This is useful for
    185   // implementing global 'on hover' features external to the view.
    186   virtual void HandleMouseMove() {}
    187   virtual void HandleMouseDown() {}
    188   virtual void HandleMouseLeave() {}
    189   virtual void HandleMouseUp() {}
    190   virtual void HandlePointerActivate() {}
    191   virtual void HandleGestureBegin() {}
    192   virtual void HandleGestureEnd() {}
    193 
    194   // Called when a file selection is to be done.
    195   virtual void RunFileChooser(
    196       RenderViewHost* render_view_host,
    197       const FileChooserParams& params) {}
    198 
    199   // Notification that the page wants to go into or out of fullscreen mode.
    200   virtual void ToggleFullscreenMode(bool enter_fullscreen) {}
    201   virtual bool IsFullscreenForCurrentTab() const;
    202 
    203   // The contents' preferred size changed.
    204   virtual void UpdatePreferredSize(const gfx::Size& pref_size) {}
    205 
    206   // The contents auto-resized and the container should match it.
    207   virtual void ResizeDueToAutoResize(const gfx::Size& new_size) {}
    208 
    209   // Requests to lock the mouse. Once the request is approved or rejected,
    210   // GotResponseToLockMouseRequest() will be called on the requesting render
    211   // view host.
    212   virtual void RequestToLockMouse(bool user_gesture,
    213                                   bool last_unlocked_by_target) {}
    214 
    215   // Notification that the view has lost the mouse lock.
    216   virtual void LostMouseLock() {}
    217 
    218   // The page is trying to open a new page (e.g. a popup window). The window
    219   // should be created associated with the given |route_id| in process
    220   // |render_process_id|, but it should not be shown yet. That should happen in
    221   // response to ShowCreatedWindow.
    222   // |params.window_container_type| describes the type of RenderViewHost
    223   // container that is requested -- in particular, the window.open call may
    224   // have specified 'background' and 'persistent' in the feature string.
    225   //
    226   // The passed |params.frame_name| parameter is the name parameter that was
    227   // passed to window.open(), and will be empty if none was passed.
    228   //
    229   // Note: this is not called "CreateWindow" because that will clash with
    230   // the Windows function which is actually a #define.
    231   virtual void CreateNewWindow(
    232       int render_process_id,
    233       int route_id,
    234       int main_frame_route_id,
    235       const ViewHostMsg_CreateWindow_Params& params,
    236       SessionStorageNamespace* session_storage_namespace) {}
    237 
    238   // The page is trying to open a new widget (e.g. a select popup). The
    239   // widget should be created associated with the given |route_id| in the
    240   // process |render_process_id|, but it should not be shown yet. That should
    241   // happen in response to ShowCreatedWidget.
    242   // |popup_type| indicates if the widget is a popup and what kind of popup it
    243   // is (select, autofill...).
    244   virtual void CreateNewWidget(int render_process_id,
    245                                int route_id,
    246                                blink::WebPopupType popup_type) {}
    247 
    248   // Creates a full screen RenderWidget. Similar to above.
    249   virtual void CreateNewFullscreenWidget(int render_process_id, int route_id) {}
    250 
    251   // Show a previously created page with the specified disposition and bounds.
    252   // The window is identified by the route_id passed to CreateNewWindow.
    253   //
    254   // Note: this is not called "ShowWindow" because that will clash with
    255   // the Windows function which is actually a #define.
    256   virtual void ShowCreatedWindow(int route_id,
    257                                  WindowOpenDisposition disposition,
    258                                  const gfx::Rect& initial_pos,
    259                                  bool user_gesture) {}
    260 
    261   // Show the newly created widget with the specified bounds.
    262   // The widget is identified by the route_id passed to CreateNewWidget.
    263   virtual void ShowCreatedWidget(int route_id,
    264                                  const gfx::Rect& initial_pos) {}
    265 
    266   // Show the newly created full screen widget. Similar to above.
    267   virtual void ShowCreatedFullscreenWidget(int route_id) {}
    268 
    269   // The render view has requested access to media devices listed in
    270   // |request|, and the client should grant or deny that permission by
    271   // calling |callback|.
    272   virtual void RequestMediaAccessPermission(
    273       const MediaStreamRequest& request,
    274       const MediaResponseCallback& callback) {}
    275 
    276   // Returns the SessionStorageNamespace the render view should use. Might
    277   // create the SessionStorageNamespace on the fly.
    278   virtual SessionStorageNamespace* GetSessionStorageNamespace(
    279       SiteInstance* instance);
    280 
    281   // Returns a copy of the map of all session storage namespaces related
    282   // to this view.
    283   virtual SessionStorageNamespaceMap GetSessionStorageNamespaceMap();
    284 
    285   // Returns true if the RenderViewHost will never be visible.
    286   virtual bool IsNeverVisible();
    287 
    288   // Returns the FrameTree the render view should use. Guaranteed to be constant
    289   // for the lifetime of the render view.
    290   //
    291   // TODO(ajwong): Remove once the main frame RenderFrameHost is no longer
    292   // created by the RenderViewHost.
    293   virtual FrameTree* GetFrameTree();
    294 
    295   // Invoked when an accessibility event is received from the renderer.
    296   virtual void AccessibilityEventReceived(
    297       const std::vector<AXEventNotificationDetails>& details) {}
    298 
    299  protected:
    300   virtual ~RenderViewHostDelegate() {}
    301 };
    302 
    303 }  // namespace content
    304 
    305 #endif  // CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_DELEGATE_H_
    306