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

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: Remove thread safety handling (and its doc) Created 4 years, 7 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
105 std::pair<FrameTreeNodeIdMap::iterator, bool> result = 104 std::pair<FrameTreeNodeIdMap::iterator, bool> result =
106 g_frame_tree_node_id_map.Get().insert( 105 g_frame_tree_node_id_map.Get().insert(
107 std::make_pair(frame_tree_node_id_, this)); 106 std::make_pair(frame_tree_node_id_, this));
108 CHECK(result.second); 107 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 } 108 }
116 109
117 FrameTreeNode::~FrameTreeNode() { 110 FrameTreeNode::~FrameTreeNode() {
118 children_.clear(); 111 children_.clear();
119 frame_tree_->FrameRemoved(this); 112 frame_tree_->FrameRemoved(this);
120 FOR_EACH_OBSERVER(Observer, observers_, OnFrameTreeNodeDestroyed(this)); 113 FOR_EACH_OBSERVER(Observer, observers_, OnFrameTreeNodeDestroyed(this));
121 114
122 if (opener_) 115 if (opener_)
123 opener_->RemoveObserver(opener_observer_.get()); 116 opener_->RemoveObserver(opener_observer_.get());
124 117
125 g_frame_tree_node_id_map.Get().erase(frame_tree_node_id_); 118 g_frame_tree_node_id_map.Get().erase(frame_tree_node_id_);
126
127 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
128 "navigation", "FrameTreeNode",
129 TRACE_ID_WITH_SCOPE("FrameTreeNode", frame_tree_node_id_));
130 } 119 }
131 120
132 void FrameTreeNode::AddObserver(Observer* observer) { 121 void FrameTreeNode::AddObserver(Observer* observer) {
133 observers_.AddObserver(observer); 122 observers_.AddObserver(observer);
134 } 123 }
135 124
136 void FrameTreeNode::RemoveObserver(Observer* observer) { 125 void FrameTreeNode::RemoveObserver(Observer* observer) {
137 observers_.RemoveObserver(observer); 126 observers_.RemoveObserver(observer);
138 } 127 }
139 128
140 bool FrameTreeNode::IsMainFrame() const { 129 bool FrameTreeNode::IsMainFrame() const {
141 return frame_tree_->root() == this; 130 return frame_tree_->root() == this;
142 } 131 }
143 132
144 FrameTreeNode* FrameTreeNode::AddChild(std::unique_ptr<FrameTreeNode> child, 133 FrameTreeNode* FrameTreeNode::AddChild(std::unique_ptr<FrameTreeNode> child,
145 int process_id, 134 int process_id,
146 int frame_routing_id) { 135 int frame_routing_id) {
147 // Child frame must always be created in the same process as the parent. 136 // Child frame must always be created in the same process as the parent.
148 CHECK_EQ(process_id, render_manager_.current_host()->GetProcess()->GetID()); 137 CHECK_EQ(process_id, render_manager_.current_host()->GetProcess()->GetID());
149 child->set_parent(this); 138 child->set_parent(this);
150 139
140 child->InitializeBlameContext();
141
151 // Initialize the RenderFrameHost for the new node. We always create child 142 // 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 143 // frames in the same SiteInstance as the current frame, and they can swap to
153 // a different one if they navigate away. 144 // a different one if they navigate away.
154 child->render_manager()->Init( 145 child->render_manager()->Init(
155 render_manager_.current_host()->GetSiteInstance(), 146 render_manager_.current_host()->GetSiteInstance(),
156 render_manager_.current_host()->GetRoutingID(), frame_routing_id, 147 render_manager_.current_host()->GetRoutingID(), frame_routing_id,
157 MSG_ROUTING_NONE); 148 MSG_ROUTING_NONE);
158 149
159 // Other renderer processes in this BrowsingInstance may need to find out 150 // 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 151 // 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)); 167 std::unique_ptr<FrameTreeNode> node_to_delete(std::move(*iter));
177 children_.erase(iter); 168 children_.erase(iter);
178 node_to_delete.reset(); 169 node_to_delete.reset();
179 return; 170 return;
180 } 171 }
181 } 172 }
182 } 173 }
183 174
184 void FrameTreeNode::ResetForNewProcess() { 175 void FrameTreeNode::ResetForNewProcess() {
185 current_frame_host()->set_last_committed_url(GURL()); 176 current_frame_host()->set_last_committed_url(GURL());
186 TraceSnapshot(); 177
178 if (blame_context_) {
179 blame_context_->UpdateArguments();
180 blame_context_->TakeSnapshot();
181 }
187 182
188 // Remove child nodes from the tree, then delete them. This destruction 183 // Remove child nodes from the tree, then delete them. This destruction
189 // operation will notify observers. 184 // operation will notify observers.
190 std::vector<std::unique_ptr<FrameTreeNode>>().swap(children_); 185 std::vector<std::unique_ptr<FrameTreeNode>>().swap(children_);
191 } 186 }
192 187
193 void FrameTreeNode::SetOpener(FrameTreeNode* opener) { 188 void FrameTreeNode::SetOpener(FrameTreeNode* opener) {
194 if (opener_) { 189 if (opener_) {
195 opener_->RemoveObserver(opener_observer_.get()); 190 opener_->RemoveObserver(opener_observer_.get());
196 opener_observer_.reset(); 191 opener_observer_.reset();
197 } 192 }
198 193
199 opener_ = opener; 194 opener_ = opener;
200 195
201 if (opener_) { 196 if (opener_) {
202 if (!opener_observer_) 197 if (!opener_observer_)
203 opener_observer_ = base::WrapUnique(new OpenerDestroyedObserver(this)); 198 opener_observer_ = base::WrapUnique(new OpenerDestroyedObserver(this));
204 opener_->AddObserver(opener_observer_.get()); 199 opener_->AddObserver(opener_observer_.get());
205 } 200 }
206 } 201 }
207 202
208 void FrameTreeNode::SetCurrentURL(const GURL& url) { 203 void FrameTreeNode::SetCurrentURL(const GURL& url) {
209 if (!has_committed_real_load_ && url != GURL(url::kAboutBlankURL)) 204 if (!has_committed_real_load_ && url != GURL(url::kAboutBlankURL))
210 has_committed_real_load_ = true; 205 has_committed_real_load_ = true;
211 current_frame_host()->set_last_committed_url(url); 206 current_frame_host()->set_last_committed_url(url);
212 TraceSnapshot(); 207
208 if (blame_context_) {
209 blame_context_->UpdateArguments();
210 blame_context_->TakeSnapshot();
211 }
213 } 212 }
214 213
215 void FrameTreeNode::SetCurrentOrigin( 214 void FrameTreeNode::SetCurrentOrigin(
216 const url::Origin& origin, 215 const url::Origin& origin,
217 bool is_potentially_trustworthy_unique_origin) { 216 bool is_potentially_trustworthy_unique_origin) {
218 if (!origin.IsSameOriginWith(replication_state_.origin) || 217 if (!origin.IsSameOriginWith(replication_state_.origin) ||
219 replication_state_.has_potentially_trustworthy_unique_origin != 218 replication_state_.has_potentially_trustworthy_unique_origin !=
220 is_potentially_trustworthy_unique_origin) { 219 is_potentially_trustworthy_unique_origin) {
221 render_manager_.OnDidUpdateOrigin(origin, 220 render_manager_.OnDidUpdateOrigin(origin,
222 is_potentially_trustworthy_unique_origin); 221 is_potentially_trustworthy_unique_origin);
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 if (speculative_frame_host) 470 if (speculative_frame_host)
472 speculative_frame_host->ResetLoadingState(); 471 speculative_frame_host->ResetLoadingState();
473 } else { 472 } else {
474 RenderFrameHostImpl* pending_frame_host = 473 RenderFrameHostImpl* pending_frame_host =
475 render_manager_.pending_frame_host(); 474 render_manager_.pending_frame_host();
476 if (pending_frame_host) 475 if (pending_frame_host)
477 pending_frame_host->ResetLoadingState(); 476 pending_frame_host->ResetLoadingState();
478 } 477 }
479 } 478 }
480 479
481 void FrameTreeNode::TraceSnapshot() const { 480 void FrameTreeNode::InitializeBlameContext() {
482 DCHECK_CURRENTLY_ON(BrowserThread::UI); 481 DCHECK(!blame_context_);
483 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( 482 blame_context_ = base::WrapUnique(new FrameTreeNodeBlameContext(this));
484 "navigation", "FrameTreeNode", 483 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 } 484 }
489 485
490 } // namespace content 486 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/frame_tree_node.h ('k') | content/browser/frame_host/frame_tree_node_blame_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698