Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / render_view_host_impl.h
index 52f36ea..a3f4009 100644 (file)
@@ -9,6 +9,7 @@
 #include <string>
 #include <vector>
 
+#include "base/callback.h"
 #include "base/compiler_specific.h"
 #include "base/logging.h"
 #include "base/memory/scoped_ptr.h"
@@ -31,7 +32,7 @@
 #include "ui/base/window_open_disposition.h"
 
 class SkBitmap;
-class ViewMsg_Navigate;
+class FrameMsg_Navigate;
 struct AccessibilityHostMsg_EventParams;
 struct AccessibilityHostMsg_LocationChangeParams;
 struct MediaPlayerAction;
@@ -39,7 +40,7 @@ struct ViewHostMsg_CreateWindow_Params;
 struct ViewHostMsg_OpenURL_Params;
 struct ViewHostMsg_SelectionBounds_Params;
 struct ViewHostMsg_ShowPopup_Params;
-struct ViewMsg_Navigate_Params;
+struct FrameMsg_Navigate_Params;
 struct ViewMsg_PostMessage_Params;
 
 namespace base {
@@ -59,12 +60,13 @@ namespace content {
 
 class BrowserMediaPlayerManager;
 class ChildProcessSecurityPolicyImpl;
+class CrossSiteTransferringRequest;
 class PageState;
 class RenderWidgetHostDelegate;
 class SessionStorageNamespace;
 class SessionStorageNamespaceImpl;
 class TestRenderViewHost;
-struct ContextMenuParams;
+class TimeoutMonitor;
 struct FileChooserParams;
 struct Referrer;
 struct ShowDesktopNotificationHostMsgParams;
@@ -99,6 +101,39 @@ class CONTENT_EXPORT RenderViewHostImpl
     : public RenderViewHost,
       public RenderWidgetHostImpl {
  public:
+  // Keeps track of the state of the RenderViewHostImpl, particularly with
+  // respect to swap out.
+  enum RenderViewHostImplState {
+    // The standard state for a RVH handling the communication with a
+    // RenderView.
+    STATE_DEFAULT = 0,
+    // The RVH has sent the SwapOut request to the renderer, but has not
+    // received the SwapOutACK yet. The new page has not been committed yet
+    // either.
+    STATE_WAITING_FOR_UNLOAD_ACK,
+    // The RVH received the SwapOutACK from the RenderView, but the new page has
+    // not been committed yet.
+    STATE_WAITING_FOR_COMMIT,
+    // The RVH is waiting for the CloseACK from the RenderView.
+    STATE_WAITING_FOR_CLOSE,
+    // The RVH has not received the SwapOutACK yet, but the new page has
+    // committed in a different RVH. The number of active views of the RVH
+    // SiteInstanceImpl is not zero. Upon reception of the SwapOutACK, the RVH
+    // will be swapped out.
+    STATE_PENDING_SWAP_OUT,
+    // The RVH has not received the SwapOutACK yet, but the new page has
+    // committed in a different RVH. The number of active views of the RVH
+    // SiteInstanceImpl is zero. Upon reception of the SwapOutACK, the RVH will
+    // be shutdown.
+    STATE_PENDING_SHUTDOWN,
+    // The RVH is swapped out, and it is being used as a placeholder to allow
+    // for cross-process communication.
+    STATE_SWAPPED_OUT,
+  };
+  // Helper function to determine whether the RVH state should contribute to the
+  // number of active views of a SiteInstance or not.
+  static bool IsRVHStateActive(RenderViewHostImplState rvh_state);
+
   // Convenience function, just like RenderViewHost::FromID.
   static RenderViewHostImpl* FromID(int render_process_id, int render_view_id);
 
@@ -167,8 +202,6 @@ class CONTENT_EXPORT RenderViewHostImpl
                                 const gfx::Size& max_size) OVERRIDE;
   virtual void DisableAutoResize(const gfx::Size& new_size) OVERRIDE;
   virtual void EnablePreferredSizeMode() OVERRIDE;
-  virtual void ExecuteCustomContextMenuCommand(
-      int action, const CustomContextMenuContext& context) OVERRIDE;
   virtual void ExecuteMediaPlayerActionAtLocation(
       const gfx::Point& location,
       const blink::WebMediaPlayerAction& action) OVERRIDE;
@@ -193,8 +226,6 @@ class CONTENT_EXPORT RenderViewHostImpl
   virtual void InsertCSS(const base::string16& frame_xpath,
                          const std::string& css) OVERRIDE;
   virtual bool IsRenderViewLive() const OVERRIDE;
-  virtual void NotifyContextMenuClosed(
-      const CustomContextMenuContext& context) OVERRIDE;
   virtual void NotifyMoveOrResizeStarted() OVERRIDE;
   virtual void ReloadFrame() OVERRIDE;
   virtual void SetWebUIProperty(const std::string& name,
@@ -246,9 +277,13 @@ class CONTENT_EXPORT RenderViewHostImpl
   // If a cross-site request is in progress, we may be suspended while waiting
   // for the onbeforeunload handler, so this function might buffer the message
   // rather than sending it.
-  void Navigate(const ViewMsg_Navigate_Params& message);
+  // TODO(nasko): Remove this method once all callers are converted to use
+  // RenderFrameHostImpl.
+  void Navigate(const FrameMsg_Navigate_Params& message);
 
   // Load the specified URL, this is a shortcut for Navigate().
+  // TODO(nasko): Remove this method once all callers are converted to use
+  // RenderFrameHostImpl.
   void NavigateToURL(const GURL& url);
 
   // Returns whether navigation messages are currently suspended for this
@@ -284,7 +319,10 @@ class CONTENT_EXPORT RenderViewHostImpl
 
   // Whether this RenderViewHost has been swapped out to be displayed by a
   // different process.
-  bool is_swapped_out() const { return is_swapped_out_; }
+  bool IsSwappedOut() const { return rvh_state_ == STATE_SWAPPED_OUT; }
+
+  // The current state of this RVH.
+  RenderViewHostImplState rvh_state() const { return rvh_state_; }
 
   // Called on the pending RenderViewHost when the network response is ready to
   // commit.  We should ensure that the old RenderViewHost runs its unload
@@ -292,7 +330,7 @@ class CONTENT_EXPORT RenderViewHostImpl
   // needed.
   void OnCrossSiteResponse(
       const GlobalRequestID& global_request_id,
-      bool is_transfer,
+      scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request,
       const std::vector<GURL>& transfer_url_chain,
       const Referrer& referrer,
       PageTransition page_transition,
@@ -317,11 +355,15 @@ class CONTENT_EXPORT RenderViewHostImpl
   // out.
   void OnSwappedOut(bool timed_out);
 
-  // Called to notify the renderer that it has been visibly swapped out and
-  // replaced by another RenderViewHost, after an earlier call to SwapOut.
-  // It is now safe for the process to exit if there are no other active
-  // RenderViews.
-  void WasSwappedOut();
+  // Called when the RenderFrameHostManager has swapped in a new
+  // RenderFrameHost. Should |this| RVH switch to the pending shutdown state,
+  // |pending_delete_on_swap_out| will be executed upon reception of the
+  // SwapOutACK, or when the unload timer times out.
+  void WasSwappedOut(const base::Closure& pending_delete_on_swap_out);
+
+  // Set |this| as pending shutdown. |on_swap_out| will be called
+  // when the SwapOutACK is received, or when the unload timer times out.
+  void SetPendingShutdown(const base::Closure& on_swap_out);
 
   // Close the page ignoring whether it has unload events registers.
   // This is called after the beforeunload and unload events have fired
@@ -423,6 +465,9 @@ class CONTENT_EXPORT RenderViewHostImpl
   int64 main_frame_id() const {
     return main_frame_id_;
   }
+  int main_frame_routing_id() const {
+    return main_frame_routing_id_;
+  }
 
   // Set the opener to null in the renderer process.
   void DisownOpener();
@@ -455,14 +500,8 @@ class CONTENT_EXPORT RenderViewHostImpl
     return is_waiting_for_beforeunload_ack_;
   }
 
-  bool is_waiting_for_unload_ack() {
-    return is_waiting_for_unload_ack_;
-  }
-
-  // Returns whether the given URL is allowed to commit in the current process.
-  // This is a more conservative check than RenderProcessHost::FilterURL, since
-  // it will be used to kill processes that commit unauthorized URLs.
-  bool CanCommitURL(const GURL& url);
+  // Whether the RVH is waiting for the unload ack from the renderer.
+  bool IsWaitingForUnloadACK() const;
 
   // Update the FrameTree to use this RenderViewHost's main frame
   // RenderFrameHost. Called when the RenderViewHost is committed.
@@ -481,6 +520,18 @@ class CONTENT_EXPORT RenderViewHostImpl
                                          bool main_frame,
                                          const GURL& url);
 
+  // Increases the refcounting on this RVH. This is done by the FrameTree on
+  // creation of a RenderFrameHost.
+  void increment_ref_count() { ++frames_ref_count_; }
+
+  // Decreases the refcounting on this RVH. This is done by the FrameTree on
+  // destruction of a RenderFrameHost.
+  void decrement_ref_count() { --frames_ref_count_; }
+
+  // Returns the refcount on this RVH, that is the number of RenderFrameHosts
+  // currently using it.
+  int ref_count() { return frames_ref_count_; }
+
   // NOTE: Do not add functions that just send an IPC message that are called in
   // one or two places. Have the caller send the IPC message directly (unless
   // the caller places are in different platforms, in which case it's better
@@ -517,13 +568,10 @@ class CONTENT_EXPORT RenderViewHostImpl
   void OnUpdateTargetURL(int32 page_id, const GURL& url);
   void OnClose();
   void OnRequestMove(const gfx::Rect& pos);
-  void OnDidStartLoading();
-  void OnDidStopLoading();
   void OnDidChangeLoadProgress(double load_progress);
   void OnDidDisownOpener();
   void OnDocumentAvailableInMainFrame();
   void OnDocumentOnLoadCompletedInMainFrame(int32 page_id);
-  void OnContextMenu(const ContextMenuParams& params);
   void OnToggleFullscreen(bool enter_fullscreen);
   void OnOpenURL(const ViewHostMsg_OpenURL_Params& params);
   void OnDidContentsPreferredSizeChange(const gfx::Size& new_size);
@@ -593,16 +641,23 @@ class CONTENT_EXPORT RenderViewHostImpl
 #endif
 
  private:
+  // TODO(nasko): Temporarily friend RenderFrameHostImpl, so we don't duplicate
+  // utility functions and state needed in both classes, while we move frame
+  // specific code away from this class.
+  friend class RenderFrameHostImpl;
   friend class TestRenderViewHost;
   FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, BasicRenderFrameHost);
   FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, RoutingIdSane);
 
