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