Skip to content

Commit

Permalink
content: Fix nested main frame tracking for provisional main frames
Browse files Browse the repository at this point in the history
The LocalMainFrame for a Document in a newly created process goes
through the CreateFrame IPC. This API misses propagating whether this is
a top-level Document vs fenced frame, guest view etc. Fix that.

R=rakina@chromium.org

Bug: 1464791
Change-Id: Ic31483053a0c64be83358582003840a83373dab5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5030933
Reviewed-by: Ken Buchanan <kenrb@chromium.org>
Commit-Queue: Khushal Sagar <khushalsagar@chromium.org>
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Auto-Submit: Khushal Sagar <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1226496}
  • Loading branch information
khushalsagar authored and Chromium LUCI CQ committed Nov 18, 2023
1 parent 6f9e8e7 commit f293502
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
3 changes: 3 additions & 0 deletions content/browser/renderer_host/render_frame_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3370,6 +3370,9 @@ bool RenderFrameHostImpl::CreateRenderFrame(
params->interface_broker.InitWithNewPipeAndPassReceiver());

params->routing_id = routing_id_;
params->is_for_nested_main_frame =
is_main_frame() &&
render_view_host_->ViewWidgetType() != mojom::ViewWidgetType::kTopLevel;
params->previous_frame_token = previous_frame_token;
params->opener_frame_token = opener_frame_token;
params->parent_frame_token = parent_frame_token;
Expand Down
39 changes: 25 additions & 14 deletions content/browser/renderer_host/render_view_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -552,22 +552,10 @@ bool RenderViewHostImpl::CreateRenderView(
}
}

bool is_portal = frame_tree_->delegate()->IsPortal();
bool is_guest_view = delegate_->IsGuest();
bool is_fenced_frame = frame_tree_->is_fenced_frame();

if (is_fenced_frame) {
params->type = mojom::ViewWidgetType::kFencedFrame;

params->type = ViewWidgetType();
if (params->type == mojom::ViewWidgetType::kFencedFrame) {
params->fenced_frame_mode =
frame_tree_->root()->GetDeprecatedFencedFrameMode();
} else if (is_portal) {
DCHECK(!is_guest_view);
params->type = mojom::ViewWidgetType::kPortal;
} else if (is_guest_view) {
params->type = mojom::ViewWidgetType::kGuestView;
} else {
params->type = mojom::ViewWidgetType::kTopLevel;
}

// Send the current page's browsing context group to the renderer. It is
Expand Down Expand Up @@ -1011,4 +999,27 @@ base::SafeRef<RenderViewHostImpl> RenderViewHostImpl::GetSafeRef() {
return weak_factory_.GetSafeRef();
}

mojom::ViewWidgetType RenderViewHostImpl::ViewWidgetType() {
if (view_widget_type_) {
return *view_widget_type_;
}

bool is_portal = frame_tree_->delegate()->IsPortal();
bool is_guest_view = delegate_->IsGuest();
bool is_fenced_frame = frame_tree_->is_fenced_frame();

if (is_fenced_frame) {
view_widget_type_ = mojom::ViewWidgetType::kFencedFrame;
} else if (is_portal) {
DCHECK(!is_guest_view);
view_widget_type_ = mojom::ViewWidgetType::kPortal;
} else if (is_guest_view) {
view_widget_type_ = mojom::ViewWidgetType::kGuestView;
} else {
view_widget_type_ = mojom::ViewWidgetType::kTopLevel;
}

return *view_widget_type_;
}

} // namespace content
4 changes: 4 additions & 0 deletions content/browser/renderer_host/render_view_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ class CONTENT_EXPORT RenderViewHostImpl

base::SafeRef<RenderViewHostImpl> GetSafeRef();

mojom::ViewWidgetType ViewWidgetType();

SiteInstanceGroup* site_instance_group() const {
return &*site_instance_group_;
}
Expand Down Expand Up @@ -409,6 +411,8 @@ class CONTENT_EXPORT RenderViewHostImpl
// Routing ID for the main frame's RenderFrameHost.
int main_frame_routing_id_;

absl::optional<mojom::ViewWidgetType> view_widget_type_;

// This monitors input changes so they can be reflected to the interaction MQ.
std::unique_ptr<InputDeviceChangeObserver> input_device_change_observer_;

Expand Down
4 changes: 4 additions & 0 deletions content/common/frame.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ struct CreateFrameParams {
// request associated interfaces from its corresponding `RenderFrameHostImpl`.
pending_associated_remote<blink.mojom.AssociatedInterfaceProvider>
associated_interface_provider_remote;

// Set if this frame corresponds to the main frame for a non top-level
// FrameTree (GuestView, fenced frame etc.).
bool is_for_nested_main_frame;
};

// Provided with each call to Frame::GetSerializedHtmlWithLocalLinks() so that
Expand Down
3 changes: 1 addition & 2 deletions content/renderer/agent_scheduling_group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,7 @@ void AgentSchedulingGroup::CreateFrame(mojom::CreateFrameParamsPtr params) {
std::move(params->widget_params),
std::move(params->frame_owner_properties),
params->is_on_initial_empty_document, params->document_token,
std::move(params->policy_container),
/*is_for_nested_main_frame=*/false);
std::move(params->policy_container), params->is_for_nested_main_frame);
}

void AgentSchedulingGroup::CreateSharedStorageWorkletService(
Expand Down

0 comments on commit f293502

Please sign in to comment.