[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> |
| 8 | |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 9 | #include <queue> |
Takuto Ikuta | adf31eb | 2019-01-05 00:32:48 | [diff] [blame] | 10 | #include <unordered_map> |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 11 | #include <utility> |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 12 | |
Mustaq Ahmed | a5dfa60b | 2018-12-08 00:30:14 | [diff] [blame] | 13 | #include "base/feature_list.h" |
scottmg | 6ece5ae | 2017-02-01 18:25:19 | [diff] [blame] | 14 | #include "base/lazy_instance.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 15 | #include "base/macros.h" |
Liviu Tinta | d9391fb9 | 2020-09-28 23:50:07 | [diff] [blame] | 16 | #include "base/metrics/histogram_functions.h" |
dcheng | 23ca947d | 2016-05-04 20:04:15 | [diff] [blame] | 17 | #include "base/metrics/histogram_macros.h" |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 18 | #include "base/stl_util.h" |
Daniel Cheng | 6ca7f1c9 | 2017-08-09 21:45:41 | [diff] [blame] | 19 | #include "base/strings/string_util.h" |
Andrey Kosyakov | f2d4ff7 | 2018-10-29 20:09:59 | [diff] [blame] | 20 | #include "content/browser/devtools/devtools_instrumentation.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 21 | #include "content/browser/renderer_host/navigation_controller_impl.h" |
| 22 | #include "content/browser/renderer_host/navigation_request.h" |
| 23 | #include "content/browser/renderer_host/navigator.h" |
| 24 | #include "content/browser/renderer_host/navigator_delegate.h" |
| 25 | #include "content/browser/renderer_host/render_frame_host_impl.h" |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 26 | #include "content/browser/renderer_host/render_view_host_impl.h" |
clamy | f73862c4 | 2015-07-08 12:31:33 | [diff] [blame] | 27 | #include "content/common/frame_messages.h" |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 28 | #include "content/common/navigation_params.h" |
| 29 | #include "content/common/navigation_params_utils.h" |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 30 | #include "content/public/browser/browser_thread.h" |
Mustaq Ahmed | a5dfa60b | 2018-12-08 00:30:14 | [diff] [blame] | 31 | #include "content/public/common/content_features.h" |
Arthur Sonzogni | f21fb51 | 2018-11-06 09:31:58 | [diff] [blame] | 32 | #include "content/public/common/navigation_policy.h" |
arthursonzogni | b93a447 | 2020-04-10 07:38:00 | [diff] [blame] | 33 | #include "services/network/public/cpp/web_sandbox_flags.h" |
| 34 | #include "services/network/public/mojom/web_sandbox_flags.mojom-shared.h" |
Antonio Gomes | 4b2c513 | 2020-01-16 11:49:48 | [diff] [blame] | 35 | #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] | 36 | #include "third_party/blink/public/mojom/security_context/insecure_request_policy.mojom.h" |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 37 | |
| 38 | namespace content { |
| 39 | |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 40 | namespace { |
| 41 | |
| 42 | // This is a global map between frame_tree_node_ids and pointers to |
| 43 | // FrameTreeNodes. |
Takuto Ikuta | adf31eb | 2019-01-05 00:32:48 | [diff] [blame] | 44 | typedef std::unordered_map<int, FrameTreeNode*> FrameTreeNodeIdMap; |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 45 | |
scottmg | 5e65e3a | 2017-03-08 08:48:46 | [diff] [blame] | 46 | base::LazyInstance<FrameTreeNodeIdMap>::DestructorAtExit |
| 47 | g_frame_tree_node_id_map = LAZY_INSTANCE_INITIALIZER; |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 48 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 49 | // These values indicate the loading progress status. The minimum progress |
| 50 | // value matches what Blink's ProgressTracker has traditionally used for a |
| 51 | // minimum progress value. |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 52 | const double kLoadingProgressMinimum = 0.1; |
| 53 | const double kLoadingProgressDone = 1.0; |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 54 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 55 | } // namespace |
fdegans | 1d1635516 | 2015-03-26 11:58:34 | [diff] [blame] | 56 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 57 | // This observer watches the opener of its owner FrameTreeNode and clears the |
| 58 | // owner's opener if the opener is destroyed. |
| 59 | class FrameTreeNode::OpenerDestroyedObserver : public FrameTreeNode::Observer { |
| 60 | public: |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 61 | OpenerDestroyedObserver(FrameTreeNode* owner, bool observing_original_opener) |
| 62 | : owner_(owner), observing_original_opener_(observing_original_opener) {} |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 63 | |
| 64 | // FrameTreeNode::Observer |
| 65 | void OnFrameTreeNodeDestroyed(FrameTreeNode* node) override { |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 66 | if (observing_original_opener_) { |
Avi Drissman | 36465f33 | 2017-09-11 20:49:39 | [diff] [blame] | 67 | // The "original owner" is special. It's used for attribution, and clients |
| 68 | // walk down the original owner chain. Therefore, if a link in the chain |
| 69 | // is being destroyed, reconnect the observation to the parent of the link |
| 70 | // being destroyed. |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 71 | CHECK_EQ(owner_->original_opener(), node); |
Avi Drissman | 36465f33 | 2017-09-11 20:49:39 | [diff] [blame] | 72 | owner_->SetOriginalOpener(node->original_opener()); |
| 73 | // |this| is deleted at this point. |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 74 | } else { |
| 75 | CHECK_EQ(owner_->opener(), node); |
| 76 | owner_->SetOpener(nullptr); |
Avi Drissman | 36465f33 | 2017-09-11 20:49:39 | [diff] [blame] | 77 | // |this| is deleted at this point. |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 78 | } |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | private: |
| 82 | FrameTreeNode* owner_; |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 83 | bool observing_original_opener_; |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 84 | |
| 85 | DISALLOW_COPY_AND_ASSIGN(OpenerDestroyedObserver); |
| 86 | }; |
| 87 | |
Kevin McNee | 88e6155 | 2020-10-22 20:41:11 | [diff] [blame^] | 88 | const int FrameTreeNode::kFrameTreeNodeInvalidId = -1; |
| 89 | |
| 90 | static_assert(FrameTreeNode::kFrameTreeNodeInvalidId == |
| 91 | RenderFrameHost::kNoFrameTreeNodeId, |
| 92 | "Have consistent sentinel values for an invalid FTN id."); |
| 93 | |
vishal.b | 782eb5d | 2015-04-29 12:22:57 | [diff] [blame] | 94 | int FrameTreeNode::next_frame_tree_node_id_ = 1; |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 95 | |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 96 | // static |
vishal.b | 782eb5d | 2015-04-29 12:22:57 | [diff] [blame] | 97 | FrameTreeNode* FrameTreeNode::GloballyFindByID(int frame_tree_node_id) { |
mostynb | 366eaf1 | 2015-03-26 00:51:19 | [diff] [blame] | 98 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
rob | 9725074 | 2015-12-10 17:45:15 | [diff] [blame] | 99 | FrameTreeNodeIdMap* nodes = g_frame_tree_node_id_map.Pointer(); |
jdoerrie | 55ec69d | 2018-10-08 13:34:46 | [diff] [blame] | 100 | auto it = nodes->find(frame_tree_node_id); |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 101 | return it == nodes->end() ? nullptr : it->second; |
| 102 | } |
| 103 | |
Alexander Timin | 381e7e18 | 2020-04-28 19:04:03 | [diff] [blame] | 104 | // static |
| 105 | FrameTreeNode* FrameTreeNode::From(RenderFrameHost* rfh) { |
| 106 | if (!rfh) |
| 107 | return nullptr; |
| 108 | return static_cast<RenderFrameHostImpl*>(rfh)->frame_tree_node(); |
| 109 | } |
| 110 | |
Julie Jeongeun Kim | 70a2e4e | 2020-02-21 05:09:54 | [diff] [blame] | 111 | FrameTreeNode::FrameTreeNode( |
| 112 | FrameTree* frame_tree, |
Alexander Timin | 381e7e18 | 2020-04-28 19:04:03 | [diff] [blame] | 113 | RenderFrameHostImpl* parent, |
Antonio Gomes | 9d5c1ef | 2020-04-30 20:56:41 | [diff] [blame] | 114 | blink::mojom::TreeScopeType scope, |
Julie Jeongeun Kim | 70a2e4e | 2020-02-21 05:09:54 | [diff] [blame] | 115 | const std::string& name, |
| 116 | const std::string& unique_name, |
| 117 | bool is_created_by_script, |
| 118 | const base::UnguessableToken& devtools_frame_token, |
| 119 | const blink::mojom::FrameOwnerProperties& frame_owner_properties, |
Antonio Gomes | 58d3806 | 2020-04-30 01:50:14 | [diff] [blame] | 120 | blink::mojom::FrameOwnerElementType owner_type) |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 121 | : frame_tree_(frame_tree), |
Lucas Furukawa Gadani | 72cc21c | 2018-09-04 18:50:46 | [diff] [blame] | 122 | render_manager_(this, frame_tree->manager_delegate()), |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 123 | frame_tree_node_id_(next_frame_tree_node_id_++), |
xiaochengh | 9848816 | 2016-05-19 15:17:59 | [diff] [blame] | 124 | parent_(parent), |
Alexander Timin | 381e7e18 | 2020-04-28 19:04:03 | [diff] [blame] | 125 | depth_(parent ? parent->frame_tree_node()->depth_ + 1 : 0u), |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 126 | opener_(nullptr), |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 127 | original_opener_(nullptr), |
creis | f0f069a | 2015-07-23 23:51:53 | [diff] [blame] | 128 | has_committed_real_load_(false), |
engedy | 6e2e099 | 2017-05-25 18:58:42 | [diff] [blame] | 129 | is_collapsed_(false), |
estark | a886b8d | 2015-12-18 21:53:08 | [diff] [blame] | 130 | replication_state_( |
| 131 | scope, |
| 132 | name, |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 133 | unique_name, |
Julie Jeongeun Kim | d90e2dd | 2020-03-03 11:45:37 | [diff] [blame] | 134 | blink::mojom::InsecureRequestPolicy:: |
| 135 | kLeaveInsecureRequestsAlone /* should enforce strict mixed content |
| 136 | checking */ |
| 137 | , |
arthursonzogni | 4b62a5cb | 2018-01-17 14:14:26 | [diff] [blame] | 138 | std::vector<uint32_t>() |
| 139 | /* hashes of hosts for insecure request upgrades */, |
japhet | 61835ae1 | 2017-01-20 01:25:39 | [diff] [blame] | 140 | false /* is a potentially trustworthy unique origin */, |
danakj | 359a434 | 2020-05-29 20:38:39 | [diff] [blame] | 141 | false /* has an active user gesture */, |
Ehsan Karamad | 192a8da | 2018-10-21 03:48:08 | [diff] [blame] | 142 | false /* has received a user gesture before nav */, |
| 143 | owner_type), |
Lukasz Anforowicz | 7bfb2e9 | 2017-11-22 17:19:45 | [diff] [blame] | 144 | is_created_by_script_(is_created_by_script), |
Pavel Feldman | 2523472 | 2017-10-11 02:49:06 | [diff] [blame] | 145 | devtools_frame_token_(devtools_frame_token), |
lazyboy | 70605c3 | 2015-11-03 01:27:31 | [diff] [blame] | 146 | frame_owner_properties_(frame_owner_properties), |
Shubhie Panicker | ddf2a4e | 2018-03-06 00:09:06 | [diff] [blame] | 147 | was_discarded_(false), |
Alexander Timin | 381e7e18 | 2020-04-28 19:04:03 | [diff] [blame] | 148 | blame_context_(frame_tree_node_id_, FrameTreeNode::From(parent)) { |
rob | 9725074 | 2015-12-10 17:45:15 | [diff] [blame] | 149 | std::pair<FrameTreeNodeIdMap::iterator, bool> result = |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 150 | g_frame_tree_node_id_map.Get().insert( |
| 151 | std::make_pair(frame_tree_node_id_, this)); |
| 152 | CHECK(result.second); |
benjhayden | d4da63d | 2016-03-11 21:29:33 | [diff] [blame] | 153 | |
xiaochengh | b9554bb | 2016-05-21 14:20:48 | [diff] [blame] | 154 | // Note: this should always be done last in the constructor. |
| 155 | blame_context_.Initialize(); |
alexmos | 998581d | 2015-01-22 01:01:59 | [diff] [blame] | 156 | } |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 157 | |
| 158 | FrameTreeNode::~FrameTreeNode() { |
Nasko Oskov | 252ae04 | 2018-10-04 21:44:12 | [diff] [blame] | 159 | // Remove the children. |
| 160 | current_frame_host()->ResetChildren(); |
Lukasz Anforowicz | 7bfb2e9 | 2017-11-22 17:19:45 | [diff] [blame] | 161 | |
Nate Chapin | 22ea659 | 2019-03-05 22:29:02 | [diff] [blame] | 162 | current_frame_host()->ResetLoadingState(); |
| 163 | |
Lukasz Anforowicz | 7bfb2e9 | 2017-11-22 17:19:45 | [diff] [blame] | 164 | // If the removed frame was created by a script, then its history entry will |
| 165 | // never be reused - we can save some memory by removing the history entry. |
| 166 | // See also https://crbug.com/784356. |
| 167 | if (is_created_by_script_ && parent_) { |
| 168 | NavigationEntryImpl* nav_entry = static_cast<NavigationEntryImpl*>( |
Fergal Daly | 09d6c76 | 2020-05-29 02:05:18 | [diff] [blame] | 169 | navigator().GetController()->GetLastCommittedEntry()); |
Lukasz Anforowicz | 7bfb2e9 | 2017-11-22 17:19:45 | [diff] [blame] | 170 | if (nav_entry) { |
| 171 | nav_entry->RemoveEntryForFrame(this, |
| 172 | /* only_if_different_position = */ false); |
| 173 | } |
| 174 | } |
| 175 | |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 176 | frame_tree_->FrameRemoved(this); |
ericwilligers | 254597b | 2016-10-17 10:32:31 | [diff] [blame] | 177 | for (auto& observer : observers_) |
| 178 | observer.OnFrameTreeNodeDestroyed(this); |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 179 | |
| 180 | if (opener_) |
| 181 | opener_->RemoveObserver(opener_observer_.get()); |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 182 | if (original_opener_) |
| 183 | original_opener_->RemoveObserver(original_opener_observer_.get()); |
dmazzoni | e950ea23 | 2015-03-13 21:39:45 | [diff] [blame] | 184 | |
| 185 | g_frame_tree_node_id_map.Get().erase(frame_tree_node_id_); |
jam | 39258caf | 2016-11-02 14:48:18 | [diff] [blame] | 186 | |
danakj | f940060 | 2019-06-07 15:44:58 | [diff] [blame] | 187 | bool did_stop_loading = false; |
| 188 | |
jam | 39258caf | 2016-11-02 14:48:18 | [diff] [blame] | 189 | if (navigation_request_) { |
danakj | f940060 | 2019-06-07 15:44:58 | [diff] [blame] | 190 | navigation_request_.reset(); |
Arthur Hemery | 0dd6581 | 2019-08-01 14:18:45 | [diff] [blame] | 191 | // If a frame with a pending navigation is detached, make sure the |
| 192 | // WebContents (and its observers) update their loading state. |
danakj | f940060 | 2019-06-07 15:44:58 | [diff] [blame] | 193 | did_stop_loading = true; |
jam | 39258caf | 2016-11-02 14:48:18 | [diff] [blame] | 194 | } |
Nate Chapin | 22ea659 | 2019-03-05 22:29:02 | [diff] [blame] | 195 | |
danakj | f940060 | 2019-06-07 15:44:58 | [diff] [blame] | 196 | // ~SiteProcessCountTracker DCHECKs in some tests if the speculative |
| 197 | // RenderFrameHostImpl is not destroyed last. Ideally this would be closer to |
| 198 | // (possible before) the ResetLoadingState() call above. |
| 199 | // |
| 200 | // There is an inherent race condition causing bugs 838348/915179/et al, where |
| 201 | // the renderer may have committed the speculative main frame and the browser |
| 202 | // has not heard about it yet. If this is a main frame, then in that case the |
| 203 | // speculative RenderFrame was unable to be deleted (it is owned by the |
| 204 | // renderer) and we should not be able to cancel the navigation at this point. |
| 205 | // CleanUpNavigation() would normally be called here but it will try to undo |
| 206 | // the navigation and expose the race condition. When it replaces the main |
| 207 | // frame with a RenderFrameProxy, that leaks the committed main frame, leaving |
| 208 | // the frame and its friend group with pointers that will become invalid |
| 209 | // shortly as we are shutting everything down and deleting the RenderView etc. |
| 210 | // We avoid this problematic situation by not calling CleanUpNavigation() or |
| 211 | // DiscardUnusedFrame() here. The speculative RenderFrameHost is simply |
| 212 | // returned and deleted immediately. This satisfies the requirement that the |
| 213 | // speculative RenderFrameHost is removed from the RenderFrameHostManager |
| 214 | // before it is destroyed. |
| 215 | if (render_manager_.speculative_frame_host()) { |
| 216 | did_stop_loading |= render_manager_.speculative_frame_host()->is_loading(); |
| 217 | render_manager_.UnsetSpeculativeRenderFrameHost(); |
| 218 | } |
| 219 | |
| 220 | if (did_stop_loading) |
| 221 | DidStopLoading(); |
| 222 | |
Nate Chapin | 22ea659 | 2019-03-05 22:29:02 | [diff] [blame] | 223 | DCHECK(!IsLoading()); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 224 | } |
| 225 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 226 | void FrameTreeNode::AddObserver(Observer* observer) { |
| 227 | observers_.AddObserver(observer); |
| 228 | } |
| 229 | |
| 230 | void FrameTreeNode::RemoveObserver(Observer* observer) { |
| 231 | observers_.RemoveObserver(observer); |
| 232 | } |
| 233 | |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 234 | bool FrameTreeNode::IsMainFrame() const { |
| 235 | return frame_tree_->root() == this; |
| 236 | } |
| 237 | |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 238 | void FrameTreeNode::ResetForNavigation() { |
| 239 | // Discard any CSP headers from the previous document. |
| 240 | replication_state_.accumulated_csp_headers.clear(); |
| 241 | render_manager_.OnDidResetContentSecurityPolicy(); |
| 242 | |
Ian Clelland | edb8c5dd | 2018-03-01 17:01:37 | [diff] [blame] | 243 | // Clear any CSP-set sandbox flags, and the declared feature policy for the |
| 244 | // frame. |
arthursonzogni | b93a447 | 2020-04-10 07:38:00 | [diff] [blame] | 245 | UpdateFramePolicyHeaders(network::mojom::WebSandboxFlags::kNone, {}); |
Shivani Sharma | c4f56158 | 2018-11-15 15:58:39 | [diff] [blame] | 246 | |
Mustaq Ahmed | c53e4c56 | 2019-01-29 19:05:09 | [diff] [blame] | 247 | // This frame has had its user activation bits cleared in the renderer |
| 248 | // before arriving here. We just need to clear them here and in the other |
| 249 | // renderer processes that may have a reference to this frame. |
Antonio Gomes | 4b2c513 | 2020-01-16 11:49:48 | [diff] [blame] | 250 | UpdateUserActivationState( |
Mustaq Ahmed | dc195e5b | 2020-08-04 18:45:11 | [diff] [blame] | 251 | blink::mojom::UserActivationUpdateType::kClearActivation, |
| 252 | blink::mojom::UserActivationNotificationType::kNone); |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 253 | } |
| 254 | |
yilkal | 34a3d75 | 2019-08-30 18:20:30 | [diff] [blame] | 255 | size_t FrameTreeNode::GetFrameTreeSize() const { |
| 256 | if (is_collapsed()) |
| 257 | return 0; |
| 258 | |
| 259 | size_t size = 0; |
| 260 | for (size_t i = 0; i < child_count(); i++) { |
| 261 | size += child_at(i)->GetFrameTreeSize(); |
| 262 | } |
| 263 | |
| 264 | // Account for this node. |
| 265 | size++; |
| 266 | return size; |
| 267 | } |
| 268 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 269 | void FrameTreeNode::SetOpener(FrameTreeNode* opener) { |
| 270 | if (opener_) { |
| 271 | opener_->RemoveObserver(opener_observer_.get()); |
| 272 | opener_observer_.reset(); |
| 273 | } |
| 274 | |
| 275 | opener_ = opener; |
| 276 | |
| 277 | if (opener_) { |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 278 | opener_observer_ = std::make_unique<OpenerDestroyedObserver>(this, false); |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 279 | opener_->AddObserver(opener_observer_.get()); |
| 280 | } |
| 281 | } |
| 282 | |
Wolfgang Beyer | d8809db | 2020-09-30 15:29:39 | [diff] [blame] | 283 | void FrameTreeNode::SetOpenerDevtoolsFrameToken( |
| 284 | base::UnguessableToken opener_devtools_frame_token) { |
| 285 | DCHECK(!opener_devtools_frame_token_ || |
| 286 | opener_devtools_frame_token_->is_empty()); |
| 287 | opener_devtools_frame_token_ = std::move(opener_devtools_frame_token); |
| 288 | } |
| 289 | |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 290 | void FrameTreeNode::SetOriginalOpener(FrameTreeNode* opener) { |
Avi Drissman | 36465f33 | 2017-09-11 20:49:39 | [diff] [blame] | 291 | // The original opener tracks main frames only. |
avi | 8d1aa16 | 2017-03-27 18:27:37 | [diff] [blame] | 292 | DCHECK(opener == nullptr || !opener->parent()); |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 293 | |
Avi Drissman | 36465f33 | 2017-09-11 20:49:39 | [diff] [blame] | 294 | if (original_opener_) { |
| 295 | original_opener_->RemoveObserver(original_opener_observer_.get()); |
| 296 | original_opener_observer_.reset(); |
| 297 | } |
| 298 | |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 299 | original_opener_ = opener; |
| 300 | |
| 301 | if (original_opener_) { |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 302 | original_opener_observer_ = |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 303 | std::make_unique<OpenerDestroyedObserver>(this, true); |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 304 | original_opener_->AddObserver(original_opener_observer_.get()); |
| 305 | } |
| 306 | } |
| 307 | |
creis | f0f069a | 2015-07-23 23:51:53 | [diff] [blame] | 308 | void FrameTreeNode::SetCurrentURL(const GURL& url) { |
Balazs Engedy | c8a7cccf | 2018-03-12 23:00:49 | [diff] [blame] | 309 | if (!has_committed_real_load_ && !url.IsAboutBlank()) |
creis | f0f069a | 2015-07-23 23:51:53 | [diff] [blame] | 310 | has_committed_real_load_ = true; |
Erik Chen | 173bf304 | 2017-07-31 06:06:21 | [diff] [blame] | 311 | current_frame_host()->SetLastCommittedUrl(url); |
xiaochengh | b9554bb | 2016-05-21 14:20:48 | [diff] [blame] | 312 | blame_context_.TakeSnapshot(); |
creis | f0f069a | 2015-07-23 23:51:53 | [diff] [blame] | 313 | } |
| 314 | |
estark | bd8e26f | 2016-03-16 23:30:37 | [diff] [blame] | 315 | void FrameTreeNode::SetCurrentOrigin( |
| 316 | const url::Origin& origin, |
| 317 | bool is_potentially_trustworthy_unique_origin) { |
| 318 | if (!origin.IsSameOriginWith(replication_state_.origin) || |
| 319 | replication_state_.has_potentially_trustworthy_unique_origin != |
| 320 | is_potentially_trustworthy_unique_origin) { |
| 321 | render_manager_.OnDidUpdateOrigin(origin, |
| 322 | is_potentially_trustworthy_unique_origin); |
| 323 | } |
alexmos | a7a4ff82 | 2015-04-27 17:59:56 | [diff] [blame] | 324 | replication_state_.origin = origin; |
estark | bd8e26f | 2016-03-16 23:30:37 | [diff] [blame] | 325 | replication_state_.has_potentially_trustworthy_unique_origin = |
| 326 | is_potentially_trustworthy_unique_origin; |
alexmos | a7a4ff82 | 2015-04-27 17:59:56 | [diff] [blame] | 327 | } |
alexmos | be2f4c3 | 2015-03-10 02:30:23 | [diff] [blame] | 328 | |
engedy | 6e2e099 | 2017-05-25 18:58:42 | [diff] [blame] | 329 | void FrameTreeNode::SetCollapsed(bool collapsed) { |
| 330 | DCHECK(!IsMainFrame()); |
| 331 | if (is_collapsed_ == collapsed) |
| 332 | return; |
| 333 | |
| 334 | is_collapsed_ = collapsed; |
| 335 | render_manager_.OnDidChangeCollapsedState(collapsed); |
| 336 | } |
| 337 | |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 338 | void FrameTreeNode::SetFrameName(const std::string& name, |
| 339 | const std::string& unique_name) { |
| 340 | if (name == replication_state_.name) { |
| 341 | // |unique_name| shouldn't change unless |name| changes. |
| 342 | DCHECK_EQ(unique_name, replication_state_.unique_name); |
| 343 | return; |
| 344 | } |
lukasza | 5140a41 | 2016-09-15 21:12:30 | [diff] [blame] | 345 | |
| 346 | if (parent()) { |
| 347 | // Non-main frames should have a non-empty unique name. |
| 348 | DCHECK(!unique_name.empty()); |
| 349 | } else { |
| 350 | // Unique name of main frames should always stay empty. |
| 351 | DCHECK(unique_name.empty()); |
| 352 | } |
| 353 | |
Daniel Cheng | 6ca7f1c9 | 2017-08-09 21:45:41 | [diff] [blame] | 354 | // Note the unique name should only be able to change before the first real |
| 355 | // load is committed, but that's not strongly enforced here. |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 356 | render_manager_.OnDidUpdateName(name, unique_name); |
alexmos | a7a4ff82 | 2015-04-27 17:59:56 | [diff] [blame] | 357 | replication_state_.name = name; |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 358 | replication_state_.unique_name = unique_name; |
alexmos | be2f4c3 | 2015-03-10 02:30:23 | [diff] [blame] | 359 | } |
| 360 | |
arthursonzogni | 662aa65 | 2017-03-28 11:09:50 | [diff] [blame] | 361 | void FrameTreeNode::AddContentSecurityPolicies( |
arthursonzogni | 35a95c7 | 2020-01-15 17:49:43 | [diff] [blame] | 362 | std::vector<network::mojom::ContentSecurityPolicyHeaderPtr> headers) { |
| 363 | for (auto& header : headers) |
| 364 | replication_state_.accumulated_csp_headers.push_back(*header); |
| 365 | render_manager_.OnDidAddContentSecurityPolicies(std::move(headers)); |
lukasza | 8e1c02e4 | 2016-05-17 20:05:10 | [diff] [blame] | 366 | } |
| 367 | |
mkwst | f672e7ef | 2016-06-09 20:51:07 | [diff] [blame] | 368 | void FrameTreeNode::SetInsecureRequestPolicy( |
Julie Jeongeun Kim | d90e2dd | 2020-03-03 11:45:37 | [diff] [blame] | 369 | blink::mojom::InsecureRequestPolicy policy) { |
mkwst | f672e7ef | 2016-06-09 20:51:07 | [diff] [blame] | 370 | if (policy == replication_state_.insecure_request_policy) |
estark | a886b8d | 2015-12-18 21:53:08 | [diff] [blame] | 371 | return; |
mkwst | f672e7ef | 2016-06-09 20:51:07 | [diff] [blame] | 372 | render_manager_.OnEnforceInsecureRequestPolicy(policy); |
| 373 | replication_state_.insecure_request_policy = policy; |
estark | a886b8d | 2015-12-18 21:53:08 | [diff] [blame] | 374 | } |
| 375 | |
arthursonzogni | 4b62a5cb | 2018-01-17 14:14:26 | [diff] [blame] | 376 | void FrameTreeNode::SetInsecureNavigationsSet( |
| 377 | const std::vector<uint32_t>& insecure_navigations_set) { |
| 378 | DCHECK(std::is_sorted(insecure_navigations_set.begin(), |
| 379 | insecure_navigations_set.end())); |
| 380 | if (insecure_navigations_set == replication_state_.insecure_navigations_set) |
| 381 | return; |
| 382 | render_manager_.OnEnforceInsecureNavigationsSet(insecure_navigations_set); |
| 383 | replication_state_.insecure_navigations_set = insecure_navigations_set; |
| 384 | } |
| 385 | |
Luna Lu | c3fdacdf | 2017-11-08 04:48:53 | [diff] [blame] | 386 | void FrameTreeNode::SetPendingFramePolicy(blink::FramePolicy frame_policy) { |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 387 | pending_frame_policy_.sandbox_flags = frame_policy.sandbox_flags; |
Dave Tapuska | 9b153a94 | 2020-02-10 19:35:10 | [diff] [blame] | 388 | pending_frame_policy_.disallow_document_access = |
| 389 | frame_policy.disallow_document_access; |
alexmos | 6e94010 | 2016-01-19 22:47:25 | [diff] [blame] | 390 | |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 391 | if (parent()) { |
| 392 | // Subframes should always inherit their parent's sandbox flags. |
Alexander Timin | 381e7e18 | 2020-04-28 19:04:03 | [diff] [blame] | 393 | pending_frame_policy_.sandbox_flags |= |
| 394 | parent()->frame_tree_node()->active_sandbox_flags(); |
Charlie Hu | e1b77ac | 2019-12-13 21:30:17 | [diff] [blame] | 395 | // This is only applied on subframes; container policy and required document |
| 396 | // policy are not mutable on main frame. |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 397 | pending_frame_policy_.container_policy = frame_policy.container_policy; |
Charlie Hu | e1b77ac | 2019-12-13 21:30:17 | [diff] [blame] | 398 | pending_frame_policy_.required_document_policy = |
| 399 | frame_policy.required_document_policy; |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 400 | } |
iclelland | 92f8c0b | 2017-04-19 12:43:05 | [diff] [blame] | 401 | } |
| 402 | |
alexmos | 9f8705a | 2015-05-06 19:58:59 | [diff] [blame] | 403 | FrameTreeNode* FrameTreeNode::PreviousSibling() const { |
paulmeyer | 322777fb | 2016-05-16 23:15:39 | [diff] [blame] | 404 | return GetSibling(-1); |
| 405 | } |
alexmos | 9f8705a | 2015-05-06 19:58:59 | [diff] [blame] | 406 | |
paulmeyer | 322777fb | 2016-05-16 23:15:39 | [diff] [blame] | 407 | FrameTreeNode* FrameTreeNode::NextSibling() const { |
| 408 | return GetSibling(1); |
alexmos | 9f8705a | 2015-05-06 19:58:59 | [diff] [blame] | 409 | } |
| 410 | |
fdegans | 4a49ce93 | 2015-03-12 17:11:37 | [diff] [blame] | 411 | bool FrameTreeNode::IsLoading() const { |
| 412 | RenderFrameHostImpl* current_frame_host = |
| 413 | render_manager_.current_frame_host(); |
fdegans | 4a49ce93 | 2015-03-12 17:11:37 | [diff] [blame] | 414 | |
| 415 | DCHECK(current_frame_host); |
fdegans | 39ff038 | 2015-04-29 19:04:39 | [diff] [blame] | 416 | |
clamy | 610c63b3 | 2017-12-22 15:05:18 | [diff] [blame] | 417 | if (navigation_request_) |
| 418 | return true; |
clamy | 11e1151 | 2015-07-07 16:42:17 | [diff] [blame] | 419 | |
clamy | 610c63b3 | 2017-12-22 15:05:18 | [diff] [blame] | 420 | RenderFrameHostImpl* speculative_frame_host = |
| 421 | render_manager_.speculative_frame_host(); |
| 422 | if (speculative_frame_host && speculative_frame_host->is_loading()) |
| 423 | return true; |
fdegans | 4a49ce93 | 2015-03-12 17:11:37 | [diff] [blame] | 424 | return current_frame_host->is_loading(); |
| 425 | } |
| 426 | |
Charlie Hu | 5ffc015 | 2019-12-06 15:59:53 | [diff] [blame] | 427 | bool FrameTreeNode::CommitFramePolicy( |
| 428 | const blink::FramePolicy& new_frame_policy) { |
| 429 | bool did_change_flags = new_frame_policy.sandbox_flags != |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 430 | replication_state_.frame_policy.sandbox_flags; |
iclelland | 92f8c0b | 2017-04-19 12:43:05 | [diff] [blame] | 431 | bool did_change_container_policy = |
Charlie Hu | 5ffc015 | 2019-12-06 15:59:53 | [diff] [blame] | 432 | new_frame_policy.container_policy != |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 433 | replication_state_.frame_policy.container_policy; |
Charlie Hu | e1b77ac | 2019-12-13 21:30:17 | [diff] [blame] | 434 | bool did_change_required_document_policy = |
| 435 | pending_frame_policy_.required_document_policy != |
| 436 | replication_state_.frame_policy.required_document_policy; |
Dave Tapuska | 9b153a94 | 2020-02-10 19:35:10 | [diff] [blame] | 437 | bool did_change_document_access = |
| 438 | new_frame_policy.disallow_document_access != |
| 439 | replication_state_.frame_policy.disallow_document_access; |
iclelland | 92f8c0b | 2017-04-19 12:43:05 | [diff] [blame] | 440 | if (did_change_flags) |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 441 | replication_state_.frame_policy.sandbox_flags = |
Charlie Hu | 5ffc015 | 2019-12-06 15:59:53 | [diff] [blame] | 442 | new_frame_policy.sandbox_flags; |
iclelland | 92f8c0b | 2017-04-19 12:43:05 | [diff] [blame] | 443 | if (did_change_container_policy) |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 444 | replication_state_.frame_policy.container_policy = |
Charlie Hu | 5ffc015 | 2019-12-06 15:59:53 | [diff] [blame] | 445 | new_frame_policy.container_policy; |
Charlie Hu | e1b77ac | 2019-12-13 21:30:17 | [diff] [blame] | 446 | if (did_change_required_document_policy) |
| 447 | replication_state_.frame_policy.required_document_policy = |
| 448 | new_frame_policy.required_document_policy; |
Dave Tapuska | 9b153a94 | 2020-02-10 19:35:10 | [diff] [blame] | 449 | if (did_change_document_access) |
| 450 | replication_state_.frame_policy.disallow_document_access = |
| 451 | new_frame_policy.disallow_document_access; |
Charlie Hu | e1b77ac | 2019-12-13 21:30:17 | [diff] [blame] | 452 | |
Charlie Hu | 5ffc015 | 2019-12-06 15:59:53 | [diff] [blame] | 453 | UpdateFramePolicyHeaders(new_frame_policy.sandbox_flags, |
Ian Clelland | edb8c5dd | 2018-03-01 17:01:37 | [diff] [blame] | 454 | replication_state_.feature_policy_header); |
Charlie Hu | e1b77ac | 2019-12-13 21:30:17 | [diff] [blame] | 455 | return did_change_flags || did_change_container_policy || |
Dave Tapuska | 9b153a94 | 2020-02-10 19:35:10 | [diff] [blame] | 456 | did_change_required_document_policy || did_change_document_access; |
alexmos | 6b29456 | 2015-03-05 19:24:10 | [diff] [blame] | 457 | } |
| 458 | |
Arthur Hemery | c338017 | 2018-01-22 14:00:17 | [diff] [blame] | 459 | void FrameTreeNode::TransferNavigationRequestOwnership( |
| 460 | RenderFrameHostImpl* render_frame_host) { |
Andrey Kosyakov | f2d4ff7 | 2018-10-29 20:09:59 | [diff] [blame] | 461 | devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get()); |
Arthur Hemery | c338017 | 2018-01-22 14:00:17 | [diff] [blame] | 462 | render_frame_host->SetNavigationRequest(std::move(navigation_request_)); |
| 463 | } |
| 464 | |
carlosk | c49005eb | 2015-06-16 11:25:07 | [diff] [blame] | 465 | void FrameTreeNode::CreatedNavigationRequest( |
dcheng | 9bfa516 | 2016-04-09 01:00:57 | [diff] [blame] | 466 | std::unique_ptr<NavigationRequest> navigation_request) { |
arthursonzogni | c79c251c | 2016-08-18 15:00:37 | [diff] [blame] | 467 | // This is never called when navigating to a Javascript URL. For the loading |
| 468 | // state, this matches what Blink is doing: Blink doesn't send throbber |
| 469 | // notifications for Javascript URLS. |
| 470 | DCHECK(!navigation_request->common_params().url.SchemeIs( |
| 471 | url::kJavaScriptScheme)); |
| 472 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 473 | bool was_previously_loading = frame_tree()->IsLoading(); |
| 474 | |
clamy | 82a2f4d | 2016-02-02 14:20:41 | [diff] [blame] | 475 | // There's no need to reset the state: there's still an ongoing load, and the |
| 476 | // RenderFrameHostManager will take care of updates to the speculative |
| 477 | // RenderFrameHost in DidCreateNavigationRequest below. |
jam | cd0b7b2 | 2017-03-24 22:13:05 | [diff] [blame] | 478 | if (was_previously_loading) { |
Mohamed Abdelhalim | f03d4a2 | 2019-10-01 13:34:31 | [diff] [blame] | 479 | if (navigation_request_ && navigation_request_->IsNavigationStarted()) { |
jam | cd0b7b2 | 2017-03-24 22:13:05 | [diff] [blame] | 480 | // Mark the old request as aborted. |
Mohamed Abdelhalim | b4db22a | 2019-06-18 10:46:52 | [diff] [blame] | 481 | navigation_request_->set_net_error(net::ERR_ABORTED); |
jam | cd0b7b2 | 2017-03-24 22:13:05 | [diff] [blame] | 482 | } |
Arthur Hemery | 241b939 | 2019-10-24 11:08:41 | [diff] [blame] | 483 | ResetNavigationRequest(true); |
jam | cd0b7b2 | 2017-03-24 22:13:05 | [diff] [blame] | 484 | } |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 485 | |
| 486 | navigation_request_ = std::move(navigation_request); |
Shubhie Panicker | ddf2a4e | 2018-03-06 00:09:06 | [diff] [blame] | 487 | if (was_discarded_) { |
| 488 | navigation_request_->set_was_discarded(); |
| 489 | was_discarded_ = false; |
| 490 | } |
clamy | 8e2e29920 | 2016-04-05 11:44:59 | [diff] [blame] | 491 | render_manager()->DidCreateNavigationRequest(navigation_request_.get()); |
fdegans | 39ff038 | 2015-04-29 19:04:39 | [diff] [blame] | 492 | |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 493 | bool to_different_document = !NavigationTypeUtils::IsSameDocument( |
arthursonzogni | 92f1868 | 2017-02-08 23:00:04 | [diff] [blame] | 494 | navigation_request_->common_params().navigation_type); |
| 495 | |
| 496 | DidStartLoading(to_different_document, was_previously_loading); |
clamy | dcb434c1 | 2015-04-16 19:29:16 | [diff] [blame] | 497 | } |
| 498 | |
Arthur Hemery | 241b939 | 2019-10-24 11:08:41 | [diff] [blame] | 499 | void FrameTreeNode::ResetNavigationRequest(bool keep_state) { |
fdegans | 39ff038 | 2015-04-29 19:04:39 | [diff] [blame] | 500 | if (!navigation_request_) |
| 501 | return; |
John Abd-El-Malek | dcc7bf4 | 2017-09-12 22:30:23 | [diff] [blame] | 502 | |
Andrey Kosyakov | f2d4ff7 | 2018-10-29 20:09:59 | [diff] [blame] | 503 | devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get()); |
clamy | dcb434c1 | 2015-04-16 19:29:16 | [diff] [blame] | 504 | navigation_request_.reset(); |
fdegans | 39ff038 | 2015-04-29 19:04:39 | [diff] [blame] | 505 | |
clamy | 82a2f4d | 2016-02-02 14:20:41 | [diff] [blame] | 506 | if (keep_state) |
fdegans | 39ff038 | 2015-04-29 19:04:39 | [diff] [blame] | 507 | return; |
| 508 | |
clamy | 82a2f4d | 2016-02-02 14:20:41 | [diff] [blame] | 509 | // The RenderFrameHostManager should clean up any speculative RenderFrameHost |
| 510 | // it created for the navigation. Also register that the load stopped. |
fdegans | 39ff038 | 2015-04-29 19:04:39 | [diff] [blame] | 511 | DidStopLoading(); |
| 512 | render_manager_.CleanUpNavigation(); |
clamy | dcb434c1 | 2015-04-16 19:29:16 | [diff] [blame] | 513 | } |
| 514 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 515 | void FrameTreeNode::DidStartLoading(bool to_different_document, |
| 516 | bool was_previously_loading) { |
Camille Lamy | efd54b0 | 2018-10-04 16:54:14 | [diff] [blame] | 517 | TRACE_EVENT2("navigation", "FrameTreeNode::DidStartLoading", |
| 518 | "frame_tree_node", frame_tree_node_id(), "to different document", |
| 519 | to_different_document); |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 520 | // Any main frame load to a new document should reset the load progress since |
| 521 | // it will replace the current page and any frames. The WebContents will |
| 522 | // be notified when DidChangeLoadProgress is called. |
| 523 | if (to_different_document && IsMainFrame()) |
| 524 | frame_tree_->ResetLoadProgress(); |
| 525 | |
| 526 | // Notify the WebContents. |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 527 | if (!was_previously_loading) |
Fergal Daly | 09d6c76 | 2020-05-29 02:05:18 | [diff] [blame] | 528 | navigator().GetDelegate()->DidStartLoading(this, to_different_document); |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 529 | |
| 530 | // Set initial load progress and update overall progress. This will notify |
| 531 | // the WebContents of the load progress change. |
| 532 | DidChangeLoadProgress(kLoadingProgressMinimum); |
| 533 | |
| 534 | // Notify the RenderFrameHostManager of the event. |
| 535 | render_manager()->OnDidStartLoading(); |
| 536 | } |
| 537 | |
| 538 | void FrameTreeNode::DidStopLoading() { |
Camille Lamy | efd54b0 | 2018-10-04 16:54:14 | [diff] [blame] | 539 | TRACE_EVENT1("navigation", "FrameTreeNode::DidStopLoading", "frame_tree_node", |
| 540 | frame_tree_node_id()); |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 541 | // Set final load progress and update overall progress. This will notify |
| 542 | // the WebContents of the load progress change. |
| 543 | DidChangeLoadProgress(kLoadingProgressDone); |
| 544 | |
Lucas Furukawa Gadani | 6faef60 | 2019-05-06 21:16:03 | [diff] [blame] | 545 | // Notify the RenderFrameHostManager of the event. |
| 546 | render_manager()->OnDidStopLoading(); |
| 547 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 548 | // Notify the WebContents. |
| 549 | if (!frame_tree_->IsLoading()) |
Fergal Daly | 09d6c76 | 2020-05-29 02:05:18 | [diff] [blame] | 550 | navigator().GetDelegate()->DidStopLoading(); |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | void FrameTreeNode::DidChangeLoadProgress(double load_progress) { |
Nate Chapin | 9353670 | 2018-02-07 00:12:21 | [diff] [blame] | 554 | DCHECK_GE(load_progress, kLoadingProgressMinimum); |
| 555 | DCHECK_LE(load_progress, kLoadingProgressDone); |
| 556 | if (IsMainFrame()) |
| 557 | frame_tree_->UpdateLoadProgress(load_progress); |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 558 | } |
| 559 | |
clamy | f73862c4 | 2015-07-08 12:31:33 | [diff] [blame] | 560 | bool FrameTreeNode::StopLoading() { |
arthursonzogni | 66f711c | 2019-10-08 14:40:36 | [diff] [blame] | 561 | if (navigation_request_ && navigation_request_->IsNavigationStarted()) |
| 562 | navigation_request_->set_net_error(net::ERR_ABORTED); |
Arthur Hemery | 241b939 | 2019-10-24 11:08:41 | [diff] [blame] | 563 | ResetNavigationRequest(false); |
clamy | f73862c4 | 2015-07-08 12:31:33 | [diff] [blame] | 564 | |
| 565 | // TODO(nasko): see if child frames should send IPCs in site-per-process |
| 566 | // mode. |
| 567 | if (!IsMainFrame()) |
| 568 | return true; |
| 569 | |
| 570 | render_manager_.Stop(); |
| 571 | return true; |
| 572 | } |
| 573 | |
alexmos | 21acae5 | 2015-11-07 01:04:43 | [diff] [blame] | 574 | void FrameTreeNode::DidFocus() { |
| 575 | last_focus_time_ = base::TimeTicks::Now(); |
ericwilligers | 254597b | 2016-10-17 10:32:31 | [diff] [blame] | 576 | for (auto& observer : observers_) |
| 577 | observer.OnFrameTreeNodeFocused(this); |
alexmos | 21acae5 | 2015-11-07 01:04:43 | [diff] [blame] | 578 | } |
| 579 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 580 | void FrameTreeNode::BeforeUnloadCanceled() { |
| 581 | // TODO(clamy): Support BeforeUnload in subframes. |
| 582 | if (!IsMainFrame()) |
| 583 | return; |
| 584 | |
| 585 | RenderFrameHostImpl* current_frame_host = |
| 586 | render_manager_.current_frame_host(); |
| 587 | DCHECK(current_frame_host); |
| 588 | current_frame_host->ResetLoadingState(); |
| 589 | |
clamy | 610c63b3 | 2017-12-22 15:05:18 | [diff] [blame] | 590 | RenderFrameHostImpl* speculative_frame_host = |
| 591 | render_manager_.speculative_frame_host(); |
| 592 | if (speculative_frame_host) |
| 593 | speculative_frame_host->ResetLoadingState(); |
| 594 | // Note: there is no need to set an error code on the NavigationHandle here |
| 595 | // as it has not been created yet. It is only created when the |
Antonio Gomes | 8678a20 | 2020-03-02 20:03:25 | [diff] [blame] | 596 | // BeforeUnloadCompleted callback is invoked. |
clamy | 610c63b3 | 2017-12-22 15:05:18 | [diff] [blame] | 597 | if (navigation_request_) |
Arthur Hemery | 241b939 | 2019-10-24 11:08:41 | [diff] [blame] | 598 | ResetNavigationRequest(false); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 599 | } |
| 600 | |
Mustaq Ahmed | ecb5c38e | 2020-07-29 00:34:30 | [diff] [blame] | 601 | bool FrameTreeNode::NotifyUserActivation( |
| 602 | blink::mojom::UserActivationNotificationType notification_type) { |
Alexander Timin | a1dfadaa | 2020-04-28 13:30:06 | [diff] [blame] | 603 | for (RenderFrameHostImpl* rfh = current_frame_host(); rfh; |
| 604 | rfh = rfh->GetParent()) { |
| 605 | if (!rfh->frame_tree_node()->user_activation_state_.HasBeenActive()) |
| 606 | rfh->DidReceiveFirstUserActivation(); |
Mustaq Ahmed | ecb5c38e | 2020-07-29 00:34:30 | [diff] [blame] | 607 | rfh->frame_tree_node()->user_activation_state_.Activate(notification_type); |
John Delaney | edd8d6c | 2019-01-25 00:23:57 | [diff] [blame] | 608 | } |
danakj | 359a434 | 2020-05-29 20:38:39 | [diff] [blame] | 609 | replication_state_.has_active_user_gesture = true; |
Mustaq Ahmed | a5dfa60b | 2018-12-08 00:30:14 | [diff] [blame] | 610 | |
Mustaq Ahmed | 0180320f | 2019-03-21 16:07:01 | [diff] [blame] | 611 | // See the "Same-origin Visibility" section in |UserActivationState| class |
| 612 | // doc. |
Mustaq Ahmed | e5f1256 | 2019-10-30 18:02:03 | [diff] [blame] | 613 | if (base::FeatureList::IsEnabled( |
Mustaq Ahmed | a5dfa60b | 2018-12-08 00:30:14 | [diff] [blame] | 614 | features::kUserActivationSameOriginVisibility)) { |
| 615 | const url::Origin& current_origin = |
| 616 | this->current_frame_host()->GetLastCommittedOrigin(); |
| 617 | for (FrameTreeNode* node : frame_tree()->Nodes()) { |
| 618 | if (node->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith( |
| 619 | current_origin)) { |
Mustaq Ahmed | ecb5c38e | 2020-07-29 00:34:30 | [diff] [blame] | 620 | node->user_activation_state_.Activate(notification_type); |
Mustaq Ahmed | a5dfa60b | 2018-12-08 00:30:14 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | } |
| 624 | |
Shivani Sharma | 20749e92 | 2019-03-11 17:00:26 | [diff] [blame] | 625 | NavigationControllerImpl* controller = |
Fergal Daly | 09d6c76 | 2020-05-29 02:05:18 | [diff] [blame] | 626 | static_cast<NavigationControllerImpl*>(navigator().GetController()); |
Shivani Sharma | 20749e92 | 2019-03-11 17:00:26 | [diff] [blame] | 627 | if (controller) |
| 628 | controller->NotifyUserActivation(); |
Shivani Sharma | 19487703 | 2019-03-07 17:52:47 | [diff] [blame] | 629 | |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 630 | return true; |
| 631 | } |
| 632 | |
| 633 | bool FrameTreeNode::ConsumeTransientUserActivation() { |
| 634 | bool was_active = user_activation_state_.IsActive(); |
| 635 | for (FrameTreeNode* node : frame_tree()->Nodes()) |
| 636 | node->user_activation_state_.ConsumeIfActive(); |
danakj | 359a434 | 2020-05-29 20:38:39 | [diff] [blame] | 637 | replication_state_.has_active_user_gesture = false; |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 638 | return was_active; |
| 639 | } |
| 640 | |
Shivani Sharma | c4f56158 | 2018-11-15 15:58:39 | [diff] [blame] | 641 | bool FrameTreeNode::ClearUserActivation() { |
Shivani Sharma | c4f56158 | 2018-11-15 15:58:39 | [diff] [blame] | 642 | for (FrameTreeNode* node : frame_tree()->SubtreeNodes(this)) |
| 643 | node->user_activation_state_.Clear(); |
danakj | 359a434 | 2020-05-29 20:38:39 | [diff] [blame] | 644 | replication_state_.has_active_user_gesture = false; |
Shivani Sharma | c4f56158 | 2018-11-15 15:58:39 | [diff] [blame] | 645 | return true; |
| 646 | } |
| 647 | |
Ella Ge | 9caed61 | 2019-08-09 16:17:25 | [diff] [blame] | 648 | bool FrameTreeNode::VerifyUserActivation() { |
Ella Ge | a78f677 | 2019-12-11 10:35:25 | [diff] [blame] | 649 | DCHECK(base::FeatureList::IsEnabled( |
| 650 | features::kBrowserVerifiedUserActivationMouse) || |
| 651 | base::FeatureList::IsEnabled( |
| 652 | features::kBrowserVerifiedUserActivationKeyboard)); |
| 653 | |
Ella Ge | 9caed61 | 2019-08-09 16:17:25 | [diff] [blame] | 654 | return render_manager_.current_frame_host() |
| 655 | ->GetRenderWidgetHost() |
Mustaq Ahmed | 83bb172 | 2019-10-22 20:00:10 | [diff] [blame] | 656 | ->RemovePendingUserActivationIfAvailable(); |
Ella Ge | 9caed61 | 2019-08-09 16:17:25 | [diff] [blame] | 657 | } |
| 658 | |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 659 | bool FrameTreeNode::UpdateUserActivationState( |
Mustaq Ahmed | dc195e5b | 2020-08-04 18:45:11 | [diff] [blame] | 660 | blink::mojom::UserActivationUpdateType update_type, |
| 661 | blink::mojom::UserActivationNotificationType notification_type) { |
Ella Ge | 9caed61 | 2019-08-09 16:17:25 | [diff] [blame] | 662 | bool update_result = false; |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 663 | switch (update_type) { |
Antonio Gomes | 4b2c513 | 2020-01-16 11:49:48 | [diff] [blame] | 664 | case blink::mojom::UserActivationUpdateType::kConsumeTransientActivation: |
Ella Ge | 9caed61 | 2019-08-09 16:17:25 | [diff] [blame] | 665 | update_result = ConsumeTransientUserActivation(); |
| 666 | break; |
Antonio Gomes | 4b2c513 | 2020-01-16 11:49:48 | [diff] [blame] | 667 | case blink::mojom::UserActivationUpdateType::kNotifyActivation: |
Mustaq Ahmed | dc195e5b | 2020-08-04 18:45:11 | [diff] [blame] | 668 | update_result = NotifyUserActivation(notification_type); |
Ella Ge | 9caed61 | 2019-08-09 16:17:25 | [diff] [blame] | 669 | break; |
Antonio Gomes | 4b2c513 | 2020-01-16 11:49:48 | [diff] [blame] | 670 | case blink::mojom::UserActivationUpdateType:: |
Liviu Tinta | d9391fb9 | 2020-09-28 23:50:07 | [diff] [blame] | 671 | kNotifyActivationPendingBrowserVerification: { |
| 672 | const bool user_activation_verified = VerifyUserActivation(); |
| 673 | // Add UMA metric for when browser user activation verification succeeds |
| 674 | base::UmaHistogramBoolean("Event.BrowserVerifiedUserActivation", |
| 675 | user_activation_verified); |
| 676 | if (user_activation_verified) { |
Mustaq Ahmed | ecb5c38e | 2020-07-29 00:34:30 | [diff] [blame] | 677 | update_result = NotifyUserActivation( |
Mustaq Ahmed | 2cfb040 | 2020-09-29 19:24:35 | [diff] [blame] | 678 | blink::mojom::UserActivationNotificationType::kInteraction); |
Antonio Gomes | 4b2c513 | 2020-01-16 11:49:48 | [diff] [blame] | 679 | update_type = blink::mojom::UserActivationUpdateType::kNotifyActivation; |
Ella Ge | 9caed61 | 2019-08-09 16:17:25 | [diff] [blame] | 680 | } else { |
| 681 | // TODO(crbug.com/848778): We need to decide what to do when user |
| 682 | // activation verification failed. NOTREACHED here will make all |
| 683 | // unrelated tests that inject event to renderer fail. |
| 684 | return false; |
| 685 | } |
Liviu Tinta | d9391fb9 | 2020-09-28 23:50:07 | [diff] [blame] | 686 | } break; |
Antonio Gomes | 4b2c513 | 2020-01-16 11:49:48 | [diff] [blame] | 687 | case blink::mojom::UserActivationUpdateType::kClearActivation: |
Ella Ge | 9caed61 | 2019-08-09 16:17:25 | [diff] [blame] | 688 | update_result = ClearUserActivation(); |
| 689 | break; |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 690 | } |
Mustaq Ahmed | dc195e5b | 2020-08-04 18:45:11 | [diff] [blame] | 691 | render_manager_.UpdateUserActivationState(update_type, notification_type); |
Ella Ge | 9caed61 | 2019-08-09 16:17:25 | [diff] [blame] | 692 | return update_result; |
japhet | 61835ae1 | 2017-01-20 01:25:39 | [diff] [blame] | 693 | } |
| 694 | |
Mustaq Ahmed | 0126174 | 2019-12-16 15:49:06 | [diff] [blame] | 695 | void FrameTreeNode::OnSetHadStickyUserActivationBeforeNavigation(bool value) { |
| 696 | render_manager_.OnSetHadStickyUserActivationBeforeNavigation(value); |
Becca Hughes | 60af7d4 | 2017-12-12 10:53:15 | [diff] [blame] | 697 | replication_state_.has_received_user_gesture_before_nav = value; |
| 698 | } |
| 699 | |
paulmeyer | 322777fb | 2016-05-16 23:15:39 | [diff] [blame] | 700 | FrameTreeNode* FrameTreeNode::GetSibling(int relative_offset) const { |
paulmeyer | f3119f5 | 2016-05-17 17:37:19 | [diff] [blame] | 701 | if (!parent_ || !parent_->child_count()) |
paulmeyer | 322777fb | 2016-05-16 23:15:39 | [diff] [blame] | 702 | return nullptr; |
| 703 | |
| 704 | for (size_t i = 0; i < parent_->child_count(); ++i) { |
| 705 | if (parent_->child_at(i) == this) { |
| 706 | if ((relative_offset < 0 && static_cast<size_t>(-relative_offset) > i) || |
| 707 | i + relative_offset >= parent_->child_count()) { |
| 708 | return nullptr; |
| 709 | } |
| 710 | return parent_->child_at(i + relative_offset); |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | NOTREACHED() << "FrameTreeNode not found in its parent's children."; |
| 715 | return nullptr; |
| 716 | } |
| 717 | |
Ian Clelland | edb8c5dd | 2018-03-01 17:01:37 | [diff] [blame] | 718 | void FrameTreeNode::UpdateFramePolicyHeaders( |
arthursonzogni | b93a447 | 2020-04-10 07:38:00 | [diff] [blame] | 719 | network::mojom::WebSandboxFlags sandbox_flags, |
Ian Clelland | edb8c5dd | 2018-03-01 17:01:37 | [diff] [blame] | 720 | const blink::ParsedFeaturePolicy& parsed_header) { |
| 721 | bool changed = false; |
| 722 | if (replication_state_.feature_policy_header != parsed_header) { |
| 723 | replication_state_.feature_policy_header = parsed_header; |
| 724 | changed = true; |
| 725 | } |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 726 | // TODO(iclelland): Kill the renderer if sandbox flags is not a subset of the |
| 727 | // currently effective sandbox flags from the frame. https://crbug.com/740556 |
arthursonzogni | b93a447 | 2020-04-10 07:38:00 | [diff] [blame] | 728 | network::mojom::WebSandboxFlags updated_flags = |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 729 | sandbox_flags | effective_frame_policy().sandbox_flags; |
Ian Clelland | edb8c5dd | 2018-03-01 17:01:37 | [diff] [blame] | 730 | if (replication_state_.active_sandbox_flags != updated_flags) { |
| 731 | replication_state_.active_sandbox_flags = updated_flags; |
| 732 | changed = true; |
| 733 | } |
| 734 | // Notify any proxies if the policies have been changed. |
| 735 | if (changed) |
| 736 | render_manager()->OnDidSetFramePolicyHeaders(); |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 737 | } |
| 738 | |
Arthur Sonzogni | f8840b9 | 2018-11-07 14:10:35 | [diff] [blame] | 739 | void FrameTreeNode::PruneChildFrameNavigationEntries( |
| 740 | NavigationEntryImpl* entry) { |
| 741 | for (size_t i = 0; i < current_frame_host()->child_count(); ++i) { |
| 742 | FrameTreeNode* child = current_frame_host()->child_at(i); |
| 743 | if (child->is_created_by_script_) { |
| 744 | entry->RemoveEntryForFrame(child, |
| 745 | /* only_if_different_position = */ false); |
| 746 | } else { |
| 747 | child->PruneChildFrameNavigationEntries(entry); |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | |
Ehsan Karamad | 3940708 | 2019-02-19 23:38:19 | [diff] [blame] | 752 | void FrameTreeNode::SetOpenerFeaturePolicyState( |
Kent Tamura | 326c2db | 2020-07-20 06:28:05 | [diff] [blame] | 753 | const blink::FeaturePolicyFeatureState& feature_state) { |
Ehsan Karamad | 3940708 | 2019-02-19 23:38:19 | [diff] [blame] | 754 | DCHECK(IsMainFrame()); |
| 755 | if (base::FeatureList::IsEnabled(features::kFeaturePolicyForSandbox)) { |
| 756 | replication_state_.opener_feature_state = feature_state; |
| 757 | } |
| 758 | } |
| 759 | |
Yao Xiao | 24ec9aa | 2020-01-28 16:36:00 | [diff] [blame] | 760 | void FrameTreeNode::SetAdFrameType(blink::mojom::AdFrameType ad_frame_type) { |
| 761 | DCHECK_NE(ad_frame_type, blink::mojom::AdFrameType::kNonAd); |
| 762 | if (replication_state_.ad_frame_type == blink::mojom::AdFrameType::kNonAd) { |
| 763 | replication_state_.ad_frame_type = ad_frame_type; |
| 764 | render_manager()->OnDidSetAdFrameType(ad_frame_type); |
| 765 | } else { |
| 766 | DCHECK_EQ(ad_frame_type, replication_state_.ad_frame_type); |
| 767 | } |
| 768 | } |
| 769 | |
arthursonzogni | 034bb9c | 2020-10-01 08:29:56 | [diff] [blame] | 770 | void FrameTreeNode::SetInitialPopupURL(const GURL& initial_popup_url) { |
| 771 | DCHECK(initial_popup_url_.is_empty()); |
| 772 | DCHECK(!has_committed_real_load_); |
| 773 | initial_popup_url_ = initial_popup_url; |
| 774 | } |
| 775 | |
| 776 | void FrameTreeNode::SetPopupCreatorOrigin( |
| 777 | const url::Origin& popup_creator_origin) { |
| 778 | DCHECK(!has_committed_real_load_); |
| 779 | popup_creator_origin_ = popup_creator_origin; |
| 780 | } |
| 781 | |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 782 | } // namespace content |