Commit 355e694e authored by Francois Doray's avatar Francois Doray Committed by Chromium LUCI CQ

[content] Do not unnecessarily handle delegated_frame_host_ being null in RenderWidgetHostViewAura.

This is a cleanup prior to fixing crbug.com/1164477. It improves
readability by removing code that handles situations that never occur.

Bug: 1164477
Change-Id: I3251051a3f66283853bf551c29284595621bd759
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2616354
Commit-Queue: Charlie Reis <creis@chromium.org>
Auto-Submit: François Doray <fdoray@chromium.org>
Reviewed-by: default avatarCharlie Reis <creis@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843677}
parent 8593927f
......@@ -534,8 +534,7 @@ bool RenderWidgetHostViewAura::HasFocus() {
}
bool RenderWidgetHostViewAura::IsSurfaceAvailableForCopy() {
if (!delegated_frame_host_)
return false;
DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
return delegated_frame_host_->CanCopyFromCompositingSurface();
}
......@@ -550,6 +549,8 @@ bool RenderWidgetHostViewAura::IsShowing() {
}
void RenderWidgetHostViewAura::WasUnOccluded() {
DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
const Visibility old_visibility = visibility_;
visibility_ = Visibility::VISIBLE;
......@@ -565,8 +566,7 @@ void RenderWidgetHostViewAura::WasUnOccluded() {
}
auto tab_switch_start_state = TakeRecordContentToVisibleTimeRequest();
bool has_saved_frame =
delegated_frame_host_ ? delegated_frame_host_->HasSavedFrame() : false;
bool has_saved_frame = delegated_frame_host_->HasSavedFrame();
bool show_reason_bfcache_restore =
tab_switch_start_state
......@@ -589,14 +589,12 @@ void RenderWidgetHostViewAura::WasUnOccluded() {
NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible());
}
if (delegated_frame_host_) {
// If the frame for the renderer is already available, then the
// tab-switching time is the presentation time for the browser-compositor.
delegated_frame_host_->WasShown(
GetLocalSurfaceId(), window_->bounds().size(),
has_saved_frame ? std::move(tab_switch_start_state)
: blink::mojom::RecordContentToVisibleTimeRequestPtr());
}
#if defined(OS_WIN)
UpdateLegacyWin();
......@@ -604,13 +602,13 @@ void RenderWidgetHostViewAura::WasUnOccluded() {
}
void RenderWidgetHostViewAura::HideImpl() {
DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
DCHECK(visibility_ == Visibility::HIDDEN ||
visibility_ == Visibility::OCCLUDED);
if (!host()->is_hidden()) {
host()->WasHidden();
aura::WindowTreeHost* host = window_->GetHost();
if (delegated_frame_host_) {
aura::Window* parent = window_->parent();
aura::Window::OcclusionState parent_occl_state =
parent ? parent->occlusion_state()
......@@ -627,7 +625,6 @@ void RenderWidgetHostViewAura::HideImpl() {
cause = DelegatedFrameHost::HiddenCause::kOther;
}
delegated_frame_host_->WasHidden(cause);
}
#if defined(OS_WIN)
if (host) {
// We reparent the legacy Chrome_RenderWidgetHostHWND window to the global
......@@ -679,10 +676,9 @@ void RenderWidgetHostViewAura::SetDisplayFeatureForTesting(
}
void RenderWidgetHostViewAura::WindowTitleChanged() {
if (delegated_frame_host_) {
DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
delegated_frame_host_->WindowTitleChanged(
base::UTF16ToUTF8(window_->GetTitle()));
}
}
bool RenderWidgetHostViewAura::IsMouseLocked() {
......@@ -824,7 +820,7 @@ RenderWidgetHostViewAura::GetParentNativeViewAccessible() {
}
void RenderWidgetHostViewAura::ResetFallbackToFirstNavigationSurface() {
if (delegated_frame_host_)
DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
delegated_frame_host_->ResetFallbackToFirstNavigationSurface();
}
......@@ -1762,14 +1758,17 @@ void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) {
}
bool RenderWidgetHostViewAura::HasFallbackSurface() const {
return delegated_frame_host_ && delegated_frame_host_->HasFallbackSurface();
DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
return delegated_frame_host_->HasFallbackSurface();
}
bool RenderWidgetHostViewAura::TransformPointToCoordSpaceForView(
const gfx::PointF& point,
RenderWidgetHostViewBase* target_view,
gfx::PointF* transformed_point) {
if (target_view == this || !delegated_frame_host_) {
DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
if (target_view == this) {
*transformed_point = point;
return true;
}
......@@ -1789,8 +1788,8 @@ viz::FrameSinkId RenderWidgetHostViewAura::GetRootFrameSinkId() {
}
viz::SurfaceId RenderWidgetHostViewAura::GetCurrentSurfaceId() const {
return delegated_frame_host_ ? delegated_frame_host_->GetCurrentSurfaceId()
: viz::SurfaceId();
DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
return delegated_frame_host_->GetCurrentSurfaceId();
}
void RenderWidgetHostViewAura::FocusedNodeChanged(
......@@ -2105,16 +2104,17 @@ bool RenderWidgetHostViewAura::SynchronizeVisualProperties(
const cc::DeadlinePolicy& deadline_policy,
const base::Optional<viz::LocalSurfaceId>& child_local_surface_id) {
DCHECK(window_);
DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
window_->UpdateLocalSurfaceIdFromEmbeddedClient(child_local_surface_id);
// If the viz::LocalSurfaceId is invalid, we may have been evicted,
// allocate a new one to establish bounds.
if (!GetLocalSurfaceId().is_valid())
window_->AllocateLocalSurfaceId();
if (delegated_frame_host_) {
delegated_frame_host_->EmbedSurface(
GetLocalSurfaceId(), window_->bounds().size(), deadline_policy);
}
return host()->SynchronizeVisualProperties();
}
......@@ -2289,6 +2289,8 @@ void RenderWidgetHostViewAura::UpdateLegacyWin() {
#endif
void RenderWidgetHostViewAura::AddedToRootWindow() {
DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
window_->GetHost()->AddObserver(this);
UpdateScreenInfo(window_);
......@@ -2308,11 +2310,12 @@ void RenderWidgetHostViewAura::AddedToRootWindow() {
UpdateLegacyWin();
#endif
if (delegated_frame_host_)
delegated_frame_host_->AttachToCompositor(window_->GetHost()->compositor());
}
void RenderWidgetHostViewAura::RemovingFromRootWindow() {
DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
aura::client::CursorClient* cursor_client =
aura::client::GetCursorClient(window_->GetRootWindow());
if (cursor_client)
......@@ -2321,7 +2324,6 @@ void RenderWidgetHostViewAura::RemovingFromRootWindow() {
DetachFromInputMethod(true);
window_->GetHost()->RemoveObserver(this);
if (delegated_frame_host_)
delegated_frame_host_->DetachFromCompositor();
#if defined(OS_WIN)
......@@ -2406,9 +2408,10 @@ void RenderWidgetHostViewAura::CreateSelectionController() {
}
void RenderWidgetHostViewAura::OnDidNavigateMainFrameToNewPage() {
DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
// Invalidate the surface so that we don't attempt to evict it multiple times.
window_->InvalidateLocalSurfaceId();
if (delegated_frame_host_)
delegated_frame_host_->OnNavigateToNewPage();
CancelActiveTouches();
}
......@@ -2566,6 +2569,8 @@ RenderWidgetHostViewAura::DidUpdateVisualProperties(
}
void RenderWidgetHostViewAura::DidNavigate() {
DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
if (!IsShowing()) {
// Navigating while hidden should not allocate a new LocalSurfaceID. Once
// sizes are ready, or we begin to Show, we can then allocate the new
......@@ -2582,7 +2587,6 @@ void RenderWidgetHostViewAura::DidNavigate() {
base::nullopt);
}
}
if (delegated_frame_host_)
delegated_frame_host_->DidNavigate();
is_first_navigation_ = false;
}
......@@ -2601,10 +2605,10 @@ void RenderWidgetHostViewAura::TakeFallbackContentFrom(
if (color)
SetBackgroundColor(*color);
if (delegated_frame_host_ && view_aura->delegated_frame_host_) {
DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
DCHECK(view_aura->delegated_frame_host_);
delegated_frame_host_->TakeFallbackContentFrom(
view_aura->delegated_frame_host_.get());
}
host()->GetContentRenderingTimeoutFrom(view_aura->host());
}
......
......@@ -592,7 +592,7 @@ class CONTENT_EXPORT RenderWidgetHostViewAura
aura::Window* window_;
std::unique_ptr<DelegatedFrameHostClient> delegated_frame_host_client_;
// NOTE: this may be null.
// NOTE: this may be null during destruction.
std::unique_ptr<DelegatedFrameHost> delegated_frame_host_;
std::unique_ptr<WindowObserver> window_observer_;
......
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