Index: android_webview/java/src/org/chromium/android_webview/AwContents.java |
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java |
index c07ef8c7305ca7d0e1e4e1bc77b38bb238e90984..243c5bff9d8107631f51089edb06a234d8a88844 100644 |
--- a/android_webview/java/src/org/chromium/android_webview/AwContents.java |
+++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java |
@@ -239,6 +239,8 @@ public class AwContents implements SmartClipProvider, |
private boolean mIsAttachedToWindow; |
// Visiblity state of |mContentViewCore|. |
private boolean mIsContentViewCoreVisible; |
+ private boolean mIsUpdateVisibilityTaskPending; |
+ private Runnable mUpdateVisibilityRunnable; |
private Bitmap mFavicon; |
private boolean mHasRequestedVisitedHistoryFromClient; |
@@ -694,6 +696,12 @@ public class AwContents implements SmartClipProvider, |
mBackgroundThreadClient = new BackgroundThreadClientImpl(); |
mIoThreadClient = new IoThreadClientImpl(); |
mInterceptNavigationDelegate = new InterceptNavigationDelegateImpl(); |
+ mUpdateVisibilityRunnable = new Runnable() { |
+ @Override |
+ public void run() { |
+ updateContentViewCoreVisibility(); |
+ } |
+ }; |
AwSettings.ZoomSupportChangeListener zoomListener = |
new AwSettings.ZoomSupportChangeListener() { |
@@ -2281,10 +2289,27 @@ public class AwContents implements SmartClipProvider, |
&& visible && !mIsWindowVisible; |
mIsWindowVisible = visible; |
if (!isDestroyed()) nativeSetWindowVisibility(mNativeAwContents, mIsWindowVisible); |
- updateContentViewCoreVisibility(); |
+ postUpdateContentViewCoreVisibility(); |
+ } |
+ |
+ private void postUpdateContentViewCoreVisibility() { |
+ if (mIsUpdateVisibilityTaskPending) return; |
+ // When WebView is attached to a visible window, WebView will be |
+ // attached to a window whose visibility is initially invisible, then |
+ // the window visibility will be updated to true. This means CVC |
+ // visibility will be set to false then true immediately, in the same |
+ // function call of View#dispatchAttachedToWindow. DetachedFromWindow |
+ // is a similar case, where window visibility changes before AwContents |
+ // is detached from window. |
+ // |
+ // To prevent this flip of CVC visibility, post the task to update CVC |
+ // visibility during attach, detach and window visibility change. |
+ mIsUpdateVisibilityTaskPending = true; |
+ mHandler.post(mUpdateVisibilityRunnable); |
} |
private void updateContentViewCoreVisibility() { |
+ mIsUpdateVisibilityTaskPending = false; |
if (isDestroyed()) return; |
boolean contentViewCoreVisible = nativeIsVisible(mNativeAwContents); |
@@ -2930,6 +2955,7 @@ public class AwContents implements SmartClipProvider, |
nativeOnAttachedToWindow(mNativeAwContents, mContainerView.getWidth(), |
mContainerView.getHeight()); |
updateHardwareAcceleratedFeaturesToggle(); |
+ postUpdateContentViewCoreVisibility(); |
setLocale(LocaleUtils.getDefaultLocale()); |
@@ -2951,6 +2977,7 @@ public class AwContents implements SmartClipProvider, |
mContentViewCore.onDetachedFromWindow(); |
updateHardwareAcceleratedFeaturesToggle(); |
+ postUpdateContentViewCoreVisibility(); |
if (mComponentCallbacks != null) { |
mContext.unregisterComponentCallbacks(mComponentCallbacks); |