render_view_host_impl.h revision 8bcbed890bc3ce4d7a057a8f32cab53fa534672e
1bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// Use of this source code is governed by a BSD-style license that can be
3f5256e16dfc425c1d466f6308d4026d529ce9e0bHoward Hinnant// found in the LICENSE file.
4bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
5b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant#ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_
6b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant#define CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_
7bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
8bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include <map>
9bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include <string>
10bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include <vector>
11bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
126e0a1f458e41c08112a130f50636ced03907e29eHoward Hinnant#include "base/compiler_specific.h"
13bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include "base/logging.h"
14bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include "base/memory/scoped_ptr.h"
15bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include "base/observer_list.h"
16bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include "base/process/kill.h"
17bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include "content/browser/renderer_host/render_frame_host_impl.h"
18061d0cc4db18d17bf01ed14c5db0be098205bd47Marshall Clow#include "content/browser/renderer_host/render_widget_host_impl.h"
199dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnant#include "content/browser/site_instance_impl.h"
20bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include "content/common/accessibility_node_data.h"
21bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include "content/common/drag_event_source_info.h"
22bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include "content/public/browser/notification_observer.h"
23bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include "content/public/browser/render_view_host.h"
24bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include "content/public/common/javascript_message_type.h"
25bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include "content/public/common/window_container_type.h"
26bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include "net/base/load_states.h"
27bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include "third_party/WebKit/public/web/WebAXEnums.h"
28bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include "third_party/WebKit/public/web/WebConsoleMessage.h"
299dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnant#include "third_party/WebKit/public/web/WebPopupType.h"
309dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnant#include "third_party/WebKit/public/web/WebTextDirection.h"
319dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnant#include "third_party/skia/include/core/SkColor.h"
329dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnant#include "ui/base/window_open_disposition.h"
339dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnant
349dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnantclass SkBitmap;
359dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnantclass ViewMsg_Navigate;
369dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnantstruct AccessibilityHostMsg_EventParams;
379dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnantstruct MediaPlayerAction;
389dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnantstruct ViewHostMsg_CreateWindow_Params;
399dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnantstruct ViewHostMsg_DidFailProvisionalLoadWithError_Params;
409dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnantstruct ViewHostMsg_OpenURL_Params;
419dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnantstruct ViewHostMsg_SelectionBounds_Params;
429dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnantstruct ViewHostMsg_ShowPopup_Params;
439dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnantstruct ViewMsg_Navigate_Params;
449dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnantstruct ViewMsg_PostMessage_Params;
459dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnantstruct ViewMsg_StopFinding_Params;
469dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnant
479dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnantnamespace base {
489dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnantclass ListValue;
499dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnant}
509dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnant
51bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantnamespace gfx {
52bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantclass Range;
53bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant}
54bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
55bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantnamespace ui {
56bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantstruct SelectedFileInfo;
57bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant}
58bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
59bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantnamespace content {
60bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
61bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantclass BrowserMediaPlayerManager;
62bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantclass ChildProcessSecurityPolicyImpl;
63bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantclass PageState;
64bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantclass RenderFrameHostImpl;
65bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantclass RenderViewHostObserver;
66bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantclass RenderWidgetHostDelegate;
679dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnantclass SessionStorageNamespace;
689dcdcdee2582575dd4a2e5857b9f32735763f9c7Howard Hinnantclass SessionStorageNamespaceImpl;
69bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantclass TestRenderViewHost;
70struct ContextMenuParams;
71struct FileChooserParams;
72struct Referrer;
73struct ShowDesktopNotificationHostMsgParams;
74
75#if defined(COMPILER_MSVC)
76// RenderViewHostImpl is the bottom of a diamond-shaped hierarchy,
77// with RenderWidgetHost at the root. VS warns when methods from the
78// root are overridden in only one of the base classes and not both
79// (in this case, RenderWidgetHostImpl provides implementations of
80// many of the methods).  This is a silly warning when dealing with
81// pure virtual methods that only have a single implementation in the
82// hierarchy above this class, and is safe to ignore in this case.
83#pragma warning(push)
84#pragma warning(disable: 4250)
85#endif
86
87// This implements the RenderViewHost interface that is exposed to
88// embedders of content, and adds things only visible to content.
89//
90// The exact API of this object needs to be more thoroughly designed. Right
91// now it mimics what WebContentsImpl exposed, which is a fairly large API and
92// may contain things that are not relevant to a common subset of views. See
93// also the comment in render_view_host_delegate.h about the size and scope of
94// the delegate API.
95//
96// Right now, the concept of page navigation (both top level and frame) exists
97// in the WebContentsImpl still, so if you instantiate one of these elsewhere,
98// you will not be able to traverse pages back and forward. We need to determine
99// if we want to bring that and other functionality down into this object so it
100// can be shared by others.
101class CONTENT_EXPORT RenderViewHostImpl
102    : public RenderViewHost,
103      public RenderWidgetHostImpl {
104 public:
105  // Convenience function, just like RenderViewHost::FromID.
106  static RenderViewHostImpl* FromID(int render_process_id, int render_view_id);
107
108  // |routing_id| could be a valid route id, or it could be MSG_ROUTING_NONE, in
109  // which case RenderWidgetHost will create a new one.  |swapped_out| indicates
110  // whether the view should initially be swapped out (e.g., for an opener
111  // frame being rendered by another process). |hidden| indicates whether the
112  // view is initially hidden or visible.
113  //
114  // The |session_storage_namespace| parameter allows multiple render views and
115  // WebContentses to share the same session storage (part of the WebStorage
116  // spec) space. This is useful when restoring contentses, but most callers
117  // should pass in NULL which will cause a new SessionStorageNamespace to be
118  // created.
119  RenderViewHostImpl(
120      SiteInstance* instance,
121      RenderViewHostDelegate* delegate,
122      RenderWidgetHostDelegate* widget_delegate,
123      int routing_id,
124      int main_frame_routing_id,
125      bool swapped_out,
126      bool hidden);
127  virtual ~RenderViewHostImpl();
128
129  // RenderViewHost implementation.
130  virtual void AllowBindings(int binding_flags) OVERRIDE;
131  virtual void ClearFocusedNode() OVERRIDE;
132  virtual void ClosePage() OVERRIDE;
133  virtual void CopyImageAt(int x, int y) OVERRIDE;
134  virtual void DesktopNotificationPermissionRequestDone(
135      int callback_context) OVERRIDE;
136  virtual void DesktopNotificationPostDisplay(int callback_context) OVERRIDE;
137  virtual void DesktopNotificationPostError(int notification_id,
138                                            const string16& message) OVERRIDE;
139  virtual void DesktopNotificationPostClose(int notification_id,
140                                            bool by_user) OVERRIDE;
141  virtual void DesktopNotificationPostClick(int notification_id) OVERRIDE;
142  virtual void DirectoryEnumerationFinished(
143      int request_id,
144      const std::vector<base::FilePath>& files) OVERRIDE;
145  virtual void DisableScrollbarsForThreshold(const gfx::Size& size) OVERRIDE;
146  virtual void DragSourceEndedAt(
147      int client_x, int client_y, int screen_x, int screen_y,
148      WebKit::WebDragOperation operation) OVERRIDE;
149  virtual void DragSourceMovedTo(
150      int client_x, int client_y, int screen_x, int screen_y) OVERRIDE;
151  virtual void DragSourceSystemDragEnded() OVERRIDE;
152  virtual void DragTargetDragEnter(
153      const DropData& drop_data,
154      const gfx::Point& client_pt,
155      const gfx::Point& screen_pt,
156      WebKit::WebDragOperationsMask operations_allowed,
157      int key_modifiers) OVERRIDE;
158  virtual void DragTargetDragOver(
159      const gfx::Point& client_pt,
160      const gfx::Point& screen_pt,
161      WebKit::WebDragOperationsMask operations_allowed,
162      int key_modifiers) OVERRIDE;
163  virtual void DragTargetDragLeave() OVERRIDE;
164  virtual void DragTargetDrop(const gfx::Point& client_pt,
165                              const gfx::Point& screen_pt,
166                              int key_modifiers) OVERRIDE;
167  virtual void EnableAutoResize(const gfx::Size& min_size,
168                                const gfx::Size& max_size) OVERRIDE;
169  virtual void DisableAutoResize(const gfx::Size& new_size) OVERRIDE;
170  virtual void EnablePreferredSizeMode() OVERRIDE;
171  virtual void ExecuteCustomContextMenuCommand(
172      int action, const CustomContextMenuContext& context) OVERRIDE;
173  virtual void ExecuteMediaPlayerActionAtLocation(
174      const gfx::Point& location,
175      const WebKit::WebMediaPlayerAction& action) OVERRIDE;
176  virtual void ExecuteJavascriptInWebFrame(const string16& frame_xpath,
177                                           const string16& jscript) OVERRIDE;
178  virtual void ExecuteJavascriptInWebFrameCallbackResult(
179      const string16& frame_xpath,
180      const string16& jscript,
181      const JavascriptResultCallback& callback) OVERRIDE;
182  virtual void ExecutePluginActionAtLocation(
183      const gfx::Point& location,
184      const WebKit::WebPluginAction& action) OVERRIDE;
185  virtual void ExitFullscreen() OVERRIDE;
186  virtual void Find(int request_id, const string16& search_text,
187                    const WebKit::WebFindOptions& options) OVERRIDE;
188  virtual void StopFinding(StopFindAction action) OVERRIDE;
189  virtual void FirePageBeforeUnload(bool for_cross_site_transition) OVERRIDE;
190  virtual void FilesSelectedInChooser(
191      const std::vector<ui::SelectedFileInfo>& files,
192      FileChooserParams::Mode permissions) OVERRIDE;
193  virtual RenderViewHostDelegate* GetDelegate() const OVERRIDE;
194  virtual int GetEnabledBindings() const OVERRIDE;
195  virtual SiteInstance* GetSiteInstance() const OVERRIDE;
196  virtual void InsertCSS(const string16& frame_xpath,
197                         const std::string& css) OVERRIDE;
198  virtual bool IsRenderViewLive() const OVERRIDE;
199  virtual bool IsSubframe() const OVERRIDE;
200  virtual void NotifyContextMenuClosed(
201      const CustomContextMenuContext& context) OVERRIDE;
202  virtual void NotifyMoveOrResizeStarted() OVERRIDE;
203  virtual void ReloadFrame() OVERRIDE;
204  virtual void SetAltErrorPageURL(const GURL& url) OVERRIDE;
205  virtual void SetWebUIProperty(const std::string& name,
206                                const std::string& value) OVERRIDE;
207  virtual void SetZoomLevel(double level) OVERRIDE;
208  virtual void Zoom(PageZoom zoom) OVERRIDE;
209  virtual void SyncRendererPrefs() OVERRIDE;
210  virtual void ToggleSpeechInput() OVERRIDE;
211  virtual WebPreferences GetWebkitPreferences() OVERRIDE;
212  virtual void UpdateWebkitPreferences(
213      const WebPreferences& prefs) OVERRIDE;
214  virtual void NotifyTimezoneChange() OVERRIDE;
215
216#if defined(OS_ANDROID)
217  virtual void ActivateNearestFindResult(int request_id,
218                                         float x,
219                                         float y) OVERRIDE;
220  virtual void RequestFindMatchRects(int current_version) OVERRIDE;
221  virtual void DisableFullscreenEncryptedMediaPlayback() OVERRIDE;
222#endif
223
224  void set_delegate(RenderViewHostDelegate* d) {
225    CHECK(d);  // http://crbug.com/82827
226    delegate_ = d;
227  }
228
229  // Set up the RenderView child process. Virtual because it is overridden by
230  // TestRenderViewHost. If the |frame_name| parameter is non-empty, it is used
231  // as the name of the new top-level frame.
232  // The |opener_route_id| parameter indicates which RenderView created this
233  // (MSG_ROUTING_NONE if none). If |max_page_id| is larger than -1, the
234  // RenderView is told to start issuing page IDs at |max_page_id| + 1.
235  virtual bool CreateRenderView(const string16& frame_name,
236                                int opener_route_id,
237                                int32 max_page_id);
238
239  base::TerminationStatus render_view_termination_status() const {
240    return render_view_termination_status_;
241  }
242
243  // Sends the given navigation message. Use this rather than sending it
244  // yourself since this does the internal bookkeeping described below. This
245  // function takes ownership of the provided message pointer.
246  //
247  // If a cross-site request is in progress, we may be suspended while waiting
248  // for the onbeforeunload handler, so this function might buffer the message
249  // rather than sending it.
250  void Navigate(const ViewMsg_Navigate_Params& message);
251
252  // Load the specified URL, this is a shortcut for Navigate().
253  void NavigateToURL(const GURL& url);
254
255  // Returns whether navigation messages are currently suspended for this
256  // RenderViewHost.  Only true during a cross-site navigation, while waiting
257  // for the onbeforeunload handler.
258  bool are_navigations_suspended() const { return navigations_suspended_; }
259
260  // Suspends (or unsuspends) any navigation messages from being sent from this
261  // RenderViewHost.  This is called when a pending RenderViewHost is created
262  // for a cross-site navigation, because we must suspend any navigations until
263  // we hear back from the old renderer's onbeforeunload handler.  Note that it
264  // is important that only one navigation event happen after calling this
265  // method with |suspend| equal to true.  If |suspend| is false and there is
266  // a suspended_nav_message_, this will send the message.  This function
267  // should only be called to toggle the state; callers should check
268  // are_navigations_suspended() first. If |suspend| is false, the time that the
269  // user decided the navigation should proceed should be passed as
270  // |proceed_time|.
271  void SetNavigationsSuspended(bool suspend,
272                               const base::TimeTicks& proceed_time);
273
274  // Clears any suspended navigation state after a cross-site navigation is
275  // canceled or suspended.  This is important if we later return to this
276  // RenderViewHost.
277  void CancelSuspendedNavigations();
278
279  // Whether the initial empty page of this view has been accessed by another
280  // page, making it unsafe to show the pending URL.  Always false after the
281  // first commit.
282  bool has_accessed_initial_document() {
283    return has_accessed_initial_document_;
284  }
285
286  // Whether this RenderViewHost has been swapped out to be displayed by a
287  // different process.
288  bool is_swapped_out() const { return is_swapped_out_; }
289
290  // Tells the renderer that this RenderView is being swapped out for one in a
291  // different renderer process.  It should run its unload handler and move to
292  // a blank document.  The renderer should preserve the Frame object until it
293  // exits, in case we come back.  The renderer can exit if it has no other
294  // active RenderViews, but not until WasSwappedOut is called (when it is no
295  // longer visible).
296  void SwapOut();
297
298  // Called when either the SwapOut request has been acknowledged or has timed
299  // out.
300  void OnSwappedOut(bool timed_out);
301
302  // Called to notify the renderer that it has been visibly swapped out and
303  // replaced by another RenderViewHost, after an earlier call to SwapOut.
304  // It is now safe for the process to exit if there are no other active
305  // RenderViews.
306  void WasSwappedOut();
307
308  // Close the page ignoring whether it has unload events registers.
309  // This is called after the beforeunload and unload events have fired
310  // and the user has agreed to continue with closing the page.
311  void ClosePageIgnoringUnloadEvents();
312
313  // Returns whether this RenderViewHost has an outstanding cross-site request.
314  // Cleared when we hear the response and start to swap out the old
315  // RenderViewHost, or if we hear a commit here without a network request.
316  bool HasPendingCrossSiteRequest();
317
318  // Sets whether this RenderViewHost has an outstanding cross-site request,
319  // for which another renderer will need to run an onunload event handler.
320  // This is called before the first navigation event for this RenderViewHost,
321  // and cleared when we hear the response or commit.
322  void SetHasPendingCrossSiteRequest(bool has_pending_request);
323
324  // Notifies the RenderView that the JavaScript message that was shown was
325  // closed by the user.
326  void JavaScriptDialogClosed(IPC::Message* reply_msg,
327                              bool success,
328                              const string16& user_input);
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 WebKit::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, WebKit::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_;
394  }
395
396  void DidSelectPopupMenuItems(const std::vector<int>& selected_indices);
397  void DidCancelPopupMenu();
398#endif
399
400  // User rotated the screen. Calls the "onorientationchange" Javascript hook.
401  void SendOrientationChangeEvent(int orientation);
402
403  // Sets a bit indicating whether the RenderView is responsible for displaying
404  // a subframe in a different process from its parent page.
405  void set_is_subframe(bool is_subframe) {
406    is_subframe_ = is_subframe;
407  }
408
409  int64 main_frame_id() const {
410    return main_frame_id_;
411  }
412
413  // Set the opener to null in the renderer process.
414  void DisownOpener();
415
416  // Turn on accessibility testing. The given callback will be run
417  // every time an accessibility notification is received from the
418  // renderer process, and the accessibility tree it sent can be
419  // retrieved using accessibility_tree_for_testing().
420  void SetAccessibilityCallbackForTesting(
421      const base::Callback<void(WebKit::WebAXEvent)>& callback);
422
423  // Only valid if SetAccessibilityCallbackForTesting was called and
424  // the callback was run at least once. Returns a snapshot of the
425  // accessibility tree received from the renderer as of the last time
426  // a LoadComplete or LayoutComplete accessibility notification was received.
427  const AccessibilityNodeDataTreeNode& accessibility_tree_for_testing() {
428    return accessibility_tree_;
429  }
430
431  // Set accessibility callbacks.
432  void SetAccessibilityLayoutCompleteCallbackForTesting(
433      const base::Closure& callback);
434  void SetAccessibilityLoadCompleteCallbackForTesting(
435      const base::Closure& callback);
436  void SetAccessibilityOtherCallbackForTesting(
437      const base::Closure& callback);
438
439  bool is_waiting_for_beforeunload_ack() {
440    return is_waiting_for_beforeunload_ack_;
441  }
442
443  bool is_waiting_for_unload_ack() {
444    return is_waiting_for_unload_ack_;
445  }
446
447  // Returns whether the given URL is allowed to commit in the current process.
448  // This is a more conservative check than FilterURL, since it will be used to
449  // kill processes that commit unauthorized URLs.
450  bool CanCommitURL(const GURL& url);
451
452  // Checks that the given renderer can request |url|, if not it sets it to
453  // about:blank.
454  // empty_allowed must be set to false for navigations for security reasons.
455  static void FilterURL(ChildProcessSecurityPolicyImpl* policy,
456                        const RenderProcessHost* process,
457                        bool empty_allowed,
458                        GURL* url);
459
460  // Update the FrameTree to use this RenderViewHost's main frame
461  // RenderFrameHost. Called when the RenderViewHost is committed.
462  //
463  // TODO(ajwong): Remove once RenderViewHost no longer owns the main frame
464  // RenderFrameHost.
465  void AttachToFrameTree();
466
467  // The following IPC handlers are public so RenderFrameHost can call them,
468  // while we transition the code to not use RenderViewHost.
469  //
470  // TODO(nasko): Remove those methods once we are done moving navigation
471  // into RenderFrameHost.
472  void OnDidStartProvisionalLoadForFrame(int64 frame_id,
473                                         int64 parent_frame_id,
474                                         bool main_frame,
475                                         const GURL& url);
476
477  // NOTE: Do not add functions that just send an IPC message that are called in
478  // one or two places. Have the caller send the IPC message directly (unless
479  // the caller places are in different platforms, in which case it's better
480  // to keep them consistent).
481
482 protected:
483  friend class RenderViewHostObserver;
484
485  // Add and remove observers for filtering IPC messages.  Clients must be sure
486  // to remove the observer before they go away.
487  void AddObserver(RenderViewHostObserver* observer);
488  void RemoveObserver(RenderViewHostObserver* observer);
489
490  // RenderWidgetHost protected overrides.
491  virtual void OnUserGesture() OVERRIDE;
492  virtual void NotifyRendererUnresponsive() OVERRIDE;
493  virtual void NotifyRendererResponsive() OVERRIDE;
494  virtual void OnRenderAutoResized(const gfx::Size& size) OVERRIDE;
495  virtual void RequestToLockMouse(bool user_gesture,
496                                  bool last_unlocked_by_target) OVERRIDE;
497  virtual bool IsFullscreen() const OVERRIDE;
498  virtual void OnFocus() OVERRIDE;
499  virtual void OnBlur() OVERRIDE;
500
501  // IPC message handlers.
502  void OnShowView(int route_id,
503                  WindowOpenDisposition disposition,
504                  const gfx::Rect& initial_pos,
505                  bool user_gesture);
506  void OnShowWidget(int route_id, const gfx::Rect& initial_pos);
507  void OnShowFullscreenWidget(int route_id);
508  void OnRunModal(int opener_id, IPC::Message* reply_msg);
509  void OnRenderViewReady();
510  void OnRenderProcessGone(int status, int error_code);
511  void OnDidRedirectProvisionalLoad(int32 page_id,
512                                    const GURL& source_url,
513                                    const GURL& target_url);
514  void OnDidFailProvisionalLoadWithError(
515      const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params);
516  void OnNavigate(const IPC::Message& msg);
517  void OnUpdateState(int32 page_id, const PageState& state);
518  void OnUpdateTitle(int32 page_id,
519                     const string16& title,
520                     WebKit::WebTextDirection title_direction);
521  void OnUpdateEncoding(const std::string& encoding);
522  void OnUpdateTargetURL(int32 page_id, const GURL& url);
523  void OnClose();
524  void OnRequestMove(const gfx::Rect& pos);
525  void OnDidStartLoading();
526  void OnDidStopLoading();
527  void OnDidChangeLoadProgress(double load_progress);
528  void OnDidDisownOpener();
529  void OnDocumentAvailableInMainFrame();
530  void OnDocumentOnLoadCompletedInMainFrame(int32 page_id);
531  void OnContextMenu(const ContextMenuParams& params);
532  void OnToggleFullscreen(bool enter_fullscreen);
533  void OnOpenURL(const ViewHostMsg_OpenURL_Params& params);
534  void OnDidContentsPreferredSizeChange(const gfx::Size& new_size);
535  void OnDidChangeScrollOffset();
536  void OnDidChangeScrollbarsForMainFrame(bool has_horizontal_scrollbar,
537                                         bool has_vertical_scrollbar);
538  void OnDidChangeScrollOffsetPinningForMainFrame(bool is_pinned_to_left,
539                                                  bool is_pinned_to_right);
540  void OnDidChangeNumWheelEvents(int count);
541  void OnSelectionChanged(const string16& text,
542                          size_t offset,
543                          const gfx::Range& range);
544  void OnSelectionBoundsChanged(
545      const ViewHostMsg_SelectionBounds_Params& params);
546  void OnPasteFromSelectionClipboard();
547  void OnRouteCloseEvent();
548  void OnRouteMessageEvent(const ViewMsg_PostMessage_Params& params);
549  void OnRunJavaScriptMessage(const string16& message,
550                              const string16& default_prompt,
551                              const GURL& frame_url,
552                              JavaScriptMessageType type,
553                              IPC::Message* reply_msg);
554  void OnRunBeforeUnloadConfirm(const GURL& frame_url,
555                                const string16& message,
556                                bool is_reload,
557                                IPC::Message* reply_msg);
558  void OnStartDragging(const DropData& drop_data,
559                       WebKit::WebDragOperationsMask operations_allowed,
560                       const SkBitmap& bitmap,
561                       const gfx::Vector2d& bitmap_offset_in_dip,
562                       const DragEventSourceInfo& event_info);
563  void OnUpdateDragCursor(WebKit::WebDragOperation drag_operation);
564  void OnTargetDropACK();
565  void OnTakeFocus(bool reverse);
566  void OnFocusedNodeChanged(bool is_editable_node);
567  void OnAddMessageToConsole(int32 level,
568                             const string16& message,
569                             int32 line_no,
570                             const string16& source_id);
571  void OnUpdateInspectorSetting(const std::string& key,
572                                const std::string& value);
573  void OnShouldCloseACK(
574      bool proceed,
575      const base::TimeTicks& renderer_before_unload_start_time,
576      const base::TimeTicks& renderer_before_unload_end_time);
577  void OnClosePageACK();
578  void OnSwapOutACK();
579  void OnAccessibilityEvents(
580      const std::vector<AccessibilityHostMsg_EventParams>& params);
581  void OnScriptEvalResponse(int id, const base::ListValue& result);
582  void OnDidZoomURL(double zoom_level, bool remember, const GURL& url);
583  void OnRequestDesktopNotificationPermission(const GURL& origin,
584                                              int callback_id);
585  void OnShowDesktopNotification(
586      const ShowDesktopNotificationHostMsgParams& params);
587  void OnCancelDesktopNotification(int notification_id);
588  void OnRunFileChooser(const FileChooserParams& params);
589  void OnDidAccessInitialDocument();
590  void OnDomOperationResponse(const std::string& json_string,
591                              int automation_id);
592
593#if defined(OS_MACOSX) || defined(OS_ANDROID)
594  void OnShowPopup(const ViewHostMsg_ShowPopup_Params& params);
595#endif
596
597  // TODO(nasko): Remove this accessor once RenderFrameHost moves into the frame
598  // tree.
599  RenderFrameHostImpl* main_render_frame_host() const {
600    return main_render_frame_host_.get();
601  }
602
603 private:
604  friend class TestRenderViewHost;
605  FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, BasicRenderFrameHost);
606  FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, RoutingIdSane);
607
608  // Sets whether this RenderViewHost is swapped out in favor of another,
609  // and clears any waiting state that is no longer relevant.
610  void SetSwappedOut(bool is_swapped_out);
611
612  bool CanAccessFilesOfPageState(const PageState& state) const;
613
614  // All RenderViewHosts must have a RenderFrameHost for its main frame.
615  // Currently the RenderFrameHost is created in lock step on construction
616  // and a pointer to the main frame is given to the FrameTreeNode
617  // when the RenderViewHost commits (see AttachToFrameTree()).
618  //
619  // TODO(ajwong): Make this reference non-owning. The root FrameTreeNode of
620  // the FrameTree should be responsible for owning the main frame's
621  // RenderFrameHost.
622  scoped_ptr<RenderFrameHostImpl> main_render_frame_host_;
623
624  // Our delegate, which wants to know about changes in the RenderView.
625  RenderViewHostDelegate* delegate_;
626
627  // The SiteInstance associated with this RenderViewHost.  All pages drawn
628  // in this RenderViewHost are part of this SiteInstance.  Should not change
629  // over time.
630  scoped_refptr<SiteInstanceImpl> instance_;
631
632  // true if we are currently waiting for a response for drag context
633  // information.
634  bool waiting_for_drag_context_response_;
635
636  // A bitwise OR of bindings types that have been enabled for this RenderView.
637  // See BindingsPolicy for details.
638  int enabled_bindings_;
639
640  // Whether we should buffer outgoing Navigate messages rather than sending
641  // them.  This will be true when a RenderViewHost is created for a cross-site
642  // request, until we hear back from the onbeforeunload handler of the old
643  // RenderViewHost.
644  bool navigations_suspended_;
645
646  // We only buffer the params for a suspended navigation while we have a
647  // pending RVH for a WebContentsImpl.  There will only ever be one suspended
648  // navigation, because WebContentsImpl will destroy the pending RVH and create
649  // a new one if a second navigation occurs.
650  scoped_ptr<ViewMsg_Navigate_Params> suspended_nav_params_;
651
652  // Whether the initial empty page of this view has been accessed by another
653  // page, making it unsafe to show the pending URL.  Usually false unless
654  // another window tries to modify the blank page.  Always false after the
655  // first commit.
656  bool has_accessed_initial_document_;
657
658  // Whether this RenderViewHost is currently swapped out, such that the view is
659  // being rendered by another process.
660  bool is_swapped_out_;
661
662  // Whether this RenderView is responsible for displaying a subframe in a
663  // different process from its parent page.
664  bool is_subframe_;
665
666  // The frame id of the main (top level) frame. This value is set on the
667  // initial navigation of a RenderView and reset when the RenderView's
668  // process is terminated (in RenderProcessGone).
669  int64 main_frame_id_;
670
671  // If we were asked to RunModal, then this will hold the reply_msg that we
672  // must return to the renderer to unblock it.
673  IPC::Message* run_modal_reply_msg_;
674  // This will hold the routing id of the RenderView that opened us.
675  int run_modal_opener_id_;
676
677  // Set to true when there is a pending ViewMsg_ShouldClose message.  This
678  // ensures we don't spam the renderer with multiple beforeunload requests.
679  // When either this value or is_waiting_for_unload_ack_ is true, the value of
680  // unload_ack_is_for_cross_site_transition_ indicates whether this is for a
681  // cross-site transition or a tab close attempt.
682  bool is_waiting_for_beforeunload_ack_;
683
684  // Set to true when there is a pending ViewMsg_Close message.  Also see
685  // is_waiting_for_beforeunload_ack_, unload_ack_is_for_cross_site_transition_.
686  bool is_waiting_for_unload_ack_;
687
688  // Set to true when waiting for ViewHostMsg_SwapOut_ACK has timed out.
689  bool has_timed_out_on_unload_;
690
691  // Valid only when is_waiting_for_beforeunload_ack_ or
692  // is_waiting_for_unload_ack_ is true.  This tells us if the unload request
693  // is for closing the entire tab ( = false), or only this RenderViewHost in
694  // the case of a cross-site transition ( = true).
695  bool unload_ack_is_for_cross_site_transition_;
696
697  bool are_javascript_messages_suppressed_;
698
699  // The mapping of pending javascript calls created by
700  // ExecuteJavascriptInWebFrameCallbackResult and their corresponding
701  // callbacks.
702  std::map<int, JavascriptResultCallback> javascript_callbacks_;
703
704  // Accessibility callback for testing.
705  base::Callback<void(WebKit::WebAXEvent)> accessibility_testing_callback_;
706
707  // The most recently received accessibility tree - for testing only.
708  AccessibilityNodeDataTreeNode accessibility_tree_;
709
710  // True if the render view can be shut down suddenly.
711  bool sudden_termination_allowed_;
712
713  // The termination status of the last render view that terminated.
714  base::TerminationStatus render_view_termination_status_;
715
716  // A list of observers that filter messages.  Weak references.
717  ObserverList<RenderViewHostObserver> observers_;
718
719  // When the last ShouldClose message was sent.
720  base::TimeTicks send_should_close_start_time_;
721
722#if defined(OS_ANDROID)
723  // Manages all the android mediaplayer objects and handling IPCs for video.
724  // This class inherits from RenderViewHostObserver.
725  BrowserMediaPlayerManager* media_player_manager_;
726#endif
727
728  DISALLOW_COPY_AND_ASSIGN(RenderViewHostImpl);
729};
730
731#if defined(COMPILER_MSVC)
732#pragma warning(pop)
733#endif
734
735}  // namespace content
736
737#endif  // CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_
738