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/i18n/rtl.h"
13 #include "base/process/kill.h"
14 #include "base/strings/string16.h"
15 #include "content/common/content_export.h"
16 #include "content/public/common/javascript_message_type.h"
17 #include "content/public/common/media_stream_request.h"
18 #include "content/public/common/page_transition_types.h"
19 #include "net/base/load_states.h"
20 #include "third_party/WebKit/public/web/WebPopupType.h"
21 #include "ui/base/window_open_disposition.h"
25 class WebKeyboardEvent
;
26 struct ViewHostMsg_CreateWindow_Params
;
27 struct ViewHostMsg_FrameNavigate_Params
;
28 struct ViewMsg_PostMessage_Params
;
29 struct WebPreferences
;
52 class RenderViewHostDelegateView
;
53 class SessionStorageNamespace
;
56 class WebContentsImpl
;
57 struct ContextMenuParams
;
58 struct FileChooserParams
;
59 struct GlobalRequestID
;
60 struct NativeWebKeyboardEvent
;
62 struct RendererPreferences
;
65 // RenderViewHostDelegate
67 // An interface implemented by an object interested in knowing about the state
68 // of the RenderViewHost.
70 // This interface currently encompasses every type of message that was
71 // previously being sent by WebContents itself. Some of these notifications
72 // may not be relevant to all users of RenderViewHost and we should consider
73 // exposing a more generic Send function on RenderViewHost and a response
74 // listener here to serve that need.
75 class CONTENT_EXPORT RenderViewHostDelegate
{
77 // RendererManagerment -------------------------------------------------------
78 // Functions for managing switching of Renderers. For WebContents, this is
79 // implemented by the RenderFrameHostManager.
81 class CONTENT_EXPORT RendererManagement
{
83 // Notification whether we should close the page, after an explicit call to
84 // AttemptToClosePage. This is called before a cross-site request or before
85 // a tab/window is closed (as indicated by the first parameter) to allow the
86 // appropriate renderer to approve or deny the request. |proceed| indicates
87 // whether the user chose to proceed. |proceed_time| is the time when the
88 // request was allowed to proceed.
89 virtual void ShouldClosePage(
90 bool for_cross_site_transition
,
92 const base::TimeTicks
& proceed_time
) = 0;
94 // The |pending_render_view_host| is ready to commit a page. The delegate
95 // should ensure that the old RenderViewHost runs its unload handler first
96 // and determine whether a RenderViewHost transfer is needed.
97 virtual void OnCrossSiteResponse(
98 RenderViewHost
* pending_render_view_host
,
99 const GlobalRequestID
& global_request_id
,
101 const std::vector
<GURL
>& transfer_url_chain
,
102 const Referrer
& referrer
,
103 PageTransition page_transition
,
105 bool should_replace_current_entry
) = 0;
108 virtual ~RendererManagement() {}
111 // ---------------------------------------------------------------------------
113 // Returns the current delegate associated with a feature. May return NULL if
114 // there is no corresponding delegate.
115 virtual RenderViewHostDelegateView
* GetDelegateView();
116 virtual RendererManagement
* GetRendererManagementDelegate();
118 // This is used to give the delegate a chance to filter IPC messages.
119 virtual bool OnMessageReceived(RenderViewHost
* render_view_host
,
120 const IPC::Message
& message
);
122 // Gets the URL that is currently being displayed, if there is one.
123 virtual const GURL
& GetURL() const;
125 // Return this object cast to a WebContents, if it is one. If the object is
126 // not a WebContents, returns NULL. DEPRECATED: Be sure to include brettw or
127 // jam as reviewers before you use this method. http://crbug.com/82582
128 virtual WebContents
* GetAsWebContents();
130 // Return the rect where to display the resize corner, if any, otherwise
132 virtual gfx::Rect
GetRootWindowResizerRect() const = 0;
134 // The RenderView is being constructed (message sent to the renderer process
135 // to construct a RenderView). Now is a good time to send other setup events
136 // to the RenderView. This precedes any other commands to the RenderView.
137 virtual void RenderViewCreated(RenderViewHost
* render_view_host
) {}
139 // The RenderView has been constructed.
140 virtual void RenderViewReady(RenderViewHost
* render_view_host
) {}
142 // The RenderView died somehow (crashed or was killed by the user).
143 virtual void RenderViewTerminated(RenderViewHost
* render_view_host
,
144 base::TerminationStatus status
,
147 // The RenderView is going to be deleted. This is called when each
148 // RenderView is going to be destroyed
149 virtual void RenderViewDeleted(RenderViewHost
* render_view_host
) {}
151 // The RenderView processed a redirect during a provisional load.
153 // TODO(creis): Remove this method and have the pre-rendering code listen to
154 // WebContentsObserver::DidGetRedirectForResourceRequest instead.
155 // See http://crbug.com/78512.
156 virtual void DidRedirectProvisionalLoad(
157 RenderViewHost
* render_view_host
,
159 const GURL
& source_url
,
160 const GURL
& target_url
) {}
162 // The RenderView was navigated to a different page.
163 virtual void DidNavigate(RenderViewHost
* render_view_host
,
164 const ViewHostMsg_FrameNavigate_Params
& params
) {}
166 // The state for the page changed and should be updated.
167 virtual void UpdateState(RenderViewHost
* render_view_host
,
169 const PageState
& state
) {}
171 // The page's title was changed and should be updated.
172 virtual void UpdateTitle(RenderViewHost
* render_view_host
,
174 const base::string16
& title
,
175 base::i18n::TextDirection title_direction
) {}
177 // The page's encoding was changed and should be updated.
178 virtual void UpdateEncoding(RenderViewHost
* render_view_host
,
179 const std::string
& encoding
) {}
181 // The destination URL has changed should be updated
182 virtual void UpdateTargetURL(int32 page_id
, const GURL
& url
) {}
184 // The page is trying to close the RenderView's representation in the client.
185 virtual void Close(RenderViewHost
* render_view_host
) {}
187 // The RenderViewHost has been swapped out.
188 virtual void SwappedOut(RenderViewHost
* render_view_host
) {}
190 // The page is trying to move the RenderView's representation in the client.
191 virtual void RequestMove(const gfx::Rect
& new_bounds
) {}
193 // The RenderView began loading a new page. This corresponds to WebKit's
194 // notion of the throbber starting.
195 virtual void DidStartLoading(RenderViewHost
* render_view_host
) {}
197 // The RenderView stopped loading a page. This corresponds to WebKit's
198 // notion of the throbber stopping.
199 virtual void DidStopLoading(RenderViewHost
* render_view_host
) {}
201 // The pending page load was canceled.
202 virtual void DidCancelLoading() {}
204 // The RenderView made progress loading a page's top frame.
205 // |progress| is a value between 0 (nothing loaded) to 1.0 (top frame
207 virtual void DidChangeLoadProgress(double progress
) {}
209 // The RenderView set its opener to null, disowning it for the lifetime of
211 virtual void DidDisownOpener(RenderViewHost
* rvh
) {}
213 // Another page accessed the initial empty document of this RenderView,
214 // which means it is no longer safe to display a pending URL without
215 // risking a URL spoof.
216 virtual void DidAccessInitialDocument() {}
218 // The RenderView's main frame document element is ready. This happens when
219 // the document has finished parsing.
220 virtual void DocumentAvailableInMainFrame(RenderViewHost
* render_view_host
) {}
222 // The onload handler in the RenderView's main frame has completed.
223 virtual void DocumentOnLoadCompletedInMainFrame(
224 RenderViewHost
* render_view_host
,
227 // The page wants to open a URL with the specified disposition.
228 virtual void RequestOpenURL(RenderViewHost
* rvh
,
230 const Referrer
& referrer
,
231 WindowOpenDisposition disposition
,
232 int64 source_frame_id
,
234 bool user_gesture
) {}
236 // The page wants to transfer the request to a new renderer.
237 // |redirect_chain| contains any redirect URLs (excluding |url|) that happened
238 // before the transfer.
239 virtual void RequestTransferURL(
241 const std::vector
<GURL
>& redirect_chain
,
242 const Referrer
& referrer
,
243 PageTransition page_transition
,
244 WindowOpenDisposition disposition
,
245 int64 source_frame_id
,
246 const GlobalRequestID
& old_request_id
,
248 bool user_gesture
) {}
250 // The page wants to close the active view in this tab.
251 virtual void RouteCloseEvent(RenderViewHost
* rvh
) {}
253 // The page wants to post a message to the active view in this tab.
254 virtual void RouteMessageEvent(
256 const ViewMsg_PostMessage_Params
& params
) {}
258 // A javascript message, confirmation or prompt should be shown.
259 virtual void RunJavaScriptMessage(RenderViewHost
* rvh
,
260 const base::string16
& message
,
261 const base::string16
& default_prompt
,
262 const GURL
& frame_url
,
263 JavaScriptMessageType type
,
264 IPC::Message
* reply_msg
,
265 bool* did_suppress_message
) {}
267 virtual void RunBeforeUnloadConfirm(RenderViewHost
* rvh
,
268 const base::string16
& message
,
270 IPC::Message
* reply_msg
) {}
272 // A message was added to to the console.
273 virtual bool AddMessageToConsole(int32 level
,
274 const base::string16
& message
,
276 const base::string16
& source_id
);
278 // Return a dummy RendererPreferences object that will be used by the renderer
279 // associated with the owning RenderViewHost.
280 virtual RendererPreferences
GetRendererPrefs(
281 BrowserContext
* browser_context
) const = 0;
283 // Returns a WebPreferences object that will be used by the renderer
284 // associated with the owning render view host.
285 virtual WebPreferences
GetWebkitPrefs();
287 // Notification the user has made a gesture while focus was on the
288 // page. This is used to avoid uninitiated user downloads (aka carpet
289 // bombing), see DownloadRequestLimiter for details.
290 virtual void OnUserGesture() {}
292 // Notification from the renderer host that blocked UI event occurred.
293 // This happens when there are tab-modal dialogs. In this case, the
294 // notification is needed to let us draw attention to the dialog (i.e.
295 // refocus on the modal dialog, flash title etc).
296 virtual void OnIgnoredUIEvent() {}
298 // Notification that the renderer has become unresponsive. The
299 // delegate can use this notification to show a warning to the user.
300 virtual void RendererUnresponsive(RenderViewHost
* render_view_host
,
301 bool is_during_before_unload
,
302 bool is_during_unload
) {}
304 // Notification that a previously unresponsive renderer has become
305 // responsive again. The delegate can use this notification to end the
306 // warning shown to the user.
307 virtual void RendererResponsive(RenderViewHost
* render_view_host
) {}
309 // Notification that the RenderViewHost's load state changed.
310 virtual void LoadStateChanged(const GURL
& url
,
311 const net::LoadStateWithParam
& load_state
,
312 uint64 upload_position
,
313 uint64 upload_size
) {}
315 // The page wants the hosting window to activate/deactivate itself (it
316 // called the JavaScript window.focus()/blur() method).
317 virtual void Activate() {}
318 virtual void Deactivate() {}
320 // Notification that the view has lost capture.
321 virtual void LostCapture() {}
323 // Notifications about mouse events in this view. This is useful for
324 // implementing global 'on hover' features external to the view.
325 virtual void HandleMouseMove() {}
326 virtual void HandleMouseDown() {}
327 virtual void HandleMouseLeave() {}
328 virtual void HandleMouseUp() {}
329 virtual void HandlePointerActivate() {}
330 virtual void HandleGestureBegin() {}
331 virtual void HandleGestureEnd() {}
333 // Called when a file selection is to be done.
334 virtual void RunFileChooser(
335 RenderViewHost
* render_view_host
,
336 const FileChooserParams
& params
) {}
338 // Notification that the page wants to go into or out of fullscreen mode.
339 virtual void ToggleFullscreenMode(bool enter_fullscreen
) {}
340 virtual bool IsFullscreenForCurrentTab() const;
342 // The contents' preferred size changed.
343 virtual void UpdatePreferredSize(const gfx::Size
& pref_size
) {}
345 // The contents auto-resized and the container should match it.
346 virtual void ResizeDueToAutoResize(const gfx::Size
& new_size
) {}
348 // Requests to lock the mouse. Once the request is approved or rejected,
349 // GotResponseToLockMouseRequest() will be called on the requesting render
351 virtual void RequestToLockMouse(bool user_gesture
,
352 bool last_unlocked_by_target
) {}
354 // Notification that the view has lost the mouse lock.
355 virtual void LostMouseLock() {}
357 // The page is trying to open a new page (e.g. a popup window). The window
358 // should be created associated with the given |route_id| in process
359 // |render_process_id|, but it should not be shown yet. That should happen in
360 // response to ShowCreatedWindow.
361 // |params.window_container_type| describes the type of RenderViewHost
362 // container that is requested -- in particular, the window.open call may
363 // have specified 'background' and 'persistent' in the feature string.
365 // The passed |params.frame_name| parameter is the name parameter that was
366 // passed to window.open(), and will be empty if none was passed.
368 // Note: this is not called "CreateWindow" because that will clash with
369 // the Windows function which is actually a #define.
370 virtual void CreateNewWindow(
371 int render_process_id
,
373 int main_frame_route_id
,
374 const ViewHostMsg_CreateWindow_Params
& params
,
375 SessionStorageNamespace
* session_storage_namespace
) {}
377 // The page is trying to open a new widget (e.g. a select popup). The
378 // widget should be created associated with the given |route_id| in the
379 // process |render_process_id|, but it should not be shown yet. That should
380 // happen in response to ShowCreatedWidget.
381 // |popup_type| indicates if the widget is a popup and what kind of popup it
382 // is (select, autofill...).
383 virtual void CreateNewWidget(int render_process_id
,
385 blink::WebPopupType popup_type
) {}
387 // Creates a full screen RenderWidget. Similar to above.
388 virtual void CreateNewFullscreenWidget(int render_process_id
, int route_id
) {}
390 // Show a previously created page with the specified disposition and bounds.
391 // The window is identified by the route_id passed to CreateNewWindow.
393 // Note: this is not called "ShowWindow" because that will clash with
394 // the Windows function which is actually a #define.
395 virtual void ShowCreatedWindow(int route_id
,
396 WindowOpenDisposition disposition
,
397 const gfx::Rect
& initial_pos
,
398 bool user_gesture
) {}
400 // Show the newly created widget with the specified bounds.
401 // The widget is identified by the route_id passed to CreateNewWidget.
402 virtual void ShowCreatedWidget(int route_id
,
403 const gfx::Rect
& initial_pos
) {}
405 // Show the newly created full screen widget. Similar to above.
406 virtual void ShowCreatedFullscreenWidget(int route_id
) {}
408 // A context menu should be shown, to be built using the context information
409 // provided in the supplied params.
410 virtual void ShowContextMenu(const ContextMenuParams
& params
) {}
412 // The render view has requested access to media devices listed in
413 // |request|, and the client should grant or deny that permission by
414 // calling |callback|.
415 virtual void RequestMediaAccessPermission(
416 const MediaStreamRequest
& request
,
417 const MediaResponseCallback
& callback
) {}
419 // Returns the SessionStorageNamespace the render view should use. Might
420 // create the SessionStorageNamespace on the fly.
421 virtual SessionStorageNamespace
* GetSessionStorageNamespace(
422 SiteInstance
* instance
);
424 // Returns the FrameTree the render view should use. Guaranteed to be constant
425 // for the lifetime of the render view.
427 // TODO(ajwong): Remove once the main frame RenderFrameHost is no longer
428 // created by the RenderViewHost.
429 virtual FrameTree
* GetFrameTree();
432 virtual ~RenderViewHostDelegate() {}
435 } // namespace content
437 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_DELEGATE_H_