| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_H_ | 5 #ifndef CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_H_ |
| 6 #define CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_H_ | 6 #define CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // all FrameTreeNodes will be created/deleted in response to frame attach and | 27 // all FrameTreeNodes will be created/deleted in response to frame attach and |
| 28 // detach events in the DOM. | 28 // detach events in the DOM. |
| 29 // | 29 // |
| 30 // The main frame's FrameTreeNode is special in that it is reused. This allows | 30 // The main frame's FrameTreeNode is special in that it is reused. This allows |
| 31 // it to serve as an anchor for state that needs to persist across top-level | 31 // it to serve as an anchor for state that needs to persist across top-level |
| 32 // page navigations. | 32 // page navigations. |
| 33 // | 33 // |
| 34 // TODO(ajwong): Move NavigationController ownership to the main frame | 34 // TODO(ajwong): Move NavigationController ownership to the main frame |
| 35 // FrameTreeNode. Possibly expose access to it from here. | 35 // FrameTreeNode. Possibly expose access to it from here. |
| 36 // | 36 // |
| 37 // TODO(ajwong): Currently this class only contains FrameTreeNodes for | |
| 38 // subframes if the --site-per-process flag is enabled. | |
| 39 // | |
| 40 // This object is only used on the UI thread. | 37 // This object is only used on the UI thread. |
| 41 class CONTENT_EXPORT FrameTree { | 38 class CONTENT_EXPORT FrameTree { |
| 42 public: | 39 public: |
| 43 // Each FrameTreeNode will default to using the given |navigator| for | 40 // Each FrameTreeNode will default to using the given |navigator| for |
| 44 // navigation tasks in the frame. | 41 // navigation tasks in the frame. |
| 45 // A set of delegates are remembered here so that we can create | 42 // A set of delegates are remembered here so that we can create |
| 46 // RenderFrameHostManagers. | 43 // RenderFrameHostManagers. |
| 47 // TODO(creis): This set of delegates will change as we move things to | 44 // TODO(creis): This set of delegates will change as we move things to |
| 48 // Navigator. | 45 // Navigator. |
| 49 FrameTree(Navigator* navigator, | 46 FrameTree(Navigator* navigator, |
| 50 RenderFrameHostDelegate* render_frame_delegate, | 47 RenderFrameHostDelegate* render_frame_delegate, |
| 51 RenderViewHostDelegate* render_view_delegate, | 48 RenderViewHostDelegate* render_view_delegate, |
| 52 RenderWidgetHostDelegate* render_widget_delegate, | 49 RenderWidgetHostDelegate* render_widget_delegate, |
| 53 RenderFrameHostManager::Delegate* manager_delegate); | 50 RenderFrameHostManager::Delegate* manager_delegate); |
| 54 ~FrameTree(); | 51 ~FrameTree(); |
| 55 | 52 |
| 56 FrameTreeNode* root() const { return root_.get(); } | 53 FrameTreeNode* root() const { return root_.get(); } |
| 57 | 54 |
| 58 // Returns the FrameTreeNode with the given |frame_tree_node_id|. | 55 // Returns the FrameTreeNode with the given |frame_tree_node_id|. |
| 59 FrameTreeNode* FindByID(int64 frame_tree_node_id); | 56 FrameTreeNode* FindByID(int64 frame_tree_node_id); |
| 60 | 57 |
| 58 // Returns the FrameTreeNode with the given renderer-specific |routing_id|. |
| 59 FrameTreeNode* FindByRoutingID(int routing_id, int process_id); |
| 60 |
| 61 // Executes |on_node| on each node in the frame tree. If |on_node| returns | 61 // Executes |on_node| on each node in the frame tree. If |on_node| returns |
| 62 // false, terminates the iteration immediately. Returning false is useful | 62 // false, terminates the iteration immediately. Returning false is useful |
| 63 // if |on_node| is just doing a search over the tree. The iteration proceeds | 63 // if |on_node| is just doing a search over the tree. The iteration proceeds |
| 64 // top-down and visits a node before adding its children to the queue, making | 64 // top-down and visits a node before adding its children to the queue, making |
| 65 // it safe to remove children during the callback. | 65 // it safe to remove children during the callback. |
| 66 void ForEach(const base::Callback<bool(FrameTreeNode*)>& on_node) const; | 66 void ForEach(const base::Callback<bool(FrameTreeNode*)>& on_node) const; |
| 67 | 67 |
| 68 // After the FrameTree is created, or after SwapMainFrame() has been called, | |
| 69 // the root node does not yet have a frame id. This is allocated by the | |
| 70 // renderer and is published to the browser process on the first navigation | |
| 71 // after a swap. These two functions are used to set the root node's frame | |
| 72 // id. | |
| 73 // | |
| 74 // TODO(ajwong): Remove these once RenderFrameHost's routing id replaces | |
| 75 // frame_id. | |
| 76 bool IsFirstNavigationAfterSwap() const; | |
| 77 void OnFirstNavigationAfterSwap(int main_frame_id); | |
| 78 | |
| 79 // Frame tree manipulation routines. | 68 // Frame tree manipulation routines. |
| 80 // TODO(creis): These should take in RenderFrameHost routing IDs. | 69 RenderFrameHostImpl* AddFrame(FrameTreeNode* parent, |
| 81 RenderFrameHostImpl* AddFrame(int frame_routing_id, | 70 int new_routing_id, |
| 82 int64 parent_frame_tree_node_id, | |
| 83 int64 frame_id, | |
| 84 const std::string& frame_name); | 71 const std::string& frame_name); |
| 85 void RemoveFrame(RenderFrameHostImpl* render_frame_host, | 72 void RemoveFrame(FrameTreeNode* child); |
| 86 int64 parent_frame_id, | |
| 87 int64 frame_id); | |
| 88 void SetFrameUrl(int64 frame_id, const GURL& url); | |
| 89 | 73 |
| 90 // Clears process specific-state after a main frame process swap. | 74 // Clears process specific-state after a main frame process swap. |
| 91 // This destroys most of the frame tree but retains the root node so that | 75 // This destroys most of the frame tree but retains the root node so that |
| 92 // navigation state may be kept on it between process swaps. Used to | 76 // navigation state may be kept on it between process swaps. Used to |
| 93 // support bookkeeping for top-level navigations. | 77 // support bookkeeping for top-level navigations. |
| 94 // TODO(creis): Look into how we can remove the need for this method. | 78 // TODO(creis): Look into how we can remove the need for this method. |
| 95 void ResetForMainFrameSwap(); | 79 void ResetForMainFrameSwap(); |
| 96 | 80 |
| 97 // Update the frame tree after a process exits. Any nodes currently using the | 81 // Update the frame tree after a process exits. Any nodes currently using the |
| 98 // given |render_view_host| will lose all their children. | 82 // given |render_view_host| will lose all their children. |
| 99 // TODO(creis): This should take a RenderProcessHost once RenderFrameHost | 83 // TODO(creis): This should take a RenderProcessHost once RenderFrameHost |
| 100 // knows its process. Until then, we would just be asking the RenderViewHost | 84 // knows its process. Until then, we would just be asking the RenderViewHost |
| 101 // for its process, so we'll skip that step. | 85 // for its process, so we'll skip that step. |
| 102 void RenderProcessGone(RenderViewHost* render_view_host); | 86 void RenderProcessGone(RenderViewHost* render_view_host); |
| 103 | 87 |
| 104 // Convenience accessor for the main frame's RenderFrameHostImpl. | 88 // Convenience accessor for the main frame's RenderFrameHostImpl. |
| 105 RenderFrameHostImpl* GetMainFrame() const; | 89 RenderFrameHostImpl* GetMainFrame() const; |
| 106 | 90 |
| 107 // Allows a client to listen for frame removal. The listener should expect | 91 // Allows a client to listen for frame removal. The listener should expect |
| 108 // to receive the RenderViewHostImpl containing the frame and the renderer- | 92 // to receive the RenderViewHostImpl containing the frame and the renderer- |
| 109 // specific frame ID of the removed frame. | 93 // specific frame routing ID of the removed frame. |
| 110 // TODO(creis): These parameters will later change to be the RenderFrameHost. | 94 // TODO(creis): These parameters will later change to be the RenderFrameHost. |
| 111 void SetFrameRemoveListener( | 95 void SetFrameRemoveListener( |
| 112 const base::Callback<void(RenderViewHostImpl*, int64)>& on_frame_removed); | 96 const base::Callback<void(RenderViewHostImpl*, int)>& on_frame_removed); |
| 113 | |
| 114 void ClearFrameRemoveListenerForTesting(); | |
| 115 | 97 |
| 116 // Creates a RenderViewHost for a new main frame RenderFrameHost in the given | 98 // Creates a RenderViewHost for a new main frame RenderFrameHost in the given |
| 117 // |site_instance|. The RenderViewHost will have its Shutdown method called | 99 // |site_instance|. The RenderViewHost will have its Shutdown method called |
| 118 // when all of the RenderFrameHosts using it are deleted. | 100 // when all of the RenderFrameHosts using it are deleted. |
| 119 RenderViewHostImpl* CreateRenderViewHostForMainFrame( | 101 RenderViewHostImpl* CreateRenderViewHostForMainFrame( |
| 120 SiteInstance* site_instance, | 102 SiteInstance* site_instance, |
| 121 int routing_id, | 103 int routing_id, |
| 122 int main_frame_routing_id, | 104 int main_frame_routing_id, |
| 123 bool swapped_out, | 105 bool swapped_out, |
| 124 bool hidden); | 106 bool hidden); |
| 125 | 107 |
| 126 // Returns the existing RenderViewHost for a new subframe RenderFrameHost. | 108 // Returns the existing RenderViewHost for a new subframe RenderFrameHost. |
| 127 // There should always be such a RenderViewHost, because the main frame | 109 // There should always be such a RenderViewHost, because the main frame |
| 128 // RenderFrameHost for each SiteInstance should be created before subframes. | 110 // RenderFrameHost for each SiteInstance should be created before subframes. |
| 129 RenderViewHostImpl* GetRenderViewHostForSubFrame(SiteInstance* site_instance); | 111 RenderViewHostImpl* GetRenderViewHostForSubFrame(SiteInstance* site_instance); |
| 130 | 112 |
| 131 // Keeps track of which RenderFrameHosts are using each RenderViewHost. When | 113 // Keeps track of which RenderFrameHosts are using each RenderViewHost. When |
| 132 // the number drops to zero, we call Shutdown on the RenderViewHost. | 114 // the number drops to zero, we call Shutdown on the RenderViewHost. |
| 133 void RegisterRenderFrameHost(RenderFrameHostImpl* render_frame_host); | 115 void RegisterRenderFrameHost(RenderFrameHostImpl* render_frame_host); |
| 134 void UnregisterRenderFrameHost(RenderFrameHostImpl* render_frame_host); | 116 void UnregisterRenderFrameHost(RenderFrameHostImpl* render_frame_host); |
| 135 | 117 |
| 136 // Returns the FrameTreeNode with the given renderer-specific |frame_id|. | |
| 137 // TODO(creis): Make this private and replace this with a version that takes | |
| 138 // in a routing ID. | |
| 139 FrameTreeNode* FindByFrameID(int64 frame_id); | |
| 140 | |
| 141 private: | 118 private: |
| 142 typedef base::hash_map<int, RenderViewHostImpl*> RenderViewHostMap; | 119 typedef base::hash_map<int, RenderViewHostImpl*> RenderViewHostMap; |
| 143 typedef std::multimap<int, RenderViewHostImpl*> RenderViewHostMultiMap; | 120 typedef std::multimap<int, RenderViewHostImpl*> RenderViewHostMultiMap; |
| 144 | 121 |
| 145 // These delegates are installed into all the RenderViewHosts and | 122 // These delegates are installed into all the RenderViewHosts and |
| 146 // RenderFrameHosts that we create. | 123 // RenderFrameHosts that we create. |
| 147 RenderFrameHostDelegate* render_frame_delegate_; | 124 RenderFrameHostDelegate* render_frame_delegate_; |
| 148 RenderViewHostDelegate* render_view_delegate_; | 125 RenderViewHostDelegate* render_view_delegate_; |
| 149 RenderWidgetHostDelegate* render_widget_delegate_; | 126 RenderWidgetHostDelegate* render_widget_delegate_; |
| 150 RenderFrameHostManager::Delegate* manager_delegate_; | 127 RenderFrameHostManager::Delegate* manager_delegate_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 161 | 138 |
| 162 // Map of SiteInstance ID to RenderViewHosts that are pending shutdown. The | 139 // Map of SiteInstance ID to RenderViewHosts that are pending shutdown. The |
| 163 // renderers of these RVH are currently executing the unload event in | 140 // renderers of these RVH are currently executing the unload event in |
| 164 // background. When the SwapOutACK is received, they will be deleted. In the | 141 // background. When the SwapOutACK is received, they will be deleted. In the |
| 165 // meantime, they are kept in this map, as they should not be reused (part of | 142 // meantime, they are kept in this map, as they should not be reused (part of |
| 166 // their state is already gone away). | 143 // their state is already gone away). |
| 167 RenderViewHostMultiMap render_view_host_pending_shutdown_map_; | 144 RenderViewHostMultiMap render_view_host_pending_shutdown_map_; |
| 168 | 145 |
| 169 scoped_ptr<FrameTreeNode> root_; | 146 scoped_ptr<FrameTreeNode> root_; |
| 170 | 147 |
| 171 base::Callback<void(RenderViewHostImpl*, int64)> on_frame_removed_; | 148 base::Callback<void(RenderViewHostImpl*, int)> on_frame_removed_; |
| 172 | 149 |
| 173 DISALLOW_COPY_AND_ASSIGN(FrameTree); | 150 DISALLOW_COPY_AND_ASSIGN(FrameTree); |
| 174 }; | 151 }; |
| 175 | 152 |
| 176 } // namespace content | 153 } // namespace content |
| 177 | 154 |
| 178 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_H_ | 155 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_H_ |
| OLD | NEW |