summaryrefslogtreecommitdiff
path: root/src/com/android/browser/TabControl.java
diff options
context:
space:
mode:
authorPatrick Scott <phanna@android.com>2010-01-27 16:39:11 -0500
committerPatrick Scott <phanna@android.com>2010-01-28 09:11:12 -0500
commitd944d4d63c9e93b51fae38fc86f0d87fff0e3a21 (patch)
treedfcbce4241990de253eed322c61f4d8eae18ac90 /src/com/android/browser/TabControl.java
parent068e48b469f5abca53ee3da38f933cf2c25c93b8 (diff)
Fix a legit crash that the monkey found.
If the device is running low on memory, the Browser may free background tabs. removeTab could potentially remove a tab that has a lower index than the current tab. That would cause mCurrentTab to point to the incorrect tab. Update mCurrentTab if that is the case so it is pointing to the correct index. Bug: 2371002
Diffstat (limited to 'src/com/android/browser/TabControl.java')
-rw-r--r--src/com/android/browser/TabControl.java16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/com/android/browser/TabControl.java b/src/com/android/browser/TabControl.java
index 5b5493f0..5e64a4b2 100644
--- a/src/com/android/browser/TabControl.java
+++ b/src/com/android/browser/TabControl.java
@@ -192,18 +192,26 @@ class TabControl {
return false;
}
- // Only remove the tab if it is the current one.
- if (getCurrentTab() == t) {
+ // Grab the current tab before modifying the list.
+ Tab current = getCurrentTab();
+
+ // Remove t from our list of tabs.
+ mTabs.remove(t);
+
+ // Put the tab in the background only if it is the current one.
+ if (current == t) {
t.putInBackground();
mCurrentTab = -1;
+ } else {
+ // If a tab that is earlier in the list gets removed, the current
+ // index no longer points to the correct tab.
+ mCurrentTab = getTabIndex(current);
}
// destroy the tab
t.destroy();
// clear it's references to parent and children
t.removeFromTree();
- // Remove it from our list of tabs.
- mTabs.remove(t);
// The tab indices have shifted, update all the saved state so we point
// to the correct index.