| 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/browser/frame_host/render_view_host_manager.h" |
| 13 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 class RenderFrameHostImpl; | 19 class RenderFrameHostImpl; |
| 19 | 20 |
| 20 // When a page contains iframes, its renderer process maintains a tree structure | 21 // 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 | 22 // 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 | 23 // class represents a node in this tree and is a wrapper for all objects that |
| 23 // are frame-specific (as opposed to page-specific). | 24 // are frame-specific (as opposed to page-specific). |
| 24 class CONTENT_EXPORT FrameTreeNode { | 25 class CONTENT_EXPORT FrameTreeNode { |
| 25 public: | 26 public: |
| 26 static const int64 kInvalidFrameId; | 27 FrameTreeNode(int64 frame_tree_node_id, |
| 27 | 28 const std::string& name, |
| 28 FrameTreeNode(int64 frame_id, const std::string& name, | 29 RenderViewHostDelegate* render_view_delegate, |
| 29 scoped_ptr<RenderFrameHostImpl> render_frame_host); | 30 RenderWidgetHostDelegate* render_widget_delegate, |
| 31 RenderViewHostManager::Delegate* manager_delegate); |
| 30 ~FrameTreeNode(); | 32 ~FrameTreeNode(); |
| 31 | 33 |
| 32 void AddChild(scoped_ptr<FrameTreeNode> child); | 34 void AddChild(scoped_ptr<FrameTreeNode> child); |
| 33 void RemoveChild(int64 child_id); | 35 void RemoveChild(int64 child_id); |
| 34 | 36 |
| 35 // Transitional API allowing the RenderFrameHost of a FrameTreeNode | 37 // This is the browser-wide unique ID for the FrameTreeNode. If you have a |
| 36 // representing the main frame to be provided by someone else. After | 38 // renderer-specific frame ID, you can look up the corresponding FrameTreeNode |
| 37 // this is called, the FrameTreeNode no longer owns its RenderFrameHost. | 39 // ID using RenderViewHostImpl::GetFrameTreeNodeID(frame_id). |
| 38 // | 40 int64 frame_tree_node_id() const { |
| 39 // This should only be used for the main frame (aka root) in a frame tree. | 41 return frame_tree_node_id_; |
| 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 | |
| 50 int64 frame_id() const { | |
| 51 return frame_id_; | |
| 52 } | 42 } |
| 53 | 43 |
| 54 const std::string& frame_name() const { | 44 const std::string& frame_name() const { |
| 55 return frame_name_; | 45 return frame_name_; |
| 56 } | 46 } |
| 57 | 47 |
| 58 size_t child_count() const { | 48 size_t child_count() const { |
| 59 return children_.size(); | 49 return children_.size(); |
| 60 } | 50 } |
| 61 | 51 |
| 62 FrameTreeNode* child_at(size_t index) const { | 52 FrameTreeNode* child_at(size_t index) const { |
| 63 return children_[index]; | 53 return children_[index]; |
| 64 } | 54 } |
| 65 | 55 |
| 66 const GURL& current_url() const { | 56 const GURL& current_url() const { |
| 67 return current_url_; | 57 return current_url_; |
| 68 } | 58 } |
| 69 | 59 |
| 70 void set_current_url(const GURL& url) { | 60 void set_current_url(const GURL& url) { |
| 71 current_url_ = url; | 61 current_url_ = url; |
| 72 } | 62 } |
| 73 | 63 |
| 64 RenderViewHostManager* render_manager() { |
| 65 return &render_manager_; |
| 66 } |
| 67 |
| 74 RenderFrameHostImpl* render_frame_host() const { | 68 RenderFrameHostImpl* render_frame_host() const { |
| 75 return render_frame_host_; | 69 return render_manager_.current_frame(); |
| 76 } | 70 } |
| 77 | 71 |
| 78 private: | 72 private: |
| 79 // The unique identifier for the frame in the page. | 73 // The browser-wide unique identifier for the frame in the page. |
| 80 int64 frame_id_; | 74 int64 frame_tree_node_id_; |
| 81 | 75 |
| 82 // The assigned name of the frame. This name can be empty, unlike the unique | 76 // The assigned name of the frame. This name can be empty, unlike the unique |
| 83 // name generated internally in the DOM tree. | 77 // name generated internally in the DOM tree. |
| 84 std::string frame_name_; | 78 std::string frame_name_; |
| 85 | 79 |
| 86 // The immediate children of this specific frame. | 80 // The immediate children of this specific frame. |
| 87 ScopedVector<FrameTreeNode> children_; | 81 ScopedVector<FrameTreeNode> children_; |
| 88 | 82 |
| 89 // When ResetForMainFrame() is called, this is set to false and the | 83 // Manages creation and swapping of RenderFrameHosts for this frame. |
| 90 // |render_frame_host_| below is not deleted on destruction. | 84 RenderViewHostManager render_manager_; |
| 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 bookkeeping 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 | 85 |
| 105 // Track the current frame's last committed URL, so we can estimate the | 86 // Track the current frame's last committed URL, so we can estimate the |
| 106 // process impact of out-of-process iframes. | 87 // process impact of out-of-process iframes. |
| 107 // TODO(creis): Remove this when we can store subframe URLs in the | 88 // TODO(creis): Remove this when we can store subframe URLs in the |
| 108 // NavigationController. | 89 // NavigationController. |
| 109 GURL current_url_; | 90 GURL current_url_; |
| 110 | 91 |
| 111 DISALLOW_COPY_AND_ASSIGN(FrameTreeNode); | 92 DISALLOW_COPY_AND_ASSIGN(FrameTreeNode); |
| 112 }; | 93 }; |
| 113 | 94 |
| 114 } // namespace content | 95 } // namespace content |
| 115 | 96 |
| 116 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ | 97 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ |
| OLD | NEW |