Fix for current state of the tab on Memory Monitor destroy
The title, url and incognito state of the tab was
getting reset, when the webview was destroyed
by memory monitor. This change restores the current state
Change-Id: I65c6f85d1a33c5c9848d861b44352fc1757b8def
diff --git a/src/com/android/browser/MemoryMonitor.java b/src/com/android/browser/MemoryMonitor.java
index a2de929..f5245a9 100644
--- a/src/com/android/browser/MemoryMonitor.java
+++ b/src/com/android/browser/MemoryMonitor.java
@@ -73,8 +73,9 @@
});
for(int i = 0; i < numActiveTabsToRelease; i++) {
- if(tabControl.getCurrentTab()!= activeTabList.get(i))
- activeTabList.get(i).destroy();
+ if(tabControl.getCurrentTab()!= activeTabList.get(i)) {
+ activeTabList.get(i).destroyThroughMemoryMonitor();
+ }
}
}
diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java
index 0a23205..fa6e372 100644
--- a/src/com/android/browser/Tab.java
+++ b/src/com/android/browser/Tab.java
@@ -195,6 +195,10 @@
private boolean mFullScreen = false;
private boolean mReceivedError;
+ // determine if webview is destroyed to MemoryMonitor
+ private boolean mWebViewDestroyedByMemoryMonitor;
+
+
private static synchronized Bitmap getDefaultFavicon(Context context) {
if (sDefaultFavicon == null) {
@@ -1292,6 +1296,7 @@
setTimeStamp();
mInPageLoad = false;
mInForeground = false;
+ mWebViewDestroyedByMemoryMonitor = false;
mDownloadListener = new BrowserDownloadListener() {
public void onDownloadStart(String url, String userAgent,
@@ -1407,10 +1412,21 @@
syncCurrentState(w, null);
} else {
mCurrentState = new PageState(mContext, mMainView.isPrivateBrowsingEnabled());
+
+ if (mWebViewDestroyedByMemoryMonitor) {
+ /*
+ * If tab was destroyed as a result of the MemoryMonitor
+ * then we need to restore the state properties
+ * from the old WebView (mMainView)
+ */
+ syncCurrentState(mMainView, null);
+ mWebViewDestroyedByMemoryMonitor = false;
+ }
}
}
// set the new one
mMainView = w;
+
// attach the WebViewClient, WebChromeClient and DownloadListener
if (mMainView != null) {
mMainView.setWebViewClient(mWebViewClient);
@@ -1437,6 +1453,11 @@
}
}
+ public void destroyThroughMemoryMonitor() {
+ mWebViewDestroyedByMemoryMonitor = true;
+ destroy();
+ }
+
/**
* Destroy the tab's main WebView and subWindow if any
*/