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_NODE_H_ | 5 #ifndef CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ |
6 #define CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ | 6 #define CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
14 #include "content/browser/frame_host/render_frame_host_impl.h" | 14 #include "content/browser/frame_host/render_frame_host_impl.h" |
15 #include "content/browser/frame_host/render_frame_host_manager.h" | 15 #include "content/browser/frame_host/render_frame_host_manager.h" |
16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 class FrameTree; | |
22 class Navigator; | 21 class Navigator; |
23 class RenderFrameHostImpl; | 22 class RenderFrameHostImpl; |
24 | 23 |
25 // When a page contains iframes, its renderer process maintains a tree structure | 24 // When a page contains iframes, its renderer process maintains a tree structure |
26 // of those frames. We are mirroring this tree in the browser process. This | 25 // of those frames. We are mirroring this tree in the browser process. This |
27 // class represents a node in this tree and is a wrapper for all objects that | 26 // class represents a node in this tree and is a wrapper for all objects that |
28 // are frame-specific (as opposed to page-specific). | 27 // are frame-specific (as opposed to page-specific). |
29 class CONTENT_EXPORT FrameTreeNode { | 28 class CONTENT_EXPORT FrameTreeNode { |
30 public: | 29 public: |
31 static const int64 kInvalidFrameId; | 30 static const int64 kInvalidFrameId; |
32 | 31 |
33 FrameTreeNode(FrameTree* frame_tree, | 32 FrameTreeNode(Navigator* navigator, |
34 Navigator* navigator, | |
35 RenderFrameHostDelegate* render_frame_delegate, | 33 RenderFrameHostDelegate* render_frame_delegate, |
36 RenderViewHostDelegate* render_view_delegate, | 34 RenderViewHostDelegate* render_view_delegate, |
37 RenderWidgetHostDelegate* render_widget_delegate, | 35 RenderWidgetHostDelegate* render_widget_delegate, |
38 RenderFrameHostManager::Delegate* manager_delegate, | 36 RenderFrameHostManager::Delegate* manager_delegate, |
39 int64 frame_id, | 37 int64 frame_id, |
40 const std::string& name); | 38 const std::string& name); |
41 | 39 |
42 ~FrameTreeNode(); | 40 ~FrameTreeNode(); |
43 | 41 |
44 bool IsMainFrame() const; | 42 void AddChild(scoped_ptr<FrameTreeNode> child); |
45 | |
46 void AddChild(scoped_ptr<FrameTreeNode> child, int frame_routing_id); | |
47 void RemoveChild(FrameTreeNode* child); | 43 void RemoveChild(FrameTreeNode* child); |
48 | 44 |
49 // Clears process specific-state after a main frame process swap. | 45 // TODO(nasko): This method should be removed once RenderFrameHosts are |
50 // TODO(creis): Look into how we can remove the need for this method. | 46 // created by RenderFrameHostManager. |
51 void ResetForMainFrameSwap(); | 47 void set_render_frame_host( |
| 48 RenderFrameHostImpl* render_frame_host, |
| 49 bool owns_render_frame_host) { |
| 50 render_frame_host_ = render_frame_host; |
| 51 owns_render_frame_host_ = owns_render_frame_host; |
| 52 } |
52 | 53 |
53 FrameTree* frame_tree() const { | 54 // Transitional API allowing the RenderFrameHost of a FrameTreeNode |
54 return frame_tree_; | 55 // representing the main frame to be provided by someone else. After |
55 } | 56 // this is called, the FrameTreeNode no longer owns its RenderFrameHost. |
| 57 // |
| 58 // This should only be used for the main frame (aka root) in a frame tree. |
| 59 // |
| 60 // TODO(ajwong): Remove this method once the main frame RenderFrameHostImpl is |
| 61 // no longer owned by the RenderViewHostImpl. |
| 62 void ResetForMainFrame(RenderFrameHostImpl* new_render_frame_host); |
56 | 63 |
57 Navigator* navigator() { | 64 Navigator* navigator() { |
58 return navigator_.get(); | 65 return navigator_.get(); |
59 } | 66 } |
60 | 67 |
61 RenderFrameHostManager* render_manager() { | 68 RenderFrameHostManager* render_manager() { |
62 return &render_manager_; | 69 return &render_manager_; |
63 } | 70 } |
64 | 71 |
65 int64 frame_tree_node_id() const { | 72 int64 frame_tree_node_id() const { |
(...skipping 23 matching lines...) Expand all Loading... |
89 } | 96 } |
90 | 97 |
91 const GURL& current_url() const { | 98 const GURL& current_url() const { |
92 return current_url_; | 99 return current_url_; |
93 } | 100 } |
94 | 101 |
95 void set_current_url(const GURL& url) { | 102 void set_current_url(const GURL& url) { |
96 current_url_ = url; | 103 current_url_ = url; |
97 } | 104 } |
98 | 105 |
99 RenderFrameHostImpl* current_frame_host() const { | 106 RenderFrameHostImpl* render_frame_host() const { |
100 return render_manager_.current_frame_host(); | 107 return render_frame_host_; |
101 } | 108 } |
102 | 109 |
103 private: | 110 private: |
104 // The next available browser-global FrameTreeNode ID. | 111 // The next available browser-global FrameTreeNode ID. |
105 static int64 next_frame_tree_node_id_; | 112 static int64 next_frame_tree_node_id_; |
106 | 113 |
107 // The FrameTree that owns us. | |
108 FrameTree* frame_tree_; // not owned. | |
109 | |
110 // The Navigator object responsible for managing navigations at this node | 114 // The Navigator object responsible for managing navigations at this node |
111 // of the frame tree. | 115 // of the frame tree. |
112 scoped_refptr<Navigator> navigator_; | 116 scoped_refptr<Navigator> navigator_; |
113 | 117 |
114 // Manages creation and swapping of RenderFrameHosts for this frame. This | 118 // Manages creation and swapping of RenderViewHosts for this frame. This must |
115 // must be declared before |children_| so that it gets deleted after them. | 119 // be declared before |children_| so that it gets deleted after them. That's |
116 // That's currently necessary so that RenderFrameHostImpl's destructor can | 120 // currently necessary so that RenderFrameHostImpl's destructor can call |
117 // call GetProcess. | 121 // GetProcess. |
| 122 // TODO(creis): This will eliminate the need for |render_frame_host_| below. |
118 RenderFrameHostManager render_manager_; | 123 RenderFrameHostManager render_manager_; |
119 | 124 |
120 // A browser-global identifier for the frame in the page, which stays stable | 125 // A browser-global identifier for the frame in the page, which stays stable |
121 // even if the frame does a cross-process navigation. | 126 // even if the frame does a cross-process navigation. |
122 const int64 frame_tree_node_id_; | 127 const int64 frame_tree_node_id_; |
123 | 128 |
124 // The renderer-specific identifier for the frame in the page. | 129 // The renderer-specific identifier for the frame in the page. |
125 // TODO(creis): Remove this in favor of the RenderFrameHost's routing ID once | 130 // TODO(creis): Remove this in favor of the RenderFrameHost's routing ID once |
126 // we create FrameTreeNodes for all frames (even without a flag), since this | 131 // we create FrameTreeNodes for all frames (even without a flag), since this |
127 // value can change after cross-process navigations. | 132 // value can change after cross-process navigations. |
128 int64 frame_id_; | 133 int64 frame_id_; |
129 | 134 |
130 // The assigned name of the frame. This name can be empty, unlike the unique | 135 // The assigned name of the frame. This name can be empty, unlike the unique |
131 // name generated internally in the DOM tree. | 136 // name generated internally in the DOM tree. |
132 std::string frame_name_; | 137 std::string frame_name_; |
133 | 138 |
134 // The immediate children of this specific frame. | 139 // The immediate children of this specific frame. |
135 ScopedVector<FrameTreeNode> children_; | 140 ScopedVector<FrameTreeNode> children_; |
136 | 141 |
| 142 // When ResetForMainFrame() is called, this is set to false and the |
| 143 // |render_frame_host_| below is not deleted on destruction. |
| 144 // |
| 145 // For the mainframe, the FrameTree does not own the |render_frame_host_|. |
| 146 // This is a transitional wart because RenderFrameHostManager does not yet |
| 147 // have the bookkeeping logic to handle creating a pending RenderFrameHost |
| 148 // along with a pending RenderViewHost. Thus, for the main frame, the |
| 149 // RenderViewHost currently retains ownership and the FrameTreeNode should |
| 150 // not delete it on destruction. |
| 151 bool owns_render_frame_host_; |
| 152 |
| 153 // The active RenderFrameHost for this frame. The FrameTreeNode does not |
| 154 // always own this pointer. See comments above |owns_render_frame_host_|. |
| 155 // TODO(ajwong): Replace with RenderFrameHostManager. |
| 156 RenderFrameHostImpl* render_frame_host_; |
| 157 |
137 // Track the current frame's last committed URL, so we can estimate the | 158 // Track the current frame's last committed URL, so we can estimate the |
138 // process impact of out-of-process iframes. | 159 // process impact of out-of-process iframes. |
139 // TODO(creis): Remove this when we can store subframe URLs in the | 160 // TODO(creis): Remove this when we can store subframe URLs in the |
140 // NavigationController. | 161 // NavigationController. |
141 GURL current_url_; | 162 GURL current_url_; |
142 | 163 |
143 DISALLOW_COPY_AND_ASSIGN(FrameTreeNode); | 164 DISALLOW_COPY_AND_ASSIGN(FrameTreeNode); |
144 }; | 165 }; |
145 | 166 |
146 } // namespace content | 167 } // namespace content |
147 | 168 |
148 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ | 169 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ |
OLD | NEW |