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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // RenderFrameHostManagers. | 46 // RenderFrameHostManagers. |
47 // TODO(creis): This set of delegates will change as we move things to | 47 // TODO(creis): This set of delegates will change as we move things to |
48 // Navigator. | 48 // Navigator. |
49 FrameTree(Navigator* navigator, | 49 FrameTree(Navigator* navigator, |
50 RenderFrameHostDelegate* render_frame_delegate, | 50 RenderFrameHostDelegate* render_frame_delegate, |
51 RenderViewHostDelegate* render_view_delegate, | 51 RenderViewHostDelegate* render_view_delegate, |
52 RenderWidgetHostDelegate* render_widget_delegate, | 52 RenderWidgetHostDelegate* render_widget_delegate, |
53 RenderFrameHostManager::Delegate* manager_delegate); | 53 RenderFrameHostManager::Delegate* manager_delegate); |
54 ~FrameTree(); | 54 ~FrameTree(); |
55 | 55 |
| 56 FrameTreeNode* root() const { return root_.get(); } |
| 57 |
56 // Returns the FrameTreeNode with the given |frame_tree_node_id|. | 58 // Returns the FrameTreeNode with the given |frame_tree_node_id|. |
57 FrameTreeNode* FindByID(int64 frame_tree_node_id); | 59 FrameTreeNode* FindByID(int64 frame_tree_node_id); |
58 | 60 |
59 // 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 |
60 // false, terminates the iteration immediately. Returning false is useful | 62 // false, terminates the iteration immediately. Returning false is useful |
61 // if |on_node| is just doing a search over the tree. | 63 // if |on_node| is just doing a search over the tree. |
62 void ForEach(const base::Callback<bool(FrameTreeNode*)>& on_node) const; | 64 void ForEach(const base::Callback<bool(FrameTreeNode*)>& on_node) const; |
63 | 65 |
64 // After the FrameTree is created, or after SwapMainFrame() has been called, | 66 // After the FrameTree is created, or after SwapMainFrame() has been called, |
65 // the root node does not yet have a frame id. This is allocated by the | 67 // the root node does not yet have a frame id. This is allocated by the |
66 // renderer and is published to the browser process on the first navigation | 68 // renderer and is published to the browser process on the first navigation |
67 // after a swap. These two functions are used to set the root node's frame | 69 // after a swap. These two functions are used to set the root node's frame |
68 // id. | 70 // id. |
69 // | 71 // |
70 // TODO(ajwong): Remove these once RenderFrameHost's routing id replaces | 72 // TODO(ajwong): Remove these once RenderFrameHost's routing id replaces |
71 // frame_id. | 73 // frame_id. |
72 bool IsFirstNavigationAfterSwap() const; | 74 bool IsFirstNavigationAfterSwap() const; |
73 void OnFirstNavigationAfterSwap(int main_frame_id); | 75 void OnFirstNavigationAfterSwap(int main_frame_id); |
74 | 76 |
75 // Frame tree manipulation routines. | 77 // Frame tree manipulation routines. |
76 // TODO(creis): These should take in RenderFrameHost routing IDs. | 78 // TODO(creis): These should take in RenderFrameHost routing IDs. |
77 RenderFrameHostImpl* AddFrame(int render_frame_host_id, | 79 RenderFrameHostImpl* AddFrame(int frame_routing_id, |
78 int64 parent_frame_tree_node_id, | 80 int64 parent_frame_tree_node_id, |
79 int64 frame_id, | 81 int64 frame_id, |
80 const std::string& frame_name); | 82 const std::string& frame_name); |
81 void RemoveFrame(RenderFrameHostImpl* render_frame_host, | 83 void RemoveFrame(RenderFrameHostImpl* render_frame_host, |
82 int64 parent_frame_id, | 84 int64 parent_frame_id, |
83 int64 frame_id); | 85 int64 frame_id); |
84 void SetFrameUrl(int64 frame_id, const GURL& url); | 86 void SetFrameUrl(int64 frame_id, const GURL& url); |
85 | 87 |
86 // Resets the FrameTree and changes RenderFrameHost for the main frame. | 88 // Clears process specific-state after a main frame process swap. |
87 // This destroys most of the frame tree but retains the root node so that | 89 // This destroys most of the frame tree but retains the root node so that |
88 // navigation state may be kept on it between process swaps. Used to | 90 // navigation state may be kept on it between process swaps. Used to |
89 // support bookkeeping for top-level navigations. | 91 // support bookkeeping for top-level navigations. |
90 // | 92 // TODO(creis): Look into how we can remove the need for this method. |
91 // If |main_frame| is NULL, reset tree to initially constructed state. | 93 void ResetForMainFrameSwap(); |
92 // | |
93 // TODO(ajwong): This function should not be given a |main_frame|. This is | |
94 // required currently because the RenderViewHost owns its main frame. When | |
95 // that relation is fixed, the FrameTree should be responsible for | |
96 // created/destroying the main frame on the swap. | |
97 void SwapMainFrame(RenderFrameHostImpl* main_frame); | |
98 | 94 |
99 // Convenience accessor for the main frame's RenderFrameHostImpl. | 95 // Convenience accessor for the main frame's RenderFrameHostImpl. |
100 RenderFrameHostImpl* GetMainFrame() const; | 96 RenderFrameHostImpl* GetMainFrame() const; |
101 | 97 |
102 // Allows a client to listen for frame removal. The listener should expect | 98 // Allows a client to listen for frame removal. The listener should expect |
103 // to receive the RenderViewHostImpl containing the frame and the renderer- | 99 // to receive the RenderViewHostImpl containing the frame and the renderer- |
104 // specific frame ID of the removed frame. | 100 // specific frame ID of the removed frame. |
105 // TODO(creis): These parameters will later change to be the RenderFrameHost. | 101 // TODO(creis): These parameters will later change to be the RenderFrameHost. |
106 void SetFrameRemoveListener( | 102 void SetFrameRemoveListener( |
107 const base::Callback<void(RenderViewHostImpl*, int64)>& on_frame_removed); | 103 const base::Callback<void(RenderViewHostImpl*, int64)>& on_frame_removed); |
108 | 104 |
109 FrameTreeNode* root() const { return root_.get(); } | 105 void ClearFrameRemoveListenerForTesting(); |
| 106 |
| 107 // Creates a RenderViewHost for a new main frame RenderFrameHost in the given |
| 108 // |site_instance|. The RenderViewHost will have its Shutdown method called |
| 109 // when all of the RenderFrameHosts using it are deleted. |
| 110 RenderViewHostImpl* CreateRenderViewHostForMainFrame( |
| 111 SiteInstance* site_instance, |
| 112 int routing_id, |
| 113 int main_frame_routing_id, |
| 114 bool swapped_out, |
| 115 bool hidden); |
| 116 |
| 117 // Returns the existing RenderViewHost for a new subframe RenderFrameHost. |
| 118 // There should always be such a RenderViewHost, because the main frame |
| 119 // RenderFrameHost for each SiteInstance should be created before subframes. |
| 120 RenderViewHostImpl* GetRenderViewHostForSubFrame(SiteInstance* site_instance); |
| 121 |
| 122 // Keeps track of which RenderFrameHosts are using each RenderViewHost. When |
| 123 // the number drops to zero, we call Shutdown on the RenderViewHost. |
| 124 void RegisterRenderFrameHost(RenderFrameHostImpl* render_frame_host); |
| 125 void UnregisterRenderFrameHost(RenderFrameHostImpl* render_frame_host); |
110 | 126 |
111 private: | 127 private: |
| 128 typedef std::pair<RenderViewHostImpl*, int> RenderViewHostRefCount; |
| 129 typedef base::hash_map<int, RenderViewHostRefCount> RenderViewHostMap; |
| 130 |
112 // Returns the FrameTreeNode with the given renderer-specific |frame_id|. | 131 // Returns the FrameTreeNode with the given renderer-specific |frame_id|. |
113 // For internal use only. | 132 // For internal use only. |
114 // TODO(creis): Replace this with a version that takes in a routing ID. | 133 // TODO(creis): Replace this with a version that takes in a routing ID. |
115 FrameTreeNode* FindByFrameID(int64 frame_id); | 134 FrameTreeNode* FindByFrameID(int64 frame_id); |
116 | 135 |
117 scoped_ptr<FrameTreeNode> CreateNode(int64 frame_id, | |
118 const std::string& frame_name, | |
119 int render_frame_host_id, | |
120 FrameTreeNode* parent_node); | |
121 | |
122 // These delegates are installed into all the RenderViewHosts and | 136 // These delegates are installed into all the RenderViewHosts and |
123 // RenderFrameHosts that we create. | 137 // RenderFrameHosts that we create. |
124 RenderFrameHostDelegate* render_frame_delegate_; | 138 RenderFrameHostDelegate* render_frame_delegate_; |
125 RenderViewHostDelegate* render_view_delegate_; | 139 RenderViewHostDelegate* render_view_delegate_; |
126 RenderWidgetHostDelegate* render_widget_delegate_; | 140 RenderWidgetHostDelegate* render_widget_delegate_; |
127 RenderFrameHostManager::Delegate* manager_delegate_; | 141 RenderFrameHostManager::Delegate* manager_delegate_; |
128 | 142 |
| 143 // Map of SiteInstance ID to a (RenderViewHost, refcount) pair. This allows |
| 144 // us to look up the RenderViewHost for a given SiteInstance when creating |
| 145 // RenderFrameHosts, and it allows us to call Shutdown on the RenderViewHost |
| 146 // and remove it from the map when no more RenderFrameHosts are using it. |
| 147 // |
| 148 // Must be declared before |root_| so that it is deleted afterward. Otherwise |
| 149 // the map will be cleared before we delete the RenderFrameHosts in the tree. |
| 150 RenderViewHostMap render_view_host_map_; |
| 151 |
129 scoped_ptr<FrameTreeNode> root_; | 152 scoped_ptr<FrameTreeNode> root_; |
130 | 153 |
131 base::Callback<void(RenderViewHostImpl*, int64)> on_frame_removed_; | 154 base::Callback<void(RenderViewHostImpl*, int64)> on_frame_removed_; |
132 | 155 |
133 DISALLOW_COPY_AND_ASSIGN(FrameTree); | 156 DISALLOW_COPY_AND_ASSIGN(FrameTree); |
134 }; | 157 }; |
135 | 158 |
136 } // namespace content | 159 } // namespace content |
137 | 160 |
138 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_H_ | 161 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_H_ |
OLD | NEW |