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 FrameHostMsg_DidCommitProvisionalLoad_Params;
28 struct ViewMsg_PostMessage_Params;
29 struct WebPreferences;
49 class CrossSiteTransferringRequest;
53 class RenderViewHostDelegateView;
54 class SessionStorageNamespace;
57 class WebContentsImpl;
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 // |cross_site_transferring_request| is NULL if a request is not being
98 // transferred between renderers.
99 virtual void OnCrossSiteResponse(
100 RenderViewHost* pending_render_view_host,
101 const GlobalRequestID& global_request_id,
102 scoped_ptr<CrossSiteTransferringRequest>
103 cross_site_transferring_request,
104 const std::vector<GURL>& transfer_url_chain,
105 const Referrer& referrer,
106 PageTransition page_transition,
108 bool should_replace_current_entry) = 0;
111 virtual ~RendererManagement() {}
114 // ---------------------------------------------------------------------------
116 // Returns the current delegate associated with a feature. May return NULL if
117 // there is no corresponding delegate.
118 virtual RenderViewHostDelegateView* GetDelegateView();
119 virtual RendererManagement* GetRendererManagementDelegate();
121 // This is used to give the delegate a chance to filter IPC messages.
122 virtual bool OnMessageReceived(RenderViewHost* render_view_host,
123 const IPC::Message& message);
125 // Gets the URL that is currently being displayed, if there is one.
126 virtual const GURL& GetURL() const;
128 // Return this object cast to a WebContents, if it is one. If the object is
129 // not a WebContents, returns NULL. DEPRECATED: Be sure to include brettw or
130 // jam as reviewers before you use this method. http://crbug.com/82582
131 virtual WebContents* GetAsWebContents();
133 // Return the rect where to display the resize corner, if any, otherwise
135 virtual gfx::Rect GetRootWindowResizerRect() const = 0;
137 // The RenderView is being constructed (message sent to the renderer process
138 // to construct a RenderView). Now is a good time to send other setup events
139 // to the RenderView. This precedes any other commands to the RenderView.
140 virtual void RenderViewCreated(RenderViewHost* render_view_host) {}
142 // The RenderView has been constructed.
143 virtual void RenderViewReady(RenderViewHost* render_view_host) {}
145 // The RenderView died somehow (crashed or was killed by the user).
146 virtual void RenderViewTerminated(RenderViewHost* render_view_host,
147 base::TerminationStatus status,
150 // The RenderView is going to be deleted. This is called when each
151 // RenderView is going to be destroyed
152 virtual void RenderViewDeleted(RenderViewHost* render_view_host) {}
154 // The state for the page changed and should be updated.
155 virtual void UpdateState(RenderViewHost* render_view_host,
157 const PageState& state) {}
159 // The page's title was changed and should be updated.
160 virtual void UpdateTitle(RenderViewHost* render_view_host,
162 const base::string16& title,
163 base::i18n::TextDirection title_direction) {}
165 // The page's encoding was changed and should be updated.
166 virtual void UpdateEncoding(RenderViewHost* render_view_host,
167 const std::string& encoding) {}
169 // The destination URL has changed should be updated
170 virtual void UpdateTargetURL(int32 page_id, const GURL& url) {}
172 // The page is trying to close the RenderView's representation in the client.
173 virtual void Close(RenderViewHost* render_view_host) {}
175 // The RenderViewHost has been swapped out.
176 virtual void SwappedOut(RenderViewHost* render_view_host) {}
178 // The page is trying to move the RenderView's representation in the client.
179 virtual void RequestMove(const gfx::Rect& new_bounds) {}
181 // The pending page load was canceled.
182 virtual void DidCancelLoading() {}
184 // The RenderView made progress loading a page's top frame.
185 // |progress| is a value between 0 (nothing loaded) to 1.0 (top frame
187 virtual void DidChangeLoadProgress(double progress) {}
189 // The RenderView set its opener to null, disowning it for the lifetime of
191 virtual void DidDisownOpener(RenderViewHost* rvh) {}
193 // Another page accessed the initial empty document of this RenderView,
194 // which means it is no longer safe to display a pending URL without
195 // risking a URL spoof.
196 virtual void DidAccessInitialDocument() {}
198 // The RenderView's main frame document element is ready. This happens when
199 // the document has finished parsing.
200 virtual void DocumentAvailableInMainFrame(RenderViewHost* render_view_host) {}
202 // The onload handler in the RenderView's main frame has completed.
203 virtual void DocumentOnLoadCompletedInMainFrame(
204 RenderViewHost* render_view_host,
207 // The page wants to open a URL with the specified disposition.
208 virtual void RequestOpenURL(RenderViewHost* rvh,
210 const Referrer& referrer,
211 WindowOpenDisposition disposition,
212 int64 source_frame_id,
214 bool user_gesture) {}
216 // The page wants to transfer the request to a new renderer.
217 // |redirect_chain| contains any redirect URLs (excluding |url|) that happened
218 // before the transfer.
219 virtual void RequestTransferURL(
221 const std::vector<GURL>& redirect_chain,
222 const Referrer& referrer,
223 PageTransition page_transition,
224 WindowOpenDisposition disposition,
225 int64 source_frame_id,
226 const GlobalRequestID& old_request_id,
228 bool user_gesture) {}
230 // The page wants to close the active view in this tab.
231 virtual void RouteCloseEvent(RenderViewHost* rvh) {}
233 // The page wants to post a message to the active view in this tab.
234 virtual void RouteMessageEvent(
236 const ViewMsg_PostMessage_Params& params) {}
238 // A javascript message, confirmation or prompt should be shown.
239 virtual void RunJavaScriptMessage(RenderViewHost* rvh,
240 const base::string16& message,
241 const base::string16& default_prompt,
242 const GURL& frame_url,
243 JavaScriptMessageType type,
244 IPC::Message* reply_msg,
245 bool* did_suppress_message) {}
247 virtual void RunBeforeUnloadConfirm(RenderViewHost* rvh,
248 const base::string16& message,
250 IPC::Message* reply_msg) {}
252 // A message was added to to the console.
253 virtual bool AddMessageToConsole(int32 level,
254 const base::string16& message,
256 const base::string16& source_id);
258 // Return a dummy RendererPreferences object that will be used by the renderer
259 // associated with the owning RenderViewHost.
260 virtual RendererPreferences GetRendererPrefs(
261 BrowserContext* browser_context) const = 0;
263 // Returns a WebPreferences object that will be used by the renderer
264 // associated with the owning render view host.
265 virtual WebPreferences GetWebkitPrefs();
267 // Notification the user has made a gesture while focus was on the
268 // page. This is used to avoid uninitiated user downloads (aka carpet
269 // bombing), see DownloadRequestLimiter for details.
270 virtual void OnUserGesture() {}
272 // Notification from the renderer host that blocked UI event occurred.
273 // This happens when there are tab-modal dialogs. In this case, the
274 // notification is needed to let us draw attention to the dialog (i.e.
275 // refocus on the modal dialog, flash title etc).
276 virtual void OnIgnoredUIEvent() {}
278 // Notification that the renderer has become unresponsive. The
279 // delegate can use this notification to show a warning to the user.
280 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
281 bool is_during_before_unload,
282 bool is_during_unload) {}
284 // Notification that a previously unresponsive renderer has become
285 // responsive again. The delegate can use this notification to end the
286 // warning shown to the user.
287 virtual void RendererResponsive(RenderViewHost* render_view_host) {}
289 // Notification that the RenderViewHost's load state changed.
290 virtual void LoadStateChanged(const GURL& url,
291 const net::LoadStateWithParam& load_state,
292 uint64 upload_position,
293 uint64 upload_size) {}
295 // The page wants the hosting window to activate/deactivate itself (it
296 // called the JavaScript window.focus()/blur() method).
297 virtual void Activate() {}
298 virtual void Deactivate() {}
300 // Notification that the view has lost capture.
301 virtual void LostCapture() {}
303 // Notifications about mouse events in this view. This is useful for
304 // implementing global 'on hover' features external to the view.
305 virtual void HandleMouseMove() {}
306 virtual void HandleMouseDown() {}
307 virtual void HandleMouseLeave() {}
308 virtual void HandleMouseUp() {}
309 virtual void HandlePointerActivate() {}
310 virtual void HandleGestureBegin() {}
311 virtual void HandleGestureEnd() {}
313 // Called when a file selection is to be done.
314 virtual void RunFileChooser(
315 RenderViewHost* render_view_host,
316 const FileChooserParams& params) {}
318 // Notification that the page wants to go into or out of fullscreen mode.
319 virtual void ToggleFullscreenMode(bool enter_fullscreen) {}
320 virtual bool IsFullscreenForCurrentTab() const;
322 // The contents' preferred size changed.
323 virtual void UpdatePreferredSize(const gfx::Size& pref_size) {}
325 // The contents auto-resized and the container should match it.
326 virtual void ResizeDueToAutoResize(const gfx::Size& new_size) {}
328 // Requests to lock the mouse. Once the request is approved or rejected,
329 // GotResponseToLockMouseRequest() will be called on the requesting render
331 virtual void RequestToLockMouse(bool user_gesture,
332 bool last_unlocked_by_target) {}
334 // Notification that the view has lost the mouse lock.
335 virtual void LostMouseLock() {}
337 // The page is trying to open a new page (e.g. a popup window). The window
338 // should be created associated with the given |route_id| in process
339 // |render_process_id|, but it should not be shown yet. That should happen in
340 // response to ShowCreatedWindow.
341 // |params.window_container_type| describes the type of RenderViewHost
342 // container that is requested -- in particular, the window.open call may
343 // have specified 'background' and 'persistent' in the feature string.
345 // The passed |params.frame_name| parameter is the name parameter that was
346 // passed to window.open(), and will be empty if none was passed.
348 // Note: this is not called "CreateWindow" because that will clash with
349 // the Windows function which is actually a #define.
350 virtual void CreateNewWindow(
351 int render_process_id,
353 int main_frame_route_id,
354 const ViewHostMsg_CreateWindow_Params& params,
355 SessionStorageNamespace* session_storage_namespace) {}
357 // The page is trying to open a new widget (e.g. a select popup). The
358 // widget should be created associated with the given |route_id| in the
359 // process |render_process_id|, but it should not be shown yet. That should
360 // happen in response to ShowCreatedWidget.
361 // |popup_type| indicates if the widget is a popup and what kind of popup it
362 // is (select, autofill...).
363 virtual void CreateNewWidget(int render_process_id,
365 blink::WebPopupType popup_type) {}
367 // Creates a full screen RenderWidget. Similar to above.
368 virtual void CreateNewFullscreenWidget(int render_process_id, int route_id) {}
370 // Show a previously created page with the specified disposition and bounds.
371 // The window is identified by the route_id passed to CreateNewWindow.
373 // Note: this is not called "ShowWindow" because that will clash with
374 // the Windows function which is actually a #define.
375 virtual void ShowCreatedWindow(int route_id,
376 WindowOpenDisposition disposition,
377 const gfx::Rect& initial_pos,
378 bool user_gesture) {}
380 // Show the newly created widget with the specified bounds.
381 // The widget is identified by the route_id passed to CreateNewWidget.
382 virtual void ShowCreatedWidget(int route_id,
383 const gfx::Rect& initial_pos) {}
385 // Show the newly created full screen widget. Similar to above.
386 virtual void ShowCreatedFullscreenWidget(int route_id) {}
388 // The render view has requested access to media devices listed in
389 // |request|, and the client should grant or deny that permission by
390 // calling |callback|.
391 virtual void RequestMediaAccessPermission(
392 const MediaStreamRequest& request,
393 const MediaResponseCallback& callback) {}
395 // Returns the SessionStorageNamespace the render view should use. Might
396 // create the SessionStorageNamespace on the fly.
397 virtual SessionStorageNamespace* GetSessionStorageNamespace(
398 SiteInstance* instance);
400 // Returns the FrameTree the render view should use. Guaranteed to be constant
401 // for the lifetime of the render view.
403 // TODO(ajwong): Remove once the main frame RenderFrameHost is no longer
404 // created by the RenderViewHost.
405 virtual FrameTree* GetFrameTree();
408 virtual ~RenderViewHostDelegate() {}
411 } // namespace content
413 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_DELEGATE_H_