Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1847)

Side by Side Diff: content/browser/frame_host/frame_tree.cc

Issue 63523004: Give FrameTreeNodes a browser-global ID for use in navigation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update parameter name Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/frame_host/frame_tree.h ('k') | content/browser/frame_host/frame_tree_node.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "content/browser/frame_host/frame_tree.h" 5 #include "content/browser/frame_host/frame_tree.h"
6 6
7 #include <queue> 7 #include <queue>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "content/browser/frame_host/frame_tree_node.h" 11 #include "content/browser/frame_host/frame_tree_node.h"
12 #include "content/browser/frame_host/render_frame_host_impl.h" 12 #include "content/browser/frame_host/render_frame_host_impl.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 namespace { 16 namespace {
17 // Used with FrameTree::ForEach() to search for the FrameTreeNode 17 // Used with FrameTree::ForEach() to search for the FrameTreeNode
18 // corresponding to |frame_id|. 18 // corresponding to |frame_tree_node_id|.
19 bool FrameTreeNodeForId(int64 frame_id, FrameTreeNode** out_node, 19 bool FrameTreeNodeForId(int64 frame_tree_node_id,
20 FrameTreeNode** out_node,
20 FrameTreeNode* node) { 21 FrameTreeNode* node) {
22 if (node->frame_tree_node_id() == frame_tree_node_id) {
23 *out_node = node;
24 // Terminate iteration once the node has been found.
25 return false;
26 }
27 return true;
28 }
29
30 // TODO(creis): Remove this version along with FrameTreeNode::frame_id().
31 bool FrameTreeNodeForFrameId(int64 frame_id,
32 FrameTreeNode** out_node,
33 FrameTreeNode* node) {
21 if (node->frame_id() == frame_id) { 34 if (node->frame_id() == frame_id) {
22 *out_node = node; 35 *out_node = node;
23 // Terminate iteration once the node has been found. 36 // Terminate iteration once the node has been found.
24 return false; 37 return false;
25 } 38 }
26 return true; 39 return true;
27 } 40 }
28 41
29 } // namespace 42 } // namespace
30 43
31 FrameTree::FrameTree() 44 FrameTree::FrameTree()
32 : root_(new FrameTreeNode(FrameTreeNode::kInvalidFrameId, std::string(), 45 : root_(new FrameTreeNode(FrameTreeNode::kInvalidFrameId, std::string(),
33 scoped_ptr<RenderFrameHostImpl>())) { 46 scoped_ptr<RenderFrameHostImpl>())) {
34 } 47 }
35 48
36 FrameTree::~FrameTree() { 49 FrameTree::~FrameTree() {
37 } 50 }
38 51
39 FrameTreeNode* FrameTree::FindByID(int64 frame_id) { 52 FrameTreeNode* FrameTree::FindByID(int64 frame_tree_node_id) {
40 FrameTreeNode* node = NULL; 53 FrameTreeNode* node = NULL;
41 ForEach(base::Bind(&FrameTreeNodeForId, frame_id, &node)); 54 ForEach(base::Bind(&FrameTreeNodeForId, frame_tree_node_id, &node));
42 return node; 55 return node;
43 } 56 }
44 57
45 void FrameTree::ForEach( 58 void FrameTree::ForEach(
46 const base::Callback<bool(FrameTreeNode*)>& on_node) const { 59 const base::Callback<bool(FrameTreeNode*)>& on_node) const {
47 std::queue<FrameTreeNode*> queue; 60 std::queue<FrameTreeNode*> queue;
48 queue.push(root_.get()); 61 queue.push(root_.get());
49 62
50 while (!queue.empty()) { 63 while (!queue.empty()) {
51 FrameTreeNode* node = queue.front(); 64 FrameTreeNode* node = queue.front();
52 queue.pop(); 65 queue.pop();
53 if (!on_node.Run(node)) 66 if (!on_node.Run(node))
54 break; 67 break;
55 68
56 for (size_t i = 0; i < node->child_count(); ++i) 69 for (size_t i = 0; i < node->child_count(); ++i)
57 queue.push(node->child_at(i)); 70 queue.push(node->child_at(i));
58 } 71 }
59 } 72 }
60 73
61 bool FrameTree::IsFirstNavigationAfterSwap() const { 74 bool FrameTree::IsFirstNavigationAfterSwap() const {
62 return root_->frame_id() == FrameTreeNode::kInvalidFrameId; 75 return root_->frame_id() == FrameTreeNode::kInvalidFrameId;
63 } 76 }
64 77
65 void FrameTree::OnFirstNavigationAfterSwap(int main_frame_id) { 78 void FrameTree::OnFirstNavigationAfterSwap(int main_frame_id) {
66 root_->set_frame_id(main_frame_id); 79 root_->set_frame_id(main_frame_id);
67 } 80 }
68 81
69 void FrameTree::AddFrame(int render_frame_host_id, int64 parent_frame_id, 82 void FrameTree::AddFrame(int render_frame_host_id,
70 int64 frame_id, const std::string& frame_name) { 83 int64 parent_frame_id,
71 FrameTreeNode* parent = FindByID(parent_frame_id); 84 int64 frame_id,
85 const std::string& frame_name) {
86 FrameTreeNode* parent = FindByFrameID(parent_frame_id);
72 // TODO(ajwong): Should the renderer be killed here? Would there be a race on 87 // TODO(ajwong): Should the renderer be killed here? Would there be a race on
73 // shutdown that might make this case possible? 88 // shutdown that might make this case possible?
74 if (!parent) 89 if (!parent)
75 return; 90 return;
76 91
77 parent->AddChild(CreateNode(frame_id, frame_name, render_frame_host_id, 92 parent->AddChild(CreateNode(frame_id, frame_name, render_frame_host_id,
78 parent->render_frame_host()->GetProcess())); 93 parent->render_frame_host()->GetProcess()));
79 } 94 }
80 95
81 void FrameTree::RemoveFrame(int64 parent_frame_id, int64 frame_id) { 96 void FrameTree::RemoveFrame(int64 parent_frame_id, int64 frame_id) {
82 // If switches::kSitePerProcess is not specified, then the FrameTree only 97 // If switches::kSitePerProcess is not specified, then the FrameTree only
83 // contains a node for the root element. However, even in this case 98 // contains a node for the root element. However, even in this case
84 // frame detachments need to be broadcast outwards. 99 // frame detachments need to be broadcast outwards.
85 // 100 //
86 // TODO(ajwong): Move this below the |parent| check after the FrameTree is 101 // TODO(ajwong): Move this below the |parent| check after the FrameTree is
87 // guaranteed to be correctly populated even without the 102 // guaranteed to be correctly populated even without the
88 // switches::kSitePerProcess flag. 103 // switches::kSitePerProcess flag.
89 FrameTreeNode* parent = FindByID(parent_frame_id); 104 FrameTreeNode* parent = FindByFrameID(parent_frame_id);
105 FrameTreeNode* child = FindByFrameID(frame_id);
90 if (!on_frame_removed_.is_null()) { 106 if (!on_frame_removed_.is_null()) {
91 on_frame_removed_.Run( 107 on_frame_removed_.Run(
92 root_->render_frame_host()->render_view_host(), frame_id); 108 root_->render_frame_host()->render_view_host(), frame_id);
93 } 109 }
94 110
95 // TODO(ajwong): Should the renderer be killed here? Would there be a race on 111 // TODO(ajwong): Should the renderer be killed here? Would there be a race on
96 // shutdown that might make this case possible? 112 // shutdown that might make this case possible?
97 if (!parent) 113 if (!parent || !child)
98 return; 114 return;
99 115
100 parent->RemoveChild(frame_id); 116 parent->RemoveChild(child);
101 } 117 }
102 118
103 void FrameTree::SetFrameUrl(int64 frame_id, const GURL& url) { 119 void FrameTree::SetFrameUrl(int64 frame_id, const GURL& url) {
104 FrameTreeNode* node = FindByID(frame_id); 120 FrameTreeNode* node = FindByFrameID(frame_id);
105 // TODO(ajwong): Should the renderer be killed here? Would there be a race on 121 // TODO(ajwong): Should the renderer be killed here? Would there be a race on
106 // shutdown that might make this case possible? 122 // shutdown that might make this case possible?
107 if (!node) 123 if (!node)
108 return; 124 return;
109 125
110 if (node) 126 if (node)
111 node->set_current_url(url); 127 node->set_current_url(url);
112 } 128 }
113 129
114 void FrameTree::SwapMainFrame(RenderFrameHostImpl* render_frame_host) { 130 void FrameTree::SwapMainFrame(RenderFrameHostImpl* render_frame_host) {
115 return root_->ResetForMainFrame(render_frame_host); 131 return root_->ResetForMainFrame(render_frame_host);
116 } 132 }
117 133
118 RenderFrameHostImpl* FrameTree::GetMainFrame() const { 134 RenderFrameHostImpl* FrameTree::GetMainFrame() const {
119 return root_->render_frame_host(); 135 return root_->render_frame_host();
120 } 136 }
121 137
122 void FrameTree::SetFrameRemoveListener( 138 void FrameTree::SetFrameRemoveListener(
123 const base::Callback<void(RenderViewHostImpl*, int64)>& on_frame_removed) { 139 const base::Callback<void(RenderViewHostImpl*, int64)>& on_frame_removed) {
124 on_frame_removed_ = on_frame_removed; 140 on_frame_removed_ = on_frame_removed;
125 } 141 }
126 142
143 FrameTreeNode* FrameTree::FindByFrameID(int64 frame_id) {
144 FrameTreeNode* node = NULL;
145 ForEach(base::Bind(&FrameTreeNodeForFrameId, frame_id, &node));
146 return node;
147 }
148
127 scoped_ptr<FrameTreeNode> FrameTree::CreateNode( 149 scoped_ptr<FrameTreeNode> FrameTree::CreateNode(
128 int64 frame_id, const std::string& frame_name, int render_frame_host_id, 150 int64 frame_id,
151 const std::string& frame_name,
152 int render_frame_host_id,
129 RenderProcessHost* render_process_host) { 153 RenderProcessHost* render_process_host) {
130 scoped_ptr<RenderFrameHostImpl> render_frame_host( 154 scoped_ptr<RenderFrameHostImpl> render_frame_host(
131 new RenderFrameHostImpl(root_->render_frame_host()->render_view_host(), 155 new RenderFrameHostImpl(root_->render_frame_host()->render_view_host(),
132 this, render_frame_host_id, false)); 156 this, render_frame_host_id, false));
133 157
134 return make_scoped_ptr(new FrameTreeNode(frame_id, frame_name, 158 return make_scoped_ptr(new FrameTreeNode(frame_id, frame_name,
135 render_frame_host.Pass())); 159 render_frame_host.Pass()));
136 } 160 }
137 161
138 } // namespace content 162 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/frame_tree.h ('k') | content/browser/frame_host/frame_tree_node.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698