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

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

Issue 23841002: 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: unittests. 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?
Charlie Reis 2013/09/27 19:19:21 I'm inclined to think we should kill the renderer,
awong 2013/09/27 20:50:09 Let's do it in a followup CL. I'd rather not risk
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 FrameTreeNode* parent = FindByID(parent_frame_id);
83 // TODO(ajwong): Should the renderer be killed here? Would there be a race on
84 // shutdown that might make this case possible?
85 if (!parent)
86 return;
87
88 parent->RemoveChild(frame_id);
89 if (!on_frame_removed_.is_null())
90 on_frame_removed_.Run(frame_id);
91 }
92
93 void FrameTree::SetFrameUrl(int64 frame_id, const GURL& url) {
94 FrameTreeNode* node = FindByID(frame_id);
95 // TODO(ajwong): Should the renderer be killed here? Would there be a race on
96 // shutdown that might make this case possible?
97 if (!node)
98 return;
99
100 if (node)
101 node->set_current_url(url);
102 }
103
104 void FrameTree::SwapMainFrame(RenderFrameHostImpl* render_frame_host) {
105 return root_->ResetForMainFrame(render_frame_host);
106 }
107
108 RenderFrameHostImpl* FrameTree::GetMainFrame() const {
109 return root_->render_frame_host();
110 }
111
112 void FrameTree::SetFrameRemoveListener(
113 const base::Callback<void(int64)>& on_frame_removed) {
114 on_frame_removed_ = on_frame_removed;
115 }
116
117 scoped_ptr<FrameTreeNode> FrameTree::CreateNode(
118 int64 frame_id, const std::string& frame_name, int render_frame_host_id,
119 RenderProcessHost* render_process_host) {
120 scoped_ptr<RenderFrameHostImpl> render_frame_host(
121 new RenderFrameHostImpl(render_process_host, this, render_frame_host_id,
122 false));
123
124 return make_scoped_ptr(new FrameTreeNode(frame_id, frame_name,
125 render_frame_host.Pass()));
126 }
127
128 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698