OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "content/browser/renderer_host/frame_tree_node.h" |
| 13 #include "content/common/content_export.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 class FrameTreeNode; |
| 18 class RenderProcessHost; |
| 19 |
| 20 // Represents the frame tree for a page. With the exception of the main frame, |
| 21 // all FrameTreeNodes will be created/deleted in response to frame attach and |
| 22 // detach events in the DOM. |
| 23 // |
| 24 // The main frame's FrameTreeNode is special in that it is reused. This allows |
| 25 // it to serve as an anchor for state that needs to persist across top-level |
| 26 // page navigations. |
| 27 // |
| 28 // TODO(ajwong): Move NavigationController ownership the to main frame |
| 29 // FrameTreeNode. Possibly expose access to it from here. |
| 30 // |
| 31 // TODO(ajwong): Currently this class only contains FrameTreeNodes for |
| 32 // subframes if the --site-per-process flag is enabled. |
| 33 // |
| 34 // This object is only used on the UI thread. |
| 35 class CONTENT_EXPORT FrameTree { |
| 36 public: |
| 37 FrameTree(); |
| 38 ~FrameTree(); |
| 39 |
| 40 // Returns the FrameTreeNode with the given |frame_id|. |
| 41 FrameTreeNode* FindByID(int64 frame_id); |
| 42 |
| 43 // Executes |on_node| on each node in the frame tree. If |on_node| returns |
| 44 // false, terminates the iteration immediately. Returning false is useful |
| 45 // if |on_node| is just doing a search over the tree. |
| 46 void ForEach(const base::Callback<bool(FrameTreeNode*)>& on_node) const; |
| 47 |
| 48 // After the FrameTree is created, or after SwapMainFrame() has been called, |
| 49 // the root node does not yet have a frame id. This is allocated by the |
| 50 // renderer and is published to the browser process on the first navigation |
| 51 // after a swap. These two functions are used to set the root node's frame |
| 52 // id. |
| 53 // |
| 54 // TODO(ajwong): Remove these once RenderFrameHost's routing id replaces |
| 55 // frame_id. |
| 56 bool IsFirstNavigationAfterSwap() const; |
| 57 void OnFirstNavigationAfterSwap(int main_frame_id); |
| 58 |
| 59 // Frame tree manipulation routines. |
| 60 void AddFrame(int render_frame_host_id, int64 parent_frame_id, |
| 61 int64 frame_id, const std::string& frame_name); |
| 62 void RemoveFrame(int64 parent_frame_id, int64 frame_id); |
| 63 void SetFrameUrl(int64 frame_id, const GURL& url); |
| 64 |
| 65 // Resets the FrameTree and changes RenderFrameHost for the main frame. |
| 66 // This destroys most of frame tree but retains the root node so that |
| 67 // navigation state may be kept on it between process swaps. Used to |
| 68 // support bookeeping for top-level navigations. |
| 69 // |
| 70 // If |main_frame| is NULL, reset tree to initially constructed state. |
| 71 // |
| 72 // TODO(ajwong): This function should not be given a |main_frame|. This is |
| 73 // required currently because the RenderViewHost owns its main frame. When |
| 74 // that relation is fixed, the FrameTree should be responsible for |
| 75 // created/destroying the main frame on the swap. |
| 76 void SwapMainFrame(RenderFrameHostImpl* main_frame); |
| 77 |
| 78 // Convenience accessor for the main frame's RenderFrameHostImpl. |
| 79 RenderFrameHostImpl* GetMainFrame() const; |
| 80 |
| 81 // Allows a client to listen for frame removal. |
| 82 void SetFrameRemoveListener( |
| 83 const base::Callback<void(int64)>& on_frame_removed); |
| 84 |
| 85 FrameTreeNode* GetRootForTesting() { return root_.get(); } |
| 86 |
| 87 private: |
| 88 scoped_ptr<FrameTreeNode> CreateNode(int64 frame_id, |
| 89 const std::string& frame_name, |
| 90 int render_frame_host_id, |
| 91 RenderProcessHost* render_process_host); |
| 92 |
| 93 scoped_ptr<FrameTreeNode> root_; |
| 94 |
| 95 base::Callback<void(int64)> on_frame_removed_; |
| 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(FrameTree); |
| 98 }; |
| 99 |
| 100 } // namespace content |
| 101 |
| 102 #endif // CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_H_ |
OLD | NEW |