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