-  // Sets whether this RenderViewHost is swapped out in favor of another,
-  // and clears any waiting state that is no longer relevant.
-  void SetSwappedOut(bool is_swapped_out);
+  // Updates the state of this RenderViewHost and clears any waiting state
+  // that is no longer relevant.
+  void SetState(RenderViewHostImplState rvh_state);
 
   bool CanAccessFilesOfPageState(const PageState& state) const;
 
+  // The number of RenderFrameHosts which have a reference to this RVH.
+  int frames_ref_count_;
+
   // Our delegate, which wants to know about changes in the RenderView.
   RenderViewHostDelegate* delegate_;
 
@@ -623,13 +678,15 @@ class CONTENT_EXPORT RenderViewHostImpl
   // them.  This will be true when a RenderViewHost is created for a cross-site
   // request, until we hear back from the onbeforeunload handler of the old
   // RenderViewHost.
+  // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
   bool navigations_suspended_;
 
   // We only buffer the params for a suspended navigation while we have a
   // pending RVH for a WebContentsImpl.  There will only ever be one suspended
   // navigation, because WebContentsImpl will destroy the pending RVH and create
   // a new one if a second navigation occurs.
-  scoped_ptr<ViewMsg_Navigate_Params> suspended_nav_params_;
+  // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
+  scoped_ptr<FrameMsg_Navigate_Params> suspended_nav_params_;
 
   // Whether the initial empty page of this view has been accessed by another
   // page, making it unsafe to show the pending URL.  Usually false unless
