blob: ce0b5df43ff71ef0b2e87cfaae7ad72cfb9c90ab [file] [log] [blame]
danakjc492bf82020-09-09 20:02:441// 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 Caballero101ac26b2021-03-24 11:54:0517#include "base/dcheck_is_on.h"
danakjc492bf82020-09-09 20:02:4418#include "base/gtest_prod_util.h"
Keishi Hattori0e45c022021-11-27 09:25:5219#include "base/memory/raw_ptr.h"
Dave Tapuskad8b0530f2021-10-19 15:12:3120#include "base/memory/safe_ref.h"
21#include "base/memory/weak_ptr.h"
danakjc492bf82020-09-09 20:02:4422#include "content/browser/renderer_host/navigator.h"
23#include "content/browser/renderer_host/navigator_delegate.h"
24#include "content/browser/renderer_host/render_frame_host_manager.h"
25#include "content/common/content_export.h"
26#include "mojo/public/cpp/bindings/pending_receiver.h"
27#include "services/service_manager/public/mojom/interface_provider.mojom.h"
Kevin McNee43fe8292021-10-04 22:59:4128#include "third_party/blink/public/common/frame/frame_owner_element_type.h"
Chris Hamilton3ff6ed0e2021-02-19 03:54:0429#include "third_party/blink/public/common/tokens/tokens.h"
danakjc492bf82020-09-09 20:02:4430#include "third_party/blink/public/mojom/frame/frame_owner_properties.mojom-forward.h"
31
32namespace blink {
Lei Zhang4a867672021-07-19 06:30:1433namespace mojom {
34class BrowserInterfaceBroker;
35enum class TreeScopeType;
36} // namespace mojom
37
danakjc492bf82020-09-09 20:02:4438struct FramePolicy;
39} // namespace blink
40
41namespace content {
42
Carlos Caballero40b0efd2021-01-26 11:55:0043class BrowserContext;
Jeremy Roman2d8dfe132021-07-06 20:51:2644class PageDelegate;
Lei Zhang4a867672021-07-19 06:30:1445class PageImpl;
danakjc492bf82020-09-09 20:02:4446class RenderFrameHostDelegate;
47class RenderViewHostDelegate;
48class RenderViewHostImpl;
49class RenderFrameHostManager;
50class RenderWidgetHostDelegate;
Carlos Caballero40b0efd2021-01-26 11:55:0051class SiteInstance;
danakjc492bf82020-09-09 20:02:4452
53// Represents the frame tree for a page. With the exception of the main frame,
54// all FrameTreeNodes will be created/deleted in response to frame attach and
55// detach events in the DOM.
56//
57// The main frame's FrameTreeNode is special in that it is reused. This allows
58// it to serve as an anchor for state that needs to persist across top-level
59// page navigations.
60//
61// TODO(ajwong): Move NavigationController ownership to the main frame
62// FrameTreeNode. Possibly expose access to it from here.
63//
64// This object is only used on the UI thread.
65class CONTENT_EXPORT FrameTree {
66 public:
67 class NodeRange;
68
69 class CONTENT_EXPORT NodeIterator
Kevin McNeeb110d0c2021-10-26 15:53:0070 : public std::iterator<std::forward_iterator_tag, FrameTreeNode*> {
danakjc492bf82020-09-09 20:02:4471 public:
72 NodeIterator(const NodeIterator& other);
73 ~NodeIterator();
74
75 NodeIterator& operator++();
Kevin McNee5f594382021-05-06 23:18:2376 // Advances the iterator and excludes the children of the current node
77 NodeIterator& AdvanceSkippingChildren();
danakjc492bf82020-09-09 20:02:4478
79 bool operator==(const NodeIterator& rhs) const;
80 bool operator!=(const NodeIterator& rhs) const { return !(*this == rhs); }
81
82 FrameTreeNode* operator*() { return current_node_; }
83
84 private:
Jayson Adams4db0bfe22021-07-15 19:24:0785 friend class FrameTreeTest;
danakjc492bf82020-09-09 20:02:4486 friend class NodeRange;
87
Kevin McNee5f594382021-05-06 23:18:2388 NodeIterator(const std::vector<FrameTreeNode*>& starting_nodes,
89 const FrameTreeNode* root_of_subtree_to_skip,
90 bool should_descend_into_inner_trees);
91
92 void AdvanceNode();
danakjc492bf82020-09-09 20:02:4493
Lukasz Anforowicz877e6222021-11-26 00:03:2394 // `current_node_` and `root_of_subtree_to_skip_` are not a raw_ptr<...> for
95 // performance reasons (based on analysis of sampling profiler data and
96 // tab_search:top100:2020).
danakjc492bf82020-09-09 20:02:4497 FrameTreeNode* current_node_;
Kevin McNee5f594382021-05-06 23:18:2398 const FrameTreeNode* const root_of_subtree_to_skip_;
Lukasz Anforowicz877e6222021-11-26 00:03:2399
Kevin McNee5f594382021-05-06 23:18:23100 const bool should_descend_into_inner_trees_;
Jayson Adams4db0bfe22021-07-15 19:24:07101 base::circular_deque<FrameTreeNode*> queue_;
danakjc492bf82020-09-09 20:02:44102 };
103
104 class CONTENT_EXPORT NodeRange {
105 public:
Kevin McNee5f594382021-05-06 23:18:23106 NodeRange(const NodeRange&);
107 ~NodeRange();
108
danakjc492bf82020-09-09 20:02:44109 NodeIterator begin();
110 NodeIterator end();
111
112 private:
113 friend class FrameTree;
114
Kevin McNee5f594382021-05-06 23:18:23115 NodeRange(const std::vector<FrameTreeNode*>& starting_nodes,
116 const FrameTreeNode* root_of_subtree_to_skip,
117 bool should_descend_into_inner_trees);
danakjc492bf82020-09-09 20:02:44118
Kevin McNee5f594382021-05-06 23:18:23119 const std::vector<FrameTreeNode*> starting_nodes_;
Keishi Hattori0e45c022021-11-27 09:25:52120 const raw_ptr<const FrameTreeNode> root_of_subtree_to_skip_;
Kevin McNee5f594382021-05-06 23:18:23121 const bool should_descend_into_inner_trees_;
danakjc492bf82020-09-09 20:02:44122 };
123
Carlos Caballero03262522021-02-05 14:49:58124 class CONTENT_EXPORT Delegate {
125 public:
126 // A RenderFrameHost in the specified |frame_tree_node| started loading a
127 // new document. This corresponds to browser UI starting to show a spinner
128 // or other visual indicator for loading. This method is only invoked if the
Nate Chapin9aabf5f2021-11-12 00:31:19129 // FrameTree hadn't been previously loading. |should_show_loading_ui| will
130 // be true unless the load is a fragment navigation, or triggered by
Carlos Caballero03262522021-02-05 14:49:58131 // history.pushState/replaceState.
132 virtual void DidStartLoading(FrameTreeNode* frame_tree_node,
Nate Chapin9aabf5f2021-11-12 00:31:19133 bool should_show_loading_ui) = 0;
Carlos Caballero03262522021-02-05 14:49:58134
Takashi Toyoshima74090df62021-03-09 14:34:57135 // This is called when all nodes in the FrameTree stopped loading. This
Carlos Caballero03262522021-02-05 14:49:58136 // corresponds to the browser UI stop showing a spinner or other visual
137 // indicator for loading.
138 virtual void DidStopLoading() = 0;
139
140 // The load progress was changed.
141 virtual void DidChangeLoadProgress() = 0;
Carlos Caballero6ff6ace2021-02-05 16:53:00142
143 // Returns true when the active RenderWidgetHostView should be hidden.
144 virtual bool IsHidden() = 0;
Sreeja Kamishettya21b4f62021-06-25 07:48:25145
Sreeja Kamishetty53468972021-07-13 11:53:32146 // Called when current Page of this frame tree changes to `page`.
147 virtual void NotifyPageChanged(PageImpl& page) = 0;
Dominic Farolinoedf44ee2021-07-20 23:50:59148
149 // If the FrameTree using this delegate is an inner/nested FrameTree, then
150 // there may be a FrameTreeNode in the outer FrameTree that is considered
151 // our outer delegate FrameTreeNode. This method returns the outer delegate
152 // FrameTreeNode ID if one exists. If we don't have a an outer delegate
153 // FrameTreeNode, this method returns
154 // FrameTreeNode::kFrameTreeNodeInvalidId.
155 virtual int GetOuterDelegateFrameTreeNodeId() = 0;
Dave Tapuskac8de3b02021-12-03 21:51:01156
157 // Returns if this FrameTree represents a portal.
158 virtual bool IsPortal() = 0;
Carlos Caballero03262522021-02-05 14:49:58159 };
160
Sreeja Kamishetty74bacd522021-03-22 17:04:24161 // Type of FrameTree instance.
162 enum class Type {
163 // This FrameTree is the primary frame tree for the WebContents, whose main
164 // document URL is shown in the Omnibox.
165 kPrimary,
166
167 // This FrameTree is used to prerender a page in the background which is
168 // invisible to the user.
Dominic Farolino4bc10ee2021-08-31 00:37:36169 kPrerender,
170
171 // This FrameTree is used to host the contents of a <fencedframe> element.
172 // Even for <fencedframe>s hosted inside a prerendered page, the FrameTree
173 // associated with the fenced frame will be kFencedFrame, but the
174 // RenderFrameHosts inside of it will have their lifecycle state set to
175 // `RenderFrameHost::LifecycleState::kActive`.
176 //
177 // TODO(crbug.com/1232528, crbug.com/1244274): We should either:
178 // * Fully support nested FrameTrees inside prerendered pages, in which
179 // case all of the RenderFrameHosts inside the nested trees should have
180 // their lifecycle state set to kPrerendering, or...
181 // * Ban nested FrameTrees in prerendered pages, and therefore obsolete the
182 // above paragraph about <fencedframe>s hosted in prerendered pages.
183 kFencedFrame
Sreeja Kamishetty74bacd522021-03-22 17:04:24184 };
Sreeja Kamishetty837a10402021-04-23 12:41:59185
186 // A set of delegates are remembered here so that we can create
187 // RenderFrameHostManagers.
188 FrameTree(BrowserContext* browser_context,
189 Delegate* delegate,
190 NavigationControllerDelegate* navigation_controller_delegate,
191 NavigatorDelegate* navigator_delegate,
192 RenderFrameHostDelegate* render_frame_delegate,
193 RenderViewHostDelegate* render_view_delegate,
194 RenderWidgetHostDelegate* render_widget_delegate,
195 RenderFrameHostManager::Delegate* manager_delegate,
Jeremy Roman2d8dfe132021-07-06 20:51:26196 PageDelegate* page_delegate,
Sreeja Kamishetty837a10402021-04-23 12:41:59197 Type type);
Peter Boström828b9022021-09-21 02:28:43198
199 FrameTree(const FrameTree&) = delete;
200 FrameTree& operator=(const FrameTree&) = delete;
201
Sreeja Kamishetty837a10402021-04-23 12:41:59202 ~FrameTree();
Sreeja Kamishetty74bacd522021-03-22 17:04:24203
Carlos Caballero40b0efd2021-01-26 11:55:00204 // Initializes the main frame for this FrameTree. That is it creates the
Rakina Zata Amniafd3c6582021-11-30 06:19:17205 // initial RenderFrameHost in the root node's RenderFrameHostManager, and also
Rakina Zata Amni2322f4f82022-01-24 13:24:24206 // creates an initial NavigationEntry (if the InitialNavigationEntry feature
207 // is enabled) that potentially inherits `opener`'s origin in its
208 // NavigationController. This method will call back into the delegates so it
209 // should only be called once they have completed their initialization. Pass
210 // in frame_policy so that it can be set in the root node's replication_state.
Carlos Caballero40b0efd2021-01-26 11:55:00211 // TODO(carlscab): It would be great if initialization could happened in the
212 // constructor so we do not leave objects in a half initialized state.
213 void Init(SiteInstance* main_frame_site_instance,
214 bool renderer_initiated_creation,
Rakina Zata Amniafd3c6582021-11-30 06:19:17215 const std::string& main_frame_name,
Harkiran Bolaria5ce27632022-01-20 15:05:05216 RenderFrameHostImpl* opener,
217 const blink::FramePolicy& frame_policy);
Sreeja Kamishetty837a10402021-04-23 12:41:59218
219 Type type() const { return type_; }
Carlos Caballero40b0efd2021-01-26 11:55:00220
danakjc492bf82020-09-09 20:02:44221 FrameTreeNode* root() const { return root_; }
222
Sreeja Kamishetty74bacd522021-03-22 17:04:24223 bool is_prerendering() const { return type_ == FrameTree::Type::kPrerender; }
Sreeja Kamishetty46f762c2021-02-05 07:52:46224
Carlos Caballero03262522021-02-05 14:49:58225 Delegate* delegate() { return delegate_; }
226
Jeremy Roman2d8dfe132021-07-06 20:51:26227 // Delegates for various objects. These can be kept centrally on the
228 // FrameTree because they are expected to be the same for all frames on a
229 // given FrameTree.
danakjc492bf82020-09-09 20:02:44230 RenderFrameHostDelegate* render_frame_delegate() {
231 return render_frame_delegate_;
232 }
233 RenderViewHostDelegate* render_view_delegate() {
234 return render_view_delegate_;
235 }
236 RenderWidgetHostDelegate* render_widget_delegate() {
237 return render_widget_delegate_;
238 }
239 RenderFrameHostManager::Delegate* manager_delegate() {
240 return manager_delegate_;
241 }
Jeremy Roman2d8dfe132021-07-06 20:51:26242 PageDelegate* page_delegate() { return page_delegate_; }
Aaron Colwell78b4bde2021-03-16 16:16:09243
Albert J. Wong1b6dc962021-07-09 18:06:57244 using RenderViewHostMapId = base::IdType32<class RenderViewHostMap>;
Sharon Yangc581a0c2021-11-02 18:09:39245
246 // SiteInstanceGroup IDs are used to look up RenderViewHosts, since there is
247 // one RenderViewHost per SiteInstanceGroup in a given FrameTree.
Aaron Colwell78b4bde2021-03-16 16:16:09248 using RenderViewHostMap = std::unordered_map<RenderViewHostMapId,
249 RenderViewHostImpl*,
250 RenderViewHostMapId::Hasher>;
251 const RenderViewHostMap& render_view_hosts() const {
danakjc492bf82020-09-09 20:02:44252 return render_view_host_map_;
253 }
254
255 // Returns the FrameTreeNode with the given |frame_tree_node_id| if it is part
256 // of this FrameTree.
257 FrameTreeNode* FindByID(int frame_tree_node_id);
258
259 // Returns the FrameTreeNode with the given renderer-specific |routing_id|.
260 FrameTreeNode* FindByRoutingID(int process_id, int routing_id);
261
262 // Returns the first frame in this tree with the given |name|, or the main
263 // frame if |name| is empty.
264 // Note that this does NOT support pseudo-names like _self, _top, and _blank,
265 // nor searching other FrameTrees (unlike blink::WebView::findFrameByName).
266 FrameTreeNode* FindByName(const std::string& name);
267
268 // Returns a range to iterate over all FrameTreeNodes in the frame tree in
269 // breadth-first traversal order.
270 NodeRange Nodes();
271
272 // Returns a range to iterate over all FrameTreeNodes in a subtree of the
273 // frame tree, starting from |subtree_root|.
274 NodeRange SubtreeNodes(FrameTreeNode* subtree_root);
275
Kevin McNee53f0b2d2021-11-02 18:00:45276 // Returns a range to iterate over all FrameTreeNodes in this frame tree, as
277 // well as any FrameTreeNodes of inner frame trees. Note that this includes
278 // inner frame trees of inner WebContents as well.
279 NodeRange NodesIncludingInnerTreeNodes();
280
Kevin McNee5f594382021-05-06 23:18:23281 // Returns a range to iterate over all FrameTreeNodes in a subtree, starting
282 // from, but not including |parent|, as well as any FrameTreeNodes of inner
Kevin McNee53f0b2d2021-11-02 18:00:45283 // frame trees. Note that this includes inner frame trees of inner WebContents
284 // as well.
Kevin McNee5f594382021-05-06 23:18:23285 static NodeRange SubtreeAndInnerTreeNodes(RenderFrameHostImpl* parent);
286
danakjc492bf82020-09-09 20:02:44287 // Adds a new child frame to the frame tree. |process_id| is required to
288 // disambiguate |new_routing_id|, and it must match the process of the
Kevin McNee43fe8292021-10-04 22:59:41289 // |parent| node. Otherwise no child is added and this method returns nullptr.
danakjc492bf82020-09-09 20:02:44290 // |interface_provider_receiver| is the receiver end of the InterfaceProvider
291 // interface through which the child RenderFrame can access Mojo services
292 // exposed by the corresponding RenderFrameHost. The caller takes care of
Antonio Sartoridb967c52021-01-20 09:54:30293 // sending the client end of the interface down to the
294 // RenderFrame. |policy_container_bind_params|, if not null, is used for
295 // binding Blink's policy container to the new RenderFrameHost's
296 // PolicyContainerHost. This is only needed if this frame is the result of the
297 // CreateChildFrame mojo call, which also delivers the
Kevin McNee43fe8292021-10-04 22:59:41298 // |policy_container_bind_params|. |is_dummy_frame_for_inner_tree| is true if
299 // the added frame is only to serve as a placeholder for an inner frame tree
300 // (e.g. fenced frames, portals) and will not have a live RenderFrame of its
301 // own.
danakjc492bf82020-09-09 20:02:44302 FrameTreeNode* AddFrame(
303 RenderFrameHostImpl* parent,
304 int process_id,
305 int new_routing_id,
danakj0bdfacd2021-01-20 19:27:18306 mojo::PendingAssociatedRemote<mojom::Frame> frame_remote,
danakjc492bf82020-09-09 20:02:44307 mojo::PendingReceiver<blink::mojom::BrowserInterfaceBroker>
308 browser_interface_broker_receiver,
Antonio Sartoridb967c52021-01-20 09:54:30309 blink::mojom::PolicyContainerBindParamsPtr policy_container_bind_params,
danakjc492bf82020-09-09 20:02:44310 blink::mojom::TreeScopeType scope,
311 const std::string& frame_name,
312 const std::string& frame_unique_name,
313 bool is_created_by_script,
Chris Hamilton3ff6ed0e2021-02-19 03:54:04314 const blink::LocalFrameToken& frame_token,
danakjc492bf82020-09-09 20:02:44315 const base::UnguessableToken& devtools_frame_token,
316 const blink::FramePolicy& frame_policy,
317 const blink::mojom::FrameOwnerProperties& frame_owner_properties,
318 bool was_discarded,
Kevin McNee43fe8292021-10-04 22:59:41319 blink::FrameOwnerElementType owner_type,
320 bool is_dummy_frame_for_inner_tree);
danakjc492bf82020-09-09 20:02:44321
322 // Removes a frame from the frame tree. |child|, its children, and objects
323 // owned by their RenderFrameHostManagers are immediately deleted. The root
324 // node cannot be removed this way.
325 void RemoveFrame(FrameTreeNode* child);
326
327 // This method walks the entire frame tree and creates a RenderFrameProxyHost
328 // for the given |site_instance| in each node except the |source| one --
329 // the source will have a RenderFrameHost. |source| may be null if there is
330 // no node navigating in this frame tree (such as when this is called
331 // for an opener's frame tree), in which case no nodes are skipped for
332 // RenderFrameProxyHost creation.
333 void CreateProxiesForSiteInstance(FrameTreeNode* source,
334 SiteInstance* site_instance);
335
336 // Convenience accessor for the main frame's RenderFrameHostImpl.
337 RenderFrameHostImpl* GetMainFrame() const;
338
339 // Returns the focused frame.
340 FrameTreeNode* GetFocusedFrame();
341
342 // Sets the focused frame to |node|. |source| identifies the SiteInstance
343 // that initiated this focus change. If this FrameTree has SiteInstances
344 // other than |source|, those SiteInstances will be notified about the new
345 // focused frame. Note that |source| may differ from |node|'s current
346 // SiteInstance (e.g., this happens for cross-process window.focus() calls).
347 void SetFocusedFrame(FrameTreeNode* node, SiteInstance* source);
348
danakjc492bf82020-09-09 20:02:44349 // Creates a RenderViewHostImpl for a given |site_instance| in the tree.
350 //
351 // The RenderFrameHostImpls and the RenderFrameProxyHosts will share ownership
352 // of this object.
353 scoped_refptr<RenderViewHostImpl> CreateRenderViewHost(
354 SiteInstance* site_instance,
355 int32_t main_frame_routing_id,
danakj08eb51d2020-12-30 20:15:23356 bool swapped_out,
357 bool renderer_initiated_creation);
danakjc492bf82020-09-09 20:02:44358
359 // Returns the existing RenderViewHost for a new RenderFrameHost.
360 // There should always be such a RenderViewHost, because the main frame
361 // RenderFrameHost for each SiteInstance should be created before subframes.
362 scoped_refptr<RenderViewHostImpl> GetRenderViewHost(
363 SiteInstance* site_instance);
364
Sharon Yangc581a0c2021-11-02 18:09:39365 // Returns the ID used for the RenderViewHost associated with
366 // |site_instance_group|.
367 RenderViewHostMapId GetRenderViewHostMapId(
368 SiteInstanceGroup* site_instance_group) const;
Aaron Colwell78b4bde2021-03-16 16:16:09369
danakjc492bf82020-09-09 20:02:44370 // Registers a RenderViewHost so that it can be reused by other frames
Aaron Colwell78b4bde2021-03-16 16:16:09371 // whose SiteInstance maps to the same RenderViewHostMapId.
danakjc492bf82020-09-09 20:02:44372 //
373 // This method does not take ownership of|rvh|.
374 //
375 // NOTE: This method CHECK fails if a RenderViewHost is already registered for
376 // |rvh|'s SiteInstance.
377 //
378 // ALSO NOTE: After calling RegisterRenderViewHost, UnregisterRenderViewHost
379 // *must* be called for |rvh| when it is destroyed or put into the
380 // BackForwardCache, to prevent FrameTree::CreateRenderViewHost from trying to
381 // reuse it.
Aaron Colwell78b4bde2021-03-16 16:16:09382 void RegisterRenderViewHost(RenderViewHostMapId id, RenderViewHostImpl* rvh);
danakjc492bf82020-09-09 20:02:44383
384 // Unregisters the RenderViewHostImpl that's available for reuse for a
Aaron Colwell78b4bde2021-03-16 16:16:09385 // particular RenderViewHostMapId. NOTE: This method CHECK fails if it is
386 // called for a |render_view_host| that is not currently set for reuse.
387 void UnregisterRenderViewHost(RenderViewHostMapId id,
Aaron Colwellc4bd7d62021-01-29 04:23:13388 RenderViewHostImpl* render_view_host);
danakjc492bf82020-09-09 20:02:44389
390 // This is called when the frame is about to be removed and started to run
391 // unload handlers.
392 void FrameUnloading(FrameTreeNode* frame);
393
394 // This is only meant to be called by FrameTreeNode. Triggers calling
395 // the listener installed by SetFrameRemoveListener.
396 void FrameRemoved(FrameTreeNode* frame);
397
Carlos Caballero03262522021-02-05 14:49:58398 void DidStartLoadingNode(FrameTreeNode& node,
Nate Chapin9aabf5f2021-11-12 00:31:19399 bool should_show_loading_ui,
Carlos Caballero03262522021-02-05 14:49:58400 bool was_previously_loading);
401 void DidStopLoadingNode(FrameTreeNode& node);
Carlos Caballero03262522021-02-05 14:49:58402 void DidCancelLoading();
danakjc492bf82020-09-09 20:02:44403
Sreeja Kamishetty0be3b1b2021-08-12 17:04:15404 // Returns this FrameTree's total load progress. If the `root_` FrameTreeNode
405 // is navigating returns `blink::kInitialLoadProgress`.
406 double GetLoadProgress();
danakjc492bf82020-09-09 20:02:44407
408 // Returns true if at least one of the nodes in this FrameTree is loading.
409 bool IsLoading() const;
410
411 // Set page-level focus in all SiteInstances involved in rendering
412 // this FrameTree, not including the current main frame's
413 // SiteInstance. The focus update will be sent via the main frame's proxies
414 // in those SiteInstances.
415 void ReplicatePageFocus(bool is_focused);
416
417 // Updates page-level focus for this FrameTree in the subframe renderer
418 // identified by |instance|.
419 void SetPageFocus(SiteInstance* instance, bool is_focused);
420
421 // Walks the current frame tree and registers any origins matching |origin|,
422 // either the last committed origin of a RenderFrameHost or the origin
423 // associated with a NavigationRequest that has been assigned to a
424 // SiteInstance, as not-opted-in for origin isolation.
425 void RegisterExistingOriginToPreventOptInIsolation(
426 const url::Origin& previously_visited_origin,
427 NavigationRequest* navigation_request_to_exclude);
428
Carlos Caballero40b0efd2021-01-26 11:55:00429 NavigationControllerImpl& controller() { return navigator_.controller(); }
danakjc492bf82020-09-09 20:02:44430 Navigator& navigator() { return navigator_; }
431
Carlos Caballeroede6f8c2021-01-28 11:01:50432 // Another page accessed the initial empty main document, which means it
433 // is no longer safe to display a pending URL without risking a URL spoof.
434 void DidAccessInitialMainDocument();
435
436 bool has_accessed_initial_main_document() const {
437 return has_accessed_initial_main_document_;
438 }
439
440 void ResetHasAccessedInitialMainDocument() {
441 has_accessed_initial_main_document_ = false;
442 }
443
Carlos Caballero6ff6ace2021-02-05 16:53:00444 bool IsHidden() const { return delegate_->IsHidden(); }
445
Carlos Caballero03262522021-02-05 14:49:58446 // Stops all ongoing navigations in each of the nodes of this FrameTree.
447 void StopLoading();
448
Carlos Caballero101ac26b2021-03-24 11:54:05449 // Prepares this frame tree for destruction, cleaning up the internal state
450 // and firing the appropriate events like FrameDeleted.
451 // Must be called before FrameTree is destroyed.
452 void Shutdown();
453
Takashi Toyoshimaea534ef22021-07-21 03:27:59454 bool IsBeingDestroyed() const { return is_being_destroyed_; }
455
Dave Tapuskad8b0530f2021-10-19 15:12:31456 base::SafeRef<FrameTree> GetSafeRef();
457
Dave Tapuska54c76a032021-10-27 22:10:42458 // Walks up the FrameTree chain and focuses the FrameTreeNode where
459 // each inner FrameTree is attached.
460 void FocusOuterFrameTrees();
461
danakjc492bf82020-09-09 20:02:44462 private:
463 friend class FrameTreeTest;
464 FRIEND_TEST_ALL_PREFIXES(RenderFrameHostImplBrowserTest, RemoveFocusedFrame);
465
466 // Returns a range to iterate over all FrameTreeNodes in the frame tree in
467 // breadth-first traversal order, skipping the subtree rooted at
468 // |node|, but including |node| itself.
469 NodeRange NodesExceptSubtree(FrameTreeNode* node);
470
Keishi Hattori0e45c022021-11-27 09:25:52471 const raw_ptr<Delegate> delegate_;
Carlos Caballero03262522021-02-05 14:49:58472
danakjc492bf82020-09-09 20:02:44473 // These delegates are installed into all the RenderViewHosts and
474 // RenderFrameHosts that we create.
Keishi Hattori0e45c022021-11-27 09:25:52475 raw_ptr<RenderFrameHostDelegate> render_frame_delegate_;
476 raw_ptr<RenderViewHostDelegate> render_view_delegate_;
477 raw_ptr<RenderWidgetHostDelegate> render_widget_delegate_;
478 raw_ptr<RenderFrameHostManager::Delegate> manager_delegate_;
479 raw_ptr<PageDelegate> page_delegate_;
danakjc492bf82020-09-09 20:02:44480
481 // The Navigator object responsible for managing navigations on this frame
Carlos Caballero40b0efd2021-01-26 11:55:00482 // tree. Each FrameTreeNode will default to using it for navigation tasks in
483 // the frame.
danakjc492bf82020-09-09 20:02:44484 Navigator navigator_;
485
Aaron Colwell78b4bde2021-03-16 16:16:09486 // Map of RenderViewHostMapId to RenderViewHost. This allows us to look up the
danakjc492bf82020-09-09 20:02:44487 // RenderViewHost for a given SiteInstance when creating RenderFrameHosts.
488 // Each RenderViewHost maintains a refcount and is deleted when there are no
489 // more RenderFrameHosts or RenderFrameProxyHosts using it.
Aaron Colwell78b4bde2021-03-16 16:16:09490 RenderViewHostMap render_view_host_map_;
danakjc492bf82020-09-09 20:02:44491
492 // This is an owned ptr to the root FrameTreeNode, which never changes over
493 // the lifetime of the FrameTree. It is not a scoped_ptr because we need the
494 // pointer to remain valid even while the FrameTreeNode is being destroyed,
495 // since it's common for a node to test whether it's the root node.
Keishi Hattori0e45c022021-11-27 09:25:52496 raw_ptr<FrameTreeNode> root_;
danakjc492bf82020-09-09 20:02:44497
498 int focused_frame_tree_node_id_;
499
danakjc492bf82020-09-09 20:02:44500 // Overall load progress.
501 double load_progress_;
502
Carlos Caballeroede6f8c2021-01-28 11:01:50503 // Whether the initial empty page has been accessed by another page, making it
504 // unsafe to show the pending URL. Usually false unless another window tries
505 // to modify the blank page. Always false after the first commit.
506 bool has_accessed_initial_main_document_ = false;
507
Sreeja Kamishetty837a10402021-04-23 12:41:59508 // Indicates type of frame tree.
509 const Type type_;
Sreeja Kamishetty74bacd522021-03-22 17:04:24510
Takashi Toyoshimaea534ef22021-07-21 03:27:59511 bool is_being_destroyed_ = false;
512
Carlos Caballero101ac26b2021-03-24 11:54:05513#if DCHECK_IS_ON()
514 // Whether Shutdown() was called.
515 bool was_shut_down_ = false;
516#endif
Dave Tapuskad8b0530f2021-10-19 15:12:31517
518 base::WeakPtrFactory<FrameTree> weak_ptr_factory_{this};
danakjc492bf82020-09-09 20:02:44519};
520
521} // namespace content
522
523#endif // CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_H_