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

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

Issue 49823002: Move navigation and frame tree classes to a new frame_host/ directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing gyp and adding TODO. 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
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 if (!on_frame_removed_.is_null()) {
91 on_frame_removed_.Run(
92 root_->render_frame_host()->render_view_host(), frame_id);
93 }
94
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 (!parent)
98 return;
99
100 parent->RemoveChild(frame_id);
101 }
102
103 void FrameTree::SetFrameUrl(int64 frame_id, const GURL& url) {
104 FrameTreeNode* node = FindByID(frame_id);
105 // TODO(ajwong): Should the renderer be killed here? Would there be a race on
106 // shutdown that might make this case possible?
107 if (!node)
108 return;
109
110 if (node)
111 node->set_current_url(url);
112 }
113
114 void FrameTree::SwapMainFrame(RenderFrameHostImpl* render_frame_host) {
115 return root_->ResetForMainFrame(render_frame_host);
116 }
117
118 RenderFrameHostImpl* FrameTree::GetMainFrame() const {
119 return root_->render_frame_host();
120 }
121
122 void FrameTree::SetFrameRemoveListener(
123 const base::Callback<void(RenderViewHostImpl*, int64)>& on_frame_removed) {
124 on_frame_removed_ = on_frame_removed;
125 }
126
127 scoped_ptr<FrameTreeNode> FrameTree::CreateNode(
128 int64 frame_id, const std::string& frame_name, int render_frame_host_id,
129 RenderProcessHost* render_process_host) {
130 scoped_ptr<RenderFrameHostImpl> render_frame_host(
131 new RenderFrameHostImpl(root_->render_frame_host()->render_view_host(),
132 this, render_frame_host_id, false));
133
134 return make_scoped_ptr(new FrameTreeNode(frame_id, frame_name,
135 render_frame_host.Pass()));
136 }
137
138 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/frame_tree.h ('k') | content/browser/renderer_host/frame_tree_node.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698