Commit a1dfadaa authored by Alexander Timin's avatar Alexander Timin Committed by Commit Bot

[content] Clean up FrameTreeNode::parent.

Convert a few places which can use FrameTreeNode::parent to use
RenderFrameHostImpl::GetParent instead.

This is more robust given that GetParent() never changes, while the
current RenderFrameHost in the parent FrameTreeNode might.

R=arthursonzogni@chromium.org,creis@chromium.org,lfg@chromium.org
CC=​alexmos@chromium.org,bfcache-bugs@chromium.org
BUG=1073269

Change-Id: I9b162f48825688f4b20c329721630d4c5cedb3e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2161076Reviewed-by: default avatarCharlie Reis <creis@chromium.org>
Reviewed-by: default avatarArthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: Alexander Timin <altimin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#763314}
parent 9a5e01d7
......@@ -130,10 +130,11 @@ void CrossProcessFrameConnector::SetView(RenderWidgetHostViewChildFrame* view) {
void CrossProcessFrameConnector::RenderProcessGone() {
has_crashed_ = true;
FrameTreeNode* node = frame_proxy_in_parent_renderer_->frame_tree_node();
int process_id = node->current_frame_host()->GetProcess()->GetID();
for (node = node->parent(); node; node = node->parent()) {
if (node->current_frame_host()->GetProcess()->GetID() == process_id) {
RenderFrameHost* rfh =
frame_proxy_in_parent_renderer_->frame_tree_node()->current_frame_host();
int process_id = rfh->GetProcess()->GetID();
for (rfh = rfh->GetParent(); rfh; rfh = rfh->GetParent()) {
if (rfh->GetProcess()->GetID() == process_id) {
// The crash will be already logged by the ancestor - ignore this crash in
// the current instance of the CrossProcessFrameConnector.
is_crash_already_logged_ = true;
......
......@@ -580,11 +580,11 @@ void FrameTreeNode::BeforeUnloadCanceled() {
}
bool FrameTreeNode::NotifyUserActivation() {
for (FrameTreeNode* node = this; node; node = node->parent()) {
if (!node->user_activation_state_.HasBeenActive() &&
node->current_frame_host())
node->current_frame_host()->DidReceiveFirstUserActivation();
node->user_activation_state_.Activate();
for (RenderFrameHostImpl* rfh = current_frame_host(); rfh;
rfh = rfh->GetParent()) {
if (!rfh->frame_tree_node()->user_activation_state_.HasBeenActive())
rfh->DidReceiveFirstUserActivation();
rfh->frame_tree_node()->user_activation_state_.Activate();
}
replication_state_.has_received_user_gesture = true;
......
......@@ -554,6 +554,10 @@ class CONTENT_EXPORT RenderFrameHostImpl
// will have the JS bindings enabled.
void EnableMojoJsBindings();
// Returns true if this is a main RenderFrameHost. True if and only if this
// RenderFrameHost doesn't have a parent.
bool is_main_frame() const { return !parent_; }
// Returns this RenderFrameHost's loading state. This method is only used by
// FrameTreeNode. The proper way to check whether a frame is loading is to
// call FrameTreeNode::IsLoading.
......@@ -1853,12 +1857,12 @@ class CONTENT_EXPORT RenderFrameHostImpl
// frames, it will return the current frame's view.
RenderWidgetHostViewBase* GetViewForAccessibility();
// Returns the child FrameTreeNode if |child_frame_routing_id| is an
// Returns the child RenderFrameHostImpl if |child_frame_routing_id| is an
// immediate child of this FrameTreeNode. |child_frame_routing_id| is
// considered untrusted, so the renderer process is killed if it refers to a
// FrameTreeNode that is not a child of this node.
FrameTreeNode* FindAndVerifyChild(int32_t child_frame_routing_id,
bad_message::BadMessageReason reason);
// RenderFrameHostImpl that is not a child of this node.
RenderFrameHostImpl* FindAndVerifyChild(int32_t child_frame_routing_id,
bad_message::BadMessageReason reason);
// Returns a raw pointer to the Web Bluetooth Service owned by the frame. Used
// for testing purposes only (see |TestRenderFrameHost|).
......
......@@ -548,9 +548,8 @@ void RenderFrameProxyHost::OnRouteMessageEvent(
// to the target frame before the postMessage, as sites might implicitly
// be relying on this ordering.
bool target_is_descendant_of_source = false;
for (FrameTreeNode* node = target_rfh->frame_tree_node(); node;
node = node->parent()) {
if (node == source_rfh->frame_tree_node()) {
for (RenderFrameHost* rfh = target_rfh; rfh; rfh = rfh->GetParent()) {
if (rfh == source_rfh) {
target_is_descendant_of_source = true;
break;
}
......
......@@ -48,14 +48,14 @@ void SetAndCheckAncestorFlag(MediaStreamRequest* request) {
// RenderFrame destroyed before the request is handled?
return;
}
FrameTreeNode* node = rfh->frame_tree_node();
while (node->parent() != nullptr) {
if (!node->HasSameOrigin(*node->parent())) {
while (rfh->GetParent()) {
if (!rfh->GetLastCommittedOrigin().IsSameOriginWith(
rfh->GetParent()->GetLastCommittedOrigin())) {
request->all_ancestors_have_same_origin = false;
return;
}
node = node->parent();
rfh = rfh->GetParent();
}
request->all_ancestors_have_same_origin = true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment