OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ | 5 #ifndef CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ |
6 #define CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ | 6 #define CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 | 17 |
18 class RenderFrameHostImpl; | 18 class RenderFrameHostImpl; |
19 | 19 |
20 // When a page contains iframes, its renderer process maintains a tree structure | 20 // When a page contains iframes, its renderer process maintains a tree structure |
21 // of those frames. We are mirroring this tree in the browser process. This | 21 // of those frames. We are mirroring this tree in the browser process. This |
22 // class represents a node in this tree and is a wrapper for all objects that | 22 // class represents a node in this tree and is a wrapper for all objects that |
23 // are frame-specific (as opposed to page-specific). | 23 // are frame-specific (as opposed to page-specific). |
24 class CONTENT_EXPORT FrameTreeNode { | 24 class CONTENT_EXPORT FrameTreeNode { |
25 public: | 25 public: |
26 static const int64 kInvalidFrameId; | 26 static const int64 kInvalidFrameId; |
27 | 27 |
28 FrameTreeNode(int64 frame_id, const std::string& name, | 28 FrameTreeNode(int64 frame_id, |
| 29 const std::string& name, |
29 scoped_ptr<RenderFrameHostImpl> render_frame_host); | 30 scoped_ptr<RenderFrameHostImpl> render_frame_host); |
30 ~FrameTreeNode(); | 31 ~FrameTreeNode(); |
31 | 32 |
32 void AddChild(scoped_ptr<FrameTreeNode> child); | 33 void AddChild(scoped_ptr<FrameTreeNode> child); |
33 void RemoveChild(int64 child_id); | 34 void RemoveChild(FrameTreeNode* child); |
34 | 35 |
35 // Transitional API allowing the RenderFrameHost of a FrameTreeNode | 36 // Transitional API allowing the RenderFrameHost of a FrameTreeNode |
36 // representing the main frame to be provided by someone else. After | 37 // representing the main frame to be provided by someone else. After |
37 // this is called, the FrameTreeNode no longer owns its RenderFrameHost. | 38 // this is called, the FrameTreeNode no longer owns its RenderFrameHost. |
38 // | 39 // |
39 // This should only be used for the main frame (aka root) in a frame tree. | 40 // This should only be used for the main frame (aka root) in a frame tree. |
40 // | 41 // |
41 // TODO(ajwong): Remove this method once the main frame RenderFrameHostImpl is | 42 // TODO(ajwong): Remove this method once the main frame RenderFrameHostImpl is |
42 // no longer owned by the RenderViewHostImpl. | 43 // no longer owned by the RenderViewHostImpl. |
43 void ResetForMainFrame(RenderFrameHostImpl* new_render_frame_host); | 44 void ResetForMainFrame(RenderFrameHostImpl* new_render_frame_host); |
44 | 45 |
| 46 int64 frame_tree_node_id() const { |
| 47 return frame_tree_node_id_; |
| 48 } |
| 49 |
| 50 // DO NOT USE. Only used by FrameTree until we replace renderer-specific |
| 51 // frame IDs with RenderFrameHost routing IDs. |
45 void set_frame_id(int64 frame_id) { | 52 void set_frame_id(int64 frame_id) { |
46 DCHECK_EQ(frame_id_, kInvalidFrameId); | 53 DCHECK_EQ(frame_id_, kInvalidFrameId); |
47 frame_id_ = frame_id; | 54 frame_id_ = frame_id; |
48 } | 55 } |
49 | |
50 int64 frame_id() const { | 56 int64 frame_id() const { |
51 return frame_id_; | 57 return frame_id_; |
52 } | 58 } |
53 | 59 |
54 const std::string& frame_name() const { | 60 const std::string& frame_name() const { |
55 return frame_name_; | 61 return frame_name_; |
56 } | 62 } |
57 | 63 |
58 size_t child_count() const { | 64 size_t child_count() const { |
59 return children_.size(); | 65 return children_.size(); |
60 } | 66 } |
61 | 67 |
62 FrameTreeNode* child_at(size_t index) const { | 68 FrameTreeNode* child_at(size_t index) const { |
63 return children_[index]; | 69 return children_[index]; |
64 } | 70 } |
65 | 71 |
66 const GURL& current_url() const { | 72 const GURL& current_url() const { |
67 return current_url_; | 73 return current_url_; |
68 } | 74 } |
69 | 75 |
70 void set_current_url(const GURL& url) { | 76 void set_current_url(const GURL& url) { |
71 current_url_ = url; | 77 current_url_ = url; |
72 } | 78 } |
73 | 79 |
74 RenderFrameHostImpl* render_frame_host() const { | 80 RenderFrameHostImpl* render_frame_host() const { |
75 return render_frame_host_; | 81 return render_frame_host_; |
76 } | 82 } |
77 | 83 |
78 private: | 84 private: |
79 // The unique identifier for the frame in the page. | 85 // The next available browser-global FrameTreeNode ID. |
| 86 static int64 next_frame_tree_node_id_; |
| 87 |
| 88 // A browser-global identifier for the frame in the page, which stays stable |
| 89 // even if the frame does a cross-process navigation. |
| 90 const int64 frame_tree_node_id_; |
| 91 |
| 92 // The renderer-specific identifier for the frame in the page. |
| 93 // TODO(creis): Remove this in favor of the RenderFrameHost's routing ID once |
| 94 // we create FrameTreeNodes for all frames (even without a flag), since this |
| 95 // value can change after cross-process navigations. |
80 int64 frame_id_; | 96 int64 frame_id_; |
81 | 97 |
82 // The assigned name of the frame. This name can be empty, unlike the unique | 98 // The assigned name of the frame. This name can be empty, unlike the unique |
83 // name generated internally in the DOM tree. | 99 // name generated internally in the DOM tree. |
84 std::string frame_name_; | 100 std::string frame_name_; |
85 | 101 |
86 // The immediate children of this specific frame. | 102 // The immediate children of this specific frame. |
87 ScopedVector<FrameTreeNode> children_; | 103 ScopedVector<FrameTreeNode> children_; |
88 | 104 |
89 // When ResetForMainFrame() is called, this is set to false and the | 105 // When ResetForMainFrame() is called, this is set to false and the |
(...skipping 17 matching lines...) Expand all Loading... |
107 // TODO(creis): Remove this when we can store subframe URLs in the | 123 // TODO(creis): Remove this when we can store subframe URLs in the |
108 // NavigationController. | 124 // NavigationController. |
109 GURL current_url_; | 125 GURL current_url_; |
110 | 126 |
111 DISALLOW_COPY_AND_ASSIGN(FrameTreeNode); | 127 DISALLOW_COPY_AND_ASSIGN(FrameTreeNode); |
112 }; | 128 }; |
113 | 129 |
114 } // namespace content | 130 } // namespace content |
115 | 131 |
116 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ | 132 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ |
OLD | NEW |