Chromium Code Reviews| 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, | 73 void SetFrameUrl(int routing_id, int process_id, const GURL& url); |
|
awong
2014/02/20 00:25:30
We have APIs for add, remove, and edit (SetFrameUR
Charlie Reis
2014/02/20 00:43:53
Sure. Even better, that just leaves a call to set
| |
| 87 int64 frame_id); | |
| 88 void SetFrameUrl(int64 frame_id, const GURL& url); | |
| 89 | 74 |
| 90 // Clears process specific-state after a main frame process swap. | 75 // 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 | 76 // 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 | 77 // navigation state may be kept on it between process swaps. Used to |
| 93 // support bookkeeping for top-level navigations. | 78 // support bookkeeping for top-level navigations. |
| 94 // TODO(creis): Look into how we can remove the need for this method. | 79 // TODO(creis): Look into how we can remove the need for this method. |
| 95 void ResetForMainFrameSwap(); | 80 void ResetForMainFrameSwap(); |
| 96 | 81 |
| 97 // Update the frame tree after a process exits. Any nodes currently using the | 82 // Update the frame tree after a process exits. Any nodes currently using the |
| 98 // given |render_view_host| will lose all their children. | 83 // given |render_view_host| will lose all their children. |
| 99 // TODO(creis): This should take a RenderProcessHost once RenderFrameHost | 84 // TODO(creis): This should take a RenderProcessHost once RenderFrameHost |
| 100 // knows its process. Until then, we would just be asking the RenderViewHost | 85 // knows its process. Until then, we would just be asking the RenderViewHost |
| 101 // for its process, so we'll skip that step. | 86 // for its process, so we'll skip that step. |
| 102 void RenderProcessGone(RenderViewHost* render_view_host); | 87 void RenderProcessGone(RenderViewHost* render_view_host); |
| 103 | 88 |
| 104 // Convenience accessor for the main frame's RenderFrameHostImpl. | 89 // Convenience accessor for the main frame's RenderFrameHostImpl. |
| 105 RenderFrameHostImpl* GetMainFrame() const; | 90 RenderFrameHostImpl* GetMainFrame() const; |
| 106 | 91 |
| 107 // Allows a client to listen for frame removal. The listener should expect | 92 // Allows a client to listen for frame removal. The listener should expect |
| 108 // to receive the RenderViewHostImpl containing the frame and the renderer- | 93 // to receive the RenderViewHostImpl containing the frame and the renderer- |
| 109 // specific frame ID of the removed frame. | 94 // specific frame routing ID of the removed frame. |
| 110 // TODO(creis): These parameters will later change to be the RenderFrameHost. | 95 // TODO(creis): These parameters will later change to be the RenderFrameHost. |
| 111 void SetFrameRemoveListener( | 96 void SetFrameRemoveListener( |
| 112 const base::Callback<void(RenderViewHostImpl*, int64)>& on_frame_removed); | 97 const base::Callback<void(RenderViewHostImpl*, int)>& on_frame_removed); |
| 113 | |
| 114 void ClearFrameRemoveListenerForTesting(); | |
| 115 | 98 |
| 116 // Creates a RenderViewHost for a new main frame RenderFrameHost in the given | 99 // Creates a RenderViewHost for a new main frame RenderFrameHost in the given |
| 117 // |site_instance|. The RenderViewHost will have its Shutdown method called | 100 // |site_instance|. The RenderViewHost will have its Shutdown method called |
| 118 // when all of the RenderFrameHosts using it are deleted. | 101 // when all of the RenderFrameHosts using it are deleted. |
| 119 RenderViewHostImpl* CreateRenderViewHostForMainFrame( | 102 RenderViewHostImpl* CreateRenderViewHostForMainFrame( |
| 120 SiteInstance* site_instance, | 103 SiteInstance* site_instance, |
| 121 int routing_id, | 104 int routing_id, |
| 122 int main_frame_routing_id, | 105 int main_frame_routing_id, |
| 123 bool swapped_out, | 106 bool swapped_out, |
| 124 bool hidden); | 107 bool hidden); |
| 125 | 108 |
| 126 // Returns the existing RenderViewHost for a new subframe RenderFrameHost. | 109 // Returns the existing RenderViewHost for a new subframe RenderFrameHost. |
| 127 // There should always be such a RenderViewHost, because the main frame | 110 // There should always be such a RenderViewHost, because the main frame |
| 128 // RenderFrameHost for each SiteInstance should be created before subframes. | 111 // RenderFrameHost for each SiteInstance should be created before subframes. |
| 129 RenderViewHostImpl* GetRenderViewHostForSubFrame(SiteInstance* site_instance); | 112 RenderViewHostImpl* GetRenderViewHostForSubFrame(SiteInstance* site_instance); |
| 130 | 113 |
| 131 // Keeps track of which RenderFrameHosts are using each RenderViewHost. When | 114 // Keeps track of which RenderFrameHosts are using each RenderViewHost. When |
| 132 // the number drops to zero, we call Shutdown on the RenderViewHost. | 115 // the number drops to zero, we call Shutdown on the RenderViewHost. |
| 133 void RegisterRenderFrameHost(RenderFrameHostImpl* render_frame_host); | 116 void RegisterRenderFrameHost(RenderFrameHostImpl* render_frame_host); |
| 134 void UnregisterRenderFrameHost(RenderFrameHostImpl* render_frame_host); | 117 void UnregisterRenderFrameHost(RenderFrameHostImpl* render_frame_host); |
| 135 | 118 |
| 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: | 119 private: |
| 142 typedef base::hash_map<int, RenderViewHostImpl*> RenderViewHostMap; | 120 typedef base::hash_map<int, RenderViewHostImpl*> RenderViewHostMap; |
| 143 typedef std::multimap<int, RenderViewHostImpl*> RenderViewHostMultiMap; | 121 typedef std::multimap<int, RenderViewHostImpl*> RenderViewHostMultiMap; |
| 144 | 122 |
| 145 // These delegates are installed into all the RenderViewHosts and | 123 // These delegates are installed into all the RenderViewHosts and |
| 146 // RenderFrameHosts that we create. | 124 // RenderFrameHosts that we create. |
| 147 RenderFrameHostDelegate* render_frame_delegate_; | 125 RenderFrameHostDelegate* render_frame_delegate_; |
| 148 RenderViewHostDelegate* render_view_delegate_; | 126 RenderViewHostDelegate* render_view_delegate_; |
| 149 RenderWidgetHostDelegate* render_widget_delegate_; | 127 RenderWidgetHostDelegate* render_widget_delegate_; |
| 150 RenderFrameHostManager::Delegate* manager_delegate_; | 128 RenderFrameHostManager::Delegate* manager_delegate_; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 161 | 139 |
| 162 // Map of SiteInstance ID to RenderViewHosts that are pending shutdown. The | 140 // Map of SiteInstance ID to RenderViewHosts that are pending shutdown. The |
| 163 // renderers of these RVH are currently executing the unload event in | 141 // renderers of these RVH are currently executing the unload event in |
| 164 // background. When the SwapOutACK is received, they will be deleted. In the | 142 // 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 | 143 // meantime, they are kept in this map, as they should not be reused (part of |
| 166 // their state is already gone away). | 144 // their state is already gone away). |
| 167 RenderViewHostMultiMap render_view_host_pending_shutdown_map_; | 145 RenderViewHostMultiMap render_view_host_pending_shutdown_map_; |
| 168 | 146 |
| 169 scoped_ptr<FrameTreeNode> root_; | 147 scoped_ptr<FrameTreeNode> root_; |
| 170 | 148 |
| 171 base::Callback<void(RenderViewHostImpl*, int64)> on_frame_removed_; | 149 base::Callback<void(RenderViewHostImpl*, int)> on_frame_removed_; |
| 172 | 150 |
| 173 DISALLOW_COPY_AND_ASSIGN(FrameTree); | 151 DISALLOW_COPY_AND_ASSIGN(FrameTree); |
| 174 }; | 152 }; |
| 175 | 153 |
| 176 } // namespace content | 154 } // namespace content |
| 177 | 155 |
| 178 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_H_ | 156 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_H_ |
| OLD | NEW |