@@ -637,9 +694,9 @@ class CONTENT_EXPORT RenderViewHostImpl
   // first commit.
   bool has_accessed_initial_document_;
 
-  // Whether this RenderViewHost is currently swapped out, such that the view is
-  // being rendered by another process.
-  bool is_swapped_out_;
+  // The current state of this RVH.
+  // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
+  RenderViewHostImplState rvh_state_;
 
   // The frame id of the main (top level) frame. This value is set on the
   // initial navigation of a RenderView and reset when the RenderView's
@@ -658,22 +715,19 @@ class CONTENT_EXPORT RenderViewHostImpl
 
   // Set to true when there is a pending ViewMsg_ShouldClose message.  This
   // ensures we don't spam the renderer with multiple beforeunload requests.
-  // When either this value or is_waiting_for_unload_ack_ is true, the value of
+  // When either this value or IsWaitingForUnloadACK is true, the value of
   // unload_ack_is_for_cross_site_transition_ indicates whether this is for a
   // cross-site transition or a tab close attempt.
+  // TODO(clamy): Remove this boolean and add one more state to the state
+  // machine.
+  // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
   bool is_waiting_for_beforeunload_ack_;
 
-  // Set to true when there is a pending ViewMsg_Close message.  Also see
-  // is_waiting_for_beforeunload_ack_, unload_ack_is_for_cross_site_transition_.
-  bool is_waiting_for_unload_ack_;
-
-  // Set to true when waiting for ViewHostMsg_SwapOut_ACK has timed out.
-  bool has_timed_out_on_unload_;
-
   // Valid only when is_waiting_for_beforeunload_ack_ or
