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