frame_tree_node.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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#ifndef CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ 6#define CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ 7 8#include <string> 9 10#include "base/basictypes.h" 11#include "base/memory/ref_counted.h" 12#include "base/memory/scoped_ptr.h" 13#include "base/memory/scoped_vector.h" 14#include "content/browser/frame_host/render_frame_host_impl.h" 15#include "content/browser/frame_host/render_frame_host_manager.h" 16#include "content/common/content_export.h" 17#include "url/gurl.h" 18 19namespace content { 20 21class FrameTree; 22class Navigator; 23class RenderFrameHostImpl; 24 25// 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 27// class represents a node in this tree and is a wrapper for all objects that 28// are frame-specific (as opposed to page-specific). 29class CONTENT_EXPORT FrameTreeNode { 30 public: 31 static const int64 kInvalidFrameId; 32 33 FrameTreeNode(FrameTree* frame_tree, 34 Navigator* navigator, 35 RenderFrameHostDelegate* render_frame_delegate, 36 RenderViewHostDelegate* render_view_delegate, 37 RenderWidgetHostDelegate* render_widget_delegate, 38 RenderFrameHostManager::Delegate* manager_delegate, 39 int64 frame_id, 40 const std::string& name); 41 42 ~FrameTreeNode(); 43 44 bool IsMainFrame() const; 45 46 void AddChild(scoped_ptr<FrameTreeNode> child, int frame_routing_id); 47 void RemoveChild(FrameTreeNode* child); 48 49 // Clears process specific-state in this node to prepare for a new process. 50 void ResetForNewProcess(); 51 52 FrameTree* frame_tree() const { 53 return frame_tree_; 54 } 55 56 Navigator* navigator() { 57 return navigator_.get(); 58 } 59 60 RenderFrameHostManager* render_manager() { 61 return &render_manager_; 62 } 63 64 int64 frame_tree_node_id() const { 65 return frame_tree_node_id_; 66 } 67 68 // DO NOT USE. Only used by FrameTree until we replace renderer-specific 69 // frame IDs with RenderFrameHost routing IDs. 70 void set_frame_id(int64 frame_id) { 71 DCHECK_EQ(frame_id_, kInvalidFrameId); 72 frame_id_ = frame_id; 73 } 74 int64 frame_id() const { 75 return frame_id_; 76 } 77 78 const std::string& frame_name() const { 79 return frame_name_; 80 } 81 82 size_t child_count() const { 83 return children_.size(); 84 } 85 86 FrameTreeNode* parent() const { return parent_; } 87 88 FrameTreeNode* child_at(size_t index) const { 89 return children_[index]; 90 } 91 92 const GURL& current_url() const { 93 return current_url_; 94 } 95 96 void set_current_url(const GURL& url) { 97 current_url_ = url; 98 } 99 100 RenderFrameHostImpl* current_frame_host() const { 101 return render_manager_.current_frame_host(); 102 } 103 104 private: 105 void set_parent(FrameTreeNode* parent) { parent_ = parent; } 106 107 // The next available browser-global FrameTreeNode ID. 108 static int64 next_frame_tree_node_id_; 109 110 // The FrameTree that owns us. 111 FrameTree* frame_tree_; // not owned. 112 113 // The Navigator object responsible for managing navigations at this node 114 // of the frame tree. 115 scoped_refptr<Navigator> navigator_; 116 117 // Manages creation and swapping of RenderFrameHosts for this frame. This 118 // must be declared before |children_| so that it gets deleted after them. 119 // That's currently necessary so that RenderFrameHostImpl's destructor can 120 // call GetProcess. 121 RenderFrameHostManager render_manager_; 122 123 // A browser-global identifier for the frame in the page, which stays stable 124 // even if the frame does a cross-process navigation. 125 const int64 frame_tree_node_id_; 126 127 // The renderer-specific identifier for the frame in the page. 128 // TODO(creis): Remove this in favor of the RenderFrameHost's routing ID once 129 // we create FrameTreeNodes for all frames (even without a flag), since this 130 // value can change after cross-process navigations. 131 int64 frame_id_; 132 133 // The assigned name of the frame. This name can be empty, unlike the unique 134 // name generated internally in the DOM tree. 135 std::string frame_name_; 136 137 // The parent node of this frame. NULL if this node is the root or if it has 138 // not yet been attached to the frame tree. 139 FrameTreeNode* parent_; 140 141 // The immediate children of this specific frame. 142 ScopedVector<FrameTreeNode> children_; 143 144 // Track the current frame's last committed URL, so we can estimate the 145 // process impact of out-of-process iframes. 146 // TODO(creis): Remove this when we can store subframe URLs in the 147 // NavigationController. 148 GURL current_url_; 149 150 DISALLOW_COPY_AND_ASSIGN(FrameTreeNode); 151}; 152 153} // namespace content 154 155#endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ 156