-  // is_waiting_for_unload_ack_ is true.  This tells us if the unload request
+  // IsWaitingForUnloadACK is true.  This tells us if the unload request
   // is for closing the entire tab ( = false), or only this RenderViewHost in
   // the case of a cross-site transition ( = true).
+  // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
   bool unload_ack_is_for_cross_site_transition_;
 
   bool are_javascript_messages_suppressed_;
@@ -696,6 +750,7 @@ class CONTENT_EXPORT RenderViewHostImpl
   base::TerminationStatus render_view_termination_status_;
 
   // When the last ShouldClose message was sent.
+  // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
   base::TimeTicks send_should_close_start_time_;
 
   // Set to true if we requested the on screen keyboard to be displayed.
@@ -706,6 +761,19 @@ class CONTENT_EXPORT RenderViewHostImpl
   scoped_ptr<BrowserMediaPlayerManager> media_player_manager_;
 #endif
 
+  // Used to swap out or shutdown this RVH when the unload event is taking too
+  // long to execute, depending on the number of active views in the
+  // SiteInstance.
+  // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
+  scoped_ptr<TimeoutMonitor> unload_event_monitor_timeout_;
+
+  // Called after receiving the SwapOutACK when the RVH is in state pending
+  // shutdown. Also called if the unload timer times out.
+  // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
+  base::Closure pending_shutdown_on_swap_out_;
+
+  base::WeakPtrFactory<RenderViewHostImpl> weak_factory_;
+
   DISALLOW_COPY_AND_ASSIGN(RenderViewHostImpl);
 };