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_WEB_CONTENTS_FRAME_TREE_NODE_H_ | 5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_FRAME_TREE_NODE_H_ |
6 #define CONTENT_BROWSER_WEB_CONTENTS_FRAME_TREE_NODE_H_ | 6 #define CONTENT_BROWSER_WEB_CONTENTS_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_vector.h" | 12 #include "base/memory/scoped_vector.h" |
12 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
13 #include "url/gurl.h" | 14 #include "url/gurl.h" |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 | 17 |
| 18 class RenderFrameHostImpl; |
| 19 |
17 // Any page that contains iframes has a tree structure of the frames in the | 20 // Any page that contains iframes has a tree structure of the frames in the |
18 // renderer process. We are mirroring this tree in the browser process. This | 21 // renderer process. We are mirroring this tree in the browser process. This |
19 // 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 |
20 // are frame-specific (as opposed to page-specific). | 23 // are frame-specific (as opposed to page-specific). |
21 class CONTENT_EXPORT FrameTreeNode { | 24 class CONTENT_EXPORT FrameTreeNode { |
22 public: | 25 public: |
23 FrameTreeNode(int64 frame_id, const std::string& name); | 26 static const int64 kInvalidFrameId; |
| 27 |
| 28 FrameTreeNode(int64 frame_id, const std::string& name, |
| 29 scoped_ptr<RenderFrameHostImpl> render_frame_host); |
24 ~FrameTreeNode(); | 30 ~FrameTreeNode(); |
25 | 31 |
26 // This method takes ownership of the child pointer. | 32 void AddChild(scoped_ptr<FrameTreeNode> child); |
27 void AddChild(FrameTreeNode* child); | |
28 void RemoveChild(int64 child_id); | 33 void RemoveChild(int64 child_id); |
29 | 34 |
| 35 // Transitional API allowing the RenderFrameHost of a FrameTreeNode |
| 36 // representing the main frame to be provided by someone else. After |
| 37 // this is called, the FrameTreeNode no longer owns its RenderFrameHost. |
| 38 // |
| 39 // This should only be used for the main frame (aka root) in a frame tree. |
| 40 // |
| 41 // TODO(ajwong): Remove this method once the main frame RenderFrameHostImpl is |
| 42 // no longer owned by the RenderViewHostImpl. |
| 43 void ResetForMainFrame(RenderFrameHostImpl* new_render_frame_host); |
| 44 |
| 45 void set_frame_id(int64 frame_id) { |
| 46 DCHECK_EQ(frame_id_, kInvalidFrameId); |
| 47 frame_id_ = frame_id; |
| 48 } |
| 49 |
30 int64 frame_id() const { | 50 int64 frame_id() const { |
31 return frame_id_; | 51 return frame_id_; |
32 } | 52 } |
33 | 53 |
34 const std::string& frame_name() const { | 54 const std::string& frame_name() const { |
35 return frame_name_; | 55 return frame_name_; |
36 } | 56 } |
37 | 57 |
38 size_t child_count() const { | 58 size_t child_count() const { |
39 return children_.size(); | 59 return children_.size(); |
40 } | 60 } |
41 | 61 |
42 FrameTreeNode* child_at(size_t index) const { | 62 FrameTreeNode* child_at(size_t index) const { |
43 return children_[index]; | 63 return children_[index]; |
44 } | 64 } |
45 | 65 |
46 const GURL& current_url() const { | 66 const GURL& current_url() const { |
47 return current_url_; | 67 return current_url_; |
48 } | 68 } |
49 | 69 |
50 void set_current_url(const GURL& url) { | 70 void set_current_url(const GURL& url) { |
51 current_url_ = url; | 71 current_url_ = url; |
52 } | 72 } |
53 | 73 |
| 74 RenderFrameHostImpl* render_frame_host() const { |
| 75 return render_frame_host_; |
| 76 } |
| 77 |
54 private: | 78 private: |
55 // The unique identifier for the frame in the page. | 79 // The unique identifier for the frame in the page. |
56 int64 frame_id_; | 80 int64 frame_id_; |
57 | 81 |
58 // The assigned name of the frame. This name can be empty, unlike the unique | 82 // The assigned name of the frame. This name can be empty, unlike the unique |
59 // name generated internally in the DOM tree. | 83 // name generated internally in the DOM tree. |
60 std::string frame_name_; | 84 std::string frame_name_; |
61 | 85 |
62 // The immediate children of this specific frame. | 86 // The immediate children of this specific frame. |
63 ScopedVector<FrameTreeNode> children_; | 87 ScopedVector<FrameTreeNode> children_; |
64 | 88 |
| 89 // When ResetForMainFrame() is called, this is set to false and the |
| 90 // |render_frame_host_| below is not deleted on destruction. |
| 91 // |
| 92 // For the mainframe, the FrameTree does not own the |render_frame_host_|. |
| 93 // This is a transitional wart because RenderViewHostManager does not yet |
| 94 // have the bookeeping logic to handle creating a pending RenderFrameHost |
| 95 // along with a pending RenderViewHost. Thus, for the main frame, the |
| 96 // RenderViewHost currently retains ownership and the FrameTreeNode should |
| 97 // not delete it on destruction. |
| 98 bool owns_render_frame_host_; |
| 99 |
| 100 // The active RenderFrameHost for this frame. The FrameTreeNode does not |
| 101 // always own this pointer. See comments above |owns_render_frame_host_|. |
| 102 // TODO(ajwong): Replace with RenderFrameHostManager. |
| 103 RenderFrameHostImpl* render_frame_host_; |
| 104 |
65 // Track the current frame's last committed URL, so we can estimate the | 105 // Track the current frame's last committed URL, so we can estimate the |
66 // process impact of out-of-process iframes. | 106 // process impact of out-of-process iframes. |
67 // TODO(creis): Remove this when we can store subframe URLs in the | 107 // TODO(creis): Remove this when we can store subframe URLs in the |
68 // NavigationController. | 108 // NavigationController. |
69 GURL current_url_; | 109 GURL current_url_; |
70 | 110 |
71 DISALLOW_COPY_AND_ASSIGN(FrameTreeNode); | 111 DISALLOW_COPY_AND_ASSIGN(FrameTreeNode); |
72 }; | 112 }; |
73 | 113 |
74 } // namespace content | 114 } // namespace content |
75 | 115 |
76 #endif // CONTENT_BROWSER_WEB_CONTENTS_FRAME_TREE_NODE_H_ | 116 #endif // CONTENT_BROWSER_WEB_CONTENTS_FRAME_TREE_NODE_H_ |
OLD | NEW |