Commit 039f8ee4 authored by jdduke's avatar jdduke Committed by Commit bot

[Android] Avoid using ContentViewCore when detaching from RWHVAndroid

The shutdown sequence for a given WebContents involves the
ContentViewCore detaching itself from WebContentsViewAndroid. This in
turn detaches the ContentViewCore from RenderWidgetHostViewAndroid.
However, as the state of the ContentViewCore may be inconsistent during
shutdown, calls into ContentViewCore during detachment may be
unreliable.

Avoid such calls by caching the WindowAndroid exposed by
ContentViewCore; the window has stronger lifetime guarantees and can
safely be used during detachment.

BUG=479878,464642

Review URL: https://codereview.chromium.org/1103213003

Cr-Commit-Position: refs/heads/master@{#327401}
parent a4fbda5f
...@@ -352,7 +352,8 @@ RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( ...@@ -352,7 +352,8 @@ RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid(
: host_(widget_host), : host_(widget_host),
outstanding_vsync_requests_(0), outstanding_vsync_requests_(0),
is_showing_(!widget_host->is_hidden()), is_showing_(!widget_host->is_hidden()),
content_view_core_(NULL), content_view_core_(nullptr),
content_view_core_window_android_(nullptr),
ime_adapter_android_(this), ime_adapter_android_(this),
cached_background_color_(SK_ColorWHITE), cached_background_color_(SK_ColorWHITE),
last_output_surface_id_(kUndefinedOutputSurfaceId), last_output_surface_id_(kUndefinedOutputSurfaceId),
...@@ -946,10 +947,9 @@ void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( ...@@ -946,10 +947,9 @@ void RenderWidgetHostViewAndroid::CopyFromCompositingSurface(
scoped_ptr<cc::CopyOutputRequest> request; scoped_ptr<cc::CopyOutputRequest> request;
scoped_refptr<cc::Layer> readback_layer; scoped_refptr<cc::Layer> readback_layer;
DCHECK(content_view_core_); DCHECK(content_view_core_window_android_);
DCHECK(content_view_core_->GetWindowAndroid());
ui::WindowAndroidCompositor* compositor = ui::WindowAndroidCompositor* compositor =
content_view_core_->GetWindowAndroid()->GetCompositor(); content_view_core_window_android_->GetCompositor();
DCHECK(compositor); DCHECK(compositor);
DCHECK(frame_provider_.get() || !surface_id_.is_null()); DCHECK(frame_provider_.get() || !surface_id_.is_null());
scoped_refptr<cc::Layer> layer = CreateDelegatedLayer(); scoped_refptr<cc::Layer> layer = CreateDelegatedLayer();
...@@ -1271,9 +1271,9 @@ bool RenderWidgetHostViewAndroid::SupportsAnimation() const { ...@@ -1271,9 +1271,9 @@ bool RenderWidgetHostViewAndroid::SupportsAnimation() const {
} }
void RenderWidgetHostViewAndroid::SetNeedsAnimate() { void RenderWidgetHostViewAndroid::SetNeedsAnimate() {
DCHECK(content_view_core_); DCHECK(content_view_core_window_android_);
DCHECK(using_browser_compositor_); DCHECK(using_browser_compositor_);
content_view_core_->GetWindowAndroid()->SetNeedsAnimate(); content_view_core_window_android_->SetNeedsAnimate();
} }
void RenderWidgetHostViewAndroid::MoveCaret(const gfx::PointF& position) { void RenderWidgetHostViewAndroid::MoveCaret(const gfx::PointF& position) {
...@@ -1442,16 +1442,16 @@ void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32 requests) { ...@@ -1442,16 +1442,16 @@ void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32 requests) {
// vsync requests will be pushed if/when we resume observing in // vsync requests will be pushed if/when we resume observing in
// |StartObservingRootWindow()|. // |StartObservingRootWindow()|.
if (observing_root_window_ && should_request_vsync) if (observing_root_window_ && should_request_vsync)
content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); content_view_core_window_android_->RequestVSyncUpdate();
} }
void RenderWidgetHostViewAndroid::StartObservingRootWindow() { void RenderWidgetHostViewAndroid::StartObservingRootWindow() {
DCHECK(content_view_core_); DCHECK(content_view_core_window_android_);
if (observing_root_window_) if (observing_root_window_)
return; return;
observing_root_window_ = true; observing_root_window_ = true;
content_view_core_->GetWindowAndroid()->AddObserver(this); content_view_core_window_android_->AddObserver(this);
// Clear existing vsync requests to allow a request to the new window. // Clear existing vsync requests to allow a request to the new window.
uint32 outstanding_vsync_requests = outstanding_vsync_requests_; uint32 outstanding_vsync_requests = outstanding_vsync_requests_;
...@@ -1460,7 +1460,7 @@ void RenderWidgetHostViewAndroid::StartObservingRootWindow() { ...@@ -1460,7 +1460,7 @@ void RenderWidgetHostViewAndroid::StartObservingRootWindow() {
} }
void RenderWidgetHostViewAndroid::StopObservingRootWindow() { void RenderWidgetHostViewAndroid::StopObservingRootWindow() {
if (!content_view_core_) { if (!content_view_core_window_android_) {
DCHECK(!observing_root_window_); DCHECK(!observing_root_window_);
return; return;
} }
...@@ -1469,7 +1469,7 @@ void RenderWidgetHostViewAndroid::StopObservingRootWindow() { ...@@ -1469,7 +1469,7 @@ void RenderWidgetHostViewAndroid::StopObservingRootWindow() {
return; return;
observing_root_window_ = false; observing_root_window_ = false;
content_view_core_->GetWindowAndroid()->RemoveObserver(this); content_view_core_window_android_->RemoveObserver(this);
} }
void RenderWidgetHostViewAndroid::SendBeginFrame(base::TimeTicks frame_time, void RenderWidgetHostViewAndroid::SendBeginFrame(base::TimeTicks frame_time,
...@@ -1744,6 +1744,9 @@ void RenderWidgetHostViewAndroid::SetContentViewCore( ...@@ -1744,6 +1744,9 @@ void RenderWidgetHostViewAndroid::SetContentViewCore(
} }
content_view_core_ = content_view_core; content_view_core_ = content_view_core;
content_view_core_window_android_ =
content_view_core_ ? content_view_core_->GetWindowAndroid() : nullptr;
DCHECK_EQ(!!content_view_core_, !!content_view_core_window_android_);
BrowserAccessibilityManager* manager = NULL; BrowserAccessibilityManager* manager = NULL;
if (host_) if (host_)
...@@ -1769,7 +1772,7 @@ void RenderWidgetHostViewAndroid::SetContentViewCore( ...@@ -1769,7 +1772,7 @@ void RenderWidgetHostViewAndroid::SetContentViewCore(
selection_controller_ = CreateSelectionController(this, content_view_core_); selection_controller_ = CreateSelectionController(this, content_view_core_);
if (!overscroll_controller_ && if (!overscroll_controller_ &&
content_view_core_->GetWindowAndroid()->GetCompositor()) { content_view_core_window_android_->GetCompositor()) {
overscroll_controller_ = CreateOverscrollController(content_view_core_); overscroll_controller_ = CreateOverscrollController(content_view_core_);
} }
} }
......
...@@ -330,6 +330,13 @@ class CONTENT_EXPORT RenderWidgetHostViewAndroid ...@@ -330,6 +330,13 @@ class CONTENT_EXPORT RenderWidgetHostViewAndroid
// ContentViewCoreImpl is our interface to the view system. // ContentViewCoreImpl is our interface to the view system.
ContentViewCoreImpl* content_view_core_; ContentViewCoreImpl* content_view_core_;
// Cache the WindowAndroid instance exposed by ContentViewCore to avoid
// calling into ContentViewCore when it is being detached from the
// WebContents during destruction. The WindowAndroid has stronger lifetime
// guarantees, and should be safe to use for observer detachment.
// This will be non-null iff |content_view_core_| is non-null.
ui::WindowAndroid* content_view_core_window_android_;
ImeAdapterAndroid ime_adapter_android_; ImeAdapterAndroid ime_adapter_android_;
// Body background color of the underlying document. // Body background color of the underlying document.
......
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