Fixes issue with reusing tab in browser
Browser has an option in intent to reuse a tab by destroying the WebView.
The cleanup of snapshots in the WebView's destruction was asynchronous which was
causing issues when reusing the tab with new instance of WebView.
Change-Id: I6a0ecf11d1ed05f8d273404784529e7e7b0ab1f1
diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java
index 7070891..3e3c9aa 100644
--- a/src/com/android/browser/Tab.java
+++ b/src/com/android/browser/Tab.java
@@ -800,7 +800,8 @@
Controller controller = (Controller)mWebViewController;
controller.getUi().translateTitleBar(topControlsOffsetYPix);
// Resize the viewport if top controls is not visible
- if (topControlsOffsetYPix == 0.0f || contentOffsetYPix == 0.0f)
+ if (mMainView != null &&
+ (topControlsOffsetYPix == 0.0f || contentOffsetYPix == 0.0f))
((BrowserWebView)mMainView).enableTopControls(
(topControlsOffsetYPix == 0.0f) ? true : false);
}
@@ -1391,8 +1392,10 @@
dismissSubWindow();
// save the WebView to call destroy() after detach it from the tab
final WebView webView = mMainView;
+ setWebView(null);
if (!mWebViewDestroyedByMemoryMonitor &&
!BrowserCommandLine.hasSwitch("ui-low-power-mode")) {
+ // Tabs can be reused with new instance of WebView so delete the snapshots
webView.getSnapshotIds(new ValueCallback<List<Integer>>() {
@Override
public void onReceiveValue(List<Integer> ids) {
@@ -1402,14 +1405,12 @@
webView.deleteSnapshot(id);
}
}
- setWebView(null);
webView.destroy();
}
});
- return;
+ } else {
+ webView.destroy();
}
- setWebView(null);
- webView.destroy();
}
}