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