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