[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 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 235 | void FrameTreeNode::SetOpener(FrameTreeNode* opener) { |
| 236 | if (opener_) { |
| 237 | opener_->RemoveObserver(opener_observer_.get()); |
| 238 | opener_observer_.reset(); |
| 239 | } |
| 240 | |
| 241 | opener_ = opener; |
| 242 | |
| 243 | if (opener_) { |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 244 | opener_observer_ = std::make_unique<OpenerDestroyedObserver>(this, false); |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 245 | opener_->AddObserver(opener_observer_.get()); |
| 246 | } |
| 247 | } |
| 248 | |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 249 | void FrameTreeNode::SetOriginalOpener(FrameTreeNode* opener) { |
Avi Drissman | 36465f33 | 2017-09-11 20:49:39 | [diff] [blame] | 250 | // The original opener tracks main frames only. |
avi | 8d1aa16 | 2017-03-27 18:27:37 | [diff] [blame] | 251 | DCHECK(opener == nullptr || !opener->parent()); |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 252 | |
Avi Drissman | 36465f33 | 2017-09-11 20:49:39 | [diff] [blame] | 253 | if (original_opener_) { |
| 254 | original_opener_->RemoveObserver(original_opener_observer_.get()); |
| 255 | original_opener_observer_.reset(); |
| 256 | } |
| 257 | |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 258 | original_opener_ = opener; |
| 259 | |
| 260 | if (original_opener_) { |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 261 | original_opener_observer_ = |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 262 | std::make_unique<OpenerDestroyedObserver>(this, true); |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 263 | original_opener_->AddObserver(original_opener_observer_.get()); |
| 264 | } |
| 265 | } |
| 266 | |
creis | f0f069a | 2015-07-23 23:51:53 | [diff] [blame] | 267 | void FrameTreeNode::SetCurrentURL(const GURL& url) { |
Balazs Engedy | c8a7cccf | 2018-03-12 23:00:49 | [diff] [blame] | 268 | if (!has_committed_real_load_ && !url.IsAboutBlank()) |
creis | f0f069a | 2015-07-23 23:51:53 | [diff] [blame] | 269 | has_committed_real_load_ = true; |
Erik Chen | 173bf304 | 2017-07-31 06:06:21 | [diff] [blame] | 270 | current_frame_host()->SetLastCommittedUrl(url); |
xiaochengh | b9554bb | 2016-05-21 14:20:48 | [diff] [blame] | 271 | blame_context_.TakeSnapshot(); |
creis | f0f069a | 2015-07-23 23:51:53 | [diff] [blame] | 272 | } |
| 273 | |
estark | bd8e26f | 2016-03-16 23:30:37 | [diff] [blame] | 274 | void FrameTreeNode::SetCurrentOrigin( |
| 275 | const url::Origin& origin, |
| 276 | bool is_potentially_trustworthy_unique_origin) { |
| 277 | if (!origin.IsSameOriginWith(replication_state_.origin) || |
| 278 | replication_state_.has_potentially_trustworthy_unique_origin != |
| 279 | is_potentially_trustworthy_unique_origin) { |
| 280 | render_manager_.OnDidUpdateOrigin(origin, |
| 281 | is_potentially_trustworthy_unique_origin); |
| 282 | } |
alexmos | a7a4ff82 | 2015-04-27 17:59:56 | [diff] [blame] | 283 | replication_state_.origin = origin; |
estark | bd8e26f | 2016-03-16 23:30:37 | [diff] [blame] | 284 | replication_state_.has_potentially_trustworthy_unique_origin = |
| 285 | is_potentially_trustworthy_unique_origin; |
alexmos | a7a4ff82 | 2015-04-27 17:59:56 | [diff] [blame] | 286 | } |
alexmos | be2f4c3 | 2015-03-10 02:30:23 | [diff] [blame] | 287 | |
engedy | 6e2e099 | 2017-05-25 18:58:42 | [diff] [blame] | 288 | void FrameTreeNode::SetCollapsed(bool collapsed) { |
| 289 | DCHECK(!IsMainFrame()); |
| 290 | if (is_collapsed_ == collapsed) |
| 291 | return; |
| 292 | |
| 293 | is_collapsed_ = collapsed; |
| 294 | render_manager_.OnDidChangeCollapsedState(collapsed); |
| 295 | } |
| 296 | |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 297 | void FrameTreeNode::SetFrameName(const std::string& name, |
| 298 | const std::string& unique_name) { |
| 299 | if (name == replication_state_.name) { |
| 300 | // |unique_name| shouldn't change unless |name| changes. |
| 301 | DCHECK_EQ(unique_name, replication_state_.unique_name); |
| 302 | return; |
| 303 | } |
lukasza | 5140a41 | 2016-09-15 21:12:30 | [diff] [blame] | 304 | |
| 305 | if (parent()) { |
| 306 | // Non-main frames should have a non-empty unique name. |
| 307 | DCHECK(!unique_name.empty()); |
| 308 | } else { |
| 309 | // Unique name of main frames should always stay empty. |
| 310 | DCHECK(unique_name.empty()); |
| 311 | } |
| 312 | |
Daniel Cheng | 6ca7f1c9 | 2017-08-09 21:45:41 | [diff] [blame] | 313 | // Note the unique name should only be able to change before the first real |
| 314 | // load is committed, but that's not strongly enforced here. |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 315 | render_manager_.OnDidUpdateName(name, unique_name); |
alexmos | a7a4ff82 | 2015-04-27 17:59:56 | [diff] [blame] | 316 | replication_state_.name = name; |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 317 | replication_state_.unique_name = unique_name; |
alexmos | be2f4c3 | 2015-03-10 02:30:23 | [diff] [blame] | 318 | } |
| 319 | |
arthursonzogni | 662aa65 | 2017-03-28 11:09:50 | [diff] [blame] | 320 | void FrameTreeNode::AddContentSecurityPolicies( |
| 321 | const std::vector<ContentSecurityPolicyHeader>& headers) { |
| 322 | replication_state_.accumulated_csp_headers.insert( |
| 323 | replication_state_.accumulated_csp_headers.end(), headers.begin(), |
| 324 | headers.end()); |
| 325 | render_manager_.OnDidAddContentSecurityPolicies(headers); |
lukasza | 8e1c02e4 | 2016-05-17 20:05:10 | [diff] [blame] | 326 | } |
| 327 | |
mkwst | f672e7ef | 2016-06-09 20:51:07 | [diff] [blame] | 328 | void FrameTreeNode::SetInsecureRequestPolicy( |
| 329 | blink::WebInsecureRequestPolicy policy) { |
| 330 | if (policy == replication_state_.insecure_request_policy) |
estark | a886b8d | 2015-12-18 21:53:08 | [diff] [blame] | 331 | return; |
mkwst | f672e7ef | 2016-06-09 20:51:07 | [diff] [blame] | 332 | render_manager_.OnEnforceInsecureRequestPolicy(policy); |
| 333 | replication_state_.insecure_request_policy = policy; |
estark | a886b8d | 2015-12-18 21:53:08 | [diff] [blame] | 334 | } |
| 335 | |
arthursonzogni | 4b62a5cb | 2018-01-17 14:14:26 | [diff] [blame] | 336 | void FrameTreeNode::SetInsecureNavigationsSet( |
| 337 | const std::vector<uint32_t>& insecure_navigations_set) { |
| 338 | DCHECK(std::is_sorted(insecure_navigations_set.begin(), |
| 339 | insecure_navigations_set.end())); |
| 340 | if (insecure_navigations_set == replication_state_.insecure_navigations_set) |
| 341 | return; |
| 342 | render_manager_.OnEnforceInsecureNavigationsSet(insecure_navigations_set); |
| 343 | replication_state_.insecure_navigations_set = insecure_navigations_set; |
| 344 | } |
| 345 | |
Luna Lu | c3fdacdf | 2017-11-08 04:48:53 | [diff] [blame] | 346 | void FrameTreeNode::SetPendingFramePolicy(blink::FramePolicy frame_policy) { |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 347 | pending_frame_policy_.sandbox_flags = frame_policy.sandbox_flags; |
alexmos | 6e94010 | 2016-01-19 22:47:25 | [diff] [blame] | 348 | |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 349 | if (parent()) { |
| 350 | // Subframes should always inherit their parent's sandbox flags. |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 351 | pending_frame_policy_.sandbox_flags |= parent()->active_sandbox_flags(); |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 352 | // This is only applied on subframes; container policy is not mutable on |
| 353 | // main frame. |
| 354 | pending_frame_policy_.container_policy = frame_policy.container_policy; |
| 355 | } |
iclelland | 92f8c0b | 2017-04-19 12:43:05 | [diff] [blame] | 356 | } |
| 357 | |
alexmos | 9f8705a | 2015-05-06 19:58:59 | [diff] [blame] | 358 | FrameTreeNode* FrameTreeNode::PreviousSibling() const { |
paulmeyer | 322777fb | 2016-05-16 23:15:39 | [diff] [blame] | 359 | return GetSibling(-1); |
| 360 | } |
alexmos | 9f8705a | 2015-05-06 19:58:59 | [diff] [blame] | 361 | |
paulmeyer | 322777fb | 2016-05-16 23:15:39 | [diff] [blame] | 362 | FrameTreeNode* FrameTreeNode::NextSibling() const { |
| 363 | return GetSibling(1); |
alexmos | 9f8705a | 2015-05-06 19:58:59 | [diff] [blame] | 364 | } |
| 365 | |
fdegans | 4a49ce93 | 2015-03-12 17:11:37 | [diff] [blame] | 366 | bool FrameTreeNode::IsLoading() const { |
| 367 | RenderFrameHostImpl* current_frame_host = |
| 368 | render_manager_.current_frame_host(); |
fdegans | 4a49ce93 | 2015-03-12 17:11:37 | [diff] [blame] | 369 | |
| 370 | DCHECK(current_frame_host); |
fdegans | 39ff038 | 2015-04-29 19:04:39 | [diff] [blame] | 371 | |
clamy | 610c63b3 | 2017-12-22 15:05:18 | [diff] [blame] | 372 | if (navigation_request_) |
| 373 | return true; |
clamy | 11e1151 | 2015-07-07 16:42:17 | [diff] [blame] | 374 | |
clamy | 610c63b3 | 2017-12-22 15:05:18 | [diff] [blame] | 375 | RenderFrameHostImpl* speculative_frame_host = |
| 376 | render_manager_.speculative_frame_host(); |
| 377 | if (speculative_frame_host && speculative_frame_host->is_loading()) |
| 378 | return true; |
fdegans | 4a49ce93 | 2015-03-12 17:11:37 | [diff] [blame] | 379 | return current_frame_host->is_loading(); |
| 380 | } |
| 381 | |
iclelland | 92f8c0b | 2017-04-19 12:43:05 | [diff] [blame] | 382 | bool FrameTreeNode::CommitPendingFramePolicy() { |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 383 | bool did_change_flags = pending_frame_policy_.sandbox_flags != |
| 384 | replication_state_.frame_policy.sandbox_flags; |
iclelland | 92f8c0b | 2017-04-19 12:43:05 | [diff] [blame] | 385 | bool did_change_container_policy = |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 386 | pending_frame_policy_.container_policy != |
| 387 | replication_state_.frame_policy.container_policy; |
iclelland | 92f8c0b | 2017-04-19 12:43:05 | [diff] [blame] | 388 | if (did_change_flags) |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 389 | replication_state_.frame_policy.sandbox_flags = |
| 390 | pending_frame_policy_.sandbox_flags; |
iclelland | 92f8c0b | 2017-04-19 12:43:05 | [diff] [blame] | 391 | if (did_change_container_policy) |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 392 | replication_state_.frame_policy.container_policy = |
| 393 | pending_frame_policy_.container_policy; |
Ian Clelland | edb8c5dd | 2018-03-01 17:01:37 | [diff] [blame] | 394 | UpdateFramePolicyHeaders(pending_frame_policy_.sandbox_flags, |
| 395 | replication_state_.feature_policy_header); |
iclelland | 92f8c0b | 2017-04-19 12:43:05 | [diff] [blame] | 396 | return did_change_flags || did_change_container_policy; |
alexmos | 6b29456 | 2015-03-05 19:24:10 | [diff] [blame] | 397 | } |
| 398 | |
Arthur Hemery | c338017 | 2018-01-22 14:00:17 | [diff] [blame] | 399 | void FrameTreeNode::TransferNavigationRequestOwnership( |
| 400 | RenderFrameHostImpl* render_frame_host) { |
Andrey Kosyakov | f2d4ff7 | 2018-10-29 20:09:59 | [diff] [blame] | 401 | devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get()); |
Arthur Hemery | c338017 | 2018-01-22 14:00:17 | [diff] [blame] | 402 | render_frame_host->SetNavigationRequest(std::move(navigation_request_)); |
| 403 | } |
| 404 | |
carlosk | c49005eb | 2015-06-16 11:25:07 | [diff] [blame] | 405 | void FrameTreeNode::CreatedNavigationRequest( |
dcheng | 9bfa516 | 2016-04-09 01:00:57 | [diff] [blame] | 406 | std::unique_ptr<NavigationRequest> navigation_request) { |
arthursonzogni | c79c251c | 2016-08-18 15:00:37 | [diff] [blame] | 407 | // This is never called when navigating to a Javascript URL. For the loading |
| 408 | // state, this matches what Blink is doing: Blink doesn't send throbber |
| 409 | // notifications for Javascript URLS. |
| 410 | DCHECK(!navigation_request->common_params().url.SchemeIs( |
| 411 | url::kJavaScriptScheme)); |
| 412 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 413 | bool was_previously_loading = frame_tree()->IsLoading(); |
| 414 | |
clamy | 82a2f4d | 2016-02-02 14:20:41 | [diff] [blame] | 415 | // There's no need to reset the state: there's still an ongoing load, and the |
| 416 | // RenderFrameHostManager will take care of updates to the speculative |
| 417 | // RenderFrameHost in DidCreateNavigationRequest below. |
jam | cd0b7b2 | 2017-03-24 22:13:05 | [diff] [blame] | 418 | if (was_previously_loading) { |
clamy | 080e796 | 2017-05-25 00:44:18 | [diff] [blame] | 419 | if (navigation_request_ && navigation_request_->navigation_handle()) { |
jam | cd0b7b2 | 2017-03-24 22:13:05 | [diff] [blame] | 420 | // Mark the old request as aborted. |
Mohamed Abdelhalim | b4db22a | 2019-06-18 10:46:52 | [diff] [blame] | 421 | navigation_request_->set_net_error(net::ERR_ABORTED); |
jam | cd0b7b2 | 2017-03-24 22:13:05 | [diff] [blame] | 422 | } |
clamy | a86695b | 2017-03-23 14:45:48 | [diff] [blame] | 423 | ResetNavigationRequest(true, true); |
jam | cd0b7b2 | 2017-03-24 22:13:05 | [diff] [blame] | 424 | } |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 425 | |
| 426 | navigation_request_ = std::move(navigation_request); |
Shubhie Panicker | ddf2a4e | 2018-03-06 00:09:06 | [diff] [blame] | 427 | if (was_discarded_) { |
| 428 | navigation_request_->set_was_discarded(); |
| 429 | was_discarded_ = false; |
| 430 | } |
clamy | 8e2e29920 | 2016-04-05 11:44:59 | [diff] [blame] | 431 | render_manager()->DidCreateNavigationRequest(navigation_request_.get()); |
fdegans | 39ff038 | 2015-04-29 19:04:39 | [diff] [blame] | 432 | |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 433 | bool to_different_document = !NavigationTypeUtils::IsSameDocument( |
arthursonzogni | 92f1868 | 2017-02-08 23:00:04 | [diff] [blame] | 434 | navigation_request_->common_params().navigation_type); |
| 435 | |
| 436 | DidStartLoading(to_different_document, was_previously_loading); |
clamy | dcb434c1 | 2015-04-16 19:29:16 | [diff] [blame] | 437 | } |
| 438 | |
clamy | a86695b | 2017-03-23 14:45:48 | [diff] [blame] | 439 | void FrameTreeNode::ResetNavigationRequest(bool keep_state, |
| 440 | bool inform_renderer) { |
fdegans | 39ff038 | 2015-04-29 19:04:39 | [diff] [blame] | 441 | if (!navigation_request_) |
| 442 | return; |
John Abd-El-Malek | dcc7bf4 | 2017-09-12 22:30:23 | [diff] [blame] | 443 | |
Andrey Kosyakov | f2d4ff7 | 2018-10-29 20:09:59 | [diff] [blame] | 444 | devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get()); |
Pavel Feldman | d8352ac | 2017-11-10 00:37:41 | [diff] [blame] | 445 | |
John Abd-El-Malek | dcc7bf4 | 2017-09-12 22:30:23 | [diff] [blame] | 446 | // The renderer should be informed if the caller allows to do so and the |
| 447 | // navigation came from a BeginNavigation IPC. |
Arthur Hemery | d3011f6 | 2018-05-30 10:38:44 | [diff] [blame] | 448 | bool need_to_inform_renderer = |
| 449 | !IsPerNavigationMojoInterfaceEnabled() & inform_renderer && |
| 450 | navigation_request_->from_begin_navigation(); |
John Abd-El-Malek | dcc7bf4 | 2017-09-12 22:30:23 | [diff] [blame] | 451 | |
clamy | 8e2e29920 | 2016-04-05 11:44:59 | [diff] [blame] | 452 | NavigationRequest::AssociatedSiteInstanceType site_instance_type = |
| 453 | navigation_request_->associated_site_instance_type(); |
clamy | dcb434c1 | 2015-04-16 19:29:16 | [diff] [blame] | 454 | navigation_request_.reset(); |
fdegans | 39ff038 | 2015-04-29 19:04:39 | [diff] [blame] | 455 | |
clamy | 82a2f4d | 2016-02-02 14:20:41 | [diff] [blame] | 456 | if (keep_state) |
fdegans | 39ff038 | 2015-04-29 19:04:39 | [diff] [blame] | 457 | return; |
| 458 | |
clamy | 82a2f4d | 2016-02-02 14:20:41 | [diff] [blame] | 459 | // The RenderFrameHostManager should clean up any speculative RenderFrameHost |
| 460 | // it created for the navigation. Also register that the load stopped. |
fdegans | 39ff038 | 2015-04-29 19:04:39 | [diff] [blame] | 461 | DidStopLoading(); |
| 462 | render_manager_.CleanUpNavigation(); |
clamy | 2567242a | 2016-02-22 18:27:38 | [diff] [blame] | 463 | |
clamy | 8e2e29920 | 2016-04-05 11:44:59 | [diff] [blame] | 464 | // When reusing the same SiteInstance, a pending WebUI may have been created |
| 465 | // on behalf of the navigation in the current RenderFrameHost. Clear it. |
| 466 | if (site_instance_type == |
| 467 | NavigationRequest::AssociatedSiteInstanceType::CURRENT) { |
| 468 | current_frame_host()->ClearPendingWebUI(); |
| 469 | } |
| 470 | |
clamy | 2567242a | 2016-02-22 18:27:38 | [diff] [blame] | 471 | // If the navigation is renderer-initiated, the renderer should also be |
clamy | a86695b | 2017-03-23 14:45:48 | [diff] [blame] | 472 | // informed that the navigation stopped if needed. In the case the renderer |
| 473 | // process asked for the navigation to be aborted, e.g. following a |
| 474 | // document.open, do not send an IPC to the renderer process as it already |
| 475 | // expects the navigation to stop. |
John Abd-El-Malek | dcc7bf4 | 2017-09-12 22:30:23 | [diff] [blame] | 476 | if (need_to_inform_renderer) { |
clamy | 2567242a | 2016-02-22 18:27:38 | [diff] [blame] | 477 | current_frame_host()->Send( |
John Abd-El-Malek | dcc7bf4 | 2017-09-12 22:30:23 | [diff] [blame] | 478 | new FrameMsg_DroppedNavigation(current_frame_host()->GetRoutingID())); |
clamy | 2567242a | 2016-02-22 18:27:38 | [diff] [blame] | 479 | } |
clamy | dcb434c1 | 2015-04-16 19:29:16 | [diff] [blame] | 480 | } |
| 481 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 482 | void FrameTreeNode::DidStartLoading(bool to_different_document, |
| 483 | bool was_previously_loading) { |
Camille Lamy | efd54b0 | 2018-10-04 16:54:14 | [diff] [blame] | 484 | TRACE_EVENT2("navigation", "FrameTreeNode::DidStartLoading", |
| 485 | "frame_tree_node", frame_tree_node_id(), "to different document", |
| 486 | to_different_document); |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 487 | // Any main frame load to a new document should reset the load progress since |
| 488 | // it will replace the current page and any frames. The WebContents will |
| 489 | // be notified when DidChangeLoadProgress is called. |
| 490 | if (to_different_document && IsMainFrame()) |
| 491 | frame_tree_->ResetLoadProgress(); |
| 492 | |
| 493 | // Notify the WebContents. |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 494 | if (!was_previously_loading) |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 495 | navigator()->GetDelegate()->DidStartLoading(this, to_different_document); |
| 496 | |
| 497 | // Set initial load progress and update overall progress. This will notify |
| 498 | // the WebContents of the load progress change. |
| 499 | DidChangeLoadProgress(kLoadingProgressMinimum); |
| 500 | |
| 501 | // Notify the RenderFrameHostManager of the event. |
| 502 | render_manager()->OnDidStartLoading(); |
| 503 | } |
| 504 | |
| 505 | void FrameTreeNode::DidStopLoading() { |
Camille Lamy | efd54b0 | 2018-10-04 16:54:14 | [diff] [blame] | 506 | TRACE_EVENT1("navigation", "FrameTreeNode::DidStopLoading", "frame_tree_node", |
| 507 | frame_tree_node_id()); |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 508 | // Set final load progress and update overall progress. This will notify |
| 509 | // the WebContents of the load progress change. |
| 510 | DidChangeLoadProgress(kLoadingProgressDone); |
| 511 | |
Lucas Furukawa Gadani | 6faef60 | 2019-05-06 21:16:03 | [diff] [blame] | 512 | // Notify the RenderFrameHostManager of the event. |
| 513 | render_manager()->OnDidStopLoading(); |
| 514 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 515 | // Notify the WebContents. |
| 516 | if (!frame_tree_->IsLoading()) |
| 517 | navigator()->GetDelegate()->DidStopLoading(); |
| 518 | |
Dominic Mazzoni | 3c7007a | 2017-12-12 07:34:05 | [diff] [blame] | 519 | // Notify accessibility that the user is no longer trying to load or |
| 520 | // reload a page. |
Dominic Farolino | f87ec2a | 2019-07-04 09:18:09 | [diff] [blame] | 521 | // TODO(domfarolino): Remove this in favor of notifying via the delegate's |
| 522 | // DidStopLoading() above. |
Dominic Mazzoni | 3c7007a | 2017-12-12 07:34:05 | [diff] [blame] | 523 | BrowserAccessibilityManager* manager = |
| 524 | current_frame_host()->browser_accessibility_manager(); |
| 525 | if (manager) |
| 526 | manager->DidStopLoading(); |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | void FrameTreeNode::DidChangeLoadProgress(double load_progress) { |
Nate Chapin | 9353670 | 2018-02-07 00:12:21 | [diff] [blame] | 530 | DCHECK_GE(load_progress, kLoadingProgressMinimum); |
| 531 | DCHECK_LE(load_progress, kLoadingProgressDone); |
| 532 | if (IsMainFrame()) |
| 533 | frame_tree_->UpdateLoadProgress(load_progress); |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 534 | } |
| 535 | |
clamy | f73862c4 | 2015-07-08 12:31:33 | [diff] [blame] | 536 | bool FrameTreeNode::StopLoading() { |
Nasko Oskov | a951135 | 2018-09-15 00:11:10 | [diff] [blame] | 537 | if (navigation_request_) { |
| 538 | int expected_pending_nav_entry_id = navigation_request_->nav_entry_id(); |
| 539 | if (navigation_request_->navigation_handle()) { |
Mohamed Abdelhalim | b4db22a | 2019-06-18 10:46:52 | [diff] [blame] | 540 | navigation_request_->set_net_error(net::ERR_ABORTED); |
Nasko Oskov | a951135 | 2018-09-15 00:11:10 | [diff] [blame] | 541 | expected_pending_nav_entry_id = |
| 542 | navigation_request_->navigation_handle()->pending_nav_entry_id(); |
jam | 0299edae | 2017-03-10 00:49:22 | [diff] [blame] | 543 | } |
Nasko Oskov | a951135 | 2018-09-15 00:11:10 | [diff] [blame] | 544 | navigator_->DiscardPendingEntryIfNeeded(expected_pending_nav_entry_id); |
jam | 0299edae | 2017-03-10 00:49:22 | [diff] [blame] | 545 | } |
Nasko Oskov | a951135 | 2018-09-15 00:11:10 | [diff] [blame] | 546 | ResetNavigationRequest(false, true); |
clamy | f73862c4 | 2015-07-08 12:31:33 | [diff] [blame] | 547 | |
| 548 | // TODO(nasko): see if child frames should send IPCs in site-per-process |
| 549 | // mode. |
| 550 | if (!IsMainFrame()) |
| 551 | return true; |
| 552 | |
| 553 | render_manager_.Stop(); |
| 554 | return true; |
| 555 | } |
| 556 | |
alexmos | 21acae5 | 2015-11-07 01:04:43 | [diff] [blame] | 557 | void FrameTreeNode::DidFocus() { |
| 558 | last_focus_time_ = base::TimeTicks::Now(); |
ericwilligers | 254597b | 2016-10-17 10:32:31 | [diff] [blame] | 559 | for (auto& observer : observers_) |
| 560 | observer.OnFrameTreeNodeFocused(this); |
alexmos | 21acae5 | 2015-11-07 01:04:43 | [diff] [blame] | 561 | } |
| 562 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 563 | void FrameTreeNode::BeforeUnloadCanceled() { |
| 564 | // TODO(clamy): Support BeforeUnload in subframes. |
| 565 | if (!IsMainFrame()) |
| 566 | return; |
| 567 | |
| 568 | RenderFrameHostImpl* current_frame_host = |
| 569 | render_manager_.current_frame_host(); |
| 570 | DCHECK(current_frame_host); |
| 571 | current_frame_host->ResetLoadingState(); |
| 572 | |
clamy | 610c63b3 | 2017-12-22 15:05:18 | [diff] [blame] | 573 | RenderFrameHostImpl* speculative_frame_host = |
| 574 | render_manager_.speculative_frame_host(); |
| 575 | if (speculative_frame_host) |
| 576 | speculative_frame_host->ResetLoadingState(); |
| 577 | // Note: there is no need to set an error code on the NavigationHandle here |
| 578 | // as it has not been created yet. It is only created when the |
| 579 | // BeforeUnloadACK is received. |
| 580 | if (navigation_request_) |
| 581 | ResetNavigationRequest(false, true); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 582 | } |
| 583 | |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 584 | bool FrameTreeNode::NotifyUserActivation() { |
John Delaney | edd8d6c | 2019-01-25 00:23:57 | [diff] [blame] | 585 | for (FrameTreeNode* node = this; node; node = node->parent()) { |
| 586 | if (!node->user_activation_state_.HasBeenActive() && |
| 587 | node->current_frame_host()) |
| 588 | node->current_frame_host()->DidReceiveFirstUserActivation(); |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 589 | node->user_activation_state_.Activate(); |
John Delaney | edd8d6c | 2019-01-25 00:23:57 | [diff] [blame] | 590 | } |
japhet | 61835ae1 | 2017-01-20 01:25:39 | [diff] [blame] | 591 | replication_state_.has_received_user_gesture = true; |
Mustaq Ahmed | a5dfa60b | 2018-12-08 00:30:14 | [diff] [blame] | 592 | |
Mustaq Ahmed | 0180320f | 2019-03-21 16:07:01 | [diff] [blame] | 593 | // See the "Same-origin Visibility" section in |UserActivationState| class |
| 594 | // doc. |
Mustaq Ahmed | a5dfa60b | 2018-12-08 00:30:14 | [diff] [blame] | 595 | if (base::FeatureList::IsEnabled(features::kUserActivationV2) && |
| 596 | base::FeatureList::IsEnabled( |
| 597 | features::kUserActivationSameOriginVisibility)) { |
| 598 | const url::Origin& current_origin = |
| 599 | this->current_frame_host()->GetLastCommittedOrigin(); |
| 600 | for (FrameTreeNode* node : frame_tree()->Nodes()) { |
| 601 | if (node->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith( |
| 602 | current_origin)) { |
| 603 | node->user_activation_state_.Activate(); |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | |
Shivani Sharma | 20749e92 | 2019-03-11 17:00:26 | [diff] [blame] | 608 | NavigationControllerImpl* controller = |
| 609 | static_cast<NavigationControllerImpl*>(navigator()->GetController()); |
| 610 | if (controller) |
| 611 | controller->NotifyUserActivation(); |
Shivani Sharma | 19487703 | 2019-03-07 17:52:47 | [diff] [blame] | 612 | |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 613 | return true; |
| 614 | } |
| 615 | |
| 616 | bool FrameTreeNode::ConsumeTransientUserActivation() { |
| 617 | bool was_active = user_activation_state_.IsActive(); |
| 618 | for (FrameTreeNode* node : frame_tree()->Nodes()) |
| 619 | node->user_activation_state_.ConsumeIfActive(); |
| 620 | return was_active; |
| 621 | } |
| 622 | |
Shivani Sharma | c4f56158 | 2018-11-15 15:58:39 | [diff] [blame] | 623 | bool FrameTreeNode::ClearUserActivation() { |
Shivani Sharma | c4f56158 | 2018-11-15 15:58:39 | [diff] [blame] | 624 | for (FrameTreeNode* node : frame_tree()->SubtreeNodes(this)) |
| 625 | node->user_activation_state_.Clear(); |
| 626 | return true; |
| 627 | } |
| 628 | |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 629 | bool FrameTreeNode::UpdateUserActivationState( |
| 630 | blink::UserActivationUpdateType update_type) { |
| 631 | render_manager_.UpdateUserActivationState(update_type); |
| 632 | switch (update_type) { |
| 633 | case blink::UserActivationUpdateType::kConsumeTransientActivation: |
| 634 | return ConsumeTransientUserActivation(); |
| 635 | |
| 636 | case blink::UserActivationUpdateType::kNotifyActivation: |
| 637 | return NotifyUserActivation(); |
Shivani Sharma | c4f56158 | 2018-11-15 15:58:39 | [diff] [blame] | 638 | |
| 639 | case blink::UserActivationUpdateType::kClearActivation: |
| 640 | return ClearUserActivation(); |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 641 | } |
| 642 | NOTREACHED() << "Invalid update_type."; |
japhet | 61835ae1 | 2017-01-20 01:25:39 | [diff] [blame] | 643 | } |
| 644 | |
Becca Hughes | 60af7d4 | 2017-12-12 10:53:15 | [diff] [blame] | 645 | void FrameTreeNode::OnSetHasReceivedUserGestureBeforeNavigation(bool value) { |
| 646 | render_manager_.OnSetHasReceivedUserGestureBeforeNavigation(value); |
| 647 | replication_state_.has_received_user_gesture_before_nav = value; |
| 648 | } |
| 649 | |
paulmeyer | 322777fb | 2016-05-16 23:15:39 | [diff] [blame] | 650 | FrameTreeNode* FrameTreeNode::GetSibling(int relative_offset) const { |
paulmeyer | f3119f5 | 2016-05-17 17:37:19 | [diff] [blame] | 651 | if (!parent_ || !parent_->child_count()) |
paulmeyer | 322777fb | 2016-05-16 23:15:39 | [diff] [blame] | 652 | return nullptr; |
| 653 | |
| 654 | for (size_t i = 0; i < parent_->child_count(); ++i) { |
| 655 | if (parent_->child_at(i) == this) { |
| 656 | if ((relative_offset < 0 && static_cast<size_t>(-relative_offset) > i) || |
| 657 | i + relative_offset >= parent_->child_count()) { |
| 658 | return nullptr; |
| 659 | } |
| 660 | return parent_->child_at(i + relative_offset); |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | NOTREACHED() << "FrameTreeNode not found in its parent's children."; |
| 665 | return nullptr; |
| 666 | } |
| 667 | |
Ian Clelland | edb8c5dd | 2018-03-01 17:01:37 | [diff] [blame] | 668 | void FrameTreeNode::UpdateFramePolicyHeaders( |
| 669 | blink::WebSandboxFlags sandbox_flags, |
| 670 | const blink::ParsedFeaturePolicy& parsed_header) { |
| 671 | bool changed = false; |
| 672 | if (replication_state_.feature_policy_header != parsed_header) { |
| 673 | replication_state_.feature_policy_header = parsed_header; |
| 674 | changed = true; |
| 675 | } |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 676 | // TODO(iclelland): Kill the renderer if sandbox flags is not a subset of the |
| 677 | // currently effective sandbox flags from the frame. https://crbug.com/740556 |
Ian Clelland | edb8c5dd | 2018-03-01 17:01:37 | [diff] [blame] | 678 | blink::WebSandboxFlags updated_flags = |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 679 | sandbox_flags | effective_frame_policy().sandbox_flags; |
Ian Clelland | edb8c5dd | 2018-03-01 17:01:37 | [diff] [blame] | 680 | if (replication_state_.active_sandbox_flags != updated_flags) { |
| 681 | replication_state_.active_sandbox_flags = updated_flags; |
| 682 | changed = true; |
| 683 | } |
| 684 | // Notify any proxies if the policies have been changed. |
| 685 | if (changed) |
| 686 | render_manager()->OnDidSetFramePolicyHeaders(); |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 687 | } |
| 688 | |
Lan Wei | f0cb8e6e | 2019-04-19 00:14:53 | [diff] [blame] | 689 | void FrameTreeNode::TransferUserActivationFrom( |
| 690 | RenderFrameHostImpl* source_rfh) { |
| 691 | user_activation_state_.TransferFrom( |
| 692 | source_rfh->frame_tree_node()->user_activation_state_); |
| 693 | |
| 694 | // Notify proxies in non-source and non-target renderer processes to |
| 695 | // transfer the activation state from the source proxy to the target |
| 696 | // so the user activation state of those proxies matches the source |
| 697 | // renderer and the target renderer (which are separately updated). |
| 698 | render_manager_.TransferUserActivationFrom(source_rfh); |
Lan Wei | 550671a2 | 2019-03-19 00:59:24 | [diff] [blame] | 699 | } |
| 700 | |
Arthur Sonzogni | f8840b9 | 2018-11-07 14:10:35 | [diff] [blame] | 701 | void FrameTreeNode::PruneChildFrameNavigationEntries( |
| 702 | NavigationEntryImpl* entry) { |
| 703 | for (size_t i = 0; i < current_frame_host()->child_count(); ++i) { |
| 704 | FrameTreeNode* child = current_frame_host()->child_at(i); |
| 705 | if (child->is_created_by_script_) { |
| 706 | entry->RemoveEntryForFrame(child, |
| 707 | /* only_if_different_position = */ false); |
| 708 | } else { |
| 709 | child->PruneChildFrameNavigationEntries(entry); |
| 710 | } |
| 711 | } |
| 712 | } |
| 713 | |
Ehsan Karamad | 3940708 | 2019-02-19 23:38:19 | [diff] [blame] | 714 | void FrameTreeNode::SetOpenerFeaturePolicyState( |
| 715 | const blink::FeaturePolicy::FeatureState& feature_state) { |
| 716 | DCHECK(IsMainFrame()); |
| 717 | if (base::FeatureList::IsEnabled(features::kFeaturePolicyForSandbox)) { |
| 718 | replication_state_.opener_feature_state = feature_state; |
| 719 | } |
| 720 | } |
| 721 | |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 722 | } // namespace content |