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

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

Issue 25503004: Create a new RenderFrameHost per child frame when --site-per-process is enabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move global map insert/erase behind the flag. Created 7 years, 2 months 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/renderer_host/frame_tree.h"
6
7 #include <queue>
8
9 #include "base/bind.h"
10 #include "base/callback.h"
11 #include "content/browser/renderer_host/frame_tree_node.h"
12 #include "content/browser/renderer_host/render_frame_host_impl.h"
13
14 namespace content {
15
16 namespace {
17 // Used with FrameTree::ForEach() to search for the FrameTreeNode
18 // corresponding to |frame_id|.
19 bool FrameTreeNodeForId(int64 frame_id, FrameTreeNode** out_node,
20 FrameTreeNode* node) {
21 if (node->frame_id() == frame_id) {
22 *out_node = node;
23 // Terminate iteration once the node has been found.
24 return false;
25 }
26 return true;
27 }
28
29 } // namespace
30
31 FrameTree::FrameTree()
32 : root_(new FrameTreeNode(FrameTreeNode::kInvalidFrameId, std::string(),
33 scoped_ptr<RenderFrameHostImpl>())) {
34 }
35
36 FrameTree::~FrameTree() {
37 }
38
39 FrameTreeNode* FrameTree::FindByID(int64 frame_id) {
40 FrameTreeNode* node = NULL;
41 ForEach(base::Bind(&FrameTreeNodeForId, frame_id, &node));
42 return node;
43 }
44
45 void FrameTree::ForEach(
46 const base::Callback<bool(FrameTreeNode*)>& on_node) const {
47 std::queue<FrameTreeNode*> queue;
48 queue.push(root_.get());
49
50 while (!queue.empty()) {
51 FrameTreeNode* node = queue.front();
52 queue.pop();
53 if (!on_node.Run(node))
54 break;
55
56 for (size_t i = 0; i < node->child_count(); ++i)
57 queue.push(node->child_at(i));
58 }
59 }
60
61 bool FrameTree::IsFirstNavigationAfterSwap() const {
62 return root_->frame_id() == FrameTreeNode::kInvalidFrameId;
63 }
64
65 void FrameTree::OnFirstNavigationAfterSwap(int main_frame_id) {
66 root_->set_frame_id(main_frame_id);
67 }
68
69 void FrameTree::AddFrame(int render_frame_host_id, int64 parent_frame_id,
70 int64 frame_id, const std::string& frame_name) {
71 FrameTreeNode* parent = FindByID(parent_frame_id);
72 // TODO(ajwong): Should the renderer be killed here? Would there be a race on
73 // shutdown that might make this case possible?
74 if (!parent)
75 return;
76
77 parent->AddChild(CreateNode(frame_id, frame_name, render_frame_host_id,
78 parent->render_frame_host()->GetProcess()));
79 }
80
81 void FrameTree::RemoveFrame(int64 parent_frame_id, int64 frame_id) {
82 // If switches::kSitePerProcess is not specified, then the FrameTree only
83 // contains a node for the root element. However, even in this case
84 // frame detachments need to be broadcast outwards.
85 //
86 // TODO(ajwong): Move this below the |parent| check after the FrameTree is
87 // guaranteed to be correctly populated even without the
88 // switches::kSitePerProcess flag.
89 FrameTreeNode* parent = FindByID(parent_frame_id);
90 FrameTreeNode* frame = FindByID(frame_id);
91 if (!on_frame_removed_.is_null()) {
92 // TODO(nasko): Remove this hack, when observers move away from using
Charlie Reis 2013/10/02 22:25:19 nit: Remove comma.
nasko 2013/10/02 23:02:06 Done.
93 // RenderViewHost as parameter.
94 RenderViewHost* rvh =
95 frame ? frame->render_frame_host()->render_view_host() :
96 root_->render_frame_host()->render_view_host();
Charlie Reis 2013/10/02 22:25:19 Seems like all the frames would have the same Rend
nasko 2013/10/02 23:02:06 As discussed, let's use the root node's RVH for no
97 on_frame_removed_.Run(rvh, frame_id);
98 }
99
100 // TODO(ajwong): Should the renderer be killed here? Would there be a race on
101 // shutdown that might make this case possible?
102 if (!parent)
103 return;
104
105 parent->RemoveChild(frame_id);
106 }
107
108 void FrameTree::SetFrameUrl(int64 frame_id, const GURL& url) {
109 FrameTreeNode* node = FindByID(frame_id);
110 // TODO(ajwong): Should the renderer be killed here? Would there be a race on
111 // shutdown that might make this case possible?
112 if (!node)
113 return;
114
115 if (node)
116 node->set_current_url(url);
117 }
118
119 void FrameTree::SwapMainFrame(RenderFrameHostImpl* render_frame_host) {
120 return root_->ResetForMainFrame(render_frame_host);
121 }
122
123 RenderFrameHostImpl* FrameTree::GetMainFrame() const {
124 return root_->render_frame_host();
125 }
126
127 void FrameTree::SetFrameRemoveListener(
128 const base::Callback<void(RenderViewHost*, int64)>& on_frame_removed) {
129 on_frame_removed_ = on_frame_removed;
130 }
131
132 scoped_ptr<FrameTreeNode> FrameTree::CreateNode(
133 int64 frame_id, const std::string& frame_name, int render_frame_host_id,
134 RenderProcessHost* render_process_host) {
135 scoped_ptr<RenderFrameHostImpl> render_frame_host(
136 new RenderFrameHostImpl(root_->render_frame_host()->render_view_host(),
Charlie Reis 2013/10/02 22:25:19 Just trying to make sure I understand how this wor
nasko 2013/10/02 23:02:06 Yes. We need to load a page in the main frame, bef
137 this, render_frame_host_id, false));
138
139 return make_scoped_ptr(new FrameTreeNode(frame_id, frame_name,
140 render_frame_host.Pass()));
141 }
142
143 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698