[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [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 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 5 | #include "content/browser/renderer_host/frame_tree_node.h" |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 6 | |
Daniel Cheng | 6ca7f1c9 | 2017-08-09 21:45:41 | [diff] [blame] | 7 | #include <math.h> |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 8 | #include <queue> |
Takuto Ikuta | adf31eb | 2019-01-05 00:32:48 | [diff] [blame] | 9 | #include <unordered_map> |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 10 | #include <utility> |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 11 | |
Mustaq Ahmed | a5dfa60b | 2018-12-08 00:30:14 | [diff] [blame] | 12 | #include "base/feature_list.h" |
scottmg | 6ece5ae | 2017-02-01 18:25:19 | [diff] [blame] | 13 | #include "base/lazy_instance.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 14 | #include "base/macros.h" |
Liviu Tinta | d9391fb9 | 2020-09-28 23:50:07 | [diff] [blame] | 15 | #include "base/metrics/histogram_functions.h" |
dcheng | 23ca947d | 2016-05-04 20:04:15 | [diff] [blame] | 16 | #include "base/metrics/histogram_macros.h" |
Daniel Cheng | 6ca7f1c9 | 2017-08-09 21:45:41 | [diff] [blame] | 17 | #include "base/strings/string_util.h" |
Andrey Kosyakov | f2d4ff7 | 2018-10-29 20:09:59 | [diff] [blame] | 18 | #include "content/browser/devtools/devtools_instrumentation.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 19 | #include "content/browser/renderer_host/navigation_controller_impl.h" |
| 20 | #include "content/browser/renderer_host/navigation_request.h" |
| 21 | #include "content/browser/renderer_host/navigator.h" |
| 22 | #include "content/browser/renderer_host/navigator_delegate.h" |
| 23 | #include "content/browser/renderer_host/render_frame_host_impl.h" |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 24 | #include "content/browser/renderer_host/render_view_host_impl.h" |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 25 | #include "content/common/navigation_params_utils.h" |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 26 | #include "content/public/browser/browser_thread.h" |
Mustaq Ahmed | a5dfa60b | 2018-12-08 00:30:14 | [diff] [blame] | 27 | #include "content/public/common/content_features.h" |
arthursonzogni | b93a447 | 2020-04-10 07:38:00 | [diff] [blame] | 28 | #include "services/network/public/cpp/web_sandbox_flags.h" |
| 29 | #include "services/network/public/mojom/web_sandbox_flags.mojom-shared.h" |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 30 | #include "third_party/blink/public/common/features.h" |
Sreeja Kamishetty | 0be3b1b | 2021-08-12 17:04:15 | [diff] [blame] | 31 | #include "third_party/blink/public/common/loader/loader_constants.h" |
Antonio Gomes | 4b2c513 | 2020-01-16 11:49:48 | [diff] [blame] | 32 | #include "third_party/blink/public/mojom/frame/user_activation_update_types.mojom.h" |
Julie Jeongeun Kim | d90e2dd | 2020-03-03 11:45:37 | [diff] [blame] | 33 | #include "third_party/blink/public/mojom/security_context/insecure_request_policy.mojom.h" |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 34 | |
| 35 | namespace content { |
| 36 | |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 37 | namespace { |
| 38 | |
| 39 | // This is a global map between frame_tree_node_ids and pointers to |
| 40 | // FrameTreeNodes. |
Takuto Ikuta | adf31eb | 2019-01-05 00:32:48 | [diff] [blame] | 41 | typedef std::unordered_map<int, FrameTreeNode*> FrameTreeNodeIdMap; |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 42 | |
scottmg | 5e65e3a | 2017-03-08 08:48:46 | [diff] [blame] | 43 | base::LazyInstance<FrameTreeNodeIdMap>::DestructorAtExit |
| 44 | g_frame_tree_node_id_map = LAZY_INSTANCE_INITIALIZER; |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 45 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 46 | } // namespace |
fdegans | 1d1635516 | 2015-03-26 11:58:34 | [diff] [blame] | 47 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 48 | // This observer watches the opener of its owner FrameTreeNode and clears the |
| 49 | // owner's opener if the opener is destroyed. |
| 50 | class FrameTreeNode::OpenerDestroyedObserver : public FrameTreeNode::Observer { |
| 51 | public: |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 52 | OpenerDestroyedObserver(FrameTreeNode* owner, bool observing_original_opener) |
| 53 | : owner_(owner), observing_original_opener_(observing_original_opener) {} |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 54 | |
Peter Boström | 9b03653 | 2021-10-28 23:37:28 | [diff] [blame] | 55 | OpenerDestroyedObserver(const OpenerDestroyedObserver&) = delete; |
| 56 | OpenerDestroyedObserver& operator=(const OpenerDestroyedObserver&) = delete; |
| 57 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 58 | // FrameTreeNode::Observer |
| 59 | void OnFrameTreeNodeDestroyed(FrameTreeNode* node) override { |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 60 | if (observing_original_opener_) { |
Avi Drissman | 36465f33 | 2017-09-11 20:49:39 | [diff] [blame] | 61 | // The "original owner" is special. It's used for attribution, and clients |
| 62 | // walk down the original owner chain. Therefore, if a link in the chain |
| 63 | // is being destroyed, reconnect the observation to the parent of the link |
| 64 | // being destroyed. |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 65 | CHECK_EQ(owner_->original_opener(), node); |
Avi Drissman | 36465f33 | 2017-09-11 20:49:39 | [diff] [blame] | 66 | owner_->SetOriginalOpener(node->original_opener()); |
| 67 | // |this| is deleted at this point. |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 68 | } else { |
| 69 | CHECK_EQ(owner_->opener(), node); |
| 70 | owner_->SetOpener(nullptr); |
Avi Drissman | 36465f33 | 2017-09-11 20:49:39 | [diff] [blame] | 71 | // |this| is deleted at this point. |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 72 | } |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | private: |
| 76 | FrameTreeNode* owner_; |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 77 | bool observing_original_opener_; |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 78 | }; |
| 79 | |
Kevin McNee | 88e6155 | 2020-10-22 20:41:11 | [diff] [blame] | 80 | const int FrameTreeNode::kFrameTreeNodeInvalidId = -1; |
| 81 | |
| 82 | static_assert(FrameTreeNode::kFrameTreeNodeInvalidId == |
| 83 | RenderFrameHost::kNoFrameTreeNodeId, |
| 84 | "Have consistent sentinel values for an invalid FTN id."); |
| 85 | |
vishal.b | 782eb5d | 2015-04-29 12:22:57 | [diff] [blame] | 86 | int FrameTreeNode::next_frame_tree_node_id_ = 1; |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 87 | |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 88 | // static |
vishal.b | 782eb5d | 2015-04-29 12:22:57 | [diff] [blame] | 89 | FrameTreeNode* FrameTreeNode::GloballyFindByID(int frame_tree_node_id) { |
mostynb | 366eaf1 | 2015-03-26 00:51:19 | [diff] [blame] | 90 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
rob | 9725074 | 2015-12-10 17:45:15 | [diff] [blame] | 91 | FrameTreeNodeIdMap* nodes = g_frame_tree_node_id_map.Pointer(); |
jdoerrie | 55ec69d | 2018-10-08 13:34:46 | [diff] [blame] | 92 | auto it = nodes->find(frame_tree_node_id); |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 93 | return it == nodes->end() ? nullptr : it->second; |
| 94 | } |
| 95 | |
Alexander Timin | 381e7e18 | 2020-04-28 19:04:03 | [diff] [blame] | 96 | // static |
| 97 | FrameTreeNode* FrameTreeNode::From(RenderFrameHost* rfh) { |
| 98 | if (!rfh) |
| 99 | return nullptr; |
| 100 | return static_cast<RenderFrameHostImpl*>(rfh)->frame_tree_node(); |
| 101 | } |
| 102 | |
Julie Jeongeun Kim | 70a2e4e | 2020-02-21 05:09:54 | [diff] [blame] | 103 | FrameTreeNode::FrameTreeNode( |
| 104 | FrameTree* frame_tree, |
Alexander Timin | 381e7e18 | 2020-04-28 19:04:03 | [diff] [blame] | 105 | RenderFrameHostImpl* parent, |
Daniel Cheng | 6ac12817 | 2021-05-25 18:49:01 | [diff] [blame] | 106 | blink::mojom::TreeScopeType tree_scope_type, |
Julie Jeongeun Kim | 70a2e4e | 2020-02-21 05:09:54 | [diff] [blame] | 107 | const std::string& name, |
| 108 | const std::string& unique_name, |
| 109 | bool is_created_by_script, |
| 110 | const base::UnguessableToken& devtools_frame_token, |
| 111 | const blink::mojom::FrameOwnerProperties& frame_owner_properties, |
Kevin McNee | 43fe829 | 2021-10-04 22:59:41 | [diff] [blame] | 112 | blink::FrameOwnerElementType owner_type, |
Dominic Farolino | 08662c8 | 2021-06-11 07:36:34 | [diff] [blame] | 113 | const blink::FramePolicy& frame_policy) |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 114 | : frame_tree_(frame_tree), |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 115 | frame_tree_node_id_(next_frame_tree_node_id_++), |
xiaochengh | 9848816 | 2016-05-19 15:17:59 | [diff] [blame] | 116 | parent_(parent), |
Daniel Cheng | 9bd90f9 | 2021-04-23 20:49:45 | [diff] [blame] | 117 | frame_owner_element_type_(owner_type), |
Daniel Cheng | 6ac12817 | 2021-05-25 18:49:01 | [diff] [blame] | 118 | tree_scope_type_(tree_scope_type), |
Gyuyoung Kim | c16e52e9 | 2021-03-19 02:45:37 | [diff] [blame] | 119 | replication_state_(blink::mojom::FrameReplicationState::New( |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 120 | url::Origin(), |
estark | a886b8d | 2015-12-18 21:53:08 | [diff] [blame] | 121 | name, |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 122 | unique_name, |
Charlie Hu | e24f0483 | 2021-03-04 21:07:06 | [diff] [blame] | 123 | blink::ParsedPermissionsPolicy(), |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 124 | network::mojom::WebSandboxFlags::kNone, |
Dominic Farolino | 08662c8 | 2021-06-11 07:36:34 | [diff] [blame] | 125 | frame_policy, |
Daniel Cheng | 9bd90f9 | 2021-04-23 20:49:45 | [diff] [blame] | 126 | // should enforce strict mixed content checking |
| 127 | blink::mojom::InsecureRequestPolicy::kLeaveInsecureRequestsAlone, |
| 128 | // hashes of hosts for insecure request upgrades |
| 129 | std::vector<uint32_t>(), |
japhet | 61835ae1 | 2017-01-20 01:25:39 | [diff] [blame] | 130 | false /* is a potentially trustworthy unique origin */, |
danakj | 359a434 | 2020-05-29 20:38:39 | [diff] [blame] | 131 | false /* has an active user gesture */, |
Ehsan Karamad | 192a8da | 2018-10-21 03:48:08 | [diff] [blame] | 132 | false /* has received a user gesture before nav */, |
Alex Turner | 10d557a4 | 2021-06-01 19:06:49 | [diff] [blame] | 133 | false /* is_ad_subframe */)), |
Dominic Farolino | 08662c8 | 2021-06-11 07:36:34 | [diff] [blame] | 134 | pending_frame_policy_(frame_policy), |
Lukasz Anforowicz | 7bfb2e9 | 2017-11-22 17:19:45 | [diff] [blame] | 135 | is_created_by_script_(is_created_by_script), |
Pavel Feldman | 2523472 | 2017-10-11 02:49:06 | [diff] [blame] | 136 | devtools_frame_token_(devtools_frame_token), |
lazyboy | 70605c3 | 2015-11-03 01:27:31 | [diff] [blame] | 137 | frame_owner_properties_(frame_owner_properties), |
Lukasz Anforowicz | 14714196 | 2020-12-16 18:03:24 | [diff] [blame] | 138 | blame_context_(frame_tree_node_id_, FrameTreeNode::From(parent)), |
| 139 | render_manager_(this, frame_tree->manager_delegate()) { |
rob | 9725074 | 2015-12-10 17:45:15 | [diff] [blame] | 140 | std::pair<FrameTreeNodeIdMap::iterator, bool> result = |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 141 | g_frame_tree_node_id_map.Get().insert( |
| 142 | std::make_pair(frame_tree_node_id_, this)); |
| 143 | CHECK(result.second); |
benjhayden | d4da63d | 2016-03-11 21:29:33 | [diff] [blame] | 144 | |
xiaochengh | b9554bb | 2016-05-21 14:20:48 | [diff] [blame] | 145 | // Note: this should always be done last in the constructor. |
| 146 | blame_context_.Initialize(); |
alexmos | 998581d | 2015-01-22 01:01:59 | [diff] [blame] | 147 | } |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 148 | |
| 149 | FrameTreeNode::~FrameTreeNode() { |
Daniel Cheng | c3d1e8d | 2021-06-23 02:11:45 | [diff] [blame] | 150 | // There should always be a current RenderFrameHost except during prerender |
| 151 | // activation. Prerender activation moves the current RenderFrameHost from |
| 152 | // the old FrameTree's FrameTreeNode to the new FrameTree's FrameTreeNode and |
| 153 | // then destroys the old FrameTree. See |
| 154 | // `RenderFrameHostManager::TakePrerenderedPage()`. |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 155 | if (current_frame_host()) { |
| 156 | // Remove the children. |
| 157 | current_frame_host()->ResetChildren(); |
Lukasz Anforowicz | 7bfb2e9 | 2017-11-22 17:19:45 | [diff] [blame] | 158 | |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 159 | current_frame_host()->ResetLoadingState(); |
| 160 | } else { |
Hiroki Nakagawa | 0a90bd4 | 2021-04-21 01:53:05 | [diff] [blame] | 161 | DCHECK(blink::features::IsPrerender2Enabled()); |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 162 | DCHECK(!parent()); // Only main documents can be activated. |
| 163 | DCHECK(!opener()); // Prerendered frame trees can't have openers. |
| 164 | |
| 165 | // Activation is not allowed during ongoing navigations. |
| 166 | DCHECK(!navigation_request_); |
| 167 | |
Carlos Caballero | d1c8043 | 2021-04-20 08:16:32 | [diff] [blame] | 168 | // TODO(https://crbug.com/1199693): Need to determine how to handle pending |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 169 | // deletions, as observers will be notified. |
| 170 | DCHECK(!render_manager()->speculative_frame_host()); |
| 171 | } |
Nate Chapin | 22ea659 | 2019-03-05 22:29:02 | [diff] [blame] | 172 | |
Lukasz Anforowicz | 7bfb2e9 | 2017-11-22 17:19:45 | [diff] [blame] | 173 | // If the removed frame was created by a script, then its history entry will |
| 174 | // never be reused - we can save some memory by removing the history entry. |
| 175 | // See also https://crbug.com/784356. |
| 176 | if (is_created_by_script_ && parent_) { |
Carlos Caballero | 04aab36 | 2021-02-15 17:38:16 | [diff] [blame] | 177 | NavigationEntryImpl* nav_entry = |
| 178 | navigator().controller().GetLastCommittedEntry(); |
Lukasz Anforowicz | 7bfb2e9 | 2017-11-22 17:19:45 | [diff] [blame] | 179 | if (nav_entry) { |
| 180 | nav_entry->RemoveEntryForFrame(this, |
| 181 | /* only_if_different_position = */ false); |
| 182 | } |
| 183 | } |
| 184 | |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 185 | frame_tree_->FrameRemoved(this); |
Carlos Caballero | 6ff6ace | 2021-02-05 16:53:00 | [diff] [blame] | 186 | |
| 187 | // Do not dispatch notification for the root frame as ~WebContentsImpl already |
| 188 | // dispatches it for now. |
| 189 | // TODO(https://crbug.com/1170277): This is only needed because the FrameTree |
| 190 | // is a member of WebContentsImpl and we would call back into it during |
| 191 | // destruction. We should clean up the FrameTree destruction code and call the |
| 192 | // delegate unconditionally. |
| 193 | if (parent()) |
| 194 | render_manager_.delegate()->OnFrameTreeNodeDestroyed(this); |
| 195 | |
ericwilligers | 254597b | 2016-10-17 10:32:31 | [diff] [blame] | 196 | for (auto& observer : observers_) |
| 197 | observer.OnFrameTreeNodeDestroyed(this); |
Lukasz Anforowicz | 14714196 | 2020-12-16 18:03:24 | [diff] [blame] | 198 | observers_.Clear(); |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 199 | |
| 200 | if (opener_) |
| 201 | opener_->RemoveObserver(opener_observer_.get()); |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 202 | if (original_opener_) |
| 203 | original_opener_->RemoveObserver(original_opener_observer_.get()); |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 204 | |
| 205 | g_frame_tree_node_id_map.Get().erase(frame_tree_node_id_); |
jam | 39258caf | 2016-11-02 14:48:18 | [diff] [blame] | 206 | |
Daniel Cheng | c3d1e8d | 2021-06-23 02:11:45 | [diff] [blame] | 207 | // If a frame with a pending navigation is detached, make sure the |
| 208 | // WebContents (and its observers) update their loading state. |
| 209 | // TODO(dcheng): This should just check `IsLoading()`, but `IsLoading()` |
| 210 | // assumes that `current_frame_host_` is not null. This is incompatible with |
| 211 | // prerender activation when destroying the old frame tree (see above). |
danakj | f940060 | 2019-06-07 15:44:58 | [diff] [blame] | 212 | bool did_stop_loading = false; |
| 213 | |
jam | 39258caf | 2016-11-02 14:48:18 | [diff] [blame] | 214 | if (navigation_request_) { |
danakj | f940060 | 2019-06-07 15:44:58 | [diff] [blame] | 215 | navigation_request_.reset(); |
danakj | f940060 | 2019-06-07 15:44:58 | [diff] [blame] | 216 | did_stop_loading = true; |
jam | 39258caf | 2016-11-02 14:48:18 | [diff] [blame] | 217 | } |
Nate Chapin | 22ea659 | 2019-03-05 22:29:02 | [diff] [blame] | 218 | |
danakj | f940060 | 2019-06-07 15:44:58 | [diff] [blame] | 219 | // ~SiteProcessCountTracker DCHECKs in some tests if the speculative |
| 220 | // RenderFrameHostImpl is not destroyed last. Ideally this would be closer to |
| 221 | // (possible before) the ResetLoadingState() call above. |
danakj | f940060 | 2019-06-07 15:44:58 | [diff] [blame] | 222 | if (render_manager_.speculative_frame_host()) { |
Daniel Cheng | c3d1e8d | 2021-06-23 02:11:45 | [diff] [blame] | 223 | // TODO(dcheng): Shouldn't a FrameTreeNode with a speculative |
| 224 | // RenderFrameHost always be considered loading? |
danakj | f940060 | 2019-06-07 15:44:58 | [diff] [blame] | 225 | did_stop_loading |= render_manager_.speculative_frame_host()->is_loading(); |
Daniel Cheng | c3d1e8d | 2021-06-23 02:11:45 | [diff] [blame] | 226 | // `FrameTree::Shutdown()` has special handling for the main frame's |
| 227 | // speculative RenderFrameHost, and the speculative RenderFrameHost should |
| 228 | // already be reset for main frames. |
| 229 | DCHECK(!IsMainFrame()); |
| 230 | |
| 231 | // This does not use `UnsetSpeculativeRenderFrameHost()`: if the speculative |
| 232 | // RenderFrameHost has already reached kPendingCommit, it would needlessly |
| 233 | // re-create a proxy for a frame that's going away. |
| 234 | render_manager_.DiscardSpeculativeRenderFrameHostForShutdown(); |
danakj | f940060 | 2019-06-07 15:44:58 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | if (did_stop_loading) |
| 238 | DidStopLoading(); |
| 239 | |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 240 | // IsLoading() requires that current_frame_host() is non-null. |
| 241 | DCHECK(!current_frame_host() || !IsLoading()); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 242 | } |
| 243 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 244 | void FrameTreeNode::AddObserver(Observer* observer) { |
| 245 | observers_.AddObserver(observer); |
| 246 | } |
| 247 | |
| 248 | void FrameTreeNode::RemoveObserver(Observer* observer) { |
| 249 | observers_.RemoveObserver(observer); |
| 250 | } |
| 251 | |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 252 | bool FrameTreeNode::IsMainFrame() const { |
| 253 | return frame_tree_->root() == this; |
| 254 | } |
| 255 | |
Hiroki Nakagawa | ab30962 | 2021-05-19 16:38:13 | [diff] [blame] | 256 | void FrameTreeNode::ResetForNavigation() { |
arthursonzogni | 76098e5 | 2020-11-25 14:18:45 | [diff] [blame] | 257 | // This frame has had its user activation bits cleared in the renderer before |
| 258 | // arriving here. We just need to clear them here and in the other renderer |
| 259 | // processes that may have a reference to this frame. |
Alexander Timin | 45b716c | 2020-11-06 01:40:31 | [diff] [blame] | 260 | // |
| 261 | // We do not take user activation into account when calculating |
| 262 | // |ResetForNavigationResult|, as we are using it to determine bfcache |
| 263 | // eligibility and the page can get another user gesture after restore. |
Antonio Gomes | 4b2c513 | 2020-01-16 11:49:48 | [diff] [blame] | 264 | UpdateUserActivationState( |
Mustaq Ahmed | dc195e5b | 2020-08-04 18:45:11 | [diff] [blame] | 265 | blink::mojom::UserActivationUpdateType::kClearActivation, |
| 266 | blink::mojom::UserActivationNotificationType::kNone); |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 267 | } |
| 268 | |
yilkal | 34a3d75 | 2019-08-30 18:20:30 | [diff] [blame] | 269 | size_t FrameTreeNode::GetFrameTreeSize() const { |
| 270 | if (is_collapsed()) |
| 271 | return 0; |
| 272 | |
| 273 | size_t size = 0; |
| 274 | for (size_t i = 0; i < child_count(); i++) { |
| 275 | size += child_at(i)->GetFrameTreeSize(); |
| 276 | } |
| 277 | |
| 278 | // Account for this node. |
| 279 | size++; |
| 280 | return size; |
| 281 | } |
| 282 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 283 | void FrameTreeNode::SetOpener(FrameTreeNode* opener) { |
| 284 | if (opener_) { |
| 285 | opener_->RemoveObserver(opener_observer_.get()); |
| 286 | opener_observer_.reset(); |
| 287 | } |
| 288 | |
| 289 | opener_ = opener; |
| 290 | |
| 291 | if (opener_) { |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 292 | opener_observer_ = std::make_unique<OpenerDestroyedObserver>(this, false); |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 293 | opener_->AddObserver(opener_observer_.get()); |
| 294 | } |
| 295 | } |
| 296 | |
Wolfgang Beyer | d8809db | 2020-09-30 15:29:39 | [diff] [blame] | 297 | void FrameTreeNode::SetOpenerDevtoolsFrameToken( |
| 298 | base::UnguessableToken opener_devtools_frame_token) { |
| 299 | DCHECK(!opener_devtools_frame_token_ || |
| 300 | opener_devtools_frame_token_->is_empty()); |
| 301 | opener_devtools_frame_token_ = std::move(opener_devtools_frame_token); |
| 302 | } |
| 303 | |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 304 | void FrameTreeNode::SetOriginalOpener(FrameTreeNode* opener) { |
Avi Drissman | 36465f33 | 2017-09-11 20:49:39 | [diff] [blame] | 305 | // The original opener tracks main frames only. |
avi | 8d1aa16 | 2017-03-27 18:27:37 | [diff] [blame] | 306 | DCHECK(opener == nullptr || !opener->parent()); |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 307 | |
Avi Drissman | 36465f33 | 2017-09-11 20:49:39 | [diff] [blame] | 308 | if (original_opener_) { |
| 309 | original_opener_->RemoveObserver(original_opener_observer_.get()); |
| 310 | original_opener_observer_.reset(); |
| 311 | } |
| 312 | |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 313 | original_opener_ = opener; |
| 314 | |
| 315 | if (original_opener_) { |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 316 | original_opener_observer_ = |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 317 | std::make_unique<OpenerDestroyedObserver>(this, true); |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 318 | original_opener_->AddObserver(original_opener_observer_.get()); |
| 319 | } |
| 320 | } |
| 321 | |
creis | f0f069a | 2015-07-23 23:51:53 | [diff] [blame] | 322 | void FrameTreeNode::SetCurrentURL(const GURL& url) { |
Erik Chen | 173bf304 | 2017-07-31 06:06:21 | [diff] [blame] | 323 | current_frame_host()->SetLastCommittedUrl(url); |
xiaochengh | b9554bb | 2016-05-21 14:20:48 | [diff] [blame] | 324 | blame_context_.TakeSnapshot(); |
creis | f0f069a | 2015-07-23 23:51:53 | [diff] [blame] | 325 | } |
| 326 | |
Rakina Zata Amni | 86c88fa | 2021-11-01 01:27:30 | [diff] [blame] | 327 | void FrameTreeNode::DidCommitNonInitialEmptyDocument() { |
Rakina Zata Amni | 86c88fa | 2021-11-01 01:27:30 | [diff] [blame] | 328 | is_on_initial_empty_document_ = false; |
| 329 | } |
| 330 | |
estark | bd8e26f | 2016-03-16 23:30:37 | [diff] [blame] | 331 | void FrameTreeNode::SetCurrentOrigin( |
| 332 | const url::Origin& origin, |
| 333 | bool is_potentially_trustworthy_unique_origin) { |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 334 | if (!origin.IsSameOriginWith(replication_state_->origin) || |
| 335 | replication_state_->has_potentially_trustworthy_unique_origin != |
estark | bd8e26f | 2016-03-16 23:30:37 | [diff] [blame] | 336 | is_potentially_trustworthy_unique_origin) { |
| 337 | render_manager_.OnDidUpdateOrigin(origin, |
| 338 | is_potentially_trustworthy_unique_origin); |
| 339 | } |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 340 | replication_state_->origin = origin; |
| 341 | replication_state_->has_potentially_trustworthy_unique_origin = |
estark | bd8e26f | 2016-03-16 23:30:37 | [diff] [blame] | 342 | is_potentially_trustworthy_unique_origin; |
alexmos | a7a4ff82 | 2015-04-27 17:59:56 | [diff] [blame] | 343 | } |
alexmos | be2f4c3 | 2015-03-10 02:30:23 | [diff] [blame] | 344 | |
engedy | 6e2e099 | 2017-05-25 18:58:42 | [diff] [blame] | 345 | void FrameTreeNode::SetCollapsed(bool collapsed) { |
| 346 | DCHECK(!IsMainFrame()); |
| 347 | if (is_collapsed_ == collapsed) |
| 348 | return; |
| 349 | |
| 350 | is_collapsed_ = collapsed; |
| 351 | render_manager_.OnDidChangeCollapsedState(collapsed); |
| 352 | } |
| 353 | |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 354 | void FrameTreeNode::SetFrameTree(FrameTree& frame_tree) { |
Hiroki Nakagawa | 0a90bd4 | 2021-04-21 01:53:05 | [diff] [blame] | 355 | DCHECK(blink::features::IsPrerender2Enabled()); |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 356 | frame_tree_ = &frame_tree; |
Kevin McNee | b110d0c | 2021-10-26 15:53:00 | [diff] [blame] | 357 | DCHECK(current_frame_host()); |
| 358 | current_frame_host()->SetFrameTree(frame_tree); |
| 359 | RenderFrameHostImpl* speculative_frame_host = |
| 360 | render_manager_.speculative_frame_host(); |
| 361 | if (speculative_frame_host) |
| 362 | speculative_frame_host->SetFrameTree(frame_tree); |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 363 | } |
| 364 | |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 365 | void FrameTreeNode::SetFrameName(const std::string& name, |
| 366 | const std::string& unique_name) { |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 367 | if (name == replication_state_->name) { |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 368 | // |unique_name| shouldn't change unless |name| changes. |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 369 | DCHECK_EQ(unique_name, replication_state_->unique_name); |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 370 | return; |
| 371 | } |
lukasza | 5140a41 | 2016-09-15 21:12:30 | [diff] [blame] | 372 | |
| 373 | if (parent()) { |
| 374 | // Non-main frames should have a non-empty unique name. |
| 375 | DCHECK(!unique_name.empty()); |
| 376 | } else { |
| 377 | // Unique name of main frames should always stay empty. |
| 378 | DCHECK(unique_name.empty()); |
| 379 | } |
| 380 | |
Daniel Cheng | 6ca7f1c9 | 2017-08-09 21:45:41 | [diff] [blame] | 381 | // Note the unique name should only be able to change before the first real |
| 382 | // load is committed, but that's not strongly enforced here. |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 383 | render_manager_.OnDidUpdateName(name, unique_name); |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 384 | replication_state_->name = name; |
| 385 | replication_state_->unique_name = unique_name; |
alexmos | be2f4c3 | 2015-03-10 02:30:23 | [diff] [blame] | 386 | } |
| 387 | |
mkwst | f672e7ef | 2016-06-09 20:51:07 | [diff] [blame] | 388 | void FrameTreeNode::SetInsecureRequestPolicy( |
Julie Jeongeun Kim | d90e2dd | 2020-03-03 11:45:37 | [diff] [blame] | 389 | blink::mojom::InsecureRequestPolicy policy) { |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 390 | if (policy == replication_state_->insecure_request_policy) |
estark | a886b8d | 2015-12-18 21:53:08 | [diff] [blame] | 391 | return; |
mkwst | f672e7ef | 2016-06-09 20:51:07 | [diff] [blame] | 392 | render_manager_.OnEnforceInsecureRequestPolicy(policy); |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 393 | replication_state_->insecure_request_policy = policy; |
estark | a886b8d | 2015-12-18 21:53:08 | [diff] [blame] | 394 | } |
| 395 | |
arthursonzogni | 4b62a5cb | 2018-01-17 14:14:26 | [diff] [blame] | 396 | void FrameTreeNode::SetInsecureNavigationsSet( |
| 397 | const std::vector<uint32_t>& insecure_navigations_set) { |
| 398 | DCHECK(std::is_sorted(insecure_navigations_set.begin(), |
| 399 | insecure_navigations_set.end())); |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 400 | if (insecure_navigations_set == replication_state_->insecure_navigations_set) |
arthursonzogni | 4b62a5cb | 2018-01-17 14:14:26 | [diff] [blame] | 401 | return; |
| 402 | render_manager_.OnEnforceInsecureNavigationsSet(insecure_navigations_set); |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 403 | replication_state_->insecure_navigations_set = insecure_navigations_set; |
arthursonzogni | 4b62a5cb | 2018-01-17 14:14:26 | [diff] [blame] | 404 | } |
| 405 | |
Luna Lu | c3fdacdf | 2017-11-08 04:48:53 | [diff] [blame] | 406 | void FrameTreeNode::SetPendingFramePolicy(blink::FramePolicy frame_policy) { |
Dominic Farolino | 08662c8 | 2021-06-11 07:36:34 | [diff] [blame] | 407 | // The |is_fenced| bit should never be able to transition from what its |
| 408 | // initial value was. Since we never expect to be in a position where it can |
| 409 | // even be updated to new value, if we catch this happening we have to kill |
| 410 | // the renderer and refuse to accept any other frame policy changes here. |
| 411 | if (pending_frame_policy_.is_fenced != frame_policy.is_fenced) { |
| 412 | mojo::ReportBadMessage( |
| 413 | "The `is_fenced` FramePolicy bit is const and should never be changed"); |
| 414 | return; |
| 415 | } |
| 416 | |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 417 | pending_frame_policy_.sandbox_flags = frame_policy.sandbox_flags; |
alexmos | 6e94010 | 2016-01-19 22:47:25 | [diff] [blame] | 418 | |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 419 | if (parent()) { |
| 420 | // Subframes should always inherit their parent's sandbox flags. |
Alexander Timin | 381e7e18 | 2020-04-28 19:04:03 | [diff] [blame] | 421 | pending_frame_policy_.sandbox_flags |= |
| 422 | parent()->frame_tree_node()->active_sandbox_flags(); |
Charlie Hu | e1b77ac | 2019-12-13 21:30:17 | [diff] [blame] | 423 | // This is only applied on subframes; container policy and required document |
| 424 | // policy are not mutable on main frame. |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 425 | pending_frame_policy_.container_policy = frame_policy.container_policy; |
Charlie Hu | e1b77ac | 2019-12-13 21:30:17 | [diff] [blame] | 426 | pending_frame_policy_.required_document_policy = |
| 427 | frame_policy.required_document_policy; |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 428 | } |
iclelland | 92f8c0b | 2017-04-19 12:43:05 | [diff] [blame] | 429 | } |
| 430 | |
fdegans | 4a49ce93 | 2015-03-12 17:11:37 | [diff] [blame] | 431 | bool FrameTreeNode::IsLoading() const { |
| 432 | RenderFrameHostImpl* current_frame_host = |
| 433 | render_manager_.current_frame_host(); |
fdegans | 4a49ce93 | 2015-03-12 17:11:37 | [diff] [blame] | 434 | |
| 435 | DCHECK(current_frame_host); |
fdegans | 39ff038 | 2015-04-29 19:04:39 | [diff] [blame] | 436 | |
clamy | 610c63b3 | 2017-12-22 15:05:18 | [diff] [blame] | 437 | if (navigation_request_) |
| 438 | return true; |
clamy | 11e1151 | 2015-07-07 16:42:17 | [diff] [blame] | 439 | |
clamy | 610c63b3 | 2017-12-22 15:05:18 | [diff] [blame] | 440 | RenderFrameHostImpl* speculative_frame_host = |
| 441 | render_manager_.speculative_frame_host(); |
Daniel Cheng | c3d1e8d | 2021-06-23 02:11:45 | [diff] [blame] | 442 | // TODO(dcheng): Shouldn't a FrameTreeNode with a speculative RenderFrameHost |
| 443 | // always be considered loading? |
clamy | 610c63b3 | 2017-12-22 15:05:18 | [diff] [blame] | 444 | if (speculative_frame_host && speculative_frame_host->is_loading()) |
| 445 | return true; |
fdegans | 4a49ce93 | 2015-03-12 17:11:37 | [diff] [blame] | 446 | return current_frame_host->is_loading(); |
| 447 | } |
| 448 | |
Alex Moshchuk | 9b0fd82 | 2020-10-26 23:08:15 | [diff] [blame] | 449 | bool FrameTreeNode::HasPendingCrossDocumentNavigation() const { |
| 450 | // Having a |navigation_request_| on FrameTreeNode implies that there's an |
| 451 | // ongoing navigation that hasn't reached the ReadyToCommit state. If the |
| 452 | // navigation is between ReadyToCommit and DidCommitNavigation, the |
| 453 | // NavigationRequest will be held by RenderFrameHost, which is checked below. |
| 454 | if (navigation_request_ && !navigation_request_->IsSameDocument()) |
| 455 | return true; |
| 456 | |
| 457 | // Having a speculative RenderFrameHost should imply a cross-document |
| 458 | // navigation. |
| 459 | if (render_manager_.speculative_frame_host()) |
| 460 | return true; |
| 461 | |
| 462 | return render_manager_.current_frame_host() |
| 463 | ->HasPendingCommitForCrossDocumentNavigation(); |
| 464 | } |
| 465 | |
Charlie Hu | 5ffc015 | 2019-12-06 15:59:53 | [diff] [blame] | 466 | bool FrameTreeNode::CommitFramePolicy( |
| 467 | const blink::FramePolicy& new_frame_policy) { |
Arthur Sonzogni | 62f4f82 | 2021-10-21 11:44:35 | [diff] [blame] | 468 | // Documents create iframes, iframes host new documents. Both are associated |
| 469 | // with sandbox flags. They are required to be stricter or equal to their |
| 470 | // owner when they change, as we go down. |
| 471 | // TODO(https://crbug.com/1262061). Enforce the invariant mentioned above, |
| 472 | // once the interactions with FencedIframe has been tested and clarified. |
| 473 | |
Charlie Hu | 5ffc015 | 2019-12-06 15:59:53 | [diff] [blame] | 474 | bool did_change_flags = new_frame_policy.sandbox_flags != |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 475 | replication_state_->frame_policy.sandbox_flags; |
iclelland | 92f8c0b | 2017-04-19 12:43:05 | [diff] [blame] | 476 | bool did_change_container_policy = |
Charlie Hu | 5ffc015 | 2019-12-06 15:59:53 | [diff] [blame] | 477 | new_frame_policy.container_policy != |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 478 | replication_state_->frame_policy.container_policy; |
Charlie Hu | e1b77ac | 2019-12-13 21:30:17 | [diff] [blame] | 479 | bool did_change_required_document_policy = |
| 480 | pending_frame_policy_.required_document_policy != |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 481 | replication_state_->frame_policy.required_document_policy; |
Dominic Farolino | 08662c8 | 2021-06-11 07:36:34 | [diff] [blame] | 482 | DCHECK_EQ(new_frame_policy.is_fenced, |
| 483 | replication_state_->frame_policy.is_fenced); |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 484 | if (did_change_flags) { |
| 485 | replication_state_->frame_policy.sandbox_flags = |
Charlie Hu | 5ffc015 | 2019-12-06 15:59:53 | [diff] [blame] | 486 | new_frame_policy.sandbox_flags; |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 487 | } |
| 488 | if (did_change_container_policy) { |
| 489 | replication_state_->frame_policy.container_policy = |
Charlie Hu | 5ffc015 | 2019-12-06 15:59:53 | [diff] [blame] | 490 | new_frame_policy.container_policy; |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 491 | } |
| 492 | if (did_change_required_document_policy) { |
| 493 | replication_state_->frame_policy.required_document_policy = |
Charlie Hu | e1b77ac | 2019-12-13 21:30:17 | [diff] [blame] | 494 | new_frame_policy.required_document_policy; |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 495 | } |
Charlie Hu | e1b77ac | 2019-12-13 21:30:17 | [diff] [blame] | 496 | |
Charlie Hu | 5ffc015 | 2019-12-06 15:59:53 | [diff] [blame] | 497 | UpdateFramePolicyHeaders(new_frame_policy.sandbox_flags, |
Charlie Hu | e20fe2f | 2021-03-07 03:39:59 | [diff] [blame] | 498 | replication_state_->permissions_policy_header); |
Charlie Hu | e1b77ac | 2019-12-13 21:30:17 | [diff] [blame] | 499 | return did_change_flags || did_change_container_policy || |
Dave Tapuska | 7fdfc2f | 2021-06-08 17:38:40 | [diff] [blame] | 500 | did_change_required_document_policy; |
alexmos | 6b29456 | 2015-03-05 19:24:10 | [diff] [blame] | 501 | } |
| 502 | |
Arthur Hemery | c338017 | 2018-01-22 14:00:17 | [diff] [blame] | 503 | void FrameTreeNode::TransferNavigationRequestOwnership( |
| 504 | RenderFrameHostImpl* render_frame_host) { |
Andrey Kosyakov | f2d4ff7 | 2018-10-29 20:09:59 | [diff] [blame] | 505 | devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get()); |
Arthur Hemery | c338017 | 2018-01-22 14:00:17 | [diff] [blame] | 506 | render_frame_host->SetNavigationRequest(std::move(navigation_request_)); |
| 507 | } |
| 508 | |
carlosk | c49005eb | 2015-06-16 11:25:07 | [diff] [blame] | 509 | void FrameTreeNode::CreatedNavigationRequest( |
dcheng | 9bfa516 | 2016-04-09 01:00:57 | [diff] [blame] | 510 | std::unique_ptr<NavigationRequest> navigation_request) { |
arthursonzogni | c79c251c | 2016-08-18 15:00:37 | [diff] [blame] | 511 | // This is never called when navigating to a Javascript URL. For the loading |
| 512 | // state, this matches what Blink is doing: Blink doesn't send throbber |
| 513 | // notifications for Javascript URLS. |
| 514 | DCHECK(!navigation_request->common_params().url.SchemeIs( |
| 515 | url::kJavaScriptScheme)); |
| 516 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 517 | bool was_previously_loading = frame_tree()->IsLoading(); |
| 518 | |
clamy | 82a2f4d | 2016-02-02 14:20:41 | [diff] [blame] | 519 | // There's no need to reset the state: there's still an ongoing load, and the |
| 520 | // RenderFrameHostManager will take care of updates to the speculative |
| 521 | // RenderFrameHost in DidCreateNavigationRequest below. |
jam | cd0b7b2 | 2017-03-24 22:13:05 | [diff] [blame] | 522 | if (was_previously_loading) { |
Mohamed Abdelhalim | f03d4a2 | 2019-10-01 13:34:31 | [diff] [blame] | 523 | if (navigation_request_ && navigation_request_->IsNavigationStarted()) { |
jam | cd0b7b2 | 2017-03-24 22:13:05 | [diff] [blame] | 524 | // Mark the old request as aborted. |
Mohamed Abdelhalim | b4db22a | 2019-06-18 10:46:52 | [diff] [blame] | 525 | navigation_request_->set_net_error(net::ERR_ABORTED); |
jam | cd0b7b2 | 2017-03-24 22:13:05 | [diff] [blame] | 526 | } |
Arthur Hemery | 241b939 | 2019-10-24 11:08:41 | [diff] [blame] | 527 | ResetNavigationRequest(true); |
jam | cd0b7b2 | 2017-03-24 22:13:05 | [diff] [blame] | 528 | } |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 529 | |
| 530 | navigation_request_ = std::move(navigation_request); |
Shubhie Panicker | ddf2a4e | 2018-03-06 00:09:06 | [diff] [blame] | 531 | if (was_discarded_) { |
| 532 | navigation_request_->set_was_discarded(); |
| 533 | was_discarded_ = false; |
| 534 | } |
clamy | 8e2e29920 | 2016-04-05 11:44:59 | [diff] [blame] | 535 | render_manager()->DidCreateNavigationRequest(navigation_request_.get()); |
fdegans | 39ff038 | 2015-04-29 19:04:39 | [diff] [blame] | 536 | |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 537 | bool to_different_document = !NavigationTypeUtils::IsSameDocument( |
arthursonzogni | 92f1868 | 2017-02-08 23:00:04 | [diff] [blame] | 538 | navigation_request_->common_params().navigation_type); |
| 539 | |
| 540 | DidStartLoading(to_different_document, was_previously_loading); |
clamy | dcb434c1 | 2015-04-16 19:29:16 | [diff] [blame] | 541 | } |
| 542 | |
Arthur Hemery | 241b939 | 2019-10-24 11:08:41 | [diff] [blame] | 543 | void FrameTreeNode::ResetNavigationRequest(bool keep_state) { |
fdegans | 39ff038 | 2015-04-29 19:04:39 | [diff] [blame] | 544 | if (!navigation_request_) |
| 545 | return; |
John Abd-El-Malek | dcc7bf4 | 2017-09-12 22:30:23 | [diff] [blame] | 546 | |
Andrey Kosyakov | f2d4ff7 | 2018-10-29 20:09:59 | [diff] [blame] | 547 | devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get()); |
clamy | dcb434c1 | 2015-04-16 19:29:16 | [diff] [blame] | 548 | navigation_request_.reset(); |
fdegans | 39ff038 | 2015-04-29 19:04:39 | [diff] [blame] | 549 | |
clamy | 82a2f4d | 2016-02-02 14:20:41 | [diff] [blame] | 550 | if (keep_state) |
fdegans | 39ff038 | 2015-04-29 19:04:39 | [diff] [blame] | 551 | return; |
| 552 | |
clamy | 82a2f4d | 2016-02-02 14:20:41 | [diff] [blame] | 553 | // The RenderFrameHostManager should clean up any speculative RenderFrameHost |
| 554 | // it created for the navigation. Also register that the load stopped. |
fdegans | 39ff038 | 2015-04-29 19:04:39 | [diff] [blame] | 555 | DidStopLoading(); |
| 556 | render_manager_.CleanUpNavigation(); |
clamy | dcb434c1 | 2015-04-16 19:29:16 | [diff] [blame] | 557 | } |
| 558 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 559 | void FrameTreeNode::DidStartLoading(bool to_different_document, |
| 560 | bool was_previously_loading) { |
Camille Lamy | efd54b0 | 2018-10-04 16:54:14 | [diff] [blame] | 561 | TRACE_EVENT2("navigation", "FrameTreeNode::DidStartLoading", |
| 562 | "frame_tree_node", frame_tree_node_id(), "to different document", |
| 563 | to_different_document); |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 564 | |
Carlos Caballero | 0326252 | 2021-02-05 14:49:58 | [diff] [blame] | 565 | frame_tree_->DidStartLoadingNode(*this, to_different_document, |
| 566 | was_previously_loading); |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 567 | |
| 568 | // Set initial load progress and update overall progress. This will notify |
| 569 | // the WebContents of the load progress change. |
Sreeja Kamishetty | 0be3b1b | 2021-08-12 17:04:15 | [diff] [blame] | 570 | DidChangeLoadProgress(blink::kInitialLoadProgress); |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 571 | |
| 572 | // Notify the RenderFrameHostManager of the event. |
| 573 | render_manager()->OnDidStartLoading(); |
| 574 | } |
| 575 | |
| 576 | void FrameTreeNode::DidStopLoading() { |
Camille Lamy | efd54b0 | 2018-10-04 16:54:14 | [diff] [blame] | 577 | TRACE_EVENT1("navigation", "FrameTreeNode::DidStopLoading", "frame_tree_node", |
| 578 | frame_tree_node_id()); |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 579 | // Set final load progress and update overall progress. This will notify |
| 580 | // the WebContents of the load progress change. |
Sreeja Kamishetty | 0be3b1b | 2021-08-12 17:04:15 | [diff] [blame] | 581 | DidChangeLoadProgress(blink::kFinalLoadProgress); |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 582 | |
Lucas Furukawa Gadani | 6faef60 | 2019-05-06 21:16:03 | [diff] [blame] | 583 | // Notify the RenderFrameHostManager of the event. |
| 584 | render_manager()->OnDidStopLoading(); |
| 585 | |
Carlos Caballero | 0326252 | 2021-02-05 14:49:58 | [diff] [blame] | 586 | frame_tree_->DidStopLoadingNode(*this); |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | void FrameTreeNode::DidChangeLoadProgress(double load_progress) { |
Sreeja Kamishetty | 0be3b1b | 2021-08-12 17:04:15 | [diff] [blame] | 590 | DCHECK_GE(load_progress, blink::kInitialLoadProgress); |
| 591 | DCHECK_LE(load_progress, blink::kFinalLoadProgress); |
| 592 | current_frame_host()->DidChangeLoadProgress(load_progress); |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 593 | } |
| 594 | |
clamy | f73862c4 | 2015-07-08 12:31:33 | [diff] [blame] | 595 | bool FrameTreeNode::StopLoading() { |
arthursonzogni | 66f711c | 2019-10-08 14:40:36 | [diff] [blame] | 596 | if (navigation_request_ && navigation_request_->IsNavigationStarted()) |
| 597 | navigation_request_->set_net_error(net::ERR_ABORTED); |
Arthur Hemery | 241b939 | 2019-10-24 11:08:41 | [diff] [blame] | 598 | ResetNavigationRequest(false); |
clamy | f73862c4 | 2015-07-08 12:31:33 | [diff] [blame] | 599 | |
clamy | f73862c4 | 2015-07-08 12:31:33 | [diff] [blame] | 600 | if (!IsMainFrame()) |
| 601 | return true; |
| 602 | |
| 603 | render_manager_.Stop(); |
| 604 | return true; |
| 605 | } |
| 606 | |
alexmos | 21acae5 | 2015-11-07 01:04:43 | [diff] [blame] | 607 | void FrameTreeNode::DidFocus() { |
| 608 | last_focus_time_ = base::TimeTicks::Now(); |
ericwilligers | 254597b | 2016-10-17 10:32:31 | [diff] [blame] | 609 | for (auto& observer : observers_) |
| 610 | observer.OnFrameTreeNodeFocused(this); |
alexmos | 21acae5 | 2015-11-07 01:04:43 | [diff] [blame] | 611 | } |
| 612 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 613 | void FrameTreeNode::BeforeUnloadCanceled() { |
| 614 | // TODO(clamy): Support BeforeUnload in subframes. |
| 615 | if (!IsMainFrame()) |
| 616 | return; |
| 617 | |
| 618 | RenderFrameHostImpl* current_frame_host = |
| 619 | render_manager_.current_frame_host(); |
| 620 | DCHECK(current_frame_host); |
| 621 | current_frame_host->ResetLoadingState(); |
| 622 | |
clamy | 610c63b3 | 2017-12-22 15:05:18 | [diff] [blame] | 623 | RenderFrameHostImpl* speculative_frame_host = |
| 624 | render_manager_.speculative_frame_host(); |
| 625 | if (speculative_frame_host) |
| 626 | speculative_frame_host->ResetLoadingState(); |
Alexander Timin | 23c110b | 2021-01-14 02:39:04 | [diff] [blame] | 627 | // Note: there is no need to set an error code on the NavigationHandle as |
| 628 | // the observers have not been notified about its creation. |
| 629 | // We also reset navigation request only when this navigation request was |
| 630 | // responsible for this dialog, as a new navigation request might cancel |
| 631 | // existing unrelated dialog. |
| 632 | if (navigation_request_ && navigation_request_->IsWaitingForBeforeUnload()) |
Arthur Hemery | 241b939 | 2019-10-24 11:08:41 | [diff] [blame] | 633 | ResetNavigationRequest(false); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 634 | } |
| 635 | |
Mustaq Ahmed | ecb5c38e | 2020-07-29 00:34:30 | [diff] [blame] | 636 | bool FrameTreeNode::NotifyUserActivation( |
| 637 | blink::mojom::UserActivationNotificationType notification_type) { |
Alex Moshchuk | 0390419 | 2021-04-02 07:29:08 | [diff] [blame] | 638 | // User Activation V2 requires activating all ancestor frames in addition to |
| 639 | // the current frame. See |
| 640 | // https://html.spec.whatwg.org/multipage/interaction.html#tracking-user-activation. |
Alexander Timin | a1dfadaa | 2020-04-28 13:30:06 | [diff] [blame] | 641 | for (RenderFrameHostImpl* rfh = current_frame_host(); rfh; |
| 642 | rfh = rfh->GetParent()) { |
John Delaney | b625dca9 | 2021-04-14 17:00:34 | [diff] [blame] | 643 | rfh->DidReceiveUserActivation(); |
Mustaq Ahmed | ecb5c38e | 2020-07-29 00:34:30 | [diff] [blame] | 644 | rfh->frame_tree_node()->user_activation_state_.Activate(notification_type); |
John Delaney | edd8d6c | 2019-01-25 00:23:57 | [diff] [blame] | 645 | } |
Alex Moshchuk | 0390419 | 2021-04-02 07:29:08 | [diff] [blame] | 646 | |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 647 | replication_state_->has_active_user_gesture = true; |
Mustaq Ahmed | a5dfa60b | 2018-12-08 00:30:14 | [diff] [blame] | 648 | |
Mustaq Ahmed | 0180320f | 2019-03-21 16:07:01 | [diff] [blame] | 649 | // See the "Same-origin Visibility" section in |UserActivationState| class |
| 650 | // doc. |
Mustaq Ahmed | e5f1256 | 2019-10-30 18:02:03 | [diff] [blame] | 651 | if (base::FeatureList::IsEnabled( |
Mustaq Ahmed | a5dfa60b | 2018-12-08 00:30:14 | [diff] [blame] | 652 | features::kUserActivationSameOriginVisibility)) { |
| 653 | const url::Origin& current_origin = |
| 654 | this->current_frame_host()->GetLastCommittedOrigin(); |
| 655 | for (FrameTreeNode* node : frame_tree()->Nodes()) { |
| 656 | if (node->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith( |
| 657 | current_origin)) { |
Mustaq Ahmed | ecb5c38e | 2020-07-29 00:34:30 | [diff] [blame] | 658 | node->user_activation_state_.Activate(notification_type); |
Mustaq Ahmed | a5dfa60b | 2018-12-08 00:30:14 | [diff] [blame] | 659 | } |
| 660 | } |
| 661 | } |
| 662 | |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 663 | navigator().controller().NotifyUserActivation(); |
Alex Moshchuk | 0390419 | 2021-04-02 07:29:08 | [diff] [blame] | 664 | current_frame_host()->MaybeIsolateForUserActivation(); |
Shivani Sharma | 19487703 | 2019-03-07 17:52:47 | [diff] [blame] | 665 | |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 666 | return true; |
| 667 | } |
| 668 | |
| 669 | bool FrameTreeNode::ConsumeTransientUserActivation() { |
| 670 | bool was_active = user_activation_state_.IsActive(); |
| 671 | for (FrameTreeNode* node : frame_tree()->Nodes()) |
| 672 | node->user_activation_state_.ConsumeIfActive(); |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 673 | replication_state_->has_active_user_gesture = false; |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 674 | return was_active; |
| 675 | } |
| 676 | |
Shivani Sharma | c4f56158 | 2018-11-15 15:58:39 | [diff] [blame] | 677 | bool FrameTreeNode::ClearUserActivation() { |
Shivani Sharma | c4f56158 | 2018-11-15 15:58:39 | [diff] [blame] | 678 | for (FrameTreeNode* node : frame_tree()->SubtreeNodes(this)) |
| 679 | node->user_activation_state_.Clear(); |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 680 | replication_state_->has_active_user_gesture = false; |
Shivani Sharma | c4f56158 | 2018-11-15 15:58:39 | [diff] [blame] | 681 | return true; |
| 682 | } |
| 683 | |
Ella Ge | 9caed61 | 2019-08-09 16:17:25 | [diff] [blame] | 684 | bool FrameTreeNode::VerifyUserActivation() { |
Ella Ge | a78f677 | 2019-12-11 10:35:25 | [diff] [blame] | 685 | DCHECK(base::FeatureList::IsEnabled( |
| 686 | features::kBrowserVerifiedUserActivationMouse) || |
| 687 | base::FeatureList::IsEnabled( |
| 688 | features::kBrowserVerifiedUserActivationKeyboard)); |
| 689 | |
Ella Ge | 9caed61 | 2019-08-09 16:17:25 | [diff] [blame] | 690 | return render_manager_.current_frame_host() |
| 691 | ->GetRenderWidgetHost() |
Mustaq Ahmed | 83bb172 | 2019-10-22 20:00:10 | [diff] [blame] | 692 | ->RemovePendingUserActivationIfAvailable(); |
Ella Ge | 9caed61 | 2019-08-09 16:17:25 | [diff] [blame] | 693 | } |
| 694 | |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 695 | bool FrameTreeNode::UpdateUserActivationState( |
Mustaq Ahmed | dc195e5b | 2020-08-04 18:45:11 | [diff] [blame] | 696 | blink::mojom::UserActivationUpdateType update_type, |
| 697 | blink::mojom::UserActivationNotificationType notification_type) { |
Ella Ge | 9caed61 | 2019-08-09 16:17:25 | [diff] [blame] | 698 | bool update_result = false; |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 699 | switch (update_type) { |
Antonio Gomes | 4b2c513 | 2020-01-16 11:49:48 | [diff] [blame] | 700 | case blink::mojom::UserActivationUpdateType::kConsumeTransientActivation: |
Ella Ge | 9caed61 | 2019-08-09 16:17:25 | [diff] [blame] | 701 | update_result = ConsumeTransientUserActivation(); |
| 702 | break; |
Antonio Gomes | 4b2c513 | 2020-01-16 11:49:48 | [diff] [blame] | 703 | case blink::mojom::UserActivationUpdateType::kNotifyActivation: |
Mustaq Ahmed | dc195e5b | 2020-08-04 18:45:11 | [diff] [blame] | 704 | update_result = NotifyUserActivation(notification_type); |
Ella Ge | 9caed61 | 2019-08-09 16:17:25 | [diff] [blame] | 705 | break; |
Antonio Gomes | 4b2c513 | 2020-01-16 11:49:48 | [diff] [blame] | 706 | case blink::mojom::UserActivationUpdateType:: |
Liviu Tinta | d9391fb9 | 2020-09-28 23:50:07 | [diff] [blame] | 707 | kNotifyActivationPendingBrowserVerification: { |
| 708 | const bool user_activation_verified = VerifyUserActivation(); |
| 709 | // Add UMA metric for when browser user activation verification succeeds |
| 710 | base::UmaHistogramBoolean("Event.BrowserVerifiedUserActivation", |
| 711 | user_activation_verified); |
| 712 | if (user_activation_verified) { |
Mustaq Ahmed | ecb5c38e | 2020-07-29 00:34:30 | [diff] [blame] | 713 | update_result = NotifyUserActivation( |
Mustaq Ahmed | 2cfb040 | 2020-09-29 19:24:35 | [diff] [blame] | 714 | blink::mojom::UserActivationNotificationType::kInteraction); |
Antonio Gomes | 4b2c513 | 2020-01-16 11:49:48 | [diff] [blame] | 715 | update_type = blink::mojom::UserActivationUpdateType::kNotifyActivation; |
Ella Ge | 9caed61 | 2019-08-09 16:17:25 | [diff] [blame] | 716 | } else { |
arthursonzogni | 9816b919 | 2021-03-29 16:09:19 | [diff] [blame] | 717 | // TODO(https://crbug.com/848778): We need to decide what to do when |
| 718 | // user activation verification failed. NOTREACHED here will make all |
Ella Ge | 9caed61 | 2019-08-09 16:17:25 | [diff] [blame] | 719 | // unrelated tests that inject event to renderer fail. |
| 720 | return false; |
| 721 | } |
Liviu Tinta | d9391fb9 | 2020-09-28 23:50:07 | [diff] [blame] | 722 | } break; |
Antonio Gomes | 4b2c513 | 2020-01-16 11:49:48 | [diff] [blame] | 723 | case blink::mojom::UserActivationUpdateType::kClearActivation: |
Ella Ge | 9caed61 | 2019-08-09 16:17:25 | [diff] [blame] | 724 | update_result = ClearUserActivation(); |
| 725 | break; |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 726 | } |
Mustaq Ahmed | dc195e5b | 2020-08-04 18:45:11 | [diff] [blame] | 727 | render_manager_.UpdateUserActivationState(update_type, notification_type); |
Ella Ge | 9caed61 | 2019-08-09 16:17:25 | [diff] [blame] | 728 | return update_result; |
japhet | 61835ae1 | 2017-01-20 01:25:39 | [diff] [blame] | 729 | } |
| 730 | |
Mustaq Ahmed | 0126174 | 2019-12-16 15:49:06 | [diff] [blame] | 731 | void FrameTreeNode::OnSetHadStickyUserActivationBeforeNavigation(bool value) { |
| 732 | render_manager_.OnSetHadStickyUserActivationBeforeNavigation(value); |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 733 | replication_state_->has_received_user_gesture_before_nav = value; |
Becca Hughes | 60af7d4 | 2017-12-12 10:53:15 | [diff] [blame] | 734 | } |
| 735 | |
Alexander Timin | 45b716c | 2020-11-06 01:40:31 | [diff] [blame] | 736 | bool FrameTreeNode::UpdateFramePolicyHeaders( |
arthursonzogni | b93a447 | 2020-04-10 07:38:00 | [diff] [blame] | 737 | network::mojom::WebSandboxFlags sandbox_flags, |
Charlie Hu | e24f0483 | 2021-03-04 21:07:06 | [diff] [blame] | 738 | const blink::ParsedPermissionsPolicy& parsed_header) { |
Ian Clelland | edb8c5dd | 2018-03-01 17:01:37 | [diff] [blame] | 739 | bool changed = false; |
Charlie Hu | e20fe2f | 2021-03-07 03:39:59 | [diff] [blame] | 740 | if (replication_state_->permissions_policy_header != parsed_header) { |
| 741 | replication_state_->permissions_policy_header = parsed_header; |
Ian Clelland | edb8c5dd | 2018-03-01 17:01:37 | [diff] [blame] | 742 | changed = true; |
| 743 | } |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 744 | // TODO(iclelland): Kill the renderer if sandbox flags is not a subset of the |
| 745 | // currently effective sandbox flags from the frame. https://crbug.com/740556 |
arthursonzogni | b93a447 | 2020-04-10 07:38:00 | [diff] [blame] | 746 | network::mojom::WebSandboxFlags updated_flags = |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 747 | sandbox_flags | effective_frame_policy().sandbox_flags; |
Antonio Sartori | 90f4121 | 2021-01-22 10:08:34 | [diff] [blame] | 748 | if (replication_state_->active_sandbox_flags != updated_flags) { |
| 749 | replication_state_->active_sandbox_flags = updated_flags; |
Ian Clelland | edb8c5dd | 2018-03-01 17:01:37 | [diff] [blame] | 750 | changed = true; |
| 751 | } |
| 752 | // Notify any proxies if the policies have been changed. |
| 753 | if (changed) |
| 754 | render_manager()->OnDidSetFramePolicyHeaders(); |
Alexander Timin | 45b716c | 2020-11-06 01:40:31 | [diff] [blame] | 755 | return changed; |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 756 | } |
| 757 | |
Arthur Sonzogni | f8840b9 | 2018-11-07 14:10:35 | [diff] [blame] | 758 | void FrameTreeNode::PruneChildFrameNavigationEntries( |
| 759 | NavigationEntryImpl* entry) { |
| 760 | for (size_t i = 0; i < current_frame_host()->child_count(); ++i) { |
| 761 | FrameTreeNode* child = current_frame_host()->child_at(i); |
| 762 | if (child->is_created_by_script_) { |
| 763 | entry->RemoveEntryForFrame(child, |
| 764 | /* only_if_different_position = */ false); |
| 765 | } else { |
| 766 | child->PruneChildFrameNavigationEntries(entry); |
| 767 | } |
| 768 | } |
| 769 | } |
| 770 | |
Alex Turner | 10d557a4 | 2021-06-01 19:06:49 | [diff] [blame] | 771 | void FrameTreeNode::SetIsAdSubframe(bool is_ad_subframe) { |
| 772 | if (is_ad_subframe == replication_state_->is_ad_subframe) |
Alex Turner | 5a09c46 | 2021-03-17 17:07:35 | [diff] [blame] | 773 | return; |
| 774 | |
Alex Turner | 10d557a4 | 2021-06-01 19:06:49 | [diff] [blame] | 775 | replication_state_->is_ad_subframe = is_ad_subframe; |
| 776 | render_manager()->OnDidSetIsAdSubframe(is_ad_subframe); |
Yao Xiao | 24ec9aa | 2020-01-28 16:36:00 | [diff] [blame] | 777 | } |
| 778 | |
arthursonzogni | 034bb9c | 2020-10-01 08:29:56 | [diff] [blame] | 779 | void FrameTreeNode::SetInitialPopupURL(const GURL& initial_popup_url) { |
| 780 | DCHECK(initial_popup_url_.is_empty()); |
Rakina Zata Amni | 4182b03 | 2021-11-01 04:22:01 | [diff] [blame^] | 781 | DCHECK(is_on_initial_empty_document_); |
arthursonzogni | 034bb9c | 2020-10-01 08:29:56 | [diff] [blame] | 782 | initial_popup_url_ = initial_popup_url; |
| 783 | } |
| 784 | |
| 785 | void FrameTreeNode::SetPopupCreatorOrigin( |
| 786 | const url::Origin& popup_creator_origin) { |
Rakina Zata Amni | 4182b03 | 2021-11-01 04:22:01 | [diff] [blame^] | 787 | DCHECK(is_on_initial_empty_document_); |
arthursonzogni | 034bb9c | 2020-10-01 08:29:56 | [diff] [blame] | 788 | popup_creator_origin_ = popup_creator_origin; |
| 789 | } |
| 790 | |
Alexander Timin | bebb200 | 2021-04-20 15:42:24 | [diff] [blame] | 791 | void FrameTreeNode::WriteIntoTrace(perfetto::TracedValue context) const { |
Alexander Timin | f785f34 | 2021-03-18 00:00:56 | [diff] [blame] | 792 | auto dict = std::move(context).WriteDictionary(); |
| 793 | dict.Add("id", frame_tree_node_id()); |
| 794 | dict.Add("is_main_frame", IsMainFrame()); |
| 795 | } |
| 796 | |
Rakina Zata Amni | 4b1968d | 2021-09-09 03:29:47 | [diff] [blame] | 797 | void FrameTreeNode::WriteIntoTrace( |
| 798 | perfetto::TracedProto<perfetto::protos::pbzero::FrameTreeNodeInfo> proto) { |
| 799 | proto->set_is_main_frame(IsMainFrame()); |
| 800 | proto->set_frame_tree_node_id(frame_tree_node_id()); |
| 801 | proto->set_has_speculative_render_frame_host( |
| 802 | !!render_manager()->speculative_frame_host()); |
| 803 | } |
| 804 | |
Carlos Caballero | 7671135 | 2021-03-24 17:38:21 | [diff] [blame] | 805 | bool FrameTreeNode::HasNavigation() { |
| 806 | if (navigation_request()) |
| 807 | return true; |
| 808 | |
| 809 | // Same-RenderFrameHost navigation is committing: |
| 810 | if (current_frame_host()->HasPendingCommitNavigation()) |
| 811 | return true; |
| 812 | |
| 813 | // Cross-RenderFrameHost navigation is committing: |
| 814 | if (render_manager()->speculative_frame_host()) |
| 815 | return true; |
| 816 | |
| 817 | return false; |
| 818 | } |
| 819 | |
Dominic Farolino | 4bc10ee | 2021-08-31 00:37:36 | [diff] [blame] | 820 | bool FrameTreeNode::IsFencedFrameRoot() const { |
shivanigithub | f3ddff5 | 2021-07-03 22:06:30 | [diff] [blame] | 821 | if (!blink::features::IsFencedFramesEnabled()) |
| 822 | return false; |
| 823 | |
| 824 | switch (blink::features::kFencedFramesImplementationTypeParam.Get()) { |
| 825 | case blink::features::FencedFramesImplementationType::kMPArch: { |
Dominic Farolino | 4bc10ee | 2021-08-31 00:37:36 | [diff] [blame] | 826 | return IsMainFrame() && |
| 827 | frame_tree()->type() == FrameTree::Type::kFencedFrame; |
shivanigithub | f3ddff5 | 2021-07-03 22:06:30 | [diff] [blame] | 828 | } |
| 829 | case blink::features::FencedFramesImplementationType::kShadowDOM: { |
| 830 | return effective_frame_policy().is_fenced; |
| 831 | } |
| 832 | default: |
| 833 | return false; |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | bool FrameTreeNode::IsInFencedFrameTree() const { |
| 838 | if (!blink::features::IsFencedFramesEnabled()) |
| 839 | return false; |
| 840 | |
| 841 | switch (blink::features::kFencedFramesImplementationTypeParam.Get()) { |
| 842 | case blink::features::FencedFramesImplementationType::kMPArch: |
Dominic Farolino | 4bc10ee | 2021-08-31 00:37:36 | [diff] [blame] | 843 | return frame_tree()->type() == FrameTree::Type::kFencedFrame; |
shivanigithub | f3ddff5 | 2021-07-03 22:06:30 | [diff] [blame] | 844 | case blink::features::FencedFramesImplementationType::kShadowDOM: { |
| 845 | auto* node = this; |
| 846 | while (node) { |
| 847 | if (node->effective_frame_policy().is_fenced) { |
| 848 | return true; |
| 849 | } |
| 850 | node = node->parent() ? node->parent()->frame_tree_node() : nullptr; |
| 851 | } |
| 852 | return false; |
| 853 | } |
| 854 | default: |
| 855 | return false; |
| 856 | } |
| 857 | } |
| 858 | |
shivanigithub | 4cd016a | 2021-09-20 21:10:30 | [diff] [blame] | 859 | void FrameTreeNode::SetFencedFrameNonceIfNeeded() { |
| 860 | if (!IsInFencedFrameTree()) { |
| 861 | return; |
| 862 | } |
| 863 | |
| 864 | if (IsFencedFrameRoot()) { |
| 865 | fenced_frame_nonce_ = base::UnguessableToken::Create(); |
| 866 | return; |
| 867 | } |
| 868 | |
| 869 | // For nested iframes in a fenced frame tree, propagate the same nonce as was |
| 870 | // set in the fenced frame root. |
| 871 | DCHECK(parent_); |
| 872 | absl::optional<base::UnguessableToken> nonce = |
| 873 | parent_->frame_tree_node()->fenced_frame_nonce(); |
| 874 | DCHECK(nonce.has_value()); |
| 875 | fenced_frame_nonce_ = nonce; |
| 876 | } |
| 877 | |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 878 | } // namespace content |