danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 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 <stdint.h> |
| 9 | |
| 10 | #include <iterator> |
| 11 | #include <memory> |
| 12 | #include <string> |
| 13 | #include <unordered_map> |
| 14 | |
| 15 | #include "base/callback.h" |
| 16 | #include "base/containers/queue.h" |
Carlos Caballero | 101ac26b | 2021-03-24 11:54:05 | [diff] [blame] | 17 | #include "base/dcheck_is_on.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 18 | #include "base/gtest_prod_util.h" |
| 19 | #include "base/macros.h" |
| 20 | #include "content/browser/renderer_host/navigator.h" |
| 21 | #include "content/browser/renderer_host/navigator_delegate.h" |
| 22 | #include "content/browser/renderer_host/render_frame_host_manager.h" |
| 23 | #include "content/common/content_export.h" |
| 24 | #include "mojo/public/cpp/bindings/pending_receiver.h" |
| 25 | #include "services/service_manager/public/mojom/interface_provider.mojom.h" |
Chris Hamilton | 3ff6ed0e | 2021-02-19 03:54:04 | [diff] [blame] | 26 | #include "third_party/blink/public/common/tokens/tokens.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 27 | #include "third_party/blink/public/mojom/frame/frame_owner_element_type.mojom.h" |
| 28 | #include "third_party/blink/public/mojom/frame/frame_owner_properties.mojom-forward.h" |
| 29 | |
| 30 | namespace blink { |
Lei Zhang | 4a86767 | 2021-07-19 06:30:14 | [diff] [blame] | 31 | namespace mojom { |
| 32 | class BrowserInterfaceBroker; |
| 33 | enum class TreeScopeType; |
| 34 | } // namespace mojom |
| 35 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 36 | struct FramePolicy; |
| 37 | } // namespace blink |
| 38 | |
| 39 | namespace content { |
| 40 | |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 41 | class BrowserContext; |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 42 | class PageDelegate; |
Lei Zhang | 4a86767 | 2021-07-19 06:30:14 | [diff] [blame] | 43 | class PageImpl; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 44 | class RenderFrameHostDelegate; |
| 45 | class RenderViewHostDelegate; |
| 46 | class RenderViewHostImpl; |
| 47 | class RenderFrameHostManager; |
| 48 | class RenderWidgetHostDelegate; |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 49 | class SiteInstance; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 50 | |
| 51 | // Represents the frame tree for a page. With the exception of the main frame, |
| 52 | // all FrameTreeNodes will be created/deleted in response to frame attach and |
| 53 | // detach events in the DOM. |
| 54 | // |
| 55 | // The main frame's FrameTreeNode is special in that it is reused. This allows |
| 56 | // it to serve as an anchor for state that needs to persist across top-level |
| 57 | // page navigations. |
| 58 | // |
| 59 | // TODO(ajwong): Move NavigationController ownership to the main frame |
| 60 | // FrameTreeNode. Possibly expose access to it from here. |
| 61 | // |
| 62 | // This object is only used on the UI thread. |
| 63 | class CONTENT_EXPORT FrameTree { |
| 64 | public: |
| 65 | class NodeRange; |
| 66 | |
| 67 | class CONTENT_EXPORT NodeIterator |
| 68 | : public std::iterator<std::forward_iterator_tag, FrameTreeNode> { |
| 69 | public: |
| 70 | NodeIterator(const NodeIterator& other); |
| 71 | ~NodeIterator(); |
| 72 | |
| 73 | NodeIterator& operator++(); |
Kevin McNee | 5f59438 | 2021-05-06 23:18:23 | [diff] [blame] | 74 | // Advances the iterator and excludes the children of the current node |
| 75 | NodeIterator& AdvanceSkippingChildren(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 76 | |
| 77 | bool operator==(const NodeIterator& rhs) const; |
| 78 | bool operator!=(const NodeIterator& rhs) const { return !(*this == rhs); } |
| 79 | |
| 80 | FrameTreeNode* operator*() { return current_node_; } |
| 81 | |
| 82 | private: |
Jayson Adams | 4db0bfe2 | 2021-07-15 19:24:07 | [diff] [blame] | 83 | friend class FrameTreeTest; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 84 | friend class NodeRange; |
| 85 | |
Kevin McNee | 5f59438 | 2021-05-06 23:18:23 | [diff] [blame] | 86 | NodeIterator(const std::vector<FrameTreeNode*>& starting_nodes, |
| 87 | const FrameTreeNode* root_of_subtree_to_skip, |
| 88 | bool should_descend_into_inner_trees); |
| 89 | |
| 90 | void AdvanceNode(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 91 | |
| 92 | FrameTreeNode* current_node_; |
Kevin McNee | 5f59438 | 2021-05-06 23:18:23 | [diff] [blame] | 93 | const FrameTreeNode* const root_of_subtree_to_skip_; |
| 94 | const bool should_descend_into_inner_trees_; |
Jayson Adams | 4db0bfe2 | 2021-07-15 19:24:07 | [diff] [blame] | 95 | base::circular_deque<FrameTreeNode*> queue_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | class CONTENT_EXPORT NodeRange { |
| 99 | public: |
Kevin McNee | 5f59438 | 2021-05-06 23:18:23 | [diff] [blame] | 100 | NodeRange(const NodeRange&); |
| 101 | ~NodeRange(); |
| 102 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 103 | NodeIterator begin(); |
| 104 | NodeIterator end(); |
| 105 | |
| 106 | private: |
| 107 | friend class FrameTree; |
| 108 | |
Kevin McNee | 5f59438 | 2021-05-06 23:18:23 | [diff] [blame] | 109 | NodeRange(const std::vector<FrameTreeNode*>& starting_nodes, |
| 110 | const FrameTreeNode* root_of_subtree_to_skip, |
| 111 | bool should_descend_into_inner_trees); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 112 | |
Kevin McNee | 5f59438 | 2021-05-06 23:18:23 | [diff] [blame] | 113 | const std::vector<FrameTreeNode*> starting_nodes_; |
| 114 | const FrameTreeNode* const root_of_subtree_to_skip_; |
| 115 | const bool should_descend_into_inner_trees_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 116 | }; |
| 117 | |
Carlos Caballero | 0326252 | 2021-02-05 14:49:58 | [diff] [blame] | 118 | class CONTENT_EXPORT Delegate { |
| 119 | public: |
| 120 | // A RenderFrameHost in the specified |frame_tree_node| started loading a |
| 121 | // new document. This corresponds to browser UI starting to show a spinner |
| 122 | // or other visual indicator for loading. This method is only invoked if the |
| 123 | // FrameTree hadn't been previously loading. |to_different_document| will be |
| 124 | // true unless the load is a fragment navigation, or triggered by |
| 125 | // history.pushState/replaceState. |
| 126 | virtual void DidStartLoading(FrameTreeNode* frame_tree_node, |
| 127 | bool to_different_document) = 0; |
| 128 | |
Takashi Toyoshima | 74090df6 | 2021-03-09 14:34:57 | [diff] [blame] | 129 | // This is called when all nodes in the FrameTree stopped loading. This |
Carlos Caballero | 0326252 | 2021-02-05 14:49:58 | [diff] [blame] | 130 | // corresponds to the browser UI stop showing a spinner or other visual |
| 131 | // indicator for loading. |
| 132 | virtual void DidStopLoading() = 0; |
| 133 | |
| 134 | // The load progress was changed. |
| 135 | virtual void DidChangeLoadProgress() = 0; |
Carlos Caballero | 6ff6ace | 2021-02-05 16:53:00 | [diff] [blame] | 136 | |
| 137 | // Returns true when the active RenderWidgetHostView should be hidden. |
| 138 | virtual bool IsHidden() = 0; |
Sreeja Kamishetty | a21b4f6 | 2021-06-25 07:48:25 | [diff] [blame] | 139 | |
Sreeja Kamishetty | 5346897 | 2021-07-13 11:53:32 | [diff] [blame] | 140 | // Called when current Page of this frame tree changes to `page`. |
| 141 | virtual void NotifyPageChanged(PageImpl& page) = 0; |
Dominic Farolino | edf44ee | 2021-07-20 23:50:59 | [diff] [blame] | 142 | |
| 143 | // If the FrameTree using this delegate is an inner/nested FrameTree, then |
| 144 | // there may be a FrameTreeNode in the outer FrameTree that is considered |
| 145 | // our outer delegate FrameTreeNode. This method returns the outer delegate |
| 146 | // FrameTreeNode ID if one exists. If we don't have a an outer delegate |
| 147 | // FrameTreeNode, this method returns |
| 148 | // FrameTreeNode::kFrameTreeNodeInvalidId. |
| 149 | virtual int GetOuterDelegateFrameTreeNodeId() = 0; |
Carlos Caballero | 0326252 | 2021-02-05 14:49:58 | [diff] [blame] | 150 | }; |
| 151 | |
Sreeja Kamishetty | 74bacd52 | 2021-03-22 17:04:24 | [diff] [blame] | 152 | // Type of FrameTree instance. |
| 153 | enum class Type { |
| 154 | // This FrameTree is the primary frame tree for the WebContents, whose main |
| 155 | // document URL is shown in the Omnibox. |
| 156 | kPrimary, |
| 157 | |
| 158 | // This FrameTree is used to prerender a page in the background which is |
| 159 | // invisible to the user. |
| 160 | kPrerender |
| 161 | }; |
Sreeja Kamishetty | 837a1040 | 2021-04-23 12:41:59 | [diff] [blame] | 162 | |
| 163 | // A set of delegates are remembered here so that we can create |
| 164 | // RenderFrameHostManagers. |
| 165 | FrameTree(BrowserContext* browser_context, |
| 166 | Delegate* delegate, |
| 167 | NavigationControllerDelegate* navigation_controller_delegate, |
| 168 | NavigatorDelegate* navigator_delegate, |
| 169 | RenderFrameHostDelegate* render_frame_delegate, |
| 170 | RenderViewHostDelegate* render_view_delegate, |
| 171 | RenderWidgetHostDelegate* render_widget_delegate, |
| 172 | RenderFrameHostManager::Delegate* manager_delegate, |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 173 | PageDelegate* page_delegate, |
Sreeja Kamishetty | 837a1040 | 2021-04-23 12:41:59 | [diff] [blame] | 174 | Type type); |
| 175 | ~FrameTree(); |
Sreeja Kamishetty | 74bacd52 | 2021-03-22 17:04:24 | [diff] [blame] | 176 | |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 177 | // Initializes the main frame for this FrameTree. That is it creates the |
| 178 | // initial RenderFrameHost in the root node's RenderFrameHostManager. This |
| 179 | // method will call back into the delegates so it should only be called once |
| 180 | // they have completed their initialization. |
| 181 | // TODO(carlscab): It would be great if initialization could happened in the |
| 182 | // constructor so we do not leave objects in a half initialized state. |
| 183 | void Init(SiteInstance* main_frame_site_instance, |
| 184 | bool renderer_initiated_creation, |
Sreeja Kamishetty | 837a1040 | 2021-04-23 12:41:59 | [diff] [blame] | 185 | const std::string& main_frame_name); |
| 186 | |
| 187 | Type type() const { return type_; } |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 188 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 189 | FrameTreeNode* root() const { return root_; } |
| 190 | |
Sreeja Kamishetty | 74bacd52 | 2021-03-22 17:04:24 | [diff] [blame] | 191 | bool is_prerendering() const { return type_ == FrameTree::Type::kPrerender; } |
Sreeja Kamishetty | 46f762c | 2021-02-05 07:52:46 | [diff] [blame] | 192 | |
Carlos Caballero | 0326252 | 2021-02-05 14:49:58 | [diff] [blame] | 193 | Delegate* delegate() { return delegate_; } |
| 194 | |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 195 | // Delegates for various objects. These can be kept centrally on the |
| 196 | // FrameTree because they are expected to be the same for all frames on a |
| 197 | // given FrameTree. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 198 | RenderFrameHostDelegate* render_frame_delegate() { |
| 199 | return render_frame_delegate_; |
| 200 | } |
| 201 | RenderViewHostDelegate* render_view_delegate() { |
| 202 | return render_view_delegate_; |
| 203 | } |
| 204 | RenderWidgetHostDelegate* render_widget_delegate() { |
| 205 | return render_widget_delegate_; |
| 206 | } |
| 207 | RenderFrameHostManager::Delegate* manager_delegate() { |
| 208 | return manager_delegate_; |
| 209 | } |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 210 | PageDelegate* page_delegate() { return page_delegate_; } |
Aaron Colwell | 78b4bde | 2021-03-16 16:16:09 | [diff] [blame] | 211 | |
Albert J. Wong | 1b6dc96 | 2021-07-09 18:06:57 | [diff] [blame] | 212 | using RenderViewHostMapId = base::IdType32<class RenderViewHostMap>; |
Aaron Colwell | 78b4bde | 2021-03-16 16:16:09 | [diff] [blame] | 213 | using RenderViewHostMap = std::unordered_map<RenderViewHostMapId, |
| 214 | RenderViewHostImpl*, |
| 215 | RenderViewHostMapId::Hasher>; |
| 216 | const RenderViewHostMap& render_view_hosts() const { |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 217 | return render_view_host_map_; |
| 218 | } |
| 219 | |
| 220 | // Returns the FrameTreeNode with the given |frame_tree_node_id| if it is part |
| 221 | // of this FrameTree. |
| 222 | FrameTreeNode* FindByID(int frame_tree_node_id); |
| 223 | |
| 224 | // Returns the FrameTreeNode with the given renderer-specific |routing_id|. |
| 225 | FrameTreeNode* FindByRoutingID(int process_id, int routing_id); |
| 226 | |
| 227 | // Returns the first frame in this tree with the given |name|, or the main |
| 228 | // frame if |name| is empty. |
| 229 | // Note that this does NOT support pseudo-names like _self, _top, and _blank, |
| 230 | // nor searching other FrameTrees (unlike blink::WebView::findFrameByName). |
| 231 | FrameTreeNode* FindByName(const std::string& name); |
| 232 | |
| 233 | // Returns a range to iterate over all FrameTreeNodes in the frame tree in |
| 234 | // breadth-first traversal order. |
| 235 | NodeRange Nodes(); |
| 236 | |
| 237 | // Returns a range to iterate over all FrameTreeNodes in a subtree of the |
| 238 | // frame tree, starting from |subtree_root|. |
| 239 | NodeRange SubtreeNodes(FrameTreeNode* subtree_root); |
| 240 | |
Kevin McNee | 5f59438 | 2021-05-06 23:18:23 | [diff] [blame] | 241 | // Returns a range to iterate over all FrameTreeNodes in a subtree, starting |
| 242 | // from, but not including |parent|, as well as any FrameTreeNodes of inner |
| 243 | // frame trees. |
| 244 | static NodeRange SubtreeAndInnerTreeNodes(RenderFrameHostImpl* parent); |
| 245 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 246 | // Adds a new child frame to the frame tree. |process_id| is required to |
| 247 | // disambiguate |new_routing_id|, and it must match the process of the |
| 248 | // |parent| node. Otherwise no child is added and this method returns false. |
| 249 | // |interface_provider_receiver| is the receiver end of the InterfaceProvider |
| 250 | // interface through which the child RenderFrame can access Mojo services |
| 251 | // exposed by the corresponding RenderFrameHost. The caller takes care of |
Antonio Sartori | db967c5 | 2021-01-20 09:54:30 | [diff] [blame] | 252 | // sending the client end of the interface down to the |
| 253 | // RenderFrame. |policy_container_bind_params|, if not null, is used for |
| 254 | // binding Blink's policy container to the new RenderFrameHost's |
| 255 | // PolicyContainerHost. This is only needed if this frame is the result of the |
| 256 | // CreateChildFrame mojo call, which also delivers the |
| 257 | // |policy_container_bind_params|. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 258 | FrameTreeNode* AddFrame( |
| 259 | RenderFrameHostImpl* parent, |
| 260 | int process_id, |
| 261 | int new_routing_id, |
danakj | 0bdfacd | 2021-01-20 19:27:18 | [diff] [blame] | 262 | mojo::PendingAssociatedRemote<mojom::Frame> frame_remote, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 263 | mojo::PendingReceiver<blink::mojom::BrowserInterfaceBroker> |
| 264 | browser_interface_broker_receiver, |
Antonio Sartori | db967c5 | 2021-01-20 09:54:30 | [diff] [blame] | 265 | blink::mojom::PolicyContainerBindParamsPtr policy_container_bind_params, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 266 | blink::mojom::TreeScopeType scope, |
| 267 | const std::string& frame_name, |
| 268 | const std::string& frame_unique_name, |
| 269 | bool is_created_by_script, |
Chris Hamilton | 3ff6ed0e | 2021-02-19 03:54:04 | [diff] [blame] | 270 | const blink::LocalFrameToken& frame_token, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 271 | const base::UnguessableToken& devtools_frame_token, |
| 272 | const blink::FramePolicy& frame_policy, |
| 273 | const blink::mojom::FrameOwnerProperties& frame_owner_properties, |
| 274 | bool was_discarded, |
| 275 | blink::mojom::FrameOwnerElementType owner_type); |
| 276 | |
| 277 | // Removes a frame from the frame tree. |child|, its children, and objects |
| 278 | // owned by their RenderFrameHostManagers are immediately deleted. The root |
| 279 | // node cannot be removed this way. |
| 280 | void RemoveFrame(FrameTreeNode* child); |
| 281 | |
| 282 | // This method walks the entire frame tree and creates a RenderFrameProxyHost |
| 283 | // for the given |site_instance| in each node except the |source| one -- |
| 284 | // the source will have a RenderFrameHost. |source| may be null if there is |
| 285 | // no node navigating in this frame tree (such as when this is called |
| 286 | // for an opener's frame tree), in which case no nodes are skipped for |
| 287 | // RenderFrameProxyHost creation. |
| 288 | void CreateProxiesForSiteInstance(FrameTreeNode* source, |
| 289 | SiteInstance* site_instance); |
| 290 | |
| 291 | // Convenience accessor for the main frame's RenderFrameHostImpl. |
| 292 | RenderFrameHostImpl* GetMainFrame() const; |
| 293 | |
| 294 | // Returns the focused frame. |
| 295 | FrameTreeNode* GetFocusedFrame(); |
| 296 | |
| 297 | // Sets the focused frame to |node|. |source| identifies the SiteInstance |
| 298 | // that initiated this focus change. If this FrameTree has SiteInstances |
| 299 | // other than |source|, those SiteInstances will be notified about the new |
| 300 | // focused frame. Note that |source| may differ from |node|'s current |
| 301 | // SiteInstance (e.g., this happens for cross-process window.focus() calls). |
| 302 | void SetFocusedFrame(FrameTreeNode* node, SiteInstance* source); |
| 303 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 304 | // Creates a RenderViewHostImpl for a given |site_instance| in the tree. |
| 305 | // |
| 306 | // The RenderFrameHostImpls and the RenderFrameProxyHosts will share ownership |
| 307 | // of this object. |
| 308 | scoped_refptr<RenderViewHostImpl> CreateRenderViewHost( |
| 309 | SiteInstance* site_instance, |
| 310 | int32_t main_frame_routing_id, |
danakj | 08eb51d | 2020-12-30 20:15:23 | [diff] [blame] | 311 | bool swapped_out, |
| 312 | bool renderer_initiated_creation); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 313 | |
| 314 | // Returns the existing RenderViewHost for a new RenderFrameHost. |
| 315 | // There should always be such a RenderViewHost, because the main frame |
| 316 | // RenderFrameHost for each SiteInstance should be created before subframes. |
| 317 | scoped_refptr<RenderViewHostImpl> GetRenderViewHost( |
| 318 | SiteInstance* site_instance); |
| 319 | |
Aaron Colwell | 78b4bde | 2021-03-16 16:16:09 | [diff] [blame] | 320 | // Returns the ID used for the RenderViewHost associated with |site_instance|. |
| 321 | // Note: Callers should not assume that there is a 1:1 mapping between |
| 322 | // SiteInstances and IDs returned by this function, since several |
| 323 | // SiteInstances may share a RenderViewHost. |
| 324 | RenderViewHostMapId GetRenderViewHostMapId(SiteInstance* site_instance) const; |
| 325 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 326 | // Registers a RenderViewHost so that it can be reused by other frames |
Aaron Colwell | 78b4bde | 2021-03-16 16:16:09 | [diff] [blame] | 327 | // whose SiteInstance maps to the same RenderViewHostMapId. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 328 | // |
| 329 | // This method does not take ownership of|rvh|. |
| 330 | // |
| 331 | // NOTE: This method CHECK fails if a RenderViewHost is already registered for |
| 332 | // |rvh|'s SiteInstance. |
| 333 | // |
| 334 | // ALSO NOTE: After calling RegisterRenderViewHost, UnregisterRenderViewHost |
| 335 | // *must* be called for |rvh| when it is destroyed or put into the |
| 336 | // BackForwardCache, to prevent FrameTree::CreateRenderViewHost from trying to |
| 337 | // reuse it. |
Aaron Colwell | 78b4bde | 2021-03-16 16:16:09 | [diff] [blame] | 338 | void RegisterRenderViewHost(RenderViewHostMapId id, RenderViewHostImpl* rvh); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 339 | |
| 340 | // Unregisters the RenderViewHostImpl that's available for reuse for a |
Aaron Colwell | 78b4bde | 2021-03-16 16:16:09 | [diff] [blame] | 341 | // particular RenderViewHostMapId. NOTE: This method CHECK fails if it is |
| 342 | // called for a |render_view_host| that is not currently set for reuse. |
| 343 | void UnregisterRenderViewHost(RenderViewHostMapId id, |
Aaron Colwell | c4bd7d6 | 2021-01-29 04:23:13 | [diff] [blame] | 344 | RenderViewHostImpl* render_view_host); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 345 | |
| 346 | // This is called when the frame is about to be removed and started to run |
| 347 | // unload handlers. |
| 348 | void FrameUnloading(FrameTreeNode* frame); |
| 349 | |
| 350 | // This is only meant to be called by FrameTreeNode. Triggers calling |
| 351 | // the listener installed by SetFrameRemoveListener. |
| 352 | void FrameRemoved(FrameTreeNode* frame); |
| 353 | |
Carlos Caballero | 0326252 | 2021-02-05 14:49:58 | [diff] [blame] | 354 | void DidStartLoadingNode(FrameTreeNode& node, |
| 355 | bool to_different_document, |
| 356 | bool was_previously_loading); |
| 357 | void DidStopLoadingNode(FrameTreeNode& node); |
| 358 | void DidChangeLoadProgressForNode(FrameTreeNode& node, double load_progress); |
| 359 | void DidCancelLoading(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 360 | |
| 361 | // Returns this FrameTree's total load progress. |
| 362 | double load_progress() const { return load_progress_; } |
| 363 | |
| 364 | // Resets the load progress on all nodes in this FrameTree. |
| 365 | void ResetLoadProgress(); |
| 366 | |
| 367 | // Returns true if at least one of the nodes in this FrameTree is loading. |
| 368 | bool IsLoading() const; |
| 369 | |
| 370 | // Set page-level focus in all SiteInstances involved in rendering |
| 371 | // this FrameTree, not including the current main frame's |
| 372 | // SiteInstance. The focus update will be sent via the main frame's proxies |
| 373 | // in those SiteInstances. |
| 374 | void ReplicatePageFocus(bool is_focused); |
| 375 | |
| 376 | // Updates page-level focus for this FrameTree in the subframe renderer |
| 377 | // identified by |instance|. |
| 378 | void SetPageFocus(SiteInstance* instance, bool is_focused); |
| 379 | |
| 380 | // Walks the current frame tree and registers any origins matching |origin|, |
| 381 | // either the last committed origin of a RenderFrameHost or the origin |
| 382 | // associated with a NavigationRequest that has been assigned to a |
| 383 | // SiteInstance, as not-opted-in for origin isolation. |
| 384 | void RegisterExistingOriginToPreventOptInIsolation( |
| 385 | const url::Origin& previously_visited_origin, |
| 386 | NavigationRequest* navigation_request_to_exclude); |
| 387 | |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 388 | NavigationControllerImpl& controller() { return navigator_.controller(); } |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 389 | Navigator& navigator() { return navigator_; } |
| 390 | |
Carlos Caballero | ede6f8c | 2021-01-28 11:01:50 | [diff] [blame] | 391 | // Another page accessed the initial empty main document, which means it |
| 392 | // is no longer safe to display a pending URL without risking a URL spoof. |
| 393 | void DidAccessInitialMainDocument(); |
| 394 | |
| 395 | bool has_accessed_initial_main_document() const { |
| 396 | return has_accessed_initial_main_document_; |
| 397 | } |
| 398 | |
| 399 | void ResetHasAccessedInitialMainDocument() { |
| 400 | has_accessed_initial_main_document_ = false; |
| 401 | } |
| 402 | |
Carlos Caballero | 6ff6ace | 2021-02-05 16:53:00 | [diff] [blame] | 403 | bool IsHidden() const { return delegate_->IsHidden(); } |
| 404 | |
Carlos Caballero | 0326252 | 2021-02-05 14:49:58 | [diff] [blame] | 405 | // Stops all ongoing navigations in each of the nodes of this FrameTree. |
| 406 | void StopLoading(); |
| 407 | |
Carlos Caballero | 101ac26b | 2021-03-24 11:54:05 | [diff] [blame] | 408 | // Prepares this frame tree for destruction, cleaning up the internal state |
| 409 | // and firing the appropriate events like FrameDeleted. |
| 410 | // Must be called before FrameTree is destroyed. |
| 411 | void Shutdown(); |
| 412 | |
shivanigithub | 93878d0 | 2021-06-15 11:37:53 | [diff] [blame] | 413 | // Returns true if this is a fenced frame tree. |
| 414 | // TODO(crbug.com/1123606): Integrate this with the MPArch based fenced frame |
| 415 | // code once that lands. |
| 416 | bool IsFencedFrameTree() const { return is_fenced_frame_tree_; } |
| 417 | void SetFencedFrameTreeForTesting() { is_fenced_frame_tree_ = true; } |
| 418 | |
Takashi Toyoshima | ea534ef2 | 2021-07-21 03:27:59 | [diff] [blame] | 419 | bool IsBeingDestroyed() const { return is_being_destroyed_; } |
| 420 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 421 | private: |
| 422 | friend class FrameTreeTest; |
| 423 | FRIEND_TEST_ALL_PREFIXES(RenderFrameHostImplBrowserTest, RemoveFocusedFrame); |
| 424 | |
| 425 | // Returns a range to iterate over all FrameTreeNodes in the frame tree in |
| 426 | // breadth-first traversal order, skipping the subtree rooted at |
| 427 | // |node|, but including |node| itself. |
| 428 | NodeRange NodesExceptSubtree(FrameTreeNode* node); |
| 429 | |
Carlos Caballero | 0326252 | 2021-02-05 14:49:58 | [diff] [blame] | 430 | Delegate* const delegate_; |
| 431 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 432 | // These delegates are installed into all the RenderViewHosts and |
| 433 | // RenderFrameHosts that we create. |
| 434 | RenderFrameHostDelegate* render_frame_delegate_; |
| 435 | RenderViewHostDelegate* render_view_delegate_; |
| 436 | RenderWidgetHostDelegate* render_widget_delegate_; |
| 437 | RenderFrameHostManager::Delegate* manager_delegate_; |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 438 | PageDelegate* page_delegate_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 439 | |
| 440 | // The Navigator object responsible for managing navigations on this frame |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 441 | // tree. Each FrameTreeNode will default to using it for navigation tasks in |
| 442 | // the frame. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 443 | Navigator navigator_; |
| 444 | |
Aaron Colwell | 78b4bde | 2021-03-16 16:16:09 | [diff] [blame] | 445 | // Map of RenderViewHostMapId to RenderViewHost. This allows us to look up the |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 446 | // RenderViewHost for a given SiteInstance when creating RenderFrameHosts. |
| 447 | // Each RenderViewHost maintains a refcount and is deleted when there are no |
| 448 | // more RenderFrameHosts or RenderFrameProxyHosts using it. |
Aaron Colwell | 78b4bde | 2021-03-16 16:16:09 | [diff] [blame] | 449 | RenderViewHostMap render_view_host_map_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 450 | |
| 451 | // This is an owned ptr to the root FrameTreeNode, which never changes over |
| 452 | // the lifetime of the FrameTree. It is not a scoped_ptr because we need the |
| 453 | // pointer to remain valid even while the FrameTreeNode is being destroyed, |
| 454 | // since it's common for a node to test whether it's the root node. |
| 455 | FrameTreeNode* root_; |
| 456 | |
| 457 | int focused_frame_tree_node_id_; |
| 458 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 459 | // Overall load progress. |
| 460 | double load_progress_; |
| 461 | |
Carlos Caballero | ede6f8c | 2021-01-28 11:01:50 | [diff] [blame] | 462 | // Whether the initial empty page has been accessed by another page, making it |
| 463 | // unsafe to show the pending URL. Usually false unless another window tries |
| 464 | // to modify the blank page. Always false after the first commit. |
| 465 | bool has_accessed_initial_main_document_ = false; |
| 466 | |
Sreeja Kamishetty | 837a1040 | 2021-04-23 12:41:59 | [diff] [blame] | 467 | // Indicates type of frame tree. |
| 468 | const Type type_; |
Sreeja Kamishetty | 74bacd52 | 2021-03-22 17:04:24 | [diff] [blame] | 469 | |
shivanigithub | 93878d0 | 2021-06-15 11:37:53 | [diff] [blame] | 470 | // TODO(crbug.com/1123606): Integrate this with the MPArch based fenced frame |
| 471 | // code once that lands. Possibly this will then be part of |type_|. |
| 472 | bool is_fenced_frame_tree_ = false; |
| 473 | |
Takashi Toyoshima | ea534ef2 | 2021-07-21 03:27:59 | [diff] [blame] | 474 | bool is_being_destroyed_ = false; |
| 475 | |
Carlos Caballero | 101ac26b | 2021-03-24 11:54:05 | [diff] [blame] | 476 | #if DCHECK_IS_ON() |
| 477 | // Whether Shutdown() was called. |
| 478 | bool was_shut_down_ = false; |
| 479 | #endif |
| 480 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 481 | DISALLOW_COPY_AND_ASSIGN(FrameTree); |
| 482 | }; |
| 483 | |
| 484 | } // namespace content |
| 485 | |
| 486 | #endif // CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_H_ |