Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(565)

Side by Side Diff: content/browser/frame_host/frame_tree_node.cc

Issue 1901023003: Introduce browser side FrameTreeNodeBlameContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/frame_host/frame_tree_node.h" 5 #include "content/browser/frame_host/frame_tree_node.h"
6 6
7 #include <queue> 7 #include <queue>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/profiler/scoped_tracker.h" 12 #include "base/profiler/scoped_tracker.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "content/browser/frame_host/frame_tree.h" 14 #include "content/browser/frame_host/frame_tree.h"
15 #include "content/browser/frame_host/navigation_request.h" 15 #include "content/browser/frame_host/navigation_request.h"
16 #include "content/browser/frame_host/navigator.h" 16 #include "content/browser/frame_host/navigator.h"
17 #include "content/browser/frame_host/render_frame_host_impl.h" 17 #include "content/browser/frame_host/render_frame_host_impl.h"
18 #include "content/browser/frame_host/traced_frame_tree_node.h"
19 #include "content/browser/renderer_host/render_view_host_impl.h" 18 #include "content/browser/renderer_host/render_view_host_impl.h"
20 #include "content/common/frame_messages.h" 19 #include "content/common/frame_messages.h"
21 #include "content/common/site_isolation_policy.h" 20 #include "content/common/site_isolation_policy.h"
22 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
23 #include "content/public/common/browser_side_navigation_policy.h" 22 #include "content/public/common/browser_side_navigation_policy.h"
24 #include "third_party/WebKit/public/web/WebSandboxFlags.h" 23 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
25 24
26 namespace content { 25 namespace content {
27 26
28 namespace { 27 namespace {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 has_committed_real_load_(false), 93 has_committed_real_load_(false),
95 replication_state_( 94 replication_state_(
96 scope, 95 scope,
97 name, 96 name,
98 unique_name, 97 unique_name,
99 blink::WebSandboxFlags::None, 98 blink::WebSandboxFlags::None,
100 false /* should enforce strict mixed content checking */, 99 false /* should enforce strict mixed content checking */,
101 false /* is a potentially trustworthy unique origin */), 100 false /* is a potentially trustworthy unique origin */),
102 pending_sandbox_flags_(blink::WebSandboxFlags::None), 101 pending_sandbox_flags_(blink::WebSandboxFlags::None),
103 frame_owner_properties_(frame_owner_properties), 102 frame_owner_properties_(frame_owner_properties),
104 loading_progress_(kLoadingProgressNotStarted) { 103 loading_progress_(kLoadingProgressNotStarted),
104 blame_context_(nullptr) {
105 std::pair<FrameTreeNodeIdMap::iterator, bool> result = 105 std::pair<FrameTreeNodeIdMap::iterator, bool> result =
106 g_frame_tree_node_id_map.Get().insert( 106 g_frame_tree_node_id_map.Get().insert(
107 std::make_pair(frame_tree_node_id_, this)); 107 std::make_pair(frame_tree_node_id_, this));
108 CHECK(result.second); 108 CHECK(result.second);
109
110 TRACE_EVENT_OBJECT_CREATED_WITH_ID(
111 "navigation", "FrameTreeNode",
112 TRACE_ID_WITH_SCOPE("FrameTreeNode", frame_tree_node_id_));
113 // Don't TraceSnapshot() until the RenderFrameHostManager is initialized and
114 // calls SetCurrentURL().
115 } 109 }
116 110
117 FrameTreeNode::~FrameTreeNode() { 111 FrameTreeNode::~FrameTreeNode() {
118 children_.clear(); 112 children_.clear();
119 frame_tree_->FrameRemoved(this); 113 frame_tree_->FrameRemoved(this);
120 FOR_EACH_OBSERVER(Observer, observers_, OnFrameTreeNodeDestroyed(this)); 114 FOR_EACH_OBSERVER(Observer, observers_, OnFrameTreeNodeDestroyed(this));
121 115
122 if (opener_) 116 if (opener_)
123 opener_->RemoveObserver(opener_observer_.get()); 117 opener_->RemoveObserver(opener_observer_.get());
124 118
125 g_frame_tree_node_id_map.Get().erase(frame_tree_node_id_); 119 g_frame_tree_node_id_map.Get().erase(frame_tree_node_id_);
126 120
127 TRACE_EVENT_OBJECT_DELETED_WITH_ID( 121 // TODO(xiaochengh): Is this check necessary?
128 "navigation", "FrameTreeNode", 122 if (blame_context_)
129 TRACE_ID_WITH_SCOPE("FrameTreeNode", frame_tree_node_id_)); 123 blame_context_->ClearArguments();
130 } 124 }
131 125
132 void FrameTreeNode::AddObserver(Observer* observer) { 126 void FrameTreeNode::AddObserver(Observer* observer) {
133 observers_.AddObserver(observer); 127 observers_.AddObserver(observer);
134 } 128 }
135 129
136 void FrameTreeNode::RemoveObserver(Observer* observer) { 130 void FrameTreeNode::RemoveObserver(Observer* observer) {
137 observers_.RemoveObserver(observer); 131 observers_.RemoveObserver(observer);
138 } 132 }
139 133
140 bool FrameTreeNode::IsMainFrame() const { 134 bool FrameTreeNode::IsMainFrame() const {
141 return frame_tree_->root() == this; 135 return frame_tree_->root() == this;
142 } 136 }
143 137
144 FrameTreeNode* FrameTreeNode::AddChild(std::unique_ptr<FrameTreeNode> child, 138 FrameTreeNode* FrameTreeNode::AddChild(std::unique_ptr<FrameTreeNode> child,
145 int process_id, 139 int process_id,
146 int frame_routing_id) { 140 int frame_routing_id) {
147 // Child frame must always be created in the same process as the parent. 141 // Child frame must always be created in the same process as the parent.
148 CHECK_EQ(process_id, render_manager_.current_host()->GetProcess()->GetID()); 142 CHECK_EQ(process_id, render_manager_.current_host()->GetProcess()->GetID());
149 child->set_parent(this); 143 child->set_parent(this);
150 144
145 // TODO(xiaochengh): Is it the right timing to initialize BlameContext?
146 // It has to be after setting parent, because BlameContext::parent_id_ cannot
147 // be changed once initialized.
148 child->InitializeBlameContext();
Xiaocheng 2016/04/20 02:01:05 One more question: BlameContext::parent_id_ is dec
Sami 2016/04/20 12:15:08 If the topology changes, the easiest thing to do i
149
151 // Initialize the RenderFrameHost for the new node. We always create child 150 // Initialize the RenderFrameHost for the new node. We always create child
152 // frames in the same SiteInstance as the current frame, and they can swap to 151 // frames in the same SiteInstance as the current frame, and they can swap to
153 // a different one if they navigate away. 152 // a different one if they navigate away.
154 child->render_manager()->Init( 153 child->render_manager()->Init(
155 render_manager_.current_host()->GetSiteInstance(), 154 render_manager_.current_host()->GetSiteInstance(),
156 render_manager_.current_host()->GetRoutingID(), frame_routing_id, 155 render_manager_.current_host()->GetRoutingID(), frame_routing_id,
157 MSG_ROUTING_NONE); 156 MSG_ROUTING_NONE);
158 157
159 // Other renderer processes in this BrowsingInstance may need to find out 158 // Other renderer processes in this BrowsingInstance may need to find out
160 // about the new frame. Create a proxy for the child frame in all 159 // about the new frame. Create a proxy for the child frame in all
(...skipping 15 matching lines...) Expand all
176 std::unique_ptr<FrameTreeNode> node_to_delete(std::move(*iter)); 175 std::unique_ptr<FrameTreeNode> node_to_delete(std::move(*iter));
177 children_.erase(iter); 176 children_.erase(iter);
178 node_to_delete.reset(); 177 node_to_delete.reset();
179 return; 178 return;
180 } 179 }
181 } 180 }
182 } 181 }
183 182
184 void FrameTreeNode::ResetForNewProcess() { 183 void FrameTreeNode::ResetForNewProcess() {
185 current_frame_host()->set_last_committed_url(GURL()); 184 current_frame_host()->set_last_committed_url(GURL());
186 TraceSnapshot(); 185
186 // TODO(xiaochengh): Is this check necessary?
187 if (blame_context_) {
188 blame_context_->UpdateArguments(this);
189 blame_context_->TakeSnapshot();
190 }
187 191
188 // Remove child nodes from the tree, then delete them. This destruction 192 // Remove child nodes from the tree, then delete them. This destruction
189 // operation will notify observers. 193 // operation will notify observers.
190 std::vector<std::unique_ptr<FrameTreeNode>>().swap(children_); 194 std::vector<std::unique_ptr<FrameTreeNode>>().swap(children_);
191 } 195 }
192 196
193 void FrameTreeNode::SetOpener(FrameTreeNode* opener) { 197 void FrameTreeNode::SetOpener(FrameTreeNode* opener) {
194 if (opener_) { 198 if (opener_) {
195 opener_->RemoveObserver(opener_observer_.get()); 199 opener_->RemoveObserver(opener_observer_.get());
196 opener_observer_.reset(); 200 opener_observer_.reset();
197 } 201 }
198 202
199 opener_ = opener; 203 opener_ = opener;
200 204
201 if (opener_) { 205 if (opener_) {
202 if (!opener_observer_) 206 if (!opener_observer_)
203 opener_observer_ = base::WrapUnique(new OpenerDestroyedObserver(this)); 207 opener_observer_ = base::WrapUnique(new OpenerDestroyedObserver(this));
204 opener_->AddObserver(opener_observer_.get()); 208 opener_->AddObserver(opener_observer_.get());
205 } 209 }
206 } 210 }
207 211
208 void FrameTreeNode::SetCurrentURL(const GURL& url) { 212 void FrameTreeNode::SetCurrentURL(const GURL& url) {
209 if (!has_committed_real_load_ && url != GURL(url::kAboutBlankURL)) 213 if (!has_committed_real_load_ && url != GURL(url::kAboutBlankURL))
210 has_committed_real_load_ = true; 214 has_committed_real_load_ = true;
211 current_frame_host()->set_last_committed_url(url); 215 current_frame_host()->set_last_committed_url(url);
212 TraceSnapshot(); 216
217 // TODO(xiaochengh): Is this check necessary?
218 if (blame_context_) {
219 blame_context_->UpdateArguments(this);
220 blame_context_->TakeSnapshot();
221 }
213 } 222 }
214 223
215 void FrameTreeNode::SetCurrentOrigin( 224 void FrameTreeNode::SetCurrentOrigin(
216 const url::Origin& origin, 225 const url::Origin& origin,
217 bool is_potentially_trustworthy_unique_origin) { 226 bool is_potentially_trustworthy_unique_origin) {
218 if (!origin.IsSameOriginWith(replication_state_.origin) || 227 if (!origin.IsSameOriginWith(replication_state_.origin) ||
219 replication_state_.has_potentially_trustworthy_unique_origin != 228 replication_state_.has_potentially_trustworthy_unique_origin !=
220 is_potentially_trustworthy_unique_origin) { 229 is_potentially_trustworthy_unique_origin) {
221 render_manager_.OnDidUpdateOrigin(origin, 230 render_manager_.OnDidUpdateOrigin(origin,
222 is_potentially_trustworthy_unique_origin); 231 is_potentially_trustworthy_unique_origin);
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 if (speculative_frame_host) 480 if (speculative_frame_host)
472 speculative_frame_host->ResetLoadingState(); 481 speculative_frame_host->ResetLoadingState();
473 } else { 482 } else {
474 RenderFrameHostImpl* pending_frame_host = 483 RenderFrameHostImpl* pending_frame_host =
475 render_manager_.pending_frame_host(); 484 render_manager_.pending_frame_host();
476 if (pending_frame_host) 485 if (pending_frame_host)
477 pending_frame_host->ResetLoadingState(); 486 pending_frame_host->ResetLoadingState();
478 } 487 }
479 } 488 }
480 489
481 void FrameTreeNode::TraceSnapshot() const { 490 void FrameTreeNode::InitializeBlameContext() {
482 DCHECK_CURRENTLY_ON(BrowserThread::UI); 491 DCHECK(!blame_context_);
483 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( 492 blame_context_ = new FrameTreeNodeBlameContext(this);
benjhayden 2016/04/20 01:37:34 Where is this object deleted?
Xiaocheng 2016/04/20 02:01:05 See the reply for the last comment.
484 "navigation", "FrameTreeNode", 493 blame_context_->Initialize();
485 TRACE_ID_WITH_SCOPE("FrameTreeNode", frame_tree_node_id_),
486 std::unique_ptr<base::trace_event::ConvertableToTraceFormat>(
487 new TracedFrameTreeNode(*this)));
488 } 494 }
489 495
490 } // namespace content 496 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698