Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / content / browser / renderer_host / render_view_host_delegate.h
blobbfa45e8f693244f692dbc3fe563edc870140a155
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_
8 #include <string>
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/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"
22 class GURL;
23 class SkBitmap;
24 class WebKeyboardEvent;
25 struct ViewHostMsg_CreateWindow_Params;
26 struct FrameHostMsg_DidCommitProvisionalLoad_Params;
27 struct ViewMsg_PostMessage_Params;
28 struct WebPreferences;
30 namespace base {
31 class ListValue;
32 class TimeTicks;
35 namespace IPC {
36 class Message;
39 namespace gfx {
40 class Point;
41 class Rect;
42 class Size;
45 namespace content {
47 class BrowserContext;
48 class CrossSiteTransferringRequest;
49 class FrameTree;
50 class PageState;
51 class RenderViewHost;
52 class RenderViewHostDelegateView;
53 class SessionStorageNamespace;
54 class SiteInstance;
55 class WebContents;
56 class WebContentsImpl;
57 struct AXEventNotificationDetails;
58 struct FileChooserParams;
59 struct GlobalRequestID;
60 struct NativeWebKeyboardEvent;
61 struct Referrer;
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 {
76 public:
77 // Returns the current delegate associated with a feature. May return NULL if
78 // there is no corresponding delegate.
79 virtual RenderViewHostDelegateView* GetDelegateView();
81 // This is used to give the delegate a chance to filter IPC messages.
82 virtual bool OnMessageReceived(RenderViewHost* render_view_host,
83 const IPC::Message& message);
85 // Return this object cast to a WebContents, if it is one. If the object is
86 // not a WebContents, returns NULL. DEPRECATED: Be sure to include brettw or
87 // jam as reviewers before you use this method. http://crbug.com/82582
88 virtual WebContents* GetAsWebContents();
90 // Return the rect where to display the resize corner, if any, otherwise
91 // an empty rect.
92 virtual gfx::Rect GetRootWindowResizerRect() const = 0;
94 // The RenderView is being constructed (message sent to the renderer process
95 // to construct a RenderView). Now is a good time to send other setup events
96 // to the RenderView. This precedes any other commands to the RenderView.
97 virtual void RenderViewCreated(RenderViewHost* render_view_host) {}
99 // The RenderView has been constructed.
100 virtual void RenderViewReady(RenderViewHost* render_view_host) {}
102 // The RenderView died somehow (crashed or was killed by the user).
103 virtual void RenderViewTerminated(RenderViewHost* render_view_host,
104 base::TerminationStatus status,
105 int error_code) {}
107 // The RenderView is going to be deleted. This is called when each
108 // RenderView is going to be destroyed
109 virtual void RenderViewDeleted(RenderViewHost* render_view_host) {}
111 // The state for the page changed and should be updated.
112 virtual void UpdateState(RenderViewHost* render_view_host,
113 int32 page_id,
114 const PageState& state) {}
116 // The page's title was changed and should be updated.
117 virtual void UpdateTitle(RenderViewHost* render_view_host,
118 int32 page_id,
119 const base::string16& title,
120 base::i18n::TextDirection title_direction) {}
122 // The page's encoding was changed and should be updated.
123 virtual void UpdateEncoding(RenderViewHost* render_view_host,
124 const std::string& encoding) {}
126 // The destination URL has changed should be updated
127 virtual void UpdateTargetURL(int32 page_id, const GURL& url) {}
129 // The page is trying to close the RenderView's representation in the client.
130 virtual void Close(RenderViewHost* render_view_host) {}
132 // The page is trying to move the RenderView's representation in the client.
133 virtual void RequestMove(const gfx::Rect& new_bounds) {}
135 // The pending page load was canceled.
136 virtual void DidCancelLoading() {}
138 // The RenderView made progress loading a page's top frame.
139 // |progress| is a value between 0 (nothing loaded) to 1.0 (top frame
140 // entirely loaded).
141 virtual void DidChangeLoadProgress(double progress) {}
143 // The RenderView's main frame document element is ready. This happens when
144 // the document has finished parsing.
145 virtual void DocumentAvailableInMainFrame(RenderViewHost* render_view_host) {}
147 // The page wants to close the active view in this tab.
148 virtual void RouteCloseEvent(RenderViewHost* rvh) {}
150 // The page wants to post a message to the active view in this tab.
151 virtual void RouteMessageEvent(
152 RenderViewHost* rvh,
153 const ViewMsg_PostMessage_Params& params) {}
155 // Return a dummy RendererPreferences object that will be used by the renderer
156 // associated with the owning RenderViewHost.
157 virtual RendererPreferences GetRendererPrefs(
158 BrowserContext* browser_context) const = 0;
160 // Returns a WebPreferences object that will be used by the renderer
161 // associated with the owning render view host.
162 virtual WebPreferences GetWebkitPrefs();
164 // Notification the user has made a gesture while focus was on the
165 // page. This is used to avoid uninitiated user downloads (aka carpet
166 // bombing), see DownloadRequestLimiter for details.
167 virtual void OnUserGesture() {}
169 // Notification from the renderer host that blocked UI event occurred.
170 // This happens when there are tab-modal dialogs. In this case, the
171 // notification is needed to let us draw attention to the dialog (i.e.
172 // refocus on the modal dialog, flash title etc).
173 virtual void OnIgnoredUIEvent() {}
175 // Notification that the renderer has become unresponsive. The
176 // delegate can use this notification to show a warning to the user.
177 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
178 bool is_during_before_unload,
179 bool is_during_unload) {}
181 // Notification that a previously unresponsive renderer has become
182 // responsive again. The delegate can use this notification to end the
183 // warning shown to the user.
184 virtual void RendererResponsive(RenderViewHost* render_view_host) {}
186 // Notification that the RenderViewHost's load state changed.
187 virtual void LoadStateChanged(const GURL& url,
188 const net::LoadStateWithParam& load_state,
189 uint64 upload_position,
190 uint64 upload_size) {}
192 // The page wants the hosting window to activate/deactivate itself (it
193 // called the JavaScript window.focus()/blur() method).
194 virtual void Activate() {}
195 virtual void Deactivate() {}
197 // Notification that the view has lost capture.
198 virtual void LostCapture() {}
200 // Notifications about mouse events in this view. This is useful for
201 // implementing global 'on hover' features external to the view.
202 virtual void HandleMouseMove() {}
203 virtual void HandleMouseDown() {}
204 virtual void HandleMouseLeave() {}
205 virtual void HandleMouseUp() {}
206 virtual void HandlePointerActivate() {}
207 virtual void HandleGestureBegin() {}
208 virtual void HandleGestureEnd() {}
210 // Called when a file selection is to be done.
211 virtual void RunFileChooser(
212 RenderViewHost* render_view_host,
213 const FileChooserParams& params) {}
215 // Notification that the page wants to go into or out of fullscreen mode.
216 virtual void ToggleFullscreenMode(bool enter_fullscreen) {}
217 virtual bool IsFullscreenForCurrentTab() const;
219 // The contents' preferred size changed.
220 virtual void UpdatePreferredSize(const gfx::Size& pref_size) {}
222 // The contents auto-resized and the container should match it.
223 virtual void ResizeDueToAutoResize(const gfx::Size& new_size) {}
225 // Requests to lock the mouse. Once the request is approved or rejected,
226 // GotResponseToLockMouseRequest() will be called on the requesting render
227 // view host.
228 virtual void RequestToLockMouse(bool user_gesture,
229 bool last_unlocked_by_target) {}
231 // Notification that the view has lost the mouse lock.
232 virtual void LostMouseLock() {}
234 // The page is trying to open a new page (e.g. a popup window). The window
235 // should be created associated with the given |route_id| in process
236 // |render_process_id|, but it should not be shown yet. That should happen in
237 // response to ShowCreatedWindow.
238 // |params.window_container_type| describes the type of RenderViewHost
239 // container that is requested -- in particular, the window.open call may
240 // have specified 'background' and 'persistent' in the feature string.
242 // The passed |params.frame_name| parameter is the name parameter that was
243 // passed to window.open(), and will be empty if none was passed.
245 // Note: this is not called "CreateWindow" because that will clash with
246 // the Windows function which is actually a #define.
247 virtual void CreateNewWindow(
248 int render_process_id,
249 int route_id,
250 int main_frame_route_id,
251 const ViewHostMsg_CreateWindow_Params& params,
252 SessionStorageNamespace* session_storage_namespace) {}
254 // The page is trying to open a new widget (e.g. a select popup). The
255 // widget should be created associated with the given |route_id| in the
256 // process |render_process_id|, but it should not be shown yet. That should
257 // happen in response to ShowCreatedWidget.
258 // |popup_type| indicates if the widget is a popup and what kind of popup it
259 // is (select, autofill...).
260 virtual void CreateNewWidget(int render_process_id,
261 int route_id,
262 blink::WebPopupType popup_type) {}
264 // Creates a full screen RenderWidget. Similar to above.
265 virtual void CreateNewFullscreenWidget(int render_process_id, int route_id) {}
267 // Show a previously created page with the specified disposition and bounds.
268 // The window is identified by the route_id passed to CreateNewWindow.
270 // Note: this is not called "ShowWindow" because that will clash with
271 // the Windows function which is actually a #define.
272 virtual void ShowCreatedWindow(int route_id,
273 WindowOpenDisposition disposition,
274 const gfx::Rect& initial_pos,
275 bool user_gesture) {}
277 // Show the newly created widget with the specified bounds.
278 // The widget is identified by the route_id passed to CreateNewWidget.
279 virtual void ShowCreatedWidget(int route_id,
280 const gfx::Rect& initial_pos) {}
282 // Show the newly created full screen widget. Similar to above.
283 virtual void ShowCreatedFullscreenWidget(int route_id) {}
285 // The render view has requested access to media devices listed in
286 // |request|, and the client should grant or deny that permission by
287 // calling |callback|.
288 virtual void RequestMediaAccessPermission(
289 const MediaStreamRequest& request,
290 const MediaResponseCallback& callback) {}
292 // Returns the SessionStorageNamespace the render view should use. Might
293 // create the SessionStorageNamespace on the fly.
294 virtual SessionStorageNamespace* GetSessionStorageNamespace(
295 SiteInstance* instance);
297 // Returns true if the RenderViewHost will never be visible.
298 virtual bool IsNeverVisible();
300 // Returns the FrameTree the render view should use. Guaranteed to be constant
301 // for the lifetime of the render view.
303 // TODO(ajwong): Remove once the main frame RenderFrameHost is no longer
304 // created by the RenderViewHost.
305 virtual FrameTree* GetFrameTree();
307 // Invoked when an accessibility event is received from the renderer.
308 virtual void AccessibilityEventReceived(
309 const std::vector<AXEventNotificationDetails>& details) {}
311 protected:
312 virtual ~RenderViewHostDelegate() {}
315 } // namespace content
317 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_DELEGATE_H_