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