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 | |
58 // Returns the FrameTreeNode with the given |frame_tree_node_id|. | 56 // Returns the FrameTreeNode with the given |frame_tree_node_id|. |
59 FrameTreeNode* FindByID(int64 frame_tree_node_id); | 57 FrameTreeNode* FindByID(int64 frame_tree_node_id); |
60 | 58 |
61 // Executes |on_node| on each node in the frame tree. If |on_node| returns | 59 // Executes |on_node| on each node in the frame tree. If |on_node| returns |
62 // false, terminates the iteration immediately. Returning false is useful | 60 // false, terminates the iteration immediately. Returning false is useful |
63 // if |on_node| is just doing a search over the tree. | 61 // if |on_node| is just doing a search over the tree. |
64 void ForEach(const base::Callback<bool(FrameTreeNode*)>& on_node) const; | 62 void ForEach(const base::Callback<bool(FrameTreeNode*)>& on_node) const; |
65 | 63 |
66 // After the FrameTree is created, or after SwapMainFrame() has been called, | 64 // After the FrameTree is created, or after SwapMainFrame() has been called, |
67 // the root node does not yet have a frame id. This is allocated by the | 65 // the root node does not yet have a frame id. This is allocated by the |
68 // renderer and is published to the browser process on the first navigation | 66 // renderer and is published to the browser process on the first navigation |
69 // after a swap. These two functions are used to set the root node's frame | 67 // after a swap. These two functions are used to set the root node's frame |
70 // id. | 68 // id. |
71 // | 69 // |
72 // TODO(ajwong): Remove these once RenderFrameHost's routing id replaces | 70 // TODO(ajwong): Remove these once RenderFrameHost's routing id replaces |
73 // frame_id. | 71 // frame_id. |
74 bool IsFirstNavigationAfterSwap() const; | 72 bool IsFirstNavigationAfterSwap() const; |
75 void OnFirstNavigationAfterSwap(int main_frame_id); | 73 void OnFirstNavigationAfterSwap(int main_frame_id); |
76 | 74 |
77 // Frame tree manipulation routines. | 75 // Frame tree manipulation routines. |
78 // TODO(creis): These should take in RenderFrameHost routing IDs. | 76 // TODO(creis): These should take in RenderFrameHost routing IDs. |
79 RenderFrameHostImpl* AddFrame(int frame_routing_id, | 77 RenderFrameHostImpl* AddFrame(int render_frame_host_id, |
80 int64 parent_frame_tree_node_id, | 78 int64 parent_frame_tree_node_id, |
81 int64 frame_id, | 79 int64 frame_id, |
82 const std::string& frame_name); | 80 const std::string& frame_name); |
83 void RemoveFrame(RenderFrameHostImpl* render_frame_host, | 81 void RemoveFrame(RenderFrameHostImpl* render_frame_host, |
84 int64 parent_frame_id, | 82 int64 parent_frame_id, |
85 int64 frame_id); | 83 int64 frame_id); |
86 void SetFrameUrl(int64 frame_id, const GURL& url); | 84 void SetFrameUrl(int64 frame_id, const GURL& url); |
87 | 85 |
88 // Clears process specific-state after a main frame process swap. | 86 // Resets the FrameTree and changes RenderFrameHost for the main frame. |
89 // This destroys most of the frame tree but retains the root node so that | 87 // This destroys most of the frame tree but retains the root node so that |
90 // navigation state may be kept on it between process swaps. Used to | 88 // navigation state may be kept on it between process swaps. Used to |
91 // support bookkeeping for top-level navigations. | 89 // support bookkeeping for top-level navigations. |
92 // TODO(creis): Look into how we can remove the need for this method. | 90 // |
93 void ResetForMainFrameSwap(); | 91 // If |main_frame| is NULL, reset tree to initially constructed state. |
| 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); |
94 | 98 |
95 // Convenience accessor for the main frame's RenderFrameHostImpl. | 99 // Convenience accessor for the main frame's RenderFrameHostImpl. |
96 RenderFrameHostImpl* GetMainFrame() const; | 100 RenderFrameHostImpl* GetMainFrame() const; |
97 | 101 |
98 // Allows a client to listen for frame removal. The listener should expect | 102 // Allows a client to listen for frame removal. The listener should expect |
99 // to receive the RenderViewHostImpl containing the frame and the renderer- | 103 // to receive the RenderViewHostImpl containing the frame and the renderer- |
100 // specific frame ID of the removed frame. | 104 // specific frame ID of the removed frame. |
101 // TODO(creis): These parameters will later change to be the RenderFrameHost. | 105 // TODO(creis): These parameters will later change to be the RenderFrameHost. |
102 void SetFrameRemoveListener( | 106 void SetFrameRemoveListener( |
103 const base::Callback<void(RenderViewHostImpl*, int64)>& on_frame_removed); | 107 const base::Callback<void(RenderViewHostImpl*, int64)>& on_frame_removed); |
104 | 108 |
105 void ClearFrameRemoveListenerForTesting(); | 109 FrameTreeNode* root() const { return root_.get(); } |
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); | |
126 | 110 |
127 private: | 111 private: |
128 typedef std::pair<RenderViewHostImpl*, int> RenderViewHostRefCount; | |
129 typedef base::hash_map<int, RenderViewHostRefCount> RenderViewHostMap; | |
130 | |
131 // Returns the FrameTreeNode with the given renderer-specific |frame_id|. | 112 // Returns the FrameTreeNode with the given renderer-specific |frame_id|. |
132 // For internal use only. | 113 // For internal use only. |
133 // TODO(creis): Replace this with a version that takes in a routing ID. | 114 // TODO(creis): Replace this with a version that takes in a routing ID. |
134 FrameTreeNode* FindByFrameID(int64 frame_id); | 115 FrameTreeNode* FindByFrameID(int64 frame_id); |
135 | 116 |
| 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 |
136 // These delegates are installed into all the RenderViewHosts and | 122 // These delegates are installed into all the RenderViewHosts and |
137 // RenderFrameHosts that we create. | 123 // RenderFrameHosts that we create. |
138 RenderFrameHostDelegate* render_frame_delegate_; | 124 RenderFrameHostDelegate* render_frame_delegate_; |
139 RenderViewHostDelegate* render_view_delegate_; | 125 RenderViewHostDelegate* render_view_delegate_; |
140 RenderWidgetHostDelegate* render_widget_delegate_; | 126 RenderWidgetHostDelegate* render_widget_delegate_; |
141 RenderFrameHostManager::Delegate* manager_delegate_; | 127 RenderFrameHostManager::Delegate* manager_delegate_; |
142 | 128 |
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 | |
152 scoped_ptr<FrameTreeNode> root_; | 129 scoped_ptr<FrameTreeNode> root_; |
153 | 130 |
154 base::Callback<void(RenderViewHostImpl*, int64)> on_frame_removed_; | 131 base::Callback<void(RenderViewHostImpl*, int64)> on_frame_removed_; |
155 | 132 |
156 DISALLOW_COPY_AND_ASSIGN(FrameTree); | 133 DISALLOW_COPY_AND_ASSIGN(FrameTree); |
157 }; | 134 }; |
158 | 135 |
159 } // namespace content | 136 } // namespace content |
160 | 137 |
161 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_H_ | 138 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_H_ |
OLD | NEW |