• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/compiler_specific.h"
13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/process/kill.h"
16 #include "content/browser/frame_host/render_frame_host_impl.h"
17 #include "content/browser/renderer_host/render_widget_host_impl.h"
18 #include "content/browser/site_instance_impl.h"
19 #include "content/common/accessibility_node_data.h"
20 #include "content/common/drag_event_source_info.h"
21 #include "content/public/browser/notification_observer.h"
22 #include "content/public/browser/render_view_host.h"
23 #include "content/public/common/javascript_message_type.h"
24 #include "content/public/common/page_transition_types.h"
25 #include "content/public/common/window_container_type.h"
26 #include "net/base/load_states.h"
27 #include "third_party/WebKit/public/web/WebAXEnums.h"
28 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
29 #include "third_party/WebKit/public/web/WebPopupType.h"
30 #include "third_party/WebKit/public/web/WebTextDirection.h"
31 #include "third_party/skia/include/core/SkColor.h"
32 #include "ui/base/window_open_disposition.h"
33 
34 class SkBitmap;
35 class ViewMsg_Navigate;
36 struct AccessibilityHostMsg_EventParams;
37 struct MediaPlayerAction;
38 struct ViewHostMsg_CreateWindow_Params;
39 struct ViewHostMsg_DidFailProvisionalLoadWithError_Params;
40 struct ViewHostMsg_OpenURL_Params;
41 struct ViewHostMsg_SelectionBounds_Params;
42 struct ViewHostMsg_ShowPopup_Params;
43 struct ViewMsg_Navigate_Params;
44 struct ViewMsg_PostMessage_Params;
45 struct ViewMsg_StopFinding_Params;
46 
47 namespace base {
48 class ListValue;
49 }
50 
51 namespace gfx {
52 class Range;
53 }
54 
55 namespace ui {
56 struct SelectedFileInfo;
57 }
58 
59 namespace content {
60 
61 class BrowserMediaPlayerManager;
62 class ChildProcessSecurityPolicyImpl;
63 class PageState;
64 class RenderFrameHostDelegate;
65 class RenderFrameHostImpl;
66 class RenderWidgetHostDelegate;
67 class SessionStorageNamespace;
68 class SessionStorageNamespaceImpl;
69 class TestRenderViewHost;
70 struct ContextMenuParams;
71 struct FileChooserParams;
72 struct Referrer;
73 struct 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.
101 class 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       RenderFrameHostDelegate* frame_delegate,
123       RenderWidgetHostDelegate* widget_delegate,
124       int routing_id,
125       int main_frame_routing_id,
126       bool swapped_out,
127       bool hidden);
128   virtual ~RenderViewHostImpl();
129 
130   // RenderViewHost implementation.
131   virtual void AllowBindings(int binding_flags) OVERRIDE;
132   virtual void ClearFocusedNode() OVERRIDE;
133   virtual void ClosePage() OVERRIDE;
134   virtual void CopyImageAt(int x, int y) OVERRIDE;
135   virtual void DesktopNotificationPermissionRequestDone(
136       int callback_context) OVERRIDE;
137   virtual void DesktopNotificationPostDisplay(int callback_context) OVERRIDE;
138   virtual void DesktopNotificationPostError(
139       int notification_id,
140       const base::string16& message) OVERRIDE;
141   virtual void DesktopNotificationPostClose(int notification_id,
142                                             bool by_user) OVERRIDE;
143   virtual void DesktopNotificationPostClick(int notification_id) OVERRIDE;
144   virtual void DirectoryEnumerationFinished(
145       int request_id,
146       const std::vector<base::FilePath>& files) OVERRIDE;
147   virtual void DisableScrollbarsForThreshold(const gfx::Size& size) OVERRIDE;
148   virtual void DragSourceEndedAt(
149       int client_x, int client_y, int screen_x, int screen_y,
150       blink::WebDragOperation operation) OVERRIDE;
151   virtual void DragSourceMovedTo(
152       int client_x, int client_y, int screen_x, int screen_y) OVERRIDE;
153   virtual void DragSourceSystemDragEnded() OVERRIDE;
154   virtual void DragTargetDragEnter(
155       const DropData& drop_data,
156       const gfx::Point& client_pt,
157       const gfx::Point& screen_pt,
158       blink::WebDragOperationsMask operations_allowed,
159       int key_modifiers) OVERRIDE;
160   virtual void DragTargetDragOver(
161       const gfx::Point& client_pt,
162       const gfx::Point& screen_pt,
163       blink::WebDragOperationsMask operations_allowed,
164       int key_modifiers) OVERRIDE;
165   virtual void DragTargetDragLeave() OVERRIDE;
166   virtual void DragTargetDrop(const gfx::Point& client_pt,
167                               const gfx::Point& screen_pt,
168                               int key_modifiers) OVERRIDE;
169   virtual void EnableAutoResize(const gfx::Size& min_size,
170                                 const gfx::Size& max_size) OVERRIDE;
171   virtual void DisableAutoResize(const gfx::Size& new_size) OVERRIDE;
172   virtual void EnablePreferredSizeMode() OVERRIDE;
173   virtual void ExecuteCustomContextMenuCommand(
174       int action, const CustomContextMenuContext& context) OVERRIDE;
175   virtual void ExecuteMediaPlayerActionAtLocation(
176       const gfx::Point& location,
177       const blink::WebMediaPlayerAction& action) OVERRIDE;
178   virtual void ExecuteJavascriptInWebFrame(
179       const base::string16& frame_xpath,
180       const base::string16& jscript) OVERRIDE;
181   virtual void ExecuteJavascriptInWebFrameCallbackResult(
182       const base::string16& frame_xpath,
183       const base::string16& jscript,
184       const JavascriptResultCallback& callback) OVERRIDE;
185   virtual void ExecutePluginActionAtLocation(
186       const gfx::Point& location,
187       const blink::WebPluginAction& action) OVERRIDE;
188   virtual void ExitFullscreen() OVERRIDE;
189   virtual void Find(int request_id, const base::string16& search_text,
190                     const blink::WebFindOptions& options) OVERRIDE;
191   virtual void StopFinding(StopFindAction action) OVERRIDE;
192   virtual void FirePageBeforeUnload(bool for_cross_site_transition) OVERRIDE;
193   virtual void FilesSelectedInChooser(
194       const std::vector<ui::SelectedFileInfo>& files,
195       FileChooserParams::Mode permissions) OVERRIDE;
196   virtual RenderViewHostDelegate* GetDelegate() const OVERRIDE;
197   virtual int GetEnabledBindings() const OVERRIDE;
198   virtual SiteInstance* GetSiteInstance() const OVERRIDE;
199   virtual void InsertCSS(const base::string16& frame_xpath,
200                          const std::string& css) OVERRIDE;
201   virtual bool IsRenderViewLive() const OVERRIDE;
202   virtual bool IsSubframe() const OVERRIDE;
203   virtual void NotifyContextMenuClosed(
204       const CustomContextMenuContext& context) OVERRIDE;
205   virtual void NotifyMoveOrResizeStarted() OVERRIDE;
206   virtual void ReloadFrame() OVERRIDE;
207   virtual void SetAltErrorPageURL(const GURL& url) OVERRIDE;
208   virtual void SetWebUIProperty(const std::string& name,
209                                 const std::string& value) OVERRIDE;
210   virtual void Zoom(PageZoom zoom) OVERRIDE;
211   virtual void SyncRendererPrefs() OVERRIDE;
212   virtual void ToggleSpeechInput() OVERRIDE;
213   virtual WebPreferences GetWebkitPreferences() OVERRIDE;
214   virtual void UpdateWebkitPreferences(
215       const WebPreferences& prefs) OVERRIDE;
216   virtual void NotifyTimezoneChange() OVERRIDE;
217   virtual void GetAudioOutputControllers(
218       const GetAudioOutputControllersCallback& callback) const OVERRIDE;
219 
220 #if defined(OS_ANDROID)
221   virtual void ActivateNearestFindResult(int request_id,
222                                          float x,
223                                          float y) OVERRIDE;
224   virtual void RequestFindMatchRects(int current_version) OVERRIDE;
225   virtual void DisableFullscreenEncryptedMediaPlayback() OVERRIDE;
226 #endif
227 
set_delegate(RenderViewHostDelegate * d)228   void set_delegate(RenderViewHostDelegate* d) {
229     CHECK(d);  // http://crbug.com/82827
230     delegate_ = d;
231   }
232 
233   // Set up the RenderView child process. Virtual because it is overridden by
234   // TestRenderViewHost. If the |frame_name| parameter is non-empty, it is used
235   // as the name of the new top-level frame.
236   // The |opener_route_id| parameter indicates which RenderView created this
237   // (MSG_ROUTING_NONE if none). If |max_page_id| is larger than -1, the
238   // RenderView is told to start issuing page IDs at |max_page_id| + 1.
239   virtual bool CreateRenderView(const base::string16& frame_name,
240                                 int opener_route_id,
241                                 int32 max_page_id);
242 
render_view_termination_status()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   void Navigate(const ViewMsg_Navigate_Params& message);
258 
259   // Load the specified URL, this is a shortcut for Navigate().
260   void NavigateToURL(const GURL& url);
261 
262   // Returns whether navigation messages are currently suspended for this
263   // RenderViewHost.  Only true during a cross-site navigation, while waiting
264   // for the onbeforeunload handler.
are_navigations_suspended()265   bool are_navigations_suspended() const { return navigations_suspended_; }
266 
267   // Suspends (or unsuspends) any navigation messages from being sent from this
268   // RenderViewHost.  This is called when a pending RenderViewHost is created
269   // for a cross-site navigation, because we must suspend any navigations until
270   // we hear back from the old renderer's onbeforeunload handler.  Note that it
271   // is important that only one navigation event happen after calling this
272   // method with |suspend| equal to true.  If |suspend| is false and there is
273   // a suspended_nav_message_, this will send the message.  This function
274   // should only be called to toggle the state; callers should check
275   // are_navigations_suspended() first. If |suspend| is false, the time that the
276   // user decided the navigation should proceed should be passed as
277   // |proceed_time|.
278   void SetNavigationsSuspended(bool suspend,
279                                const base::TimeTicks& proceed_time);
280 
281   // Clears any suspended navigation state after a cross-site navigation is
282   // canceled or suspended.  This is important if we later return to this
283   // RenderViewHost.
284   void CancelSuspendedNavigations();
285 
286   // Whether the initial empty page of this view has been accessed by another
287   // page, making it unsafe to show the pending URL.  Always false after the
288   // first commit.
has_accessed_initial_document()289   bool has_accessed_initial_document() {
290     return has_accessed_initial_document_;
291   }
292 
293   // Whether this RenderViewHost has been swapped out to be displayed by a
294   // different process.
is_swapped_out()295   bool is_swapped_out() const { return is_swapped_out_; }
296 
297   // Called on the pending RenderViewHost when the network response is ready to
298   // commit.  We should ensure that the old RenderViewHost runs its unload
299   // handler and determine whether a transfer to a different RenderViewHost is
300   // needed.
301   void OnCrossSiteResponse(
302       const GlobalRequestID& global_request_id,
303       bool is_transfer,
304       const std::vector<GURL>& transfer_url_chain,
305       const Referrer& referrer,
306       PageTransition page_transition,
307       int64 frame_id,
308       bool should_replace_current_entry);
309 
310   // Tells the renderer that this RenderView will soon be swapped out, and thus
311   // not to create any new modal dialogs until it happens.  This must be done
312   // separately so that the PageGroupLoadDeferrers of any current dialogs are no
313   // longer on the stack when we attempt to swap it out.
314   void SuppressDialogsUntilSwapOut();
315 
316   // Tells the renderer that this RenderView is being swapped out for one in a
317   // different renderer process.  It should run its unload handler and move to
318   // a blank document.  The renderer should preserve the Frame object until it
319   // exits, in case we come back.  The renderer can exit if it has no other
320   // active RenderViews, but not until WasSwappedOut is called (when it is no
321   // longer visible).
322   void SwapOut();
323 
324   // Called when either the SwapOut request has been acknowledged or has timed
325   // out.
326   void OnSwappedOut(bool timed_out);
327 
328   // Called to notify the renderer that it has been visibly swapped out and
329   // replaced by another RenderViewHost, after an earlier call to SwapOut.
330   // It is now safe for the process to exit if there are no other active
331   // RenderViews.
332   void WasSwappedOut();
333 
334   // Close the page ignoring whether it has unload events registers.
335   // This is called after the beforeunload and unload events have fired
336   // and the user has agreed to continue with closing the page.
337   void ClosePageIgnoringUnloadEvents();
338 
339   // Returns whether this RenderViewHost has an outstanding cross-site request.
340   // Cleared when we hear the response and start to swap out the old
341   // RenderViewHost, or if we hear a commit here without a network request.
342   bool HasPendingCrossSiteRequest();
343 
344   // Sets whether this RenderViewHost has an outstanding cross-site request,
345   // for which another renderer will need to run an onunload event handler.
346   // This is called before the first navigation event for this RenderViewHost,
347   // and cleared when we hear the response or commit.
348   void SetHasPendingCrossSiteRequest(bool has_pending_request);
349 
350   // Notifies the RenderView that the JavaScript message that was shown was
351   // closed by the user.
352   void JavaScriptDialogClosed(IPC::Message* reply_msg,
353                               bool success,
354                               const base::string16& user_input);
355 
356   // Tells the renderer view to focus the first (last if reverse is true) node.
357   void SetInitialFocus(bool reverse);
358 
359   // Get html data by serializing all frames of current page with lists
360   // which contain all resource links that have local copy.
361   // The parameter links contain original URLs of all saved links.
362   // The parameter local_paths contain corresponding local file paths of
363   // all saved links, which matched with vector:links one by one.
364   // The parameter local_directory_name is relative path of directory which
365   // contain all saved auxiliary files included all sub frames and resouces.
366   void GetSerializedHtmlDataForCurrentPageWithLocalLinks(
367       const std::vector<GURL>& links,
368       const std::vector<base::FilePath>& local_paths,
369       const base::FilePath& local_directory_name);
370 
371   // Notifies the RenderViewHost that its load state changed.
372   void LoadStateChanged(const GURL& url,
373                         const net::LoadStateWithParam& load_state,
374                         uint64 upload_position,
375                         uint64 upload_size);
376 
377   bool SuddenTerminationAllowed() const;
set_sudden_termination_allowed(bool enabled)378   void set_sudden_termination_allowed(bool enabled) {
379     sudden_termination_allowed_ = enabled;
380   }
381 
382   // RenderWidgetHost public overrides.
383   virtual void Init() OVERRIDE;
384   virtual void Shutdown() OVERRIDE;
385   virtual bool IsRenderView() const OVERRIDE;
386   virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
387   virtual void GotFocus() OVERRIDE;
388   virtual void LostCapture() OVERRIDE;
389   virtual void LostMouseLock() OVERRIDE;
390   virtual void ForwardMouseEvent(
391       const blink::WebMouseEvent& mouse_event) OVERRIDE;
392   virtual void OnPointerEventActivate() OVERRIDE;
393   virtual void ForwardKeyboardEvent(
394       const NativeWebKeyboardEvent& key_event) OVERRIDE;
395   virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
396 
397   // Creates a new RenderView with the given route id.
398   void CreateNewWindow(
399       int route_id,
400       int main_frame_route_id,
401       const ViewHostMsg_CreateWindow_Params& params,
402       SessionStorageNamespace* session_storage_namespace);
403 
404   // Creates a new RenderWidget with the given route id.  |popup_type| indicates
405   // if this widget is a popup and what kind of popup it is (select, autofill).
406   void CreateNewWidget(int route_id, blink::WebPopupType popup_type);
407 
408   // Creates a full screen RenderWidget.
409   void CreateNewFullscreenWidget(int route_id);
410 
411 #if defined(OS_MACOSX)
412   // Select popup menu related methods (for external popup menus).
413   void DidSelectPopupMenuItem(int selected_index);
414   void DidCancelPopupMenu();
415 #endif
416 
417 #if defined(OS_ANDROID)
media_player_manager()418   BrowserMediaPlayerManager* media_player_manager() {
419     return media_player_manager_.get();
420   }
421 
422   void DidSelectPopupMenuItems(const std::vector<int>& selected_indices);
423   void DidCancelPopupMenu();
424 #endif
425 
426   // User rotated the screen. Calls the "onorientationchange" Javascript hook.
427   void SendOrientationChangeEvent(int orientation);
428 
429   // Sets a bit indicating whether the RenderView is responsible for displaying
430   // a subframe in a different process from its parent page.
set_is_subframe(bool is_subframe)431   void set_is_subframe(bool is_subframe) {
432     is_subframe_ = is_subframe;
433   }
434 
435   // TODO(creis): Remove this when we replace frame IDs with RenderFrameHost
436   // routing IDs.
main_frame_id()437   int64 main_frame_id() const {
438     return main_frame_id_;
439   }
440 
441   // Set the opener to null in the renderer process.
442   void DisownOpener();
443 
444   // Turn on accessibility testing. The given callback will be run
445   // every time an accessibility notification is received from the
446   // renderer process, and the accessibility tree it sent can be
447   // retrieved using accessibility_tree_for_testing().
448   void SetAccessibilityCallbackForTesting(
449       const base::Callback<void(blink::WebAXEvent)>& callback);
450 
451   // Only valid if SetAccessibilityCallbackForTesting was called and
452   // the callback was run at least once. Returns a snapshot of the
453   // accessibility tree received from the renderer as of the last time
454   // a LoadComplete or LayoutComplete accessibility notification was received.
accessibility_tree_for_testing()455   const AccessibilityNodeDataTreeNode& accessibility_tree_for_testing() {
456     return accessibility_tree_;
457   }
458 
459   // Set accessibility callbacks.
460   void SetAccessibilityLayoutCompleteCallbackForTesting(
461       const base::Closure& callback);
462   void SetAccessibilityLoadCompleteCallbackForTesting(
463       const base::Closure& callback);
464   void SetAccessibilityOtherCallbackForTesting(
465       const base::Closure& callback);
466 
is_waiting_for_beforeunload_ack()467   bool is_waiting_for_beforeunload_ack() {
468     return is_waiting_for_beforeunload_ack_;
469   }
470 
is_waiting_for_unload_ack()471   bool is_waiting_for_unload_ack() {
472     return is_waiting_for_unload_ack_;
473   }
474 
475   // Returns whether the given URL is allowed to commit in the current process.
476   // This is a more conservative check than FilterURL, since it will be used to
477   // kill processes that commit unauthorized URLs.
478   bool CanCommitURL(const GURL& url);
479 
480   // Checks that the given renderer can request |url|, if not it sets it to
481   // about:blank.
482   // empty_allowed must be set to false for navigations for security reasons.
483   static void FilterURL(ChildProcessSecurityPolicyImpl* policy,
484                         const RenderProcessHost* process,
485                         bool empty_allowed,
486                         GURL* url);
487 
488   // Update the FrameTree to use this RenderViewHost's main frame
489   // RenderFrameHost. Called when the RenderViewHost is committed.
490   //
491   // TODO(ajwong): Remove once RenderViewHost no longer owns the main frame
492   // RenderFrameHost.
493   void AttachToFrameTree();
494 
495   // The following IPC handlers are public so RenderFrameHost can call them,
496   // while we transition the code to not use RenderViewHost.
497   //
498   // TODO(nasko): Remove those methods once we are done moving navigation
499   // into RenderFrameHost.
500   void OnDidStartProvisionalLoadForFrame(int64 frame_id,
501                                          int64 parent_frame_id,
502                                          bool main_frame,
503                                          const GURL& url);
504 
505   // NOTE: Do not add functions that just send an IPC message that are called in
506   // one or two places. Have the caller send the IPC message directly (unless
507   // the caller places are in different platforms, in which case it's better
508   // to keep them consistent).
509 
510  protected:
511   // RenderWidgetHost protected overrides.
512   virtual void OnUserGesture() OVERRIDE;
513   virtual void NotifyRendererUnresponsive() OVERRIDE;
514   virtual void NotifyRendererResponsive() OVERRIDE;
515   virtual void OnRenderAutoResized(const gfx::Size& size) OVERRIDE;
516   virtual void RequestToLockMouse(bool user_gesture,
517                                   bool last_unlocked_by_target) OVERRIDE;
518   virtual bool IsFullscreen() const OVERRIDE;
519   virtual void OnFocus() OVERRIDE;
520   virtual void OnBlur() OVERRIDE;
521 
522   // IPC message handlers.
523   void OnShowView(int route_id,
524                   WindowOpenDisposition disposition,
525                   const gfx::Rect& initial_pos,
526                   bool user_gesture);
527   void OnShowWidget(int route_id, const gfx::Rect& initial_pos);
528   void OnShowFullscreenWidget(int route_id);
529   void OnRunModal(int opener_id, IPC::Message* reply_msg);
530   void OnRenderViewReady();
531   void OnRenderProcessGone(int status, int error_code);
532   void OnDidRedirectProvisionalLoad(int32 page_id,
533                                     const GURL& source_url,
534                                     const GURL& target_url);
535   void OnDidFailProvisionalLoadWithError(
536       const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params);
537   void OnNavigate(const IPC::Message& msg);
538   void OnUpdateState(int32 page_id, const PageState& state);
539   void OnUpdateTitle(int32 page_id,
540                      const base::string16& title,
541                      blink::WebTextDirection title_direction);
542   void OnUpdateEncoding(const std::string& encoding);
543   void OnUpdateTargetURL(int32 page_id, const GURL& url);
544   void OnClose();
545   void OnRequestMove(const gfx::Rect& pos);
546   void OnDidStartLoading();
547   void OnDidStopLoading();
548   void OnDidChangeLoadProgress(double load_progress);
549   void OnDidDisownOpener();
550   void OnDocumentAvailableInMainFrame();
551   void OnDocumentOnLoadCompletedInMainFrame(int32 page_id);
552   void OnContextMenu(const ContextMenuParams& params);
553   void OnToggleFullscreen(bool enter_fullscreen);
554   void OnOpenURL(const ViewHostMsg_OpenURL_Params& params);
555   void OnDidContentsPreferredSizeChange(const gfx::Size& new_size);
556   void OnDidChangeScrollOffset();
557   void OnDidChangeScrollbarsForMainFrame(bool has_horizontal_scrollbar,
558                                          bool has_vertical_scrollbar);
559   void OnDidChangeScrollOffsetPinningForMainFrame(bool is_pinned_to_left,
560                                                   bool is_pinned_to_right);
561   void OnDidChangeNumWheelEvents(int count);
562   void OnSelectionChanged(const base::string16& text,
563                           size_t offset,
564                           const gfx::Range& range);
565   void OnSelectionBoundsChanged(
566       const ViewHostMsg_SelectionBounds_Params& params);
567   void OnPasteFromSelectionClipboard();
568   void OnRouteCloseEvent();
569   void OnRouteMessageEvent(const ViewMsg_PostMessage_Params& params);
570   void OnRunJavaScriptMessage(const base::string16& message,
571                               const base::string16& default_prompt,
572                               const GURL& frame_url,
573                               JavaScriptMessageType type,
574                               IPC::Message* reply_msg);
575   void OnRunBeforeUnloadConfirm(const GURL& frame_url,
576                                 const base::string16& message,
577                                 bool is_reload,
578                                 IPC::Message* reply_msg);
579   void OnStartDragging(const DropData& drop_data,
580                        blink::WebDragOperationsMask operations_allowed,
581                        const SkBitmap& bitmap,
582                        const gfx::Vector2d& bitmap_offset_in_dip,
583                        const DragEventSourceInfo& event_info);
584   void OnUpdateDragCursor(blink::WebDragOperation drag_operation);
585   void OnTargetDropACK();
586   void OnTakeFocus(bool reverse);
587   void OnFocusedNodeChanged(bool is_editable_node);
588   void OnAddMessageToConsole(int32 level,
589                              const base::string16& message,
590                              int32 line_no,
591                              const base::string16& source_id);
592   void OnUpdateInspectorSetting(const std::string& key,
593                                 const std::string& value);
594   void OnShouldCloseACK(
595       bool proceed,
596       const base::TimeTicks& renderer_before_unload_start_time,
597       const base::TimeTicks& renderer_before_unload_end_time);
598   void OnClosePageACK();
599   void OnSwapOutACK();
600   void OnAccessibilityEvents(
601       const std::vector<AccessibilityHostMsg_EventParams>& params);
602   void OnScriptEvalResponse(int id, const base::ListValue& result);
603   void OnDidZoomURL(double zoom_level, bool remember, const GURL& url);
604   void OnRequestDesktopNotificationPermission(const GURL& origin,
605                                               int callback_id);
606   void OnShowDesktopNotification(
607       const ShowDesktopNotificationHostMsgParams& params);
608   void OnCancelDesktopNotification(int notification_id);
609   void OnRunFileChooser(const FileChooserParams& params);
610   void OnDidAccessInitialDocument();
611   void OnDomOperationResponse(const std::string& json_string,
612                               int automation_id);
613   void OnFocusedNodeTouched(bool editable);
614 
615 #if defined(OS_MACOSX) || defined(OS_ANDROID)
616   void OnShowPopup(const ViewHostMsg_ShowPopup_Params& params);
617 #endif
618 
619   // TODO(nasko): Remove this accessor once RenderFrameHost moves into the frame
620   // tree.
main_render_frame_host()621   RenderFrameHostImpl* main_render_frame_host() const {
622     return main_render_frame_host_.get();
623   }
624 
625  private:
626   friend class TestRenderViewHost;
627   FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, BasicRenderFrameHost);
628   FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, RoutingIdSane);
629 
630   // Sets whether this RenderViewHost is swapped out in favor of another,
631   // and clears any waiting state that is no longer relevant.
632   void SetSwappedOut(bool is_swapped_out);
633 
634   bool CanAccessFilesOfPageState(const PageState& state) const;
635 
636   // All RenderViewHosts must have a RenderFrameHost for its main frame.
637   // Currently the RenderFrameHost is created in lock step on construction
638   // and a pointer to the main frame is given to the FrameTreeNode
639   // when the RenderViewHost commits (see AttachToFrameTree()).
640   //
641   // TODO(ajwong): Make this reference non-owning. The root FrameTreeNode of
642   // the FrameTree should be responsible for owning the main frame's
643   // RenderFrameHost.
644   scoped_ptr<RenderFrameHostImpl> main_render_frame_host_;
645 
646   // Our delegate, which wants to know about changes in the RenderView.
647   RenderViewHostDelegate* delegate_;
648 
649   // The SiteInstance associated with this RenderViewHost.  All pages drawn
650   // in this RenderViewHost are part of this SiteInstance.  Should not change
651   // over time.
652   scoped_refptr<SiteInstanceImpl> instance_;
653 
654   // true if we are currently waiting for a response for drag context
655   // information.
656   bool waiting_for_drag_context_response_;
657 
658   // A bitwise OR of bindings types that have been enabled for this RenderView.
659   // See BindingsPolicy for details.
660   int enabled_bindings_;
661 
662   // Whether we should buffer outgoing Navigate messages rather than sending
663   // them.  This will be true when a RenderViewHost is created for a cross-site
664   // request, until we hear back from the onbeforeunload handler of the old
665   // RenderViewHost.
666   bool navigations_suspended_;
667 
668   // We only buffer the params for a suspended navigation while we have a
669   // pending RVH for a WebContentsImpl.  There will only ever be one suspended
670   // navigation, because WebContentsImpl will destroy the pending RVH and create
671   // a new one if a second navigation occurs.
672   scoped_ptr<ViewMsg_Navigate_Params> suspended_nav_params_;
673 
674   // Whether the initial empty page of this view has been accessed by another
675   // page, making it unsafe to show the pending URL.  Usually false unless
676   // another window tries to modify the blank page.  Always false after the
677   // first commit.
678   bool has_accessed_initial_document_;
679 
680   // Whether this RenderViewHost is currently swapped out, such that the view is
681   // being rendered by another process.
682   bool is_swapped_out_;
683 
684   // Whether this RenderView is responsible for displaying a subframe in a
685   // different process from its parent page.
686   bool is_subframe_;
687 
688   // The frame id of the main (top level) frame. This value is set on the
689   // initial navigation of a RenderView and reset when the RenderView's
690   // process is terminated (in RenderProcessGone).
691   int64 main_frame_id_;
692 
693   // If we were asked to RunModal, then this will hold the reply_msg that we
694   // must return to the renderer to unblock it.
695   IPC::Message* run_modal_reply_msg_;
696   // This will hold the routing id of the RenderView that opened us.
697   int run_modal_opener_id_;
698 
699   // Set to true when there is a pending ViewMsg_ShouldClose message.  This
700   // ensures we don't spam the renderer with multiple beforeunload requests.
701   // When either this value or is_waiting_for_unload_ack_ is true, the value of
702   // unload_ack_is_for_cross_site_transition_ indicates whether this is for a
703   // cross-site transition or a tab close attempt.
704   bool is_waiting_for_beforeunload_ack_;
705 
706   // Set to true when there is a pending ViewMsg_Close message.  Also see
707   // is_waiting_for_beforeunload_ack_, unload_ack_is_for_cross_site_transition_.
708   bool is_waiting_for_unload_ack_;
709 
710   // Set to true when waiting for ViewHostMsg_SwapOut_ACK has timed out.
711   bool has_timed_out_on_unload_;
712 
713   // Valid only when is_waiting_for_beforeunload_ack_ or
714   // is_waiting_for_unload_ack_ is true.  This tells us if the unload request
715   // is for closing the entire tab ( = false), or only this RenderViewHost in
716   // the case of a cross-site transition ( = true).
717   bool unload_ack_is_for_cross_site_transition_;
718 
719   bool are_javascript_messages_suppressed_;
720 
721   // The mapping of pending javascript calls created by
722   // ExecuteJavascriptInWebFrameCallbackResult and their corresponding
723   // callbacks.
724   std::map<int, JavascriptResultCallback> javascript_callbacks_;
725 
726   // Accessibility callback for testing.
727   base::Callback<void(blink::WebAXEvent)> accessibility_testing_callback_;
728 
729   // The most recently received accessibility tree - for testing only.
730   AccessibilityNodeDataTreeNode accessibility_tree_;
731 
732   // True if the render view can be shut down suddenly.
733   bool sudden_termination_allowed_;
734 
735   // The termination status of the last render view that terminated.
736   base::TerminationStatus render_view_termination_status_;
737 
738   // When the last ShouldClose message was sent.
739   base::TimeTicks send_should_close_start_time_;
740 
741   // Set to true if we requested the on screen keyboard to be displayed.
742   bool virtual_keyboard_requested_;
743 
744 #if defined(OS_ANDROID)
745   // Manages all the android mediaplayer objects and handling IPCs for video.
746   scoped_ptr<BrowserMediaPlayerManager> media_player_manager_;
747 #endif
748 
749   DISALLOW_COPY_AND_ASSIGN(RenderViewHostImpl);
750 };
751 
752 #if defined(COMPILER_MSVC)
753 #pragma warning(pop)
754 #endif
755 
756 }  // namespace content
757 
758 #endif  // CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_
759