Upstream version 8.37.180.0
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / render_view_host_impl.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_IMPL_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/callback.h"
13 #include "base/compiler_specific.h"
14 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/process/kill.h"
17 #include "content/browser/renderer_host/render_widget_host_impl.h"
18 #include "content/browser/site_instance_impl.h"
19 #include "content/common/drag_event_source_info.h"
20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/render_view_host.h"
22 #include "content/public/common/window_container_type.h"
23 #include "net/base/load_states.h"
24 #include "third_party/WebKit/public/web/WebAXEnums.h"
25 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
26 #include "third_party/WebKit/public/web/WebPopupType.h"
27 #include "third_party/skia/include/core/SkColor.h"
28 #include "ui/accessibility/ax_node_data.h"
29 #include "ui/base/window_open_disposition.h"
30
31 class SkBitmap;
32 class FrameMsg_Navigate;
33 struct AccessibilityHostMsg_EventParams;
34 struct AccessibilityHostMsg_LocationChangeParams;
35 struct MediaPlayerAction;
36 struct ViewHostMsg_CreateWindow_Params;
37 struct ViewHostMsg_ShowPopup_Params;
38 struct FrameMsg_Navigate_Params;
39 struct ViewMsg_PostMessage_Params;
40
41 namespace base {
42 class ListValue;
43 }
44
45 namespace gfx {
46 class Range;
47 }
48
49 namespace ui {
50 class AXTree;
51 struct SelectedFileInfo;
52 }
53
54 namespace content {
55
56 class MediaWebContentsObserver;
57 class ChildProcessSecurityPolicyImpl;
58 class PageState;
59 class RenderWidgetHostDelegate;
60 class SessionStorageNamespace;
61 class SessionStorageNamespaceImpl;
62 class TestRenderViewHost;
63 class TimeoutMonitor;
64 struct FileChooserParams;
65
66 #if defined(COMPILER_MSVC)
67 // RenderViewHostImpl is the bottom of a diamond-shaped hierarchy,
68 // with RenderWidgetHost at the root. VS warns when methods from the
69 // root are overridden in only one of the base classes and not both
70 // (in this case, RenderWidgetHostImpl provides implementations of
71 // many of the methods).  This is a silly warning when dealing with
72 // pure virtual methods that only have a single implementation in the
73 // hierarchy above this class, and is safe to ignore in this case.
74 #pragma warning(push)
75 #pragma warning(disable: 4250)
76 #endif
77
78 // This implements the RenderViewHost interface that is exposed to
79 // embedders of content, and adds things only visible to content.
80 //
81 // The exact API of this object needs to be more thoroughly designed. Right
82 // now it mimics what WebContentsImpl exposed, which is a fairly large API and
83 // may contain things that are not relevant to a common subset of views. See
84 // also the comment in render_view_host_delegate.h about the size and scope of
85 // the delegate API.
86 //
87 // Right now, the concept of page navigation (both top level and frame) exists
88 // in the WebContentsImpl still, so if you instantiate one of these elsewhere,
89 // you will not be able to traverse pages back and forward. We need to determine
90 // if we want to bring that and other functionality down into this object so it
91 // can be shared by others.
92 class CONTENT_EXPORT RenderViewHostImpl
93     : public RenderViewHost,
94       public RenderWidgetHostImpl {
95  public:
96   // Keeps track of the state of the RenderViewHostImpl, particularly with
97   // respect to swap out.
98   enum RenderViewHostImplState {
99     // The standard state for a RVH handling the communication with a
100     // RenderView.
101     STATE_DEFAULT = 0,
102     // The RVH has sent the SwapOut request to the renderer, but has not
103     // received the SwapOutACK yet. The new page has not been committed yet
104     // either.
105     STATE_WAITING_FOR_UNLOAD_ACK,
106     // The RVH received the SwapOutACK from the RenderView, but the new page has
107     // not been committed yet.
108     STATE_WAITING_FOR_COMMIT,
109     // The RVH is waiting for the CloseACK from the RenderView.
110     STATE_WAITING_FOR_CLOSE,
111     // The RVH has not received the SwapOutACK yet, but the new page has
112     // committed in a different RVH. The number of active views of the RVH
113     // SiteInstanceImpl is not zero. Upon reception of the SwapOutACK, the RVH
114     // will be swapped out.
115     STATE_PENDING_SWAP_OUT,
116     // The RVH has not received the SwapOutACK yet, but the new page has
117     // committed in a different RVH. The number of active views of the RVH
118     // SiteInstanceImpl is zero. Upon reception of the SwapOutACK, the RVH will
119     // be shutdown.
120     STATE_PENDING_SHUTDOWN,
121     // The RVH is swapped out, and it is being used as a placeholder to allow
122     // for cross-process communication.
123     STATE_SWAPPED_OUT,
124   };
125   // Helper function to determine whether the RVH state should contribute to the
126   // number of active views of a SiteInstance or not.
127   static bool IsRVHStateActive(RenderViewHostImplState rvh_state);
128
129   // Convenience function, just like RenderViewHost::FromID.
130   static RenderViewHostImpl* FromID(int render_process_id, int render_view_id);
131
132   // |routing_id| could be a valid route id, or it could be MSG_ROUTING_NONE, in
133   // which case RenderWidgetHost will create a new one.  |swapped_out| indicates
134   // whether the view should initially be swapped out (e.g., for an opener
135   // frame being rendered by another process). |hidden| indicates whether the
136   // view is initially hidden or visible.
137   //
138   // The |session_storage_namespace| parameter allows multiple render views and
139   // WebContentses to share the same session storage (part of the WebStorage
140   // spec) space. This is useful when restoring contentses, but most callers
141   // should pass in NULL which will cause a new SessionStorageNamespace to be
142   // created.
143   RenderViewHostImpl(
144       SiteInstance* instance,
145       RenderViewHostDelegate* delegate,
146       RenderWidgetHostDelegate* widget_delegate,
147       int routing_id,
148       int main_frame_routing_id,
149       bool swapped_out,
150       bool hidden);
151   virtual ~RenderViewHostImpl();
152
153   // RenderViewHost implementation.
154   virtual RenderFrameHost* GetMainFrame() OVERRIDE;
155   virtual void AllowBindings(int binding_flags) OVERRIDE;
156   virtual void ClearFocusedElement() OVERRIDE;
157   virtual bool IsFocusedElementEditable() OVERRIDE;
158   virtual void ClosePage() OVERRIDE;
159   virtual void CopyImageAt(int x, int y) OVERRIDE;
160   virtual void SaveImageAt(int x, int y) OVERRIDE;
161   virtual void DirectoryEnumerationFinished(
162       int request_id,
163       const std::vector<base::FilePath>& files) OVERRIDE;
164   virtual void DisableScrollbarsForThreshold(const gfx::Size& size) OVERRIDE;
165   virtual void DragSourceEndedAt(
166       int client_x, int client_y, int screen_x, int screen_y,
167       blink::WebDragOperation operation) OVERRIDE;
168   virtual void DragSourceSystemDragEnded() OVERRIDE;
169   virtual void DragTargetDragEnter(
170       const DropData& drop_data,
171       const gfx::Point& client_pt,
172       const gfx::Point& screen_pt,
173       blink::WebDragOperationsMask operations_allowed,
174       int key_modifiers) OVERRIDE;
175   virtual void DragTargetDragOver(
176       const gfx::Point& client_pt,
177       const gfx::Point& screen_pt,
178       blink::WebDragOperationsMask operations_allowed,
179       int key_modifiers) OVERRIDE;
180   virtual void DragTargetDragLeave() OVERRIDE;
181   virtual void DragTargetDrop(const gfx::Point& client_pt,
182                               const gfx::Point& screen_pt,
183                               int key_modifiers) OVERRIDE;
184   virtual void EnableAutoResize(const gfx::Size& min_size,
185                                 const gfx::Size& max_size) OVERRIDE;
186   virtual void DisableAutoResize(const gfx::Size& new_size) OVERRIDE;
187   virtual void EnablePreferredSizeMode() OVERRIDE;
188   virtual void ExecuteMediaPlayerActionAtLocation(
189       const gfx::Point& location,
190       const blink::WebMediaPlayerAction& action) OVERRIDE;
191   virtual void ExecutePluginActionAtLocation(
192       const gfx::Point& location,
193       const blink::WebPluginAction& action) OVERRIDE;
194   virtual void ExitFullscreen() OVERRIDE;
195   virtual void FilesSelectedInChooser(
196       const std::vector<ui::SelectedFileInfo>& files,
197       FileChooserParams::Mode permissions) OVERRIDE;
198   virtual RenderViewHostDelegate* GetDelegate() const OVERRIDE;
199   virtual int GetEnabledBindings() const OVERRIDE;
200   virtual SiteInstance* GetSiteInstance() const OVERRIDE;
201   virtual bool IsRenderViewLive() const OVERRIDE;
202   virtual void NotifyMoveOrResizeStarted() OVERRIDE;
203   virtual void SetWebUIProperty(const std::string& name,
204                                 const std::string& value) OVERRIDE;
205   virtual void Zoom(PageZoom zoom) OVERRIDE;
206   virtual void SyncRendererPrefs() OVERRIDE;
207   virtual WebPreferences GetWebkitPreferences() OVERRIDE;
208   virtual void UpdateWebkitPreferences(
209       const WebPreferences& prefs) OVERRIDE;
210   virtual void GetAudioOutputControllers(
211       const GetAudioOutputControllersCallback& callback) const OVERRIDE;
212   virtual void SetWebUIHandle(mojo::ScopedMessagePipeHandle handle) OVERRIDE;
213   virtual void SelectWordAroundCaret() OVERRIDE;
214
215 #if defined(OS_ANDROID)
216   virtual void ActivateNearestFindResult(int request_id,
217                                          float x,
218                                          float y) OVERRIDE;
219   virtual void RequestFindMatchRects(int current_version) OVERRIDE;
220 #endif
221
222   void set_delegate(RenderViewHostDelegate* d) {
223     CHECK(d);  // http://crbug.com/82827
224     delegate_ = d;
225   }
226
227   // Set up the RenderView child process. Virtual because it is overridden by
228   // TestRenderViewHost. If the |frame_name| parameter is non-empty, it is used
229   // as the name of the new top-level frame.
230   // The |opener_route_id| parameter indicates which RenderView created this
231   // (MSG_ROUTING_NONE if none). If |max_page_id| is larger than -1, the
232   // RenderView is told to start issuing page IDs at |max_page_id| + 1.
233   // |window_was_created_with_opener| is true if this top-level frame was
234   // created with an opener. (The opener may have been closed since.)
235   // The |proxy_route_id| is only used when creating a RenderView in swapped out
236   // state.
237   virtual bool CreateRenderView(const base::string16& frame_name,
238                                 int opener_route_id,
239                                 int proxy_route_id,
240                                 int32 max_page_id,
241                                 bool window_was_created_with_opener);
242
243   base::TerminationStatus render_view_termination_status() const {
244     return render_view_termination_status_;
245   }
246
247   // Returns the content specific prefs for this RenderViewHost.
248   WebPreferences GetWebkitPrefs(const GURL& url);
249
250   // Sends the given navigation message. Use this rather than sending it
251   // yourself since this does the internal bookkeeping described below. This
252   // function takes ownership of the provided message pointer.
253   //
254   // If a cross-site request is in progress, we may be suspended while waiting
255   // for the onbeforeunload handler, so this function might buffer the message
256   // rather than sending it.
257   // TODO(nasko): Remove this method once all callers are converted to use
258   // RenderFrameHostImpl.
259   void Navigate(const FrameMsg_Navigate_Params& message);
260
261   // Load the specified URL, this is a shortcut for Navigate().
262   // TODO(nasko): Remove this method once all callers are converted to use
263   // RenderFrameHostImpl.
264   void NavigateToURL(const GURL& url);
265
266   // Returns whether navigation messages are currently suspended for this
267   // RenderViewHost.  Only true during a cross-site navigation, while waiting
268   // for the onbeforeunload handler.
269   bool are_navigations_suspended() const { return navigations_suspended_; }
270
271   // Suspends (or unsuspends) any navigation messages from being sent from this
272   // RenderViewHost.  This is called when a pending RenderViewHost is created
273   // for a cross-site navigation, because we must suspend any navigations until
274   // we hear back from the old renderer's onbeforeunload handler.  Note that it
275   // is important that only one navigation event happen after calling this
276   // method with |suspend| equal to true.  If |suspend| is false and there is
277   // a suspended_nav_message_, this will send the message.  This function
278   // should only be called to toggle the state; callers should check
279   // are_navigations_suspended() first. If |suspend| is false, the time that the
280   // user decided the navigation should proceed should be passed as
281   // |proceed_time|.
282   void SetNavigationsSuspended(bool suspend,
283                                const base::TimeTicks& proceed_time);
284
285   // Clears any suspended navigation state after a cross-site navigation is
286   // canceled or suspended.  This is important if we later return to this
287   // RenderViewHost.
288   void CancelSuspendedNavigations();
289
290   // Whether this RenderViewHost has been swapped out to be displayed by a
291   // different process.
292   bool IsSwappedOut() const { return rvh_state_ == STATE_SWAPPED_OUT; }
293
294   // The current state of this RVH.
295   RenderViewHostImplState rvh_state() const { return rvh_state_; }
296
297   // Tells the renderer that this RenderView will soon be swapped out, and thus
298   // not to create any new modal dialogs until it happens.  This must be done
299   // separately so that the PageGroupLoadDeferrers of any current dialogs are no
300   // longer on the stack when we attempt to swap it out.
301   void SuppressDialogsUntilSwapOut();
302
303   // Called when either the SwapOut request has been acknowledged or has timed
304   // out.
305   void OnSwappedOut(bool timed_out);
306
307   // Called when the RenderFrameHostManager has swapped in a new
308   // RenderFrameHost. Should |this| RVH switch to the pending shutdown state,
309   // |pending_delete_on_swap_out| will be executed upon reception of the
310   // SwapOutACK, or when the unload timer times out.
311   void WasSwappedOut(const base::Closure& pending_delete_on_swap_out);
312
313   // Set |this| as pending shutdown. |on_swap_out| will be called
314   // when the SwapOutACK is received, or when the unload timer times out.
315   void SetPendingShutdown(const base::Closure& on_swap_out);
316
317   // Close the page ignoring whether it has unload events registers.
318   // This is called after the beforeunload and unload events have fired
319   // and the user has agreed to continue with closing the page.
320   void ClosePageIgnoringUnloadEvents();
321
322   // Returns whether this RenderViewHost has an outstanding cross-site request.
323   // Cleared when we hear the response and start to swap out the old
324   // RenderViewHost, or if we hear a commit here without a network request.
325   bool HasPendingCrossSiteRequest();
326
327   // Sets whether this RenderViewHost has an outstanding cross-site request,
328   // for which another renderer will need to run an onunload event handler.
329   // This is called before the first navigation event for this RenderViewHost,
330   // and cleared when we hear the response or commit.
331   void SetHasPendingCrossSiteRequest(bool has_pending_request);
332
333   // Tells the renderer view to focus the first (last if reverse is true) node.
334   void SetInitialFocus(bool reverse);
335
336   // Get html data by serializing all frames of current page with lists
337   // which contain all resource links that have local copy.
338   // The parameter links contain original URLs of all saved links.
339   // The parameter local_paths contain corresponding local file paths of
340   // all saved links, which matched with vector:links one by one.
341   // The parameter local_directory_name is relative path of directory which
342   // contain all saved auxiliary files included all sub frames and resouces.
343   void GetSerializedHtmlDataForCurrentPageWithLocalLinks(
344       const std::vector<GURL>& links,
345       const std::vector<base::FilePath>& local_paths,
346       const base::FilePath& local_directory_name);
347
348   // Notifies the RenderViewHost that its load state changed.
349   void LoadStateChanged(const GURL& url,
350                         const net::LoadStateWithParam& load_state,
351                         uint64 upload_position,
352                         uint64 upload_size);
353
354   bool SuddenTerminationAllowed() const;
355   void set_sudden_termination_allowed(bool enabled) {
356     sudden_termination_allowed_ = enabled;
357   }
358
359   // RenderWidgetHost public overrides.
360   virtual void Init() OVERRIDE;
361   virtual void Shutdown() OVERRIDE;
362   virtual bool IsRenderView() const OVERRIDE;
363   virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
364   virtual void GotFocus() OVERRIDE;
365   virtual void LostCapture() OVERRIDE;
366   virtual void LostMouseLock() OVERRIDE;
367   virtual void ForwardMouseEvent(
368       const blink::WebMouseEvent& mouse_event) OVERRIDE;
369   virtual void OnPointerEventActivate() OVERRIDE;
370   virtual void ForwardKeyboardEvent(
371       const NativeWebKeyboardEvent& key_event) OVERRIDE;
372   virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
373
374   // Creates a new RenderView with the given route id.
375   void CreateNewWindow(
376       int route_id,
377       int main_frame_route_id,
378       const ViewHostMsg_CreateWindow_Params& params,
379       SessionStorageNamespace* session_storage_namespace);
380
381   // Creates a new RenderWidget with the given route id.  |popup_type| indicates
382   // if this widget is a popup and what kind of popup it is (select, autofill).
383   void CreateNewWidget(int route_id, blink::WebPopupType popup_type);
384
385   // Creates a full screen RenderWidget.
386   void CreateNewFullscreenWidget(int route_id);
387
388 #if defined(OS_MACOSX)
389   // Select popup menu related methods (for external popup menus).
390   void DidSelectPopupMenuItem(int selected_index);
391   void DidCancelPopupMenu();
392 #endif
393
394 #if defined(ENABLE_BROWSER_CDMS)
395   MediaWebContentsObserver* media_web_contents_observer() {
396     return media_web_contents_observer_.get();
397   }
398 #endif
399
400 #if defined(OS_ANDROID)
401   void DidSelectPopupMenuItems(const std::vector<int>& selected_indices);
402   void DidCancelPopupMenu();
403 #endif
404
405   int main_frame_routing_id() const {
406     return main_frame_routing_id_;
407   }
408
409   // Set the opener to null in the renderer process.
410   void DisownOpener();
411
412   // Turn on accessibility testing. The given callback will be run
413   // every time an accessibility notification is received from the
414   // renderer process, and the accessibility tree it sent can be
415   // retrieved using accessibility_tree_for_testing().
416   void SetAccessibilityCallbackForTesting(
417       const base::Callback<void(ui::AXEvent, int)>& callback);
418
419   // Only valid if SetAccessibilityCallbackForTesting was called and
420   // the callback was run at least once. Returns a snapshot of the
421   // accessibility tree received from the renderer as of the last time
422   // an accessibility notification was received.
423   const ui::AXTree& ax_tree_for_testing() {
424     CHECK(ax_tree_.get());
425     return *ax_tree_.get();
426   }
427
428   // Set accessibility callbacks.
429   void SetAccessibilityLayoutCompleteCallbackForTesting(
430       const base::Closure& callback);
431   void SetAccessibilityLoadCompleteCallbackForTesting(
432       const base::Closure& callback);
433   void SetAccessibilityOtherCallbackForTesting(
434       const base::Closure& callback);
435
436   bool is_waiting_for_beforeunload_ack() {
437     return is_waiting_for_beforeunload_ack_;
438   }
439
440   // Whether the RVH is waiting for the unload ack from the renderer.
441   bool IsWaitingForUnloadACK() const;
442
443   void OnTextSurroundingSelectionResponse(const base::string16& content,
444                                           size_t start_offset,
445                                           size_t end_offset);
446
447   // Update the FrameTree to use this RenderViewHost's main frame
448   // RenderFrameHost. Called when the RenderViewHost is committed.
449   //
450   // TODO(ajwong): Remove once RenderViewHost no longer owns the main frame
451   // RenderFrameHost.
452   void AttachToFrameTree();
453
454   // Increases the refcounting on this RVH. This is done by the FrameTree on
455   // creation of a RenderFrameHost.
456   void increment_ref_count() { ++frames_ref_count_; }
457
458   // Decreases the refcounting on this RVH. This is done by the FrameTree on
459   // destruction of a RenderFrameHost.
460   void decrement_ref_count() { --frames_ref_count_; }
461
462   // Returns the refcount on this RVH, that is the number of RenderFrameHosts
463   // currently using it.
464   int ref_count() { return frames_ref_count_; }
465
466   // NOTE: Do not add functions that just send an IPC message that are called in
467   // one or two places. Have the caller send the IPC message directly (unless
468   // the caller places are in different platforms, in which case it's better
469   // to keep them consistent).
470
471  protected:
472   // RenderWidgetHost protected overrides.
473   virtual void OnUserGesture() OVERRIDE;
474   virtual void NotifyRendererUnresponsive() OVERRIDE;
475   virtual void NotifyRendererResponsive() OVERRIDE;
476   virtual void OnRenderAutoResized(const gfx::Size& size) OVERRIDE;
477   virtual void RequestToLockMouse(bool user_gesture,
478                                   bool last_unlocked_by_target) OVERRIDE;
479   virtual bool IsFullscreen() const OVERRIDE;
480   virtual void OnFocus() OVERRIDE;
481   virtual void OnBlur() OVERRIDE;
482
483   // IPC message handlers.
484   void OnShowView(int route_id,
485                   WindowOpenDisposition disposition,
486                   const gfx::Rect& initial_pos,
487                   bool user_gesture);
488   void OnShowWidget(int route_id, const gfx::Rect& initial_pos);
489   void OnShowFullscreenWidget(int route_id);
490   void OnRunModal(int opener_id, IPC::Message* reply_msg);
491   void OnRenderViewReady();
492   void OnRenderProcessGone(int status, int error_code);
493   void OnUpdateState(int32 page_id, const PageState& state);
494   void OnUpdateTargetURL(int32 page_id, const GURL& url);
495   void OnClose();
496   void OnRequestMove(const gfx::Rect& pos);
497   void OnDocumentAvailableInMainFrame(bool uses_temporary_zoom_level);
498   void OnToggleFullscreen(bool enter_fullscreen);
499   void OnDidContentsPreferredSizeChange(const gfx::Size& new_size);
500   void OnDidChangeScrollOffset();
501   void OnPasteFromSelectionClipboard();
502   void OnRouteCloseEvent();
503   void OnRouteMessageEvent(const ViewMsg_PostMessage_Params& params);
504   void OnStartDragging(const DropData& drop_data,
505                        blink::WebDragOperationsMask operations_allowed,
506                        const SkBitmap& bitmap,
507                        const gfx::Vector2d& bitmap_offset_in_dip,
508                        const DragEventSourceInfo& event_info);
509   void OnUpdateDragCursor(blink::WebDragOperation drag_operation);
510   void OnTargetDropACK();
511   void OnTakeFocus(bool reverse);
512   void OnFocusedNodeChanged(bool is_editable_node);
513   void OnUpdateInspectorSetting(const std::string& key,
514                                 const std::string& value);
515   void OnClosePageACK();
516   void OnAccessibilityEvents(
517       const std::vector<AccessibilityHostMsg_EventParams>& params);
518   void OnAccessibilityLocationChanges(
519       const std::vector<AccessibilityHostMsg_LocationChangeParams>& params);
520   void OnDidZoomURL(double zoom_level, const GURL& url);
521   void OnRunFileChooser(const FileChooserParams& params);
522   void OnFocusedNodeTouched(bool editable);
523
524 #if defined(OS_MACOSX) || defined(OS_ANDROID)
525   void OnShowPopup(const ViewHostMsg_ShowPopup_Params& params);
526   void OnHidePopup();
527 #endif
528
529  private:
530   // TODO(nasko): Temporarily friend RenderFrameHostImpl, so we don't duplicate
531   // utility functions and state needed in both classes, while we move frame
532   // specific code away from this class.
533   friend class RenderFrameHostImpl;
534   friend class TestRenderViewHost;
535   FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, BasicRenderFrameHost);
536   FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, RoutingIdSane);
537
538   // TODO(creis): Move to a private namespace on RenderFrameHostImpl.
539   // Delay to wait on closing the WebContents for a beforeunload/unload handler
540   // to fire.
541   static const int kUnloadTimeoutMS;
542
543   // Updates the state of this RenderViewHost and clears any waiting state
544   // that is no longer relevant.
545   void SetState(RenderViewHostImplState rvh_state);
546
547   bool CanAccessFilesOfPageState(const PageState& state) const;
548
549   // The number of RenderFrameHosts which have a reference to this RVH.
550   int frames_ref_count_;
551
552   // Our delegate, which wants to know about changes in the RenderView.
553   RenderViewHostDelegate* delegate_;
554
555   // The SiteInstance associated with this RenderViewHost.  All pages drawn
556   // in this RenderViewHost are part of this SiteInstance.  Should not change
557   // over time.
558   scoped_refptr<SiteInstanceImpl> instance_;
559
560   // true if we are currently waiting for a response for drag context
561   // information.
562   bool waiting_for_drag_context_response_;
563
564   // A bitwise OR of bindings types that have been enabled for this RenderView.
565   // See BindingsPolicy for details.
566   int enabled_bindings_;
567
568   // Whether we should buffer outgoing Navigate messages rather than sending
569   // them.  This will be true when a RenderViewHost is created for a cross-site
570   // request, until we hear back from the onbeforeunload handler of the old
571   // RenderViewHost.
572   // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
573   bool navigations_suspended_;
574
575   // We only buffer the params for a suspended navigation while we have a
576   // pending RVH for a WebContentsImpl.  There will only ever be one suspended
577   // navigation, because WebContentsImpl will destroy the pending RVH and create
578   // a new one if a second navigation occurs.
579   // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
580   scoped_ptr<FrameMsg_Navigate_Params> suspended_nav_params_;
581
582   // The current state of this RVH.
583   // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
584   RenderViewHostImplState rvh_state_;
585
586   // Routing ID for the main frame's RenderFrameHost.
587   int main_frame_routing_id_;
588
589   // If we were asked to RunModal, then this will hold the reply_msg that we
590   // must return to the renderer to unblock it.
591   IPC::Message* run_modal_reply_msg_;
592   // This will hold the routing id of the RenderView that opened us.
593   int run_modal_opener_id_;
594
595   // Set to true when there is a pending ViewMsg_ShouldClose message.  This
596   // ensures we don't spam the renderer with multiple beforeunload requests.
597   // When either this value or IsWaitingForUnloadACK is true, the value of
598   // unload_ack_is_for_cross_site_transition_ indicates whether this is for a
599   // cross-site transition or a tab close attempt.
600   // TODO(clamy): Remove this boolean and add one more state to the state
601   // machine.
602   // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
603   bool is_waiting_for_beforeunload_ack_;
604
605   // Valid only when is_waiting_for_beforeunload_ack_ or
606   // IsWaitingForUnloadACK is true.  This tells us if the unload request
607   // is for closing the entire tab ( = false), or only this RenderViewHost in
608   // the case of a cross-site transition ( = true).
609   // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
610   bool unload_ack_is_for_cross_site_transition_;
611
612   // Accessibility callback for testing.
613   base::Callback<void(ui::AXEvent, int)> accessibility_testing_callback_;
614
615   // The most recently received accessibility tree - for testing only.
616   scoped_ptr<ui::AXTree> ax_tree_;
617
618   // True if the render view can be shut down suddenly.
619   bool sudden_termination_allowed_;
620
621   // The termination status of the last render view that terminated.
622   base::TerminationStatus render_view_termination_status_;
623
624   // Set to true if we requested the on screen keyboard to be displayed.
625   bool virtual_keyboard_requested_;
626
627 #if defined(ENABLE_BROWSER_CDMS)
628   // Manages all the media player and CDM managers and forwards IPCs to them.
629   scoped_ptr<MediaWebContentsObserver> media_web_contents_observer_;
630 #endif
631
632   // Used to swap out or shutdown this RVH when the unload event is taking too
633   // long to execute, depending on the number of active views in the
634   // SiteInstance.
635   // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
636   scoped_ptr<TimeoutMonitor> unload_event_monitor_timeout_;
637
638   // Called after receiving the SwapOutACK when the RVH is in state pending
639   // shutdown. Also called if the unload timer times out.
640   // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
641   base::Closure pending_shutdown_on_swap_out_;
642
643   base::WeakPtrFactory<RenderViewHostImpl> weak_factory_;
644
645   // True if the current focused element is editable.
646   bool is_focused_element_editable_;
647
648   DISALLOW_COPY_AND_ASSIGN(RenderViewHostImpl);
649 };
650
651 #if defined(COMPILER_MSVC)
652 #pragma warning(pop)
653 #endif
654
655 }  // namespace content
656
657 #endif  // CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_