| 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_H_ | 5 #ifndef CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_H_ |
| 6 #define CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_H_ | 6 #define CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // all FrameTreeNodes will be created/deleted in response to frame attach and | 26 // all FrameTreeNodes will be created/deleted in response to frame attach and |
| 27 // detach events in the DOM. | 27 // detach events in the DOM. |
| 28 // | 28 // |
| 29 // The main frame's FrameTreeNode is special in that it is reused. This allows | 29 // The main frame's FrameTreeNode is special in that it is reused. This allows |
| 30 // it to serve as an anchor for state that needs to persist across top-level | 30 // it to serve as an anchor for state that needs to persist across top-level |
| 31 // page navigations. | 31 // page navigations. |
| 32 // | 32 // |
| 33 // TODO(ajwong): Move NavigationController ownership to the main frame | 33 // TODO(ajwong): Move NavigationController ownership to the main frame |
| 34 // FrameTreeNode. Possibly expose access to it from here. | 34 // FrameTreeNode. Possibly expose access to it from here. |
| 35 // | 35 // |
| 36 // TODO(ajwong): Currently this class only contains FrameTreeNodes for | |
| 37 // subframes if the --site-per-process flag is enabled. | |
| 38 // | |
| 39 // This object is only used on the UI thread. | 36 // This object is only used on the UI thread. |
| 40 class CONTENT_EXPORT FrameTree { | 37 class CONTENT_EXPORT FrameTree { |
| 41 public: | 38 public: |
| 42 // Each FrameTreeNode will default to using the given |navigator| for | 39 // Each FrameTreeNode will default to using the given |navigator| for |
| 43 // navigation tasks in the frame. | 40 // navigation tasks in the frame. |
| 44 // A set of delegates are remembered here so that we can create | 41 // A set of delegates are remembered here so that we can create |
| 45 // RenderViewHostManagers. | 42 // RenderViewHostManagers. |
| 46 // TODO(creis): This set of delegates will change as we move things to | 43 // TODO(creis): This set of delegates will change as we move things to |
| 47 // Navigator. | 44 // Navigator. |
| 48 FrameTree(Navigator* navigator, | 45 FrameTree(Navigator* navigator, |
| 49 RenderViewHostDelegate* render_view_delegate, | 46 RenderViewHostDelegate* render_view_delegate, |
| 50 RenderWidgetHostDelegate* render_widget_delegate, | 47 RenderWidgetHostDelegate* render_widget_delegate, |
| 51 RenderViewHostManager::Delegate* manager_delegate); | 48 RenderViewHostManager::Delegate* manager_delegate); |
| 52 ~FrameTree(); | 49 ~FrameTree(); |
| 53 | 50 |
| 54 // Returns the FrameTreeNode with the given |frame_tree_node_id|. | 51 // Returns the FrameTreeNode with the given |frame_tree_node_id|. |
| 55 FrameTreeNode* FindByID(int64 frame_tree_node_id); | 52 FrameTreeNode* FindByID(int64 frame_tree_node_id); |
| 56 | 53 |
| 57 // Executes |on_node| on each node in the frame tree. If |on_node| returns | 54 // Executes |on_node| on each node in the frame tree. If |on_node| returns |
| 58 // false, terminates the iteration immediately. Returning false is useful | 55 // false, terminates the iteration immediately. Returning false is useful |
| 59 // if |on_node| is just doing a search over the tree. | 56 // if |on_node| is just doing a search over the tree. |
| 60 void ForEach(const base::Callback<bool(FrameTreeNode*)>& on_node) const; | 57 void ForEach(const base::Callback<bool(FrameTreeNode*)>& on_node) const; |
| 61 | 58 |
| 62 // After the FrameTree is created, or after SwapMainFrame() has been called, | |
| 63 // the root node does not yet have a frame id. This is allocated by the | |
| 64 // renderer and is published to the browser process on the first navigation | |
| 65 // after a swap. These two functions are used to set the root node's frame | |
| 66 // id. | |
| 67 // | |
| 68 // TODO(ajwong): Remove these once RenderFrameHost's routing id replaces | |
| 69 // frame_id. | |
| 70 bool IsFirstNavigationAfterSwap() const; | |
| 71 void OnFirstNavigationAfterSwap(int main_frame_id); | |
| 72 | |
| 73 // Frame tree manipulation routines. | 59 // Frame tree manipulation routines. |
| 74 // TODO(creis): These should take in RenderFrameHost routing IDs. | 60 void AddFrame(RenderViewHostImpl* parent_render_view_host, |
| 75 void AddFrame(int render_frame_host_id, | 61 int render_frame_host_id, |
| 76 int64 parent_frame_tree_node_id, | 62 int64 parent_frame_id, |
| 77 int64 frame_id, | 63 int64 frame_id, |
| 78 const std::string& frame_name); | 64 const std::string& frame_name); |
| 79 void RemoveFrame(int64 parent_frame_id, int64 frame_id); | 65 void RemoveFrame(int64 parent_frame_tree_node_id, |
| 80 void SetFrameUrl(int64 frame_id, const GURL& url); | 66 int64 frame_tree_node_id); |
| 81 | 67 void SetFrameUrl(int64 frame_tree_node_id, const GURL& url); |
| 82 // Resets the FrameTree and changes RenderFrameHost for the main frame. | |
| 83 // This destroys most of the frame tree but retains the root node so that | |
| 84 // navigation state may be kept on it between process swaps. Used to | |
| 85 // support bookkeeping for top-level navigations. | |
| 86 // | |
| 87 // If |main_frame| is NULL, reset tree to initially constructed state. | |
| 88 // | |
| 89 // TODO(ajwong): This function should not be given a |main_frame|. This is | |
| 90 // required currently because the RenderViewHost owns its main frame. When | |
| 91 // that relation is fixed, the FrameTree should be responsible for | |
| 92 // created/destroying the main frame on the swap. | |
| 93 void SwapMainFrame(RenderFrameHostImpl* main_frame); | |
| 94 | 68 |
| 95 // Convenience accessor for the main frame's RenderFrameHostImpl. | 69 // Convenience accessor for the main frame's RenderFrameHostImpl. |
| 96 RenderFrameHostImpl* GetMainFrame() const; | 70 RenderFrameHostImpl* GetMainFrame() const; |
| 97 | 71 |
| 98 // Allows a client to listen for frame removal. The listener should expect | 72 // Allows a client to listen for frame removal. The listener should expect |
| 99 // to receive the RenderViewHostImpl containing the frame and the renderer- | 73 // to receive the RenderViewHostImpl containing the frame and the renderer- |
| 100 // specific frame ID of the removed frame. | 74 // specific frame ID of the removed frame. |
| 101 // TODO(creis): These parameters will later change to be the RenderFrameHost. | 75 // TODO(creis): These parameters will later change to be the RenderFrameHost. |
| 102 void SetFrameRemoveListener( | 76 void SetFrameRemoveListener( |
| 103 const base::Callback<void(RenderViewHostImpl*, int64)>& on_frame_removed); | 77 const base::Callback<void(RenderViewHostImpl*, int64)>& on_frame_removed); |
| 104 | 78 |
| 79 // Get the RenderViewHost needed for a new RenderFrameHost in the given |
| 80 // |site_instance|. Creates it if necessary and increments the refcount. |
| 81 // The RenderViewHost will have its Shutdown method called when all of the |
| 82 // RenderFrameHosts using it are deleted. |
| 83 RenderViewHostImpl* GetRenderViewHostForNewFrame(SiteInstance* site_instance, |
| 84 int routing_id, |
| 85 int main_frame_routing_id, |
| 86 bool swapped_out, |
| 87 bool hidden); |
| 88 |
| 105 FrameTreeNode* root() const { return root_.get(); } | 89 FrameTreeNode* root() const { return root_.get(); } |
| 106 | 90 |
| 107 private: | 91 private: |
| 108 // Returns the FrameTreeNode with the given renderer-specific |frame_id|. | 92 typedef base::hash_map<int, RenderViewHostImpl*> RenderViewHostMap; |
| 109 // For internal use only. | |
| 110 // TODO(creis): Replace this with a version that takes in a routing ID. | |
| 111 FrameTreeNode* FindByFrameID(int64 frame_id); | |
| 112 | 93 |
| 113 scoped_ptr<FrameTreeNode> CreateNode(int64 frame_id, | 94 scoped_ptr<FrameTreeNode> CreateNode(int64 frame_id, |
| 114 const std::string& frame_name, | 95 const std::string& frame_name, |
| 115 int render_frame_host_id, | |
| 116 Navigator* navigator, | 96 Navigator* navigator, |
| 117 RenderProcessHost* render_process_host); | 97 RenderViewHostImpl* render_view_host); |
| 118 | 98 |
| 119 // These delegates are installed into all the RenderViewHosts and | 99 // These delegates are installed into all the RenderViewHosts and |
| 120 // RenderFrameHosts that we create. | 100 // RenderFrameHosts that we create. |
| 121 RenderViewHostDelegate* render_view_delegate_; | 101 RenderViewHostDelegate* render_view_delegate_; |
| 122 RenderWidgetHostDelegate* render_widget_delegate_; | 102 RenderWidgetHostDelegate* render_widget_delegate_; |
| 123 RenderViewHostManager::Delegate* manager_delegate_; | 103 RenderViewHostManager::Delegate* manager_delegate_; |
| 124 | 104 |
| 125 scoped_ptr<FrameTreeNode> root_; | 105 scoped_ptr<FrameTreeNode> root_; |
| 126 | 106 |
| 107 // Map of SiteInstance ID to RenderViewHost, which we can consult when |
| 108 // creating a new RenderFrameHost in this tree. RenderViewHosts are kept |
| 109 // alive as long as they have at least one RenderFrameHost using them. |
| 110 RenderViewHostMap render_view_host_map_; |
| 111 |
| 127 base::Callback<void(RenderViewHostImpl*, int64)> on_frame_removed_; | 112 base::Callback<void(RenderViewHostImpl*, int64)> on_frame_removed_; |
| 128 | 113 |
| 129 DISALLOW_COPY_AND_ASSIGN(FrameTree); | 114 DISALLOW_COPY_AND_ASSIGN(FrameTree); |
| 130 }; | 115 }; |
| 131 | 116 |
| 132 } // namespace content | 117 } // namespace content |
| 133 | 118 |
| 134 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_H_ | 119 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_H_ |
| OLD | NEW |