IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / frame_host / frame_tree_node.h
blobe7b0800319e1332cefbf88c2bf42905c6787a38a
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.
5 #ifndef CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_
6 #define CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_
8 #include <string>
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"
19 namespace content {
21 class FrameTree;
22 class Navigator;
23 class RenderFrameHostImpl;
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).
29 class CONTENT_EXPORT FrameTreeNode {
30 public:
31 static const int64 kInvalidFrameId;
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);
42 ~FrameTreeNode();
44 bool IsMainFrame() const;
46 void AddChild(scoped_ptr<FrameTreeNode> child, int frame_routing_id);
47 void RemoveChild(FrameTreeNode* child);
49 // Clears process specific-state after a main frame process swap.
50 // TODO(creis): Look into how we can remove the need for this method.
51 void ResetForMainFrameSwap();
53 FrameTree* frame_tree() const {
54 return frame_tree_;
57 Navigator* navigator() {
58 return navigator_.get();
61 RenderFrameHostManager* render_manager() {
62 return &render_manager_;
65 int64 frame_tree_node_id() const {
66 return frame_tree_node_id_;
69 // DO NOT USE. Only used by FrameTree until we replace renderer-specific
70 // frame IDs with RenderFrameHost routing IDs.
71 void set_frame_id(int64 frame_id) {
72 DCHECK_EQ(frame_id_, kInvalidFrameId);
73 frame_id_ = frame_id;
75 int64 frame_id() const {
76 return frame_id_;
79 const std::string& frame_name() const {
80 return frame_name_;
83 size_t child_count() const {
84 return children_.size();
87 FrameTreeNode* child_at(size_t index) const {
88 return children_[index];
91 const GURL& current_url() const {
92 return current_url_;
95 void set_current_url(const GURL& url) {
96 current_url_ = url;
99 RenderFrameHostImpl* current_frame_host() const {
100 return render_manager_.current_frame_host();
103 private:
104 // The next available browser-global FrameTreeNode ID.
105 static int64 next_frame_tree_node_id_;
107 // The FrameTree that owns us.
108 FrameTree* frame_tree_; // not owned.
110 // The Navigator object responsible for managing navigations at this node
111 // of the frame tree.
112 scoped_refptr<Navigator> navigator_;
114 // Manages creation and swapping of RenderFrameHosts for this frame. This
115 // must be declared before |children_| so that it gets deleted after them.
116 // That's currently necessary so that RenderFrameHostImpl's destructor can
117 // call GetProcess.
118 RenderFrameHostManager render_manager_;
120 // A browser-global identifier for the frame in the page, which stays stable
121 // even if the frame does a cross-process navigation.
122 const int64 frame_tree_node_id_;
124 // The renderer-specific identifier for the frame in the page.
125 // TODO(creis): Remove this in favor of the RenderFrameHost's routing ID once
126 // we create FrameTreeNodes for all frames (even without a flag), since this
127 // value can change after cross-process navigations.
128 int64 frame_id_;
130 // The assigned name of the frame. This name can be empty, unlike the unique
131 // name generated internally in the DOM tree.
132 std::string frame_name_;
134 // The immediate children of this specific frame.
135 ScopedVector<FrameTreeNode> children_;
137 // Track the current frame's last committed URL, so we can estimate the
138 // process impact of out-of-process iframes.
139 // TODO(creis): Remove this when we can store subframe URLs in the
140 // NavigationController.
141 GURL current_url_;
143 DISALLOW_COPY_AND_ASSIGN(FrameTreeNode);
146 } // namespace content
148 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_