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 17 matching lines...) Expand all Loading... |
28 // | 28 // |
29 // TODO(ajwong): Move NavigationController ownership to the main frame | 29 // TODO(ajwong): Move NavigationController ownership to the main frame |
30 // FrameTreeNode. Possibly expose access to it from here. | 30 // FrameTreeNode. Possibly expose access to it from here. |
31 // | 31 // |
32 // TODO(ajwong): Currently this class only contains FrameTreeNodes for | 32 // TODO(ajwong): Currently this class only contains FrameTreeNodes for |
33 // subframes if the --site-per-process flag is enabled. | 33 // subframes if the --site-per-process flag is enabled. |
34 // | 34 // |
35 // This object is only used on the UI thread. | 35 // This object is only used on the UI thread. |
36 class CONTENT_EXPORT FrameTree { | 36 class CONTENT_EXPORT FrameTree { |
37 public: | 37 public: |
38 FrameTree(); | 38 // A set of delegates are remembered here so that we can create |
| 39 // RenderFrameHostManagers (and so that those can create RVHs and RFHs). |
| 40 // TODO(creis): This set of delegates will change as we create a Navigator |
| 41 // interface. |
| 42 FrameTree(RenderViewHostDelegate* render_view_delegate, |
| 43 RenderWidgetHostDelegate* render_widget_delegate, |
| 44 RenderViewHostManager::Delegate* manager_delegate); |
39 ~FrameTree(); | 45 ~FrameTree(); |
40 | 46 |
41 // Returns the FrameTreeNode with the given |frame_id|. | 47 // Returns the FrameTreeNode with the given |frame_id|. |
42 FrameTreeNode* FindByID(int64 frame_id); | 48 FrameTreeNode* FindByID(int64 frame_id); |
43 | 49 |
44 // Executes |on_node| on each node in the frame tree. If |on_node| returns | 50 // Executes |on_node| on each node in the frame tree. If |on_node| returns |
45 // false, terminates the iteration immediately. Returning false is useful | 51 // false, terminates the iteration immediately. Returning false is useful |
46 // if |on_node| is just doing a search over the tree. | 52 // if |on_node| is just doing a search over the tree. |
47 void ForEach(const base::Callback<bool(FrameTreeNode*)>& on_node) const; | 53 void ForEach(const base::Callback<bool(FrameTreeNode*)>& on_node) const; |
48 | 54 |
49 // After the FrameTree is created, or after SwapMainFrame() has been called, | |
50 // the root node does not yet have a frame id. This is allocated by the | |
51 // renderer and is published to the browser process on the first navigation | |
52 // after a swap. These two functions are used to set the root node's frame | |
53 // id. | |
54 // | |
55 // TODO(ajwong): Remove these once RenderFrameHost's routing id replaces | |
56 // frame_id. | |
57 bool IsFirstNavigationAfterSwap() const; | |
58 void OnFirstNavigationAfterSwap(int main_frame_id); | |
59 | |
60 // Frame tree manipulation routines. | 55 // Frame tree manipulation routines. |
61 void AddFrame(int render_frame_host_id, int64 parent_frame_id, | 56 void AddFrame(RenderViewHostImpl* parent_render_view_host, |
62 int64 frame_id, const std::string& frame_name); | 57 int render_frame_host_id, |
63 void RemoveFrame(int64 parent_frame_id, int64 frame_id); | 58 int64 parent_frame_id, |
64 void SetFrameUrl(int64 frame_id, const GURL& url); | 59 int64 frame_id, |
65 | 60 const std::string& frame_name); |
66 // Resets the FrameTree and changes RenderFrameHost for the main frame. | 61 void RemoveFrame(int64 parent_frame_tree_node_id, |
67 // This destroys most of the frame tree but retains the root node so that | 62 int64 frame_tree_node_id); |
68 // navigation state may be kept on it between process swaps. Used to | 63 void SetFrameUrl(int64 frame_tree_node_id, const GURL& url); |
69 // support bookkeeping for top-level navigations. | |
70 // | |
71 // If |main_frame| is NULL, reset tree to initially constructed state. | |
72 // | |
73 // TODO(ajwong): This function should not be given a |main_frame|. This is | |
74 // required currently because the RenderViewHost owns its main frame. When | |
75 // that relation is fixed, the FrameTree should be responsible for | |
76 // created/destroying the main frame on the swap. | |
77 void SwapMainFrame(RenderFrameHostImpl* main_frame); | |
78 | 64 |
79 // Convenience accessor for the main frame's RenderFrameHostImpl. | 65 // Convenience accessor for the main frame's RenderFrameHostImpl. |
80 RenderFrameHostImpl* GetMainFrame() const; | 66 RenderFrameHostImpl* GetMainFrame() const; |
81 | 67 |
82 // Allows a client to listen for frame removal. | 68 // Allows a client to listen for frame removal. |
83 void SetFrameRemoveListener( | 69 void SetFrameRemoveListener( |
84 const base::Callback<void(RenderViewHostImpl*, int64)>& on_frame_removed); | 70 const base::Callback<void(RenderViewHostImpl*, int64)>& on_frame_removed); |
85 | 71 |
86 FrameTreeNode* GetRootForTesting() { return root_.get(); } | 72 // Get the RenderViewHost needed for a new RenderFrameHost in the given |
| 73 // |site_instance|. Creates it if necessary and increments the refcount. |
| 74 // The RenderViewHost will have its Shutdown method called when all of the |
| 75 // RenderFrameHosts using it are deleted. |
| 76 RenderViewHostImpl* GetRenderViewHostForNewFrame(SiteInstance* site_instance, |
| 77 int routing_id, |
| 78 int main_frame_routing_id, |
| 79 bool swapped_out, |
| 80 bool hidden); |
| 81 |
| 82 FrameTreeNode* root() const { return root_.get(); } |
87 | 83 |
88 private: | 84 private: |
| 85 typedef base::hash_map<int, RenderViewHostImpl*> RenderViewHostMap; |
| 86 |
| 87 // The next available FrameTreeNode ID. |
| 88 static int64 next_frame_tree_node_id_; |
| 89 |
89 scoped_ptr<FrameTreeNode> CreateNode(int64 frame_id, | 90 scoped_ptr<FrameTreeNode> CreateNode(int64 frame_id, |
90 const std::string& frame_name, | 91 const std::string& frame_name, |
91 int render_frame_host_id, | 92 int render_frame_host_id, |
92 RenderProcessHost* render_process_host); | 93 RenderViewHostImpl* render_view_host); |
| 94 |
| 95 // Generate a browser-wide unique ID for a new FrameTreeNode. |
| 96 int64 GetNextFrameTreeNodeID(); |
| 97 |
| 98 // These delegates are installed into all the RenderViewHosts and |
| 99 // RenderFrameHosts that we create. |
| 100 RenderViewHostDelegate* render_view_delegate_; |
| 101 RenderWidgetHostDelegate* render_widget_delegate_; |
| 102 RenderViewHostManager::Delegate* manager_delegate_; |
93 | 103 |
94 scoped_ptr<FrameTreeNode> root_; | 104 scoped_ptr<FrameTreeNode> root_; |
95 | 105 |
| 106 // Map of SiteInstance ID to RenderViewHost, which we can consult when |
| 107 // creating a new RenderFrameHost in this tree. RenderViewHosts are kept |
| 108 // alive as long as they have at least one RenderFrameHost using them. |
| 109 RenderViewHostMap render_view_host_map_; |
| 110 |
| 111 // Because of the complex shutdown path for RenderViewHosts, we also maintain |
| 112 // the refcount for them in this class. This is a map from RenderViewHost |
| 113 // routing ID to refcount. |
| 114 base::hash_map<int, int> rvh_refcounts_; |
| 115 |
96 base::Callback<void(RenderViewHostImpl*, int64)> on_frame_removed_; | 116 base::Callback<void(RenderViewHostImpl*, int64)> on_frame_removed_; |
97 | 117 |
98 DISALLOW_COPY_AND_ASSIGN(FrameTree); | 118 DISALLOW_COPY_AND_ASSIGN(FrameTree); |
99 }; | 119 }; |
100 | 120 |
101 } // namespace content | 121 } // namespace content |
102 | 122 |
103 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_H_ | 123 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_H_ |
OLD | NEW |