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 d2964150cc89a0fc601ddcbdaba3f4b4ce63e73e..37aad23306bdd6098201359fecfe1dfce0f1b772 100644 |
--- a/android_webview/java/src/org/chromium/android_webview/AwContents.java |
+++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java |
@@ -20,6 +20,7 @@ import android.net.http.SslCertificate; |
import android.os.AsyncTask; |
import android.os.Build; |
import android.os.Bundle; |
+import android.os.Handler; |
import android.os.Message; |
import android.text.TextUtils; |
import android.util.Log; |
@@ -889,8 +890,19 @@ public class AwContents { |
* Destroys this object and deletes its native counterpart. |
*/ |
public void destroy() { |
+ if (isDestroyed()) return; |
+ // If we are attached, we have to call native detach to clean up |
+ // hardware resources. |
+ if (mIsAttachedToWindow) { |
+ nativeOnDetachedFromWindow(mNativeAwContents); |
+ } |
mIsDestroyed = true; |
- destroyNatives(); |
+ new Handler().post(new Runnable() { |
+ @Override |
+ public void run() { |
+ destroyNatives(); |
+ } |
+ }); |
} |
/** |
@@ -899,11 +911,6 @@ public class AwContents { |
private void destroyNatives() { |
if (mCleanupReference != null) { |
assert mNativeAwContents != 0; |
- // If we are attached, we have to call native detach to clean up |
- // hardware resources. |
- if (mIsAttachedToWindow) { |
- nativeOnDetachedFromWindow(mNativeAwContents); |
- } |
mWebContentsObserver.detachFromWebContents(); |
mWebContentsObserver = null; |
@@ -924,12 +931,7 @@ public class AwContents { |
} |
private boolean isDestroyed() { |
- if (mIsDestroyed) { |
- assert mContentViewCore == null; |
- assert mWebContents == null; |
- assert mNavigationController == null; |
- assert mNativeAwContents == 0; |
- } else { |
+ if (!mIsDestroyed) { |
assert mContentViewCore != null; |
assert mWebContents != null; |
assert mNavigationController != null; |