Upstream version 5.34.104.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/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"
22
23 class GURL;
24 class SkBitmap;
25 class WebKeyboardEvent;
26 struct ViewHostMsg_CreateWindow_Params;
27 struct FrameHostMsg_DidCommitProvisionalLoad_Params;
28 struct ViewMsg_PostMessage_Params;
29 struct WebPreferences;
30
31 namespace base {
32 class ListValue;
33 class TimeTicks;
34 }
35
36 namespace IPC {
37 class Message;
38 }
39
40 namespace gfx {
41 class Point;
42 class Rect;
43 class Size;
44 }
45
46 namespace content {
47
48 class BrowserContext;
49 class CrossSiteTransferringRequest;
50 class FrameTree;
51 class PageState;
52 class RenderViewHost;
53 class RenderViewHostDelegateView;
54 class SessionStorageNamespace;
55 class SiteInstance;
56 class WebContents;
57 class WebContentsImpl;
58 struct FileChooserParams;
59 struct GlobalRequestID;
60 struct NativeWebKeyboardEvent;
61 struct Referrer;
62 struct RendererPreferences;
63
64 //
65 // RenderViewHostDelegate
66 //
67 //  An interface implemented by an object interested in knowing about the state
68 //  of the RenderViewHost.
69 //
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   // RendererManagerment -------------------------------------------------------
78   // Functions for managing switching of Renderers. For WebContents, this is
79   // implemented by the RenderFrameHostManager.
80
81   class CONTENT_EXPORT RendererManagement {
82    public:
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,
91         bool proceed,
92         const base::TimeTicks& proceed_time) = 0;
93
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,
107         int64 frame_id,
108         bool should_replace_current_entry) = 0;
109
110    protected:
111     virtual ~RendererManagement() {}
112   };
113
114   // ---------------------------------------------------------------------------
115
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();
120
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);
124
125   // Gets the URL that is currently being displayed, if there is one.
126   virtual const GURL& GetURL() const;
127
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();
132
133   // Return the rect where to display the resize corner, if any, otherwise
134   // an empty rect.
135   virtual gfx::Rect GetRootWindowResizerRect() const = 0;
136
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) {}
141
142   // The RenderView has been constructed.
143   virtual void RenderViewReady(RenderViewHost* render_view_host) {}
144
145   // The RenderView died somehow (crashed or was killed by the user).
146   virtual void RenderViewTerminated(RenderViewHost* render_view_host,
147                                     base::TerminationStatus status,
148                                     int error_code) {}
149
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) {}
153
154   // The state for the page changed and should be updated.
155   virtual void UpdateState(RenderViewHost* render_view_host,
156                            int32 page_id,
157                            const PageState& state) {}
158
159   // The page's title was changed and should be updated.
160   virtual void UpdateTitle(RenderViewHost* render_view_host,
161                            int32 page_id,
162                            const base::string16& title,
163                            base::i18n::TextDirection title_direction) {}
164
165   // The page's encoding was changed and should be updated.
166   virtual void UpdateEncoding(RenderViewHost* render_view_host,
167                               const std::string& encoding) {}
168
169   // The destination URL has changed should be updated
170   virtual void UpdateTargetURL(int32 page_id, const GURL& url) {}
171
172   // The page is trying to close the RenderView's representation in the client.
173   virtual void Close(RenderViewHost* render_view_host) {}
174
175   // The RenderViewHost has been swapped out.
176   virtual void SwappedOut(RenderViewHost* render_view_host) {}
177
178   // The page is trying to move the RenderView's representation in the client.
179   virtual void RequestMove(const gfx::Rect& new_bounds) {}
180
181   // The pending page load was canceled.
182   virtual void DidCancelLoading() {}
183
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
186   // entirely loaded).
187   virtual void DidChangeLoadProgress(double progress) {}
188
189   // The RenderView set its opener to null, disowning it for the lifetime of
190   // the window.
191   virtual void DidDisownOpener(RenderViewHost* rvh) {}
192
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() {}
197
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) {}
201
202   // The onload handler in the RenderView's main frame has completed.
203   virtual void DocumentOnLoadCompletedInMainFrame(
204       RenderViewHost* render_view_host,
205       int32 page_id) {}
206
207   // The page wants to open a URL with the specified disposition.
208   virtual void RequestOpenURL(RenderViewHost* rvh,
209                               const GURL& url,
210                               const Referrer& referrer,
211                               WindowOpenDisposition disposition,
212                               int64 source_frame_id,
213                               bool is_redirect,
214                               bool user_gesture) {}
215
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(
220       const GURL& url,
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,
227       bool is_redirect,
228       bool user_gesture) {}
229
230   // The page wants to close the active view in this tab.
231   virtual void RouteCloseEvent(RenderViewHost* rvh) {}
232
233   // The page wants to post a message to the active view in this tab.
234   virtual void RouteMessageEvent(
235       RenderViewHost* rvh,
236       const ViewMsg_PostMessage_Params& params) {}
237
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) {}
246
247   virtual void RunBeforeUnloadConfirm(RenderViewHost* rvh,
248                                       const base::string16& message,
249                                       bool is_reload,
250                                       IPC::Message* reply_msg) {}
251
252   // A message was added to to the console.
253   virtual bool AddMessageToConsole(int32 level,
254                                    const base::string16& message,
255                                    int32 line_no,
256                                    const base::string16& source_id);
257
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;
262
263   // Returns a WebPreferences object that will be used by the renderer
264   // associated with the owning render view host.
265   virtual WebPreferences GetWebkitPrefs();
266
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() {}
271
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() {}
277
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) {}
283
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) {}
288
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) {}
294
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() {}
299
300   // Notification that the view has lost capture.
301   virtual void LostCapture() {}
302
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() {}
312
313   // Called when a file selection is to be done.
314   virtual void RunFileChooser(
315       RenderViewHost* render_view_host,
316       const FileChooserParams& params) {}
317
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;
321
322   // The contents' preferred size changed.
323   virtual void UpdatePreferredSize(const gfx::Size& pref_size) {}
324
325   // The contents auto-resized and the container should match it.
326   virtual void ResizeDueToAutoResize(const gfx::Size& new_size) {}
327
328   // Requests to lock the mouse. Once the request is approved or rejected,
329   // GotResponseToLockMouseRequest() will be called on the requesting render
330   // view host.
331   virtual void RequestToLockMouse(bool user_gesture,
332                                   bool last_unlocked_by_target) {}
333
334   // Notification that the view has lost the mouse lock.
335   virtual void LostMouseLock() {}
336
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.
344   //
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.
347   //
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,
352       int route_id,
353       int main_frame_route_id,
354       const ViewHostMsg_CreateWindow_Params& params,
355       SessionStorageNamespace* session_storage_namespace) {}
356
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,
364                                int route_id,
365                                blink::WebPopupType popup_type) {}
366
367   // Creates a full screen RenderWidget. Similar to above.
368   virtual void CreateNewFullscreenWidget(int render_process_id, int route_id) {}
369
370   // Show a previously created page with the specified disposition and bounds.
371   // The window is identified by the route_id passed to CreateNewWindow.
372   //
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) {}
379
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) {}
384
385   // Show the newly created full screen widget. Similar to above.
386   virtual void ShowCreatedFullscreenWidget(int route_id) {}
387
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) {}
394
395   // Returns the SessionStorageNamespace the render view should use. Might
396   // create the SessionStorageNamespace on the fly.
397   virtual SessionStorageNamespace* GetSessionStorageNamespace(
398       SiteInstance* instance);
399
400   // Returns the FrameTree the render view should use. Guaranteed to be constant
401   // for the lifetime of the render view.
402   //
403   // TODO(ajwong): Remove once the main frame RenderFrameHost is no longer
404   // created by the RenderViewHost.
405   virtual FrameTree* GetFrameTree();
406
407  protected:
408   virtual ~RenderViewHostDelegate() {}
409 };
410
411 }  // namespace content
412
413 #endif  // CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_DELEGATE_H_